| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_manager_impl.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_manager_impl.h" |
| 6 | 6 |
| 7 #include "content/common/browser_plugin/browser_plugin_constants.h" | 7 #include "content/common/browser_plugin/browser_plugin_constants.h" |
| 8 #include "content/common/browser_plugin/browser_plugin_messages.h" | 8 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| 9 #include "content/common/cursors/webcursor.h" | 9 #include "content/common/cursors/webcursor.h" |
| 10 #include "content/renderer/browser_plugin/browser_plugin.h" | 10 #include "content/renderer/browser_plugin/browser_plugin.h" |
| 11 #include "content/renderer/render_thread_impl.h" | 11 #include "content/renderer/render_thread_impl.h" |
| 12 #include "ui/gfx/point.h" | 12 #include "ui/gfx/point.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 BrowserPluginManagerImpl::BrowserPluginManagerImpl( | 16 BrowserPluginManagerImpl::BrowserPluginManagerImpl( |
| 17 RenderViewImpl* render_view) | 17 RenderViewImpl* render_view) |
| 18 : BrowserPluginManager(render_view), | 18 : BrowserPluginManager(render_view) { |
| 19 request_id_counter_(0) { | |
| 20 } | 19 } |
| 21 | 20 |
| 22 BrowserPluginManagerImpl::~BrowserPluginManagerImpl() { | 21 BrowserPluginManagerImpl::~BrowserPluginManagerImpl() { |
| 23 } | 22 } |
| 24 | 23 |
| 25 BrowserPlugin* BrowserPluginManagerImpl::CreateBrowserPlugin( | 24 BrowserPlugin* BrowserPluginManagerImpl::CreateBrowserPlugin( |
| 26 RenderViewImpl* render_view, | 25 RenderViewImpl* render_view, |
| 27 blink::WebFrame* frame, | 26 blink::WebFrame* frame, |
| 28 bool auto_navigate) { | 27 bool auto_navigate) { |
| 29 return new BrowserPlugin(render_view, frame, auto_navigate); | 28 return new BrowserPlugin(render_view, frame, auto_navigate); |
| 30 } | 29 } |
| 31 | 30 |
| 32 void BrowserPluginManagerImpl::AllocateInstanceID( | |
| 33 const base::WeakPtr<BrowserPlugin>& browser_plugin) { | |
| 34 int request_id = ++request_id_counter_; | |
| 35 pending_allocate_guest_instance_id_requests_.insert( | |
| 36 std::make_pair(request_id, browser_plugin)); | |
| 37 Send(new BrowserPluginHostMsg_AllocateInstanceID( | |
| 38 browser_plugin->render_view_routing_id(), request_id)); | |
| 39 } | |
| 40 | |
| 41 bool BrowserPluginManagerImpl::Send(IPC::Message* msg) { | 31 bool BrowserPluginManagerImpl::Send(IPC::Message* msg) { |
| 42 return RenderThread::Get()->Send(msg); | 32 return RenderThread::Get()->Send(msg); |
| 43 } | 33 } |
| 44 | 34 |
| 45 bool BrowserPluginManagerImpl::OnMessageReceived( | 35 bool BrowserPluginManagerImpl::OnMessageReceived( |
| 46 const IPC::Message& message) { | 36 const IPC::Message& message) { |
| 47 if (BrowserPlugin::ShouldForwardToBrowserPlugin(message)) { | 37 if (BrowserPlugin::ShouldForwardToBrowserPlugin(message)) { |
| 48 int guest_instance_id = browser_plugin::kInstanceIDNone; | 38 int guest_instance_id = browser_plugin::kInstanceIDNone; |
| 49 // All allowed messages must have |guest_instance_id| as their first | 39 // All allowed messages must have |guest_instance_id| as their first |
| 50 // parameter. | 40 // parameter. |
| 51 PickleIterator iter(message); | 41 PickleIterator iter(message); |
| 52 bool success = iter.ReadInt(&guest_instance_id); | 42 bool success = iter.ReadInt(&guest_instance_id); |
| 53 DCHECK(success); | 43 DCHECK(success); |
| 54 BrowserPlugin* plugin = GetBrowserPlugin(guest_instance_id); | 44 BrowserPlugin* plugin = GetBrowserPlugin(guest_instance_id); |
| 55 if (plugin && plugin->OnMessageReceived(message)) | 45 if (plugin && plugin->OnMessageReceived(message)) |
| 56 return true; | 46 return true; |
| 57 } | 47 } |
| 58 | 48 |
| 59 bool handled = true; | 49 return false; |
| 60 IPC_BEGIN_MESSAGE_MAP(BrowserPluginManagerImpl, message) | |
| 61 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AllocateInstanceID_ACK, | |
| 62 OnAllocateInstanceIDACK) | |
| 63 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 64 IPC_END_MESSAGE_MAP() | |
| 65 return handled; | |
| 66 } | 50 } |
| 67 | 51 |
| 68 void BrowserPluginManagerImpl::DidCommitCompositorFrame() { | 52 void BrowserPluginManagerImpl::DidCommitCompositorFrame() { |
| 69 IDMap<BrowserPlugin>::iterator iter(&instances_); | 53 IDMap<BrowserPlugin>::iterator iter(&instances_); |
| 70 while (!iter.IsAtEnd()) { | 54 while (!iter.IsAtEnd()) { |
| 71 iter.GetCurrentValue()->DidCommitCompositorFrame(); | 55 iter.GetCurrentValue()->DidCommitCompositorFrame(); |
| 72 iter.Advance(); | 56 iter.Advance(); |
| 73 } | 57 } |
| 74 } | 58 } |
| 75 | 59 |
| 76 void BrowserPluginManagerImpl::OnAllocateInstanceIDACK( | |
| 77 int request_id, | |
| 78 int guest_instance_id) { | |
| 79 InstanceIDMap::iterator it = | |
| 80 pending_allocate_guest_instance_id_requests_.find(request_id); | |
| 81 if (it == pending_allocate_guest_instance_id_requests_.end()) | |
| 82 return; | |
| 83 | |
| 84 const base::WeakPtr<BrowserPlugin> plugin(it->second); | |
| 85 if (!plugin) | |
| 86 return; | |
| 87 pending_allocate_guest_instance_id_requests_.erase(request_id); | |
| 88 plugin->OnInstanceIDAllocated(guest_instance_id); | |
| 89 } | |
| 90 | |
| 91 } // namespace content | 60 } // namespace content |
| OLD | NEW |