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

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

Issue 2417693002: Allow MimeHandlerViewGuest be embedded inside OOPIFs (Closed)
Patch Set: Rebased Created 4 years, 1 month 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 int BrowserPluginGuest::GetGuestProxyRoutingID() { 119 int BrowserPluginGuest::GetGuestProxyRoutingID() {
120 if (GuestMode::IsCrossProcessFrameGuest(GetWebContents())) { 120 if (GuestMode::IsCrossProcessFrameGuest(GetWebContents())) {
121 // We don't use the proxy to send postMessage in --site-per-process, since 121 // We don't use the proxy to send postMessage in --site-per-process, since
122 // we use the contentWindow directly from the frame element instead. 122 // we use the contentWindow directly from the frame element instead.
123 return MSG_ROUTING_NONE; 123 return MSG_ROUTING_NONE;
124 } 124 }
125 125
126 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE) 126 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE)
127 return guest_proxy_routing_id_; 127 return guest_proxy_routing_id_;
128 128
129 // Create a RenderFrameProxyHost for the guest in the embedder renderer 129 // In order to enable the embedder to post messages to the
130 // process, so that the embedder can access the guest's window object. 130 // guest, we need to create a RenderFrameProxyHost in root node of guest
131 // On reattachment, we can reuse the same RenderFrameProxyHost because 131 // WebContents' frame tree (i.e., create a RenderFrameProxy in the embedder
132 // the embedder process will always be the same even if the embedder 132 // process which can be used by the embedder to post messages to the guest).
133 // WebContents changes. 133 // The creation of RFPH for the reverse path, which enables the guest to post
134 // messages to the embedder, will be postponed to when the embedder posts its
135 // first message to the guest.
134 // 136 //
135 // TODO(fsamuel): Make sure this works for transferring guests across 137 // TODO(fsamuel): Make sure this works for transferring guests across
136 // owners in different processes. We probably need to clear the 138 // owners in different processes. We probably need to clear the
137 // |guest_proxy_routing_id_| and perform any necessary cleanup on Detach 139 // |guest_proxy_routing_id_| and perform any necessary cleanup on Detach
138 // to enable this. 140 // to enable this.
139 SiteInstance* owner_site_instance = owner_web_contents_->GetSiteInstance(); 141 //
140 int proxy_routing_id = 142 // TODO(ekaramad): If the guest is embedded inside a cross-process <iframe>
141 GetWebContents()->GetFrameTree()->root()->render_manager()-> 143 // (e.g., <embed>-ed PDF), the reverse proxy will not be created and the
142 CreateRenderFrameProxy(owner_site_instance); 144 // posted message's source attribute will be null which in turn breaks the
145 // two-way messaging between the guest and the embedder. We should either
146 // create a RenderFrameProxyHost for the reverse path, or, implement
147 // MimeHandlerViewGuest's using OOPIF (https://crbug.com/659750).
148 SiteInstance* owner_site_instance = GetEmbedderFrame()->GetSiteInstance();
149 int proxy_routing_id = GetWebContents()
150 ->GetFrameTree()
151 ->root()
152 ->render_manager()
153 ->CreateRenderFrameProxy(owner_site_instance);
143 guest_proxy_routing_id_ = RenderFrameProxyHost::FromID( 154 guest_proxy_routing_id_ = RenderFrameProxyHost::FromID(
144 owner_site_instance->GetProcess()->GetID(), proxy_routing_id) 155 owner_site_instance->GetProcess()->GetID(), proxy_routing_id)
145 ->GetRenderViewHost()->GetRoutingID(); 156 ->GetRenderViewHost()->GetRoutingID();
146 157
147 return guest_proxy_routing_id_; 158 return guest_proxy_routing_id_;
148 } 159 }
149 160
150 int BrowserPluginGuest::LoadURLWithParams( 161 int BrowserPluginGuest::LoadURLWithParams(
151 const NavigationController::LoadURLParams& load_params) { 162 const NavigationController::LoadURLParams& load_params) {
152 GetWebContents()->GetController().LoadURLWithParams(load_params); 163 GetWebContents()->GetController().LoadURLWithParams(load_params);
(...skipping 10 matching lines...) Expand all
163 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) { 174 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) {
164 GetWebContents()->GetView()->SizeContents(new_size); 175 GetWebContents()->GetView()->SizeContents(new_size);
165 } 176 }
166 177
167 void BrowserPluginGuest::WillDestroy() { 178 void BrowserPluginGuest::WillDestroy() {
168 is_in_destruction_ = true; 179 is_in_destruction_ = true;
169 owner_web_contents_ = nullptr; 180 owner_web_contents_ = nullptr;
170 attached_ = false; 181 attached_ = false;
171 } 182 }
172 183
184 RenderFrameHostImpl* BrowserPluginGuest::GetEmbedderFrame() const {
185 return static_cast<RenderFrameHostImpl*>(delegate_->GetEmbedderFrame());
186 }
187
173 void BrowserPluginGuest::Init() { 188 void BrowserPluginGuest::Init() {
174 if (initialized_) 189 if (initialized_)
175 return; 190 return;
176 initialized_ = true; 191 initialized_ = true;
177 192
178 // TODO(fsamuel): Initiailization prior to attachment should be behind a 193 // TODO(fsamuel): Initiailization prior to attachment should be behind a
179 // command line flag once we introduce experimental guest types that rely on 194 // command line flag once we introduce experimental guest types that rely on
180 // this functionality. 195 // this functionality.
181 if (!delegate_->CanRunInDetachedState()) 196 if (!delegate_->CanRunInDetachedState())
182 return; 197 return;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 WebContentsImpl* new_contents = 249 WebContentsImpl* new_contents =
235 static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params)); 250 static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params));
236 DCHECK(new_contents); 251 DCHECK(new_contents);
237 return new_contents; 252 return new_contents;
238 } 253 }
239 254
240 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( 255 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder(
241 const IPC::Message& message) { 256 const IPC::Message& message) {
242 RenderWidgetHostViewGuest* rwhv = static_cast<RenderWidgetHostViewGuest*>( 257 RenderWidgetHostViewGuest* rwhv = static_cast<RenderWidgetHostViewGuest*>(
243 web_contents()->GetRenderWidgetHostView()); 258 web_contents()->GetRenderWidgetHostView());
259 RenderFrameHostImpl* rfhi = GetEmbedderFrame();
260 RenderWidgetHostImpl* rwhi = rfhi ? rfhi->GetRenderWidgetHost() : nullptr;
nasko 2016/11/09 01:13:07 In what cases will this result in rwhi being nullp
244 // Until the guest is attached, it should not be handling input events. 261 // Until the guest is attached, it should not be handling input events.
245 if (attached() && rwhv && 262 if (attached() && rwhv && rwhi &&
246 rwhv->OnMessageReceivedFromEmbedder( 263 rwhv->OnMessageReceivedFromEmbedder(message, rwhi)) {
247 message,
248 RenderWidgetHostImpl::From(
249 embedder_web_contents()->GetRenderViewHost()->GetWidget()))) {
250 return true; 264 return true;
251 } 265 }
252 266
253 bool handled = true; 267 bool handled = true;
254 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) 268 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message)
255 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Detach, OnDetach) 269 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Detach, OnDetach)
256 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, 270 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate,
257 OnDragStatusUpdate) 271 OnDragStatusUpdate)
258 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand, 272 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand,
259 OnExecuteEditCommand) 273 OnExecuteEditCommand)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 381 }
368 382
369 // static 383 // static
370 bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) { 384 bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) {
371 return render_view_host && IsGuest( 385 return render_view_host && IsGuest(
372 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost( 386 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(
373 render_view_host))); 387 render_view_host)));
374 } 388 }
375 389
376 RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() { 390 RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() {
377 if (!owner_web_contents_) 391 if (GetEmbedderFrame())
378 return nullptr; 392 return GetEmbedderFrame()->GetView();
379 return owner_web_contents_->GetRenderWidgetHostView(); 393
394 return nullptr;
380 } 395 }
381 396
382 void BrowserPluginGuest::UpdateVisibility() { 397 void BrowserPluginGuest::UpdateVisibility() {
383 OnSetVisibility(browser_plugin_instance_id(), visible()); 398 OnSetVisibility(browser_plugin_instance_id(), visible());
384 } 399 }
385 400
386 BrowserPluginGuestManager* 401 BrowserPluginGuestManager*
387 BrowserPluginGuest::GetBrowserPluginGuestManager() const { 402 BrowserPluginGuest::GetBrowserPluginGuestManager() const {
388 return GetWebContents()->GetBrowserContext()->GetGuestManager(); 403 return GetWebContents()->GetBrowserContext()->GetGuestManager();
389 } 404 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 bool BrowserPluginGuest::HandleStopFindingForEmbedder(StopFindAction action) { 456 bool BrowserPluginGuest::HandleStopFindingForEmbedder(StopFindAction action) {
442 return delegate_->HandleStopFindingForEmbedder(action); 457 return delegate_->HandleStopFindingForEmbedder(action);
443 } 458 }
444 459
445 void BrowserPluginGuest::ResendEventToEmbedder( 460 void BrowserPluginGuest::ResendEventToEmbedder(
446 const blink::WebInputEvent& event) { 461 const blink::WebInputEvent& event) {
447 if (!attached() || !owner_web_contents_) 462 if (!attached() || !owner_web_contents_)
448 return; 463 return;
449 464
450 DCHECK(browser_plugin_instance_id_); 465 DCHECK(browser_plugin_instance_id_);
451 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( 466 RenderWidgetHostViewBase* view =
452 embedder_web_contents()->GetMainFrame()->GetView()); 467 static_cast<RenderWidgetHostViewBase*>(GetOwnerRenderWidgetHostView());
453 468
454 gfx::Vector2d offset_from_embedder = guest_window_rect_.OffsetFromOrigin(); 469 gfx::Vector2d offset_from_embedder = guest_window_rect_.OffsetFromOrigin();
455 if (event.type == blink::WebInputEvent::GestureScrollUpdate) { 470 if (event.type == blink::WebInputEvent::GestureScrollUpdate) {
456 blink::WebGestureEvent resent_gesture_event; 471 blink::WebGestureEvent resent_gesture_event;
457 memcpy(&resent_gesture_event, &event, sizeof(blink::WebGestureEvent)); 472 memcpy(&resent_gesture_event, &event, sizeof(blink::WebGestureEvent));
458 resent_gesture_event.x += offset_from_embedder.x(); 473 resent_gesture_event.x += offset_from_embedder.x();
459 resent_gesture_event.y += offset_from_embedder.y(); 474 resent_gesture_event.y += offset_from_embedder.y();
460 // Mark the resend source with the browser plugin's instance id, so the 475 // Mark the resend source with the browser plugin's instance id, so the
461 // correct browser_plugin will know to ignore the event. 476 // correct browser_plugin will know to ignore the event.
462 resent_gesture_event.resendingPluginId = browser_plugin_instance_id_; 477 resent_gesture_event.resendingPluginId = browser_plugin_instance_id_;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 // in this case just queue any messages we receive. 514 // in this case just queue any messages we receive.
500 if (!attached() || !owner_web_contents_) { 515 if (!attached() || !owner_web_contents_) {
501 // Some pages such as data URLs, javascript URLs, and about:blank 516 // Some pages such as data URLs, javascript URLs, and about:blank
502 // do not load external resources and so they load prior to attachment. 517 // do not load external resources and so they load prior to attachment.
503 // As a result, we must save all these IPCs until attachment and then 518 // As a result, we must save all these IPCs until attachment and then
504 // forward them so that the embedder gets a chance to see and process 519 // forward them so that the embedder gets a chance to see and process
505 // the load events. 520 // the load events.
506 pending_messages_.push_back(std::move(msg)); 521 pending_messages_.push_back(std::move(msg));
507 return; 522 return;
508 } 523 }
509 owner_web_contents_->Send(msg.release()); 524
525 GetEmbedderFrame()->GetRenderWidgetHost()->Send(msg.release());
510 } 526 }
511 527
512 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, 528 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y,
513 int screen_x, int screen_y, blink::WebDragOperation operation) { 529 int screen_x, int screen_y, blink::WebDragOperation operation) {
514 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, 530 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y,
515 screen_x, screen_y, operation); 531 screen_x, screen_y, operation);
516 seen_embedder_drag_source_ended_at_ = true; 532 seen_embedder_drag_source_ended_at_ = true;
517 EndSystemDragIfApplicable(); 533 EndSystemDragIfApplicable();
518 } 534 }
519 535
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 range, character_bounds); 1051 range, character_bounds);
1036 } 1052 }
1037 #endif 1053 #endif
1038 1054
1039 void BrowserPluginGuest::SetContextMenuPosition(const gfx::Point& position) { 1055 void BrowserPluginGuest::SetContextMenuPosition(const gfx::Point& position) {
1040 if (delegate_) 1056 if (delegate_)
1041 delegate_->SetContextMenuPosition(position); 1057 delegate_->SetContextMenuPosition(position);
1042 } 1058 }
1043 1059
1044 } // namespace content 1060 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698