| Index: content/renderer/browser_plugin/browser_plugin.cc
|
| diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc
|
| index a3e78d59460a49429ba6a0abb7f22ba3b77200d0..b7d5ab050171257514b8fe514c26dc1b021b66df 100644
|
| --- a/content/renderer/browser_plugin/browser_plugin.cc
|
| +++ b/content/renderer/browser_plugin/browser_plugin.cc
|
| @@ -40,6 +40,14 @@ using blink::WebRect;
|
| using blink::WebURL;
|
| using blink::WebVector;
|
|
|
| +namespace {
|
| +typedef std::map<blink::WebPluginContainer*, content::BrowserPlugin*>
|
| + PluginContainerMap;
|
| +static base::LazyInstance<PluginContainerMap> g_plugin_container_map =
|
| + LAZY_INSTANCE_INITIALIZER;
|
| +
|
| +} // namespace
|
| +
|
| namespace content {
|
|
|
| BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view,
|
| @@ -64,6 +72,8 @@ BrowserPlugin::BrowserPlugin(RenderViewImpl* render_view,
|
| }
|
|
|
| BrowserPlugin::~BrowserPlugin() {
|
| + browser_plugin_manager()->RemoveBrowserPluginInternal(
|
| + browser_plugin_instance_id_);
|
| // If the BrowserPlugin has never navigated then the browser process and
|
| // BrowserPluginManager don't know about it and so there is nothing to do
|
| // here.
|
| @@ -158,10 +168,8 @@ void BrowserPlugin::ParseAllowTransparencyAttribute() {
|
| opaque));
|
| }
|
|
|
| -void BrowserPlugin::Attach(int guest_instance_id,
|
| - scoped_ptr<base::DictionaryValue> extra_params) {
|
| - CHECK(guest_instance_id != browser_plugin::kInstanceIDNone);
|
| -
|
| +void BrowserPlugin::Attach(int guest_instance_id) {
|
| + CHECK_NE(browser_plugin::kInstanceIDNone, guest_instance_id);
|
| // If this BrowserPlugin is already attached to a guest, then kill the guest.
|
| if (HasGuestInstanceID()) {
|
| if (guest_instance_id == guest_instance_id_)
|
| @@ -177,8 +185,6 @@ void BrowserPlugin::Attach(int guest_instance_id,
|
| render_view_routing_id_, guest_instance_id_));
|
| }
|
|
|
| - // This API may be called directly without setting the src attribute.
|
| - // In that case, we need to make sure we don't allocate another instance ID.
|
| guest_instance_id_ = guest_instance_id;
|
| browser_plugin_manager()->AddBrowserPlugin(guest_instance_id, this);
|
|
|
| @@ -189,10 +195,10 @@ void BrowserPlugin::Attach(int guest_instance_id,
|
| attach_params.origin = plugin_rect().origin();
|
| GetSizeParams(&attach_params.resize_guest_params, false);
|
|
|
| - browser_plugin_manager()->Send(
|
| - new BrowserPluginHostMsg_Attach(render_view_routing_id_,
|
| - guest_instance_id_, attach_params,
|
| - *extra_params));
|
| + browser_plugin_manager()->Send(new BrowserPluginHostMsg_Attach(
|
| + render_view_routing_id_,
|
| + browser_plugin_instance_id_,
|
| + attach_params));
|
| }
|
|
|
| void BrowserPlugin::DidCommitCompositorFrame() {
|
| @@ -206,6 +212,7 @@ void BrowserPlugin::OnAdvanceFocus(int guest_instance_id, bool reverse) {
|
| }
|
|
|
| void BrowserPlugin::OnAttachACK(int guest_instance_id) {
|
| + DCHECK(!attached());
|
| attached_ = true;
|
| }
|
|
|
| @@ -299,9 +306,9 @@ void BrowserPlugin::OnSetMouseLock(int guest_instance_id,
|
| void BrowserPlugin::OnShouldAcceptTouchEvents(int guest_instance_id,
|
| bool accept) {
|
| if (container()) {
|
| - container()->requestTouchEventType(accept ?
|
| - blink::WebPluginContainer::TouchEventRequestTypeRaw :
|
| - blink::WebPluginContainer::TouchEventRequestTypeNone);
|
| + container()->requestTouchEventType(
|
| + accept ? WebPluginContainer::TouchEventRequestTypeRaw
|
| + : WebPluginContainer::TouchEventRequestTypeNone);
|
| }
|
| }
|
|
|
| @@ -389,7 +396,7 @@ bool BrowserPlugin::ShouldGuestBeFocused() const {
|
| return plugin_focused_ && embedder_focused;
|
| }
|
|
|
| -blink::WebPluginContainer* BrowserPlugin::container() const {
|
| +WebPluginContainer* BrowserPlugin::container() const {
|
| return container_;
|
| }
|
|
|
| @@ -404,10 +411,17 @@ bool BrowserPlugin::initialize(WebPluginContainer* container) {
|
| bindings_.reset(new BrowserPluginBindings(this));
|
| container_ = container;
|
| container_->setWantsWheelEvents(true);
|
| - // This is a way to notify observers of our attributes that we have the
|
| - // bindings ready. This also means that this plugin is available in render
|
| - // tree.
|
| - UpdateDOMAttribute("internalbindings", "true");
|
| +
|
| + g_plugin_container_map.Get().insert(std::make_pair(container_, this));
|
| +
|
| + // This is a way to notify observers of our attributes that this plugin is
|
| + // available in render tree.
|
| + browser_plugin_instance_id_ = browser_plugin_manager()->GetNextInstanceID();
|
| + UpdateDOMAttribute("internalinstanceid",
|
| + base::StringPrintf("%d", browser_plugin_instance_id_));
|
| +
|
| + browser_plugin_manager()->AddBrowserPluginInternal(
|
| + browser_plugin_instance_id_, this);
|
| return true;
|
| }
|
|
|
| @@ -440,6 +454,10 @@ void BrowserPlugin::destroy() {
|
| if (container_)
|
| container_->clearScriptObjects();
|
|
|
| + // The BrowserPlugin's WebPluginContainer is deleted immediately after this
|
| + // call returns, so let's not keep a reference to it around.
|
| + g_plugin_container_map.Get().erase(container_);
|
| +
|
| if (compositing_helper_.get())
|
| compositing_helper_->OnContainerDestroy();
|
| container_ = NULL;
|
| @@ -507,12 +525,22 @@ void BrowserPlugin::paint(WebCanvas* canvas, const WebRect& rect) {
|
| canvas->drawRect(image_data_rect, paint);
|
| }
|
|
|
| +// static.
|
| +BrowserPlugin* BrowserPlugin::FromNode(blink::WebNode& node) {
|
| + blink::WebPluginContainer* container = node.pluginContainer();
|
| + if (!container)
|
| + return NULL;
|
| +
|
| + PluginContainerMap* browser_plugins = g_plugin_container_map.Pointer();
|
| + PluginContainerMap::iterator it = browser_plugins->find(container);
|
| + return it == browser_plugins->end() ? NULL : it->second;
|
| +}
|
| +
|
| // static
|
| bool BrowserPlugin::ShouldForwardToBrowserPlugin(
|
| const IPC::Message& message) {
|
| switch (message.type()) {
|
| case BrowserPluginMsg_AdvanceFocus::ID:
|
| - case BrowserPluginMsg_Attach_ACK::ID:
|
| case BrowserPluginMsg_BuffersSwapped::ID:
|
| case BrowserPluginMsg_CompositorFrameSwapped::ID:
|
| case BrowserPluginMsg_CopyFromCompositingSurface::ID:
|
|
|