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

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: Addressed Charlie's comments 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 // TODO(fsamuel): Initiailization prior to attachment should be behind a
109 // command line flag once we introduce experimental guest types that rely on
110 // this functionality.
111 if (!delegate_->CanRunInDetachedState())
112 return;
113
114 WebContentsImpl* owner_web_contents = static_cast<WebContentsImpl*>(
115 delegate_->GetOwnerWebContents());
116 InitInternal(BrowserPluginHostMsg_Attach_Params(), owner_web_contents);
117 }
118
102 void BrowserPluginGuest::WillDestroy() { 119 void BrowserPluginGuest::WillDestroy() {
103 is_in_destruction_ = true; 120 is_in_destruction_ = true;
104 owner_web_contents_ = NULL; 121 owner_web_contents_ = NULL;
105 attached_ = false; 122 attached_ = false;
106 } 123 }
107 124
108 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { 125 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() {
109 return weak_ptr_factory_.GetWeakPtr(); 126 return weak_ptr_factory_.GetWeakPtr();
110 } 127 }
111 128
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 OnSetEditCommandsForNextKeyEvent) 203 OnSetEditCommandsForNextKeyEvent)
187 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus) 204 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus)
188 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) 205 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility)
189 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) 206 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck)
190 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) 207 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry)
191 IPC_MESSAGE_UNHANDLED(handled = false) 208 IPC_MESSAGE_UNHANDLED(handled = false)
192 IPC_END_MESSAGE_MAP() 209 IPC_END_MESSAGE_MAP()
193 return handled; 210 return handled;
194 } 211 }
195 212
196 void BrowserPluginGuest::Initialize( 213 void BrowserPluginGuest::InitInternal(
197 int browser_plugin_instance_id,
198 const BrowserPluginHostMsg_Attach_Params& params, 214 const BrowserPluginHostMsg_Attach_Params& params,
199 WebContentsImpl* embedder_web_contents) { 215 WebContentsImpl* owner_web_contents) {
200 browser_plugin_instance_id_ = browser_plugin_instance_id;
201 focused_ = params.focused; 216 focused_ = params.focused;
217 OnSetFocus(browser_plugin::kInstanceIDNone, focused_);
218
202 guest_visible_ = params.visible; 219 guest_visible_ = params.visible;
220 UpdateVisibility();
221
203 is_full_page_plugin_ = params.is_full_page_plugin; 222 is_full_page_plugin_ = params.is_full_page_plugin;
204 guest_window_rect_ = gfx::Rect(params.origin, 223 guest_window_rect_ = gfx::Rect(params.origin,
205 params.resize_guest_params.view_size); 224 params.resize_guest_params.view_size);
206 225
207 WebContentsViewGuest* new_view = 226 if (owner_web_contents_ != owner_web_contents) {
208 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); 227 WebContentsViewGuest* new_view =
209 if (attached()) 228 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView());
210 new_view->OnGuestDetached(owner_web_contents_->GetView()); 229 if (owner_web_contents_)
230 new_view->OnGuestDetached(owner_web_contents_->GetView());
211 231
212 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to 232 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to
213 // be attached. 233 // be attached.
214 owner_web_contents_ = embedder_web_contents; 234 owner_web_contents_ = owner_web_contents;
215 new_view->OnGuestAttached(owner_web_contents_->GetView()); 235 new_view->OnGuestAttached(owner_web_contents_->GetView());
236 }
216 237
217 RendererPreferences* renderer_prefs = 238 RendererPreferences* renderer_prefs =
218 GetWebContents()->GetMutableRendererPrefs(); 239 GetWebContents()->GetMutableRendererPrefs();
219 std::string guest_user_agent_override = renderer_prefs->user_agent_override; 240 std::string guest_user_agent_override = renderer_prefs->user_agent_override;
220 // Copy renderer preferences (and nothing else) from the embedder's 241 // Copy renderer preferences (and nothing else) from the embedder's
221 // WebContents to the guest. 242 // WebContents to the guest.
222 // 243 //
223 // For GTK and Aura this is necessary to get proper renderer configuration 244 // For GTK and Aura this is necessary to get proper renderer configuration
224 // values for caret blinking interval, colors related to selection and 245 // values for caret blinking interval, colors related to selection and
225 // focus. 246 // focus.
226 *renderer_prefs = *owner_web_contents_->GetMutableRendererPrefs(); 247 *renderer_prefs = *owner_web_contents_->GetMutableRendererPrefs();
227 renderer_prefs->user_agent_override = guest_user_agent_override; 248 renderer_prefs->user_agent_override = guest_user_agent_override;
228 249
229 // We would like the guest to report changes to frame names so that we can 250 // We would like the guest to report changes to frame names so that we can
230 // update the BrowserPlugin's corresponding 'name' attribute. 251 // update the BrowserPlugin's corresponding 'name' attribute.
231 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed. 252 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed.
232 renderer_prefs->report_frame_name_changes = true; 253 renderer_prefs->report_frame_name_changes = true;
233 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated 254 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated
234 // navigations still continue to function inside the app. 255 // navigations still continue to function inside the app.
235 renderer_prefs->browser_handles_all_top_level_requests = false; 256 renderer_prefs->browser_handles_all_top_level_requests = false;
236 // Disable "client blocked" error page for browser plugin. 257 // Disable "client blocked" error page for browser plugin.
237 renderer_prefs->disable_client_blocked_error_page = true; 258 renderer_prefs->disable_client_blocked_error_page = true;
238 259
239 embedder_visibility_observer_.reset(new EmbedderVisibilityObserver(this)); 260 embedder_visibility_observer_.reset(new EmbedderVisibilityObserver(this));
240 261
241 OnResizeGuest(browser_plugin_instance_id_, params.resize_guest_params); 262 // The instance ID does not matter here. This instance ID is used by the IPC
263 // for routing, but here we're calling OnResizeGuest for initialization.
264 OnResizeGuest(browser_plugin::kInstanceIDNone, params.resize_guest_params);
242 265
243 // TODO(chrishtr): this code is wrong. The navigate_on_drag_drop field will 266 // TODO(chrishtr): this code is wrong. The navigate_on_drag_drop field will
244 // be reset again the next time preferences are updated. 267 // be reset again the next time preferences are updated.
245 WebPreferences prefs = 268 WebPreferences prefs =
246 GetWebContents()->GetRenderViewHost()->GetWebkitPreferences(); 269 GetWebContents()->GetRenderViewHost()->GetWebkitPreferences();
247 prefs.navigate_on_drag_drop = false; 270 prefs.navigate_on_drag_drop = false;
248 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs); 271 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs);
249 272
250 // Enable input method for guest if it's enabled for the embedder. 273 // Enable input method for guest if it's enabled for the embedder.
251 if (static_cast<RenderViewHostImpl*>( 274 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(); 336 frame->delegated_frame_data->render_pass_list.back();
314 gfx::Size view_size(gfx::ToFlooredSize(gfx::ScaleSize( 337 gfx::Size view_size(gfx::ToFlooredSize(gfx::ScaleSize(
315 root_pass->output_rect.size(), 338 root_pass->output_rect.size(),
316 1.0f / frame->metadata.device_scale_factor))); 339 1.0f / frame->metadata.device_scale_factor)));
317 340
318 if (last_seen_view_size_ != view_size) { 341 if (last_seen_view_size_ != view_size) {
319 delegate_->GuestSizeChanged(last_seen_view_size_, view_size); 342 delegate_->GuestSizeChanged(last_seen_view_size_, view_size);
320 last_seen_view_size_ = view_size; 343 last_seen_view_size_ = view_size;
321 } 344 }
322 345
323 FrameMsg_CompositorFrameSwapped_Params guest_params; 346 last_pending_frame_.reset(new FrameMsg_CompositorFrameSwapped_Params());
324 frame->AssignTo(&guest_params.frame); 347 frame->AssignTo(&last_pending_frame_->frame);
325 guest_params.output_surface_id = output_surface_id; 348 last_pending_frame_->output_surface_id = output_surface_id;
326 guest_params.producing_route_id = host_routing_id; 349 last_pending_frame_->producing_route_id = host_routing_id;
327 guest_params.producing_host_id = host_process_id; 350 last_pending_frame_->producing_host_id = host_process_id;
351
328 SendMessageToEmbedder( 352 SendMessageToEmbedder(
329 new BrowserPluginMsg_CompositorFrameSwapped( 353 new BrowserPluginMsg_CompositorFrameSwapped(
330 browser_plugin_instance_id(), guest_params)); 354 browser_plugin_instance_id(), *last_pending_frame_));
331 } 355 }
332 356
333 void BrowserPluginGuest::SetContentsOpaque(bool opaque) { 357 void BrowserPluginGuest::SetContentsOpaque(bool opaque) {
334 SendMessageToEmbedder( 358 SendMessageToEmbedder(
335 new BrowserPluginMsg_SetContentsOpaque( 359 new BrowserPluginMsg_SetContentsOpaque(
336 browser_plugin_instance_id(), opaque)); 360 browser_plugin_instance_id(), opaque));
337 } 361 }
338 362
339 bool BrowserPluginGuest::Find(int request_id, 363 bool BrowserPluginGuest::Find(int request_id,
340 const base::string16& search_text, 364 const base::string16& search_text,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 return handled; 530 return handled;
507 #else 531 #else
508 return false; 532 return false;
509 #endif 533 #endif
510 } 534 }
511 535
512 void BrowserPluginGuest::Attach( 536 void BrowserPluginGuest::Attach(
513 int browser_plugin_instance_id, 537 int browser_plugin_instance_id,
514 WebContentsImpl* embedder_web_contents, 538 WebContentsImpl* embedder_web_contents,
515 const BrowserPluginHostMsg_Attach_Params& params) { 539 const BrowserPluginHostMsg_Attach_Params& params) {
540 browser_plugin_instance_id_ = browser_plugin_instance_id;
541 // If a guest is detaching from one container and attaching to another
542 // container, then late arriving ACKs may be lost if the mapping from
543 // |browser_plugin_instance_id| to |guest_instance_id| changes. Thus we
544 // ensure that we always get new frames on attachment by ACKing the pending
545 // frame if it's still waiting on the ACK.
546 if (last_pending_frame_) {
547 cc::CompositorFrameAck ack;
548 RenderWidgetHostImpl::SendSwapCompositorFrameAck(
549 last_pending_frame_->producing_route_id,
550 last_pending_frame_->output_surface_id,
551 last_pending_frame_->producing_host_id,
552 ack);
553 last_pending_frame_.reset();
554 }
516 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id, 555 delegate_->WillAttach(embedder_web_contents, browser_plugin_instance_id,
517 params.is_full_page_plugin); 556 params.is_full_page_plugin);
518 557
519 // If a RenderView has already been created for this new window, then we need 558 // 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 559 // to initialize the browser-side state now so that the RenderFrameHostManager
521 // does not create a new RenderView on navigation. 560 // does not create a new RenderView on navigation.
522 if (has_render_view_) { 561 if (has_render_view_) {
523 // This will trigger a callback to RenderViewReady after a round-trip IPC. 562 // This will trigger a callback to RenderViewReady after a round-trip IPC.
524 static_cast<RenderViewHostImpl*>( 563 static_cast<RenderViewHostImpl*>(
525 GetWebContents()->GetRenderViewHost())->Init(); 564 GetWebContents()->GetRenderViewHost())->Init();
526 WebContentsViewGuest* web_contents_view = 565 WebContentsViewGuest* web_contents_view =
527 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); 566 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView());
528 if (!web_contents()->GetRenderViewHost()->GetView()) { 567 if (!web_contents()->GetRenderViewHost()->GetView()) {
529 web_contents_view->CreateViewForWidget( 568 web_contents_view->CreateViewForWidget(
530 web_contents()->GetRenderViewHost(), true); 569 web_contents()->GetRenderViewHost(), true);
531 } 570 }
532 } 571 }
533 572
534 Initialize(browser_plugin_instance_id, params, embedder_web_contents); 573 InitInternal(params, embedder_web_contents);
535 574
536 attached_ = true; 575 attached_ = true;
537 SendQueuedMessages(); 576 SendQueuedMessages();
538 577
539 // Create a swapped out RenderView for the guest in the embedder render 578 // 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. 579 // process, so that the embedder can access the guest's window object.
541 // On reattachment, we can reuse the same swapped out RenderView because 580 // On reattachment, we can reuse the same swapped out RenderView because
542 // the embedder process will always be the same even if the embedder 581 // the embedder process will always be the same even if the embedder
543 // WebContents changes. 582 // WebContents changes.
544 if (guest_proxy_routing_id_ == MSG_ROUTING_NONE) { 583 if (guest_proxy_routing_id_ == MSG_ROUTING_NONE) {
545 guest_proxy_routing_id_ = 584 guest_proxy_routing_id_ =
546 GetWebContents()->CreateSwappedOutRenderView( 585 GetWebContents()->CreateSwappedOutRenderView(
547 owner_web_contents_->GetSiteInstance()); 586 owner_web_contents_->GetSiteInstance());
548 } 587 }
549 588
550 delegate_->DidAttach(guest_proxy_routing_id_); 589 delegate_->DidAttach(guest_proxy_routing_id_);
551 590
552 has_render_view_ = true; 591 has_render_view_ = true;
553 592
554 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); 593 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached"));
555 } 594 }
556 595
557 void BrowserPluginGuest::OnCompositorFrameSwappedACK( 596 void BrowserPluginGuest::OnCompositorFrameSwappedACK(
558 int browser_plugin_instance_id, 597 int browser_plugin_instance_id,
559 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { 598 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) {
560 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, 599 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id,
561 params.output_surface_id, 600 params.output_surface_id,
562 params.producing_host_id, 601 params.producing_host_id,
563 params.ack); 602 params.ack);
603 last_pending_frame_.reset();
564 } 604 }
565 605
566 void BrowserPluginGuest::OnDetach(int browser_plugin_instance_id) { 606 void BrowserPluginGuest::OnDetach(int browser_plugin_instance_id) {
567 if (!attached()) 607 if (!attached())
568 return; 608 return;
569 609
570 // This tells BrowserPluginGuest to queue up all IPCs to BrowserPlugin until 610 // This tells BrowserPluginGuest to queue up all IPCs to BrowserPlugin until
571 // it's attached again. 611 // it's attached again.
572 attached_ = false; 612 attached_ = false;
573 613
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 void BrowserPluginGuest::OnImeCompositionRangeChanged( 846 void BrowserPluginGuest::OnImeCompositionRangeChanged(
807 const gfx::Range& range, 847 const gfx::Range& range,
808 const std::vector<gfx::Rect>& character_bounds) { 848 const std::vector<gfx::Rect>& character_bounds) {
809 static_cast<RenderWidgetHostViewBase*>( 849 static_cast<RenderWidgetHostViewBase*>(
810 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( 850 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged(
811 range, character_bounds); 851 range, character_bounds);
812 } 852 }
813 #endif 853 #endif
814 854
815 } // namespace content 855 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_guest.h ('k') | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698