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

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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // Create a RenderFrameProxyHost for the guest in the embedder renderer 129 // Create a RenderFrameProxyHost for the guest in the embedder renderer
130 // process, so that the embedder can access the guest's window object. 130 // process, so that the embedder can access the guest's window object.
131 // On reattachment, we can reuse the same RenderFrameProxyHost because 131 // On reattachment, we can reuse the same RenderFrameProxyHost because
132 // the embedder process will always be the same even if the embedder 132 // the embedder process will always be the same even if the embedder
133 // WebContents changes. 133 // WebContents changes.
134 // 134 //
135 // TODO(fsamuel): Make sure this works for transferring guests across 135 // TODO(fsamuel): Make sure this works for transferring guests across
136 // owners in different processes. We probably need to clear the 136 // owners in different processes. We probably need to clear the
137 // |guest_proxy_routing_id_| and perform any necessary cleanup on Detach 137 // |guest_proxy_routing_id_| and perform any necessary cleanup on Detach
138 // to enable this. 138 // to enable this.
139 SiteInstance* owner_site_instance = owner_web_contents_->GetSiteInstance(); 139 SiteInstance* owner_site_instance = GetEmbedderFrame()->GetSiteInstance();
140 int proxy_routing_id = 140 int proxy_routing_id = GetWebContents()
141 GetWebContents()->GetFrameTree()->root()->render_manager()-> 141 ->GetFrameTree()
142 CreateRenderFrameProxy(owner_site_instance); 142 ->root()
143 ->render_manager()
144 ->CreateRenderFrameProxy(owner_site_instance);
nasko 2016/10/27 21:03:40 This doesn't seem right, as we take the SiteInstan
EhsanK 2016/10/27 22:06:48 This was my main question from you on this CL. Tha
nasko 2016/11/09 01:13:07 I didn't realize at the time that GetEmbedderFrame
EhsanK 2016/11/15 19:54:22 Acknowledged.
143 guest_proxy_routing_id_ = RenderFrameProxyHost::FromID( 145 guest_proxy_routing_id_ = RenderFrameProxyHost::FromID(
144 owner_site_instance->GetProcess()->GetID(), proxy_routing_id) 146 owner_site_instance->GetProcess()->GetID(), proxy_routing_id)
145 ->GetRenderViewHost()->GetRoutingID(); 147 ->GetRenderViewHost()->GetRoutingID();
146 148
147 return guest_proxy_routing_id_; 149 return guest_proxy_routing_id_;
148 } 150 }
149 151
150 int BrowserPluginGuest::LoadURLWithParams( 152 int BrowserPluginGuest::LoadURLWithParams(
151 const NavigationController::LoadURLParams& load_params) { 153 const NavigationController::LoadURLParams& load_params) {
152 GetWebContents()->GetController().LoadURLWithParams(load_params); 154 GetWebContents()->GetController().LoadURLWithParams(load_params);
(...skipping 10 matching lines...) Expand all
163 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) { 165 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) {
164 GetWebContents()->GetView()->SizeContents(new_size); 166 GetWebContents()->GetView()->SizeContents(new_size);
165 } 167 }
166 168
167 void BrowserPluginGuest::WillDestroy() { 169 void BrowserPluginGuest::WillDestroy() {
168 is_in_destruction_ = true; 170 is_in_destruction_ = true;
169 owner_web_contents_ = nullptr; 171 owner_web_contents_ = nullptr;
170 attached_ = false; 172 attached_ = false;
171 } 173 }
172 174
175 RenderFrameHostImpl* BrowserPluginGuest::GetEmbedderFrame() const {
176 return static_cast<RenderFrameHostImpl*>(delegate_->GetEmbedderFrame());
177 }
178
173 void BrowserPluginGuest::Init() { 179 void BrowserPluginGuest::Init() {
174 if (initialized_) 180 if (initialized_)
175 return; 181 return;
176 initialized_ = true; 182 initialized_ = true;
177 183
178 // TODO(fsamuel): Initiailization prior to attachment should be behind a 184 // TODO(fsamuel): Initiailization prior to attachment should be behind a
179 // 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
180 // this functionality. 186 // this functionality.
181 if (!delegate_->CanRunInDetachedState()) 187 if (!delegate_->CanRunInDetachedState())
182 return; 188 return;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params)); 241 static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params));
236 DCHECK(new_contents); 242 DCHECK(new_contents);
237 return new_contents; 243 return new_contents;
238 } 244 }
239 245
240 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( 246 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder(
241 const IPC::Message& message) { 247 const IPC::Message& message) {
242 RenderWidgetHostViewGuest* rwhv = static_cast<RenderWidgetHostViewGuest*>( 248 RenderWidgetHostViewGuest* rwhv = static_cast<RenderWidgetHostViewGuest*>(
243 web_contents()->GetRenderWidgetHostView()); 249 web_contents()->GetRenderWidgetHostView());
244 // 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.
245 if (attached() && rwhv && 251 RenderFrameHostImpl* rfhi = GetEmbedderFrame();
246 rwhv->OnMessageReceivedFromEmbedder( 252 RenderWidgetHostImpl* rwhi = rfhi ? rfhi->GetRenderWidgetHost() : nullptr;
247 message, 253 if (attached() && rwhv && rwhi &&
248 RenderWidgetHostImpl::From( 254 rwhv->OnMessageReceivedFromEmbedder(message, rwhi)) {
249 embedder_web_contents()->GetRenderViewHost()->GetWidget()))) {
250 return true; 255 return true;
251 } 256 }
252 257
253 bool handled = true; 258 bool handled = true;
254 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) 259 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message)
255 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Detach, OnDetach) 260 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Detach, OnDetach)
256 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, 261 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate,
257 OnDragStatusUpdate) 262 OnDragStatusUpdate)
258 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand, 263 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand,
259 OnExecuteEditCommand) 264 OnExecuteEditCommand)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 372 }
368 373
369 // static 374 // static
370 bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) { 375 bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) {
371 return render_view_host && IsGuest( 376 return render_view_host && IsGuest(
372 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost( 377 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(
373 render_view_host))); 378 render_view_host)));
374 } 379 }
375 380
376 RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() { 381 RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() {
377 if (!owner_web_contents_) 382 if (GetEmbedderFrame())
378 return nullptr; 383 return GetEmbedderFrame()->GetView();
379 return owner_web_contents_->GetRenderWidgetHostView(); 384
385 return nullptr;
380 } 386 }
381 387
382 void BrowserPluginGuest::UpdateVisibility() { 388 void BrowserPluginGuest::UpdateVisibility() {
383 OnSetVisibility(browser_plugin_instance_id(), visible()); 389 OnSetVisibility(browser_plugin_instance_id(), visible());
384 } 390 }
385 391
386 BrowserPluginGuestManager* 392 BrowserPluginGuestManager*
387 BrowserPluginGuest::GetBrowserPluginGuestManager() const { 393 BrowserPluginGuest::GetBrowserPluginGuestManager() const {
388 return GetWebContents()->GetBrowserContext()->GetGuestManager(); 394 return GetWebContents()->GetBrowserContext()->GetGuestManager();
389 } 395 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 bool BrowserPluginGuest::HandleStopFindingForEmbedder(StopFindAction action) { 447 bool BrowserPluginGuest::HandleStopFindingForEmbedder(StopFindAction action) {
442 return delegate_->HandleStopFindingForEmbedder(action); 448 return delegate_->HandleStopFindingForEmbedder(action);
443 } 449 }
444 450
445 void BrowserPluginGuest::ResendEventToEmbedder( 451 void BrowserPluginGuest::ResendEventToEmbedder(
446 const blink::WebInputEvent& event) { 452 const blink::WebInputEvent& event) {
447 if (!attached() || !owner_web_contents_) 453 if (!attached() || !owner_web_contents_)
448 return; 454 return;
449 455
450 DCHECK(browser_plugin_instance_id_); 456 DCHECK(browser_plugin_instance_id_);
451 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( 457 RenderWidgetHostViewBase* view =
452 embedder_web_contents()->GetMainFrame()->GetView()); 458 static_cast<RenderWidgetHostViewBase*>(GetOwnerRenderWidgetHostView());
453 459
454 gfx::Vector2d offset_from_embedder = guest_window_rect_.OffsetFromOrigin(); 460 gfx::Vector2d offset_from_embedder = guest_window_rect_.OffsetFromOrigin();
455 if (event.type == blink::WebInputEvent::GestureScrollUpdate) { 461 if (event.type == blink::WebInputEvent::GestureScrollUpdate) {
456 blink::WebGestureEvent resent_gesture_event; 462 blink::WebGestureEvent resent_gesture_event;
457 memcpy(&resent_gesture_event, &event, sizeof(blink::WebGestureEvent)); 463 memcpy(&resent_gesture_event, &event, sizeof(blink::WebGestureEvent));
458 resent_gesture_event.x += offset_from_embedder.x(); 464 resent_gesture_event.x += offset_from_embedder.x();
459 resent_gesture_event.y += offset_from_embedder.y(); 465 resent_gesture_event.y += offset_from_embedder.y();
460 // Mark the resend source with the browser plugin's instance id, so the 466 // Mark the resend source with the browser plugin's instance id, so the
461 // correct browser_plugin will know to ignore the event. 467 // correct browser_plugin will know to ignore the event.
462 resent_gesture_event.resendingPluginId = browser_plugin_instance_id_; 468 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. 505 // in this case just queue any messages we receive.
500 if (!attached() || !owner_web_contents_) { 506 if (!attached() || !owner_web_contents_) {
501 // Some pages such as data URLs, javascript URLs, and about:blank 507 // Some pages such as data URLs, javascript URLs, and about:blank
502 // 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.
503 // 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
504 // 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
505 // the load events. 511 // the load events.
506 pending_messages_.push_back(std::move(msg)); 512 pending_messages_.push_back(std::move(msg));
507 return; 513 return;
508 } 514 }
509 owner_web_contents_->Send(msg.release()); 515
516 GetEmbedderFrame()->GetRenderWidgetHost()->Send(msg.release());
510 } 517 }
511 518
512 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, 519 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y,
513 int screen_x, int screen_y, blink::WebDragOperation operation) { 520 int screen_x, int screen_y, blink::WebDragOperation operation) {
514 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, 521 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y,
515 screen_x, screen_y, operation); 522 screen_x, screen_y, operation);
516 seen_embedder_drag_source_ended_at_ = true; 523 seen_embedder_drag_source_ended_at_ = true;
517 EndSystemDragIfApplicable(); 524 EndSystemDragIfApplicable();
518 } 525 }
519 526
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 range, character_bounds); 1042 range, character_bounds);
1036 } 1043 }
1037 #endif 1044 #endif
1038 1045
1039 void BrowserPluginGuest::SetContextMenuPosition(const gfx::Point& position) { 1046 void BrowserPluginGuest::SetContextMenuPosition(const gfx::Point& position) {
1040 if (delegate_) 1047 if (delegate_)
1041 delegate_->SetContextMenuPosition(position); 1048 delegate_->SetContextMenuPosition(position);
1042 } 1049 }
1043 1050
1044 } // namespace content 1051 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698