| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/navigation_resource_throttle.h" | 5 #include "content/browser/loader/navigation_resource_throttle.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ref_counted.h" |
| 13 #include "content/browser/frame_host/navigation_handle_impl.h" | 14 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 14 #include "content/browser/frame_host/render_frame_host_impl.h" | 15 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 16 #include "content/browser/loader/resource_request_info_impl.h" |
| 15 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/navigation_data.h" | 18 #include "content/public/browser/navigation_data.h" |
| 17 #include "content/public/browser/resource_context.h" | 19 #include "content/public/browser/resource_context.h" |
| 18 #include "content/public/browser/resource_controller.h" | 20 #include "content/public/browser/resource_controller.h" |
| 19 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 21 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 20 #include "content/public/browser/resource_request_info.h" | 22 #include "content/public/browser/resource_request_info.h" |
| 21 #include "content/public/common/referrer.h" | 23 #include "content/public/common/referrer.h" |
| 22 #include "net/url_request/redirect_info.h" | 24 #include "net/url_request/redirect_info.h" |
| 23 #include "net/url_request/url_request.h" | 25 #include "net/url_request/url_request.h" |
| 24 #include "net/url_request/url_request_context.h" | 26 #include "net/url_request/url_request_context.h" |
| 25 #include "net/url_request/url_request_job_factory.h" | 27 #include "net/url_request/url_request_job_factory.h" |
| 26 #include "ui/base/page_transition_types.h" | 28 #include "ui/base/page_transition_types.h" |
| 27 | 29 |
| 28 namespace content { | 30 namespace content { |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> | 33 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> |
| 32 UIChecksPerformedCallback; | 34 UIChecksPerformedCallback; |
| 33 | 35 |
| 34 void SendCheckResultToIOThread(UIChecksPerformedCallback callback, | 36 void SendCheckResultToIOThread(UIChecksPerformedCallback callback, |
| 35 NavigationThrottle::ThrottleCheckResult result) { | 37 NavigationThrottle::ThrottleCheckResult result) { |
| 36 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 38 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 37 DCHECK_NE(result, NavigationThrottle::DEFER); | 39 DCHECK_NE(result, NavigationThrottle::DEFER); |
| 38 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 40 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 39 base::Bind(callback, result)); | 41 base::Bind(callback, result)); |
| 40 } | 42 } |
| 41 | 43 |
| 42 void CheckWillStartRequestOnUIThread(UIChecksPerformedCallback callback, | 44 void CheckWillStartRequestOnUIThread( |
| 43 int render_process_id, | 45 UIChecksPerformedCallback callback, |
| 44 int render_frame_host_id, | 46 int render_process_id, |
| 45 const std::string& method, | 47 int render_frame_host_id, |
| 46 const Referrer& sanitized_referrer, | 48 const std::string& method, |
| 47 bool has_user_gesture, | 49 const scoped_refptr<content::ResourceRequestBody>& resource_request_body, |
| 48 ui::PageTransition transition, | 50 const Referrer& sanitized_referrer, |
| 49 bool is_external_protocol) { | 51 bool has_user_gesture, |
| 52 ui::PageTransition transition, |
| 53 bool is_external_protocol) { |
| 50 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 54 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 51 RenderFrameHostImpl* render_frame_host = | 55 RenderFrameHostImpl* render_frame_host = |
| 52 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); | 56 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); |
| 53 if (!render_frame_host) { | 57 if (!render_frame_host) { |
| 54 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | 58 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); |
| 55 return; | 59 return; |
| 56 } | 60 } |
| 57 | 61 |
| 58 NavigationHandleImpl* navigation_handle = | 62 NavigationHandleImpl* navigation_handle = |
| 59 render_frame_host->navigation_handle(); | 63 render_frame_host->navigation_handle(); |
| 60 if (!navigation_handle) { | 64 if (!navigation_handle) { |
| 61 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | 65 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); |
| 62 return; | 66 return; |
| 63 } | 67 } |
| 64 | 68 |
| 65 navigation_handle->WillStartRequest( | 69 navigation_handle->WillStartRequest( |
| 66 method, sanitized_referrer, has_user_gesture, transition, | 70 method, resource_request_body, sanitized_referrer, has_user_gesture, |
| 67 is_external_protocol, base::Bind(&SendCheckResultToIOThread, callback)); | 71 transition, is_external_protocol, |
| 72 base::Bind(&SendCheckResultToIOThread, callback)); |
| 68 } | 73 } |
| 69 | 74 |
| 70 void CheckWillRedirectRequestOnUIThread( | 75 void CheckWillRedirectRequestOnUIThread( |
| 71 UIChecksPerformedCallback callback, | 76 UIChecksPerformedCallback callback, |
| 72 int render_process_id, | 77 int render_process_id, |
| 73 int render_frame_host_id, | 78 int render_frame_host_id, |
| 74 const GURL& new_url, | 79 const GURL& new_url, |
| 75 const std::string& new_method, | 80 const std::string& new_method, |
| 76 const GURL& new_referrer_url, | 81 const GURL& new_referrer_url, |
| 77 bool new_is_external_protocol, | 82 bool new_is_external_protocol, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 net::URLRequest* request, | 139 net::URLRequest* request, |
| 135 ResourceDispatcherHostDelegate* resource_dispatcher_host_delegate) | 140 ResourceDispatcherHostDelegate* resource_dispatcher_host_delegate) |
| 136 : request_(request), | 141 : request_(request), |
| 137 resource_dispatcher_host_delegate_(resource_dispatcher_host_delegate), | 142 resource_dispatcher_host_delegate_(resource_dispatcher_host_delegate), |
| 138 weak_ptr_factory_(this) {} | 143 weak_ptr_factory_(this) {} |
| 139 | 144 |
| 140 NavigationResourceThrottle::~NavigationResourceThrottle() {} | 145 NavigationResourceThrottle::~NavigationResourceThrottle() {} |
| 141 | 146 |
| 142 void NavigationResourceThrottle::WillStartRequest(bool* defer) { | 147 void NavigationResourceThrottle::WillStartRequest(bool* defer) { |
| 143 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 148 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 144 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); | 149 const ResourceRequestInfoImpl* info = |
| 150 ResourceRequestInfoImpl::ForRequest(request_); |
| 145 if (!info) | 151 if (!info) |
| 146 return; | 152 return; |
| 147 | 153 |
| 148 int render_process_id, render_frame_id; | 154 int render_process_id, render_frame_id; |
| 149 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) | 155 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) |
| 150 return; | 156 return; |
| 151 | 157 |
| 152 bool is_external_protocol = | 158 bool is_external_protocol = |
| 153 !info->GetContext()->GetRequestContext()->job_factory()->IsHandledURL( | 159 !info->GetContext()->GetRequestContext()->job_factory()->IsHandledURL( |
| 154 request_->url()); | 160 request_->url()); |
| 155 UIChecksPerformedCallback callback = | 161 UIChecksPerformedCallback callback = |
| 156 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, | 162 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, |
| 157 weak_ptr_factory_.GetWeakPtr()); | 163 weak_ptr_factory_.GetWeakPtr()); |
| 158 DCHECK(request_->method() == "POST" || request_->method() == "GET"); | 164 DCHECK(request_->method() == "POST" || request_->method() == "GET"); |
| 159 BrowserThread::PostTask( | 165 BrowserThread::PostTask( |
| 160 BrowserThread::UI, FROM_HERE, | 166 BrowserThread::UI, FROM_HERE, |
| 161 base::Bind(&CheckWillStartRequestOnUIThread, callback, render_process_id, | 167 base::Bind(&CheckWillStartRequestOnUIThread, callback, render_process_id, |
| 162 render_frame_id, request_->method(), | 168 render_frame_id, request_->method(), info->body(), |
| 163 Referrer::SanitizeForRequest( | 169 Referrer::SanitizeForRequest( |
| 164 request_->url(), Referrer(GURL(request_->referrer()), | 170 request_->url(), Referrer(GURL(request_->referrer()), |
| 165 info->GetReferrerPolicy())), | 171 info->GetReferrerPolicy())), |
| 166 info->HasUserGesture(), info->GetPageTransition(), | 172 info->HasUserGesture(), info->GetPageTransition(), |
| 167 is_external_protocol)); | 173 is_external_protocol)); |
| 168 *defer = true; | 174 *defer = true; |
| 169 } | 175 } |
| 170 | 176 |
| 171 void NavigationResourceThrottle::WillRedirectRequest( | 177 void NavigationResourceThrottle::WillRedirectRequest( |
| 172 const net::RedirectInfo& redirect_info, | 178 const net::RedirectInfo& redirect_info, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | 264 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { |
| 259 controller()->CancelAndIgnore(); | 265 controller()->CancelAndIgnore(); |
| 260 } else if (result == NavigationThrottle::CANCEL) { | 266 } else if (result == NavigationThrottle::CANCEL) { |
| 261 controller()->Cancel(); | 267 controller()->Cancel(); |
| 262 } else { | 268 } else { |
| 263 controller()->Resume(); | 269 controller()->Resume(); |
| 264 } | 270 } |
| 265 } | 271 } |
| 266 | 272 |
| 267 } // namespace content | 273 } // namespace content |
| OLD | NEW |