Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "android_webview/browser/aw_contents_io_thread_client.h" | 9 #include "android_webview/browser/aw_contents_io_thread_client.h" |
| 10 #include "android_webview/browser/aw_login_delegate.h" | 10 #include "android_webview/browser/aw_login_delegate.h" |
| 11 #include "android_webview/browser/aw_resource_context.h" | |
| 11 #include "android_webview/common/url_constants.h" | 12 #include "android_webview/common/url_constants.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 14 #include "components/auto_login_parser/auto_login_parser.h" | 15 #include "components/auto_login_parser/auto_login_parser.h" |
| 15 #include "components/navigation_interception/intercept_navigation_delegate.h" | 16 #include "components/navigation_interception/intercept_navigation_delegate.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/resource_controller.h" | 18 #include "content/public/browser/resource_controller.h" |
| 18 #include "content/public/browser/resource_dispatcher_host.h" | 19 #include "content/public/browser/resource_dispatcher_host.h" |
| 19 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" | 20 #include "content/public/browser/resource_dispatcher_host_login_delegate.h" |
| 20 #include "content/public/browser/resource_request_info.h" | 21 #include "content/public/browser/resource_request_info.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 ScopedVector<content::ResourceThrottle>* throttles) { | 219 ScopedVector<content::ResourceThrottle>* throttles) { |
| 219 // If io_client is NULL, then the browser side objects have already been | 220 // If io_client is NULL, then the browser side objects have already been |
| 220 // destroyed, so do not do anything to the request. Conversely if the | 221 // destroyed, so do not do anything to the request. Conversely if the |
| 221 // request relates to a not-yet-created popup window, then the client will | 222 // request relates to a not-yet-created popup window, then the client will |
| 222 // be non-NULL but PopupPendingAssociation() will be set. | 223 // be non-NULL but PopupPendingAssociation() will be set. |
| 223 scoped_ptr<AwContentsIoThreadClient> io_client = | 224 scoped_ptr<AwContentsIoThreadClient> io_client = |
| 224 AwContentsIoThreadClient::FromID(child_id, route_id); | 225 AwContentsIoThreadClient::FromID(child_id, route_id); |
| 225 if (!io_client) | 226 if (!io_client) |
| 226 return; | 227 return; |
| 227 | 228 |
| 229 AddExtraHeadersIfNeeded(request, resource_context); | |
| 230 | |
| 228 throttles->push_back(new IoThreadClientThrottle( | 231 throttles->push_back(new IoThreadClientThrottle( |
| 229 child_id, route_id, request)); | 232 child_id, route_id, request)); |
| 230 | 233 |
| 231 bool allow_intercepting = | 234 bool allow_intercepting = |
| 232 // We allow intercepting navigations within subframes, but only if the | 235 // We allow intercepting navigations within subframes, but only if the |
| 233 // scheme other than http or https. This is because the embedder | 236 // scheme other than http or https. This is because the embedder |
| 234 // can't distinguish main frame and subframe callbacks (which could lead | 237 // can't distinguish main frame and subframe callbacks (which could lead |
| 235 // to broken content if the embedder decides to not ignore the main frame | 238 // to broken content if the embedder decides to not ignore the main frame |
| 236 // navigation, but ignores the subframe navigation). | 239 // navigation, but ignores the subframe navigation). |
| 237 // The reason this is supported at all is that certain JavaScript-based | 240 // The reason this is supported at all is that certain JavaScript-based |
| 238 // frameworks use iframe navigation as a form of communication with the | 241 // frameworks use iframe navigation as a form of communication with the |
| 239 // embedder. | 242 // embedder. |
| 240 (resource_type == ResourceType::MAIN_FRAME || | 243 (resource_type == ResourceType::MAIN_FRAME || |
| 241 (resource_type == ResourceType::SUB_FRAME && | 244 (resource_type == ResourceType::SUB_FRAME && |
| 242 !request->url().SchemeIs(content::kHttpScheme) && | 245 !request->url().SchemeIs(content::kHttpScheme) && |
| 243 !request->url().SchemeIs(content::kHttpsScheme))); | 246 !request->url().SchemeIs(content::kHttpsScheme))); |
| 244 if (allow_intercepting) { | 247 if (allow_intercepting) { |
| 245 throttles->push_back(InterceptNavigationDelegate::CreateThrottleFor( | 248 throttles->push_back(InterceptNavigationDelegate::CreateThrottleFor( |
| 246 request)); | 249 request)); |
| 247 } | 250 } |
| 248 } | 251 } |
| 249 | 252 |
| 253 void AwResourceDispatcherHostDelegate::OnRequestRedirected( | |
| 254 const GURL& redirect_url, | |
| 255 net::URLRequest* request, | |
| 256 content::ResourceContext* resource_context, | |
| 257 content::ResourceResponse* response) { | |
| 258 AddExtraHeadersIfNeeded(request, resource_context); | |
| 259 } | |
| 260 | |
| 261 | |
| 250 void AwResourceDispatcherHostDelegate::DownloadStarting( | 262 void AwResourceDispatcherHostDelegate::DownloadStarting( |
| 251 net::URLRequest* request, | 263 net::URLRequest* request, |
| 252 content::ResourceContext* resource_context, | 264 content::ResourceContext* resource_context, |
| 253 int child_id, | 265 int child_id, |
| 254 int route_id, | 266 int route_id, |
| 255 int request_id, | 267 int request_id, |
| 256 bool is_content_initiated, | 268 bool is_content_initiated, |
| 257 bool must_download, | 269 bool must_download, |
| 258 ScopedVector<content::ResourceThrottle>* throttles) { | 270 ScopedVector<content::ResourceThrottle>* throttles) { |
| 259 GURL url(request->url()); | 271 GURL url(request->url()); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 PendingThrottleMap::iterator it = pending_throttles_.find( | 417 PendingThrottleMap::iterator it = pending_throttles_.find( |
| 406 ChildRouteIDPair(new_child_id, new_route_id)); | 418 ChildRouteIDPair(new_child_id, new_route_id)); |
| 407 | 419 |
| 408 if (it != pending_throttles_.end()) { | 420 if (it != pending_throttles_.end()) { |
| 409 IoThreadClientThrottle* throttle = it->second; | 421 IoThreadClientThrottle* throttle = it->second; |
| 410 throttle->OnIoThreadClientReady(new_child_id, new_route_id); | 422 throttle->OnIoThreadClientReady(new_child_id, new_route_id); |
| 411 pending_throttles_.erase(it); | 423 pending_throttles_.erase(it); |
| 412 } | 424 } |
| 413 } | 425 } |
| 414 | 426 |
| 427 void AwResourceDispatcherHostDelegate::AddExtraHeadersIfNeeded( | |
| 428 net::URLRequest* request, | |
| 429 content::ResourceContext* resource_context) { | |
| 430 const content::ResourceRequestInfo* request_info = | |
| 431 content::ResourceRequestInfo::ForRequest(request); | |
| 432 if (!request_info) return; | |
| 433 if (request_info->GetResourceType() != ResourceType::MAIN_FRAME) return; | |
| 434 | |
| 435 const bool is_load_url = request_info->GetPageTransition() & | |
| 436 content::PAGE_TRANSITION_FROM_API; | |
| 437 const bool is_go_back_forward = request_info->GetPageTransition() & | |
| 438 content::PAGE_TRANSITION_FORWARD_BACK; | |
| 439 const bool is_reload = content::PageTransitionCoreTypeIs( | |
| 440 request_info->GetPageTransition(), content::PAGE_TRANSITION_RELOAD); | |
| 441 if (is_load_url || is_go_back_forward || is_reload) { | |
| 442 AwResourceContext* awrc = static_cast<AwResourceContext*>(resource_context); | |
| 443 std::string extra_headers = awrc->GetExtraHeaders(request->url()); | |
| 444 if (!extra_headers.empty()) { | |
| 445 net::HttpRequestHeaders headers; | |
| 446 headers.AddHeadersFromString(extra_headers); | |
| 447 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) { | |
| 448 request->SetExtraRequestHeaderByName(it.name(), it.value(), true); | |
|
benm (inactive)
2013/12/09 17:49:11
What's the behaviour in Classic vs. Chromium WebVi
mnaganov (inactive)
2013/12/10 11:03:31
That's a good catch! In fact, the old WebView seem
| |
| 449 } | |
| 450 } | |
| 451 } | |
| 452 } | |
| 453 | |
| 415 } // namespace android_webview | 454 } // namespace android_webview |
| OLD | NEW |