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(RenderViewImpl* render_view) |
17 RenderViewImpl* render_view) | 17 : BrowserPluginManager(render_view) { |
18 : BrowserPluginManager(render_view), | |
19 request_id_counter_(0) { | |
20 } | 18 } |
21 | 19 |
22 BrowserPluginManagerImpl::~BrowserPluginManagerImpl() { | 20 BrowserPluginManagerImpl::~BrowserPluginManagerImpl() { |
23 } | 21 } |
24 | 22 |
25 BrowserPlugin* BrowserPluginManagerImpl::CreateBrowserPlugin( | 23 BrowserPlugin* BrowserPluginManagerImpl::CreateBrowserPlugin( |
26 RenderViewImpl* render_view, | 24 RenderViewImpl* render_view, |
27 blink::WebFrame* frame, | 25 blink::WebFrame* frame, |
28 bool auto_navigate) { | 26 bool auto_navigate) { |
29 return new BrowserPlugin(render_view, frame, auto_navigate); | 27 return new BrowserPlugin(render_view, frame, auto_navigate); |
30 } | 28 } |
31 | 29 |
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) { | 30 bool BrowserPluginManagerImpl::Send(IPC::Message* msg) { |
42 return RenderThread::Get()->Send(msg); | 31 return RenderThread::Get()->Send(msg); |
43 } | 32 } |
44 | 33 |
45 bool BrowserPluginManagerImpl::OnMessageReceived( | 34 bool BrowserPluginManagerImpl::OnMessageReceived( |
46 const IPC::Message& message) { | 35 const IPC::Message& message) { |
47 if (BrowserPlugin::ShouldForwardToBrowserPlugin(message)) { | 36 if (BrowserPlugin::ShouldForwardToBrowserPlugin(message)) { |
48 int guest_instance_id = browser_plugin::kInstanceIDNone; | 37 int guest_instance_id = browser_plugin::kInstanceIDNone; |
49 // All allowed messages must have |guest_instance_id| as their first | 38 // All allowed messages must have |guest_instance_id| as their first |
50 // parameter. | 39 // parameter. |
51 PickleIterator iter(message); | 40 PickleIterator iter(message); |
52 bool success = iter.ReadInt(&guest_instance_id); | 41 bool success = iter.ReadInt(&guest_instance_id); |
53 DCHECK(success); | 42 DCHECK(success); |
54 BrowserPlugin* plugin = GetBrowserPlugin(guest_instance_id); | 43 BrowserPlugin* plugin = GetBrowserPlugin(guest_instance_id); |
55 if (plugin && plugin->OnMessageReceived(message)) | 44 if (plugin && plugin->OnMessageReceived(message)) |
56 return true; | 45 return true; |
57 } | 46 } |
58 | 47 |
59 bool handled = true; | 48 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 } | 49 } |
67 | 50 |
68 void BrowserPluginManagerImpl::DidCommitCompositorFrame() { | 51 void BrowserPluginManagerImpl::DidCommitCompositorFrame() { |
69 IDMap<BrowserPlugin>::iterator iter(&instances_); | 52 IDMap<BrowserPlugin>::iterator iter(&instances_); |
70 while (!iter.IsAtEnd()) { | 53 while (!iter.IsAtEnd()) { |
71 iter.GetCurrentValue()->DidCommitCompositorFrame(); | 54 iter.GetCurrentValue()->DidCommitCompositorFrame(); |
72 iter.Advance(); | 55 iter.Advance(); |
73 } | 56 } |
74 } | 57 } |
75 | 58 |
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 | 59 } // namespace content |
OLD | NEW |