Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: chrome/browser/chrome_content_browser_client.cc

Issue 2368923003: Support the Clear-Site-Data header on resource requests (Closed)
Patch Set: Addressed comments, formatted. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/chrome_content_browser_client.h" 5 #include "chrome/browser/chrome_content_browser_client.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 #include "components/task_scheduler_util/common/variations_util.h" 154 #include "components/task_scheduler_util/common/variations_util.h"
155 #include "components/translate/core/common/translate_switches.h" 155 #include "components/translate/core/common/translate_switches.h"
156 #include "components/url_formatter/url_fixer.h" 156 #include "components/url_formatter/url_fixer.h"
157 #include "components/variations/variations_associated_data.h" 157 #include "components/variations/variations_associated_data.h"
158 #include "components/version_info/version_info.h" 158 #include "components/version_info/version_info.h"
159 #include "content/public/browser/browser_child_process_host.h" 159 #include "content/public/browser/browser_child_process_host.h"
160 #include "content/public/browser/browser_main_parts.h" 160 #include "content/public/browser/browser_main_parts.h"
161 #include "content/public/browser/browser_ppapi_host.h" 161 #include "content/public/browser/browser_ppapi_host.h"
162 #include "content/public/browser/browser_thread.h" 162 #include "content/public/browser/browser_thread.h"
163 #include "content/public/browser/browser_url_handler.h" 163 #include "content/public/browser/browser_url_handler.h"
164 #include "content/public/browser/browsing_data_filter_builder.h"
165 #include "content/public/browser/browsing_data_remover.h" 164 #include "content/public/browser/browsing_data_remover.h"
166 #include "content/public/browser/child_process_data.h" 165 #include "content/public/browser/child_process_data.h"
167 #include "content/public/browser/child_process_security_policy.h" 166 #include "content/public/browser/child_process_security_policy.h"
168 #include "content/public/browser/client_certificate_delegate.h" 167 #include "content/public/browser/client_certificate_delegate.h"
169 #include "content/public/browser/navigation_handle.h" 168 #include "content/public/browser/navigation_handle.h"
170 #include "content/public/browser/navigation_throttle.h" 169 #include "content/public/browser/navigation_throttle.h"
171 #include "content/public/browser/render_frame_host.h" 170 #include "content/public/browser/render_frame_host.h"
172 #include "content/public/browser/render_process_host.h" 171 #include "content/public/browser/render_process_host.h"
173 #include "content/public/browser/render_view_host.h" 172 #include "content/public/browser/render_view_host.h"
174 #include "content/public/browser/resource_context.h" 173 #include "content/public/browser/resource_context.h"
(...skipping 13 matching lines...) Expand all
188 #include "device/bluetooth/adapter_factory.h" 187 #include "device/bluetooth/adapter_factory.h"
189 #include "device/bluetooth/public/interfaces/adapter.mojom.h" 188 #include "device/bluetooth/public/interfaces/adapter.mojom.h"
190 #include "device/usb/public/interfaces/chooser_service.mojom.h" 189 #include "device/usb/public/interfaces/chooser_service.mojom.h"
191 #include "device/usb/public/interfaces/device_manager.mojom.h" 190 #include "device/usb/public/interfaces/device_manager.mojom.h"
192 #include "extensions/features/features.h" 191 #include "extensions/features/features.h"
193 #include "gpu/config/gpu_switches.h" 192 #include "gpu/config/gpu_switches.h"
194 #include "media/audio/audio_manager.h" 193 #include "media/audio/audio_manager.h"
195 #include "media/media_features.h" 194 #include "media/media_features.h"
196 #include "media/mojo/features.h" 195 #include "media/mojo/features.h"
197 #include "net/base/mime_util.h" 196 #include "net/base/mime_util.h"
198 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
199 #include "net/cookies/canonical_cookie.h" 197 #include "net/cookies/canonical_cookie.h"
200 #include "net/cookies/cookie_options.h" 198 #include "net/cookies/cookie_options.h"
201 #include "net/ssl/ssl_cert_request_info.h" 199 #include "net/ssl/ssl_cert_request_info.h"
202 #include "ppapi/features/features.h" 200 #include "ppapi/features/features.h"
203 #include "ppapi/host/ppapi_host.h" 201 #include "ppapi/host/ppapi_host.h"
204 #include "printing/features/features.h" 202 #include "printing/features/features.h"
205 #include "services/preferences/public/interfaces/preferences.mojom.h" 203 #include "services/preferences/public/interfaces/preferences.mojom.h"
206 #include "services/service_manager/public/cpp/binder_registry.h" 204 #include "services/service_manager/public/cpp/binder_registry.h"
207 #include "services/service_manager/public/cpp/interface_provider.h" 205 #include "services/service_manager/public/cpp/interface_provider.h"
208 #include "services/service_manager/public/cpp/service.h" 206 #include "services/service_manager/public/cpp/service.h"
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 } 920 }
923 921
924 bool GetDataSaverEnabledPref(const PrefService* prefs) { 922 bool GetDataSaverEnabledPref(const PrefService* prefs) {
925 // Enable data saver only when data saver pref is enabled and not part of 923 // Enable data saver only when data saver pref is enabled and not part of
926 // "Disabled" group of "SaveDataHeader" experiment. 924 // "Disabled" group of "SaveDataHeader" experiment.
927 return prefs->GetBoolean(prefs::kDataSaverEnabled) && 925 return prefs->GetBoolean(prefs::kDataSaverEnabled) &&
928 base::FieldTrialList::FindFullName("SaveDataHeader") 926 base::FieldTrialList::FindFullName("SaveDataHeader")
929 .compare("Disabled"); 927 .compare("Disabled");
930 } 928 }
931 929
932 // A BrowsingDataRemover::Observer that waits for |count|
933 // OnBrowsingDataRemoverDone() callbacks, translates them into
934 // one base::Closure, and then destroys itself.
935 class ClearSiteDataObserver : public content::BrowsingDataRemover::Observer {
936 public:
937 explicit ClearSiteDataObserver(content::BrowsingDataRemover* remover,
938 const base::Closure& callback,
939 int count)
940 : remover_(remover), callback_(callback), count_(count) {
941 remover_->AddObserver(this);
942 }
943
944 ~ClearSiteDataObserver() override { remover_->RemoveObserver(this); }
945
946 // BrowsingDataRemover::Observer.
947 void OnBrowsingDataRemoverDone() override {
948 DCHECK(count_);
949 if (--count_)
950 return;
951
952 callback_.Run();
953 delete this;
954 }
955
956 private:
957 content::BrowsingDataRemover* remover_;
958 base::Closure callback_;
959 int count_;
960 };
961
962 WebContents* GetWebContents(int render_process_id, int render_frame_id) { 930 WebContents* GetWebContents(int render_process_id, int render_frame_id) {
963 RenderFrameHost* rfh = 931 RenderFrameHost* rfh =
964 RenderFrameHost::FromID(render_process_id, render_frame_id); 932 RenderFrameHost::FromID(render_process_id, render_frame_id);
965 return WebContents::FromRenderFrameHost(rfh); 933 return WebContents::FromRenderFrameHost(rfh);
966 } 934 }
967 935
968 #if BUILDFLAG(ENABLE_EXTENSIONS) 936 #if BUILDFLAG(ENABLE_EXTENSIONS)
969 // Returns true if there is is an extension with the same origin as 937 // Returns true if there is is an extension with the same origin as
970 // |source_origin| in |opener_render_process_id| with 938 // |source_origin| in |opener_render_process_id| with
971 // APIPermission::kBackground. 939 // APIPermission::kBackground.
(...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after
2733 #else 2701 #else
2734 // Handler to rewrite chrome://newtab for InstantExtended. 2702 // Handler to rewrite chrome://newtab for InstantExtended.
2735 handler->AddHandlerPair(&search::HandleNewTabURLRewrite, 2703 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
2736 &search::HandleNewTabURLReverseRewrite); 2704 &search::HandleNewTabURLReverseRewrite);
2737 #endif 2705 #endif
2738 2706
2739 // chrome: & friends. 2707 // chrome: & friends.
2740 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse); 2708 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
2741 } 2709 }
2742 2710
2743 void ChromeContentBrowserClient::ClearSiteData(
2744 content::BrowserContext* browser_context,
2745 const url::Origin& origin,
2746 bool remove_cookies,
2747 bool remove_storage,
2748 bool remove_cache,
2749 const base::Closure& callback) {
2750 content::BrowsingDataRemover* remover =
2751 content::BrowserContext::GetBrowsingDataRemover(browser_context);
2752
2753 // ClearSiteDataObserver deletes itself when callbacks from both removal
2754 // tasks are received.
2755 ClearSiteDataObserver* observer =
2756 new ClearSiteDataObserver(remover, callback, 2 /* number of tasks */);
2757
2758 // Cookies and channel IDs are scoped to
2759 // a) eTLD+1 of |origin|'s host if |origin|'s host is a registrable domain
2760 // or a subdomain thereof
2761 // b) |origin|'s host exactly if it is an IP address or an internal hostname
2762 // (e.g. "localhost" or "fileserver").
2763 if (remove_cookies) {
2764 std::string domain = GetDomainAndRegistry(
2765 origin.host(),
2766 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
2767
2768 if (domain.empty())
2769 domain = origin.host(); // IP address or internal hostname.
2770
2771 std::unique_ptr<BrowsingDataFilterBuilder> domain_filter_builder(
2772 BrowsingDataFilterBuilder::Create(
2773 BrowsingDataFilterBuilder::WHITELIST));
2774 domain_filter_builder->AddRegisterableDomain(domain);
2775
2776 remover->RemoveWithFilterAndReply(
2777 base::Time(), base::Time::Max(),
2778 content::BrowsingDataRemover::DATA_TYPE_COOKIES |
2779 content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
2780 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA,
2781 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES,
2782 std::move(domain_filter_builder), observer);
2783 } else {
2784 // The first removal task is a no-op.
2785 observer->OnBrowsingDataRemoverDone();
2786 }
2787
2788 // Delete origin-scoped data.
2789 int remove_mask = 0;
2790 if (remove_storage)
2791 remove_mask |= content::BrowsingDataRemover::DATA_TYPE_DOM_STORAGE;
2792 if (remove_cache)
2793 remove_mask |= content::BrowsingDataRemover::DATA_TYPE_CACHE;
2794
2795 if (remove_mask) {
2796 std::unique_ptr<BrowsingDataFilterBuilder> origin_filter_builder(
2797 BrowsingDataFilterBuilder::Create(
2798 BrowsingDataFilterBuilder::WHITELIST));
2799 origin_filter_builder->AddOrigin(origin);
2800
2801 remover->RemoveWithFilterAndReply(
2802 base::Time(), base::Time::Max(), remove_mask,
2803 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES,
2804 std::move(origin_filter_builder), observer);
2805 } else {
2806 // The second removal task is a no-op.
2807 observer->OnBrowsingDataRemoverDone();
2808 }
2809 }
2810
2811 base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { 2711 base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2812 return DownloadPrefs::GetDefaultDownloadDirectory(); 2712 return DownloadPrefs::GetDefaultDownloadDirectory();
2813 } 2713 }
2814 2714
2815 std::string ChromeContentBrowserClient::GetDefaultDownloadName() { 2715 std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2816 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); 2716 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2817 } 2717 }
2818 2718
2819 base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() { 2719 base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
2820 base::FilePath user_data_dir; 2720 base::FilePath user_data_dir;
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
3582 RedirectNonUINonIOBrowserThreadsToTaskScheduler() { 3482 RedirectNonUINonIOBrowserThreadsToTaskScheduler() {
3583 return variations::GetVariationParamValue( 3483 return variations::GetVariationParamValue(
3584 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true"; 3484 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true";
3585 } 3485 }
3586 3486
3587 // static 3487 // static
3588 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( 3488 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
3589 const storage::QuotaSettings* settings) { 3489 const storage::QuotaSettings* settings) {
3590 g_default_quota_settings = settings; 3490 g_default_quota_settings = settings;
3591 } 3491 }
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.h ('k') | chrome/browser/chrome_content_browser_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698