Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: content/browser/browser_plugin/browser_plugin_embedder_helper.cc

Issue 10868012: Browser Plugin: New Implementation (Browser Side) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master-trial-obrowser
Patch Set: Disable BrowserPluginHostTest.NavigateGuest on win, flaking. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/browser_plugin/browser_plugin_embedder_helper.h"
6
7 #include "content/browser/browser_plugin/browser_plugin_embedder.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/common/browser_plugin_messages.h"
10 #include "content/common/view_messages.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/render_widget_host_view.h"
14 #include "ui/gfx/size.h"
15
16 namespace content {
17
18 BrowserPluginEmbedderHelper::BrowserPluginEmbedderHelper(
19 BrowserPluginEmbedder* embedder,
20 RenderViewHost* render_view_host)
21 : RenderViewHostObserver(render_view_host),
22 embedder_(embedder) {
23 }
24
25 BrowserPluginEmbedderHelper::~BrowserPluginEmbedderHelper() {
26 }
27
28 bool BrowserPluginEmbedderHelper::Send(IPC::Message* message) {
29 return RenderViewHostObserver::Send(message);
30 }
31
32 bool BrowserPluginEmbedderHelper::OnMessageReceived(
33 const IPC::Message& message) {
34 bool handled = true;
35 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedderHelper, message)
36 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest,
37 OnNavigateGuest);
38 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest)
39 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK);
40 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus);
41 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_HandleInputEvent,
42 OnHandleInputEvent(*static_cast<const IPC::SyncMessage*>(&message),
43 &handled))
44 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed,
45 OnPluginDestroyed);
46 IPC_MESSAGE_UNHANDLED(handled = false)
47 IPC_END_MESSAGE_MAP()
48 return handled;
49 }
50
51 void BrowserPluginEmbedderHelper::OnResizeGuest(
52 int instance_id,
53 const BrowserPluginHostMsg_ResizeGuest_Params& params) {
54 TransportDIB* damage_buffer = NULL;
55 #if defined(OS_WIN)
56 // On Windows we need to duplicate the handle from the remote process.
57 HANDLE section;
58 DuplicateHandle(render_view_host()->GetProcess()->GetHandle(),
59 params.damage_buffer_id.handle,
60 GetCurrentProcess(),
61 &section,
62 STANDARD_RIGHTS_REQUIRED | FILE_MAP_READ | FILE_MAP_WRITE,
63 FALSE, 0);
64 damage_buffer = TransportDIB::Map(section);
65 #elif defined(OS_MACOSX)
66 // On OSX, the browser allocates all DIBs and keeps a file descriptor around
67 // for each.
68 damage_buffer = render_view_host()->GetProcess()->
69 GetTransportDIB(params.damage_buffer_id);
70 #elif defined(OS_ANDROID)
71 damage_buffer = TransportDIB::Map(params.damage_buffer_id);
72 #elif defined(OS_POSIX)
73 damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey);
74 #endif // defined(OS_POSIX)
75 DCHECK(damage_buffer);
76 // TODO(fsamuel): Schedule this later so that we don't stall the embedder for
77 // too long.
78 embedder_->ResizeGuest(instance_id,
79 damage_buffer,
80 #if defined(OS_WIN)
81 params.damage_buffer_size,
82 #endif
83 params.width,
84 params.height,
85 params.resize_pending,
86 params.scale_factor);
87 }
88
89 void BrowserPluginEmbedderHelper::OnHandleInputEvent(
90 const IPC::SyncMessage& message,
91 bool* handled) {
92 *handled = true;
93 PickleIterator iter(message);
94
95 // TODO(fsamuel): This appears to be a monotonically increasing value.
96 int instance_id = -1;
97 const char* guest_rect_data = NULL;
98 int guest_rect_data_length = -1;
99 const char* input_event_data = NULL;
100 int input_event_data_length = -1;
101 if (!iter.SkipBytes(4) ||
102 !message.ReadInt(&iter, &instance_id) ||
103 !message.ReadData(&iter, &guest_rect_data, &guest_rect_data_length) ||
104 !message.ReadData(&iter, &input_event_data, &input_event_data_length)) {
105 *handled = false;
106 return;
107 }
108 const gfx::Rect* guest_rect =
109 reinterpret_cast<const gfx::Rect*>(guest_rect_data);
110 const WebKit::WebInputEvent* input_event =
111 reinterpret_cast<const WebKit::WebInputEvent*>(input_event_data);
112 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
113 render_view_host());
114
115 // Convert the window coordinates into screen coordinates.
116 gfx::Rect guest_screen_rect(*guest_rect);
117 if (rvh->GetView())
118 guest_screen_rect.Offset(rvh->GetView()->GetViewBounds().origin());
119
120 IPC::Message* reply_message =
121 IPC::SyncMessage::GenerateReply(&message);
122 embedder_->HandleInputEvent(instance_id,
123 rvh,
124 guest_screen_rect,
125 *input_event,
126 reply_message);
127 }
128
129 void BrowserPluginEmbedderHelper::OnNavigateGuest(int instance_id,
130 int64 frame_id,
131 const std::string& src,
132 const gfx::Size& size) {
133 embedder_->NavigateGuest(render_view_host(), instance_id, frame_id, src,
134 size);
135 }
136
137 void BrowserPluginEmbedderHelper::OnUpdateRectACK(int instance_id,
138 int message_id,
139 const gfx::Size& size) {
140 embedder_->UpdateRectACK(instance_id, message_id, size);
141 }
142
143 void BrowserPluginEmbedderHelper::OnSetFocus(int instance_id, bool focused) {
144 embedder_->SetFocus(instance_id, focused);
145 }
146
147 void BrowserPluginEmbedderHelper::OnPluginDestroyed(int instance_id) {
148 embedder_->PluginDestroyed(instance_id);
149 }
150
151 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_embedder_helper.h ('k') | content/browser/browser_plugin/browser_plugin_guest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698