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 23 matching lines...) Expand all Loading... |
34 #include "ui/events/keycodes/keyboard_codes.h" | 34 #include "ui/events/keycodes/keyboard_codes.h" |
35 | 35 |
36 using blink::WebCanvas; | 36 using blink::WebCanvas; |
37 using blink::WebPluginContainer; | 37 using blink::WebPluginContainer; |
38 using blink::WebPluginParams; | 38 using blink::WebPluginParams; |
39 using blink::WebPoint; | 39 using blink::WebPoint; |
40 using blink::WebRect; | 40 using blink::WebRect; |
41 using blink::WebURL; | 41 using blink::WebURL; |
42 using blink::WebVector; | 42 using blink::WebVector; |
43 | 43 |
| 44 namespace { |
| 45 typedef std::map<blink::WebPluginContainer*, content::BrowserPlugin*> |
| 46 PluginContainerMap; |
| 47 static base::LazyInstance<PluginContainerMap> g_plugin_container_map = |
| 48 LAZY_INSTANCE_INITIALIZER; |
| 49 } // namespace |
| 50 |
44 namespace content { | 51 namespace content { |
45 | 52 |
| 53 // static |
| 54 BrowserPlugin* BrowserPlugin::GetFromNode(blink::WebNode& node) { |
| 55 blink::WebPluginContainer* container = node.pluginContainer(); |
| 56 if (!container) |
| 57 return NULL; |
| 58 |
| 59 PluginContainerMap* browser_plugins = g_plugin_container_map.Pointer(); |
| 60 PluginContainerMap::iterator it = browser_plugins->find(container); |
| 61 return it == browser_plugins->end() ? NULL : it->second; |
| 62 } |
| 63 |
46 BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view, | 64 BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view, |
47 blink::WebFrame* frame, | 65 blink::WebFrame* frame, |
48 scoped_ptr<BrowserPluginDelegate> delegate) | 66 scoped_ptr<BrowserPluginDelegate> delegate) |
49 : attached_(false), | 67 : attached_(false), |
50 attach_pending_(false), | 68 attach_pending_(false), |
51 render_view_(render_view->AsWeakPtr()), | 69 render_view_(render_view->AsWeakPtr()), |
52 render_view_routing_id_(render_view->GetRoutingID()), | 70 render_view_routing_id_(render_view->GetRoutingID()), |
53 container_(NULL), | 71 container_(NULL), |
54 last_device_scale_factor_(GetDeviceScaleFactor()), | 72 last_device_scale_factor_(GetDeviceScaleFactor()), |
55 sad_guest_(NULL), | 73 sad_guest_(NULL), |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 return false; | 389 return false; |
372 | 390 |
373 // Tell |container| to allow this plugin to use script objects. | 391 // Tell |container| to allow this plugin to use script objects. |
374 npp_.reset(new NPP_t); | 392 npp_.reset(new NPP_t); |
375 container->allowScriptObjects(); | 393 container->allowScriptObjects(); |
376 | 394 |
377 bindings_.reset(new BrowserPluginBindings(this)); | 395 bindings_.reset(new BrowserPluginBindings(this)); |
378 container_ = container; | 396 container_ = container; |
379 container_->setWantsWheelEvents(true); | 397 container_->setWantsWheelEvents(true); |
380 | 398 |
| 399 g_plugin_container_map.Get().insert(std::make_pair(container_, this)); |
| 400 |
381 // This is a way to notify observers of our attributes that this plugin is | 401 // This is a way to notify observers of our attributes that this plugin is |
382 // available in render tree. | 402 // available in render tree. |
383 // TODO(lazyboy): This should be done through the delegate instead. Perhaps | 403 // TODO(lazyboy): This should be done through the delegate instead. Perhaps |
384 // by firing an event from there. | 404 // by firing an event from there. |
385 UpdateDOMAttribute("internalinstanceid", | 405 UpdateDOMAttribute("internalinstanceid", |
386 base::IntToString(browser_plugin_instance_id_)); | 406 base::IntToString(browser_plugin_instance_id_)); |
387 | 407 |
388 browser_plugin_manager()->AddBrowserPlugin(browser_plugin_instance_id_, this); | 408 browser_plugin_manager()->AddBrowserPlugin(browser_plugin_instance_id_, this); |
389 return true; | 409 return true; |
390 } | 410 } |
(...skipping 20 matching lines...) Expand all Loading... |
411 } | 431 } |
412 } | 432 } |
413 | 433 |
414 void BrowserPlugin::destroy() { | 434 void BrowserPlugin::destroy() { |
415 // If the plugin was initialized then it has a valid |npp_| identifier, and | 435 // If the plugin was initialized then it has a valid |npp_| identifier, and |
416 // the |container_| must clear references to the plugin's script objects. | 436 // the |container_| must clear references to the plugin's script objects. |
417 DCHECK(!npp_ || container_); | 437 DCHECK(!npp_ || container_); |
418 if (container_) | 438 if (container_) |
419 container_->clearScriptObjects(); | 439 container_->clearScriptObjects(); |
420 | 440 |
| 441 // The BrowserPlugin's WebPluginContainer is deleted immediately after this |
| 442 // call returns, so let's not keep a reference to it around. |
| 443 g_plugin_container_map.Get().erase(container_); |
| 444 |
421 if (compositing_helper_.get()) | 445 if (compositing_helper_.get()) |
422 compositing_helper_->OnContainerDestroy(); | 446 compositing_helper_->OnContainerDestroy(); |
423 container_ = NULL; | 447 container_ = NULL; |
424 // Will be a no-op if the mouse is not currently locked. | 448 // Will be a no-op if the mouse is not currently locked. |
425 if (render_view_) | 449 if (render_view_) |
426 render_view_->mouse_lock_dispatcher()->OnLockTargetDestroyed(this); | 450 render_view_->mouse_lock_dispatcher()->OnLockTargetDestroyed(this); |
427 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 451 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
428 } | 452 } |
429 | 453 |
430 NPObject* BrowserPlugin::scriptableObject() { | 454 NPObject* BrowserPlugin::scriptableObject() { |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 const blink::WebMouseEvent& event) { | 749 const blink::WebMouseEvent& event) { |
726 browser_plugin_manager()->Send( | 750 browser_plugin_manager()->Send( |
727 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, | 751 new BrowserPluginHostMsg_HandleInputEvent(render_view_routing_id_, |
728 browser_plugin_instance_id_, | 752 browser_plugin_instance_id_, |
729 plugin_rect_, | 753 plugin_rect_, |
730 &event)); | 754 &event)); |
731 return true; | 755 return true; |
732 } | 756 } |
733 | 757 |
734 } // namespace content | 758 } // namespace content |
OLD | NEW |