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 <set> | 7 #include <set> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "content/browser/browser_plugin/browser_plugin_embedder_helper.h" | 12 #include "content/browser/browser_plugin/browser_plugin_embedder_helper.h" |
13 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 13 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
14 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" | |
14 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 15 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
15 #include "content/browser/renderer_host/render_view_host_impl.h" | 16 #include "content/browser/renderer_host/render_view_host_impl.h" |
16 #include "content/browser/web_contents/web_contents_impl.h" | 17 #include "content/browser/web_contents/web_contents_impl.h" |
17 #include "content/common/browser_plugin_messages.h" | 18 #include "content/common/browser_plugin_messages.h" |
19 #include "content/common/view_messages.h" | |
18 #include "content/public/browser/notification_details.h" | 20 #include "content/public/browser/notification_details.h" |
19 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
21 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
22 #include "content/public/browser/web_contents_view.h" | 24 #include "content/public/browser/web_contents_view.h" |
23 #include "content/public/common/url_constants.h" | 25 #include "content/public/common/url_constants.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
25 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
26 #include "ui/surface/transport_dib.h" | 28 #include "ui/surface/transport_dib.h" |
27 | 29 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 static_cast<WebContentsImpl*>(guest->GetWebContents()); | 124 static_cast<WebContentsImpl*>(guest->GetWebContents()); |
123 | 125 |
124 // We ignore loading empty urls in web_contents. | 126 // We ignore loading empty urls in web_contents. |
125 // If a guest sets empty src attribute after it has navigated to some | 127 // If a guest sets empty src attribute after it has navigated to some |
126 // non-empty page, the action is considered no-op. | 128 // non-empty page, the action is considered no-op. |
127 // TODO(lazyboy): The js shim for browser-plugin might need to reflect empty | 129 // TODO(lazyboy): The js shim for browser-plugin might need to reflect empty |
128 // src ignoring in the shadow DOM element: http://crbug.com/149001. | 130 // src ignoring in the shadow DOM element: http://crbug.com/149001. |
129 if (!src.empty()) { | 131 if (!src.empty()) { |
130 guest_web_contents->GetController().LoadURL(url, | 132 guest_web_contents->GetController().LoadURL(url, |
131 Referrer(), | 133 Referrer(), |
132 PAGE_TRANSITION_AUTO_SUBFRAME, | 134 PAGE_TRANSITION_AUTO_TOPLEVEL, |
133 std::string()); | 135 std::string()); |
134 } | 136 } |
135 | 137 |
138 // Prepare the swapped out RenderView for the guest in the embedder process | |
nasko
2012/10/02 17:52:31
Shouldn't that code move to the new _CreateGuest m
Fady Samuel
2012/10/02 22:04:08
The first block can be. The second block cannot be
| |
139 // and the swapped out RenderView for the embedder in the guest render process | |
140 // to enable two-way postMessage. | |
141 SiteInstance* guest_site_instance = guest_web_contents->GetSiteInstance(); | |
142 // Create a swapped out RenderView for the embedder in the guest render | |
143 // process if it does not already exist. | |
144 if (guest->swapped_out_guest_routing_id() == MSG_ROUTING_NONE) { | |
145 guest->set_swapped_out_guest_routing_id( | |
146 static_cast<WebContentsImpl*>(web_contents())-> | |
147 CreateSwappedOutRenderViewForGuest(guest_site_instance)); | |
148 // Attach a BrowserPluginGuestHelper to the swapped out guest RVH so that it | |
149 // can catch custom IDs. | |
150 RenderViewHostImpl* swapped_out_rvh = RenderViewHostImpl::FromID( | |
151 guest_site_instance->GetProcess()->GetID(), | |
152 guest->swapped_out_guest_routing_id()); | |
153 DCHECK(swapped_out_rvh); | |
154 // |swapped_out_rvh| manages the ownership of this BrowserPluginGuestHelper. | |
155 new BrowserPluginGuestHelper(guest, swapped_out_rvh); | |
156 } | |
157 | |
158 // Create a swapped out RenderView for the guest in the embedder render | |
159 // process, so that the embedder can reply to the guest from the source | |
160 // field in the JS event object. | |
161 if (guest->swapped_out_embedder_routing_id() == MSG_ROUTING_NONE) { | |
162 guest->set_swapped_out_embedder_routing_id( | |
163 static_cast<WebContentsImpl*>(guest->GetWebContents())-> | |
164 CreateSwappedOutRenderViewForGuest( | |
165 web_contents()->GetSiteInstance())); | |
166 // Attach a BrowserPluginEmbedderHelper to the swapped out embedder RVH | |
167 // so that it can catch custom IDs. | |
168 RenderViewHostImpl* swapped_out_rvh = RenderViewHostImpl::FromID( | |
169 web_contents()->GetRenderProcessHost()->GetID(), | |
170 guest->swapped_out_embedder_routing_id()); | |
171 DCHECK(swapped_out_rvh); | |
172 // |swapped_out_rvh| manages the ownership of this | |
173 // BrowserPluginEmbedderHelper. | |
174 new BrowserPluginEmbedderHelper(this, swapped_out_rvh); | |
175 // Tell the embedder about its routing ID so it can use its content window. | |
176 render_view_host->Send(new BrowserPluginMsg_GuestContentWindowReady( | |
177 instance_id, | |
178 guest->swapped_out_embedder_routing_id())); | |
179 } | |
180 | |
136 // Resize the guest if the resize parameter was set from the renderer. | 181 // Resize the guest if the resize parameter was set from the renderer. |
137 ResizeGuest(render_view_host, instance_id, resize_params); | 182 ResizeGuest(render_view_host, instance_id, resize_params); |
138 } | 183 } |
139 | 184 |
140 void BrowserPluginEmbedder::UpdateRectACK(int instance_id, | 185 void BrowserPluginEmbedder::UpdateRectACK(int instance_id, |
141 int message_id, | 186 int message_id, |
142 const gfx::Size& size) { | 187 const gfx::Size& size) { |
143 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); | 188 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
144 if (guest) | 189 if (guest) |
145 guest->UpdateRectACK(message_id, size); | 190 guest->UpdateRectACK(message_id, size); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 WebContents* guest_web_contents = guest->GetWebContents(); | 279 WebContents* guest_web_contents = guest->GetWebContents(); |
235 | 280 |
236 // Destroy the guest's web_contents. | 281 // Destroy the guest's web_contents. |
237 delete guest_web_contents; | 282 delete guest_web_contents; |
238 guest_web_contents_by_instance_id_.erase(instance_id); | 283 guest_web_contents_by_instance_id_.erase(instance_id); |
239 } | 284 } |
240 } | 285 } |
241 | 286 |
242 void BrowserPluginEmbedder::RenderViewDeleted( | 287 void BrowserPluginEmbedder::RenderViewDeleted( |
243 RenderViewHost* render_view_host) { | 288 RenderViewHost* render_view_host) { |
244 DestroyGuests(); | |
245 } | 289 } |
246 | 290 |
247 void BrowserPluginEmbedder::RenderViewGone(base::TerminationStatus status) { | 291 void BrowserPluginEmbedder::RenderViewGone(base::TerminationStatus status) { |
248 DestroyGuests(); | 292 DestroyGuests(); |
249 } | 293 } |
250 | 294 |
251 void BrowserPluginEmbedder::WebContentsVisibilityChanged(bool visible) { | 295 void BrowserPluginEmbedder::WebContentsVisibilityChanged(bool visible) { |
252 // If the embedder is hidden we need to hide the guests as well. | 296 // If the embedder is hidden we need to hide the guests as well. |
253 for (ContainerInstanceMap::const_iterator it = | 297 for (ContainerInstanceMap::const_iterator it = |
254 guest_web_contents_by_instance_id_.begin(); | 298 guest_web_contents_by_instance_id_.begin(); |
255 it != guest_web_contents_by_instance_id_.end(); ++it) { | 299 it != guest_web_contents_by_instance_id_.end(); ++it) { |
256 WebContents* web_contents = it->second; | 300 WebContents* web_contents = it->second; |
257 if (visible) | 301 if (visible) |
258 web_contents->WasShown(); | 302 web_contents->WasShown(); |
259 else | 303 else |
260 web_contents->WasHidden(); | 304 web_contents->WasHidden(); |
261 } | 305 } |
262 } | 306 } |
263 | 307 |
264 void BrowserPluginEmbedder::PluginDestroyed(int instance_id) { | 308 void BrowserPluginEmbedder::PluginDestroyed(int instance_id) { |
265 DestroyGuestByInstanceID(instance_id); | 309 DestroyGuestByInstanceID(instance_id); |
266 } | 310 } |
267 | 311 |
312 void BrowserPluginEmbedder::RouteMessageEvent( | |
313 int instance_id, | |
314 const string16& data, | |
315 int source_frame_id, | |
316 const string16& target_origin, | |
317 int target_frame_id) { | |
318 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); | |
319 if (!guest) | |
320 return; | |
321 | |
322 WebContentsImpl* guest_web_contents = | |
323 static_cast<WebContentsImpl*>(guest->GetWebContents()); | |
324 | |
325 ViewMsg_PostMessage_Params new_params; | |
326 new_params.data = data; | |
327 new_params.target_origin = target_origin; | |
328 new_params.target_frame_id = target_frame_id; | |
329 new_params.source_frame_id = source_frame_id; | |
330 | |
331 DCHECK(guest->swapped_out_guest_routing_id() != MSG_ROUTING_NONE); | |
332 new_params.source_routing_id = guest->swapped_out_guest_routing_id(); | |
333 | |
334 guest_web_contents->GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent( | |
335 guest_web_contents->GetRenderViewHost()->GetRoutingID(), new_params)); | |
336 } | |
337 | |
268 void BrowserPluginEmbedder::Go(int instance_id, int relative_index) { | 338 void BrowserPluginEmbedder::Go(int instance_id, int relative_index) { |
269 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); | 339 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
270 if (guest) | 340 if (guest) |
271 guest->Go(relative_index); | 341 guest->Go(relative_index); |
272 } | 342 } |
273 | 343 |
274 void BrowserPluginEmbedder::Stop(int instance_id) { | 344 void BrowserPluginEmbedder::Stop(int instance_id) { |
275 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); | 345 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
276 if (guest) | 346 if (guest) |
277 guest->Stop(); | 347 guest->Stop(); |
(...skipping 13 matching lines...) Expand all Loading... | |
291 bool visible = *Details<bool>(details).ptr(); | 361 bool visible = *Details<bool>(details).ptr(); |
292 WebContentsVisibilityChanged(visible); | 362 WebContentsVisibilityChanged(visible); |
293 break; | 363 break; |
294 } | 364 } |
295 default: | 365 default: |
296 NOTREACHED() << "Unexpected notification type: " << type; | 366 NOTREACHED() << "Unexpected notification type: " << type; |
297 } | 367 } |
298 } | 368 } |
299 | 369 |
300 } // namespace content | 370 } // namespace content |
OLD | NEW |