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/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 blink::WebPluginContainer* container = node.pluginContainer(); | 54 blink::WebPluginContainer* container = node.pluginContainer(); |
55 if (!container) | 55 if (!container) |
56 return nullptr; | 56 return nullptr; |
57 | 57 |
58 PluginContainerMap* browser_plugins = g_plugin_container_map.Pointer(); | 58 PluginContainerMap* browser_plugins = g_plugin_container_map.Pointer(); |
59 PluginContainerMap::iterator it = browser_plugins->find(container); | 59 PluginContainerMap::iterator it = browser_plugins->find(container); |
60 return it == browser_plugins->end() ? nullptr : it->second; | 60 return it == browser_plugins->end() ? nullptr : it->second; |
61 } | 61 } |
62 | 62 |
63 BrowserPlugin::BrowserPlugin(RenderFrame* render_frame, | 63 BrowserPlugin::BrowserPlugin(RenderFrame* render_frame, |
64 scoped_ptr<BrowserPluginDelegate> delegate) | 64 BrowserPluginDelegate* delegate) |
65 : attached_(false), | 65 : attached_(false), |
66 render_frame_routing_id_(render_frame->GetRoutingID()), | 66 render_frame_routing_id_(render_frame->GetRoutingID()), |
67 container_(nullptr), | 67 container_(nullptr), |
68 sad_guest_(nullptr), | 68 sad_guest_(nullptr), |
69 guest_crashed_(false), | 69 guest_crashed_(false), |
70 plugin_focused_(false), | 70 plugin_focused_(false), |
71 visible_(true), | 71 visible_(true), |
72 mouse_locked_(false), | 72 mouse_locked_(false), |
73 ready_(false), | 73 ready_(false), |
74 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), | 74 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), |
75 contents_opaque_(true), | 75 contents_opaque_(true), |
76 delegate_(delegate.Pass()), | 76 delegate_(delegate), |
77 weak_ptr_factory_(this) { | 77 weak_ptr_factory_(this) { |
78 browser_plugin_instance_id_ = | 78 browser_plugin_instance_id_ = |
79 BrowserPluginManager::Get()->GetNextInstanceID(); | 79 BrowserPluginManager::Get()->GetNextInstanceID(); |
80 | 80 |
81 if (delegate_) | 81 if (delegate_) |
82 delegate_->SetElementInstanceID(browser_plugin_instance_id_); | 82 delegate_->SetElementInstanceID(browser_plugin_instance_id_); |
83 } | 83 } |
84 | 84 |
85 BrowserPlugin::~BrowserPlugin() { | 85 BrowserPlugin::~BrowserPlugin() { |
86 if (compositing_helper_.get()) | 86 if (compositing_helper_.get()) |
87 compositing_helper_->OnContainerDestroy(); | 87 compositing_helper_->OnContainerDestroy(); |
88 | 88 |
| 89 if (delegate_) |
| 90 delegate_->DidDestroyElement(); |
| 91 delegate_ = nullptr; |
| 92 |
89 BrowserPluginManager::Get()->RemoveBrowserPlugin(browser_plugin_instance_id_); | 93 BrowserPluginManager::Get()->RemoveBrowserPlugin(browser_plugin_instance_id_); |
90 } | 94 } |
91 | 95 |
92 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { | 96 bool BrowserPlugin::OnMessageReceived(const IPC::Message& message) { |
93 bool handled = true; | 97 bool handled = true; |
94 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) | 98 IPC_BEGIN_MESSAGE_MAP(BrowserPlugin, message) |
95 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) | 99 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) |
96 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped, | 100 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginMsg_CompositorFrameSwapped, |
97 OnCompositorFrameSwapped(message)) | 101 OnCompositorFrameSwapped(message)) |
98 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) | 102 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 } | 260 } |
257 } | 261 } |
258 | 262 |
259 void BrowserPlugin::ShowSadGraphic() { | 263 void BrowserPlugin::ShowSadGraphic() { |
260 // If the BrowserPlugin is scheduled to be deleted, then container_ will be | 264 // If the BrowserPlugin is scheduled to be deleted, then container_ will be |
261 // nullptr so we shouldn't attempt to access it. | 265 // nullptr so we shouldn't attempt to access it. |
262 if (container_) | 266 if (container_) |
263 container_->invalidate(); | 267 container_->invalidate(); |
264 } | 268 } |
265 | 269 |
| 270 void BrowserPlugin::UpdateInternalInstanceId() { |
| 271 // This is a way to notify observers of our attributes that this plugin is |
| 272 // available in render tree. |
| 273 // TODO(lazyboy): This should be done through the delegate instead. Perhaps |
| 274 // by firing an event from there. |
| 275 UpdateDOMAttribute( |
| 276 "internalinstanceid", |
| 277 base::UTF8ToUTF16(base::IntToString(browser_plugin_instance_id_))); |
| 278 } |
| 279 |
266 void BrowserPlugin::UpdateGuestFocusState(blink::WebFocusType focus_type) { | 280 void BrowserPlugin::UpdateGuestFocusState(blink::WebFocusType focus_type) { |
267 if (!attached()) | 281 if (!attached()) |
268 return; | 282 return; |
269 bool should_be_focused = ShouldGuestBeFocused(); | 283 bool should_be_focused = ShouldGuestBeFocused(); |
270 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_SetFocus( | 284 BrowserPluginManager::Get()->Send(new BrowserPluginHostMsg_SetFocus( |
271 browser_plugin_instance_id_, | 285 browser_plugin_instance_id_, |
272 should_be_focused, | 286 should_be_focused, |
273 focus_type)); | 287 focus_type)); |
274 } | 288 } |
275 | 289 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 compositing_helper_->EnableCompositing(enable); | 336 compositing_helper_->EnableCompositing(enable); |
323 compositing_helper_->SetContentsOpaque(contents_opaque_); | 337 compositing_helper_->SetContentsOpaque(contents_opaque_); |
324 | 338 |
325 if (!enable) { | 339 if (!enable) { |
326 DCHECK(compositing_helper_.get()); | 340 DCHECK(compositing_helper_.get()); |
327 compositing_helper_->OnContainerDestroy(); | 341 compositing_helper_->OnContainerDestroy(); |
328 compositing_helper_ = nullptr; | 342 compositing_helper_ = nullptr; |
329 } | 343 } |
330 } | 344 } |
331 | 345 |
332 void BrowserPlugin::UpdateInternalInstanceId() { | |
333 // This is a way to notify observers of our attributes that this plugin is | |
334 // available in render tree. | |
335 // TODO(lazyboy): This should be done through the delegate instead. Perhaps | |
336 // by firing an event from there. | |
337 UpdateDOMAttribute( | |
338 "internalinstanceid", | |
339 base::UTF8ToUTF16(base::IntToString(browser_plugin_instance_id_))); | |
340 } | |
341 | |
342 void BrowserPlugin::destroy() { | 346 void BrowserPlugin::destroy() { |
343 if (container_) { | 347 if (container_) { |
344 // The BrowserPlugin's WebPluginContainer is deleted immediately after this | 348 // The BrowserPlugin's WebPluginContainer is deleted immediately after this |
345 // call returns, so let's not keep a reference to it around. | 349 // call returns, so let's not keep a reference to it around. |
346 g_plugin_container_map.Get().erase(container_); | 350 g_plugin_container_map.Get().erase(container_); |
347 } | 351 } |
348 | 352 |
349 container_ = nullptr; | 353 container_ = nullptr; |
350 // Will be a no-op if the mouse is not currently locked. | 354 // Will be a no-op if the mouse is not currently locked. |
351 auto render_frame = RenderFrameImpl::FromRoutingID(render_frame_routing_id()); | 355 auto render_frame = RenderFrameImpl::FromRoutingID(render_frame_routing_id()); |
(...skipping 20 matching lines...) Expand all Loading... |
372 return true; | 376 return true; |
373 } | 377 } |
374 | 378 |
375 bool BrowserPlugin::canProcessDrag() const { | 379 bool BrowserPlugin::canProcessDrag() const { |
376 return true; | 380 return true; |
377 } | 381 } |
378 | 382 |
379 void BrowserPlugin::paint(WebCanvas* canvas, const WebRect& rect) { | 383 void BrowserPlugin::paint(WebCanvas* canvas, const WebRect& rect) { |
380 if (guest_crashed_) { | 384 if (guest_crashed_) { |
381 if (!sad_guest_) // Lazily initialize bitmap. | 385 if (!sad_guest_) // Lazily initialize bitmap. |
382 sad_guest_ = content::GetContentClient()->renderer()-> | 386 sad_guest_ = GetContentClient()->renderer()->GetSadWebViewBitmap(); |
383 GetSadWebViewBitmap(); | |
384 // content_shell does not have the sad plugin bitmap, so we'll paint black | 387 // content_shell does not have the sad plugin bitmap, so we'll paint black |
385 // instead to make it clear that something went wrong. | 388 // instead to make it clear that something went wrong. |
386 if (sad_guest_) { | 389 if (sad_guest_) { |
387 PaintSadPlugin(canvas, view_rect_, *sad_guest_); | 390 PaintSadPlugin(canvas, view_rect_, *sad_guest_); |
388 return; | 391 return; |
389 } | 392 } |
390 } | 393 } |
391 SkAutoCanvasRestore auto_restore(canvas, true); | 394 SkAutoCanvasRestore auto_restore(canvas, true); |
392 canvas->translate(view_rect_.x(), view_rect_.y()); | 395 canvas->translate(view_rect_.x(), view_rect_.y()); |
393 SkRect image_data_rect = SkRect::MakeXYWH( | 396 SkRect image_data_rect = SkRect::MakeXYWH( |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 bool BrowserPlugin::HandleMouseLockedInputEvent( | 613 bool BrowserPlugin::HandleMouseLockedInputEvent( |
611 const blink::WebMouseEvent& event) { | 614 const blink::WebMouseEvent& event) { |
612 BrowserPluginManager::Get()->Send( | 615 BrowserPluginManager::Get()->Send( |
613 new BrowserPluginHostMsg_HandleInputEvent(browser_plugin_instance_id_, | 616 new BrowserPluginHostMsg_HandleInputEvent(browser_plugin_instance_id_, |
614 view_rect_, | 617 view_rect_, |
615 &event)); | 618 &event)); |
616 return true; | 619 return true; |
617 } | 620 } |
618 | 621 |
619 } // namespace content | 622 } // namespace content |
OLD | NEW |