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_guest.h" | 5 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 // Create a RenderFrameProxyHost for the guest in the embedder renderer | 128 // Create a RenderFrameProxyHost for the guest in the embedder renderer |
129 // process, so that the embedder can access the guest's window object. | 129 // process, so that the embedder can access the guest's window object. |
130 // On reattachment, we can reuse the same RenderFrameProxyHost because | 130 // On reattachment, we can reuse the same RenderFrameProxyHost because |
131 // the embedder process will always be the same even if the embedder | 131 // the embedder process will always be the same even if the embedder |
132 // WebContents changes. | 132 // WebContents changes. |
133 // | 133 // |
134 // TODO(fsamuel): Make sure this works for transferring guests across | 134 // TODO(fsamuel): Make sure this works for transferring guests across |
135 // owners in different processes. We probably need to clear the | 135 // owners in different processes. We probably need to clear the |
136 // |guest_proxy_routing_id_| and perform any necessary cleanup on Detach | 136 // |guest_proxy_routing_id_| and perform any necessary cleanup on Detach |
137 // to enable this. | 137 // to enable this. |
138 SiteInstance* owner_site_instance = owner_web_contents_->GetSiteInstance(); | 138 SiteInstance* owner_site_instance = |
139 int proxy_routing_id = | 139 GetEmbedderFrame()->render_view_host()->GetSiteInstance(); |
140 GetWebContents()->GetFrameTree()->root()->render_manager()-> | 140 int proxy_routing_id = GetWebContents() |
141 CreateRenderFrameProxy(owner_site_instance); | 141 ->GetFrameTree() |
142 ->root() | |
143 ->render_manager() | |
144 ->CreateRenderFrameProxy(owner_site_instance); | |
142 guest_proxy_routing_id_ = RenderFrameProxyHost::FromID( | 145 guest_proxy_routing_id_ = RenderFrameProxyHost::FromID( |
143 owner_site_instance->GetProcess()->GetID(), proxy_routing_id) | 146 owner_site_instance->GetProcess()->GetID(), proxy_routing_id) |
144 ->GetRenderViewHost()->GetRoutingID(); | 147 ->GetRenderViewHost()->GetRoutingID(); |
145 | 148 |
146 return guest_proxy_routing_id_; | 149 return guest_proxy_routing_id_; |
147 } | 150 } |
148 | 151 |
149 int BrowserPluginGuest::LoadURLWithParams( | 152 int BrowserPluginGuest::LoadURLWithParams( |
150 const NavigationController::LoadURLParams& load_params) { | 153 const NavigationController::LoadURLParams& load_params) { |
151 GetWebContents()->GetController().LoadURLWithParams(load_params); | 154 GetWebContents()->GetController().LoadURLWithParams(load_params); |
(...skipping 10 matching lines...) Expand all Loading... | |
162 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) { | 165 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) { |
163 GetWebContents()->GetView()->SizeContents(new_size); | 166 GetWebContents()->GetView()->SizeContents(new_size); |
164 } | 167 } |
165 | 168 |
166 void BrowserPluginGuest::WillDestroy() { | 169 void BrowserPluginGuest::WillDestroy() { |
167 is_in_destruction_ = true; | 170 is_in_destruction_ = true; |
168 owner_web_contents_ = nullptr; | 171 owner_web_contents_ = nullptr; |
169 attached_ = false; | 172 attached_ = false; |
170 } | 173 } |
171 | 174 |
175 RenderFrameHostImpl* BrowserPluginGuest::GetEmbedderFrame() const { | |
176 return static_cast<RenderFrameHostImpl*>(delegate_->GetEmbedderFrame()); | |
177 } | |
178 | |
172 void BrowserPluginGuest::Init() { | 179 void BrowserPluginGuest::Init() { |
173 if (initialized_) | 180 if (initialized_) |
174 return; | 181 return; |
175 initialized_ = true; | 182 initialized_ = true; |
176 | 183 |
177 // TODO(fsamuel): Initiailization prior to attachment should be behind a | 184 // TODO(fsamuel): Initiailization prior to attachment should be behind a |
178 // command line flag once we introduce experimental guest types that rely on | 185 // command line flag once we introduce experimental guest types that rely on |
179 // this functionality. | 186 // this functionality. |
180 if (!delegate_->CanRunInDetachedState()) | 187 if (!delegate_->CanRunInDetachedState()) |
181 return; | 188 return; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params)); | 241 static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params)); |
235 DCHECK(new_contents); | 242 DCHECK(new_contents); |
236 return new_contents; | 243 return new_contents; |
237 } | 244 } |
238 | 245 |
239 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( | 246 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
240 const IPC::Message& message) { | 247 const IPC::Message& message) { |
241 RenderWidgetHostViewGuest* rwhv = static_cast<RenderWidgetHostViewGuest*>( | 248 RenderWidgetHostViewGuest* rwhv = static_cast<RenderWidgetHostViewGuest*>( |
242 web_contents()->GetRenderWidgetHostView()); | 249 web_contents()->GetRenderWidgetHostView()); |
243 // Until the guest is attached, it should not be handling input events. | 250 // Until the guest is attached, it should not be handling input events. |
244 if (attached() && rwhv && | 251 if (attached() && rwhv && GetEmbedderFrame() && |
wjmaclean
2016/10/20 14:47:22
nit: Instead of the repeated calls to GetEmbedderF
EhsanK
2016/10/20 21:41:18
Acknowledged.
| |
252 GetEmbedderFrame()->GetRenderWidgetHost() && | |
245 rwhv->OnMessageReceivedFromEmbedder( | 253 rwhv->OnMessageReceivedFromEmbedder( |
246 message, | 254 message, RenderWidgetHostImpl::From( |
247 RenderWidgetHostImpl::From( | 255 GetEmbedderFrame()->GetRenderWidgetHost()))) { |
248 embedder_web_contents()->GetRenderViewHost()->GetWidget()))) { | |
249 return true; | 256 return true; |
250 } | 257 } |
251 | 258 |
252 bool handled = true; | 259 bool handled = true; |
253 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 260 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
254 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Detach, OnDetach) | 261 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Detach, OnDetach) |
255 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, | 262 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, |
256 OnDragStatusUpdate) | 263 OnDragStatusUpdate) |
257 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand, | 264 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand, |
258 OnExecuteEditCommand) | 265 OnExecuteEditCommand) |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 } | 373 } |
367 | 374 |
368 // static | 375 // static |
369 bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) { | 376 bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) { |
370 return render_view_host && IsGuest( | 377 return render_view_host && IsGuest( |
371 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost( | 378 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost( |
372 render_view_host))); | 379 render_view_host))); |
373 } | 380 } |
374 | 381 |
375 RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() { | 382 RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() { |
376 if (!owner_web_contents_) | 383 if (GetEmbedderFrame()) |
377 return nullptr; | 384 return GetEmbedderFrame()->GetView(); |
378 return owner_web_contents_->GetRenderWidgetHostView(); | 385 |
386 return nullptr; | |
379 } | 387 } |
380 | 388 |
381 void BrowserPluginGuest::UpdateVisibility() { | 389 void BrowserPluginGuest::UpdateVisibility() { |
382 OnSetVisibility(browser_plugin_instance_id(), visible()); | 390 OnSetVisibility(browser_plugin_instance_id(), visible()); |
383 } | 391 } |
384 | 392 |
385 BrowserPluginGuestManager* | 393 BrowserPluginGuestManager* |
386 BrowserPluginGuest::GetBrowserPluginGuestManager() const { | 394 BrowserPluginGuest::GetBrowserPluginGuestManager() const { |
387 return GetWebContents()->GetBrowserContext()->GetGuestManager(); | 395 return GetWebContents()->GetBrowserContext()->GetGuestManager(); |
388 } | 396 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 bool BrowserPluginGuest::HandleStopFindingForEmbedder(StopFindAction action) { | 448 bool BrowserPluginGuest::HandleStopFindingForEmbedder(StopFindAction action) { |
441 return delegate_->HandleStopFindingForEmbedder(action); | 449 return delegate_->HandleStopFindingForEmbedder(action); |
442 } | 450 } |
443 | 451 |
444 void BrowserPluginGuest::ResendEventToEmbedder( | 452 void BrowserPluginGuest::ResendEventToEmbedder( |
445 const blink::WebInputEvent& event) { | 453 const blink::WebInputEvent& event) { |
446 if (!attached() || !owner_web_contents_) | 454 if (!attached() || !owner_web_contents_) |
447 return; | 455 return; |
448 | 456 |
449 DCHECK(browser_plugin_instance_id_); | 457 DCHECK(browser_plugin_instance_id_); |
450 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( | 458 RenderWidgetHostViewBase* view = |
451 embedder_web_contents()->GetMainFrame()->GetView()); | 459 static_cast<RenderWidgetHostViewBase*>(GetEmbedderFrame()->GetView()); |
452 | 460 |
453 gfx::Vector2d offset_from_embedder = guest_window_rect_.OffsetFromOrigin(); | 461 gfx::Vector2d offset_from_embedder = guest_window_rect_.OffsetFromOrigin(); |
454 if (event.type == blink::WebInputEvent::GestureScrollUpdate) { | 462 if (event.type == blink::WebInputEvent::GestureScrollUpdate) { |
455 blink::WebGestureEvent resent_gesture_event; | 463 blink::WebGestureEvent resent_gesture_event; |
456 memcpy(&resent_gesture_event, &event, sizeof(blink::WebGestureEvent)); | 464 memcpy(&resent_gesture_event, &event, sizeof(blink::WebGestureEvent)); |
457 resent_gesture_event.x += offset_from_embedder.x(); | 465 resent_gesture_event.x += offset_from_embedder.x(); |
458 resent_gesture_event.y += offset_from_embedder.y(); | 466 resent_gesture_event.y += offset_from_embedder.y(); |
459 // Mark the resend source with the browser plugin's instance id, so the | 467 // Mark the resend source with the browser plugin's instance id, so the |
460 // correct browser_plugin will know to ignore the event. | 468 // correct browser_plugin will know to ignore the event. |
461 resent_gesture_event.resendingPluginId = browser_plugin_instance_id_; | 469 resent_gesture_event.resendingPluginId = browser_plugin_instance_id_; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 // in this case just queue any messages we receive. | 505 // in this case just queue any messages we receive. |
498 if (!attached() || !owner_web_contents_) { | 506 if (!attached() || !owner_web_contents_) { |
499 // Some pages such as data URLs, javascript URLs, and about:blank | 507 // Some pages such as data URLs, javascript URLs, and about:blank |
500 // do not load external resources and so they load prior to attachment. | 508 // do not load external resources and so they load prior to attachment. |
501 // As a result, we must save all these IPCs until attachment and then | 509 // As a result, we must save all these IPCs until attachment and then |
502 // forward them so that the embedder gets a chance to see and process | 510 // forward them so that the embedder gets a chance to see and process |
503 // the load events. | 511 // the load events. |
504 pending_messages_.push_back(linked_ptr<IPC::Message>(msg)); | 512 pending_messages_.push_back(linked_ptr<IPC::Message>(msg)); |
505 return; | 513 return; |
506 } | 514 } |
507 owner_web_contents_->Send(msg); | 515 |
516 GetEmbedderFrame()->GetRenderWidgetHost()->Send(msg); | |
508 } | 517 } |
509 | 518 |
510 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, | 519 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, |
511 int screen_x, int screen_y, blink::WebDragOperation operation) { | 520 int screen_x, int screen_y, blink::WebDragOperation operation) { |
512 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, | 521 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, |
513 screen_x, screen_y, operation); | 522 screen_x, screen_y, operation); |
514 seen_embedder_drag_source_ended_at_ = true; | 523 seen_embedder_drag_source_ended_at_ = true; |
515 EndSystemDragIfApplicable(); | 524 EndSystemDragIfApplicable(); |
516 } | 525 } |
517 | 526 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 return handled; | 748 return handled; |
740 #else | 749 #else |
741 return false; | 750 return false; |
742 #endif | 751 #endif |
743 } | 752 } |
744 | 753 |
745 void BrowserPluginGuest::Attach( | 754 void BrowserPluginGuest::Attach( |
746 int browser_plugin_instance_id, | 755 int browser_plugin_instance_id, |
747 WebContentsImpl* embedder_web_contents, | 756 WebContentsImpl* embedder_web_contents, |
748 const BrowserPluginHostMsg_Attach_Params& params) { | 757 const BrowserPluginHostMsg_Attach_Params& params) { |
758 DCHECK_EQ(GetEmbedderFrame()->delegate(), embedder_web_contents); | |
749 browser_plugin_instance_id_ = browser_plugin_instance_id; | 759 browser_plugin_instance_id_ = browser_plugin_instance_id; |
750 // The guest is owned by the embedder. Attach is queued up so we cannot | 760 // The guest is owned by the embedder. Attach is queued up so we cannot |
751 // change embedders before attach completes. If the embedder goes away, | 761 // change embedders before attach completes. If the embedder goes away, |
752 // so does the guest and so we will never call WillAttachComplete because | 762 // so does the guest and so we will never call WillAttachComplete because |
753 // we have a weak ptr. | 763 // we have a weak ptr. |
754 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id, | 764 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id, |
755 params.is_full_page_plugin, | 765 params.is_full_page_plugin, |
756 base::Bind(&BrowserPluginGuest::OnWillAttachComplete, | 766 base::Bind(&BrowserPluginGuest::OnWillAttachComplete, |
757 weak_ptr_factory_.GetWeakPtr(), | 767 weak_ptr_factory_.GetWeakPtr(), |
758 embedder_web_contents, params)); | 768 embedder_web_contents, params)); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1034 range, character_bounds); | 1044 range, character_bounds); |
1035 } | 1045 } |
1036 #endif | 1046 #endif |
1037 | 1047 |
1038 void BrowserPluginGuest::SetContextMenuPosition(const gfx::Point& position) { | 1048 void BrowserPluginGuest::SetContextMenuPosition(const gfx::Point& position) { |
1039 if (delegate_) | 1049 if (delegate_) |
1040 delegate_->SetContextMenuPosition(position); | 1050 delegate_->SetContextMenuPosition(position); |
1041 } | 1051 } |
1042 | 1052 |
1043 } // namespace content | 1053 } // namespace content |
OLD | NEW |