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

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

Issue 10868012: Browser Plugin: New Implementation (Browser Side) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master-trial-obrowser
Patch Set: Fixed tests. Also fixed a case where UpdateRect was being sent from bp renderer before NavigateGues… Created 8 years, 4 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_host_embedder_role.h"
6
7 #include "base/time.h"
8 #include "content/browser/browser_plugin/browser_plugin_host_embedder_delegate.h "
9 #include "content/browser/renderer_host/render_view_host_impl.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h"
11 #include "content/browser/web_contents/web_contents_impl.h"
12 #include "content/common/browser_plugin_messages.h"
13 #include "content/common/view_messages.h"
14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/notification_source.h"
17 #include "content/public/browser/notification_types.h"
18 #include "content/public/browser/render_process_host.h"
19 #include "content/public/browser/render_view_host.h"
20 #include "content/public/browser/render_widget_host_view.h"
21 #include "ui/gfx/size.h"
22
23 namespace content {
24
25 BrowserPluginHostEmbedderRole::BrowserPluginHostEmbedderRole(
26 WebContentsImpl* web_contents, RenderViewHost* render_view_host)
27 : RenderViewHostObserver(render_view_host) {
28 delegate_.reset(new BrowserPluginHostEmbedderDelegate(web_contents));
29 // Listen to visibility changes so that an embedder hides its guests
30 // as well.
31 registrar_.Add(this,
32 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
33 Source<WebContents>(web_contents));
34 }
35
36 BrowserPluginHostEmbedderRole::~BrowserPluginHostEmbedderRole() {
37 }
38
39 bool BrowserPluginHostEmbedderRole::Send(IPC::Message* message) {
40 return RenderViewHostObserver::Send(message);
41 }
42
43 bool BrowserPluginHostEmbedderRole::OnMessageReceived(
44 const IPC::Message& message) {
45 bool handled = true;
46 IPC_BEGIN_MESSAGE_MAP(BrowserPluginHostEmbedderRole, message)
47 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest,
48 OnNavigateGuest);
49 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest)
50 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK);
51 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus);
52 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_HandleInputEvent,
53 OnHandleInputEvent(*static_cast<const IPC::SyncMessage*>(&message),
54 &handled))
55 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed,
56 OnPluginDestroyed);
57 IPC_MESSAGE_UNHANDLED(handled = false)
58 IPC_END_MESSAGE_MAP()
59 return handled;
60 }
61
62 void BrowserPluginHostEmbedderRole::NavigateGuest(int instance_id,
63 int64 frame_id,
64 const std::string& src,
65 const gfx::Size& size) {
66 delegate_->NavigateGuest(render_view_host(), instance_id, frame_id, src,
67 size);
68 }
69
70 void BrowserPluginHostEmbedderRole::OnResizeGuest(
71 int instance_id,
72 const BrowserPluginHostMsg_ResizeGuest_Params& params) {
73 TransportDIB* damage_buffer = NULL;
74 #if defined(OS_WIN)
75 // On Windows we need to duplicate the handle from the remote process
rjkroege 2012/08/22 21:57:38 need a . at end of setnence.
lazyboy 2012/08/23 00:45:22 Done.
76 HANDLE section;
77 DuplicateHandle(GetHandle(),
78 params.damage_buffer_id.handle,
79 GetCurrentProcess(),
80 &section,
81 STANDARD_RIGHTS_REQUIRED | FILE_MAP_READ | FILE_MAP_WRITE,
82 FALSE, 0);
83 damage_buffer = TransportDIB::Map(section);
84 #elif defined(OS_MACOSX)
85 // On OSX, the browser allocates all DIBs and keeps a file descriptor around
86 // for each.
87 damage_buffer = widget_helper_->MapTransportDIB(params.damage_buffer_id);
88 #elif defined(OS_ANDROID)
89 damage_buffer = TransportDIB::Map(params.damage_buffer_id);
90 #elif defined(OS_POSIX)
91 damage_buffer = TransportDIB::Map(params.damage_buffer_id.shmkey);
92 #endif // defined(OS_POSIX)
93 DCHECK(damage_buffer);
94 // TODO(fsamuel): Schedule this later so that we don't stall the embedder for
95 // too long.
96 delegate_->ResizeGuest(instance_id,
97 damage_buffer,
98 params.width,
99 params.height,
100 params.resize_pending,
101 params.scale_factor);
102 }
103
104 void BrowserPluginHostEmbedderRole::OnHandleInputEvent(
105 const IPC::SyncMessage& message,
106 bool* handled) {
107 *handled = true;
108 PickleIterator iter(message);
109
110 // TODO(fsamuel): This appears to be a monotonically increasing value.
rjkroege 2012/08/22 21:57:38 let's DCHECK that we believe it to be so.
lazyboy 2012/08/23 00:45:22 I have no idea abt this TODO, Fady is probably the
111 int instance_id = -1;
112 const char* guest_rect_data = NULL;
113 int guest_rect_data_length = -1;
114 const char* input_event_data = NULL;
115 int input_event_data_length = -1;
116 if (!iter.SkipBytes(4) ||
117 !message.ReadInt(&iter, &instance_id) ||
118 !message.ReadData(&iter, &guest_rect_data, &guest_rect_data_length) ||
119 !message.ReadData(&iter, &input_event_data, &input_event_data_length)) {
120 *handled = false;
121 return;
122 }
123 const gfx::Rect* guest_rect =
124 reinterpret_cast<const gfx::Rect*>(guest_rect_data);
125 const WebKit::WebInputEvent* input_event =
126 reinterpret_cast<const WebKit::WebInputEvent*>(input_event_data);
127 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
128 render_view_host());
129
130 // Convert the window coordinates into screen coordinates.
131 gfx::Rect guest_screen_rect(*guest_rect);
132 if (rvh->GetView())
133 guest_screen_rect.Offset(
134 rvh->GetView()->GetViewBounds().origin());
135
136 IPC::Message* reply_message =
137 IPC::SyncMessage::GenerateReply(&message);
138 delegate_->HandleInputEvent(instance_id, rvh, guest_screen_rect, *input_event,
139 reply_message);
140 }
141
142 void BrowserPluginHostEmbedderRole::OnNavigateGuest(int instance_id,
143 int64 frame_id,
144 const std::string& src,
145 const gfx::Size& size) {
146 delegate_->NavigateGuest(render_view_host(), instance_id, frame_id, src,
147 size);
148 }
149
150 void BrowserPluginHostEmbedderRole::OnUpdateRectACK(int instance_id,
151 int message_id,
152 const gfx::Size& size) {
153 delegate_->UpdateRectACK(instance_id, message_id, size);
154 }
155
156 void BrowserPluginHostEmbedderRole::OnSetFocus(int instance_id, bool focused) {
157 delegate_->SetFocus(instance_id, focused);
158 }
159
160 void BrowserPluginHostEmbedderRole::OnPluginDestroyed(int instance_id) {
161 delegate_->PluginDestroyed(instance_id);
162 }
163
164 void BrowserPluginHostEmbedderRole::Observe(
165 int type,
166 const NotificationSource& source,
167 const NotificationDetails& details) {
168 switch (type) {
169 case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: {
170 bool visible = *Details<bool>(details).ptr();
171 delegate_->WebContentsVisiblitlyChanged(visible);
172 break;
173 }
174 default:
175 NOTREACHED() << "Unexpected notification type: " << type;
176 }
177 }
178
179 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698