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

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

Issue 2417693002: Allow MimeHandlerViewGuest be embedded inside OOPIFs (Closed)
Patch Set: Addressing lfg@ and nasko@ comments 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 //
140 int proxy_routing_id = 140 // TODO(ekaramad): We create the proxy for post messaging to the guest. The
Charlie Reis 2016/11/02 20:47:06 nit: Say "to the guest below." (I was having a ha
EhsanK 2016/11/08 23:10:16 Sorry but I am a bit confused with the term "to th
141 GetWebContents()->GetFrameTree()->root()->render_manager()-> 141 // reverse route proxies are created when we first post message. However, if
142 CreateRenderFrameProxy(owner_site_instance); 142 // the guest is inisde an <iframe> (e.g., <embed>-ed PDF) then the reverse
Charlie Reis 2016/11/02 20:47:06 nit: inside
EhsanK 2016/11/08 23:10:16 Done.
143 // proxy is not created and the posted messages's source attribute is null.
144 // We should either create a RenderFrameProxyHost for the reverse path or
145 // implement MimeHandlerViewGuest's using OOPIF (https://crbug.com/659750).
146 SiteInstance* owner_site_instance = GetEmbedderFrame()->GetSiteInstance();
147 int proxy_routing_id = GetWebContents()
148 ->GetFrameTree()
149 ->root()
150 ->render_manager()
151 ->CreateRenderFrameProxy(owner_site_instance);
143 guest_proxy_routing_id_ = RenderFrameProxyHost::FromID( 152 guest_proxy_routing_id_ = RenderFrameProxyHost::FromID(
144 owner_site_instance->GetProcess()->GetID(), proxy_routing_id) 153 owner_site_instance->GetProcess()->GetID(), proxy_routing_id)
145 ->GetRenderViewHost()->GetRoutingID(); 154 ->GetRenderViewHost()->GetRoutingID();
146 155
147 return guest_proxy_routing_id_; 156 return guest_proxy_routing_id_;
148 } 157 }
149 158
150 int BrowserPluginGuest::LoadURLWithParams( 159 int BrowserPluginGuest::LoadURLWithParams(
151 const NavigationController::LoadURLParams& load_params) { 160 const NavigationController::LoadURLParams& load_params) {
152 GetWebContents()->GetController().LoadURLWithParams(load_params); 161 GetWebContents()->GetController().LoadURLWithParams(load_params);
(...skipping 10 matching lines...) Expand all
163 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) { 172 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) {
164 GetWebContents()->GetView()->SizeContents(new_size); 173 GetWebContents()->GetView()->SizeContents(new_size);
165 } 174 }
166 175
167 void BrowserPluginGuest::WillDestroy() { 176 void BrowserPluginGuest::WillDestroy() {
168 is_in_destruction_ = true; 177 is_in_destruction_ = true;
169 owner_web_contents_ = nullptr; 178 owner_web_contents_ = nullptr;
170 attached_ = false; 179 attached_ = false;
171 } 180 }
172 181
182 RenderFrameHostImpl* BrowserPluginGuest::GetEmbedderFrame() const {
183 return static_cast<RenderFrameHostImpl*>(delegate_->GetEmbedderFrame());
184 }
185
173 void BrowserPluginGuest::Init() { 186 void BrowserPluginGuest::Init() {
174 if (initialized_) 187 if (initialized_)
175 return; 188 return;
176 initialized_ = true; 189 initialized_ = true;
177 190
178 // TODO(fsamuel): Initiailization prior to attachment should be behind a 191 // TODO(fsamuel): Initiailization prior to attachment should be behind a
179 // command line flag once we introduce experimental guest types that rely on 192 // command line flag once we introduce experimental guest types that rely on
180 // this functionality. 193 // this functionality.
181 if (!delegate_->CanRunInDetachedState()) 194 if (!delegate_->CanRunInDetachedState())
182 return; 195 return;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params)); 248 static_cast<WebContentsImpl*>(delegate_->CreateNewGuestWindow(params));
236 DCHECK(new_contents); 249 DCHECK(new_contents);
237 return new_contents; 250 return new_contents;
238 } 251 }
239 252
240 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( 253 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder(
241 const IPC::Message& message) { 254 const IPC::Message& message) {
242 RenderWidgetHostViewGuest* rwhv = static_cast<RenderWidgetHostViewGuest*>( 255 RenderWidgetHostViewGuest* rwhv = static_cast<RenderWidgetHostViewGuest*>(
243 web_contents()->GetRenderWidgetHostView()); 256 web_contents()->GetRenderWidgetHostView());
244 // Until the guest is attached, it should not be handling input events. 257 // Until the guest is attached, it should not be handling input events.
245 if (attached() && rwhv && 258 RenderFrameHostImpl* rfhi = GetEmbedderFrame();
246 rwhv->OnMessageReceivedFromEmbedder( 259 RenderWidgetHostImpl* rwhi = rfhi ? rfhi->GetRenderWidgetHost() : nullptr;
Charlie Reis 2016/11/02 20:47:06 nit: Move these two lines above the "// Until" com
EhsanK 2016/11/08 23:10:16 Done.
247 message, 260 if (attached() && rwhv && rwhi &&
248 RenderWidgetHostImpl::From( 261 rwhv->OnMessageReceivedFromEmbedder(message, rwhi)) {
249 embedder_web_contents()->GetRenderViewHost()->GetWidget()))) {
250 return true; 262 return true;
251 } 263 }
252 264
253 bool handled = true; 265 bool handled = true;
254 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) 266 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message)
255 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Detach, OnDetach) 267 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Detach, OnDetach)
256 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate, 268 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_DragStatusUpdate,
257 OnDragStatusUpdate) 269 OnDragStatusUpdate)
258 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand, 270 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ExecuteEditCommand,
259 OnExecuteEditCommand) 271 OnExecuteEditCommand)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 379 }
368 380
369 // static 381 // static
370 bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) { 382 bool BrowserPluginGuest::IsGuest(RenderViewHostImpl* render_view_host) {
371 return render_view_host && IsGuest( 383 return render_view_host && IsGuest(
372 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost( 384 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(
373 render_view_host))); 385 render_view_host)));
374 } 386 }
375 387
376 RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() { 388 RenderWidgetHostView* BrowserPluginGuest::GetOwnerRenderWidgetHostView() {
377 if (!owner_web_contents_) 389 if (GetEmbedderFrame())
378 return nullptr; 390 return GetEmbedderFrame()->GetView();
379 return owner_web_contents_->GetRenderWidgetHostView(); 391
392 return nullptr;
380 } 393 }
381 394
382 void BrowserPluginGuest::UpdateVisibility() { 395 void BrowserPluginGuest::UpdateVisibility() {
383 OnSetVisibility(browser_plugin_instance_id(), visible()); 396 OnSetVisibility(browser_plugin_instance_id(), visible());
384 } 397 }
385 398
386 BrowserPluginGuestManager* 399 BrowserPluginGuestManager*
387 BrowserPluginGuest::GetBrowserPluginGuestManager() const { 400 BrowserPluginGuest::GetBrowserPluginGuestManager() const {
388 return GetWebContents()->GetBrowserContext()->GetGuestManager(); 401 return GetWebContents()->GetBrowserContext()->GetGuestManager();
389 } 402 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 bool BrowserPluginGuest::HandleStopFindingForEmbedder(StopFindAction action) { 454 bool BrowserPluginGuest::HandleStopFindingForEmbedder(StopFindAction action) {
442 return delegate_->HandleStopFindingForEmbedder(action); 455 return delegate_->HandleStopFindingForEmbedder(action);
443 } 456 }
444 457
445 void BrowserPluginGuest::ResendEventToEmbedder( 458 void BrowserPluginGuest::ResendEventToEmbedder(
446 const blink::WebInputEvent& event) { 459 const blink::WebInputEvent& event) {
447 if (!attached() || !owner_web_contents_) 460 if (!attached() || !owner_web_contents_)
448 return; 461 return;
449 462
450 DCHECK(browser_plugin_instance_id_); 463 DCHECK(browser_plugin_instance_id_);
451 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( 464 RenderWidgetHostViewBase* view =
452 embedder_web_contents()->GetMainFrame()->GetView()); 465 static_cast<RenderWidgetHostViewBase*>(GetOwnerRenderWidgetHostView());
453 466
454 gfx::Vector2d offset_from_embedder = guest_window_rect_.OffsetFromOrigin(); 467 gfx::Vector2d offset_from_embedder = guest_window_rect_.OffsetFromOrigin();
455 if (event.type == blink::WebInputEvent::GestureScrollUpdate) { 468 if (event.type == blink::WebInputEvent::GestureScrollUpdate) {
456 blink::WebGestureEvent resent_gesture_event; 469 blink::WebGestureEvent resent_gesture_event;
457 memcpy(&resent_gesture_event, &event, sizeof(blink::WebGestureEvent)); 470 memcpy(&resent_gesture_event, &event, sizeof(blink::WebGestureEvent));
458 resent_gesture_event.x += offset_from_embedder.x(); 471 resent_gesture_event.x += offset_from_embedder.x();
459 resent_gesture_event.y += offset_from_embedder.y(); 472 resent_gesture_event.y += offset_from_embedder.y();
460 // Mark the resend source with the browser plugin's instance id, so the 473 // Mark the resend source with the browser plugin's instance id, so the
461 // correct browser_plugin will know to ignore the event. 474 // correct browser_plugin will know to ignore the event.
462 resent_gesture_event.resendingPluginId = browser_plugin_instance_id_; 475 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. 512 // in this case just queue any messages we receive.
500 if (!attached() || !owner_web_contents_) { 513 if (!attached() || !owner_web_contents_) {
501 // Some pages such as data URLs, javascript URLs, and about:blank 514 // Some pages such as data URLs, javascript URLs, and about:blank
502 // do not load external resources and so they load prior to attachment. 515 // 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 516 // 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 517 // forward them so that the embedder gets a chance to see and process
505 // the load events. 518 // the load events.
506 pending_messages_.push_back(std::move(msg)); 519 pending_messages_.push_back(std::move(msg));
507 return; 520 return;
508 } 521 }
509 owner_web_contents_->Send(msg.release()); 522
523 GetEmbedderFrame()->GetRenderWidgetHost()->Send(msg.release());
Charlie Reis 2016/11/02 20:47:06 This change looks a little odd to me (sending via
EhsanK 2016/11/08 23:10:16 To respect the exact implementation, we should sen
510 } 524 }
511 525
512 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y, 526 void BrowserPluginGuest::DragSourceEndedAt(int client_x, int client_y,
513 int screen_x, int screen_y, blink::WebDragOperation operation) { 527 int screen_x, int screen_y, blink::WebDragOperation operation) {
514 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, 528 web_contents()->GetRenderViewHost()->DragSourceEndedAt(client_x, client_y,
515 screen_x, screen_y, operation); 529 screen_x, screen_y, operation);
516 seen_embedder_drag_source_ended_at_ = true; 530 seen_embedder_drag_source_ended_at_ = true;
517 EndSystemDragIfApplicable(); 531 EndSystemDragIfApplicable();
518 } 532 }
519 533
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 range, character_bounds); 1049 range, character_bounds);
1036 } 1050 }
1037 #endif 1051 #endif
1038 1052
1039 void BrowserPluginGuest::SetContextMenuPosition(const gfx::Point& position) { 1053 void BrowserPluginGuest::SetContextMenuPosition(const gfx::Point& position) {
1040 if (delegate_) 1054 if (delegate_)
1041 delegate_->SetContextMenuPosition(position); 1055 delegate_->SetContextMenuPosition(position);
1042 } 1056 }
1043 1057
1044 } // namespace content 1058 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698