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

Side by Side Diff: content/browser/loader/resource_request_info_impl.cc

Issue 1459473003: Add a WebContents getter callback in ResourceRequestInfo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Nasko's comment Created 5 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/loader/resource_request_info_impl.h" 5 #include "content/browser/loader/resource_request_info_impl.h"
6 6
7 #include "base/command_line.h"
8 #include "content/browser/frame_host/frame_tree_node.h"
7 #include "content/browser/loader/global_routing_id.h" 9 #include "content/browser/loader/global_routing_id.h"
8 #include "content/browser/loader/resource_message_filter.h" 10 #include "content/browser/loader/resource_message_filter.h"
11 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "content/common/net/url_request_user_data.h" 12 #include "content/common/net/url_request_user_data.h"
13 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/global_request_id.h" 14 #include "content/public/browser/global_request_id.h"
15 #include "content/public/common/content_switches.h"
11 #include "content/public/common/process_type.h" 16 #include "content/public/common/process_type.h"
12 #include "net/url_request/url_request.h" 17 #include "net/url_request/url_request.h"
13 18
14 namespace content { 19 namespace content {
15 20
21 namespace {
22
23 WebContents* GetWebContentsFromFTNID(int frame_tree_node_id) {
24 DCHECK_CURRENTLY_ON(BrowserThread::UI);
25 FrameTreeNode* frame_tree_node =
26 FrameTreeNode::GloballyFindByID(frame_tree_node_id);
27 if (!frame_tree_node)
28 return nullptr;
29
30 return WebContentsImpl::FromFrameTreeNode(frame_tree_node);
31 }
32
33 } // namespace
34
16 // ---------------------------------------------------------------------------- 35 // ----------------------------------------------------------------------------
17 // ResourceRequestInfo 36 // ResourceRequestInfo
18 37
19 // static 38 // static
20 const ResourceRequestInfo* ResourceRequestInfo::ForRequest( 39 const ResourceRequestInfo* ResourceRequestInfo::ForRequest(
21 const net::URLRequest* request) { 40 const net::URLRequest* request) {
22 return ResourceRequestInfoImpl::ForRequest(request); 41 return ResourceRequestInfoImpl::ForRequest(request);
23 } 42 }
24 43
25 // static 44 // static
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 context_(context), 180 context_(context),
162 filter_(filter), 181 filter_(filter),
163 report_raw_headers_(report_raw_headers), 182 report_raw_headers_(report_raw_headers),
164 is_async_(is_async), 183 is_async_(is_async),
165 is_using_lofi_(is_using_lofi) { 184 is_using_lofi_(is_using_lofi) {
166 } 185 }
167 186
168 ResourceRequestInfoImpl::~ResourceRequestInfoImpl() { 187 ResourceRequestInfoImpl::~ResourceRequestInfoImpl() {
169 } 188 }
170 189
190 base::Callback<WebContents*(void)>
191 ResourceRequestInfoImpl::GetWebContentsForRequest() const {
192 // PlzNavigate: navigation requests are created with a valid FrameTreeNode ID
193 // and invalid RenderProcessHost and RenderFrameHost IDs. The FrameTreeNode
194 // ID should be used to access the WebContents.
195 if (frame_tree_node_id_ != -1) {
196 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
197 switches::kEnableBrowserSideNavigation));
198 return base::Bind(&GetWebContentsFromFTNID, frame_tree_node_id_);
199 }
200
201 // In other cases, use the RenderProcessHost ID + RenderFrameHost ID to get
202 // the WebContents.
203 int render_process_host_id = -1;
204 int render_frame_host_id = -1;
205 if (!GetAssociatedRenderFrame(&render_process_host_id,
206 &render_frame_host_id)) {
207 NOTREACHED();
208 }
209
210 return base::Bind(&WebContentsImpl::FromRenderFrameHostID,
211 render_process_host_id, render_frame_host_id);
212 }
213
171 ResourceContext* ResourceRequestInfoImpl::GetContext() const { 214 ResourceContext* ResourceRequestInfoImpl::GetContext() const {
172 return context_; 215 return context_;
173 } 216 }
174 217
175 int ResourceRequestInfoImpl::GetChildID() const { 218 int ResourceRequestInfoImpl::GetChildID() const {
176 return child_id_; 219 return child_id_;
177 } 220 }
178 221
179 int ResourceRequestInfoImpl::GetRouteID() const { 222 int ResourceRequestInfoImpl::GetRouteID() const {
180 return route_id_; 223 return route_id_;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 base::WeakPtr<ResourceMessageFilter> filter) { 333 base::WeakPtr<ResourceMessageFilter> filter) {
291 child_id_ = child_id; 334 child_id_ = child_id;
292 route_id_ = route_id; 335 route_id_ = route_id;
293 origin_pid_ = origin_pid; 336 origin_pid_ = origin_pid;
294 request_id_ = request_id; 337 request_id_ = request_id;
295 parent_render_frame_id_ = parent_render_frame_id; 338 parent_render_frame_id_ = parent_render_frame_id;
296 filter_ = filter; 339 filter_ = filter;
297 } 340 }
298 341
299 } // namespace content 342 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_request_info_impl.h ('k') | content/browser/renderer_host/websocket_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698