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 RegisterBrowserPluginMessages(); | |
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(++browser_plugin_counter_, |
28 render_view, | 29 render_view, |
29 frame, | 30 frame, |
30 params); | 31 params); |
31 } | 32 } |
32 | 33 |
33 bool BrowserPluginManagerImpl::Send(IPC::Message* msg) { | 34 bool BrowserPluginManagerImpl::Send(IPC::Message* msg) { |
34 return RenderThread::Get()->Send(msg); | 35 return RenderThread::Get()->Send(msg); |
35 } | 36 } |
36 | 37 |
37 bool BrowserPluginManagerImpl::OnMessageReceived( | 38 bool BrowserPluginManagerImpl::OnMessageReceived( |
38 const IPC::Message& message) { | 39 const IPC::Message& message) { |
40 if (browser_plugin_messages_.count(message.type()) > 0) { | |
Charlie Reis
2012/12/14 18:24:02
This feels like a mis-use of the IPC logic. All t
Fady Samuel
2012/12/14 18:47:48
Regardless of the direction we go, BrowserPluginMa
Charlie Reis
2012/12/14 19:16:36
Perhaps the class is still needed.
| |
41 int instance_id = 0; | |
42 PickleIterator iter(message); | |
Charlie Reis
2012/12/14 19:16:36
Please document that all messages that we allow he
Fady Samuel
2012/12/14 19:34:08
Done.
| |
43 bool success = iter.ReadInt(&instance_id); | |
44 DCHECK(success); | |
45 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | |
46 if (plugin && plugin->OnMessageReceived(message)) | |
47 return true; | |
48 } | |
49 | |
39 bool handled = true; | 50 bool handled = true; |
40 IPC_BEGIN_MESSAGE_MAP(BrowserPluginManagerImpl, message) | 51 IPC_BEGIN_MESSAGE_MAP(BrowserPluginManagerImpl, message) |
41 IPC_MESSAGE_HANDLER(BrowserPluginMsg_UpdateRect, OnUpdateRect) | |
42 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestGone, OnGuestGone) | |
43 IPC_MESSAGE_HANDLER(BrowserPluginMsg_AdvanceFocus, OnAdvanceFocus) | |
44 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestContentWindowReady, | |
45 OnGuestContentWindowReady) | |
46 IPC_MESSAGE_HANDLER(BrowserPluginMsg_ShouldAcceptTouchEvents, | |
47 OnShouldAcceptTouchEvents) | |
48 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStart, OnLoadStart) | |
49 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadAbort, OnLoadAbort) | |
50 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadRedirect, OnLoadRedirect) | |
51 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadCommit, OnLoadCommit) | |
52 IPC_MESSAGE_HANDLER(BrowserPluginMsg_LoadStop, OnLoadStop) | |
53 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SetCursor, OnSetCursor) | |
54 IPC_MESSAGE_HANDLER(BrowserPluginMsg_PluginAtPositionRequest, | 52 IPC_MESSAGE_HANDLER(BrowserPluginMsg_PluginAtPositionRequest, |
55 OnPluginAtPositionRequest); | 53 OnPluginAtPositionRequest); |
56 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestUnresponsive, OnGuestUnresponsive) | |
57 IPC_MESSAGE_HANDLER(BrowserPluginMsg_GuestResponsive, OnGuestResponsive) | |
58 IPC_MESSAGE_UNHANDLED(handled = false) | 54 IPC_MESSAGE_UNHANDLED(handled = false) |
59 IPC_END_MESSAGE_MAP() | 55 IPC_END_MESSAGE_MAP() |
60 return handled; | 56 return handled; |
61 } | 57 } |
62 | 58 |
63 void BrowserPluginManagerImpl::OnPluginAtPositionRequest( | 59 void BrowserPluginManagerImpl::OnPluginAtPositionRequest( |
64 const IPC::Message& message, | 60 const IPC::Message& message, |
65 int request_id, | 61 int request_id, |
66 const gfx::Point& position) { | 62 const gfx::Point& position) { |
67 int instance_id = -1; | 63 int instance_id = -1; |
(...skipping 13 matching lines...) Expand all Loading... | |
81 it.Advance(); | 77 it.Advance(); |
82 } | 78 } |
83 | 79 |
84 Send(new BrowserPluginHostMsg_PluginAtPositionResponse( | 80 Send(new BrowserPluginHostMsg_PluginAtPositionResponse( |
85 source_routing_id, | 81 source_routing_id, |
86 instance_id, | 82 instance_id, |
87 request_id, | 83 request_id, |
88 local_position)); | 84 local_position)); |
89 } | 85 } |
90 | 86 |
91 void BrowserPluginManagerImpl::OnUpdateRect( | 87 void BrowserPluginManagerImpl::RegisterBrowserPluginMessages() { |
Charlie Reis
2012/12/14 19:16:36
Instead of holding a set, just use a switch statem
Fady Samuel
2012/12/14 19:34:08
I made this a set rather than a static switch stat
Charlie Reis
2012/12/14 19:40:32
That doesn't imply that you need a set at runtime,
| |
92 int instance_id, | 88 browser_plugin_messages_.insert(BrowserPluginMsg_UpdateRect::ID); |
93 int message_id, | 89 browser_plugin_messages_.insert(BrowserPluginMsg_GuestGone::ID); |
94 const BrowserPluginMsg_UpdateRect_Params& params) { | 90 browser_plugin_messages_.insert(BrowserPluginMsg_AdvanceFocus::ID); |
95 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | 91 browser_plugin_messages_.insert(BrowserPluginMsg_GuestContentWindowReady::ID); |
96 if (plugin) | 92 browser_plugin_messages_.insert(BrowserPluginMsg_ShouldAcceptTouchEvents::ID); |
97 plugin->UpdateRect(message_id, params); | 93 browser_plugin_messages_.insert(BrowserPluginMsg_LoadStart::ID); |
94 browser_plugin_messages_.insert(BrowserPluginMsg_LoadAbort::ID); | |
95 browser_plugin_messages_.insert(BrowserPluginMsg_LoadRedirect::ID); | |
96 browser_plugin_messages_.insert(BrowserPluginMsg_LoadCommit::ID); | |
97 browser_plugin_messages_.insert(BrowserPluginMsg_LoadStop::ID); | |
98 browser_plugin_messages_.insert(BrowserPluginMsg_SetCursor::ID); | |
99 browser_plugin_messages_.insert(BrowserPluginMsg_GuestUnresponsive::ID); | |
100 browser_plugin_messages_.insert(BrowserPluginMsg_GuestResponsive::ID); | |
98 } | 101 } |
99 | 102 |
100 void BrowserPluginManagerImpl::OnGuestGone(int instance_id, | |
101 int process_id, | |
102 int status) { | |
103 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | |
104 if (plugin) | |
105 plugin->GuestGone(process_id, static_cast<base::TerminationStatus>(status)); | |
106 } | |
107 | |
108 void BrowserPluginManagerImpl::OnAdvanceFocus(int instance_id, bool reverse) { | |
109 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | |
110 if (plugin) | |
111 plugin->AdvanceFocus(reverse); | |
112 } | |
113 | |
114 void BrowserPluginManagerImpl::OnGuestContentWindowReady(int instance_id, | |
115 int guest_routing_id) { | |
116 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | |
117 if (plugin) | |
118 plugin->GuestContentWindowReady(guest_routing_id); | |
119 } | |
120 | |
121 void BrowserPluginManagerImpl::OnShouldAcceptTouchEvents(int instance_id, | |
122 bool accept) { | |
123 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | |
124 if (plugin) | |
125 plugin->SetAcceptTouchEvents(accept); | |
126 } | |
127 | |
128 void BrowserPluginManagerImpl::OnLoadStart(int instance_id, | |
129 const GURL& url, | |
130 bool is_top_level) { | |
131 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | |
132 if (plugin) | |
133 plugin->LoadStart(url, is_top_level); | |
134 } | |
135 | |
136 void BrowserPluginManagerImpl::OnLoadCommit( | |
137 int instance_id, | |
138 const BrowserPluginMsg_LoadCommit_Params& params) { | |
139 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | |
140 if (plugin) | |
141 plugin->LoadCommit(params); | |
142 } | |
143 | |
144 void BrowserPluginManagerImpl::OnLoadStop(int instance_id) { | |
145 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | |
146 if (plugin) | |
147 plugin->LoadStop(); | |
148 } | |
149 | |
150 void BrowserPluginManagerImpl::OnLoadAbort(int instance_id, | |
151 const GURL& url, | |
152 bool is_top_level, | |
153 const std::string& type) { | |
154 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | |
155 if (plugin) | |
156 plugin->LoadAbort(url, is_top_level, type); | |
157 } | |
158 | |
159 void BrowserPluginManagerImpl::OnLoadRedirect(int instance_id, | |
160 const GURL& old_url, | |
161 const GURL& new_url, | |
162 bool is_top_level) { | |
163 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | |
164 if (plugin) | |
165 plugin->LoadRedirect(old_url, new_url, is_top_level); | |
166 } | |
167 | |
168 void BrowserPluginManagerImpl::OnSetCursor(int instance_id, | |
169 const WebCursor& cursor) { | |
170 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | |
171 if (plugin) | |
172 plugin->SetCursor(cursor); | |
173 } | |
174 | |
175 void BrowserPluginManagerImpl::OnGuestUnresponsive(int instance_id, | |
176 int process_id) { | |
177 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | |
178 if (plugin) | |
179 plugin->GuestUnresponsive(process_id); | |
180 } | |
181 | |
182 void BrowserPluginManagerImpl::OnGuestResponsive(int instance_id, | |
183 int process_id) { | |
184 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | |
185 if (plugin) | |
186 plugin->GuestResponsive(process_id); | |
187 } | |
188 } // namespace content | 103 } // namespace content |
OLD | NEW |