Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.cc

Issue 2417693002: Allow MimeHandlerViewGuest be embedded inside OOPIFs (Closed)
Patch Set: Added a NOTREACHED Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 has_render_view_(has_render_view), 100 has_render_view_(has_render_view),
101 is_in_destruction_(false), 101 is_in_destruction_(false),
102 initialized_(false), 102 initialized_(false),
103 guest_proxy_routing_id_(MSG_ROUTING_NONE), 103 guest_proxy_routing_id_(MSG_ROUTING_NONE),
104 last_drag_status_(blink::WebDragStatusUnknown), 104 last_drag_status_(blink::WebDragStatusUnknown),
105 seen_embedder_system_drag_ended_(false), 105 seen_embedder_system_drag_ended_(false),
106 seen_embedder_drag_source_ended_at_(false), 106 seen_embedder_drag_source_ended_at_(false),
107 ignore_dragged_url_(true), 107 ignore_dragged_url_(true),
108 delegate_(delegate), 108 delegate_(delegate),
109 can_use_cross_process_frames_(delegate->CanUseCrossProcessFrames()), 109 can_use_cross_process_frames_(delegate->CanUseCrossProcessFrames()),
110 embedder_process_id_(0),
Charlie Reis 2016/10/18 22:52:20 ChildProcessHost::kInvalidUniqueID
EhsanK 2016/10/20 21:41:17 Thanks. Used in mime_handler_view_guest.cc.
111 embedder_routing_id_(MSG_ROUTING_NONE),
110 weak_ptr_factory_(this) { 112 weak_ptr_factory_(this) {
111 DCHECK(web_contents); 113 DCHECK(web_contents);
112 DCHECK(delegate); 114 DCHECK(delegate);
113 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); 115 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create"));
114 web_contents->SetBrowserPluginGuest(this); 116 web_contents->SetBrowserPluginGuest(this);
115 delegate->SetGuestHost(this); 117 delegate->SetGuestHost(this);
116 } 118 }
117 119
118 int BrowserPluginGuest::GetGuestProxyRoutingID() { 120 int BrowserPluginGuest::GetGuestProxyRoutingID() {
119 if (GuestMode::IsCrossProcessFrameGuest(GetWebContents())) { 121 if (GuestMode::IsCrossProcessFrameGuest(GetWebContents())) {
120 // We don't use the proxy to send postMessage in --site-per-process, since 122 // We don't use the proxy to send postMessage in --site-per-process, since
121 // we use the contentWindow directly from the frame element instead. 123 // we use the contentWindow directly from the frame element instead.
122 return MSG_ROUTING_NONE; 124 return MSG_ROUTING_NONE;
123 } 125 }
124 126
125 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE) 127 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE)
126 return guest_proxy_routing_id_; 128 return guest_proxy_routing_id_;
127 129
128 // Create a RenderFrameProxyHost for the guest in the embedder renderer 130 // Create a RenderFrameProxyHost for the guest in the embedder renderer
129 // process, so that the embedder can access the guest's window object. 131 // process, so that the embedder can access the guest's window object.
130 // On reattachment, we can reuse the same RenderFrameProxyHost because 132 // On reattachment, we can reuse the same RenderFrameProxyHost because
131 // the embedder process will always be the same even if the embedder 133 // the embedder process will always be the same even if the embedder
132 // WebContents changes. 134 // WebContents changes.
133 // 135 //
134 // TODO(fsamuel): Make sure this works for transferring guests across 136 // TODO(fsamuel): Make sure this works for transferring guests across
135 // owners in different processes. We probably need to clear the 137 // owners in different processes. We probably need to clear the
136 // |guest_proxy_routing_id_| and perform any necessary cleanup on Detach 138 // |guest_proxy_routing_id_| and perform any necessary cleanup on Detach
137 // to enable this. 139 // to enable this.
138 SiteInstance* owner_site_instance = owner_web_contents_->GetSiteInstance(); 140 SiteInstance* owner_site_instance =
139 int proxy_routing_id = 141 GetEmbedderFrame()->render_view_host()->GetSiteInstance();
140 GetWebContents()->GetFrameTree()->root()->render_manager()-> 142 int proxy_routing_id = GetWebContents()
141 CreateRenderFrameProxy(owner_site_instance); 143 ->GetFrameTree()
144 ->root()
145 ->render_manager()
146 ->CreateRenderFrameProxy(owner_site_instance);
142 guest_proxy_routing_id_ = RenderFrameProxyHost::FromID( 147 guest_proxy_routing_id_ = RenderFrameProxyHost::FromID(
143 owner_site_instance->GetProcess()->GetID(), proxy_routing_id) 148 owner_site_instance->GetProcess()->GetID(), proxy_routing_id)
144 ->GetRenderViewHost()->GetRoutingID(); 149 ->GetRenderViewHost()->GetRoutingID();
145 150
146 return guest_proxy_routing_id_; 151 return guest_proxy_routing_id_;
147 } 152 }
148 153
149 int BrowserPluginGuest::LoadURLWithParams( 154 int BrowserPluginGuest::LoadURLWithParams(
150 const NavigationController::LoadURLParams& load_params) { 155 const NavigationController::LoadURLParams& load_params) {
151 GetWebContents()->GetController().LoadURLWithParams(load_params); 156 GetWebContents()->GetController().LoadURLWithParams(load_params);
(...skipping 10 matching lines...) Expand all
162 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) { 167 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) {
163 GetWebContents()->GetView()->SizeContents(new_size); 168 GetWebContents()->GetView()->SizeContents(new_size);
164 } 169 }
165 170
166 void BrowserPluginGuest::WillDestroy() { 171 void BrowserPluginGuest::WillDestroy() {
167 is_in_destruction_ = true; 172 is_in_destruction_ = true;
168 owner_web_contents_ = nullptr; 173 owner_web_contents_ = nullptr;
169 attached_ = false; 174 attached_ = false;
170 } 175 }
171 176
177 WebContents* BrowserPluginGuest::RegisterEmbedderID(int process_id,
178 int routing_id) {
179 RenderFrameHostImpl* rfh =
180 RenderFrameHostImpl::FromID(process_id, routing_id);
181
182 // Both |process_id| and |routing_id| are reported from the renderer side. For
Charlie Reis 2016/10/18 22:52:20 Renderer processes should never be told process ID
EhsanK 2016/10/20 21:41:17 I see. I moved the logic to initialize the embedde
183 // invalid values, |rfh| will be nullptr.
184 if (!rfh)
185 return nullptr;
186
187 // For now consider the |rfh| as the rightful embedder. The GuestViewManager
188 // will later decide if this |rfh| could be an embedder of the BrowserPlugin.
189 embedder_process_id_ = process_id;
190 embedder_routing_id_ = routing_id;
191
192 return static_cast<WebContentsImpl*>(rfh->delegate());
193 }
194
195 RenderFrameHostImpl* BrowserPluginGuest::GetEmbedderFrame() const {
196 RenderFrameHostImpl* rfh =
197 RenderFrameHostImpl::FromID(embedder_process_id_, embedder_routing_id_);
198
199 // In <webview> we get here before GuestViewManager::AttachGuest is called.
200 // Our best bet for now is to rely on |owner_web_contents_| main frame. This
201 // is incorrect is <webview> is at some point embedded inside an OOPIF.
Charlie Reis 2016/10/18 22:52:20 Typo (too many "is"'s)
EhsanK 2016/10/20 21:41:17 Thanks! This block is removed now however.
202 if (!rfh)
203 rfh = owner_web_contents_ ? owner_web_contents_->GetMainFrame() : nullptr;
204
205 return rfh;
206 }
207
172 void BrowserPluginGuest::Init() { 208 void BrowserPluginGuest::Init() {
173 if (initialized_) 209 if (initialized_)
174 return; 210 return;
175 initialized_ = true; 211 initialized_ = true;
176 212
177 // TODO(fsamuel): Initiailization prior to attachment should be behind a 213 // TODO(fsamuel): Initiailization prior to attachment should be behind a
178 // command line flag once we introduce experimental guest types that rely on 214 // command line flag once we introduce experimental guest types that rely on
179 // this functionality. 215 // this functionality.
180 if (!delegate_->CanRunInDetachedState()) 216 if (!delegate_->CanRunInDetachedState())
181 return; 217 return;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params)); 270 static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params));
235 DCHECK(new_contents); 271 DCHECK(new_contents);
236 return new_contents; 272 return new_contents;
237 } 273 }
238 274
239 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( 275 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder(
240 const IPC::Message& message) { 276 const IPC::Message& message) {
241 RenderWidgetHostViewGuest* rwhv = static_cast<RenderWidgetHostViewGuest*>( 277 RenderWidgetHostViewGuest* rwhv = static_cast<RenderWidgetHostViewGuest*>(
242 web_contents()->GetRenderWidgetHostView()); 278 web_contents()->GetRenderWidgetHostView());
243 // Until the guest is attached, it should not be handling input events. 279 // Until the guest is attached, it should not be handling input events.
244 if (attached() && rwhv && 280 if (attached() && rwhv && GetEmbedderFrame() &&
281 GetEmbedderFrame()->GetRenderWidgetHost() &&
245 rwhv->OnMessageReceivedFromEmbedder( 282 rwhv->OnMessageReceivedFromEmbedder(
246 message, 283 message, RenderWidgetHostImpl::From(
247 RenderWidgetHostImpl::From( 284 GetEmbedderFrame()->GetRenderWidgetHost()))) {
248 embedder_web_contents()->GetRenderViewHost()->GetWidget()))) {
249 return true; 285 return true;
250 } 286 }
251 287
252 bool handled = true; 288 bool handled = true;
253 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) 289 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message)
254 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Detach, OnDetach) 290 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Detach, OnDetach)
255 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, 291 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate,
256 OnDragStatusUpdate) 292 OnDragStatusUpdate)
257 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand, 293 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand,
258 OnExecuteEditCommand) 294 OnExecuteEditCommand)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } 402 }
367 403
368 // static 404 // static
369 bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) { 405 bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) {
370 return render_view_host && IsGuest( 406 return render_view_host && IsGuest(
371 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost( 407 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(
372 render_view_host))); 408 render_view_host)));
373 } 409 }
374 410
375 RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() { 411 RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() {
376 if (!owner_web_contents_) 412 if (GetEmbedderFrame())
377 return nullptr; 413 return GetEmbedderFrame()->GetView();
378 return owner_web_contents_->GetRenderWidgetHostView(); 414
415 return nullptr;
379 } 416 }
380 417
381 void BrowserPluginGuest::UpdateVisibility() { 418 void BrowserPluginGuest::UpdateVisibility() {
382 OnSetVisibility(browser_plugin_instance_id(), visible()); 419 OnSetVisibility(browser_plugin_instance_id(), visible());
383 } 420 }
384 421
385 BrowserPluginGuestManager* 422 BrowserPluginGuestManager*
386 BrowserPluginGuest::GetBrowserPluginGuestManager() const { 423 BrowserPluginGuest::GetBrowserPluginGuestManager() const {
387 return GetWebContents()->GetBrowserContext()->GetGuestManager(); 424 return GetWebContents()->GetBrowserContext()->GetGuestManager();
388 } 425 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 bool BrowserPluginGuest::HandleStopFindingForEmbedder(StopFindAction action) { 477 bool BrowserPluginGuest::HandleStopFindingForEmbedder(StopFindAction action) {
441 return delegate_->HandleStopFindingForEmbedder(action); 478 return delegate_->HandleStopFindingForEmbedder(action);
442 } 479 }
443 480
444 void BrowserPluginGuest::ResendEventToEmbedder( 481 void BrowserPluginGuest::ResendEventToEmbedder(
445 const blink::WebInputEvent& event) { 482 const blink::WebInputEvent& event) {
446 if (!attached() || !owner_web_contents_) 483 if (!attached() || !owner_web_contents_)
447 return; 484 return;
448 485
449 DCHECK(browser_plugin_instance_id_); 486 DCHECK(browser_plugin_instance_id_);
450 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( 487 RenderWidgetHostViewBase* view =
451 embedder_web_contents()->GetMainFrame()->GetView()); 488 static_cast<RenderWidgetHostViewBase*>(GetEmbedderFrame()->GetView());
452 489
453 gfx::Vector2d offset_from_embedder = guest_window_rect_.OffsetFromOrigin(); 490 gfx::Vector2d offset_from_embedder = guest_window_rect_.OffsetFromOrigin();
454 if (event.type == blink::WebInputEvent::GestureScrollUpdate) { 491 if (event.type == blink::WebInputEvent::GestureScrollUpdate) {
455 blink::WebGestureEvent resent_gesture_event; 492 blink::WebGestureEvent resent_gesture_event;
456 memcpy(&resent_gesture_event, &event, sizeof(blink::WebGestureEvent)); 493 memcpy(&resent_gesture_event, &event, sizeof(blink::WebGestureEvent));
457 resent_gesture_event.x += offset_from_embedder.x(); 494 resent_gesture_event.x += offset_from_embedder.x();
458 resent_gesture_event.y += offset_from_embedder.y(); 495 resent_gesture_event.y += offset_from_embedder.y();
459 // Mark the resend source with the browser plugin's instance id, so the 496 // Mark the resend source with the browser plugin's instance id, so the
460 // correct browser_plugin will know to ignore the event. 497 // correct browser_plugin will know to ignore the event.
461 resent_gesture_event.resendingPluginId = browser_plugin_instance_id_; 498 resent_gesture_event.resendingPluginId = browser_plugin_instance_id_;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 // in this case just queue any messages we receive. 534 // in this case just queue any messages we receive.
498 if (!attached() || !owner_web_contents_) { 535 if (!attached() || !owner_web_contents_) {
499 // Some pages such as data URLs, javascript URLs, and about:blank 536 // Some pages such as data URLs, javascript URLs, and about:blank
500 // do not load external resources and so they load prior to attachment. 537 // 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 538 // 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 539 // forward them so that the embedder gets a chance to see and process
503 // the load events. 540 // the load events.
504 pending_messages_.push_back(linked_ptr<IPC::Message>(msg)); 541 pending_messages_.push_back(linked_ptr<IPC::Message>(msg));
505 return; 542 return;
506 } 543 }
507 owner_web_contents_->Send(msg); 544
545 GetEmbedderFrame()->GetRenderWidgetHost()->Send(msg);
508 } 546 }
509 547
510 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, 548 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y,
511 int screen_x, int screen_y, blink::WebDragOperation operation) { 549 int screen_x, int screen_y, blink::WebDragOperation operation) {
512 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, 550 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y,
513 screen_x, screen_y, operation); 551 screen_x, screen_y, operation);
514 seen_embedder_drag_source_ended_at_ = true; 552 seen_embedder_drag_source_ended_at_ = true;
515 EndSystemDragIfApplicable(); 553 EndSystemDragIfApplicable();
516 } 554 }
517 555
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 return handled; 777 return handled;
740 #else 778 #else
741 return false; 779 return false;
742 #endif 780 #endif
743 } 781 }
744 782
745 void BrowserPluginGuest::Attach( 783 void BrowserPluginGuest::Attach(
746 int browser_plugin_instance_id, 784 int browser_plugin_instance_id,
747 WebContentsImpl* embedder_web_contents, 785 WebContentsImpl* embedder_web_contents,
748 const BrowserPluginHostMsg_Attach_Params& params) { 786 const BrowserPluginHostMsg_Attach_Params& params) {
787 DCHECK_EQ(GetEmbedderFrame()->delegate(), embedder_web_contents);
749 browser_plugin_instance_id_ = browser_plugin_instance_id; 788 browser_plugin_instance_id_ = browser_plugin_instance_id;
750 // The guest is owned by the embedder. Attach is queued up so we cannot 789 // 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, 790 // change embedders before attach completes. If the embedder goes away,
752 // so does the guest and so we will never call WillAttachComplete because 791 // so does the guest and so we will never call WillAttachComplete because
753 // we have a weak ptr. 792 // we have a weak ptr.
754 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id, 793 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id,
755 params.is_full_page_plugin, 794 params.is_full_page_plugin,
756 base::Bind(&BrowserPluginGuest::OnWillAttachComplete, 795 base::Bind(&BrowserPluginGuest::OnWillAttachComplete,
757 weak_ptr_factory_.GetWeakPtr(), 796 weak_ptr_factory_.GetWeakPtr(),
758 embedder_web_contents, params)); 797 embedder_web_contents, params));
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 range, character_bounds); 1073 range, character_bounds);
1035 } 1074 }
1036 #endif 1075 #endif
1037 1076
1038 void BrowserPluginGuest::SetContextMenuPosition(const gfx::Point& position) { 1077 void BrowserPluginGuest::SetContextMenuPosition(const gfx::Point& position) {
1039 if (delegate_) 1078 if (delegate_)
1040 delegate_->SetContextMenuPosition(position); 1079 delegate_->SetContextMenuPosition(position);
1041 } 1080 }
1042 1081
1043 } // namespace content 1082 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698