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

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

Issue 1269813002: Add a NavigationThrottle to the public content/ interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@navigation-api
Patch Set: Created 5 years, 3 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/loader/navigation_resource_throttle.h"
6
7 #include "base/callback.h"
8 #include "content/browser/frame_host/navigation_handle_impl.h"
9 #include "content/browser/frame_host/render_frame_host_impl.h"
10 #include "content/public/browser/resource_context.h"
11 #include "content/public/browser/resource_controller.h"
12 #include "content/public/browser/resource_request_info.h"
13 #include "content/public/common/referrer.h"
14 #include "net/url_request/redirect_info.h"
15 #include "net/url_request/url_request.h"
16 #include "net/url_request/url_request_context.h"
17 #include "net/url_request/url_request_job_factory.h"
18 #include "ui/base/page_transition_types.h"
19
20 namespace content {
21
22 namespace {
23 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)>
24 UIChecksPerformedCallback;
25
26 void CheckWillStartRequestOnUIThread(UIChecksPerformedCallback callback,
27 int render_process_id,
28 int render_frame_host_id,
29 bool is_post,
30 const Referrer& sanitized_referrer,
31 bool has_user_gesture,
32 ui::PageTransition transition,
33 bool is_external_protocol) {
34 DCHECK_CURRENTLY_ON(BrowserThread::UI);
35 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::PROCEED;
36 RenderFrameHostImpl* render_frame_host =
37 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id);
38 if (render_frame_host) {
nasko 2015/08/31 23:25:15 This doesn't seem right. Before we have gotten the
davidben 2015/09/01 21:55:18 This is the pre-PlzNavigate codepath I believe, so
clamy 2015/09/03 15:30:52 Yes this is only used by the pre-PlzNavigate codep
nasko 2015/09/04 23:36:49 Let's add a comment to clarify this then. Also a T
39 NavigationHandleImpl* navigation_handle =
40 render_frame_host->navigation_handle();
41 if (navigation_handle) {
42 result = navigation_handle->WillStartRequest(is_post, sanitized_referrer,
43 has_user_gesture, transition,
44 is_external_protocol);
45 }
46 }
47 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
48 base::Bind(callback, result));
49 }
50
51 void CheckWillRedirectRequestOnUIThread(UIChecksPerformedCallback callback,
52 int render_process_id,
53 int render_frame_host_id,
54 const GURL& new_url,
55 bool new_method_is_post,
56 const GURL& new_referrer_url,
57 bool new_is_external_protocol) {
58 DCHECK_CURRENTLY_ON(BrowserThread::UI);
59 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::PROCEED;
60 RenderFrameHostImpl* render_frame_host =
61 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id);
62 if (render_frame_host) {
63 NavigationHandleImpl* navigation_handle =
64 render_frame_host->navigation_handle();
65 if (navigation_handle) {
66 RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
67 GURL new_validated_url = new_url;
68 rph->FilterURL(false, &new_validated_url);
69 result = navigation_handle->WillRedirectRequest(
70 new_url, new_validated_url, new_method_is_post, new_referrer_url,
71 new_is_external_protocol);
72 }
73 }
74 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
75 base::Bind(callback, result));
76 }
77 } // namespace
78
79 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request)
80 : request_(request), weak_ptr_factory_(this) {}
nasko 2015/08/31 23:25:15 Each member initialization on new line, no? Or has
clamy 2015/09/03 15:30:52 Yes apparently clang-format likes it that way nowa
nasko 2015/09/04 23:36:49 Yuck :(
81
82 NavigationResourceThrottle::~NavigationResourceThrottle() {}
83
84 void NavigationResourceThrottle::WillStartRequest(bool* defer) {
nasko 2015/08/31 23:25:15 Let's add DCHECKs for which thread each function i
clamy 2015/09/03 15:30:51 Done.
85 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_);
86 if (!info)
87 return;
88
nasko 2015/08/31 23:25:15 Is it possible to know on the IO thread whether th
clamy 2015/09/03 15:30:52 For the redirects yes but not for the start. In an
nasko 2015/09/04 23:36:49 I think performance is always an issue. nick@chrom
89 int render_process_id, render_frame_id;
90 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id))
91 return;
92
93 bool is_external_protocol =
94 !info->GetContext()->GetRequestContext()->job_factory()->IsHandledURL(
95 request_->url());
96 UIChecksPerformedCallback callback =
97 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed,
98 weak_ptr_factory_.GetWeakPtr());
99 BrowserThread::PostTask(
100 BrowserThread::UI, FROM_HERE,
101 base::Bind(&CheckWillStartRequestOnUIThread, callback, render_process_id,
102 render_frame_id, request_->method() == "POST",
nasko 2015/08/31 23:25:15 Do we have render_frame_id at the time of sending
clamy 2015/09/03 15:30:51 As mentionned before, this is entirely pre-PlzNavi
103 Referrer::SanitizeForRequest(
104 request_->url(), Referrer(GURL(request_->referrer()),
105 info->GetReferrerPolicy())),
106 info->HasUserGesture(), info->GetPageTransition(),
107 is_external_protocol));
108 *defer = true;
109 }
110
111 void NavigationResourceThrottle::WillRedirectRequest(
112 const net::RedirectInfo& redirect_info,
113 bool* defer) {
114 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_);
115 if (!info)
116 return;
117
118 int render_process_id, render_frame_id;
119 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id))
120 return;
121
122 bool new_is_external_protocol =
123 !info->GetContext()->GetRequestContext()->job_factory()->IsHandledURL(
124 request_->url());
125 UIChecksPerformedCallback callback =
126 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed,
127 weak_ptr_factory_.GetWeakPtr());
128 BrowserThread::PostTask(
129 BrowserThread::UI, FROM_HERE,
130 base::Bind(&CheckWillRedirectRequestOnUIThread, callback,
131 render_process_id, render_frame_id, redirect_info.new_url,
132 redirect_info.new_method == "POST",
133 GURL(redirect_info.new_referrer), new_is_external_protocol));
134 *defer = true;
135 }
136
137 const char* NavigationResourceThrottle::GetNameForLogging() const {
138 return "NavigationResourceThrottle";
139 }
140
141 void NavigationResourceThrottle::OnUIChecksPerformed(
142 NavigationThrottle::ThrottleCheckResult result) {
143 DCHECK_CURRENTLY_ON(BrowserThread::IO);
144 if (result == NavigationThrottle::CANCEL_AND_IGNORE) {
145 controller()->CancelAndIgnore();
146 } else {
147 controller()->Resume();
148 }
149 }
150
151 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698