OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/browser_plugin/browser_plugin.h" | 5 #include "content/renderer/browser_plugin/browser_plugin.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 using blink::WebPoint; | 38 using blink::WebPoint; |
39 using blink::WebRect; | 39 using blink::WebRect; |
40 using blink::WebURL; | 40 using blink::WebURL; |
41 using blink::WebVector; | 41 using blink::WebVector; |
42 | 42 |
43 namespace content { | 43 namespace content { |
44 | 44 |
45 BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view, | 45 BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view, |
46 blink::WebFrame* frame, | 46 blink::WebFrame* frame, |
47 bool auto_navigate) | 47 bool auto_navigate) |
48 : guest_instance_id_(browser_plugin::kInstanceIDNone), | 48 : attached_(false), |
49 attached_(false), | 49 attach_pending_(false), |
50 render_view_(render_view->AsWeakPtr()), | 50 render_view_(render_view->AsWeakPtr()), |
51 render_view_routing_id_(render_view->GetRoutingID()), | 51 render_view_routing_id_(render_view->GetRoutingID()), |
52 container_(NULL), | 52 container_(NULL), |
53 paint_ack_received_(true), | 53 paint_ack_received_(true), |
54 last_device_scale_factor_(GetDeviceScaleFactor()), | 54 last_device_scale_factor_(GetDeviceScaleFactor()), |
55 sad_guest_(NULL), | 55 sad_guest_(NULL), |
56 guest_crashed_(false), | 56 guest_crashed_(false), |
57 content_window_routing_id_(MSG_ROUTING_NONE), | 57 content_window_routing_id_(MSG_ROUTING_NONE), |
58 plugin_focused_(false), | 58 plugin_focused_(false), |
59 visible_(true), | 59 visible_(true), |
60 auto_navigate_(auto_navigate), | 60 auto_navigate_(auto_navigate), |
61 mouse_locked_(false), | 61 mouse_locked_(false), |
62 browser_plugin_manager_(render_view->GetBrowserPluginManager()), | 62 browser_plugin_manager_(render_view->GetBrowserPluginManager()), |
| 63 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), |
63 weak_ptr_factory_(this) { | 64 weak_ptr_factory_(this) { |
64 } | 65 } |
65 | 66 |
66 BrowserPlugin::~BrowserPlugin() { | 67 BrowserPlugin::~BrowserPlugin() { |
67 // If the BrowserPlugin has never navigated then the browser process and | 68 browser_plugin_manager()->RemoveBrowserPlugin(browser_plugin_instance_id_); |
68 // BrowserPluginManager don't know about it and so there is nothing to do | 69 |
69 // here. | 70 if (!ready()) |
70 if (!HasGuestInstanceID()) | |
71 return; | 71 return; |
72 browser_plugin_manager()->RemoveBrowserPlugin(guest_instance_id_); | 72 |
73 browser_plugin_manager()->Send( | 73 browser_plugin_manager()->Send( |
74 new BrowserPluginHostMsg_PluginDestroyed(render_view_routing_id_, | 74 new BrowserPluginHostMsg_PluginDestroyed(render_view_routing_id_, |
75 guest_instance_id_)); | 75 browser_plugin_instance_id_)); |
76 } | 76 } |
77 | 77 |
78 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { | 78 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { |
79 bool handled = true; | 79 bool handled = true; |
80 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) | 80 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) |
| 81 IPC_MESSAGE_HANDLER(BrowserPluginMsg_Attach_ACK, OnAttachACK) |
81 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) | 82 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) |
82 IPC_MESSAGE_HANDLER(BrowserPluginMsg_Attach_ACK, OnAttachACK) | |
83 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) | 83 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, OnBuffersSwapped) |
84 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped, | 84 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped, |
85 OnCompositorFrameSwapped(message)) | 85 OnCompositorFrameSwapped(message)) |
86 IPC_MESSAGE_HANDLER(BrowserPluginMsg_CopyFromCompositingSurface, | 86 IPC_MESSAGE_HANDLER(BrowserPluginMsg_CopyFromCompositingSurface, |
87 OnCopyFromCompositingSurface) | 87 OnCopyFromCompositingSurface) |
88 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, | 88 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, |
89 OnGuestContentWindowReady) | 89 OnGuestContentWindowReady) |
90 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) | 90 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) |
91 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) | 91 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) |
92 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetMouseLock, OnSetMouseLock) | 92 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetMouseLock, OnSetMouseLock) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 137 |
138 return container()->element().hasAttribute( | 138 return container()->element().hasAttribute( |
139 blink::WebString::fromUTF8(attribute_name)); | 139 blink::WebString::fromUTF8(attribute_name)); |
140 } | 140 } |
141 | 141 |
142 bool BrowserPlugin::GetAllowTransparencyAttribute() const { | 142 bool BrowserPlugin::GetAllowTransparencyAttribute() const { |
143 return HasDOMAttribute(browser_plugin::kAttributeAllowTransparency); | 143 return HasDOMAttribute(browser_plugin::kAttributeAllowTransparency); |
144 } | 144 } |
145 | 145 |
146 void BrowserPlugin::ParseAllowTransparencyAttribute() { | 146 void BrowserPlugin::ParseAllowTransparencyAttribute() { |
147 if (!HasGuestInstanceID()) | 147 if (!ready()) |
148 return; | 148 return; |
149 | 149 |
150 bool opaque = !GetAllowTransparencyAttribute(); | 150 bool opaque = !GetAllowTransparencyAttribute(); |
151 | 151 |
152 if (compositing_helper_) | 152 if (compositing_helper_) |
153 compositing_helper_->SetContentsOpaque(opaque); | 153 compositing_helper_->SetContentsOpaque(opaque); |
154 | 154 |
155 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetContentsOpaque( | 155 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetContentsOpaque( |
156 render_view_routing_id_, | 156 render_view_routing_id_, |
157 guest_instance_id_, | 157 browser_plugin_instance_id_, |
158 opaque)); | 158 opaque)); |
159 } | 159 } |
160 | 160 |
161 void BrowserPlugin::Attach(int guest_instance_id, | 161 void BrowserPlugin::Attach() { |
162 scoped_ptr<base::DictionaryValue> extra_params) { | 162 if (ready()) { |
163 CHECK(guest_instance_id != browser_plugin::kInstanceIDNone); | 163 attached_ = false; |
164 | |
165 // If this BrowserPlugin is already attached to a guest, then kill the guest. | |
166 if (HasGuestInstanceID()) { | |
167 if (guest_instance_id == guest_instance_id_) | |
168 return; | |
169 guest_crashed_ = false; | 164 guest_crashed_ = false; |
170 EnableCompositing(false); | 165 EnableCompositing(false); |
171 if (compositing_helper_) { | 166 if (compositing_helper_) { |
172 compositing_helper_->OnContainerDestroy(); | 167 compositing_helper_->OnContainerDestroy(); |
173 compositing_helper_ = NULL; | 168 compositing_helper_ = NULL; |
174 } | 169 } |
175 browser_plugin_manager()->RemoveBrowserPlugin(guest_instance_id_); | |
176 browser_plugin_manager()->Send(new BrowserPluginHostMsg_PluginDestroyed( | |
177 render_view_routing_id_, guest_instance_id_)); | |
178 } | 170 } |
179 | 171 |
180 // This API may be called directly without setting the src attribute. | 172 // TODO(fsamuel): Add support for reattachment. |
181 // In that case, we need to make sure we don't allocate another instance ID. | |
182 guest_instance_id_ = guest_instance_id; | |
183 browser_plugin_manager()->AddBrowserPlugin(guest_instance_id, this); | |
184 | |
185 BrowserPluginHostMsg_Attach_Params attach_params; | 173 BrowserPluginHostMsg_Attach_Params attach_params; |
186 attach_params.focused = ShouldGuestBeFocused(); | 174 attach_params.focused = ShouldGuestBeFocused(); |
187 attach_params.visible = visible_; | 175 attach_params.visible = visible_; |
188 attach_params.opaque = !GetAllowTransparencyAttribute(); | 176 attach_params.opaque = !GetAllowTransparencyAttribute(); |
189 attach_params.origin = plugin_rect().origin(); | 177 attach_params.origin = plugin_rect().origin(); |
190 GetSizeParams(&attach_params.resize_guest_params, false); | 178 GetSizeParams(&attach_params.resize_guest_params, false); |
191 | 179 |
192 browser_plugin_manager()->Send( | 180 browser_plugin_manager()->Send(new BrowserPluginHostMsg_Attach( |
193 new BrowserPluginHostMsg_Attach(render_view_routing_id_, | 181 render_view_routing_id_, |
194 guest_instance_id_, attach_params, | 182 browser_plugin_instance_id_, |
195 *extra_params)); | 183 attach_params)); |
| 184 |
| 185 attach_pending_ = true; |
196 } | 186 } |
197 | 187 |
198 void BrowserPlugin::DidCommitCompositorFrame() { | 188 void BrowserPlugin::DidCommitCompositorFrame() { |
199 if (compositing_helper_.get()) | 189 if (compositing_helper_.get()) |
200 compositing_helper_->DidCommitCompositorFrame(); | 190 compositing_helper_->DidCommitCompositorFrame(); |
201 } | 191 } |
202 | 192 |
203 void BrowserPlugin::OnAdvanceFocus(int guest_instance_id, bool reverse) { | 193 void BrowserPlugin::OnAdvanceFocus(int browser_plugin_instance_id, |
| 194 bool reverse) { |
204 DCHECK(render_view_.get()); | 195 DCHECK(render_view_.get()); |
205 render_view_->GetWebView()->advanceFocus(reverse); | 196 render_view_->GetWebView()->advanceFocus(reverse); |
206 } | 197 } |
207 | 198 |
208 void BrowserPlugin::OnAttachACK(int guest_instance_id) { | 199 void BrowserPlugin::OnAttachACK(int browser_plugin_instance_id) { |
| 200 DCHECK(!attached()); |
209 attached_ = true; | 201 attached_ = true; |
| 202 attach_pending_ = false; |
210 } | 203 } |
211 | 204 |
212 void BrowserPlugin::OnBuffersSwapped( | 205 void BrowserPlugin::OnBuffersSwapped( |
213 int instance_id, | 206 int instance_id, |
214 const FrameMsg_BuffersSwapped_Params& params) { | 207 const FrameMsg_BuffersSwapped_Params& params) { |
215 EnableCompositing(true); | 208 EnableCompositing(true); |
216 | 209 |
217 compositing_helper_->OnBuffersSwapped(params.size, | 210 compositing_helper_->OnBuffersSwapped(params.size, |
218 params.mailbox, | 211 params.mailbox, |
219 params.gpu_route_id, | 212 params.gpu_route_id, |
220 params.gpu_host_id, | 213 params.gpu_host_id, |
221 GetDeviceScaleFactor()); | 214 GetDeviceScaleFactor()); |
222 } | 215 } |
223 | 216 |
224 void BrowserPlugin::OnCompositorFrameSwapped(const IPC::Message& message) { | 217 void BrowserPlugin::OnCompositorFrameSwapped(const IPC::Message& message) { |
225 BrowserPluginMsg_CompositorFrameSwapped::Param param; | 218 BrowserPluginMsg_CompositorFrameSwapped::Param param; |
226 if (!BrowserPluginMsg_CompositorFrameSwapped::Read(&message, ¶m)) | 219 if (!BrowserPluginMsg_CompositorFrameSwapped::Read(&message, ¶m)) |
227 return; | 220 return; |
228 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); | 221 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
229 param.b.frame.AssignTo(frame.get()); | 222 param.b.frame.AssignTo(frame.get()); |
230 | 223 |
231 EnableCompositing(true); | 224 EnableCompositing(true); |
232 compositing_helper_->OnCompositorFrameSwapped(frame.Pass(), | 225 compositing_helper_->OnCompositorFrameSwapped(frame.Pass(), |
233 param.b.producing_route_id, | 226 param.b.producing_route_id, |
234 param.b.output_surface_id, | 227 param.b.output_surface_id, |
235 param.b.producing_host_id, | 228 param.b.producing_host_id, |
236 param.b.shared_memory_handle); | 229 param.b.shared_memory_handle); |
237 } | 230 } |
238 | 231 |
239 void BrowserPlugin::OnCopyFromCompositingSurface(int guest_instance_id, | 232 void BrowserPlugin::OnCopyFromCompositingSurface(int browser_plugin_instance_id, |
240 int request_id, | 233 int request_id, |
241 gfx::Rect source_rect, | 234 gfx::Rect source_rect, |
242 gfx::Size dest_size) { | 235 gfx::Size dest_size) { |
243 if (!compositing_helper_) { | 236 if (!compositing_helper_) { |
244 browser_plugin_manager()->Send( | 237 browser_plugin_manager()->Send( |
245 new BrowserPluginHostMsg_CopyFromCompositingSurfaceAck( | 238 new BrowserPluginHostMsg_CopyFromCompositingSurfaceAck( |
246 render_view_routing_id_, | 239 render_view_routing_id_, |
247 guest_instance_id_, | 240 browser_plugin_instance_id_, |
248 request_id, | 241 request_id, |
249 SkBitmap())); | 242 SkBitmap())); |
250 return; | 243 return; |
251 } | 244 } |
252 compositing_helper_->CopyFromCompositingSurface(request_id, source_rect, | 245 compositing_helper_->CopyFromCompositingSurface(request_id, source_rect, |
253 dest_size); | 246 dest_size); |
254 } | 247 } |
255 | 248 |
256 void BrowserPlugin::OnGuestContentWindowReady(int guest_instance_id, | 249 void BrowserPlugin::OnGuestContentWindowReady(int browser_plugin_instance_id, |
257 int content_window_routing_id) { | 250 int content_window_routing_id) { |
258 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); | 251 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); |
259 content_window_routing_id_ = content_window_routing_id; | 252 content_window_routing_id_ = content_window_routing_id; |
260 } | 253 } |
261 | 254 |
262 void BrowserPlugin::OnGuestGone(int guest_instance_id) { | 255 void BrowserPlugin::OnGuestGone(int browser_plugin_instance_id) { |
263 guest_crashed_ = true; | 256 guest_crashed_ = true; |
264 | 257 |
265 // Turn off compositing so we can display the sad graphic. Changes to | 258 // Turn off compositing so we can display the sad graphic. Changes to |
266 // compositing state will show up at a later time after a layout and commit. | 259 // compositing state will show up at a later time after a layout and commit. |
267 EnableCompositing(false); | 260 EnableCompositing(false); |
268 | 261 |
269 // Queue up showing the sad graphic to give content embedders an opportunity | 262 // Queue up showing the sad graphic to give content embedders an opportunity |
270 // to fire their listeners and potentially overlay the webview with custom | 263 // to fire their listeners and potentially overlay the webview with custom |
271 // behavior. If the BrowserPlugin is destroyed in the meantime, then the | 264 // behavior. If the BrowserPlugin is destroyed in the meantime, then the |
272 // task will not be executed. | 265 // task will not be executed. |
273 base::MessageLoop::current()->PostTask( | 266 base::MessageLoop::current()->PostTask( |
274 FROM_HERE, | 267 FROM_HERE, |
275 base::Bind(&BrowserPlugin::ShowSadGraphic, | 268 base::Bind(&BrowserPlugin::ShowSadGraphic, |
276 weak_ptr_factory_.GetWeakPtr())); | 269 weak_ptr_factory_.GetWeakPtr())); |
277 } | 270 } |
278 | 271 |
279 void BrowserPlugin::OnSetCursor(int guest_instance_id, | 272 void BrowserPlugin::OnSetCursor(int browser_plugin_instance_id, |
280 const WebCursor& cursor) { | 273 const WebCursor& cursor) { |
281 cursor_ = cursor; | 274 cursor_ = cursor; |
282 } | 275 } |
283 | 276 |
284 void BrowserPlugin::OnSetMouseLock(int guest_instance_id, | 277 void BrowserPlugin::OnSetMouseLock(int browser_plugin_instance_id, |
285 bool enable) { | 278 bool enable) { |
286 if (enable) { | 279 if (enable) { |
287 if (mouse_locked_) | 280 if (mouse_locked_) |
288 return; | 281 return; |
289 render_view_->mouse_lock_dispatcher()->LockMouse(this); | 282 render_view_->mouse_lock_dispatcher()->LockMouse(this); |
290 } else { | 283 } else { |
291 if (!mouse_locked_) { | 284 if (!mouse_locked_) { |
292 OnLockMouseACK(false); | 285 OnLockMouseACK(false); |
293 return; | 286 return; |
294 } | 287 } |
295 render_view_->mouse_lock_dispatcher()->UnlockMouse(this); | 288 render_view_->mouse_lock_dispatcher()->UnlockMouse(this); |
296 } | 289 } |
297 } | 290 } |
298 | 291 |
299 void BrowserPlugin::OnShouldAcceptTouchEvents(int guest_instance_id, | 292 void BrowserPlugin::OnShouldAcceptTouchEvents(int browser_plugin_instance_id, |
300 bool accept) { | 293 bool accept) { |
301 if (container()) { | 294 if (container()) { |
302 container()->requestTouchEventType(accept ? | 295 container()->requestTouchEventType( |
303 blink::WebPluginContainer::TouchEventRequestTypeRaw : | 296 accept ? WebPluginContainer::TouchEventRequestTypeRaw |
304 blink::WebPluginContainer::TouchEventRequestTypeNone); | 297 : WebPluginContainer::TouchEventRequestTypeNone); |
305 } | 298 } |
306 } | 299 } |
307 | 300 |
308 void BrowserPlugin::OnUpdateRect( | 301 void BrowserPlugin::OnUpdateRect( |
309 int guest_instance_id, | 302 int browser_plugin_instance_id, |
310 const BrowserPluginMsg_UpdateRect_Params& params) { | 303 const BrowserPluginMsg_UpdateRect_Params& params) { |
311 // Note that there is no need to send ACK for this message. | 304 // Note that there is no need to send ACK for this message. |
312 // If the guest has updated pixels then it is no longer crashed. | 305 // If the guest has updated pixels then it is no longer crashed. |
313 guest_crashed_ = false; | 306 guest_crashed_ = false; |
314 | 307 |
315 // We receive a resize ACK in regular mode, but not in autosize. | 308 // We receive a resize ACK in regular mode, but not in autosize. |
316 // In Compositing mode, we need to do it here so we can continue sending | 309 // In Compositing mode, we need to do it here so we can continue sending |
317 // resize messages when needed. | 310 // resize messages when needed. |
318 if (params.is_resize_ack) | 311 if (params.is_resize_ack) |
319 paint_ack_received_ = true; | 312 paint_ack_received_ = true; |
320 | 313 |
321 if (params.view_size.width() == width() && | 314 if (params.view_size.width() == width() && |
322 params.view_size.height() == height()) { | 315 params.view_size.height() == height()) { |
323 return; | 316 return; |
324 } | 317 } |
325 | 318 |
326 BrowserPluginHostMsg_ResizeGuest_Params resize_params; | 319 BrowserPluginHostMsg_ResizeGuest_Params resize_params; |
327 PopulateResizeGuestParameters(&resize_params, plugin_size(), false); | 320 PopulateResizeGuestParameters(&resize_params, plugin_size(), false); |
328 paint_ack_received_ = false; | 321 paint_ack_received_ = false; |
329 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 322 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
330 render_view_routing_id_, | 323 render_view_routing_id_, |
331 guest_instance_id_, | 324 browser_plugin_instance_id_, |
332 resize_params)); | 325 resize_params)); |
333 } | 326 } |
334 | 327 |
335 NPObject* BrowserPlugin::GetContentWindow() const { | 328 NPObject* BrowserPlugin::GetContentWindow() const { |
336 if (content_window_routing_id_ == MSG_ROUTING_NONE) | 329 if (content_window_routing_id_ == MSG_ROUTING_NONE) |
337 return NULL; | 330 return NULL; |
338 RenderViewImpl* guest_render_view = RenderViewImpl::FromRoutingID( | 331 RenderViewImpl* guest_render_view = RenderViewImpl::FromRoutingID( |
339 content_window_routing_id_); | 332 content_window_routing_id_); |
340 if (!guest_render_view) | 333 if (!guest_render_view) |
341 return NULL; | 334 return NULL; |
342 blink::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); | 335 blink::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); |
343 return guest_frame->windowObject(); | 336 return guest_frame->windowObject(); |
344 } | 337 } |
345 | 338 |
346 bool BrowserPlugin::HasGuestInstanceID() const { | |
347 return guest_instance_id_ != browser_plugin::kInstanceIDNone; | |
348 } | |
349 | |
350 void BrowserPlugin::ShowSadGraphic() { | 339 void BrowserPlugin::ShowSadGraphic() { |
351 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | 340 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
352 // NULL so we shouldn't attempt to access it. | 341 // NULL so we shouldn't attempt to access it. |
353 if (container_) | 342 if (container_) |
354 container_->invalidate(); | 343 container_->invalidate(); |
355 } | 344 } |
356 | 345 |
357 float BrowserPlugin::GetDeviceScaleFactor() const { | 346 float BrowserPlugin::GetDeviceScaleFactor() const { |
358 if (!render_view_.get()) | 347 if (!render_view_.get()) |
359 return 1.0f; | 348 return 1.0f; |
360 return render_view_->GetWebView()->deviceScaleFactor(); | 349 return render_view_->GetWebView()->deviceScaleFactor(); |
361 } | 350 } |
362 | 351 |
363 void BrowserPlugin::UpdateDeviceScaleFactor(float device_scale_factor) { | 352 void BrowserPlugin::UpdateDeviceScaleFactor(float device_scale_factor) { |
364 if (last_device_scale_factor_ == device_scale_factor || !paint_ack_received_) | 353 if (last_device_scale_factor_ == device_scale_factor || !paint_ack_received_) |
365 return; | 354 return; |
366 | 355 |
367 BrowserPluginHostMsg_ResizeGuest_Params params; | 356 BrowserPluginHostMsg_ResizeGuest_Params params; |
368 PopulateResizeGuestParameters(¶ms, plugin_size(), true); | 357 PopulateResizeGuestParameters(¶ms, plugin_size(), true); |
369 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 358 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
370 render_view_routing_id_, | 359 render_view_routing_id_, |
371 guest_instance_id_, | 360 browser_plugin_instance_id_, |
372 params)); | 361 params)); |
373 } | 362 } |
374 | 363 |
375 void BrowserPlugin::UpdateGuestFocusState() { | 364 void BrowserPlugin::UpdateGuestFocusState() { |
376 if (!HasGuestInstanceID()) | 365 if (!ready()) |
377 return; | 366 return; |
378 bool should_be_focused = ShouldGuestBeFocused(); | 367 bool should_be_focused = ShouldGuestBeFocused(); |
379 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( | 368 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetFocus( |
380 render_view_routing_id_, | 369 render_view_routing_id_, |
381 guest_instance_id_, | 370 browser_plugin_instance_id_, |
382 should_be_focused)); | 371 should_be_focused)); |
383 } | 372 } |
384 | 373 |
385 bool BrowserPlugin::ShouldGuestBeFocused() const { | 374 bool BrowserPlugin::ShouldGuestBeFocused() const { |
386 bool embedder_focused = false; | 375 bool embedder_focused = false; |
387 if (render_view_.get()) | 376 if (render_view_.get()) |
388 embedder_focused = render_view_->has_focus(); | 377 embedder_focused = render_view_->has_focus(); |
389 return plugin_focused_ && embedder_focused; | 378 return plugin_focused_ && embedder_focused; |
390 } | 379 } |
391 | 380 |
392 blink::WebPluginContainer* BrowserPlugin::container() const { | 381 WebPluginContainer* BrowserPlugin::container() const { |
393 return container_; | 382 return container_; |
394 } | 383 } |
395 | 384 |
396 bool BrowserPlugin::initialize(WebPluginContainer* container) { | 385 bool BrowserPlugin::initialize(WebPluginContainer* container) { |
397 if (!container) | 386 if (!container) |
398 return false; | 387 return false; |
399 | 388 |
400 // Tell |container| to allow this plugin to use script objects. | 389 // Tell |container| to allow this plugin to use script objects. |
401 npp_.reset(new NPP_t); | 390 npp_.reset(new NPP_t); |
402 container->allowScriptObjects(); | 391 container->allowScriptObjects(); |
403 | 392 |
404 bindings_.reset(new BrowserPluginBindings(this)); | 393 bindings_.reset(new BrowserPluginBindings(this)); |
405 container_ = container; | 394 container_ = container; |
406 container_->setWantsWheelEvents(true); | 395 container_->setWantsWheelEvents(true); |
407 // This is a way to notify observers of our attributes that we have the | 396 |
408 // bindings ready. This also means that this plugin is available in render | 397 // This is a way to notify observers of our attributes that this plugin is |
409 // tree. | 398 // available in render tree. |
410 UpdateDOMAttribute("internalbindings", "true"); | 399 browser_plugin_instance_id_ = browser_plugin_manager()->GetNextInstanceID(); |
| 400 UpdateDOMAttribute("internalinstanceid", |
| 401 base::IntToString(browser_plugin_instance_id_)); |
| 402 |
| 403 browser_plugin_manager()->AddBrowserPlugin(browser_plugin_instance_id_, this); |
411 return true; | 404 return true; |
412 } | 405 } |
413 | 406 |
414 void BrowserPlugin::EnableCompositing(bool enable) { | 407 void BrowserPlugin::EnableCompositing(bool enable) { |
415 bool enabled = !!compositing_helper_; | 408 bool enabled = !!compositing_helper_; |
416 if (enabled == enable) | 409 if (enabled == enable) |
417 return; | 410 return; |
418 | 411 |
419 if (enable) { | 412 if (enable) { |
420 DCHECK(!compositing_helper_.get()); | 413 DCHECK(!compositing_helper_.get()); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 SkPaint paint; | 497 SkPaint paint; |
505 paint.setStyle(SkPaint::kFill_Style); | 498 paint.setStyle(SkPaint::kFill_Style); |
506 paint.setColor(guest_crashed_ ? SK_ColorBLACK : SK_ColorWHITE); | 499 paint.setColor(guest_crashed_ ? SK_ColorBLACK : SK_ColorWHITE); |
507 canvas->drawRect(image_data_rect, paint); | 500 canvas->drawRect(image_data_rect, paint); |
508 } | 501 } |
509 | 502 |
510 // static | 503 // static |
511 bool BrowserPlugin::ShouldForwardToBrowserPlugin( | 504 bool BrowserPlugin::ShouldForwardToBrowserPlugin( |
512 const IPC::Message& message) { | 505 const IPC::Message& message) { |
513 switch (message.type()) { | 506 switch (message.type()) { |
| 507 case BrowserPluginMsg_Attach_ACK::ID: |
514 case BrowserPluginMsg_AdvanceFocus::ID: | 508 case BrowserPluginMsg_AdvanceFocus::ID: |
515 case BrowserPluginMsg_Attach_ACK::ID: | |
516 case BrowserPluginMsg_BuffersSwapped::ID: | 509 case BrowserPluginMsg_BuffersSwapped::ID: |
517 case BrowserPluginMsg_CompositorFrameSwapped::ID: | 510 case BrowserPluginMsg_CompositorFrameSwapped::ID: |
518 case BrowserPluginMsg_CopyFromCompositingSurface::ID: | 511 case BrowserPluginMsg_CopyFromCompositingSurface::ID: |
519 case BrowserPluginMsg_GuestContentWindowReady::ID: | 512 case BrowserPluginMsg_GuestContentWindowReady::ID: |
520 case BrowserPluginMsg_GuestGone::ID: | 513 case BrowserPluginMsg_GuestGone::ID: |
521 case BrowserPluginMsg_SetCursor::ID: | 514 case BrowserPluginMsg_SetCursor::ID: |
522 case BrowserPluginMsg_SetMouseLock::ID: | 515 case BrowserPluginMsg_SetMouseLock::ID: |
523 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: | 516 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: |
524 case BrowserPluginMsg_UpdateRect::ID: | 517 case BrowserPluginMsg_UpdateRect::ID: |
525 return true; | 518 return true; |
(...skipping 17 matching lines...) Expand all Loading... |
543 // In AutoSize mode, guests don't care when the BrowserPlugin container is | 536 // In AutoSize mode, guests don't care when the BrowserPlugin container is |
544 // resized. If |!paint_ack_received_|, then we are still waiting on a | 537 // resized. If |!paint_ack_received_|, then we are still waiting on a |
545 // previous resize to be ACK'ed and so we don't issue additional resizes | 538 // previous resize to be ACK'ed and so we don't issue additional resizes |
546 // until the previous one is ACK'ed. | 539 // until the previous one is ACK'ed. |
547 // TODO(mthiesse): Assess the performance of calling GetAutoSizeAttribute() on | 540 // TODO(mthiesse): Assess the performance of calling GetAutoSizeAttribute() on |
548 // resize. | 541 // resize. |
549 if (!paint_ack_received_ || | 542 if (!paint_ack_received_ || |
550 (old_width == window_rect.width && old_height == window_rect.height)) { | 543 (old_width == window_rect.width && old_height == window_rect.height)) { |
551 // Let the browser know about the updated view rect. | 544 // Let the browser know about the updated view rect. |
552 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateGeometry( | 545 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UpdateGeometry( |
553 render_view_routing_id_, guest_instance_id_, plugin_rect_)); | 546 render_view_routing_id_, browser_plugin_instance_id_, plugin_rect_)); |
554 return; | 547 return; |
555 } | 548 } |
556 | 549 |
557 BrowserPluginHostMsg_ResizeGuest_Params params; | 550 BrowserPluginHostMsg_ResizeGuest_Params params; |
558 PopulateResizeGuestParameters(¶ms, plugin_size(), false); | 551 PopulateResizeGuestParameters(¶ms, plugin_size(), false); |
559 paint_ack_received_ = false; | 552 paint_ack_received_ = false; |
560 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( | 553 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ResizeGuest( |
561 render_view_routing_id_, | 554 render_view_routing_id_, |
562 guest_instance_id_, | 555 browser_plugin_instance_id_, |
563 params)); | 556 params)); |
564 } | 557 } |
565 | 558 |
566 void BrowserPlugin::PopulateResizeGuestParameters( | 559 void BrowserPlugin::PopulateResizeGuestParameters( |
567 BrowserPluginHostMsg_ResizeGuest_Params* params, | 560 BrowserPluginHostMsg_ResizeGuest_Params* params, |
568 const gfx::Size& view_size, | 561 const gfx::Size& view_size, |
569 bool needs_repaint) { | 562 bool needs_repaint) { |
570 params->size_changed = true; | 563 params->size_changed = true; |
571 params->view_size = view_size; | 564 params->view_size = view_size; |
572 params->repaint = needs_repaint; | 565 params->repaint = needs_repaint; |
(...skipping 17 matching lines...) Expand all Loading... |
590 void BrowserPlugin::updateFocus(bool focused) { | 583 void BrowserPlugin::updateFocus(bool focused) { |
591 plugin_focused_ = focused; | 584 plugin_focused_ = focused; |
592 UpdateGuestFocusState(); | 585 UpdateGuestFocusState(); |
593 } | 586 } |
594 | 587 |
595 void BrowserPlugin::updateVisibility(bool visible) { | 588 void BrowserPlugin::updateVisibility(bool visible) { |
596 if (visible_ == visible) | 589 if (visible_ == visible) |
597 return; | 590 return; |
598 | 591 |
599 visible_ = visible; | 592 visible_ = visible; |
600 if (!HasGuestInstanceID()) | 593 if (!ready()) |
601 return; | 594 return; |
602 | 595 |
603 if (compositing_helper_.get()) | 596 if (compositing_helper_.get()) |
604 compositing_helper_->UpdateVisibility(visible); | 597 compositing_helper_->UpdateVisibility(visible); |
605 | 598 |
606 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetVisibility( | 599 browser_plugin_manager()->Send(new BrowserPluginHostMsg_SetVisibility( |
607 render_view_routing_id_, | 600 render_view_routing_id_, |
608 guest_instance_id_, | 601 browser_plugin_instance_id_, |
609 visible)); | 602 visible)); |
610 } | 603 } |
611 | 604 |
612 bool BrowserPlugin::acceptsInputEvents() { | 605 bool BrowserPlugin::acceptsInputEvents() { |
613 return true; | 606 return true; |
614 } | 607 } |
615 | 608 |
616 bool BrowserPlugin::handleInputEvent(const blink::WebInputEvent& event, | 609 bool BrowserPlugin::handleInputEvent(const blink::WebInputEvent& event, |
617 blink::WebCursorInfo& cursor_info) { | 610 blink::WebCursorInfo& cursor_info) { |
618 if (guest_crashed_ || !HasGuestInstanceID()) | 611 if (guest_crashed_ || !ready()) |
619 return false; | 612 return false; |
620 | 613 |
621 if (event.type == blink::WebInputEvent::ContextMenu) | 614 if (event.type == blink::WebInputEvent::ContextMenu) |
622 return true; | 615 return true; |
623 | 616 |
624 const blink::WebInputEvent* modified_event = &event; | 617 const blink::WebInputEvent* modified_event = &event; |
625 scoped_ptr<blink::WebTouchEvent> touch_event; | 618 scoped_ptr<blink::WebTouchEvent> touch_event; |
626 if (blink::WebInputEvent::isTouchEventType(event.type)) { | 619 if (blink::WebInputEvent::isTouchEventType(event.type)) { |
627 const blink::WebTouchEvent* orig_touch_event = | 620 const blink::WebTouchEvent* orig_touch_event = |
628 static_cast<const blink::WebTouchEvent*>(&event); | 621 static_cast<const blink::WebTouchEvent*>(&event); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 } | 655 } |
663 } | 656 } |
664 modified_event = touch_event.get(); | 657 modified_event = touch_event.get(); |
665 } | 658 } |
666 | 659 |
667 if (blink::WebInputEvent::isKeyboardEventType(event.type) && | 660 if (blink::WebInputEvent::isKeyboardEventType(event.type) && |
668 !edit_commands_.empty()) { | 661 !edit_commands_.empty()) { |
669 browser_plugin_manager()->Send( | 662 browser_plugin_manager()->Send( |
670 new BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent( | 663 new BrowserPluginHostMsg_SetEditCommandsForNextKeyEvent( |
671 render_view_routing_id_, | 664 render_view_routing_id_, |
672 guest_instance_id_, | 665 browser_plugin_instance_id_, |
673 edit_commands_)); | 666 edit_commands_)); |
674 edit_commands_.clear(); | 667 edit_commands_.clear(); |
675 } | 668 } |
676 | 669 |
677 browser_plugin_manager()->Send( | 670 browser_plugin_manager()->Send( |
678 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 671 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
679 guest_instance_id_, | 672 browser_plugin_instance_id_, |
680 plugin_rect_, | 673 plugin_rect_, |
681 modified_event)); | 674 modified_event)); |
682 GetWebKitCursorInfo(cursor_, &cursor_info); | 675 GetWebKitCursorInfo(cursor_, &cursor_info); |
683 return true; | 676 return true; |
684 } | 677 } |
685 | 678 |
686 bool BrowserPlugin::handleDragStatusUpdate(blink::WebDragStatus drag_status, | 679 bool BrowserPlugin::handleDragStatusUpdate(blink::WebDragStatus drag_status, |
687 const blink::WebDragData& drag_data, | 680 const blink::WebDragData& drag_data, |
688 blink::WebDragOperationsMask mask, | 681 blink::WebDragOperationsMask mask, |
689 const blink::WebPoint& position, | 682 const blink::WebPoint& position, |
690 const blink::WebPoint& screen) { | 683 const blink::WebPoint& screen) { |
691 if (guest_crashed_ || !HasGuestInstanceID()) | 684 if (guest_crashed_ || !ready()) |
692 return false; | 685 return false; |
693 browser_plugin_manager()->Send( | 686 browser_plugin_manager()->Send( |
694 new BrowserPluginHostMsg_DragStatusUpdate( | 687 new BrowserPluginHostMsg_DragStatusUpdate( |
695 render_view_routing_id_, | 688 render_view_routing_id_, |
696 guest_instance_id_, | 689 browser_plugin_instance_id_, |
697 drag_status, | 690 drag_status, |
698 DropDataBuilder::Build(drag_data), | 691 DropDataBuilder::Build(drag_data), |
699 mask, | 692 mask, |
700 position)); | 693 position)); |
701 return true; | 694 return true; |
702 } | 695 } |
703 | 696 |
704 void BrowserPlugin::didReceiveResponse( | 697 void BrowserPlugin::didReceiveResponse( |
705 const blink::WebURLResponse& response) { | 698 const blink::WebURLResponse& response) { |
706 } | 699 } |
(...skipping 21 matching lines...) Expand all Loading... |
728 | 721 |
729 void BrowserPlugin::didFailLoadingFrameRequest( | 722 void BrowserPlugin::didFailLoadingFrameRequest( |
730 const blink::WebURL& url, | 723 const blink::WebURL& url, |
731 void* notify_data, | 724 void* notify_data, |
732 const blink::WebURLError& error) { | 725 const blink::WebURLError& error) { |
733 } | 726 } |
734 | 727 |
735 bool BrowserPlugin::executeEditCommand(const blink::WebString& name) { | 728 bool BrowserPlugin::executeEditCommand(const blink::WebString& name) { |
736 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ExecuteEditCommand( | 729 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ExecuteEditCommand( |
737 render_view_routing_id_, | 730 render_view_routing_id_, |
738 guest_instance_id_, | 731 browser_plugin_instance_id_, |
739 name.utf8())); | 732 name.utf8())); |
740 | 733 |
741 // BrowserPlugin swallows edit commands. | 734 // BrowserPlugin swallows edit commands. |
742 return true; | 735 return true; |
743 } | 736 } |
744 | 737 |
745 bool BrowserPlugin::executeEditCommand(const blink::WebString& name, | 738 bool BrowserPlugin::executeEditCommand(const blink::WebString& name, |
746 const blink::WebString& value) { | 739 const blink::WebString& value) { |
747 edit_commands_.push_back(EditCommand(name.utf8(), value.utf8())); | 740 edit_commands_.push_back(EditCommand(name.utf8(), value.utf8())); |
748 // BrowserPlugin swallows edit commands. | 741 // BrowserPlugin swallows edit commands. |
749 return true; | 742 return true; |
750 } | 743 } |
751 | 744 |
752 bool BrowserPlugin::setComposition( | 745 bool BrowserPlugin::setComposition( |
753 const blink::WebString& text, | 746 const blink::WebString& text, |
754 const blink::WebVector<blink::WebCompositionUnderline>& underlines, | 747 const blink::WebVector<blink::WebCompositionUnderline>& underlines, |
755 int selectionStart, | 748 int selectionStart, |
756 int selectionEnd) { | 749 int selectionEnd) { |
757 if (!HasGuestInstanceID()) | 750 if (!ready()) |
758 return false; | 751 return false; |
759 std::vector<blink::WebCompositionUnderline> std_underlines; | 752 std::vector<blink::WebCompositionUnderline> std_underlines; |
760 for (size_t i = 0; i < underlines.size(); ++i) { | 753 for (size_t i = 0; i < underlines.size(); ++i) { |
761 std_underlines.push_back(underlines[i]); | 754 std_underlines.push_back(underlines[i]); |
762 } | 755 } |
763 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ImeSetComposition( | 756 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ImeSetComposition( |
764 render_view_routing_id_, | 757 render_view_routing_id_, |
765 guest_instance_id_, | 758 browser_plugin_instance_id_, |
766 text.utf8(), | 759 text.utf8(), |
767 std_underlines, | 760 std_underlines, |
768 selectionStart, | 761 selectionStart, |
769 selectionEnd)); | 762 selectionEnd)); |
770 // TODO(kochi): This assumes the IPC handling always succeeds. | 763 // TODO(kochi): This assumes the IPC handling always succeeds. |
771 return true; | 764 return true; |
772 } | 765 } |
773 | 766 |
774 bool BrowserPlugin::confirmComposition( | 767 bool BrowserPlugin::confirmComposition( |
775 const blink::WebString& text, | 768 const blink::WebString& text, |
776 blink::WebWidget::ConfirmCompositionBehavior selectionBehavior) { | 769 blink::WebWidget::ConfirmCompositionBehavior selectionBehavior) { |
777 if (!HasGuestInstanceID()) | 770 if (!ready()) |
778 return false; | 771 return false; |
779 bool keep_selection = (selectionBehavior == blink::WebWidget::KeepSelection); | 772 bool keep_selection = (selectionBehavior == blink::WebWidget::KeepSelection); |
780 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ImeConfirmComposition( | 773 browser_plugin_manager()->Send(new BrowserPluginHostMsg_ImeConfirmComposition( |
781 render_view_routing_id_, | 774 render_view_routing_id_, |
782 guest_instance_id_, | 775 browser_plugin_instance_id_, |
783 text.utf8(), | 776 text.utf8(), |
784 keep_selection)); | 777 keep_selection)); |
785 // TODO(kochi): This assumes the IPC handling always succeeds. | 778 // TODO(kochi): This assumes the IPC handling always succeeds. |
786 return true; | 779 return true; |
787 } | 780 } |
788 | 781 |
789 void BrowserPlugin::extendSelectionAndDelete(int before, int after) { | 782 void BrowserPlugin::extendSelectionAndDelete(int before, int after) { |
790 if (!HasGuestInstanceID()) | 783 if (!ready()) |
791 return; | 784 return; |
792 browser_plugin_manager()->Send( | 785 browser_plugin_manager()->Send( |
793 new BrowserPluginHostMsg_ExtendSelectionAndDelete( | 786 new BrowserPluginHostMsg_ExtendSelectionAndDelete( |
794 render_view_routing_id_, | 787 render_view_routing_id_, |
795 guest_instance_id_, | 788 browser_plugin_instance_id_, |
796 before, | 789 before, |
797 after)); | 790 after)); |
798 } | 791 } |
799 | 792 |
800 void BrowserPlugin::OnLockMouseACK(bool succeeded) { | 793 void BrowserPlugin::OnLockMouseACK(bool succeeded) { |
801 mouse_locked_ = succeeded; | 794 mouse_locked_ = succeeded; |
802 browser_plugin_manager()->Send(new BrowserPluginHostMsg_LockMouse_ACK( | 795 browser_plugin_manager()->Send(new BrowserPluginHostMsg_LockMouse_ACK( |
803 render_view_routing_id_, | 796 render_view_routing_id_, |
804 guest_instance_id_, | 797 browser_plugin_instance_id_, |
805 succeeded)); | 798 succeeded)); |
806 } | 799 } |
807 | 800 |
808 void BrowserPlugin::OnMouseLockLost() { | 801 void BrowserPlugin::OnMouseLockLost() { |
809 mouse_locked_ = false; | 802 mouse_locked_ = false; |
810 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UnlockMouse_ACK( | 803 browser_plugin_manager()->Send(new BrowserPluginHostMsg_UnlockMouse_ACK( |
811 render_view_routing_id_, | 804 render_view_routing_id_, |
812 guest_instance_id_)); | 805 browser_plugin_instance_id_)); |
813 } | 806 } |
814 | 807 |
815 bool BrowserPlugin::HandleMouseLockedInputEvent( | 808 bool BrowserPlugin::HandleMouseLockedInputEvent( |
816 const blink::WebMouseEvent& event) { | 809 const blink::WebMouseEvent& event) { |
817 browser_plugin_manager()->Send( | 810 browser_plugin_manager()->Send( |
818 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 811 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
819 guest_instance_id_, | 812 browser_plugin_instance_id_, |
820 plugin_rect_, | 813 plugin_rect_, |
821 &event)); | 814 &event)); |
822 return true; | 815 return true; |
823 } | 816 } |
824 | 817 |
825 } // namespace content | 818 } // namespace content |
OLD | NEW |