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

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: Fix the compilation error Created 3 years, 7 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 #include "components/task_scheduler_util/common/variations_util.h" 155 #include "components/task_scheduler_util/common/variations_util.h"
156 #include "components/translate/core/common/translate_switches.h" 156 #include "components/translate/core/common/translate_switches.h"
157 #include "components/url_formatter/url_fixer.h" 157 #include "components/url_formatter/url_fixer.h"
158 #include "components/variations/variations_associated_data.h" 158 #include "components/variations/variations_associated_data.h"
159 #include "components/version_info/version_info.h" 159 #include "components/version_info/version_info.h"
160 #include "content/public/browser/browser_child_process_host.h" 160 #include "content/public/browser/browser_child_process_host.h"
161 #include "content/public/browser/browser_main_parts.h" 161 #include "content/public/browser/browser_main_parts.h"
162 #include "content/public/browser/browser_ppapi_host.h" 162 #include "content/public/browser/browser_ppapi_host.h"
163 #include "content/public/browser/browser_thread.h" 163 #include "content/public/browser/browser_thread.h"
164 #include "content/public/browser/browser_url_handler.h" 164 #include "content/public/browser/browser_url_handler.h"
165 #include "content/public/browser/browsing_data_filter_builder.h"
166 #include "content/public/browser/browsing_data_remover.h" 165 #include "content/public/browser/browsing_data_remover.h"
167 #include "content/public/browser/child_process_data.h" 166 #include "content/public/browser/child_process_data.h"
168 #include "content/public/browser/child_process_security_policy.h" 167 #include "content/public/browser/child_process_security_policy.h"
169 #include "content/public/browser/client_certificate_delegate.h" 168 #include "content/public/browser/client_certificate_delegate.h"
170 #include "content/public/browser/navigation_handle.h" 169 #include "content/public/browser/navigation_handle.h"
171 #include "content/public/browser/navigation_throttle.h" 170 #include "content/public/browser/navigation_throttle.h"
172 #include "content/public/browser/render_frame_host.h" 171 #include "content/public/browser/render_frame_host.h"
173 #include "content/public/browser/render_process_host.h" 172 #include "content/public/browser/render_process_host.h"
174 #include "content/public/browser/render_view_host.h" 173 #include "content/public/browser/render_view_host.h"
175 #include "content/public/browser/resource_context.h" 174 #include "content/public/browser/resource_context.h"
(...skipping 12 matching lines...) Expand all
188 #include "content/public/common/web_preferences.h" 187 #include "content/public/common/web_preferences.h"
189 #include "device/bluetooth/adapter_factory.h" 188 #include "device/bluetooth/adapter_factory.h"
190 #include "device/bluetooth/public/interfaces/adapter.mojom.h" 189 #include "device/bluetooth/public/interfaces/adapter.mojom.h"
191 #include "device/usb/public/interfaces/chooser_service.mojom.h" 190 #include "device/usb/public/interfaces/chooser_service.mojom.h"
192 #include "device/usb/public/interfaces/device_manager.mojom.h" 191 #include "device/usb/public/interfaces/device_manager.mojom.h"
193 #include "extensions/features/features.h" 192 #include "extensions/features/features.h"
194 #include "gpu/config/gpu_switches.h" 193 #include "gpu/config/gpu_switches.h"
195 #include "media/audio/audio_manager.h" 194 #include "media/audio/audio_manager.h"
196 #include "media/media_features.h" 195 #include "media/media_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 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 } 915 }
918 916
919 bool GetDataSaverEnabledPref(const PrefService* prefs) { 917 bool GetDataSaverEnabledPref(const PrefService* prefs) {
920 // Enable data saver only when data saver pref is enabled and not part of 918 // Enable data saver only when data saver pref is enabled and not part of
921 // "Disabled" group of "SaveDataHeader" experiment. 919 // "Disabled" group of "SaveDataHeader" experiment.
922 return prefs->GetBoolean(prefs::kDataSaverEnabled) && 920 return prefs->GetBoolean(prefs::kDataSaverEnabled) &&
923 base::FieldTrialList::FindFullName("SaveDataHeader") 921 base::FieldTrialList::FindFullName("SaveDataHeader")
924 .compare("Disabled"); 922 .compare("Disabled");
925 } 923 }
926 924
927 // A BrowsingDataRemover::Observer that waits for |count|
928 // OnBrowsingDataRemoverDone() callbacks, translates them into
929 // one base::Closure, and then destroys itself.
930 class ClearSiteDataObserver : public content::BrowsingDataRemover::Observer {
931 public:
932 explicit ClearSiteDataObserver(content::BrowsingDataRemover* remover,
933 const base::Closure& callback,
934 int count)
935 : remover_(remover), callback_(callback), count_(count) {
936 remover_->AddObserver(this);
937 }
938
939 ~ClearSiteDataObserver() override { remover_->RemoveObserver(this); }
940
941 // BrowsingDataRemover::Observer.
942 void OnBrowsingDataRemoverDone() override {
943 DCHECK(count_);
944 if (--count_)
945 return;
946
947 callback_.Run();
948 delete this;
949 }
950
951 private:
952 content::BrowsingDataRemover* remover_;
953 base::Closure callback_;
954 int count_;
955 };
956
957 WebContents* GetWebContents(int render_process_id, int render_frame_id) { 925 WebContents* GetWebContents(int render_process_id, int render_frame_id) {
958 RenderFrameHost* rfh = 926 RenderFrameHost* rfh =
959 RenderFrameHost::FromID(render_process_id, render_frame_id); 927 RenderFrameHost::FromID(render_process_id, render_frame_id);
960 return WebContents::FromRenderFrameHost(rfh); 928 return WebContents::FromRenderFrameHost(rfh);
961 } 929 }
962 930
963 #if BUILDFLAG(ENABLE_EXTENSIONS) 931 #if BUILDFLAG(ENABLE_EXTENSIONS)
964 // Returns true if there is is an extension with the same origin as 932 // Returns true if there is is an extension with the same origin as
965 // |source_origin| in |opener_render_process_id| with 933 // |source_origin| in |opener_render_process_id| with
966 // APIPermission::kBackground. 934 // APIPermission::kBackground.
(...skipping 1791 matching lines...) Expand 10 before | Expand all | Expand 10 after
2758 2726
2759 void ChromeContentBrowserClient::ClearCache(RenderFrameHost* rfh) { 2727 void ChromeContentBrowserClient::ClearCache(RenderFrameHost* rfh) {
2760 content::BrowsingDataRemover* remover = 2728 content::BrowsingDataRemover* remover =
2761 content::BrowserContext::GetBrowsingDataRemover( 2729 content::BrowserContext::GetBrowsingDataRemover(
2762 rfh->GetSiteInstance()->GetProcess()->GetBrowserContext()); 2730 rfh->GetSiteInstance()->GetProcess()->GetBrowserContext());
2763 remover->Remove(base::Time(), base::Time::Max(), 2731 remover->Remove(base::Time(), base::Time::Max(),
2764 content::BrowsingDataRemover::DATA_TYPE_CACHE, 2732 content::BrowsingDataRemover::DATA_TYPE_CACHE,
2765 content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB); 2733 content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB);
2766 } 2734 }
2767 2735
2768 void ChromeContentBrowserClient::ClearSiteData(
2769 content::BrowserContext* browser_context,
2770 const url::Origin& origin,
2771 bool remove_cookies,
2772 bool remove_storage,
2773 bool remove_cache,
2774 const base::Closure& callback) {
2775 content::BrowsingDataRemover* remover =
2776 content::BrowserContext::GetBrowsingDataRemover(browser_context);
2777
2778 // ClearSiteDataObserver deletes itself when callbacks from both removal
2779 // tasks are received.
2780 ClearSiteDataObserver* observer =
2781 new ClearSiteDataObserver(remover, callback, 2 /* number of tasks */);
2782
2783 // Cookies and channel IDs are scoped to
2784 // a) eTLD+1 of |origin|'s host if |origin|'s host is a registrable domain
2785 // or a subdomain thereof
2786 // b) |origin|'s host exactly if it is an IP address or an internal hostname
2787 // (e.g. "localhost" or "fileserver").
2788 if (remove_cookies) {
2789 std::string domain = GetDomainAndRegistry(
2790 origin.host(),
2791 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
2792
2793 if (domain.empty())
2794 domain = origin.host(); // IP address or internal hostname.
2795
2796 std::unique_ptr<BrowsingDataFilterBuilder> domain_filter_builder(
2797 BrowsingDataFilterBuilder::Create(
2798 BrowsingDataFilterBuilder::WHITELIST));
2799 domain_filter_builder->AddRegisterableDomain(domain);
2800
2801 remover->RemoveWithFilterAndReply(
2802 base::Time(), base::Time::Max(),
2803 content::BrowsingDataRemover::DATA_TYPE_COOKIES |
2804 content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
2805 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA,
2806 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES,
2807 std::move(domain_filter_builder), observer);
2808 } else {
2809 // The first removal task is a no-op.
2810 observer->OnBrowsingDataRemoverDone();
2811 }
2812
2813 // Delete origin-scoped data.
2814 int remove_mask = 0;
2815 if (remove_storage)
2816 remove_mask |= content::BrowsingDataRemover::DATA_TYPE_DOM_STORAGE;
2817 if (remove_cache)
2818 remove_mask |= content::BrowsingDataRemover::DATA_TYPE_CACHE;
2819
2820 if (remove_mask) {
2821 std::unique_ptr<BrowsingDataFilterBuilder> origin_filter_builder(
2822 BrowsingDataFilterBuilder::Create(
2823 BrowsingDataFilterBuilder::WHITELIST));
2824 origin_filter_builder->AddOrigin(origin);
2825
2826 remover->RemoveWithFilterAndReply(
2827 base::Time(), base::Time::Max(), remove_mask,
2828 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES,
2829 std::move(origin_filter_builder), observer);
2830 } else {
2831 // The second removal task is a no-op.
2832 observer->OnBrowsingDataRemoverDone();
2833 }
2834 }
2835
2836 base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { 2736 base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
2837 return DownloadPrefs::GetDefaultDownloadDirectory(); 2737 return DownloadPrefs::GetDefaultDownloadDirectory();
2838 } 2738 }
2839 2739
2840 std::string ChromeContentBrowserClient::GetDefaultDownloadName() { 2740 std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2841 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); 2741 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2842 } 2742 }
2843 2743
2844 base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() { 2744 base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() {
2845 base::FilePath user_data_dir; 2745 base::FilePath user_data_dir;
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
3611 RedirectNonUINonIOBrowserThreadsToTaskScheduler() { 3511 RedirectNonUINonIOBrowserThreadsToTaskScheduler() {
3612 return variations::GetVariationParamValue( 3512 return variations::GetVariationParamValue(
3613 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true"; 3513 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true";
3614 } 3514 }
3615 3515
3616 // static 3516 // static
3617 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( 3517 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
3618 const storage::QuotaSettings* settings) { 3518 const storage::QuotaSettings* settings) {
3619 g_default_quota_settings = settings; 3519 g_default_quota_settings = settings;
3620 } 3520 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698