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