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" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 : content::ResourceDispatcherHostDelegate() { | 204 : content::ResourceDispatcherHostDelegate() { |
205 } | 205 } |
206 | 206 |
207 AwResourceDispatcherHostDelegate::~AwResourceDispatcherHostDelegate() { | 207 AwResourceDispatcherHostDelegate::~AwResourceDispatcherHostDelegate() { |
208 } | 208 } |
209 | 209 |
210 void AwResourceDispatcherHostDelegate::RequestBeginning( | 210 void AwResourceDispatcherHostDelegate::RequestBeginning( |
211 net::URLRequest* request, | 211 net::URLRequest* request, |
212 content::ResourceContext* resource_context, | 212 content::ResourceContext* resource_context, |
213 content::AppCacheService* appcache_service, | 213 content::AppCacheService* appcache_service, |
214 ResourceType::Type resource_type, | 214 ResourceType resource_type, |
215 int child_id, | 215 int child_id, |
216 int route_id, | 216 int route_id, |
217 ScopedVector<content::ResourceThrottle>* throttles) { | 217 ScopedVector<content::ResourceThrottle>* throttles) { |
218 | 218 |
219 AddExtraHeadersIfNeeded(request, resource_context); | 219 AddExtraHeadersIfNeeded(request, resource_context); |
220 | 220 |
221 const content::ResourceRequestInfo* request_info = | 221 const content::ResourceRequestInfo* request_info = |
222 content::ResourceRequestInfo::ForRequest(request); | 222 content::ResourceRequestInfo::ForRequest(request); |
223 | 223 |
224 // We always push the throttles here. Checking the existence of io_client | 224 // We always push the throttles here. Checking the existence of io_client |
225 // is racy when a popup window is created. That is because RequestBeginning | 225 // is racy when a popup window is created. That is because RequestBeginning |
226 // is called whether or not requests are blocked via BlockRequestForRoute() | 226 // is called whether or not requests are blocked via BlockRequestForRoute() |
227 // however io_client may or may not be ready at the time depending on whether | 227 // however io_client may or may not be ready at the time depending on whether |
228 // webcontents is created. | 228 // webcontents is created. |
229 throttles->push_back(new IoThreadClientThrottle( | 229 throttles->push_back(new IoThreadClientThrottle( |
230 child_id, request_info->GetRenderFrameID(), request)); | 230 child_id, request_info->GetRenderFrameID(), request)); |
231 | 231 |
232 // We allow intercepting only navigations within main frames. This | 232 // We allow intercepting only navigations within main frames. This |
233 // is used to post onPageStarted. We handle shouldOverrideUrlLoading | 233 // is used to post onPageStarted. We handle shouldOverrideUrlLoading |
234 // via a sync IPC. | 234 // via a sync IPC. |
235 if (resource_type == ResourceType::MAIN_FRAME) | 235 if (resource_type == content::RESOURCE_TYPE_MAIN_FRAME) |
236 throttles->push_back(InterceptNavigationDelegate::CreateThrottleFor( | 236 throttles->push_back(InterceptNavigationDelegate::CreateThrottleFor( |
237 request)); | 237 request)); |
238 } | 238 } |
239 | 239 |
240 void AwResourceDispatcherHostDelegate::OnRequestRedirected( | 240 void AwResourceDispatcherHostDelegate::OnRequestRedirected( |
241 const GURL& redirect_url, | 241 const GURL& redirect_url, |
242 net::URLRequest* request, | 242 net::URLRequest* request, |
243 content::ResourceContext* resource_context, | 243 content::ResourceContext* resource_context, |
244 content::ResourceResponse* response) { | 244 content::ResourceResponse* response) { |
245 AddExtraHeadersIfNeeded(request, resource_context); | 245 AddExtraHeadersIfNeeded(request, resource_context); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 content::ResourceResponse* response, | 314 content::ResourceResponse* response, |
315 IPC::Sender* sender) { | 315 IPC::Sender* sender) { |
316 const content::ResourceRequestInfo* request_info = | 316 const content::ResourceRequestInfo* request_info = |
317 content::ResourceRequestInfo::ForRequest(request); | 317 content::ResourceRequestInfo::ForRequest(request); |
318 if (!request_info) { | 318 if (!request_info) { |
319 DLOG(FATAL) << "Started request without associated info: " << | 319 DLOG(FATAL) << "Started request without associated info: " << |
320 request->url(); | 320 request->url(); |
321 return; | 321 return; |
322 } | 322 } |
323 | 323 |
324 if (request_info->GetResourceType() == ResourceType::MAIN_FRAME) { | 324 if (request_info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME) { |
325 // Check for x-auto-login header. | 325 // Check for x-auto-login header. |
326 auto_login_parser::HeaderData header_data; | 326 auto_login_parser::HeaderData header_data; |
327 if (auto_login_parser::ParserHeaderInResponse( | 327 if (auto_login_parser::ParserHeaderInResponse( |
328 request, auto_login_parser::ALLOW_ANY_REALM, &header_data)) { | 328 request, auto_login_parser::ALLOW_ANY_REALM, &header_data)) { |
329 scoped_ptr<AwContentsIoThreadClient> io_client = | 329 scoped_ptr<AwContentsIoThreadClient> io_client = |
330 AwContentsIoThreadClient::FromID(request_info->GetChildID(), | 330 AwContentsIoThreadClient::FromID(request_info->GetChildID(), |
331 request_info->GetRenderFrameID()); | 331 request_info->GetRenderFrameID()); |
332 if (io_client) { | 332 if (io_client) { |
333 io_client->NewLoginRequest( | 333 io_client->NewLoginRequest( |
334 header_data.realm, header_data.account, header_data.args); | 334 header_data.realm, header_data.account, header_data.args); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 throttle->OnIoThreadClientReady(new_render_process_id, new_render_frame_id); | 396 throttle->OnIoThreadClientReady(new_render_process_id, new_render_frame_id); |
397 pending_throttles_.erase(it); | 397 pending_throttles_.erase(it); |
398 } | 398 } |
399 } | 399 } |
400 | 400 |
401 void AwResourceDispatcherHostDelegate::AddExtraHeadersIfNeeded( | 401 void AwResourceDispatcherHostDelegate::AddExtraHeadersIfNeeded( |
402 net::URLRequest* request, | 402 net::URLRequest* request, |
403 content::ResourceContext* resource_context) { | 403 content::ResourceContext* resource_context) { |
404 const content::ResourceRequestInfo* request_info = | 404 const content::ResourceRequestInfo* request_info = |
405 content::ResourceRequestInfo::ForRequest(request); | 405 content::ResourceRequestInfo::ForRequest(request); |
406 if (!request_info) return; | 406 if (!request_info) |
407 if (request_info->GetResourceType() != ResourceType::MAIN_FRAME) return; | 407 return; |
| 408 if (request_info->GetResourceType() != content::RESOURCE_TYPE_MAIN_FRAME) |
| 409 return; |
408 | 410 |
409 const content::PageTransition transition = request_info->GetPageTransition(); | 411 const content::PageTransition transition = request_info->GetPageTransition(); |
410 const bool is_load_url = | 412 const bool is_load_url = |
411 transition & content::PAGE_TRANSITION_FROM_API; | 413 transition & content::PAGE_TRANSITION_FROM_API; |
412 const bool is_go_back_forward = | 414 const bool is_go_back_forward = |
413 transition & content::PAGE_TRANSITION_FORWARD_BACK; | 415 transition & content::PAGE_TRANSITION_FORWARD_BACK; |
414 const bool is_reload = content::PageTransitionCoreTypeIs( | 416 const bool is_reload = content::PageTransitionCoreTypeIs( |
415 transition, content::PAGE_TRANSITION_RELOAD); | 417 transition, content::PAGE_TRANSITION_RELOAD); |
416 if (is_load_url || is_go_back_forward || is_reload) { | 418 if (is_load_url || is_go_back_forward || is_reload) { |
417 AwResourceContext* awrc = static_cast<AwResourceContext*>(resource_context); | 419 AwResourceContext* awrc = static_cast<AwResourceContext*>(resource_context); |
418 std::string extra_headers = awrc->GetExtraHeaders(request->url()); | 420 std::string extra_headers = awrc->GetExtraHeaders(request->url()); |
419 if (!extra_headers.empty()) { | 421 if (!extra_headers.empty()) { |
420 net::HttpRequestHeaders headers; | 422 net::HttpRequestHeaders headers; |
421 headers.AddHeadersFromString(extra_headers); | 423 headers.AddHeadersFromString(extra_headers); |
422 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) { | 424 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext(); ) { |
423 request->SetExtraRequestHeaderByName(it.name(), it.value(), false); | 425 request->SetExtraRequestHeaderByName(it.name(), it.value(), false); |
424 } | 426 } |
425 } | 427 } |
426 } | 428 } |
427 } | 429 } |
428 | 430 |
429 } // namespace android_webview | 431 } // namespace android_webview |
OLD | NEW |