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

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

Issue 769363002: Initialize BrowserPluginGuest to attach to the View hierarchy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@basic_detach_plumbing
Patch Set: Don't initialize by default Created 6 years 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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 private: 65 private:
66 BrowserPluginGuest* browser_plugin_guest_; 66 BrowserPluginGuest* browser_plugin_guest_;
67 67
68 DISALLOW_COPY_AND_ASSIGN(EmbedderVisibilityObserver); 68 DISALLOW_COPY_AND_ASSIGN(EmbedderVisibilityObserver);
69 }; 69 };
70 70
71 BrowserPluginGuest::BrowserPluginGuest(bool has_render_view, 71 BrowserPluginGuest::BrowserPluginGuest(bool has_render_view,
72 WebContentsImpl* web_contents, 72 WebContentsImpl* web_contents,
73 BrowserPluginGuestDelegate* delegate) 73 BrowserPluginGuestDelegate* delegate)
74 : WebContentsObserver(web_contents), 74 : WebContentsObserver(web_contents),
75 owner_web_contents_(NULL), 75 owner_web_contents_(nullptr),
76 attached_(false), 76 attached_(false),
77 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone), 77 browser_plugin_instance_id_(browser_plugin::kInstanceIDNone),
78 guest_device_scale_factor_(1.0f), 78 guest_device_scale_factor_(1.0f),
79 focused_(false), 79 focused_(false),
80 mouse_locked_(false), 80 mouse_locked_(false),
81 pending_lock_request_(false), 81 pending_lock_request_(false),
82 guest_visible_(false), 82 guest_visible_(false),
83 embedder_visible_(true), 83 embedder_visible_(true),
84 is_full_page_plugin_(false), 84 is_full_page_plugin_(false),
85 has_render_view_(has_render_view), 85 has_render_view_(has_render_view),
86 is_in_destruction_(false), 86 is_in_destruction_(false),
87 initialized_(false),
87 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 88 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
88 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), 89 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
89 last_input_flags_(0), 90 last_input_flags_(0),
90 last_can_compose_inline_(true), 91 last_can_compose_inline_(true),
91 guest_proxy_routing_id_(MSG_ROUTING_NONE), 92 guest_proxy_routing_id_(MSG_ROUTING_NONE),
92 delegate_(delegate), 93 delegate_(delegate),
93 weak_ptr_factory_(this) { 94 weak_ptr_factory_(this) {
94 DCHECK(web_contents); 95 DCHECK(web_contents);
95 DCHECK(delegate); 96 DCHECK(delegate);
96 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); 97 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create"));
97 web_contents->SetBrowserPluginGuest(this); 98 web_contents->SetBrowserPluginGuest(this);
98 delegate->RegisterDestructionCallback( 99 delegate->RegisterDestructionCallback(
99 base::Bind(&BrowserPluginGuest::WillDestroy, AsWeakPtr())); 100 base::Bind(&BrowserPluginGuest::WillDestroy, AsWeakPtr()));
100 } 101 }
101 102
103 void BrowserPluginGuest::Init() {
104 if (initialized_)
105 return;
106 initialized_ = true;
107
108 if (!delegate_->CanRunInDetachedState())
lazyboy 2014/12/04 16:51:13 Add a todo saying we should guard this with WTFram
Fady Samuel 2014/12/04 20:54:44 Done.
109 return;
110
111 WebContentsImpl* owner_web_contents = static_cast<WebContentsImpl*>(
112 delegate_->GetOwnerWebContents());
113 InitInternal(BrowserPluginHostMsg_Attach_Params(), owner_web_contents);
114 }
115
102 void BrowserPluginGuest::WillDestroy() { 116 void BrowserPluginGuest::WillDestroy() {
103 is_in_destruction_ = true; 117 is_in_destruction_ = true;
104 owner_web_contents_ = NULL; 118 owner_web_contents_ = NULL;
105 attached_ = false; 119 attached_ = false;
106 } 120 }
107 121
108 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { 122 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() {
109 return weak_ptr_factory_.GetWeakPtr(); 123 return weak_ptr_factory_.GetWeakPtr();
110 } 124 }
111 125
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 OnSetEditCommandsForNextKeyEvent) 200 OnSetEditCommandsForNextKeyEvent)
187 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) 201 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus)
188 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) 202 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility)
189 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) 203 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck)
190 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) 204 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry)
191 IPC_MESSAGE_UNHANDLED(handled = false) 205 IPC_MESSAGE_UNHANDLED(handled = false)
192 IPC_END_MESSAGE_MAP() 206 IPC_END_MESSAGE_MAP()
193 return handled; 207 return handled;
194 } 208 }
195 209
196 void BrowserPluginGuest::Initialize( 210 void BrowserPluginGuest::InitInternal(
197 int browser_plugin_instance_id,
198 const BrowserPluginHostMsg_Attach_Params& params, 211 const BrowserPluginHostMsg_Attach_Params& params,
199 WebContentsImpl* embedder_web_contents) { 212 WebContentsImpl* owner_web_contents) {
200 browser_plugin_instance_id_ = browser_plugin_instance_id;
201 focused_ = params.focused; 213 focused_ = params.focused;
214 OnSetFocus(0, focused_);
215
202 guest_visible_ = params.visible; 216 guest_visible_ = params.visible;
217 UpdateVisibility();
218
203 is_full_page_plugin_ = params.is_full_page_plugin; 219 is_full_page_plugin_ = params.is_full_page_plugin;
204 guest_window_rect_ = gfx::Rect(params.origin, 220 guest_window_rect_ = gfx::Rect(params.origin,
205 params.resize_guest_params.view_size); 221 params.resize_guest_params.view_size);
206 222
207 WebContentsViewGuest* new_view = 223 if (owner_web_contents_ != owner_web_contents) {
208 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); 224 WebContentsViewGuest* new_view =
209 if (attached()) 225 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView());
210 new_view->OnGuestDetached(owner_web_contents_->GetView()); 226 if (owner_web_contents_)
227 new_view->OnGuestDetached(owner_web_contents_->GetView());
211 228
212 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to 229 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to
213 // be attached. 230 // be attached.
214 owner_web_contents_ = embedder_web_contents; 231 owner_web_contents_ = owner_web_contents;
215 new_view->OnGuestAttached(owner_web_contents_->GetView()); 232 new_view->OnGuestAttached(owner_web_contents_->GetView());
233 }
216 234
217 RendererPreferences* renderer_prefs = 235 RendererPreferences* renderer_prefs =
218 GetWebContents()->GetMutableRendererPrefs(); 236 GetWebContents()->GetMutableRendererPrefs();
219 std::string guest_user_agent_override = renderer_prefs->user_agent_override; 237 std::string guest_user_agent_override = renderer_prefs->user_agent_override;
220 // Copy renderer preferences (and nothing else) from the embedder's 238 // Copy renderer preferences (and nothing else) from the embedder's
221 // WebContents to the guest. 239 // WebContents to the guest.
222 // 240 //
223 // For GTK and Aura this is necessary to get proper renderer configuration 241 // For GTK and Aura this is necessary to get proper renderer configuration
224 // values for caret blinking interval, colors related to selection and 242 // values for caret blinking interval, colors related to selection and
225 // focus. 243 // focus.
226 *renderer_prefs = *owner_web_contents_->GetMutableRendererPrefs(); 244 *renderer_prefs = *owner_web_contents_->GetMutableRendererPrefs();
227 renderer_prefs->user_agent_override = guest_user_agent_override; 245 renderer_prefs->user_agent_override = guest_user_agent_override;
228 246
229 // We would like the guest to report changes to frame names so that we can 247 // We would like the guest to report changes to frame names so that we can
230 // update the BrowserPlugin's corresponding 'name' attribute. 248 // update the BrowserPlugin's corresponding 'name' attribute.
231 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed. 249 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed.
232 renderer_prefs->report_frame_name_changes = true; 250 renderer_prefs->report_frame_name_changes = true;
233 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated 251 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated
234 // navigations still continue to function inside the app. 252 // navigations still continue to function inside the app.
235 renderer_prefs->browser_handles_all_top_level_requests = false; 253 renderer_prefs->browser_handles_all_top_level_requests = false;
236 // Disable "client blocked" error page for browser plugin. 254 // Disable "client blocked" error page for browser plugin.
237 renderer_prefs->disable_client_blocked_error_page = true; 255 renderer_prefs->disable_client_blocked_error_page = true;
238 256
239 embedder_visibility_observer_.reset(new EmbedderVisibilityObserver(this)); 257 embedder_visibility_observer_.reset(new EmbedderVisibilityObserver(this));
240 258
241 OnResizeGuest(browser_plugin_instance_id_, params.resize_guest_params); 259 // The instance ID does not matter here.
260 OnResizeGuest(browser_plugin::kInstanceIDNone, params.resize_guest_params);
242 261
243 // TODO(chrishtr): this code is wrong. The navigate_on_drag_drop field will 262 // TODO(chrishtr): this code is wrong. The navigate_on_drag_drop field will
244 // be reset again the next time preferences are updated. 263 // be reset again the next time preferences are updated.
245 WebPreferences prefs = 264 WebPreferences prefs =
246 GetWebContents()->GetRenderViewHost()->GetWebkitPreferences(); 265 GetWebContents()->GetRenderViewHost()->GetWebkitPreferences();
247 prefs.navigate_on_drag_drop = false; 266 prefs.navigate_on_drag_drop = false;
248 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs); 267 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs);
249 268
250 // Enable input method for guest if it's enabled for the embedder. 269 // Enable input method for guest if it's enabled for the embedder.
251 if (static_cast<RenderViewHostImpl*>( 270 if (static_cast<RenderViewHostImpl*>(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 frame->delegated_frame_data->render_pass_list.back(); 332 frame->delegated_frame_data->render_pass_list.back();
314 gfx::Size view_size(gfx::ToFlooredSize(gfx::ScaleSize( 333 gfx::Size view_size(gfx::ToFlooredSize(gfx::ScaleSize(
315 root_pass->output_rect.size(), 334 root_pass->output_rect.size(),
316 1.0f / frame->metadata.device_scale_factor))); 335 1.0f / frame->metadata.device_scale_factor)));
317 336
318 if (last_seen_view_size_ != view_size) { 337 if (last_seen_view_size_ != view_size) {
319 delegate_->GuestSizeChanged(last_seen_view_size_, view_size); 338 delegate_->GuestSizeChanged(last_seen_view_size_, view_size);
320 last_seen_view_size_ = view_size; 339 last_seen_view_size_ = view_size;
321 } 340 }
322 341
323 FrameMsg_CompositorFrameSwapped_Params guest_params; 342 pending_frame_.reset(new FrameMsg_CompositorFrameSwapped_Params());
324 frame->AssignTo(&guest_params.frame); 343 frame->AssignTo(&pending_frame_->frame);
325 guest_params.output_surface_id = output_surface_id; 344 pending_frame_->output_surface_id = output_surface_id;
326 guest_params.producing_route_id = host_routing_id; 345 pending_frame_->producing_route_id = host_routing_id;
327 guest_params.producing_host_id = host_process_id; 346 pending_frame_->producing_host_id = host_process_id;
347
328 SendMessageToEmbedder( 348 SendMessageToEmbedder(
329 new BrowserPluginMsg_CompositorFrameSwapped( 349 new BrowserPluginMsg_CompositorFrameSwapped(
330 browser_plugin_instance_id(), guest_params)); 350 browser_plugin_instance_id(), *pending_frame_));
331 } 351 }
332 352
333 void BrowserPluginGuest::SetContentsOpaque(bool opaque) { 353 void BrowserPluginGuest::SetContentsOpaque(bool opaque) {
334 SendMessageToEmbedder( 354 SendMessageToEmbedder(
335 new BrowserPluginMsg_SetContentsOpaque( 355 new BrowserPluginMsg_SetContentsOpaque(
336 browser_plugin_instance_id(), opaque)); 356 browser_plugin_instance_id(), opaque));
337 } 357 }
338 358
339 bool BrowserPluginGuest::Find(int request_id, 359 bool BrowserPluginGuest::Find(int request_id,
340 const base::string16& search_text, 360 const base::string16& search_text,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 return handled; 526 return handled;
507 #else 527 #else
508 return false; 528 return false;
509 #endif 529 #endif
510 } 530 }
511 531
512 void BrowserPluginGuest::Attach( 532 void BrowserPluginGuest::Attach(
513 int browser_plugin_instance_id, 533 int browser_plugin_instance_id,
514 WebContentsImpl* embedder_web_contents, 534 WebContentsImpl* embedder_web_contents,
515 const BrowserPluginHostMsg_Attach_Params& params) { 535 const BrowserPluginHostMsg_Attach_Params& params) {
536 browser_plugin_instance_id_ = browser_plugin_instance_id;
537 if (pending_frame_) {
lazyboy 2014/12/04 16:51:12 Add a not when this can happen.
Fady Samuel 2014/12/04 20:54:44 Done.
538 cc::CompositorFrameAck ack;
539 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
540 pending_frame_->producing_route_id,
541 pending_frame_->output_surface_id,
542 pending_frame_->producing_host_id,
543 ack);
544 pending_frame_.reset();
545 }
516 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id, 546 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id,
517 params.is_full_page_plugin); 547 params.is_full_page_plugin);
518 548
519 // If a RenderView has already been created for this new window, then we need 549 // If a RenderView has already been created for this new window, then we need
520 // to initialize the browser-side state now so that the RenderFrameHostManager 550 // to initialize the browser-side state now so that the RenderFrameHostManager
521 // does not create a new RenderView on navigation. 551 // does not create a new RenderView on navigation.
522 if (has_render_view_) { 552 if (has_render_view_) {
523 // This will trigger a callback to RenderViewReady after a round-trip IPC. 553 // This will trigger a callback to RenderViewReady after a round-trip IPC.
524 static_cast<RenderViewHostImpl*>( 554 static_cast<RenderViewHostImpl*>(
525 GetWebContents()->GetRenderViewHost())->Init(); 555 GetWebContents()->GetRenderViewHost())->Init();
526 WebContentsViewGuest* web_contents_view = 556 WebContentsViewGuest* web_contents_view =
527 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); 557 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView());
528 if (!web_contents()->GetRenderViewHost()->GetView()) { 558 if (!web_contents()->GetRenderViewHost()->GetView()) {
529 web_contents_view->CreateViewForWidget( 559 web_contents_view->CreateViewForWidget(
530 web_contents()->GetRenderViewHost(), true); 560 web_contents()->GetRenderViewHost(), true);
531 } 561 }
532 } 562 }
533 563
534 Initialize(browser_plugin_instance_id, params, embedder_web_contents); 564 InitInternal(params, embedder_web_contents);
535 565
536 attached_ = true; 566 attached_ = true;
537 SendQueuedMessages(); 567 SendQueuedMessages();
538 568
539 // Create a swapped out RenderView for the guest in the embedder render 569 // Create a swapped out RenderView for the guest in the embedder render
540 // process, so that the embedder can access the guest's window object. 570 // process, so that the embedder can access the guest's window object.
541 // On reattachment, we can reuse the same swapped out RenderView because 571 // On reattachment, we can reuse the same swapped out RenderView because
542 // the embedder process will always be the same even if the embedder 572 // the embedder process will always be the same even if the embedder
543 // WebContents changes. 573 // WebContents changes.
544 if (guest_proxy_routing_id_ == MSG_ROUTING_NONE) { 574 if (guest_proxy_routing_id_ == MSG_ROUTING_NONE) {
545 guest_proxy_routing_id_ = 575 guest_proxy_routing_id_ =
546 GetWebContents()->CreateSwappedOutRenderView( 576 GetWebContents()->CreateSwappedOutRenderView(
547 owner_web_contents_->GetSiteInstance()); 577 owner_web_contents_->GetSiteInstance());
548 } 578 }
549 579
550 delegate_->DidAttach(guest_proxy_routing_id_); 580 delegate_->DidAttach(guest_proxy_routing_id_);
551 581
552 has_render_view_ = true; 582 has_render_view_ = true;
553 583
554 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); 584 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached"));
555 } 585 }
556 586
557 void BrowserPluginGuest::OnCompositorFrameSwappedACK( 587 void BrowserPluginGuest::OnCompositorFrameSwappedACK(
558 int browser_plugin_instance_id, 588 int browser_plugin_instance_id,
559 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { 589 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) {
560 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, 590 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id,
561 params.output_surface_id, 591 params.output_surface_id,
562 params.producing_host_id, 592 params.producing_host_id,
563 params.ack); 593 params.ack);
594 pending_frame_.reset();
564 } 595 }
565 596
566 void BrowserPluginGuest::OnDetach(int browser_plugin_instance_id) { 597 void BrowserPluginGuest::OnDetach(int browser_plugin_instance_id) {
567 if (!attached()) 598 if (!attached())
568 return; 599 return;
569 600
570 // This tells BrowserPluginGuest to queue up all IPCs to BrowserPlugin until 601 // This tells BrowserPluginGuest to queue up all IPCs to BrowserPlugin until
571 // it's attached again. 602 // it's attached again.
572 attached_ = false; 603 attached_ = false;
573 604
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 699
669 void BrowserPluginGuest::OnLockMouseAck(int browser_plugin_instance_id, 700 void BrowserPluginGuest::OnLockMouseAck(int browser_plugin_instance_id,
670 bool succeeded) { 701 bool succeeded) {
671 Send(new ViewMsg_LockMouse_ACK(routing_id(), succeeded)); 702 Send(new ViewMsg_LockMouse_ACK(routing_id(), succeeded));
672 pending_lock_request_ = false; 703 pending_lock_request_ = false;
673 if (succeeded) 704 if (succeeded)
674 mouse_locked_ = true; 705 mouse_locked_ = true;
675 } 706 }
676 707
677 void BrowserPluginGuest::OnResizeGuest( 708 void BrowserPluginGuest::OnResizeGuest(
678 int browser_plugin_instance_id, 709 int /* unused */,
lazyboy 2014/12/04 16:51:13 nit: This is not consistent in this file, revert t
Fady Samuel 2014/12/04 20:54:44 Done.
679 const BrowserPluginHostMsg_ResizeGuest_Params& params) { 710 const BrowserPluginHostMsg_ResizeGuest_Params& params) {
680 // If we are setting the size for the first time before navigating then 711 // If we are setting the size for the first time before navigating then
681 // BrowserPluginGuest does not yet have a RenderViewHost. 712 // BrowserPluginGuest does not yet have a RenderViewHost.
682 if (guest_device_scale_factor_ != params.scale_factor && 713 if (guest_device_scale_factor_ != params.scale_factor &&
683 GetWebContents()->GetRenderViewHost()) { 714 GetWebContents()->GetRenderViewHost()) {
684 RenderWidgetHostImpl* render_widget_host = 715 RenderWidgetHostImpl* render_widget_host =
685 RenderWidgetHostImpl::From(GetWebContents()->GetRenderViewHost()); 716 RenderWidgetHostImpl::From(GetWebContents()->GetRenderViewHost());
686 guest_device_scale_factor_ = params.scale_factor; 717 guest_device_scale_factor_ = params.scale_factor;
687 render_widget_host->NotifyScreenInfoChanged(); 718 render_widget_host->NotifyScreenInfoChanged();
688 } 719 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 void BrowserPluginGuest::OnImeCompositionRangeChanged( 837 void BrowserPluginGuest::OnImeCompositionRangeChanged(
807 const gfx::Range& range, 838 const gfx::Range& range,
808 const std::vector<gfx::Rect>& character_bounds) { 839 const std::vector<gfx::Rect>& character_bounds) {
809 static_cast<RenderWidgetHostViewBase*>( 840 static_cast<RenderWidgetHostViewBase*>(
810 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( 841 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged(
811 range, character_bounds); 842 range, character_bounds);
812 } 843 }
813 #endif 844 #endif
814 845
815 } // namespace content 846 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698