| 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/content_settings/tab_specific_content_settings.h" | 5 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "components/content_settings/core/browser/content_settings_details.h" | 31 #include "components/content_settings/core/browser/content_settings_details.h" |
| 32 #include "components/content_settings/core/browser/content_settings_info.h" | 32 #include "components/content_settings/core/browser/content_settings_info.h" |
| 33 #include "components/content_settings/core/browser/content_settings_registry.h" | 33 #include "components/content_settings/core/browser/content_settings_registry.h" |
| 34 #include "components/content_settings/core/browser/content_settings_utils.h" | 34 #include "components/content_settings/core/browser/content_settings_utils.h" |
| 35 #include "components/content_settings/core/browser/host_content_settings_map.h" | 35 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 36 #include "components/prefs/pref_service.h" | 36 #include "components/prefs/pref_service.h" |
| 37 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/navigation_controller.h" | 38 #include "content/public/browser/navigation_controller.h" |
| 39 #include "content/public/browser/navigation_details.h" | 39 #include "content/public/browser/navigation_details.h" |
| 40 #include "content/public/browser/navigation_entry.h" | 40 #include "content/public/browser/navigation_entry.h" |
| 41 #include "content/public/browser/navigation_handle.h" |
| 41 #include "content/public/browser/notification_registrar.h" | 42 #include "content/public/browser/notification_registrar.h" |
| 42 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
| 43 #include "content/public/browser/render_frame_host.h" | 44 #include "content/public/browser/render_frame_host.h" |
| 44 #include "content/public/browser/render_view_host.h" | 45 #include "content/public/browser/render_view_host.h" |
| 45 #include "content/public/browser/web_contents.h" | 46 #include "content/public/browser/web_contents.h" |
| 46 #include "content/public/browser/web_contents_delegate.h" | 47 #include "content/public/browser/web_contents_delegate.h" |
| 47 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 48 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 48 #include "net/cookies/canonical_cookie.h" | 49 #include "net/cookies/canonical_cookie.h" |
| 49 #include "storage/common/fileapi/file_system_types.h" | 50 #include "storage/common/fileapi/file_system_types.h" |
| 50 | 51 |
| 51 using content::BrowserThread; | 52 using content::BrowserThread; |
| 52 using content::NavigationController; | 53 using content::NavigationController; |
| 53 using content::NavigationEntry; | 54 using content::NavigationEntry; |
| 54 using content::WebContents; | 55 using content::WebContents; |
| 55 | 56 |
| 56 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings); | |
| 57 | |
| 58 namespace { | 57 namespace { |
| 59 | 58 |
| 60 ContentSettingsUsagesState::CommittedDetails GetCommittedDetails( | 59 static TabSpecificContentSettings* GetForWCGetter( |
| 61 const content::LoadCommittedDetails& details) { | 60 const base::Callback<content::WebContents*(void)>& wc_getter) { |
| 62 ContentSettingsUsagesState::CommittedDetails committed_details; | 61 WebContents* web_contents = wc_getter.Run(); |
| 63 committed_details.current_url_valid = !!details.entry; | 62 if (!web_contents) |
| 64 if (details.entry) | 63 return nullptr; |
| 65 committed_details.current_url = details.entry->GetURL(); | 64 |
| 66 committed_details.previous_url = details.previous_url; | 65 return TabSpecificContentSettings::FromWebContents(web_contents); |
| 67 return committed_details; | |
| 68 } | 66 } |
| 69 | 67 |
| 70 } // namespace | 68 } // namespace |
| 71 | 69 |
| 70 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings); |
| 71 |
| 72 TabSpecificContentSettings::SiteDataObserver::SiteDataObserver( | 72 TabSpecificContentSettings::SiteDataObserver::SiteDataObserver( |
| 73 TabSpecificContentSettings* tab_specific_content_settings) | 73 TabSpecificContentSettings* tab_specific_content_settings) |
| 74 : tab_specific_content_settings_(tab_specific_content_settings) { | 74 : tab_specific_content_settings_(tab_specific_content_settings) { |
| 75 tab_specific_content_settings_->AddSiteDataObserver(this); | 75 tab_specific_content_settings_->AddSiteDataObserver(this); |
| 76 } | 76 } |
| 77 | 77 |
| 78 TabSpecificContentSettings::SiteDataObserver::~SiteDataObserver() { | 78 TabSpecificContentSettings::SiteDataObserver::~SiteDataObserver() { |
| 79 if (tab_specific_content_settings_) | 79 if (tab_specific_content_settings_) |
| 80 tab_specific_content_settings_->RemoveSiteDataObserver(this); | 80 tab_specific_content_settings_->RemoveSiteDataObserver(this); |
| 81 } | 81 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 content::RenderFrameHost* frame = content::RenderFrameHost::FromID( | 126 content::RenderFrameHost* frame = content::RenderFrameHost::FromID( |
| 127 render_process_id, render_frame_id); | 127 render_process_id, render_frame_id); |
| 128 WebContents* web_contents = WebContents::FromRenderFrameHost(frame); | 128 WebContents* web_contents = WebContents::FromRenderFrameHost(frame); |
| 129 if (!web_contents) | 129 if (!web_contents) |
| 130 return nullptr; | 130 return nullptr; |
| 131 | 131 |
| 132 return TabSpecificContentSettings::FromWebContents(web_contents); | 132 return TabSpecificContentSettings::FromWebContents(web_contents); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // static | 135 // static |
| 136 void TabSpecificContentSettings::CookiesRead(int render_process_id, | 136 void TabSpecificContentSettings::CookiesRead( |
| 137 int render_frame_id, | 137 const base::Callback<content::WebContents*(void)>& wc_getter, |
| 138 const GURL& url, | 138 const GURL& url, |
| 139 const GURL& frame_url, | 139 const GURL& frame_url, |
| 140 const net::CookieList& cookie_list, | 140 const net::CookieList& cookie_list, |
| 141 bool blocked_by_policy) { | 141 bool blocked_by_policy) { |
| 142 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 142 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 143 TabSpecificContentSettings* settings = | 143 TabSpecificContentSettings* settings = GetForWCGetter(wc_getter); |
| 144 GetForFrame(render_process_id, render_frame_id); | |
| 145 if (settings) { | 144 if (settings) { |
| 146 settings->OnCookiesRead(url, frame_url, cookie_list, | 145 settings->OnCookiesRead(url, frame_url, cookie_list, |
| 147 blocked_by_policy); | 146 blocked_by_policy); |
| 148 } | 147 } |
| 149 } | 148 } |
| 150 | 149 |
| 151 // static | 150 // static |
| 152 void TabSpecificContentSettings::CookieChanged( | 151 void TabSpecificContentSettings::CookieChanged( |
| 153 int render_process_id, | 152 const base::Callback<WebContents*(void)>& wc_getter, |
| 154 int render_frame_id, | |
| 155 const GURL& url, | 153 const GURL& url, |
| 156 const GURL& frame_url, | 154 const GURL& frame_url, |
| 157 const std::string& cookie_line, | 155 const std::string& cookie_line, |
| 158 const net::CookieOptions& options, | 156 const net::CookieOptions& options, |
| 159 bool blocked_by_policy) { | 157 bool blocked_by_policy) { |
| 160 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 158 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 161 TabSpecificContentSettings* settings = | 159 TabSpecificContentSettings* settings = GetForWCGetter(wc_getter); |
| 162 GetForFrame(render_process_id, render_frame_id); | |
| 163 if (settings) | 160 if (settings) |
| 164 settings->OnCookieChanged(url, frame_url, cookie_line, options, | 161 settings->OnCookieChanged(url, frame_url, cookie_line, options, |
| 165 blocked_by_policy); | 162 blocked_by_policy); |
| 166 } | 163 } |
| 167 | 164 |
| 168 // static | 165 // static |
| 169 void TabSpecificContentSettings::WebDatabaseAccessed( | 166 void TabSpecificContentSettings::WebDatabaseAccessed( |
| 170 int render_process_id, | 167 int render_process_id, |
| 171 int render_frame_id, | 168 int render_frame_id, |
| 172 const GURL& url, | 169 const GURL& url, |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 bool handled = true; | 768 bool handled = true; |
| 772 IPC_BEGIN_MESSAGE_MAP(TabSpecificContentSettings, message) | 769 IPC_BEGIN_MESSAGE_MAP(TabSpecificContentSettings, message) |
| 773 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ContentBlocked, | 770 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ContentBlocked, |
| 774 OnContentBlockedWithDetail) | 771 OnContentBlockedWithDetail) |
| 775 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidUseKeygen, OnDidUseKeygen) | 772 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidUseKeygen, OnDidUseKeygen) |
| 776 IPC_MESSAGE_UNHANDLED(handled = false) | 773 IPC_MESSAGE_UNHANDLED(handled = false) |
| 777 IPC_END_MESSAGE_MAP() | 774 IPC_END_MESSAGE_MAP() |
| 778 return handled; | 775 return handled; |
| 779 } | 776 } |
| 780 | 777 |
| 781 void TabSpecificContentSettings::DidNavigateMainFrame( | 778 void TabSpecificContentSettings::DidStartNavigation( |
| 782 const content::LoadCommittedDetails& details, | 779 content::NavigationHandle* navigation_handle) { |
| 783 const content::FrameNavigateParams& params) { | 780 if (!navigation_handle->IsInMainFrame()) |
| 784 if (!details.is_in_page) { | 781 return; |
| 785 // Clear "blocked" flags. | |
| 786 ClearBlockedContentSettingsExceptForCookies(); | |
| 787 blocked_plugin_names_.clear(); | |
| 788 GeolocationDidNavigate(details); | |
| 789 MidiDidNavigate(details); | |
| 790 | 782 |
| 791 if (web_contents()->GetVisibleURL().SchemeIsHTTPOrHTTPS()) { | 783 const content::NavigationController& controller = |
| 792 content_settings::RecordPluginsAction( | 784 web_contents()->GetController(); |
| 793 content_settings::PLUGINS_ACTION_TOTAL_NAVIGATIONS); | 785 content::NavigationEntry* last_committed_entry = |
| 794 } | 786 controller.GetLastCommittedEntry(); |
| 795 } | 787 if (last_committed_entry) |
| 796 } | 788 previous_url_ = last_committed_entry->GetURL(); |
| 797 | |
| 798 void TabSpecificContentSettings::DidStartProvisionalLoadForFrame( | |
| 799 content::RenderFrameHost* render_frame_host, | |
| 800 const GURL& validated_url, | |
| 801 bool is_error_page, | |
| 802 bool is_iframe_srcdoc) { | |
| 803 if (render_frame_host->GetParent()) | |
| 804 return; | |
| 805 | 789 |
| 806 // If we're displaying a network error page do not reset the content | 790 // If we're displaying a network error page do not reset the content |
| 807 // settings delegate's cookies so the user has a chance to modify cookie | 791 // settings delegate's cookies so the user has a chance to modify cookie |
| 808 // settings. | 792 // settings. |
| 809 if (!is_error_page) | 793 if (!navigation_handle->IsErrorPage()) |
| 810 ClearCookieSpecificContentSettings(); | 794 ClearCookieSpecificContentSettings(); |
| 811 ClearGeolocationContentSettings(); | 795 ClearGeolocationContentSettings(); |
| 812 ClearMidiContentSettings(); | 796 ClearMidiContentSettings(); |
| 813 ClearPendingProtocolHandler(); | 797 ClearPendingProtocolHandler(); |
| 814 } | 798 } |
| 815 | 799 |
| 800 void TabSpecificContentSettings::DidFinishNavigation( |
| 801 content::NavigationHandle* navigation_handle) { |
| 802 if (!navigation_handle->IsInMainFrame() || |
| 803 !navigation_handle->HasCommitted() || |
| 804 navigation_handle->IsSamePage()) { |
| 805 return; |
| 806 } |
| 807 |
| 808 // Clear "blocked" flags. |
| 809 ClearBlockedContentSettingsExceptForCookies(); |
| 810 blocked_plugin_names_.clear(); |
| 811 GeolocationDidNavigate(navigation_handle); |
| 812 MidiDidNavigate(navigation_handle); |
| 813 |
| 814 if (web_contents()->GetVisibleURL().SchemeIsHTTPOrHTTPS()) { |
| 815 content_settings::RecordPluginsAction( |
| 816 content_settings::PLUGINS_ACTION_TOTAL_NAVIGATIONS); |
| 817 } |
| 818 } |
| 819 |
| 816 void TabSpecificContentSettings::AppCacheAccessed(const GURL& manifest_url, | 820 void TabSpecificContentSettings::AppCacheAccessed(const GURL& manifest_url, |
| 817 bool blocked_by_policy) { | 821 bool blocked_by_policy) { |
| 818 if (blocked_by_policy) { | 822 if (blocked_by_policy) { |
| 819 blocked_local_shared_objects_.appcaches()->AddAppCache(manifest_url); | 823 blocked_local_shared_objects_.appcaches()->AddAppCache(manifest_url); |
| 820 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES); | 824 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES); |
| 821 } else { | 825 } else { |
| 822 allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url); | 826 allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url); |
| 823 OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES); | 827 OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES); |
| 824 } | 828 } |
| 825 } | 829 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 840 | 844 |
| 841 void TabSpecificContentSettings::ClearGeolocationContentSettings() { | 845 void TabSpecificContentSettings::ClearGeolocationContentSettings() { |
| 842 geolocation_usages_state_.ClearStateMap(); | 846 geolocation_usages_state_.ClearStateMap(); |
| 843 } | 847 } |
| 844 | 848 |
| 845 void TabSpecificContentSettings::ClearMidiContentSettings() { | 849 void TabSpecificContentSettings::ClearMidiContentSettings() { |
| 846 midi_usages_state_.ClearStateMap(); | 850 midi_usages_state_.ClearStateMap(); |
| 847 } | 851 } |
| 848 | 852 |
| 849 void TabSpecificContentSettings::GeolocationDidNavigate( | 853 void TabSpecificContentSettings::GeolocationDidNavigate( |
| 850 const content::LoadCommittedDetails& details) { | 854 content::NavigationHandle* navigation_handle) { |
| 851 geolocation_usages_state_.DidNavigate(GetCommittedDetails(details)); | 855 ContentSettingsUsagesState::CommittedDetails committed_details; |
| 856 committed_details.current_url = navigation_handle->GetURL(); |
| 857 committed_details.previous_url = previous_url_; |
| 858 |
| 859 geolocation_usages_state_.DidNavigate(committed_details); |
| 852 } | 860 } |
| 853 | 861 |
| 854 void TabSpecificContentSettings::MidiDidNavigate( | 862 void TabSpecificContentSettings::MidiDidNavigate( |
| 855 const content::LoadCommittedDetails& details) { | 863 content::NavigationHandle* navigation_handle) { |
| 856 midi_usages_state_.DidNavigate(GetCommittedDetails(details)); | 864 ContentSettingsUsagesState::CommittedDetails committed_details; |
| 865 committed_details.current_url = navigation_handle->GetURL(); |
| 866 committed_details.previous_url = previous_url_; |
| 867 midi_usages_state_.DidNavigate(committed_details); |
| 857 } | 868 } |
| 858 | 869 |
| 859 void TabSpecificContentSettings::BlockAllContentForTesting() { | 870 void TabSpecificContentSettings::BlockAllContentForTesting() { |
| 860 content_settings::ContentSettingsRegistry* registry = | 871 content_settings::ContentSettingsRegistry* registry = |
| 861 content_settings::ContentSettingsRegistry::GetInstance(); | 872 content_settings::ContentSettingsRegistry::GetInstance(); |
| 862 for (const content_settings::ContentSettingsInfo* info : *registry) { | 873 for (const content_settings::ContentSettingsInfo* info : *registry) { |
| 863 ContentSettingsType type = info->website_settings_info()->type(); | 874 ContentSettingsType type = info->website_settings_info()->type(); |
| 864 if (type != CONTENT_SETTINGS_TYPE_GEOLOCATION && | 875 if (type != CONTENT_SETTINGS_TYPE_GEOLOCATION && |
| 865 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | 876 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && |
| 866 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | 877 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
| 867 OnContentBlocked(type); | 878 OnContentBlocked(type); |
| 868 } | 879 } |
| 869 } | 880 } |
| 870 | 881 |
| 871 // Geolocation and media must be blocked separately, as the generic | 882 // Geolocation and media must be blocked separately, as the generic |
| 872 // TabSpecificContentSettings::OnContentBlocked does not apply to them. | 883 // TabSpecificContentSettings::OnContentBlocked does not apply to them. |
| 873 OnGeolocationPermissionSet(web_contents()->GetLastCommittedURL(), false); | 884 OnGeolocationPermissionSet(web_contents()->GetLastCommittedURL(), false); |
| 874 MicrophoneCameraStateFlags media_blocked = | 885 MicrophoneCameraStateFlags media_blocked = |
| 875 static_cast<MicrophoneCameraStateFlags>( | 886 static_cast<MicrophoneCameraStateFlags>( |
| 876 TabSpecificContentSettings::MICROPHONE_ACCESSED | | 887 TabSpecificContentSettings::MICROPHONE_ACCESSED | |
| 877 TabSpecificContentSettings::MICROPHONE_BLOCKED | | 888 TabSpecificContentSettings::MICROPHONE_BLOCKED | |
| 878 TabSpecificContentSettings::CAMERA_ACCESSED | | 889 TabSpecificContentSettings::CAMERA_ACCESSED | |
| 879 TabSpecificContentSettings::CAMERA_BLOCKED); | 890 TabSpecificContentSettings::CAMERA_BLOCKED); |
| 880 OnMediaStreamPermissionSet( | 891 OnMediaStreamPermissionSet( |
| 881 web_contents()->GetLastCommittedURL(), | 892 web_contents()->GetLastCommittedURL(), |
| 882 media_blocked, | 893 media_blocked, |
| 883 std::string(), std::string(), std::string(), std::string()); | 894 std::string(), std::string(), std::string(), std::string()); |
| 884 } | 895 } |
| OLD | NEW |