| 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" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 void CheckWillStartRequestOnUIThread( | 44 void CheckWillStartRequestOnUIThread( |
| 45 UIChecksPerformedCallback callback, | 45 UIChecksPerformedCallback callback, |
| 46 int render_process_id, | 46 int render_process_id, |
| 47 int render_frame_host_id, | 47 int render_frame_host_id, |
| 48 const std::string& method, | 48 const std::string& method, |
| 49 const scoped_refptr<content::ResourceRequestBodyImpl>& | 49 const scoped_refptr<content::ResourceRequestBodyImpl>& |
| 50 resource_request_body, | 50 resource_request_body, |
| 51 const Referrer& sanitized_referrer, | 51 const Referrer& sanitized_referrer, |
| 52 bool has_user_gesture, | 52 bool has_user_gesture, |
| 53 ui::PageTransition transition, | 53 ui::PageTransition transition, |
| 54 bool is_external_protocol) { | 54 bool is_external_protocol, |
| 55 RequestContextType request_context_type) { |
| 55 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 56 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 56 RenderFrameHostImpl* render_frame_host = | 57 RenderFrameHostImpl* render_frame_host = |
| 57 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); | 58 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); |
| 58 if (!render_frame_host) { | 59 if (!render_frame_host) { |
| 59 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | 60 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); |
| 60 return; | 61 return; |
| 61 } | 62 } |
| 62 | 63 |
| 63 NavigationHandleImpl* navigation_handle = | 64 NavigationHandleImpl* navigation_handle = |
| 64 render_frame_host->navigation_handle(); | 65 render_frame_host->navigation_handle(); |
| 65 if (!navigation_handle) { | 66 if (!navigation_handle) { |
| 66 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); | 67 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); |
| 67 return; | 68 return; |
| 68 } | 69 } |
| 69 | 70 |
| 70 navigation_handle->WillStartRequest( | 71 navigation_handle->WillStartRequest( |
| 71 method, resource_request_body, sanitized_referrer, has_user_gesture, | 72 method, resource_request_body, sanitized_referrer, has_user_gesture, |
| 72 transition, is_external_protocol, | 73 transition, is_external_protocol, request_context_type, |
| 73 base::Bind(&SendCheckResultToIOThread, callback)); | 74 base::Bind(&SendCheckResultToIOThread, callback)); |
| 74 } | 75 } |
| 75 | 76 |
| 76 void CheckWillRedirectRequestOnUIThread( | 77 void CheckWillRedirectRequestOnUIThread( |
| 77 UIChecksPerformedCallback callback, | 78 UIChecksPerformedCallback callback, |
| 78 int render_process_id, | 79 int render_process_id, |
| 79 int render_frame_host_id, | 80 int render_frame_host_id, |
| 80 const GURL& new_url, | 81 const GURL& new_url, |
| 81 const std::string& new_method, | 82 const std::string& new_method, |
| 82 const GURL& new_referrer_url, | 83 const GURL& new_referrer_url, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 132 |
| 132 navigation_handle->WillProcessResponse( | 133 navigation_handle->WillProcessResponse( |
| 133 render_frame_host, headers, | 134 render_frame_host, headers, |
| 134 base::Bind(&SendCheckResultToIOThread, callback)); | 135 base::Bind(&SendCheckResultToIOThread, callback)); |
| 135 } | 136 } |
| 136 | 137 |
| 137 } // namespace | 138 } // namespace |
| 138 | 139 |
| 139 NavigationResourceThrottle::NavigationResourceThrottle( | 140 NavigationResourceThrottle::NavigationResourceThrottle( |
| 140 net::URLRequest* request, | 141 net::URLRequest* request, |
| 141 ResourceDispatcherHostDelegate* resource_dispatcher_host_delegate) | 142 ResourceDispatcherHostDelegate* resource_dispatcher_host_delegate, |
| 143 RequestContextType request_context_type) |
| 142 : request_(request), | 144 : request_(request), |
| 143 resource_dispatcher_host_delegate_(resource_dispatcher_host_delegate), | 145 resource_dispatcher_host_delegate_(resource_dispatcher_host_delegate), |
| 146 request_context_type_(request_context_type), |
| 144 weak_ptr_factory_(this) {} | 147 weak_ptr_factory_(this) {} |
| 145 | 148 |
| 146 NavigationResourceThrottle::~NavigationResourceThrottle() {} | 149 NavigationResourceThrottle::~NavigationResourceThrottle() {} |
| 147 | 150 |
| 148 void NavigationResourceThrottle::WillStartRequest(bool* defer) { | 151 void NavigationResourceThrottle::WillStartRequest(bool* defer) { |
| 149 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 152 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 150 const ResourceRequestInfoImpl* info = | 153 const ResourceRequestInfoImpl* info = |
| 151 ResourceRequestInfoImpl::ForRequest(request_); | 154 ResourceRequestInfoImpl::ForRequest(request_); |
| 152 if (!info) | 155 if (!info) |
| 153 return; | 156 return; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 164 weak_ptr_factory_.GetWeakPtr()); | 167 weak_ptr_factory_.GetWeakPtr()); |
| 165 DCHECK(request_->method() == "POST" || request_->method() == "GET"); | 168 DCHECK(request_->method() == "POST" || request_->method() == "GET"); |
| 166 BrowserThread::PostTask( | 169 BrowserThread::PostTask( |
| 167 BrowserThread::UI, FROM_HERE, | 170 BrowserThread::UI, FROM_HERE, |
| 168 base::Bind(&CheckWillStartRequestOnUIThread, callback, render_process_id, | 171 base::Bind(&CheckWillStartRequestOnUIThread, callback, render_process_id, |
| 169 render_frame_id, request_->method(), info->body(), | 172 render_frame_id, request_->method(), info->body(), |
| 170 Referrer::SanitizeForRequest( | 173 Referrer::SanitizeForRequest( |
| 171 request_->url(), Referrer(GURL(request_->referrer()), | 174 request_->url(), Referrer(GURL(request_->referrer()), |
| 172 info->GetReferrerPolicy())), | 175 info->GetReferrerPolicy())), |
| 173 info->HasUserGesture(), info->GetPageTransition(), | 176 info->HasUserGesture(), info->GetPageTransition(), |
| 174 is_external_protocol)); | 177 is_external_protocol, request_context_type_)); |
| 175 *defer = true; | 178 *defer = true; |
| 176 } | 179 } |
| 177 | 180 |
| 178 void NavigationResourceThrottle::WillRedirectRequest( | 181 void NavigationResourceThrottle::WillRedirectRequest( |
| 179 const net::RedirectInfo& redirect_info, | 182 const net::RedirectInfo& redirect_info, |
| 180 bool* defer) { | 183 bool* defer) { |
| 181 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 184 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 182 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request_); | 185 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request_); |
| 183 if (!info) | 186 if (!info) |
| 184 return; | 187 return; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } else if (result == NavigationThrottle::CANCEL) { | 273 } else if (result == NavigationThrottle::CANCEL) { |
| 271 controller()->Cancel(); | 274 controller()->Cancel(); |
| 272 } else if (result == NavigationThrottle::BLOCK_REQUEST) { | 275 } else if (result == NavigationThrottle::BLOCK_REQUEST) { |
| 273 controller()->CancelWithError(net::ERR_BLOCKED_BY_CLIENT); | 276 controller()->CancelWithError(net::ERR_BLOCKED_BY_CLIENT); |
| 274 } else { | 277 } else { |
| 275 controller()->Resume(); | 278 controller()->Resume(); |
| 276 } | 279 } |
| 277 } | 280 } |
| 278 | 281 |
| 279 } // namespace content | 282 } // namespace content |
| OLD | NEW |