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" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "chrome/browser/browser_process.h" | |
14 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" | 15 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" |
15 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" | 16 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" |
16 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" | 17 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" |
17 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" | 18 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" |
18 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" | 19 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" |
19 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" | 20 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
20 #include "chrome/browser/browsing_data/cookies_tree_model.h" | 21 #include "chrome/browser/browsing_data/cookies_tree_model.h" |
21 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
22 #include "chrome/browser/content_settings/chrome_content_settings_utils.h" | 23 #include "chrome/browser/content_settings/chrome_content_settings_utils.h" |
23 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 24 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
24 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 25 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
25 #include "chrome/browser/media/media_stream_capture_indicator.h" | 26 #include "chrome/browser/media/media_stream_capture_indicator.h" |
26 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
29 #include "chrome/common/render_messages.h" | 30 #include "chrome/common/render_messages.h" |
30 #include "components/content_settings/content/common/content_settings_messages.h " | 31 #include "components/content_settings/content/common/content_settings_messages.h " |
31 #include "components/content_settings/core/browser/content_settings_details.h" | 32 #include "components/content_settings/core/browser/content_settings_details.h" |
32 #include "components/content_settings/core/browser/content_settings_info.h" | 33 #include "components/content_settings/core/browser/content_settings_info.h" |
33 #include "components/content_settings/core/browser/content_settings_registry.h" | 34 #include "components/content_settings/core/browser/content_settings_registry.h" |
34 #include "components/content_settings/core/browser/content_settings_utils.h" | 35 #include "components/content_settings/core/browser/content_settings_utils.h" |
35 #include "components/content_settings/core/browser/host_content_settings_map.h" | 36 #include "components/content_settings/core/browser/host_content_settings_map.h" |
36 #include "components/prefs/pref_service.h" | 37 #include "components/prefs/pref_service.h" |
38 #include "components/rappor/rappor_service.h" | |
37 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
38 #include "content/public/browser/navigation_controller.h" | 40 #include "content/public/browser/navigation_controller.h" |
39 #include "content/public/browser/navigation_details.h" | 41 #include "content/public/browser/navigation_details.h" |
40 #include "content/public/browser/navigation_entry.h" | 42 #include "content/public/browser/navigation_entry.h" |
41 #include "content/public/browser/notification_registrar.h" | 43 #include "content/public/browser/notification_registrar.h" |
42 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
43 #include "content/public/browser/render_frame_host.h" | 45 #include "content/public/browser/render_frame_host.h" |
44 #include "content/public/browser/render_view_host.h" | 46 #include "content/public/browser/render_view_host.h" |
45 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
46 #include "content/public/browser/web_contents_delegate.h" | 48 #include "content/public/browser/web_contents_delegate.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 CONTENT_SETTINGS_TYPE_GEOLOCATION), | 98 CONTENT_SETTINGS_TYPE_GEOLOCATION), |
97 midi_usages_state_( | 99 midi_usages_state_( |
98 HostContentSettingsMapFactory::GetForProfile( | 100 HostContentSettingsMapFactory::GetForProfile( |
99 Profile::FromBrowserContext(tab->GetBrowserContext())), | 101 Profile::FromBrowserContext(tab->GetBrowserContext())), |
100 CONTENT_SETTINGS_TYPE_MIDI_SYSEX), | 102 CONTENT_SETTINGS_TYPE_MIDI_SYSEX), |
101 pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), | 103 pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), |
102 previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), | 104 previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), |
103 pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT), | 105 pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT), |
104 load_plugins_link_enabled_(true), | 106 load_plugins_link_enabled_(true), |
105 microphone_camera_state_(MICROPHONE_CAMERA_NOT_ACCESSED), | 107 microphone_camera_state_(MICROPHONE_CAMERA_NOT_ACCESSED), |
106 observer_(this) { | 108 observer_(this), |
109 rappor_service_(g_browser_process->rappor_service()) { | |
107 ClearBlockedContentSettingsExceptForCookies(); | 110 ClearBlockedContentSettingsExceptForCookies(); |
108 ClearCookieSpecificContentSettings(); | 111 ClearCookieSpecificContentSettings(); |
109 | 112 |
110 observer_.Add(HostContentSettingsMapFactory::GetForProfile( | 113 observer_.Add(HostContentSettingsMapFactory::GetForProfile( |
111 Profile::FromBrowserContext(tab->GetBrowserContext()))); | 114 Profile::FromBrowserContext(tab->GetBrowserContext()))); |
112 } | 115 } |
113 | 116 |
114 TabSpecificContentSettings::~TabSpecificContentSettings() { | 117 TabSpecificContentSettings::~TabSpecificContentSettings() { |
115 FOR_EACH_OBSERVER( | 118 FOR_EACH_OBSERVER( |
116 SiteDataObserver, observer_list_, ContentSettingsDestroyed()); | 119 SiteDataObserver, observer_list_, ContentSettingsDestroyed()); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 // TODO: it would be nice to have a way of mocking this in tests. | 340 // TODO: it would be nice to have a way of mocking this in tests. |
338 content::NotificationService::current()->Notify( | 341 content::NotificationService::current()->Notify( |
339 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 342 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
340 content::Source<WebContents>(web_contents()), | 343 content::Source<WebContents>(web_contents()), |
341 content::NotificationService::NoDetails()); | 344 content::NotificationService::NoDetails()); |
342 | 345 |
343 if (type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { | 346 if (type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { |
344 content_settings::RecordMixedScriptAction( | 347 content_settings::RecordMixedScriptAction( |
345 content_settings::MIXED_SCRIPT_ACTION_DISPLAYED_SHIELD); | 348 content_settings::MIXED_SCRIPT_ACTION_DISPLAYED_SHIELD); |
346 content_settings::RecordMixedScriptActionWithRAPPOR( | 349 content_settings::RecordMixedScriptActionWithRAPPOR( |
350 rappor_service_, | |
347 content_settings::MIXED_SCRIPT_ACTION_DISPLAYED_SHIELD, | 351 content_settings::MIXED_SCRIPT_ACTION_DISPLAYED_SHIELD, |
348 GURL(base::UTF16ToUTF8(details))); | 352 GURL(details)); |
felt
2016/06/10 03:41:08
A note for posterity: this code path used to only
| |
349 } | 353 } |
350 } | 354 } |
351 } | 355 } |
352 | 356 |
353 void TabSpecificContentSettings::OnContentAllowed(ContentSettingsType type) { | 357 void TabSpecificContentSettings::OnContentAllowed(ContentSettingsType type) { |
354 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) | 358 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
355 << "Geolocation settings handled by OnGeolocationPermissionSet"; | 359 << "Geolocation settings handled by OnGeolocationPermissionSet"; |
356 DCHECK(type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | 360 DCHECK(type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && |
357 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | 361 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) |
358 << "Media stream settings handled by OnMediaStreamPermissionSet"; | 362 << "Media stream settings handled by OnMediaStreamPermissionSet"; |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 content_settings::ContentSettingsRegistry* registry = | 841 content_settings::ContentSettingsRegistry* registry = |
838 content_settings::ContentSettingsRegistry::GetInstance(); | 842 content_settings::ContentSettingsRegistry::GetInstance(); |
839 for (const content_settings::ContentSettingsInfo* info : *registry) { | 843 for (const content_settings::ContentSettingsInfo* info : *registry) { |
840 ContentSettingsType type = info->website_settings_info()->type(); | 844 ContentSettingsType type = info->website_settings_info()->type(); |
841 if (type != CONTENT_SETTINGS_TYPE_GEOLOCATION && | 845 if (type != CONTENT_SETTINGS_TYPE_GEOLOCATION && |
842 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | 846 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && |
843 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | 847 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
844 OnContentBlocked(type); | 848 OnContentBlocked(type); |
845 } | 849 } |
846 } | 850 } |
847 | |
felt
2016/06/10 03:41:08
nit: why kill this line break?
estark
2016/06/10 03:55:20
Oops, undone.
| |
848 // Geolocation and media must be blocked separately, as the generic | 851 // Geolocation and media must be blocked separately, as the generic |
849 // TabSpecificContentSettings::OnContentBlocked does not apply to them. | 852 // TabSpecificContentSettings::OnContentBlocked does not apply to them. |
850 OnGeolocationPermissionSet(web_contents()->GetLastCommittedURL(), false); | 853 OnGeolocationPermissionSet(web_contents()->GetLastCommittedURL(), false); |
851 MicrophoneCameraStateFlags media_blocked = | 854 MicrophoneCameraStateFlags media_blocked = |
852 static_cast<MicrophoneCameraStateFlags>( | 855 static_cast<MicrophoneCameraStateFlags>( |
853 TabSpecificContentSettings::MICROPHONE_ACCESSED | | 856 TabSpecificContentSettings::MICROPHONE_ACCESSED | |
854 TabSpecificContentSettings::MICROPHONE_BLOCKED | | 857 TabSpecificContentSettings::MICROPHONE_BLOCKED | |
855 TabSpecificContentSettings::CAMERA_ACCESSED | | 858 TabSpecificContentSettings::CAMERA_ACCESSED | |
856 TabSpecificContentSettings::CAMERA_BLOCKED); | 859 TabSpecificContentSettings::CAMERA_BLOCKED); |
857 OnMediaStreamPermissionSet( | 860 OnMediaStreamPermissionSet( |
858 web_contents()->GetLastCommittedURL(), | 861 web_contents()->GetLastCommittedURL(), |
859 media_blocked, | 862 media_blocked, |
860 std::string(), std::string(), std::string(), std::string()); | 863 std::string(), std::string(), std::string(), std::string()); |
861 } | 864 } |
865 | |
866 void TabSpecificContentSettings::SetRapporServiceForTesting( | |
867 rappor::RapporService* rappor_service) { | |
868 rappor_service_ = rappor_service; | |
869 } | |
OLD | NEW |