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

Side by Side Diff: content/browser/renderer_host/render_widget_helper.cc

Issue 2821473002: Service CreateNewWindow on the UI thread with a new mojo interface (Closed)
Patch Set: MakeShared goodness Created 3 years, 7 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/renderer_host/render_widget_helper.h" 5 #include "content/browser/renderer_host/render_widget_helper.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/posix/eintr_wrapper.h" 10 #include "base/posix/eintr_wrapper.h"
11 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
12 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
13 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
14 #include "content/browser/frame_host/render_frame_host_impl.h"
15 #include "content/browser/loader/resource_dispatcher_host_impl.h" 13 #include "content/browser/loader/resource_dispatcher_host_impl.h"
16 #include "content/browser/renderer_host/render_process_host_impl.h"
17 #include "content/browser/renderer_host/render_view_host_impl.h" 14 #include "content/browser/renderer_host/render_view_host_impl.h"
18 #include "content/common/view_messages.h" 15 #include "content/common/view_messages.h"
19 16
20 namespace content { 17 namespace content {
21 namespace { 18 namespace {
22 19
23 typedef std::map<int, RenderWidgetHelper*> WidgetHelperMap; 20 typedef std::map<int, RenderWidgetHelper*> WidgetHelperMap;
24 base::LazyInstance<WidgetHelperMap>::DestructorAtExit g_widget_helpers = 21 base::LazyInstance<WidgetHelperMap>::DestructorAtExit g_widget_helpers =
25 LAZY_INSTANCE_INITIALIZER; 22 LAZY_INSTANCE_INITIALIZER;
26 23
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 base::Bind(&RenderWidgetHelper::OnResumeDeferredNavigation, 78 base::Bind(&RenderWidgetHelper::OnResumeDeferredNavigation,
82 this, 79 this,
83 request_id)); 80 request_id));
84 } 81 }
85 82
86 void RenderWidgetHelper::OnResumeDeferredNavigation( 83 void RenderWidgetHelper::OnResumeDeferredNavigation(
87 const GlobalRequestID& request_id) { 84 const GlobalRequestID& request_id) {
88 resource_dispatcher_host_->ResumeDeferredNavigation(request_id); 85 resource_dispatcher_host_->ResumeDeferredNavigation(request_id);
89 } 86 }
90 87
91 void RenderWidgetHelper::CreateNewWindow(
92 mojom::CreateNewWindowParamsPtr params,
93 bool no_javascript_access,
94 int32_t* render_view_route_id,
95 int32_t* main_frame_route_id,
96 int32_t* main_frame_widget_route_id,
97 SessionStorageNamespace* session_storage_namespace) {
98 if (params->opener_suppressed || no_javascript_access) {
99 // If the opener is supppressed or script access is disallowed, we should
100 // open the window in a new BrowsingInstance, and thus a new process. That
101 // means the current renderer process will not be able to route messages to
102 // it. Because of this, we will immediately show and navigate the window
103 // in OnCreateNewWindowOnUI, using the params provided here.
104 *render_view_route_id = MSG_ROUTING_NONE;
105 *main_frame_route_id = MSG_ROUTING_NONE;
106 *main_frame_widget_route_id = MSG_ROUTING_NONE;
107 } else {
108 *render_view_route_id = GetNextRoutingID();
109 *main_frame_route_id = GetNextRoutingID();
110 // TODO(avi): When RenderViewHostImpl has-a RenderWidgetHostImpl, this
111 // should be updated to give the widget a distinct routing ID.
112 // https://crbug.com/545684
113 *main_frame_widget_route_id = *render_view_route_id;
114 // Block resource requests until the frame is created, since the HWND might
115 // be needed if a response ends up creating a plugin. We'll only have a
116 // single frame at this point. These requests will be resumed either in
117 // WebContentsImpl::CreateNewWindow or RenderFrameHost::Init.
118 resource_dispatcher_host_->BlockRequestsForRoute(
119 GlobalFrameRoutingId(render_process_id_, *main_frame_route_id));
120 }
121
122 BrowserThread::PostTask(
123 BrowserThread::UI, FROM_HERE,
124 base::Bind(&RenderWidgetHelper::OnCreateNewWindowOnUI, this,
125 base::Passed(&params), *render_view_route_id,
126 *main_frame_route_id, *main_frame_widget_route_id,
127 base::RetainedRef(session_storage_namespace)));
128 }
129
130 void RenderWidgetHelper::OnCreateNewWindowOnUI(
131 mojom::CreateNewWindowParamsPtr params,
132 int32_t render_view_route_id,
133 int32_t main_frame_route_id,
134 int32_t main_frame_widget_route_id,
135 SessionStorageNamespace* session_storage_namespace) {
136 RenderFrameHostImpl* opener = RenderFrameHostImpl::FromID(
137 render_process_id_, params->opener_render_frame_id);
138 if (opener && opener->IsRenderFrameLive()) {
139 opener->OnCreateNewWindow(render_view_route_id, main_frame_route_id,
140 main_frame_widget_route_id, *params,
141 session_storage_namespace);
142 }
143
144 // If we did not create a WebContents to host the renderer-created
145 // RenderFrame/RenderView/RenderWidget objects, destroy them.
146 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id_);
147 if (main_frame_route_id != MSG_ROUTING_NONE && rph != nullptr) {
148 bool succeeded =
149 RenderWidgetHost::FromID(render_process_id_,
150 main_frame_widget_route_id) != nullptr;
151 if (!succeeded) {
152 DCHECK(!RenderFrameHost::FromID(render_process_id_, main_frame_route_id));
153 DCHECK(!RenderViewHost::FromID(render_process_id_, render_view_route_id));
154
155 rph->Send(new ViewMsg_Close(render_view_route_id));
156 } else {
157 // If a RWH was created, there should also be an RFH and RVH.
158 DCHECK(RenderFrameHost::FromID(render_process_id_, main_frame_route_id));
159 DCHECK(RenderViewHost::FromID(render_process_id_, render_view_route_id));
160 }
161 }
162 }
163
164 void RenderWidgetHelper::CreateNewWidget(int opener_id, 88 void RenderWidgetHelper::CreateNewWidget(int opener_id,
165 blink::WebPopupType popup_type, 89 blink::WebPopupType popup_type,
166 int* route_id) { 90 int* route_id) {
167 *route_id = GetNextRoutingID(); 91 *route_id = GetNextRoutingID();
168 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 92 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
169 base::Bind(&RenderWidgetHelper::OnCreateWidgetOnUI, 93 base::Bind(&RenderWidgetHelper::OnCreateWidgetOnUI,
170 this, opener_id, *route_id, popup_type)); 94 this, opener_id, *route_id, popup_type));
171 } 95 }
172 96
173 void RenderWidgetHelper::CreateNewFullscreenWidget(int opener_id, 97 void RenderWidgetHelper::CreateNewFullscreenWidget(int opener_id,
(...skipping 16 matching lines...) Expand all
190 114
191 void RenderWidgetHelper::OnCreateFullscreenWidgetOnUI(int32_t opener_id, 115 void RenderWidgetHelper::OnCreateFullscreenWidgetOnUI(int32_t opener_id,
192 int32_t route_id) { 116 int32_t route_id) {
193 RenderViewHostImpl* host = RenderViewHostImpl::FromID( 117 RenderViewHostImpl* host = RenderViewHostImpl::FromID(
194 render_process_id_, opener_id); 118 render_process_id_, opener_id);
195 if (host) 119 if (host)
196 host->CreateNewFullscreenWidget(route_id); 120 host->CreateNewFullscreenWidget(route_id);
197 } 121 }
198 122
199 } // namespace content 123 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698