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_counter_(0) { | |
lazyboy
2013/01/17 17:39:25
nit: request_id_counter_ so it's obvious that this
Fady Samuel
2013/01/17 18:40:38
Done.
| |
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_counter_++; | |
34 requests_.AddWithID(browser_plugin, request_id); | |
lazyboy
2013/01/17 17:39:25
requests_ probably too broad name, maybe name it t
Fady Samuel
2013/01/17 18:40:38
Done.
| |
35 Send(new BrowserPluginHostMsg_AllocateInstanceIDRequest( | |
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_GENERIC(BrowserPluginMsg_AllocateInstanceIDResponse, | |
59 OnAllocateInstanceIDResponse(message)) | |
52 IPC_MESSAGE_HANDLER(BrowserPluginMsg_PluginAtPositionRequest, | 60 IPC_MESSAGE_HANDLER(BrowserPluginMsg_PluginAtPositionRequest, |
53 OnPluginAtPositionRequest); | 61 OnPluginAtPositionRequest); |
54 IPC_MESSAGE_UNHANDLED(handled = false) | 62 IPC_MESSAGE_UNHANDLED(handled = false) |
55 IPC_END_MESSAGE_MAP() | 63 IPC_END_MESSAGE_MAP() |
56 return handled; | 64 return handled; |
57 } | 65 } |
58 | 66 |
67 void BrowserPluginManagerImpl::OnAllocateInstanceIDResponse( | |
68 const IPC::Message& message) { | |
69 int request_id = 0; | |
70 PickleIterator iter(message); | |
71 bool success = iter.ReadInt(&request_id); | |
72 DCHECK(success); | |
73 BrowserPlugin* plugin = requests_.Lookup(request_id); | |
74 requests_.Remove(request_id); | |
75 if (plugin) | |
76 plugin->OnMessageReceived(message); | |
lazyboy
2013/01/17 17:39:25
Can we just read both request_id and instance_id (
Fady Samuel
2013/01/17 18:40:38
I'd prefer to leave it this way because eventually
| |
77 } | |
78 | |
59 void BrowserPluginManagerImpl::OnPluginAtPositionRequest( | 79 void BrowserPluginManagerImpl::OnPluginAtPositionRequest( |
60 const IPC::Message& message, | 80 const IPC::Message& message, |
61 int request_id, | 81 int request_id, |
62 const gfx::Point& position) { | 82 const gfx::Point& position) { |
63 int instance_id = -1; | 83 int instance_id = -1; |
64 IDMap<BrowserPlugin>::iterator it(&instances_); | 84 IDMap<BrowserPlugin>::iterator it(&instances_); |
65 gfx::Point local_position = position; | 85 gfx::Point local_position = position; |
66 int source_routing_id = message.routing_id(); | 86 int source_routing_id = message.routing_id(); |
67 while (!it.IsAtEnd()) { | 87 while (!it.IsAtEnd()) { |
68 const BrowserPlugin* plugin = it.GetCurrentValue(); | 88 const BrowserPlugin* plugin = it.GetCurrentValue(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 case BrowserPluginMsg_UpdateRect::ID: | 124 case BrowserPluginMsg_UpdateRect::ID: |
105 case BrowserPluginMsg_BuffersSwapped::ID: | 125 case BrowserPluginMsg_BuffersSwapped::ID: |
106 return true; | 126 return true; |
107 default: | 127 default: |
108 break; | 128 break; |
109 } | 129 } |
110 return false; | 130 return false; |
111 } | 131 } |
112 | 132 |
113 } // namespace content | 133 } // namespace content |
OLD | NEW |