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 } | 18 } |
19 | 19 |
20 BrowserPluginManagerImpl::~BrowserPluginManagerImpl() { | 20 BrowserPluginManagerImpl::~BrowserPluginManagerImpl() { |
21 } | 21 } |
22 | 22 |
23 BrowserPlugin* BrowserPluginManagerImpl::CreateBrowserPlugin( | 23 BrowserPlugin* BrowserPluginManagerImpl::CreateBrowserPlugin( |
24 RenderViewImpl* render_view, | 24 RenderViewImpl* render_view, |
25 WebKit::WebFrame* frame, | 25 WebKit::WebFrame* frame, |
26 const WebKit::WebPluginParams& params) { | 26 const WebKit::WebPluginParams& params) { |
27 return new BrowserPlugin(browser_plugin_counter_++, | 27 return new BrowserPlugin(++browser_plugin_counter_, |
28 render_view, | 28 render_view, |
29 frame, | 29 frame, |
30 params); | 30 params); |
31 } | 31 } |
32 | 32 |
33 bool BrowserPluginManagerImpl::Send(IPC::Message* msg) { | 33 bool BrowserPluginManagerImpl::Send(IPC::Message* msg) { |
34 return RenderThread::Get()->Send(msg); | 34 return RenderThread::Get()->Send(msg); |
35 } | 35 } |
36 | 36 |
37 bool BrowserPluginManagerImpl::OnMessageReceived( | 37 bool BrowserPluginManagerImpl::OnMessageReceived( |
38 const IPC::Message& message) { | 38 const IPC::Message& message) { |
| 39 if (ShouldForwardToBrowserPlugin(message)) { |
| 40 int instance_id = 0; |
| 41 // All allowed messages must have instance_id as their first parameter. |
| 42 PickleIterator iter(message); |
| 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 // static |
92 int instance_id, | 88 bool BrowserPluginManagerImpl::ShouldForwardToBrowserPlugin( |
93 int message_id, | 89 const IPC::Message& message) { |
94 const BrowserPluginMsg_UpdateRect_Params& params) { | 90 switch (message.type()) { |
95 BrowserPlugin* plugin = GetBrowserPlugin(instance_id); | 91 case BrowserPluginMsg_UpdateRect::ID: |
96 if (plugin) | 92 case BrowserPluginMsg_GuestGone::ID: |
97 plugin->UpdateRect(message_id, params); | 93 case BrowserPluginMsg_AdvanceFocus::ID: |
| 94 case BrowserPluginMsg_GuestContentWindowReady::ID: |
| 95 case BrowserPluginMsg_ShouldAcceptTouchEvents::ID: |
| 96 case BrowserPluginMsg_LoadStart::ID: |
| 97 case BrowserPluginMsg_LoadAbort::ID: |
| 98 case BrowserPluginMsg_LoadRedirect::ID: |
| 99 case BrowserPluginMsg_LoadCommit::ID: |
| 100 case BrowserPluginMsg_LoadStop::ID: |
| 101 case BrowserPluginMsg_SetCursor::ID: |
| 102 case BrowserPluginMsg_GuestUnresponsive::ID: |
| 103 case BrowserPluginMsg_GuestResponsive::ID: |
| 104 return true; |
| 105 default: |
| 106 break; |
| 107 } |
| 108 return false; |
98 } | 109 } |
99 | 110 |
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 | 111 } // namespace content |
OLD | NEW |