| 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/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 17 matching lines...) Expand all Loading... |
| 28 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/threading/sequenced_worker_pool.h" | 29 #include "base/threading/sequenced_worker_pool.h" |
| 30 #include "base/threading/thread_task_runner_handle.h" | 30 #include "base/threading/thread_task_runner_handle.h" |
| 31 #include "build/build_config.h" | 31 #include "build/build_config.h" |
| 32 #include "chrome/browser/after_startup_task_utils.h" | 32 #include "chrome/browser/after_startup_task_utils.h" |
| 33 #include "chrome/browser/apps/app_url_redirector.h" | 33 #include "chrome/browser/apps/app_url_redirector.h" |
| 34 #include "chrome/browser/browser_about_handler.h" | 34 #include "chrome/browser/browser_about_handler.h" |
| 35 #include "chrome/browser/browser_process.h" | 35 #include "chrome/browser/browser_process.h" |
| 36 #include "chrome/browser/browser_shutdown.h" | 36 #include "chrome/browser/browser_shutdown.h" |
| 37 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 37 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 38 #include "chrome/browser/browsing_data/browsing_data_remover.h" | |
| 39 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | |
| 40 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" | 38 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" |
| 41 #include "chrome/browser/budget_service/budget_service_impl.h" | 39 #include "chrome/browser/budget_service/budget_service_impl.h" |
| 42 #include "chrome/browser/chrome_content_browser_client_parts.h" | 40 #include "chrome/browser/chrome_content_browser_client_parts.h" |
| 43 #include "chrome/browser/chrome_quota_permission_context.h" | 41 #include "chrome/browser/chrome_quota_permission_context.h" |
| 44 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 42 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
| 45 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 43 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 46 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 44 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 47 #include "chrome/browser/defaults.h" | 45 #include "chrome/browser/defaults.h" |
| 48 #include "chrome/browser/download/download_prefs.h" | 46 #include "chrome/browser/download/download_prefs.h" |
| 49 #include "chrome/browser/font_family_cache.h" | 47 #include "chrome/browser/font_family_cache.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 #include "components/translate/core/common/translate_switches.h" | 152 #include "components/translate/core/common/translate_switches.h" |
| 155 #include "components/url_formatter/url_fixer.h" | 153 #include "components/url_formatter/url_fixer.h" |
| 156 #include "components/variations/variations_associated_data.h" | 154 #include "components/variations/variations_associated_data.h" |
| 157 #include "components/version_info/version_info.h" | 155 #include "components/version_info/version_info.h" |
| 158 #include "content/public/browser/browser_child_process_host.h" | 156 #include "content/public/browser/browser_child_process_host.h" |
| 159 #include "content/public/browser/browser_main_parts.h" | 157 #include "content/public/browser/browser_main_parts.h" |
| 160 #include "content/public/browser/browser_ppapi_host.h" | 158 #include "content/public/browser/browser_ppapi_host.h" |
| 161 #include "content/public/browser/browser_thread.h" | 159 #include "content/public/browser/browser_thread.h" |
| 162 #include "content/public/browser/browser_url_handler.h" | 160 #include "content/public/browser/browser_url_handler.h" |
| 163 #include "content/public/browser/browsing_data_filter_builder.h" | 161 #include "content/public/browser/browsing_data_filter_builder.h" |
| 162 #include "content/public/browser/browsing_data_remover.h" |
| 164 #include "content/public/browser/child_process_data.h" | 163 #include "content/public/browser/child_process_data.h" |
| 165 #include "content/public/browser/child_process_security_policy.h" | 164 #include "content/public/browser/child_process_security_policy.h" |
| 166 #include "content/public/browser/client_certificate_delegate.h" | 165 #include "content/public/browser/client_certificate_delegate.h" |
| 167 #include "content/public/browser/navigation_handle.h" | 166 #include "content/public/browser/navigation_handle.h" |
| 168 #include "content/public/browser/navigation_throttle.h" | 167 #include "content/public/browser/navigation_throttle.h" |
| 169 #include "content/public/browser/render_frame_host.h" | 168 #include "content/public/browser/render_frame_host.h" |
| 170 #include "content/public/browser/render_process_host.h" | 169 #include "content/public/browser/render_process_host.h" |
| 171 #include "content/public/browser/render_view_host.h" | 170 #include "content/public/browser/render_view_host.h" |
| 172 #include "content/public/browser/resource_context.h" | 171 #include "content/public/browser/resource_context.h" |
| 173 #include "content/public/browser/site_instance.h" | 172 #include "content/public/browser/site_instance.h" |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 // Enable data saver only when data saver pref is enabled and not part of | 925 // Enable data saver only when data saver pref is enabled and not part of |
| 927 // "Disabled" group of "SaveDataHeader" experiment. | 926 // "Disabled" group of "SaveDataHeader" experiment. |
| 928 return prefs->GetBoolean(prefs::kDataSaverEnabled) && | 927 return prefs->GetBoolean(prefs::kDataSaverEnabled) && |
| 929 base::FieldTrialList::FindFullName("SaveDataHeader") | 928 base::FieldTrialList::FindFullName("SaveDataHeader") |
| 930 .compare("Disabled"); | 929 .compare("Disabled"); |
| 931 } | 930 } |
| 932 | 931 |
| 933 // A BrowsingDataRemover::Observer that waits for |count| | 932 // A BrowsingDataRemover::Observer that waits for |count| |
| 934 // OnBrowsingDataRemoverDone() callbacks, translates them into | 933 // OnBrowsingDataRemoverDone() callbacks, translates them into |
| 935 // one base::Closure, and then destroys itself. | 934 // one base::Closure, and then destroys itself. |
| 936 class ClearSiteDataObserver : public BrowsingDataRemover::Observer { | 935 class ClearSiteDataObserver : public content::BrowsingDataRemover::Observer { |
| 937 public: | 936 public: |
| 938 explicit ClearSiteDataObserver(BrowsingDataRemover* remover, | 937 explicit ClearSiteDataObserver(content::BrowsingDataRemover* remover, |
| 939 const base::Closure& callback, | 938 const base::Closure& callback, |
| 940 int count) | 939 int count) |
| 941 : remover_(remover), callback_(callback), count_(count) { | 940 : remover_(remover), callback_(callback), count_(count) { |
| 942 remover_->AddObserver(this); | 941 remover_->AddObserver(this); |
| 943 } | 942 } |
| 944 | 943 |
| 945 ~ClearSiteDataObserver() override { remover_->RemoveObserver(this); } | 944 ~ClearSiteDataObserver() override { remover_->RemoveObserver(this); } |
| 946 | 945 |
| 947 // BrowsingDataRemover::Observer. | 946 // BrowsingDataRemover::Observer. |
| 948 void OnBrowsingDataRemoverDone() override { | 947 void OnBrowsingDataRemoverDone() override { |
| 949 DCHECK(count_); | 948 DCHECK(count_); |
| 950 if (--count_) | 949 if (--count_) |
| 951 return; | 950 return; |
| 952 | 951 |
| 953 callback_.Run(); | 952 callback_.Run(); |
| 954 delete this; | 953 delete this; |
| 955 } | 954 } |
| 956 | 955 |
| 957 private: | 956 private: |
| 958 BrowsingDataRemover* remover_; | 957 content::BrowsingDataRemover* remover_; |
| 959 base::Closure callback_; | 958 base::Closure callback_; |
| 960 int count_; | 959 int count_; |
| 961 }; | 960 }; |
| 962 | 961 |
| 963 WebContents* GetWebContents(int render_process_id, int render_frame_id) { | 962 WebContents* GetWebContents(int render_process_id, int render_frame_id) { |
| 964 RenderFrameHost* rfh = | 963 RenderFrameHost* rfh = |
| 965 RenderFrameHost::FromID(render_process_id, render_frame_id); | 964 RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 966 return WebContents::FromRenderFrameHost(rfh); | 965 return WebContents::FromRenderFrameHost(rfh); |
| 967 } | 966 } |
| 968 | 967 |
| (...skipping 1599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2568 | 2567 |
| 2569 content::SpeechRecognitionManagerDelegate* | 2568 content::SpeechRecognitionManagerDelegate* |
| 2570 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() { | 2569 ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() { |
| 2571 return new speech::ChromeSpeechRecognitionManagerDelegate(); | 2570 return new speech::ChromeSpeechRecognitionManagerDelegate(); |
| 2572 } | 2571 } |
| 2573 | 2572 |
| 2574 net::NetLog* ChromeContentBrowserClient::GetNetLog() { | 2573 net::NetLog* ChromeContentBrowserClient::GetNetLog() { |
| 2575 return g_browser_process->net_log(); | 2574 return g_browser_process->net_log(); |
| 2576 } | 2575 } |
| 2577 | 2576 |
| 2577 bool ChromeContentBrowserClient::MayDeleteHistory( |
| 2578 content::BrowserContext* browser_context) { |
| 2579 const Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2580 return profile->GetPrefs()->GetBoolean(prefs::kAllowDeletingBrowserHistory); |
| 2581 } |
| 2582 |
| 2578 void ChromeContentBrowserClient::OverrideWebkitPrefs( | 2583 void ChromeContentBrowserClient::OverrideWebkitPrefs( |
| 2579 RenderViewHost* rvh, WebPreferences* web_prefs) { | 2584 RenderViewHost* rvh, WebPreferences* web_prefs) { |
| 2580 Profile* profile = Profile::FromBrowserContext( | 2585 Profile* profile = Profile::FromBrowserContext( |
| 2581 rvh->GetProcess()->GetBrowserContext()); | 2586 rvh->GetProcess()->GetBrowserContext()); |
| 2582 PrefService* prefs = profile->GetPrefs(); | 2587 PrefService* prefs = profile->GetPrefs(); |
| 2583 | 2588 |
| 2584 // Fill font preferences. These are not registered on Android | 2589 // Fill font preferences. These are not registered on Android |
| 2585 // - http://crbug.com/308033, http://crbug.com/696364. | 2590 // - http://crbug.com/308033, http://crbug.com/696364. |
| 2586 #if !defined(OS_ANDROID) | 2591 #if !defined(OS_ANDROID) |
| 2587 FontFamilyCache::FillFontFamilyMap(profile, | 2592 FontFamilyCache::FillFontFamilyMap(profile, |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2753 // Handler to rewrite chrome://newtab for InstantExtended. | 2758 // Handler to rewrite chrome://newtab for InstantExtended. |
| 2754 handler->AddHandlerPair(&search::HandleNewTabURLRewrite, | 2759 handler->AddHandlerPair(&search::HandleNewTabURLRewrite, |
| 2755 &search::HandleNewTabURLReverseRewrite); | 2760 &search::HandleNewTabURLReverseRewrite); |
| 2756 #endif | 2761 #endif |
| 2757 | 2762 |
| 2758 // chrome: & friends. | 2763 // chrome: & friends. |
| 2759 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse); | 2764 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse); |
| 2760 } | 2765 } |
| 2761 | 2766 |
| 2762 void ChromeContentBrowserClient::ClearCache(RenderFrameHost* rfh) { | 2767 void ChromeContentBrowserClient::ClearCache(RenderFrameHost* rfh) { |
| 2763 Profile* profile = Profile::FromBrowserContext( | 2768 content::BrowsingDataRemover* remover = |
| 2764 rfh->GetSiteInstance()->GetProcess()->GetBrowserContext()); | 2769 content::BrowserContext::GetBrowsingDataRemover( |
| 2765 BrowsingDataRemover* remover = | 2770 rfh->GetSiteInstance()->GetProcess()->GetBrowserContext()); |
| 2766 BrowsingDataRemoverFactory::GetForBrowserContext(profile); | |
| 2767 remover->Remove(base::Time(), base::Time::Max(), | 2771 remover->Remove(base::Time(), base::Time::Max(), |
| 2768 BrowsingDataRemover::DATA_TYPE_CACHE, | 2772 content::BrowsingDataRemover::DATA_TYPE_CACHE, |
| 2769 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB); | 2773 content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB); |
| 2770 } | 2774 } |
| 2771 | 2775 |
| 2772 void ChromeContentBrowserClient::ClearSiteData( | 2776 void ChromeContentBrowserClient::ClearSiteData( |
| 2773 content::BrowserContext* browser_context, | 2777 content::BrowserContext* browser_context, |
| 2774 const url::Origin& origin, | 2778 const url::Origin& origin, |
| 2775 bool remove_cookies, | 2779 bool remove_cookies, |
| 2776 bool remove_storage, | 2780 bool remove_storage, |
| 2777 bool remove_cache, | 2781 bool remove_cache, |
| 2778 const base::Closure& callback) { | 2782 const base::Closure& callback) { |
| 2779 BrowsingDataRemover* remover = | 2783 content::BrowsingDataRemover* remover = |
| 2780 BrowsingDataRemoverFactory::GetForBrowserContext(browser_context); | 2784 content::BrowserContext::GetBrowsingDataRemover(browser_context); |
| 2781 | 2785 |
| 2782 // ClearSiteDataObserver deletes itself when callbacks from both removal | 2786 // ClearSiteDataObserver deletes itself when callbacks from both removal |
| 2783 // tasks are received. | 2787 // tasks are received. |
| 2784 ClearSiteDataObserver* observer = | 2788 ClearSiteDataObserver* observer = |
| 2785 new ClearSiteDataObserver(remover, callback, 2 /* number of tasks */); | 2789 new ClearSiteDataObserver(remover, callback, 2 /* number of tasks */); |
| 2786 | 2790 |
| 2787 // Cookies and channel IDs are scoped to | 2791 // Cookies and channel IDs are scoped to |
| 2788 // a) eTLD+1 of |origin|'s host if |origin|'s host is a registrable domain | 2792 // a) eTLD+1 of |origin|'s host if |origin|'s host is a registrable domain |
| 2789 // or a subdomain thereof | 2793 // or a subdomain thereof |
| 2790 // b) |origin|'s host exactly if it is an IP address or an internal hostname | 2794 // b) |origin|'s host exactly if it is an IP address or an internal hostname |
| 2791 // (e.g. "localhost" or "fileserver"). | 2795 // (e.g. "localhost" or "fileserver"). |
| 2792 if (remove_cookies) { | 2796 if (remove_cookies) { |
| 2793 std::string domain = GetDomainAndRegistry( | 2797 std::string domain = GetDomainAndRegistry( |
| 2794 origin.host(), | 2798 origin.host(), |
| 2795 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 2799 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 2796 | 2800 |
| 2797 if (domain.empty()) | 2801 if (domain.empty()) |
| 2798 domain = origin.host(); // IP address or internal hostname. | 2802 domain = origin.host(); // IP address or internal hostname. |
| 2799 | 2803 |
| 2800 std::unique_ptr<BrowsingDataFilterBuilder> domain_filter_builder( | 2804 std::unique_ptr<BrowsingDataFilterBuilder> domain_filter_builder( |
| 2801 BrowsingDataFilterBuilder::Create( | 2805 BrowsingDataFilterBuilder::Create( |
| 2802 BrowsingDataFilterBuilder::WHITELIST)); | 2806 BrowsingDataFilterBuilder::WHITELIST)); |
| 2803 domain_filter_builder->AddRegisterableDomain(domain); | 2807 domain_filter_builder->AddRegisterableDomain(domain); |
| 2804 | 2808 |
| 2805 remover->RemoveWithFilterAndReply( | 2809 remover->RemoveWithFilterAndReply( |
| 2806 base::Time(), base::Time::Max(), | 2810 base::Time(), base::Time::Max(), |
| 2807 BrowsingDataRemover::DATA_TYPE_COOKIES | | 2811 content::BrowsingDataRemover::DATA_TYPE_COOKIES | |
| 2808 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS | | 2812 content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS | |
| 2809 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA, | 2813 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA, |
| 2810 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES, | 2814 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES, |
| 2811 std::move(domain_filter_builder), observer); | 2815 std::move(domain_filter_builder), observer); |
| 2812 } else { | 2816 } else { |
| 2813 // The first removal task is a no-op. | 2817 // The first removal task is a no-op. |
| 2814 observer->OnBrowsingDataRemoverDone(); | 2818 observer->OnBrowsingDataRemoverDone(); |
| 2815 } | 2819 } |
| 2816 | 2820 |
| 2817 // Delete origin-scoped data. | 2821 // Delete origin-scoped data. |
| 2818 int remove_mask = 0; | 2822 int remove_mask = 0; |
| 2819 if (remove_storage) | 2823 if (remove_storage) |
| 2820 remove_mask |= BrowsingDataRemover::DATA_TYPE_DOM_STORAGE; | 2824 remove_mask |= content::BrowsingDataRemover::DATA_TYPE_DOM_STORAGE; |
| 2821 if (remove_cache) | 2825 if (remove_cache) |
| 2822 remove_mask |= BrowsingDataRemover::DATA_TYPE_CACHE; | 2826 remove_mask |= content::BrowsingDataRemover::DATA_TYPE_CACHE; |
| 2823 | 2827 |
| 2824 if (remove_mask) { | 2828 if (remove_mask) { |
| 2825 std::unique_ptr<BrowsingDataFilterBuilder> origin_filter_builder( | 2829 std::unique_ptr<BrowsingDataFilterBuilder> origin_filter_builder( |
| 2826 BrowsingDataFilterBuilder::Create( | 2830 BrowsingDataFilterBuilder::Create( |
| 2827 BrowsingDataFilterBuilder::WHITELIST)); | 2831 BrowsingDataFilterBuilder::WHITELIST)); |
| 2828 origin_filter_builder->AddOrigin(origin); | 2832 origin_filter_builder->AddOrigin(origin); |
| 2829 | 2833 |
| 2830 remover->RemoveWithFilterAndReply( | 2834 remover->RemoveWithFilterAndReply( |
| 2831 base::Time(), base::Time::Max(), remove_mask, | 2835 base::Time(), base::Time::Max(), remove_mask, |
| 2832 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES, | 2836 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES, |
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3619 RedirectNonUINonIOBrowserThreadsToTaskScheduler() { | 3623 RedirectNonUINonIOBrowserThreadsToTaskScheduler() { |
| 3620 return variations::GetVariationParamValue( | 3624 return variations::GetVariationParamValue( |
| 3621 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true"; | 3625 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true"; |
| 3622 } | 3626 } |
| 3623 | 3627 |
| 3624 // static | 3628 // static |
| 3625 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( | 3629 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( |
| 3626 const storage::QuotaSettings* settings) { | 3630 const storage::QuotaSettings* settings) { |
| 3627 g_default_quota_settings = settings; | 3631 g_default_quota_settings = settings; |
| 3628 } | 3632 } |
| OLD | NEW |