| 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 "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele
gate.h" | 5 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele
gate.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <string> | 8 #include <string> |
| 8 | 9 |
| 9 #include "android_webview/browser/aw_contents_io_thread_client.h" | 10 #include "android_webview/browser/aw_contents_io_thread_client.h" |
| 10 #include "android_webview/browser/aw_login_delegate.h" | 11 #include "android_webview/browser/aw_login_delegate.h" |
| 11 #include "android_webview/browser/aw_resource_context.h" | 12 #include "android_webview/browser/aw_resource_context.h" |
| 12 #include "android_webview/common/url_constants.h" | 13 #include "android_webview/common/url_constants.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "components/auto_login_parser/auto_login_parser.h" | 15 #include "components/auto_login_parser/auto_login_parser.h" |
| 16 #include "components/navigation_interception/intercept_navigation_delegate.h" | 16 #include "components/navigation_interception/intercept_navigation_delegate.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/resource_controller.h" | 18 #include "content/public/browser/resource_controller.h" |
| 19 #include "content/public/browser/resource_dispatcher_host.h" | 19 #include "content/public/browser/resource_dispatcher_host.h" |
| 20 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" | 20 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" |
| 21 #include "content/public/browser/resource_request_info.h" | 21 #include "content/public/browser/resource_request_info.h" |
| 22 #include "content/public/browser/resource_throttle.h" | 22 #include "content/public/browser/resource_throttle.h" |
| 23 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 const char* GetNameForLogging() const override; | 73 const char* GetNameForLogging() const override; |
| 74 | 74 |
| 75 void OnIoThreadClientReady(int new_render_process_id, | 75 void OnIoThreadClientReady(int new_render_process_id, |
| 76 int new_render_frame_id); | 76 int new_render_frame_id); |
| 77 bool MaybeBlockRequest(); | 77 bool MaybeBlockRequest(); |
| 78 bool ShouldBlockRequest(); | 78 bool ShouldBlockRequest(); |
| 79 int render_process_id() const { return render_process_id_; } | 79 int render_process_id() const { return render_process_id_; } |
| 80 int render_frame_id() const { return render_frame_id_; } | 80 int render_frame_id() const { return render_frame_id_; } |
| 81 | 81 |
| 82 private: | 82 private: |
| 83 scoped_ptr<AwContentsIoThreadClient> GetIoThreadClient() const; | 83 std::unique_ptr<AwContentsIoThreadClient> GetIoThreadClient() const; |
| 84 | 84 |
| 85 int render_process_id_; | 85 int render_process_id_; |
| 86 int render_frame_id_; | 86 int render_frame_id_; |
| 87 net::URLRequest* request_; | 87 net::URLRequest* request_; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 IoThreadClientThrottle::IoThreadClientThrottle(int render_process_id, | 90 IoThreadClientThrottle::IoThreadClientThrottle(int render_process_id, |
| 91 int render_frame_id, | 91 int render_frame_id, |
| 92 net::URLRequest* request) | 92 net::URLRequest* request) |
| 93 : render_process_id_(render_process_id), | 93 : render_process_id_(render_process_id), |
| 94 render_frame_id_(render_frame_id), | 94 render_frame_id_(render_frame_id), |
| 95 request_(request) { } | 95 request_(request) { } |
| 96 | 96 |
| 97 IoThreadClientThrottle::~IoThreadClientThrottle() { | 97 IoThreadClientThrottle::~IoThreadClientThrottle() { |
| 98 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 98 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 99 g_webview_resource_dispatcher_host_delegate.Get(). | 99 g_webview_resource_dispatcher_host_delegate.Get(). |
| 100 RemovePendingThrottleOnIoThread(this); | 100 RemovePendingThrottleOnIoThread(this); |
| 101 } | 101 } |
| 102 | 102 |
| 103 const char* IoThreadClientThrottle::GetNameForLogging() const { | 103 const char* IoThreadClientThrottle::GetNameForLogging() const { |
| 104 return "IoThreadClientThrottle"; | 104 return "IoThreadClientThrottle"; |
| 105 } | 105 } |
| 106 | 106 |
| 107 scoped_ptr<AwContentsIoThreadClient> | 107 std::unique_ptr<AwContentsIoThreadClient> |
| 108 IoThreadClientThrottle::GetIoThreadClient() const { | 108 IoThreadClientThrottle::GetIoThreadClient() const { |
| 109 if (content::ResourceRequestInfo::OriginatedFromServiceWorker(request_)) | 109 if (content::ResourceRequestInfo::OriginatedFromServiceWorker(request_)) |
| 110 return AwContentsIoThreadClient::GetServiceWorkerIoThreadClient(); | 110 return AwContentsIoThreadClient::GetServiceWorkerIoThreadClient(); |
| 111 | 111 |
| 112 return AwContentsIoThreadClient::FromID(render_process_id_, render_frame_id_); | 112 return AwContentsIoThreadClient::FromID(render_process_id_, render_frame_id_); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void IoThreadClientThrottle::WillStartRequest(bool* defer) { | 115 void IoThreadClientThrottle::WillStartRequest(bool* defer) { |
| 116 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 116 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 117 // valid render_frame_id_ implies nonzero render_processs_id_ | 117 // valid render_frame_id_ implies nonzero render_processs_id_ |
| 118 DCHECK((render_frame_id_ < 1) || (render_process_id_ != 0)); | 118 DCHECK((render_frame_id_ < 1) || (render_process_id_ != 0)); |
| 119 *defer = false; | 119 *defer = false; |
| 120 | 120 |
| 121 // Defer all requests of a pop up that is still not associated with Java | 121 // Defer all requests of a pop up that is still not associated with Java |
| 122 // client so that the client will get a chance to override requests. | 122 // client so that the client will get a chance to override requests. |
| 123 scoped_ptr<AwContentsIoThreadClient> io_client = GetIoThreadClient(); | 123 std::unique_ptr<AwContentsIoThreadClient> io_client = GetIoThreadClient(); |
| 124 if (io_client && io_client->PendingAssociation()) { | 124 if (io_client && io_client->PendingAssociation()) { |
| 125 *defer = true; | 125 *defer = true; |
| 126 AwResourceDispatcherHostDelegate::AddPendingThrottle( | 126 AwResourceDispatcherHostDelegate::AddPendingThrottle( |
| 127 render_process_id_, render_frame_id_, this); | 127 render_process_id_, render_frame_id_, this); |
| 128 } else { | 128 } else { |
| 129 MaybeBlockRequest(); | 129 MaybeBlockRequest(); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 void IoThreadClientThrottle::WillRedirectRequest( | 133 void IoThreadClientThrottle::WillRedirectRequest( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 147 | 147 |
| 148 bool IoThreadClientThrottle::MaybeBlockRequest() { | 148 bool IoThreadClientThrottle::MaybeBlockRequest() { |
| 149 if (ShouldBlockRequest()) { | 149 if (ShouldBlockRequest()) { |
| 150 controller()->CancelWithError(net::ERR_ACCESS_DENIED); | 150 controller()->CancelWithError(net::ERR_ACCESS_DENIED); |
| 151 return true; | 151 return true; |
| 152 } | 152 } |
| 153 return false; | 153 return false; |
| 154 } | 154 } |
| 155 | 155 |
| 156 bool IoThreadClientThrottle::ShouldBlockRequest() { | 156 bool IoThreadClientThrottle::ShouldBlockRequest() { |
| 157 scoped_ptr<AwContentsIoThreadClient> io_client = GetIoThreadClient(); | 157 std::unique_ptr<AwContentsIoThreadClient> io_client = GetIoThreadClient(); |
| 158 if (!io_client) | 158 if (!io_client) |
| 159 return false; | 159 return false; |
| 160 | 160 |
| 161 // Part of implementation of WebSettings.allowContentAccess. | 161 // Part of implementation of WebSettings.allowContentAccess. |
| 162 if (request_->url().SchemeIs(url::kContentScheme) && | 162 if (request_->url().SchemeIs(url::kContentScheme) && |
| 163 io_client->ShouldBlockContentUrls()) { | 163 io_client->ShouldBlockContentUrls()) { |
| 164 return true; | 164 return true; |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Part of implementation of WebSettings.allowFileAccess. | 167 // Part of implementation of WebSettings.allowFileAccess. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 content::ResourceContext* resource_context, | 238 content::ResourceContext* resource_context, |
| 239 content::ResourceResponse* response) { | 239 content::ResourceResponse* response) { |
| 240 AddExtraHeadersIfNeeded(request, resource_context); | 240 AddExtraHeadersIfNeeded(request, resource_context); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void AwResourceDispatcherHostDelegate::RequestComplete( | 243 void AwResourceDispatcherHostDelegate::RequestComplete( |
| 244 net::URLRequest* request) { | 244 net::URLRequest* request) { |
| 245 if (request && !request->status().is_success()) { | 245 if (request && !request->status().is_success()) { |
| 246 const content::ResourceRequestInfo* request_info = | 246 const content::ResourceRequestInfo* request_info = |
| 247 content::ResourceRequestInfo::ForRequest(request); | 247 content::ResourceRequestInfo::ForRequest(request); |
| 248 scoped_ptr<AwContentsIoThreadClient> io_client = | 248 std::unique_ptr<AwContentsIoThreadClient> io_client = |
| 249 AwContentsIoThreadClient::FromID(request_info->GetChildID(), | 249 AwContentsIoThreadClient::FromID(request_info->GetChildID(), |
| 250 request_info->GetRenderFrameID()); | 250 request_info->GetRenderFrameID()); |
| 251 if (io_client) { | 251 if (io_client) { |
| 252 io_client->OnReceivedError(request); | 252 io_client->OnReceivedError(request); |
| 253 } else { | 253 } else { |
| 254 DLOG(WARNING) << "io_client is null, onReceivedError dropped for " << | 254 DLOG(WARNING) << "io_client is null, onReceivedError dropped for " << |
| 255 request->url(); | 255 request->url(); |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 } | 258 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 282 response_headers->GetNormalizedHeader("content-disposition", | 282 response_headers->GetNormalizedHeader("content-disposition", |
| 283 &content_disposition); | 283 &content_disposition); |
| 284 response_headers->GetMimeType(&mime_type); | 284 response_headers->GetMimeType(&mime_type); |
| 285 } | 285 } |
| 286 | 286 |
| 287 request->Cancel(); | 287 request->Cancel(); |
| 288 | 288 |
| 289 const content::ResourceRequestInfo* request_info = | 289 const content::ResourceRequestInfo* request_info = |
| 290 content::ResourceRequestInfo::ForRequest(request); | 290 content::ResourceRequestInfo::ForRequest(request); |
| 291 | 291 |
| 292 scoped_ptr<AwContentsIoThreadClient> io_client = | 292 std::unique_ptr<AwContentsIoThreadClient> io_client = |
| 293 AwContentsIoThreadClient::FromID( | 293 AwContentsIoThreadClient::FromID(child_id, |
| 294 child_id, request_info->GetRenderFrameID()); | 294 request_info->GetRenderFrameID()); |
| 295 | 295 |
| 296 // POST request cannot be repeated in general, so prevent client from | 296 // POST request cannot be repeated in general, so prevent client from |
| 297 // retrying the same request, even if it is with a GET. | 297 // retrying the same request, even if it is with a GET. |
| 298 if ("GET" == request->method() && io_client) { | 298 if ("GET" == request->method() && io_client) { |
| 299 io_client->NewDownload(url, | 299 io_client->NewDownload(url, |
| 300 user_agent, | 300 user_agent, |
| 301 content_disposition, | 301 content_disposition, |
| 302 mime_type, | 302 mime_type, |
| 303 content_length); | 303 content_length); |
| 304 } | 304 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 335 DLOG(FATAL) << "Started request without associated info: " << | 335 DLOG(FATAL) << "Started request without associated info: " << |
| 336 request->url(); | 336 request->url(); |
| 337 return; | 337 return; |
| 338 } | 338 } |
| 339 | 339 |
| 340 if (request_info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME) { | 340 if (request_info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME) { |
| 341 // Check for x-auto-login header. | 341 // Check for x-auto-login header. |
| 342 auto_login_parser::HeaderData header_data; | 342 auto_login_parser::HeaderData header_data; |
| 343 if (auto_login_parser::ParserHeaderInResponse( | 343 if (auto_login_parser::ParserHeaderInResponse( |
| 344 request, auto_login_parser::ALLOW_ANY_REALM, &header_data)) { | 344 request, auto_login_parser::ALLOW_ANY_REALM, &header_data)) { |
| 345 scoped_ptr<AwContentsIoThreadClient> io_client = | 345 std::unique_ptr<AwContentsIoThreadClient> io_client = |
| 346 AwContentsIoThreadClient::FromID(request_info->GetChildID(), | 346 AwContentsIoThreadClient::FromID(request_info->GetChildID(), |
| 347 request_info->GetRenderFrameID()); | 347 request_info->GetRenderFrameID()); |
| 348 if (io_client) { | 348 if (io_client) { |
| 349 io_client->NewLoginRequest( | 349 io_client->NewLoginRequest( |
| 350 header_data.realm, header_data.account, header_data.args); | 350 header_data.realm, header_data.account, header_data.args); |
| 351 } | 351 } |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 | 355 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 net::HttpRequestHeaders headers; | 438 net::HttpRequestHeaders headers; |
| 439 headers.AddHeadersFromString(extra_headers); | 439 headers.AddHeadersFromString(extra_headers); |
| 440 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) { | 440 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) { |
| 441 request->SetExtraRequestHeaderByName(it.name(), it.value(), false); | 441 request->SetExtraRequestHeaderByName(it.name(), it.value(), false); |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 } | 445 } |
| 446 | 446 |
| 447 } // namespace android_webview | 447 } // namespace android_webview |
| OLD | NEW |