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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 | 206 |
| 206 void AwResourceDispatcherHostDelegate::RequestBeginning( | 207 void AwResourceDispatcherHostDelegate::RequestBeginning( |
| 207 net::URLRequest* request, | 208 net::URLRequest* request, |
| 208 content::ResourceContext* resource_context, | 209 content::ResourceContext* resource_context, |
| 209 appcache::AppCacheService* appcache_service, | 210 appcache::AppCacheService* appcache_service, |
| 210 ResourceType::Type resource_type, | 211 ResourceType::Type resource_type, |
| 211 int child_id, | 212 int child_id, |
| 212 int route_id, | 213 int route_id, |
| 213 ScopedVector<content::ResourceThrottle>* throttles) { | 214 ScopedVector<content::ResourceThrottle>* throttles) { |
| 214 | 215 |
| 216 AddExtraHeadersIfNeeded(request, resource_context); | |
| 217 | |
| 215 // We always push the throttles here. Checking the existence of io_client | 218 // We always push the throttles here. Checking the existence of io_client |
| 216 // is racy when a popup window is created. That is because RequestBeginning | 219 // is racy when a popup window is created. That is because RequestBeginning |
| 217 // is called whether or not requests are blocked via BlockRequestForRoute() | 220 // is called whether or not requests are blocked via BlockRequestForRoute() |
| 218 // however io_client may or may not be ready at the time depending on whether | 221 // however io_client may or may not be ready at the time depending on whether |
| 219 // webcontents is created. | 222 // webcontents is created. |
| 220 throttles->push_back(new IoThreadClientThrottle( | 223 throttles->push_back(new IoThreadClientThrottle( |
| 221 child_id, route_id, request)); | 224 child_id, route_id, request)); |
| 222 | 225 |
| 223 // We allow intercepting only navigations within main frames. This | 226 // We allow intercepting only navigations within main frames. This |
| 224 // is used to post onPageStarted. We handle shouldOverrideUrlLoading | 227 // is used to post onPageStarted. We handle shouldOverrideUrlLoading |
| 225 // via a sync IPC. | 228 // via a sync IPC. |
| 226 if (resource_type == ResourceType::MAIN_FRAME) | 229 if (resource_type == ResourceType::MAIN_FRAME) |
| 227 throttles->push_back(InterceptNavigationDelegate::CreateThrottleFor( | 230 throttles->push_back(InterceptNavigationDelegate::CreateThrottleFor( |
| 228 request)); | 231 request)); |
| 229 } | 232 } |
| 230 | 233 |
| 234 void AwResourceDispatcherHostDelegate::OnRequestRedirected( | |
| 235 const GURL& redirect_url, | |
| 236 net::URLRequest* request, | |
| 237 content::ResourceContext* resource_context, | |
| 238 content::ResourceResponse* response) { | |
| 239 AddExtraHeadersIfNeeded(request, resource_context); | |
| 240 } | |
| 241 | |
| 242 | |
| 231 void AwResourceDispatcherHostDelegate::DownloadStarting( | 243 void AwResourceDispatcherHostDelegate::DownloadStarting( |
| 232 net::URLRequest* request, | 244 net::URLRequest* request, |
| 233 content::ResourceContext* resource_context, | 245 content::ResourceContext* resource_context, |
| 234 int child_id, | 246 int child_id, |
| 235 int route_id, | 247 int route_id, |
| 236 int request_id, | 248 int request_id, |
| 237 bool is_content_initiated, | 249 bool is_content_initiated, |
| 238 bool must_download, | 250 bool must_download, |
| 239 ScopedVector<content::ResourceThrottle>* throttles) { | 251 ScopedVector<content::ResourceThrottle>* throttles) { |
| 240 GURL url(request->url()); | 252 GURL url(request->url()); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 PendingThrottleMap::iterator it = pending_throttles_.find( | 398 PendingThrottleMap::iterator it = pending_throttles_.find( |
| 387 ChildRouteIDPair(new_child_id, new_route_id)); | 399 ChildRouteIDPair(new_child_id, new_route_id)); |
| 388 | 400 |
| 389 if (it != pending_throttles_.end()) { | 401 if (it != pending_throttles_.end()) { |
| 390 IoThreadClientThrottle* throttle = it->second; | 402 IoThreadClientThrottle* throttle = it->second; |
| 391 throttle->OnIoThreadClientReady(new_child_id, new_route_id); | 403 throttle->OnIoThreadClientReady(new_child_id, new_route_id); |
| 392 pending_throttles_.erase(it); | 404 pending_throttles_.erase(it); |
| 393 } | 405 } |
| 394 } | 406 } |
| 395 | 407 |
| 408 void AwResourceDispatcherHostDelegate::AddExtraHeadersIfNeeded( | |
| 409 net::URLRequest* request, | |
| 410 content::ResourceContext* resource_context) { | |
| 411 const content::ResourceRequestInfo* request_info = | |
| 412 content::ResourceRequestInfo::ForRequest(request); | |
| 413 if (!request_info) return; | |
| 414 if (request_info->GetResourceType() != ResourceType::MAIN_FRAME) return; | |
| 415 | |
| 416 const bool is_load_url = request_info->GetPageTransition() & | |
| 417 content::PAGE_TRANSITION_FROM_API; | |
| 418 const bool is_go_back_forward = request_info->GetPageTransition() & | |
| 419 content::PAGE_TRANSITION_FORWARD_BACK; | |
| 420 const bool is_reload = content::PageTransitionCoreTypeIs( | |
| 421 request_info->GetPageTransition(), content::PAGE_TRANSITION_RELOAD); | |
|
bulach
2013/12/10 15:16:57
nit: perhaps unroll request_info->GetPageTransitio
mnaganov (inactive)
2013/12/10 16:00:37
Done.
| |
| 422 if (is_load_url || is_go_back_forward || is_reload) { | |
| 423 AwResourceContext* awrc = static_cast<AwResourceContext*>(resource_context); | |
| 424 std::string extra_headers = awrc->GetExtraHeaders(request->url()); | |
| 425 if (!extra_headers.empty()) { | |
| 426 net::HttpRequestHeaders headers; | |
| 427 headers.AddHeadersFromString(extra_headers); | |
| 428 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) { | |
| 429 request->SetExtraRequestHeaderByName(it.name(), it.value(), false); | |
| 430 } | |
| 431 } | |
| 432 } | |
| 433 } | |
| 434 | |
| 396 } // namespace android_webview | 435 } // namespace android_webview |
| OLD | NEW |