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/browser/browser_plugin/browser_plugin_embedder.h" | 5 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 8 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
9 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 9 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
10 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 // static | 25 // static |
26 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; | 26 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; |
27 | 27 |
28 BrowserPluginEmbedder::BrowserPluginEmbedder( | 28 BrowserPluginEmbedder::BrowserPluginEmbedder( |
29 WebContentsImpl* web_contents, | 29 WebContentsImpl* web_contents, |
30 RenderViewHost* render_view_host) | 30 RenderViewHost* render_view_host) |
31 : WebContentsObserver(web_contents), | 31 : WebContentsObserver(web_contents), |
32 render_view_host_(render_view_host), | 32 render_view_host_(render_view_host), |
33 visible_(true), | 33 visible_(true), |
34 next_get_render_view_request_id_(0) { | 34 next_get_render_view_request_id_(0), |
| 35 next_instance_id_(0) { |
35 // Listen to visibility changes so that an embedder hides its guests | 36 // Listen to visibility changes so that an embedder hides its guests |
36 // as well. | 37 // as well. |
37 registrar_.Add(this, | 38 registrar_.Add(this, |
38 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 39 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
39 Source<WebContents>(web_contents)); | 40 Source<WebContents>(web_contents)); |
40 } | 41 } |
41 | 42 |
42 BrowserPluginEmbedder::~BrowserPluginEmbedder() { | 43 BrowserPluginEmbedder::~BrowserPluginEmbedder() { |
43 CleanUp(); | 44 CleanUp(); |
44 } | 45 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 149 |
149 // Create a swapped out RenderView for the guest in the embedder render | 150 // Create a swapped out RenderView for the guest in the embedder render |
150 // process, so that the embedder can access the guest's window object. | 151 // process, so that the embedder can access the guest's window object. |
151 int guest_routing_id = | 152 int guest_routing_id = |
152 static_cast<WebContentsImpl*>(guest->GetWebContents())-> | 153 static_cast<WebContentsImpl*>(guest->GetWebContents())-> |
153 CreateSwappedOutRenderView(web_contents()->GetSiteInstance()); | 154 CreateSwappedOutRenderView(web_contents()->GetSiteInstance()); |
154 render_view_host_->Send(new BrowserPluginMsg_GuestContentWindowReady( | 155 render_view_host_->Send(new BrowserPluginMsg_GuestContentWindowReady( |
155 render_view_host_->GetRoutingID(), instance_id, guest_routing_id)); | 156 render_view_host_->GetRoutingID(), instance_id, guest_routing_id)); |
156 | 157 |
157 guest->Initialize(params, guest_web_contents->GetRenderViewHost()); | 158 guest->Initialize(params, guest_web_contents->GetRenderViewHost()); |
| 159 |
| 160 if (params.src.empty()) |
| 161 return; |
| 162 |
| 163 BrowserPluginHostMsg_NavigateGuest navigate_msg( |
| 164 render_view_host_->GetRoutingID(), instance_id, params.src); |
| 165 GetGuestByInstanceID(instance_id)-> |
| 166 OnMessageReceivedFromEmbedder(navigate_msg); |
158 } | 167 } |
159 | 168 |
160 BrowserPluginGuest* BrowserPluginEmbedder::GetGuestByInstanceID( | 169 BrowserPluginGuest* BrowserPluginEmbedder::GetGuestByInstanceID( |
161 int instance_id) const { | 170 int instance_id) const { |
162 ContainerInstanceMap::const_iterator it = | 171 ContainerInstanceMap::const_iterator it = |
163 guest_web_contents_by_instance_id_.find(instance_id); | 172 guest_web_contents_by_instance_id_.find(instance_id); |
164 if (it != guest_web_contents_by_instance_id_.end()) | 173 if (it != guest_web_contents_by_instance_id_.end()) |
165 return static_cast<WebContentsImpl*>(it->second)->GetBrowserPluginGuest(); | 174 return static_cast<WebContentsImpl*>(it->second)->GetBrowserPluginGuest(); |
166 return NULL; | 175 return NULL; |
167 } | 176 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // All allowed messages must have instance_id as their first parameter. | 213 // All allowed messages must have instance_id as their first parameter. |
205 PickleIterator iter(message); | 214 PickleIterator iter(message); |
206 bool success = iter.ReadInt(&instance_id); | 215 bool success = iter.ReadInt(&instance_id); |
207 DCHECK(success); | 216 DCHECK(success); |
208 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); | 217 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
209 if (guest && guest->OnMessageReceivedFromEmbedder(message)) | 218 if (guest && guest->OnMessageReceivedFromEmbedder(message)) |
210 return true; | 219 return true; |
211 } | 220 } |
212 bool handled = true; | 221 bool handled = true; |
213 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) | 222 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) |
| 223 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID, |
| 224 OnAllocateInstanceID) |
214 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CreateGuest, | 225 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CreateGuest, |
215 OnCreateGuest) | 226 OnCreateGuest) |
216 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginAtPositionResponse, | 227 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginAtPositionResponse, |
217 OnPluginAtPositionResponse) | 228 OnPluginAtPositionResponse) |
218 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, | 229 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, |
219 OnPluginDestroyed) | 230 OnPluginDestroyed) |
220 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_BuffersSwappedACK, | 231 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_BuffersSwappedACK, |
221 OnSwapBuffersACK) | 232 OnSwapBuffersACK) |
222 IPC_MESSAGE_UNHANDLED(handled = false) | 233 IPC_MESSAGE_UNHANDLED(handled = false) |
223 IPC_END_MESSAGE_MAP() | 234 IPC_END_MESSAGE_MAP() |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 case BrowserPluginHostMsg_Stop::ID: | 298 case BrowserPluginHostMsg_Stop::ID: |
288 case BrowserPluginHostMsg_TerminateGuest::ID: | 299 case BrowserPluginHostMsg_TerminateGuest::ID: |
289 case BrowserPluginHostMsg_UpdateRect_ACK::ID: | 300 case BrowserPluginHostMsg_UpdateRect_ACK::ID: |
290 return true; | 301 return true; |
291 default: | 302 default: |
292 break; | 303 break; |
293 } | 304 } |
294 return false; | 305 return false; |
295 } | 306 } |
296 | 307 |
| 308 void BrowserPluginEmbedder::OnAllocateInstanceID(int request_id) { |
| 309 int instance_id = ++next_instance_id_; |
| 310 render_view_host_->Send(new BrowserPluginMsg_AllocateInstanceID_ACK( |
| 311 render_view_host_->GetRoutingID(), request_id, instance_id)); |
| 312 } |
| 313 |
297 void BrowserPluginEmbedder::OnCreateGuest( | 314 void BrowserPluginEmbedder::OnCreateGuest( |
298 int instance_id, | 315 int instance_id, |
299 const BrowserPluginHostMsg_CreateGuest_Params& params) { | 316 const BrowserPluginHostMsg_CreateGuest_Params& params) { |
300 CreateGuest(instance_id, MSG_ROUTING_NONE, NULL, params); | 317 CreateGuest(instance_id, MSG_ROUTING_NONE, NULL, params); |
301 } | 318 } |
302 | 319 |
303 void BrowserPluginEmbedder::OnPluginAtPositionResponse( | 320 void BrowserPluginEmbedder::OnPluginAtPositionResponse( |
304 int instance_id, int request_id, const gfx::Point& position) { | 321 int instance_id, int request_id, const gfx::Point& position) { |
305 const std::map<int, WebContents::GetRenderViewHostCallback>::iterator | 322 const std::map<int, WebContents::GetRenderViewHostCallback>::iterator |
306 callback_iter = pending_get_render_view_callbacks_.find(request_id); | 323 callback_iter = pending_get_render_view_callbacks_.find(request_id); |
(...skipping 21 matching lines...) Expand all Loading... |
328 uint32 sync_point) { | 345 uint32 sync_point) { |
329 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | 346 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; |
330 ack_params.mailbox_name = mailbox_name; | 347 ack_params.mailbox_name = mailbox_name; |
331 ack_params.sync_point = sync_point; | 348 ack_params.sync_point = sync_point; |
332 RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id, | 349 RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id, |
333 gpu_host_id, | 350 gpu_host_id, |
334 ack_params); | 351 ack_params); |
335 } | 352 } |
336 | 353 |
337 } // namespace content | 354 } // namespace content |
OLD | NEW |