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

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