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

Side by Side Diff: chrome/browser/content_settings/tab_specific_content_settings.cc

Issue 2543613002: Revert "Don't update TabSpecificContentSettings on same-page navigation" (Closed)
Patch Set: Created 4 years 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/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 19 matching lines...) Expand all
30 #include "components/content_settings/core/browser/content_settings_details.h" 30 #include "components/content_settings/core/browser/content_settings_details.h"
31 #include "components/content_settings/core/browser/content_settings_info.h" 31 #include "components/content_settings/core/browser/content_settings_info.h"
32 #include "components/content_settings/core/browser/content_settings_registry.h" 32 #include "components/content_settings/core/browser/content_settings_registry.h"
33 #include "components/content_settings/core/browser/content_settings_utils.h" 33 #include "components/content_settings/core/browser/content_settings_utils.h"
34 #include "components/content_settings/core/browser/host_content_settings_map.h" 34 #include "components/content_settings/core/browser/host_content_settings_map.h"
35 #include "components/prefs/pref_service.h" 35 #include "components/prefs/pref_service.h"
36 #include "content/public/browser/browser_thread.h" 36 #include "content/public/browser/browser_thread.h"
37 #include "content/public/browser/navigation_controller.h" 37 #include "content/public/browser/navigation_controller.h"
38 #include "content/public/browser/navigation_details.h" 38 #include "content/public/browser/navigation_details.h"
39 #include "content/public/browser/navigation_entry.h" 39 #include "content/public/browser/navigation_entry.h"
40 #include "content/public/browser/navigation_handle.h"
41 #include "content/public/browser/notification_registrar.h" 40 #include "content/public/browser/notification_registrar.h"
42 #include "content/public/browser/notification_service.h" 41 #include "content/public/browser/notification_service.h"
43 #include "content/public/browser/render_frame_host.h" 42 #include "content/public/browser/render_frame_host.h"
44 #include "content/public/browser/render_view_host.h" 43 #include "content/public/browser/render_view_host.h"
45 #include "content/public/browser/web_contents.h" 44 #include "content/public/browser/web_contents.h"
46 #include "content/public/browser/web_contents_delegate.h" 45 #include "content/public/browser/web_contents_delegate.h"
47 #include "content/public/common/content_constants.h" 46 #include "content/public/common/content_constants.h"
48 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 47 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
49 #include "net/cookies/canonical_cookie.h" 48 #include "net/cookies/canonical_cookie.h"
50 #include "storage/common/fileapi/file_system_types.h" 49 #include "storage/common/fileapi/file_system_types.h"
51 50
52 using content::BrowserThread; 51 using content::BrowserThread;
53 using content::NavigationController; 52 using content::NavigationController;
54 using content::NavigationEntry; 53 using content::NavigationEntry;
55 using content::WebContents; 54 using content::WebContents;
56 55
56 DEFINE_WEB_CONTENTS_USER_DATA_KEY(TabSpecificContentSettings);
57
57 namespace { 58 namespace {
58 59
59 static TabSpecificContentSettings* GetForWCGetter( 60 ContentSettingsUsagesState::CommittedDetails GetCommittedDetails(
60 const base::Callback<content::WebContents*(void)>& wc_getter) { 61 const content::LoadCommittedDetails& details) {
61 WebContents* web_contents = wc_getter.Run(); 62 ContentSettingsUsagesState::CommittedDetails committed_details;
62 if (!web_contents) 63 committed_details.current_url_valid = !!details.entry;
63 return nullptr; 64 if (details.entry)
64 65 committed_details.current_url = details.entry->GetURL();
65 return TabSpecificContentSettings::FromWebContents(web_contents); 66 committed_details.previous_url = details.previous_url;
67 return committed_details;
66 } 68 }
67 69
68 } // namespace 70 } // namespace
69 71
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
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( 136 void TabSpecificContentSettings::CookiesRead(int render_process_id,
137 const base::Callback<content::WebContents*(void)>& wc_getter, 137 int render_frame_id,
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 = GetForWCGetter(wc_getter); 143 TabSpecificContentSettings* settings =
144 GetForFrame(render_process_id, render_frame_id);
144 if (settings) { 145 if (settings) {
145 settings->OnCookiesRead(url, frame_url, cookie_list, 146 settings->OnCookiesRead(url, frame_url, cookie_list,
146 blocked_by_policy); 147 blocked_by_policy);
147 } 148 }
148 } 149 }
149 150
150 // static 151 // static
151 void TabSpecificContentSettings::CookieChanged( 152 void TabSpecificContentSettings::CookieChanged(
152 const base::Callback<WebContents*(void)>& wc_getter, 153 int render_process_id,
154 int render_frame_id,
153 const GURL& url, 155 const GURL& url,
154 const GURL& frame_url, 156 const GURL& frame_url,
155 const std::string& cookie_line, 157 const std::string& cookie_line,
156 const net::CookieOptions& options, 158 const net::CookieOptions& options,
157 bool blocked_by_policy) { 159 bool blocked_by_policy) {
158 DCHECK_CURRENTLY_ON(BrowserThread::UI); 160 DCHECK_CURRENTLY_ON(BrowserThread::UI);
159 TabSpecificContentSettings* settings = GetForWCGetter(wc_getter); 161 TabSpecificContentSettings* settings =
162 GetForFrame(render_process_id, render_frame_id);
160 if (settings) 163 if (settings)
161 settings->OnCookieChanged(url, frame_url, cookie_line, options, 164 settings->OnCookieChanged(url, frame_url, cookie_line, options,
162 blocked_by_policy); 165 blocked_by_policy);
163 } 166 }
164 167
165 // static 168 // static
166 void TabSpecificContentSettings::WebDatabaseAccessed( 169 void TabSpecificContentSettings::WebDatabaseAccessed(
167 int render_process_id, 170 int render_process_id,
168 int render_frame_id, 171 int render_frame_id,
169 const GURL& url, 172 const GURL& url,
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 bool handled = true; 794 bool handled = true;
792 IPC_BEGIN_MESSAGE_MAP(TabSpecificContentSettings, message) 795 IPC_BEGIN_MESSAGE_MAP(TabSpecificContentSettings, message)
793 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ContentBlocked, 796 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ContentBlocked,
794 OnContentBlockedWithDetail) 797 OnContentBlockedWithDetail)
795 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidUseKeygen, OnDidUseKeygen) 798 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidUseKeygen, OnDidUseKeygen)
796 IPC_MESSAGE_UNHANDLED(handled = false) 799 IPC_MESSAGE_UNHANDLED(handled = false)
797 IPC_END_MESSAGE_MAP() 800 IPC_END_MESSAGE_MAP()
798 return handled; 801 return handled;
799 } 802 }
800 803
801 void TabSpecificContentSettings::DidStartNavigation( 804 void TabSpecificContentSettings::DidNavigateMainFrame(
802 content::NavigationHandle* navigation_handle) { 805 const content::LoadCommittedDetails& details,
803 if (!navigation_handle->IsInMainFrame() || navigation_handle->IsSamePage()) 806 const content::FrameNavigateParams& params) {
807 if (!details.is_in_page) {
808 // Clear "blocked" flags.
809 ClearContentSettingsExceptForNavigationRelatedSettings();
810 blocked_plugin_names_.clear();
811 GeolocationDidNavigate(details);
812 MidiDidNavigate(details);
813
814 if (web_contents()->GetVisibleURL().SchemeIsHTTPOrHTTPS()) {
815 content_settings::RecordPluginsAction(
816 content_settings::PLUGINS_ACTION_TOTAL_NAVIGATIONS);
817 }
818 }
819 }
820
821 void TabSpecificContentSettings::DidStartProvisionalLoadForFrame(
822 content::RenderFrameHost* render_frame_host,
823 const GURL& validated_url,
824 bool is_error_page,
825 bool is_iframe_srcdoc) {
826 if (render_frame_host->GetParent())
804 return; 827 return;
805 828
806 const content::NavigationController& controller =
807 web_contents()->GetController();
808 content::NavigationEntry* last_committed_entry =
809 controller.GetLastCommittedEntry();
810 if (last_committed_entry)
811 previous_url_ = last_committed_entry->GetURL();
812
813 // If we're displaying a network error page do not reset the content 829 // If we're displaying a network error page do not reset the content
814 // settings delegate's cookies so the user has a chance to modify cookie 830 // settings delegate's cookies so the user has a chance to modify cookie
815 // settings. 831 // settings.
816 if (!navigation_handle->IsErrorPage()) 832 if (!is_error_page)
817 ClearNavigationRelatedContentSettings(); 833 ClearNavigationRelatedContentSettings();
818 ClearGeolocationContentSettings(); 834 ClearGeolocationContentSettings();
819 ClearMidiContentSettings(); 835 ClearMidiContentSettings();
820 ClearPendingProtocolHandler(); 836 ClearPendingProtocolHandler();
821 } 837 }
822 838
823 void TabSpecificContentSettings::DidFinishNavigation(
824 content::NavigationHandle* navigation_handle) {
825 if (!navigation_handle->IsInMainFrame() ||
826 !navigation_handle->HasCommitted() ||
827 navigation_handle->IsSamePage()) {
828 return;
829 }
830
831 // Clear "blocked" flags.
832 ClearContentSettingsExceptForNavigationRelatedSettings();
833 blocked_plugin_names_.clear();
834 GeolocationDidNavigate(navigation_handle);
835 MidiDidNavigate(navigation_handle);
836
837 if (web_contents()->GetVisibleURL().SchemeIsHTTPOrHTTPS()) {
838 content_settings::RecordPluginsAction(
839 content_settings::PLUGINS_ACTION_TOTAL_NAVIGATIONS);
840 }
841 }
842
843 void TabSpecificContentSettings::AppCacheAccessed(const GURL& manifest_url, 839 void TabSpecificContentSettings::AppCacheAccessed(const GURL& manifest_url,
844 bool blocked_by_policy) { 840 bool blocked_by_policy) {
845 if (blocked_by_policy) { 841 if (blocked_by_policy) {
846 blocked_local_shared_objects_.appcaches()->AddAppCache(manifest_url); 842 blocked_local_shared_objects_.appcaches()->AddAppCache(manifest_url);
847 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES); 843 OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES);
848 } else { 844 } else {
849 allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url); 845 allowed_local_shared_objects_.appcaches()->AddAppCache(manifest_url);
850 OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES); 846 OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES);
851 } 847 }
852 } 848 }
(...skipping 14 matching lines...) Expand all
867 863
868 void TabSpecificContentSettings::ClearGeolocationContentSettings() { 864 void TabSpecificContentSettings::ClearGeolocationContentSettings() {
869 geolocation_usages_state_.ClearStateMap(); 865 geolocation_usages_state_.ClearStateMap();
870 } 866 }
871 867
872 void TabSpecificContentSettings::ClearMidiContentSettings() { 868 void TabSpecificContentSettings::ClearMidiContentSettings() {
873 midi_usages_state_.ClearStateMap(); 869 midi_usages_state_.ClearStateMap();
874 } 870 }
875 871
876 void TabSpecificContentSettings::GeolocationDidNavigate( 872 void TabSpecificContentSettings::GeolocationDidNavigate(
877 content::NavigationHandle* navigation_handle) { 873 const content::LoadCommittedDetails& details) {
878 ContentSettingsUsagesState::CommittedDetails committed_details; 874 geolocation_usages_state_.DidNavigate(GetCommittedDetails(details));
879 committed_details.current_url = navigation_handle->GetURL();
880 committed_details.previous_url = previous_url_;
881
882 geolocation_usages_state_.DidNavigate(committed_details);
883 } 875 }
884 876
885 void TabSpecificContentSettings::MidiDidNavigate( 877 void TabSpecificContentSettings::MidiDidNavigate(
886 content::NavigationHandle* navigation_handle) { 878 const content::LoadCommittedDetails& details) {
887 ContentSettingsUsagesState::CommittedDetails committed_details; 879 midi_usages_state_.DidNavigate(GetCommittedDetails(details));
888 committed_details.current_url = navigation_handle->GetURL();
889 committed_details.previous_url = previous_url_;
890 midi_usages_state_.DidNavigate(committed_details);
891 } 880 }
892 881
893 void TabSpecificContentSettings::BlockAllContentForTesting() { 882 void TabSpecificContentSettings::BlockAllContentForTesting() {
894 content_settings::ContentSettingsRegistry* registry = 883 content_settings::ContentSettingsRegistry* registry =
895 content_settings::ContentSettingsRegistry::GetInstance(); 884 content_settings::ContentSettingsRegistry::GetInstance();
896 for (const content_settings::ContentSettingsInfo* info : *registry) { 885 for (const content_settings::ContentSettingsInfo* info : *registry) {
897 ContentSettingsType type = info->website_settings_info()->type(); 886 ContentSettingsType type = info->website_settings_info()->type();
898 if (type != CONTENT_SETTINGS_TYPE_GEOLOCATION && 887 if (type != CONTENT_SETTINGS_TYPE_GEOLOCATION &&
899 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && 888 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC &&
900 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { 889 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) {
901 OnContentBlocked(type); 890 OnContentBlocked(type);
902 } 891 }
903 } 892 }
904 893
905 // Geolocation and media must be blocked separately, as the generic 894 // Geolocation and media must be blocked separately, as the generic
906 // TabSpecificContentSettings::OnContentBlocked does not apply to them. 895 // TabSpecificContentSettings::OnContentBlocked does not apply to them.
907 OnGeolocationPermissionSet(web_contents()->GetLastCommittedURL(), false); 896 OnGeolocationPermissionSet(web_contents()->GetLastCommittedURL(), false);
908 MicrophoneCameraStateFlags media_blocked = 897 MicrophoneCameraStateFlags media_blocked =
909 static_cast<MicrophoneCameraStateFlags>( 898 static_cast<MicrophoneCameraStateFlags>(
910 TabSpecificContentSettings::MICROPHONE_ACCESSED | 899 TabSpecificContentSettings::MICROPHONE_ACCESSED |
911 TabSpecificContentSettings::MICROPHONE_BLOCKED | 900 TabSpecificContentSettings::MICROPHONE_BLOCKED |
912 TabSpecificContentSettings::CAMERA_ACCESSED | 901 TabSpecificContentSettings::CAMERA_ACCESSED |
913 TabSpecificContentSettings::CAMERA_BLOCKED); 902 TabSpecificContentSettings::CAMERA_BLOCKED);
914 OnMediaStreamPermissionSet( 903 OnMediaStreamPermissionSet(
915 web_contents()->GetLastCommittedURL(), 904 web_contents()->GetLastCommittedURL(),
916 media_blocked, 905 media_blocked,
917 std::string(), std::string(), std::string(), std::string()); 906 std::string(), std::string(), std::string(), std::string());
918 } 907 }
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/tab_specific_content_settings.h ('k') | chrome/browser/net/chrome_network_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698