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 "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" | 5 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 #include "extensions/common/constants.h" | 72 #include "extensions/common/constants.h" |
73 #include "extensions/common/extension_urls.h" | 73 #include "extensions/common/extension_urls.h" |
74 #include "extensions/common/manifest_handlers/mime_types_handler.h" | 74 #include "extensions/common/manifest_handlers/mime_types_handler.h" |
75 #include "extensions/common/user_script.h" | 75 #include "extensions/common/user_script.h" |
76 #endif | 76 #endif |
77 | 77 |
78 #if defined(ENABLE_SUPERVISED_USERS) | 78 #if defined(ENABLE_SUPERVISED_USERS) |
79 #include "chrome/browser/supervised_user/supervised_user_resource_throttle.h" | 79 #include "chrome/browser/supervised_user/supervised_user_resource_throttle.h" |
80 #endif | 80 #endif |
81 | 81 |
| 82 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 83 #include "chrome/browser/ui/sync/one_click_signin_helper.h" |
| 84 #endif |
| 85 |
82 #if defined(USE_SYSTEM_PROTOBUF) | 86 #if defined(USE_SYSTEM_PROTOBUF) |
83 #include <google/protobuf/repeated_field.h> | 87 #include <google/protobuf/repeated_field.h> |
84 #else | 88 #else |
85 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" | 89 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" |
86 #endif | 90 #endif |
87 | 91 |
88 #if defined(OS_ANDROID) | 92 #if defined(OS_ANDROID) |
89 #include "chrome/browser/android/intercept_download_resource_throttle.h" | 93 #include "chrome/browser/android/intercept_download_resource_throttle.h" |
90 #include "components/navigation_interception/intercept_navigation_delegate.h" | 94 #include "components/navigation_interception/intercept_navigation_delegate.h" |
91 #endif | 95 #endif |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 bool is_off_the_record = io_data->IsOffTheRecord(); | 432 bool is_off_the_record = io_data->IsOffTheRecord(); |
429 variations::VariationsHttpHeaderProvider::GetInstance()-> | 433 variations::VariationsHttpHeaderProvider::GetInstance()-> |
430 AppendHeaders(request->url(), | 434 AppendHeaders(request->url(), |
431 is_off_the_record, | 435 is_off_the_record, |
432 !is_off_the_record && | 436 !is_off_the_record && |
433 io_data->GetMetricsEnabledStateOnIOThread(), | 437 io_data->GetMetricsEnabledStateOnIOThread(), |
434 &headers); | 438 &headers); |
435 request->SetExtraRequestHeaders(headers); | 439 request->SetExtraRequestHeaders(headers); |
436 } | 440 } |
437 | 441 |
| 442 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 443 AppendChromeSyncGaiaHeader(request, resource_context); |
| 444 #endif |
| 445 |
438 #if defined(ENABLE_CONFIGURATION_POLICY) | 446 #if defined(ENABLE_CONFIGURATION_POLICY) |
439 if (io_data->policy_header_helper()) | 447 if (io_data->policy_header_helper()) |
440 io_data->policy_header_helper()->AddPolicyHeaders(request->url(), request); | 448 io_data->policy_header_helper()->AddPolicyHeaders(request->url(), request); |
441 #endif | 449 #endif |
442 | 450 |
443 signin::AppendMirrorRequestHeaderIfPossible( | 451 signin::AppendMirrorRequestHeaderIfPossible( |
444 request, GURL() /* redirect_url */, io_data, | 452 request, GURL() /* redirect_url */, io_data, |
445 info->GetChildID(), info->GetRouteID()); | 453 info->GetChildID(), info->GetRouteID()); |
446 | 454 |
447 AppendStandardResourceThrottles(request, | 455 AppendStandardResourceThrottles(request, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 if (throttle) | 586 if (throttle) |
579 throttles->push_back(throttle); | 587 throttles->push_back(throttle); |
580 #endif | 588 #endif |
581 | 589 |
582 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 590 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
583 if (info->GetVisibilityState() == blink::WebPageVisibilityStatePrerender) { | 591 if (info->GetVisibilityState() == blink::WebPageVisibilityStatePrerender) { |
584 throttles->push_back(new prerender::PrerenderResourceThrottle(request)); | 592 throttles->push_back(new prerender::PrerenderResourceThrottle(request)); |
585 } | 593 } |
586 } | 594 } |
587 | 595 |
| 596 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 597 void ChromeResourceDispatcherHostDelegate::AppendChromeSyncGaiaHeader( |
| 598 net::URLRequest* request, |
| 599 content::ResourceContext* resource_context) { |
| 600 static const char kAllowChromeSignIn[] = "Allow-Chrome-SignIn"; |
| 601 |
| 602 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 603 OneClickSigninHelper::Offer offer = |
| 604 OneClickSigninHelper::CanOfferOnIOThread(request, io_data); |
| 605 switch (offer) { |
| 606 case OneClickSigninHelper::CAN_OFFER: |
| 607 request->SetExtraRequestHeaderByName(kAllowChromeSignIn, "1", false); |
| 608 break; |
| 609 case OneClickSigninHelper::DONT_OFFER: |
| 610 request->RemoveRequestHeaderByName(kAllowChromeSignIn); |
| 611 break; |
| 612 case OneClickSigninHelper::IGNORE_REQUEST: |
| 613 break; |
| 614 } |
| 615 } |
| 616 #endif |
| 617 |
588 bool ChromeResourceDispatcherHostDelegate::ShouldForceDownloadResource( | 618 bool ChromeResourceDispatcherHostDelegate::ShouldForceDownloadResource( |
589 const GURL& url, const std::string& mime_type) { | 619 const GURL& url, const std::string& mime_type) { |
590 #if defined(ENABLE_EXTENSIONS) | 620 #if defined(ENABLE_EXTENSIONS) |
591 // Special-case user scripts to get downloaded instead of viewed. | 621 // Special-case user scripts to get downloaded instead of viewed. |
592 return extensions::UserScript::IsURLUserScript(url, mime_type); | 622 return extensions::UserScript::IsURLUserScript(url, mime_type); |
593 #else | 623 #else |
594 return false; | 624 return false; |
595 #endif | 625 #endif |
596 } | 626 } |
597 | 627 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 } | 696 } |
667 | 697 |
668 void ChromeResourceDispatcherHostDelegate::OnResponseStarted( | 698 void ChromeResourceDispatcherHostDelegate::OnResponseStarted( |
669 net::URLRequest* request, | 699 net::URLRequest* request, |
670 content::ResourceContext* resource_context, | 700 content::ResourceContext* resource_context, |
671 content::ResourceResponse* response, | 701 content::ResourceResponse* response, |
672 IPC::Sender* sender) { | 702 IPC::Sender* sender) { |
673 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 703 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
674 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 704 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
675 | 705 |
| 706 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 707 // See if the response contains the Google-Accounts-SignIn header. If so, |
| 708 // then the user has just finished signing in, and the server is allowing the |
| 709 // browser to suggest connecting the user's profile to the account. |
| 710 OneClickSigninHelper::ShowInfoBarIfPossible(request, io_data, |
| 711 info->GetChildID(), |
| 712 info->GetRouteID()); |
| 713 #endif |
| 714 |
676 // See if the response contains the X-Chrome-Manage-Accounts header. If so | 715 // See if the response contains the X-Chrome-Manage-Accounts header. If so |
677 // show the profile avatar bubble so that user can complete signin/out action | 716 // show the profile avatar bubble so that user can complete signin/out action |
678 // the native UI. | 717 // the native UI. |
679 signin::ProcessMirrorResponseHeaderIfExists(request, io_data, | 718 signin::ProcessMirrorResponseHeaderIfExists(request, io_data, |
680 info->GetChildID(), | 719 info->GetChildID(), |
681 info->GetRouteID()); | 720 info->GetRouteID()); |
682 | 721 |
683 // Build in additional protection for the chrome web store origin. | 722 // Build in additional protection for the chrome web store origin. |
684 #if defined(ENABLE_EXTENSIONS) | 723 #if defined(ENABLE_EXTENSIONS) |
685 GURL webstore_url(extension_urls::GetWebstoreLaunchURL()); | 724 GURL webstore_url(extension_urls::GetWebstoreLaunchURL()); |
(...skipping 29 matching lines...) Expand all Loading... |
715 | 754 |
716 void ChromeResourceDispatcherHostDelegate::OnRequestRedirected( | 755 void ChromeResourceDispatcherHostDelegate::OnRequestRedirected( |
717 const GURL& redirect_url, | 756 const GURL& redirect_url, |
718 net::URLRequest* request, | 757 net::URLRequest* request, |
719 content::ResourceContext* resource_context, | 758 content::ResourceContext* resource_context, |
720 content::ResourceResponse* response) { | 759 content::ResourceResponse* response) { |
721 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); | 760 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
722 | 761 |
723 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 762 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
724 | 763 |
| 764 #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 765 // See if the response contains the Google-Accounts-SignIn header. If so, |
| 766 // then the user has just finished signing in, and the server is allowing the |
| 767 // browser to suggest connecting the user's profile to the account. |
| 768 OneClickSigninHelper::ShowInfoBarIfPossible(request, io_data, |
| 769 info->GetChildID(), |
| 770 info->GetRouteID()); |
| 771 AppendChromeSyncGaiaHeader(request, resource_context); |
| 772 #endif |
| 773 |
725 // In the Mirror world, Chrome should append a X-Chrome-Connected header to | 774 // In the Mirror world, Chrome should append a X-Chrome-Connected header to |
726 // all Gaia requests from a connected profile so Gaia could return a 204 | 775 // all Gaia requests from a connected profile so Gaia could return a 204 |
727 // response and let Chrome handle the action with native UI. The only | 776 // response and let Chrome handle the action with native UI. The only |
728 // exception is requests from gaia webview, since the native profile | 777 // exception is requests from gaia webview, since the native profile |
729 // management UI is built on top of it. | 778 // management UI is built on top of it. |
730 signin::AppendMirrorRequestHeaderIfPossible(request, redirect_url, io_data, | 779 signin::AppendMirrorRequestHeaderIfPossible(request, redirect_url, io_data, |
731 info->GetChildID(), info->GetRouteID()); | 780 info->GetChildID(), info->GetRouteID()); |
732 | 781 |
733 if (io_data->resource_prefetch_predictor_observer()) { | 782 if (io_data->resource_prefetch_predictor_observer()) { |
734 io_data->resource_prefetch_predictor_observer()->OnRequestRedirected( | 783 io_data->resource_prefetch_predictor_observer()->OnRequestRedirected( |
(...skipping 21 matching lines...) Expand all Loading... |
756 url_request->GetTotalReceivedBytes())); | 805 url_request->GetTotalReceivedBytes())); |
757 } | 806 } |
758 } | 807 } |
759 | 808 |
760 // static | 809 // static |
761 void ChromeResourceDispatcherHostDelegate:: | 810 void ChromeResourceDispatcherHostDelegate:: |
762 SetExternalProtocolHandlerDelegateForTesting( | 811 SetExternalProtocolHandlerDelegateForTesting( |
763 ExternalProtocolHandler::Delegate* delegate) { | 812 ExternalProtocolHandler::Delegate* delegate) { |
764 g_external_protocol_handler_delegate = delegate; | 813 g_external_protocol_handler_delegate = delegate; |
765 } | 814 } |
OLD | NEW |