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_messages.h" | 7 #include "content/common/browser_plugin_messages.h" |
8 #include "content/renderer/browser_plugin/browser_plugin.h" | 8 #include "content/renderer/browser_plugin/browser_plugin.h" |
9 #include "content/renderer/render_thread_impl.h" | 9 #include "content/renderer/render_thread_impl.h" |
10 #include "ui/gfx/point.h" | 10 #include "ui/gfx/point.h" |
11 #include "webkit/glue/webcursor.h" | 11 #include "webkit/glue/webcursor.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 | 14 |
15 BrowserPluginManagerImpl::BrowserPluginManagerImpl( | 15 BrowserPluginManagerImpl::BrowserPluginManagerImpl( |
16 RenderViewImpl* render_view) | 16 RenderViewImpl* render_view) |
17 : BrowserPluginManager(render_view) { | 17 : BrowserPluginManager(render_view), |
| 18 request_id_counter_(0) { |
18 } | 19 } |
19 | 20 |
20 BrowserPluginManagerImpl::~BrowserPluginManagerImpl() { | 21 BrowserPluginManagerImpl::~BrowserPluginManagerImpl() { |
21 } | 22 } |
22 | 23 |
23 BrowserPlugin* BrowserPluginManagerImpl::CreateBrowserPlugin( | 24 BrowserPlugin* BrowserPluginManagerImpl::CreateBrowserPlugin( |
24 RenderViewImpl* render_view, | 25 RenderViewImpl* render_view, |
25 WebKit::WebFrame* frame, | 26 WebKit::WebFrame* frame, |
26 const WebKit::WebPluginParams& params) { | 27 const WebKit::WebPluginParams& params) { |
27 return new BrowserPlugin(++browser_plugin_counter_, | 28 return new BrowserPlugin(render_view, frame, params); |
28 render_view, | 29 } |
29 frame, | 30 |
30 params); | 31 void BrowserPluginManagerImpl::AllocateInstanceID( |
| 32 BrowserPlugin* browser_plugin) { |
| 33 int request_id = request_id_counter_++; |
| 34 pending_allocate_instance_id_requests_.AddWithID(browser_plugin, request_id); |
| 35 Send(new BrowserPluginHostMsg_AllocateInstanceID( |
| 36 browser_plugin->render_view_routing_id(), request_id)); |
31 } | 37 } |
32 | 38 |
33 bool BrowserPluginManagerImpl::Send(IPC::Message* msg) { | 39 bool BrowserPluginManagerImpl::Send(IPC::Message* msg) { |
34 return RenderThread::Get()->Send(msg); | 40 return RenderThread::Get()->Send(msg); |
35 } | 41 } |
36 | 42 |
37 bool BrowserPluginManagerImpl::OnMessageReceived( | 43 bool BrowserPluginManagerImpl::OnMessageReceived( |
38 const IPC::Message& message) { | 44 const IPC::Message& message) { |
39 if (ShouldForwardToBrowserPlugin(message)) { | 45 if (ShouldForwardToBrowserPlugin(message)) { |
40 int instance_id = 0; | 46 int instance_id = 0; |
41 // All allowed messages must have instance_id as their first parameter. | 47 // All allowed messages must have instance_id as their first parameter. |
42 PickleIterator iter(message); | 48 PickleIterator iter(message); |
43 bool success = iter.ReadInt(&instance_id); | 49 bool success = iter.ReadInt(&instance_id); |
44 DCHECK(success); | 50 DCHECK(success); |
45 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | 51 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); |
46 if (plugin && plugin->OnMessageReceived(message)) | 52 if (plugin && plugin->OnMessageReceived(message)) |
47 return true; | 53 return true; |
48 } | 54 } |
49 | 55 |
50 bool handled = true; | 56 bool handled = true; |
51 IPC_BEGIN_MESSAGE_MAP(BrowserPluginManagerImpl, message) | 57 IPC_BEGIN_MESSAGE_MAP(BrowserPluginManagerImpl, message) |
| 58 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AllocateInstanceID_ACK, |
| 59 OnAllocateInstanceIDACK) |
52 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, | 60 IPC_MESSAGE_HANDLER(BrowserPluginMsg_BuffersSwapped, |
53 OnUnhandledSwap); | 61 OnUnhandledSwap); |
54 IPC_MESSAGE_HANDLER(BrowserPluginMsg_PluginAtPositionRequest, | 62 IPC_MESSAGE_HANDLER(BrowserPluginMsg_PluginAtPositionRequest, |
55 OnPluginAtPositionRequest); | 63 OnPluginAtPositionRequest); |
56 IPC_MESSAGE_UNHANDLED(handled = false) | 64 IPC_MESSAGE_UNHANDLED(handled = false) |
57 IPC_END_MESSAGE_MAP() | 65 IPC_END_MESSAGE_MAP() |
58 return handled; | 66 return handled; |
59 } | 67 } |
60 | 68 |
| 69 void BrowserPluginManagerImpl::OnAllocateInstanceIDACK( |
| 70 const IPC::Message& message, int request_id, int instance_id) { |
| 71 BrowserPlugin* plugin = |
| 72 pending_allocate_instance_id_requests_.Lookup(request_id); |
| 73 pending_allocate_instance_id_requests_.Remove(request_id); |
| 74 if (plugin) |
| 75 plugin->SetInstanceID(instance_id); |
| 76 } |
| 77 |
61 void BrowserPluginManagerImpl::OnPluginAtPositionRequest( | 78 void BrowserPluginManagerImpl::OnPluginAtPositionRequest( |
62 const IPC::Message& message, | 79 const IPC::Message& message, |
63 int request_id, | 80 int request_id, |
64 const gfx::Point& position) { | 81 const gfx::Point& position) { |
65 int instance_id = -1; | 82 int instance_id = -1; |
66 IDMap<BrowserPlugin>::iterator it(&instances_); | 83 IDMap<BrowserPlugin>::iterator it(&instances_); |
67 gfx::Point local_position = position; | 84 gfx::Point local_position = position; |
68 while (!it.IsAtEnd()) { | 85 while (!it.IsAtEnd()) { |
69 const BrowserPlugin* plugin = it.GetCurrentValue(); | 86 const BrowserPlugin* plugin = it.GetCurrentValue(); |
70 if (plugin->InBounds(position)) { | 87 if (plugin->InBounds(position)) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 case BrowserPluginMsg_UpdateRect::ID: | 136 case BrowserPluginMsg_UpdateRect::ID: |
120 case BrowserPluginMsg_BuffersSwapped::ID: | 137 case BrowserPluginMsg_BuffersSwapped::ID: |
121 return true; | 138 return true; |
122 default: | 139 default: |
123 break; | 140 break; |
124 } | 141 } |
125 return false; | 142 return false; |
126 } | 143 } |
127 | 144 |
128 } // namespace content | 145 } // namespace content |
OLD | NEW |