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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 status.blocked = true; | 339 status.blocked = true; |
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); |
| 349 GURL url(details); |
| 350 DCHECK(url.is_valid()); |
346 content_settings::RecordMixedScriptActionWithRAPPOR( | 351 content_settings::RecordMixedScriptActionWithRAPPOR( |
347 content_settings::MIXED_SCRIPT_ACTION_DISPLAYED_SHIELD, | 352 rappor_service_, |
348 GURL(base::UTF16ToUTF8(details))); | 353 content_settings::MIXED_SCRIPT_ACTION_DISPLAYED_SHIELD, url); |
349 } | 354 } |
350 } | 355 } |
351 } | 356 } |
352 | 357 |
353 void TabSpecificContentSettings::OnContentAllowed(ContentSettingsType type) { | 358 void TabSpecificContentSettings::OnContentAllowed(ContentSettingsType type) { |
354 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) | 359 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
355 << "Geolocation settings handled by OnGeolocationPermissionSet"; | 360 << "Geolocation settings handled by OnGeolocationPermissionSet"; |
356 DCHECK(type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | 361 DCHECK(type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && |
357 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | 362 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) |
358 << "Media stream settings handled by OnMediaStreamPermissionSet"; | 363 << "Media stream settings handled by OnMediaStreamPermissionSet"; |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 void TabSpecificContentSettings::MidiDidNavigate( | 836 void TabSpecificContentSettings::MidiDidNavigate( |
832 const content::LoadCommittedDetails& details) { | 837 const content::LoadCommittedDetails& details) { |
833 midi_usages_state_.DidNavigate(GetCommittedDetails(details)); | 838 midi_usages_state_.DidNavigate(GetCommittedDetails(details)); |
834 } | 839 } |
835 | 840 |
836 void TabSpecificContentSettings::BlockAllContentForTesting() { | 841 void TabSpecificContentSettings::BlockAllContentForTesting() { |
837 content_settings::ContentSettingsRegistry* registry = | 842 content_settings::ContentSettingsRegistry* registry = |
838 content_settings::ContentSettingsRegistry::GetInstance(); | 843 content_settings::ContentSettingsRegistry::GetInstance(); |
839 for (const content_settings::ContentSettingsInfo* info : *registry) { | 844 for (const content_settings::ContentSettingsInfo* info : *registry) { |
840 ContentSettingsType type = info->website_settings_info()->type(); | 845 ContentSettingsType type = info->website_settings_info()->type(); |
841 if (type != CONTENT_SETTINGS_TYPE_GEOLOCATION && | 846 if (type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { |
842 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | 847 // For mixed script, OnContentBlockedWithDetail() expects a valid |
843 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | 848 // URL in the |details| argument. |
| 849 OnContentBlockedWithDetail(CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, |
| 850 base::ASCIIToUTF16("http://example.test")); |
| 851 } else if (type != CONTENT_SETTINGS_TYPE_GEOLOCATION && |
| 852 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && |
| 853 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
844 OnContentBlocked(type); | 854 OnContentBlocked(type); |
845 } | 855 } |
846 } | 856 } |
847 | 857 |
848 // Geolocation and media must be blocked separately, as the generic | 858 // Geolocation and media must be blocked separately, as the generic |
849 // TabSpecificContentSettings::OnContentBlocked does not apply to them. | 859 // TabSpecificContentSettings::OnContentBlocked does not apply to them. |
850 OnGeolocationPermissionSet(web_contents()->GetLastCommittedURL(), false); | 860 OnGeolocationPermissionSet(web_contents()->GetLastCommittedURL(), false); |
851 MicrophoneCameraStateFlags media_blocked = | 861 MicrophoneCameraStateFlags media_blocked = |
852 static_cast<MicrophoneCameraStateFlags>( | 862 static_cast<MicrophoneCameraStateFlags>( |
853 TabSpecificContentSettings::MICROPHONE_ACCESSED | | 863 TabSpecificContentSettings::MICROPHONE_ACCESSED | |
854 TabSpecificContentSettings::MICROPHONE_BLOCKED | | 864 TabSpecificContentSettings::MICROPHONE_BLOCKED | |
855 TabSpecificContentSettings::CAMERA_ACCESSED | | 865 TabSpecificContentSettings::CAMERA_ACCESSED | |
856 TabSpecificContentSettings::CAMERA_BLOCKED); | 866 TabSpecificContentSettings::CAMERA_BLOCKED); |
857 OnMediaStreamPermissionSet( | 867 OnMediaStreamPermissionSet( |
858 web_contents()->GetLastCommittedURL(), | 868 web_contents()->GetLastCommittedURL(), |
859 media_blocked, | 869 media_blocked, |
860 std::string(), std::string(), std::string(), std::string()); | 870 std::string(), std::string(), std::string(), std::string()); |
861 } | 871 } |
| 872 |
| 873 void TabSpecificContentSettings::SetRapporServiceForTesting( |
| 874 rappor::RapporService* rappor_service) { |
| 875 rappor_service_ = rappor_service; |
| 876 } |
OLD | NEW |