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

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

Issue 910073003: <webview>: Make contentWindow available prior to attachment (on display:none). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use constants Created 5 years, 9 months 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 13 matching lines...) Expand all
24 #include "content/common/browser_plugin/browser_plugin_messages.h" 24 #include "content/common/browser_plugin/browser_plugin_messages.h"
25 #include "content/common/content_constants_internal.h" 25 #include "content/common/content_constants_internal.h"
26 #include "content/common/drag_messages.h" 26 #include "content/common/drag_messages.h"
27 #include "content/common/frame_messages.h" 27 #include "content/common/frame_messages.h"
28 #include "content/common/host_shared_bitmap_manager.h" 28 #include "content/common/host_shared_bitmap_manager.h"
29 #include "content/common/input_messages.h" 29 #include "content/common/input_messages.h"
30 #include "content/common/view_messages.h" 30 #include "content/common/view_messages.h"
31 #include "content/public/browser/browser_context.h" 31 #include "content/public/browser/browser_context.h"
32 #include "content/public/browser/browser_plugin_guest_manager.h" 32 #include "content/public/browser/browser_plugin_guest_manager.h"
33 #include "content/public/browser/content_browser_client.h" 33 #include "content/public/browser/content_browser_client.h"
34 #include "content/public/browser/guest_sizer.h" 34 #include "content/public/browser/guest_proxy_host.h"
35 #include "content/public/browser/render_widget_host_view.h" 35 #include "content/public/browser/render_widget_host_view.h"
36 #include "content/public/browser/user_metrics.h" 36 #include "content/public/browser/user_metrics.h"
37 #include "content/public/browser/web_contents_observer.h" 37 #include "content/public/browser/web_contents_observer.h"
38 #include "content/public/common/drop_data.h" 38 #include "content/public/common/drop_data.h"
39 #include "ui/gfx/geometry/size_conversions.h" 39 #include "ui/gfx/geometry/size_conversions.h"
40 40
41 #if defined(OS_MACOSX) 41 #if defined(OS_MACOSX)
42 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h" 42 #include "content/browser/browser_plugin/browser_plugin_popup_menu_helper_mac.h"
43 #endif 43 #endif
44 44
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 guest_proxy_routing_id_(MSG_ROUTING_NONE), 92 guest_proxy_routing_id_(MSG_ROUTING_NONE),
93 last_drag_status_(blink::WebDragStatusUnknown), 93 last_drag_status_(blink::WebDragStatusUnknown),
94 seen_embedder_system_drag_ended_(false), 94 seen_embedder_system_drag_ended_(false),
95 seen_embedder_drag_source_ended_at_(false), 95 seen_embedder_drag_source_ended_at_(false),
96 delegate_(delegate), 96 delegate_(delegate),
97 weak_ptr_factory_(this) { 97 weak_ptr_factory_(this) {
98 DCHECK(web_contents); 98 DCHECK(web_contents);
99 DCHECK(delegate); 99 DCHECK(delegate);
100 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); 100 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create"));
101 web_contents->SetBrowserPluginGuest(this); 101 web_contents->SetBrowserPluginGuest(this);
102 delegate->RegisterDestructionCallback( 102 delegate->SetGuestProxyHost(this);
103 base::Bind(&BrowserPluginGuest::WillDestroy, AsWeakPtr())); 103 }
104 delegate->SetGuestSizer(this); 104
105 int BrowserPluginGuest::GetGuestProxyRoutingID() const {
106 return guest_proxy_routing_id_;
107 }
108
109 int BrowserPluginGuest::GetOrCreateGuestProxyInOwnerProcess() {
Charlie Reis 2015/03/04 20:08:36 I don't think we need the "OrCreate" in the name i
Fady Samuel 2015/03/05 20:56:23 Done.
110 // Create a swapped out RenderView for the guest in the embedder render
Charlie Reis 2015/03/04 20:08:36 nit: render -> renderer
Fady Samuel 2015/03/05 20:56:23 Done.
111 // process, so that the embedder can access the guest's window object.
112 // On reattachment, we can reuse the same swapped out RenderView because
113 // the embedder process will always be the same even if the embedder
Charlie Reis 2015/03/04 20:08:36 Do you mean the guest WebContents? (The embedder
Fady Samuel 2015/03/05 20:56:23 The embedder WebContents can change. If the guest
Charlie Reis 2015/03/06 00:05:35 Acknowledged.
114 // WebContents changes.
115 // TODO(fsamuel): Make sure this works for transferring guests across
116 // owners in different processes. We probably need to clear the
117 // |guest_proxy_routing_id_| and perform any necessary cleanup on Detach
118 // to enable this.
119 if (guest_proxy_routing_id_ != MSG_ROUTING_NONE)
Charlie Reis 2015/03/04 20:08:36 These two lines should go above the comment.
Fady Samuel 2015/03/05 20:56:23 Done.
120 return guest_proxy_routing_id_;
121
122 SiteInstance* owner_site_instance = owner_web_contents_->GetSiteInstance();
123 guest_proxy_routing_id_ =
124 GetWebContents()->CreateSwappedOutRenderView(owner_site_instance);
125
126 return guest_proxy_routing_id_;
105 } 127 }
106 128
107 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) { 129 void BrowserPluginGuest::SizeContents(const gfx::Size& new_size) {
108 GetWebContents()->GetView()->SizeContents(new_size); 130 GetWebContents()->GetView()->SizeContents(new_size);
109 } 131 }
110 132
133 void BrowserPluginGuest::WillDestroy() {
134 is_in_destruction_ = true;
135 owner_web_contents_ = nullptr;
136 attached_ = false;
137 }
138
111 void BrowserPluginGuest::Init() { 139 void BrowserPluginGuest::Init() {
112 if (initialized_) 140 if (initialized_)
113 return; 141 return;
114 initialized_ = true; 142 initialized_ = true;
115 143
116 // TODO(fsamuel): Initiailization prior to attachment should be behind a 144 // TODO(fsamuel): Initiailization prior to attachment should be behind a
117 // command line flag once we introduce experimental guest types that rely on 145 // command line flag once we introduce experimental guest types that rely on
118 // this functionality. 146 // this functionality.
119 if (!delegate_->CanRunInDetachedState()) 147 if (!delegate_->CanRunInDetachedState())
120 return; 148 return;
121 149
122 WebContentsImpl* owner_web_contents = static_cast<WebContentsImpl*>( 150 WebContentsImpl* owner_web_contents = static_cast<WebContentsImpl*>(
123 delegate_->GetOwnerWebContents()); 151 delegate_->GetOwnerWebContents());
152 owner_web_contents->CreateBrowserPluginEmbedderIfNecessary();
124 InitInternal(BrowserPluginHostMsg_Attach_Params(), owner_web_contents); 153 InitInternal(BrowserPluginHostMsg_Attach_Params(), owner_web_contents);
125 } 154 }
126 155
127 void BrowserPluginGuest::WillDestroy() {
128 is_in_destruction_ = true;
129 owner_web_contents_ = nullptr;
130 attached_ = false;
131 }
132
133 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { 156 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() {
134 return weak_ptr_factory_.GetWeakPtr(); 157 return weak_ptr_factory_.GetWeakPtr();
135 } 158 }
136 159
137 void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh, 160 void BrowserPluginGuest::SetFocus(RenderWidgetHost* rwh,
138 bool focused, 161 bool focused,
139 blink::WebFocusType focus_type) { 162 blink::WebFocusType focus_type) {
140 focused_ = focused; 163 focused_ = focused;
141 if (!rwh) 164 if (!rwh)
142 return; 165 return;
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 web_contents_view->CreateViewForWidget( 636 web_contents_view->CreateViewForWidget(
614 web_contents()->GetRenderViewHost(), true); 637 web_contents()->GetRenderViewHost(), true);
615 } 638 }
616 } 639 }
617 640
618 InitInternal(params, embedder_web_contents); 641 InitInternal(params, embedder_web_contents);
619 642
620 attached_ = true; 643 attached_ = true;
621 SendQueuedMessages(); 644 SendQueuedMessages();
622 645
623 // Create a swapped out RenderView for the guest in the embedder render 646 delegate_->DidAttach();
624 // process, so that the embedder can access the guest's window object.
625 // On reattachment, we can reuse the same swapped out RenderView because
626 // the embedder process will always be the same even if the embedder
627 // WebContents changes.
628 if (guest_proxy_routing_id_ == MSG_ROUTING_NONE) {
629 guest_proxy_routing_id_ =
630 GetWebContents()->CreateSwappedOutRenderView(
631 owner_web_contents_->GetSiteInstance());
632 }
633
634 delegate_->DidAttach(guest_proxy_routing_id_);
635 647
636 has_render_view_ = true; 648 has_render_view_ = true;
637 649
638 // Enable input method for guest if it's enabled for the embedder. 650 // Enable input method for guest if it's enabled for the embedder.
639 if (static_cast<RenderViewHostImpl*>( 651 if (static_cast<RenderViewHostImpl*>(
640 owner_web_contents_->GetRenderViewHost())->input_method_active()) { 652 owner_web_contents_->GetRenderViewHost())->input_method_active()) {
641 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( 653 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
642 GetWebContents()->GetRenderViewHost()); 654 GetWebContents()->GetRenderViewHost());
643 guest_rvh->SetInputMethodActive(true); 655 guest_rvh->SetInputMethodActive(true);
644 } 656 }
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 void BrowserPluginGuest::OnImeCompositionRangeChanged( 899 void BrowserPluginGuest::OnImeCompositionRangeChanged(
888 const gfx::Range& range, 900 const gfx::Range& range,
889 const std::vector<gfx::Rect>& character_bounds) { 901 const std::vector<gfx::Rect>& character_bounds) {
890 static_cast<RenderWidgetHostViewBase*>( 902 static_cast<RenderWidgetHostViewBase*>(
891 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( 903 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged(
892 range, character_bounds); 904 range, character_bounds);
893 } 905 }
894 #endif 906 #endif
895 907
896 } // namespace content 908 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698