OLD | NEW |
---|---|
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 "components/navigation_interception/intercept_navigation_resource_throt tle.h" | 5 #include "components/navigation_interception/intercept_navigation_resource_throt tle.h" |
6 | 6 |
7 #include "components/navigation_interception/navigation_params.h" | 7 #include "components/navigation_interception/navigation_params.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 #include "content/public/browser/child_process_security_policy.h" | 9 #include "content/public/browser/child_process_security_policy.h" |
10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
11 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
12 #include "content/public/browser/resource_context.h" | 12 #include "content/public/browser/resource_context.h" |
13 #include "content/public/browser/resource_controller.h" | 13 #include "content/public/browser/resource_controller.h" |
14 #include "content/public/browser/resource_request_info.h" | 14 #include "content/public/browser/resource_request_info.h" |
15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
16 #include "content/public/common/referrer.h" | 16 #include "content/public/common/referrer.h" |
17 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
18 #include "net/url_request/redirect_info.h" | |
18 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
19 #include "net/url_request/url_request_job_factory.h" | 20 #include "net/url_request/url_request_job_factory.h" |
20 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
21 #include "ui/base/page_transition_types.h" | 22 #include "ui/base/page_transition_types.h" |
22 | 23 |
23 using content::BrowserThread; | 24 using content::BrowserThread; |
24 using content::ChildProcessSecurityPolicy; | 25 using content::ChildProcessSecurityPolicy; |
25 using ui::PageTransition; | 26 using ui::PageTransition; |
26 using content::Referrer; | 27 using content::Referrer; |
27 using content::RenderProcessHost; | 28 using content::RenderProcessHost; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 InterceptNavigationResourceThrottle::~InterceptNavigationResourceThrottle() { | 75 InterceptNavigationResourceThrottle::~InterceptNavigationResourceThrottle() { |
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
76 } | 77 } |
77 | 78 |
78 void InterceptNavigationResourceThrottle::WillStartRequest(bool* defer) { | 79 void InterceptNavigationResourceThrottle::WillStartRequest(bool* defer) { |
79 *defer = | 80 *defer = |
80 CheckIfShouldIgnoreNavigation(request_->url(), request_->method(), false); | 81 CheckIfShouldIgnoreNavigation(request_->url(), request_->method(), false); |
81 } | 82 } |
82 | 83 |
83 void InterceptNavigationResourceThrottle::WillRedirectRequest( | 84 void InterceptNavigationResourceThrottle::WillRedirectRequest( |
84 const GURL& new_url, | 85 const net::RedirectInfo& redirect_info, |
85 bool* defer) { | 86 bool* defer) { |
86 *defer = | 87 *defer = CheckIfShouldIgnoreNavigation(redirect_info.new_url, |
87 CheckIfShouldIgnoreNavigation(new_url, GetMethodAfterRedirect(), true); | 88 redirect_info.new_method, true); |
88 } | 89 } |
89 | 90 |
90 const char* InterceptNavigationResourceThrottle::GetNameForLogging() const { | 91 const char* InterceptNavigationResourceThrottle::GetNameForLogging() const { |
91 return "InterceptNavigationResourceThrottle"; | 92 return "InterceptNavigationResourceThrottle"; |
92 } | 93 } |
93 | 94 |
94 std::string InterceptNavigationResourceThrottle::GetMethodAfterRedirect() { | |
95 net::HttpResponseHeaders* headers = request_->response_headers(); | |
96 if (!headers) | |
97 return request_->method(); | |
98 // TODO(davidben): Plumb net::RedirectInfo through content::ResourceThrottle | |
99 // and unexpose net::URLRequest::ComputeMethodForRedirect. | |
100 return net::URLRequest::ComputeMethodForRedirect( | |
101 request_->method(), headers->response_code()); | |
davidben
2015/02/05 20:44:06
All that work to remove this one function. :-)
| |
102 } | |
103 | |
104 bool InterceptNavigationResourceThrottle::CheckIfShouldIgnoreNavigation( | 95 bool InterceptNavigationResourceThrottle::CheckIfShouldIgnoreNavigation( |
105 const GURL& url, | 96 const GURL& url, |
106 const std::string& method, | 97 const std::string& method, |
107 bool is_redirect) { | 98 bool is_redirect) { |
108 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); | 99 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); |
109 if (!info) | 100 if (!info) |
110 return false; | 101 return false; |
111 | 102 |
112 int render_process_id, render_frame_id; | 103 int render_process_id, render_frame_id; |
113 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) | 104 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) |
(...skipping 30 matching lines...) Expand all Loading... | |
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
145 | 136 |
146 if (should_ignore_navigation) { | 137 if (should_ignore_navigation) { |
147 controller()->CancelAndIgnore(); | 138 controller()->CancelAndIgnore(); |
148 } else { | 139 } else { |
149 controller()->Resume(); | 140 controller()->Resume(); |
150 } | 141 } |
151 } | 142 } |
152 | 143 |
153 } // namespace navigation_interception | 144 } // namespace navigation_interception |
OLD | NEW |