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

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: Rebase + addressed David's comments 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 WebContents* GetWebContentsFromRFHID(int render_process_id,
34 int render_frame_id) {
35 DCHECK_CURRENTLY_ON(BrowserThread::UI);
36 RenderFrameHost* render_frame_host =
37 RenderFrameHost::FromID(render_process_id, render_frame_id);
38 if (!render_frame_host)
39 return nullptr;
40
41 return WebContents::FromRenderFrameHost(render_frame_host);
42 }
43
44 } // namespace
45
16 // ---------------------------------------------------------------------------- 46 // ----------------------------------------------------------------------------
17 // ResourceRequestInfo 47 // ResourceRequestInfo
18 48
19 // static 49 // static
20 const ResourceRequestInfo* ResourceRequestInfo::ForRequest( 50 const ResourceRequestInfo* ResourceRequestInfo::ForRequest(
21 const net::URLRequest* request) { 51 const net::URLRequest* request) {
22 return ResourceRequestInfoImpl::ForRequest(request); 52 return ResourceRequestInfoImpl::ForRequest(request);
23 } 53 }
24 54
25 // static 55 // static
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 context_(context), 191 context_(context),
162 filter_(filter), 192 filter_(filter),
163 report_raw_headers_(report_raw_headers), 193 report_raw_headers_(report_raw_headers),
164 is_async_(is_async), 194 is_async_(is_async),
165 is_using_lofi_(is_using_lofi) { 195 is_using_lofi_(is_using_lofi) {
166 } 196 }
167 197
168 ResourceRequestInfoImpl::~ResourceRequestInfoImpl() { 198 ResourceRequestInfoImpl::~ResourceRequestInfoImpl() {
169 } 199 }
170 200
201 base::Callback<WebContents*(void)>
202 ResourceRequestInfoImpl::GetWebContentsForRequest() const {
203 // PlzNavigate: navigation requests are created with a valid FrameTreeNode ID
204 // and invalid RenderProcessHost and RenderFrameHost IDs. The FrameTreeNode
205 // ID should be used to access the WebContents.
206 if (frame_tree_node_id_ != -1) {
207 DCHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
208 switches::kEnableBrowserSideNavigation));
209 return base::Bind(&GetWebContentsFromFTNID, frame_tree_node_id_);
210 }
211
212 // In other cases, use the RenderProcessHost ID + RenderFrameHost ID to get
213 // the WebContents.
214 int render_process_host_id = -1;
215 int render_frame_host_id = -1;
216 if (!GetAssociatedRenderFrame(&render_process_host_id, &render_frame_host_id))
217 NOTREACHED();
nasko 2015/11/23 17:00:24 Since this is a macro and it isn't evident whether
clamy 2015/11/23 17:56:53 Done.
218
219 return base::Bind(&GetWebContentsFromRFHID, render_process_host_id,
220 render_frame_host_id);
221 }
222
171 ResourceContext* ResourceRequestInfoImpl::GetContext() const { 223 ResourceContext* ResourceRequestInfoImpl::GetContext() const {
172 return context_; 224 return context_;
173 } 225 }
174 226
175 int ResourceRequestInfoImpl::GetChildID() const { 227 int ResourceRequestInfoImpl::GetChildID() const {
176 return child_id_; 228 return child_id_;
177 } 229 }
178 230
179 int ResourceRequestInfoImpl::GetRouteID() const { 231 int ResourceRequestInfoImpl::GetRouteID() const {
180 return route_id_; 232 return route_id_;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 base::WeakPtr<ResourceMessageFilter> filter) { 342 base::WeakPtr<ResourceMessageFilter> filter) {
291 child_id_ = child_id; 343 child_id_ = child_id;
292 route_id_ = route_id; 344 route_id_ = route_id;
293 origin_pid_ = origin_pid; 345 origin_pid_ = origin_pid;
294 request_id_ = request_id; 346 request_id_ = request_id;
295 parent_render_frame_id_ = parent_render_frame_id; 347 parent_render_frame_id_ = parent_render_frame_id;
296 filter_ = filter; 348 filter_ = filter;
297 } 349 }
298 350
299 } // namespace content 351 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698