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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 blocked_local_shared_objects_( | 91 blocked_local_shared_objects_( |
92 Profile::FromBrowserContext(tab->GetBrowserContext())), | 92 Profile::FromBrowserContext(tab->GetBrowserContext())), |
93 geolocation_usages_state_( | 93 geolocation_usages_state_( |
94 HostContentSettingsMapFactory::GetForProfile( | 94 HostContentSettingsMapFactory::GetForProfile( |
95 Profile::FromBrowserContext(tab->GetBrowserContext())), | 95 Profile::FromBrowserContext(tab->GetBrowserContext())), |
96 CONTENT_SETTINGS_TYPE_GEOLOCATION), | 96 CONTENT_SETTINGS_TYPE_GEOLOCATION), |
97 midi_usages_state_( | 97 midi_usages_state_( |
98 HostContentSettingsMapFactory::GetForProfile( | 98 HostContentSettingsMapFactory::GetForProfile( |
99 Profile::FromBrowserContext(tab->GetBrowserContext())), | 99 Profile::FromBrowserContext(tab->GetBrowserContext())), |
100 CONTENT_SETTINGS_TYPE_MIDI_SYSEX), | 100 CONTENT_SETTINGS_TYPE_MIDI_SYSEX), |
| 101 // TODO(riju): when UMA is ready |
| 102 /* |
| 103 sensors_usages_state_( |
| 104 HostContentSettingsMapFactory::GetForProfile( |
| 105 Profile::FromBrowserContext(tab->GetBrowserContext())), |
| 106 CONTENT_SETTINGS_TYPE_SENSORS), |
| 107 */ |
101 pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), | 108 pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), |
102 previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), | 109 previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), |
103 pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT), | 110 pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT), |
104 load_plugins_link_enabled_(true), | 111 load_plugins_link_enabled_(true), |
105 microphone_camera_state_(MICROPHONE_CAMERA_NOT_ACCESSED), | 112 microphone_camera_state_(MICROPHONE_CAMERA_NOT_ACCESSED), |
106 subresource_filter_enabled_(false), | 113 subresource_filter_enabled_(false), |
107 subresource_filter_blockage_indicated_(false), | 114 subresource_filter_blockage_indicated_(false), |
108 observer_(this) { | 115 observer_(this) { |
109 ClearContentSettingsExceptForNavigationRelatedSettings(); | 116 ClearContentSettingsExceptForNavigationRelatedSettings(); |
110 ClearNavigationRelatedContentSettings(); | 117 ClearNavigationRelatedContentSettings(); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || | 250 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || |
244 content_type == CONTENT_SETTINGS_TYPE_PLUGINS || | 251 content_type == CONTENT_SETTINGS_TYPE_PLUGINS || |
245 content_type == CONTENT_SETTINGS_TYPE_COOKIES || | 252 content_type == CONTENT_SETTINGS_TYPE_COOKIES || |
246 content_type == CONTENT_SETTINGS_TYPE_POPUPS || | 253 content_type == CONTENT_SETTINGS_TYPE_POPUPS || |
247 content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT || | 254 content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT || |
248 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | 255 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
249 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA || | 256 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA || |
250 content_type == CONTENT_SETTINGS_TYPE_PPAPI_BROKER || | 257 content_type == CONTENT_SETTINGS_TYPE_PPAPI_BROKER || |
251 content_type == CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS || | 258 content_type == CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS || |
252 content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX || | 259 content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX || |
| 260 // content_type == CONTENT_SETTINGS_TYPE_SENSORS || |
253 content_type == CONTENT_SETTINGS_TYPE_KEYGEN) { | 261 content_type == CONTENT_SETTINGS_TYPE_KEYGEN) { |
254 const auto& it = content_settings_status_.find(content_type); | 262 const auto& it = content_settings_status_.find(content_type); |
255 if (it != content_settings_status_.end()) | 263 if (it != content_settings_status_.end()) |
256 return it->second.blocked; | 264 return it->second.blocked; |
257 } | 265 } |
258 | 266 |
259 return false; | 267 return false; |
260 } | 268 } |
261 | 269 |
262 bool TabSpecificContentSettings::IsSubresourceBlocked() const { | 270 bool TabSpecificContentSettings::IsSubresourceBlocked() const { |
(...skipping 23 matching lines...) Expand all Loading... |
286 | 294 |
287 bool TabSpecificContentSettings::IsContentAllowed( | 295 bool TabSpecificContentSettings::IsContentAllowed( |
288 ContentSettingsType content_type) const { | 296 ContentSettingsType content_type) const { |
289 // This method currently only returns meaningful values for the content type | 297 // This method currently only returns meaningful values for the content type |
290 // cookies, media, PPAPI broker, downloads, and MIDI sysex. | 298 // cookies, media, PPAPI broker, downloads, and MIDI sysex. |
291 if (content_type != CONTENT_SETTINGS_TYPE_COOKIES && | 299 if (content_type != CONTENT_SETTINGS_TYPE_COOKIES && |
292 content_type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | 300 content_type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && |
293 content_type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA && | 301 content_type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA && |
294 content_type != CONTENT_SETTINGS_TYPE_PPAPI_BROKER && | 302 content_type != CONTENT_SETTINGS_TYPE_PPAPI_BROKER && |
295 content_type != CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS && | 303 content_type != CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS && |
| 304 // content_type != CONTENT_SETTINGS_TYPE_SENSORS && |
296 content_type != CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { | 305 content_type != CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { |
297 return false; | 306 return false; |
298 } | 307 } |
299 | 308 |
300 const auto& it = content_settings_status_.find(content_type); | 309 const auto& it = content_settings_status_.find(content_type); |
301 if (it != content_settings_status_.end()) | 310 if (it != content_settings_status_.end()) |
302 return it->second.allowed; | 311 return it->second.allowed; |
303 return false; | 312 return false; |
304 } | 313 } |
305 | 314 |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 midi_usages_state_.OnPermissionSet(requesting_origin, true); | 666 midi_usages_state_.OnPermissionSet(requesting_origin, true); |
658 OnContentAllowed(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 667 OnContentAllowed(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
659 } | 668 } |
660 | 669 |
661 void TabSpecificContentSettings::OnMidiSysExAccessBlocked( | 670 void TabSpecificContentSettings::OnMidiSysExAccessBlocked( |
662 const GURL& requesting_origin) { | 671 const GURL& requesting_origin) { |
663 midi_usages_state_.OnPermissionSet(requesting_origin, false); | 672 midi_usages_state_.OnPermissionSet(requesting_origin, false); |
664 OnContentBlocked(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 673 OnContentBlocked(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
665 } | 674 } |
666 | 675 |
| 676 void TabSpecificContentSettings::OnSensorAccessed( |
| 677 const GURL& requesting_origin) { |
| 678 OnContentAllowed(CONTENT_SETTINGS_TYPE_SENSORS); |
| 679 } |
| 680 |
| 681 void TabSpecificContentSettings::OnSensorAccessBlocked( |
| 682 const GURL& requesting_origin) { |
| 683 OnContentBlocked(CONTENT_SETTINGS_TYPE_SENSORS); |
| 684 } |
| 685 |
667 void TabSpecificContentSettings:: | 686 void TabSpecificContentSettings:: |
668 ClearContentSettingsExceptForNavigationRelatedSettings() { | 687 ClearContentSettingsExceptForNavigationRelatedSettings() { |
669 for (auto& status : content_settings_status_) { | 688 for (auto& status : content_settings_status_) { |
670 if (status.first == CONTENT_SETTINGS_TYPE_COOKIES || | 689 if (status.first == CONTENT_SETTINGS_TYPE_COOKIES || |
671 status.first == CONTENT_SETTINGS_TYPE_JAVASCRIPT) | 690 status.first == CONTENT_SETTINGS_TYPE_JAVASCRIPT) |
672 continue; | 691 continue; |
673 status.second.blocked = false; | 692 status.second.blocked = false; |
674 status.second.blockage_indicated_to_user = false; | 693 status.second.blockage_indicated_to_user = false; |
675 status.second.allowed = false; | 694 status.second.allowed = false; |
676 } | 695 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 if (last_committed_entry) | 829 if (last_committed_entry) |
811 previous_url_ = last_committed_entry->GetURL(); | 830 previous_url_ = last_committed_entry->GetURL(); |
812 | 831 |
813 // If we're displaying a network error page do not reset the content | 832 // 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 | 833 // settings delegate's cookies so the user has a chance to modify cookie |
815 // settings. | 834 // settings. |
816 if (!navigation_handle->IsErrorPage()) | 835 if (!navigation_handle->IsErrorPage()) |
817 ClearNavigationRelatedContentSettings(); | 836 ClearNavigationRelatedContentSettings(); |
818 ClearGeolocationContentSettings(); | 837 ClearGeolocationContentSettings(); |
819 ClearMidiContentSettings(); | 838 ClearMidiContentSettings(); |
| 839 // ClearSensorContentSettings(); |
820 ClearPendingProtocolHandler(); | 840 ClearPendingProtocolHandler(); |
821 } | 841 } |
822 | 842 |
823 void TabSpecificContentSettings::DidFinishNavigation( | 843 void TabSpecificContentSettings::DidFinishNavigation( |
824 content::NavigationHandle* navigation_handle) { | 844 content::NavigationHandle* navigation_handle) { |
825 if (!navigation_handle->IsInMainFrame() || | 845 if (!navigation_handle->IsInMainFrame() || |
826 !navigation_handle->HasCommitted() || | 846 !navigation_handle->HasCommitted() || |
827 navigation_handle->IsSamePage()) { | 847 navigation_handle->IsSamePage()) { |
828 return; | 848 return; |
829 } | 849 } |
830 | 850 |
831 // Clear "blocked" flags. | 851 // Clear "blocked" flags. |
832 ClearContentSettingsExceptForNavigationRelatedSettings(); | 852 ClearContentSettingsExceptForNavigationRelatedSettings(); |
833 blocked_plugin_names_.clear(); | 853 blocked_plugin_names_.clear(); |
834 GeolocationDidNavigate(navigation_handle); | 854 GeolocationDidNavigate(navigation_handle); |
835 MidiDidNavigate(navigation_handle); | 855 MidiDidNavigate(navigation_handle); |
| 856 // SensorDidNavigate(navigation_handle); |
836 | 857 |
837 if (web_contents()->GetVisibleURL().SchemeIsHTTPOrHTTPS()) { | 858 if (web_contents()->GetVisibleURL().SchemeIsHTTPOrHTTPS()) { |
838 content_settings::RecordPluginsAction( | 859 content_settings::RecordPluginsAction( |
839 content_settings::PLUGINS_ACTION_TOTAL_NAVIGATIONS); | 860 content_settings::PLUGINS_ACTION_TOTAL_NAVIGATIONS); |
840 } | 861 } |
841 } | 862 } |
842 | 863 |
843 void TabSpecificContentSettings::AppCacheAccessed(const GURL& manifest_url, | 864 void TabSpecificContentSettings::AppCacheAccessed(const GURL& manifest_url, |
844 bool blocked_by_policy) { | 865 bool blocked_by_policy) { |
845 if (blocked_by_policy) { | 866 if (blocked_by_policy) { |
(...skipping 21 matching lines...) Expand all Loading... |
867 } | 888 } |
868 | 889 |
869 void TabSpecificContentSettings::ClearGeolocationContentSettings() { | 890 void TabSpecificContentSettings::ClearGeolocationContentSettings() { |
870 geolocation_usages_state_.ClearStateMap(); | 891 geolocation_usages_state_.ClearStateMap(); |
871 } | 892 } |
872 | 893 |
873 void TabSpecificContentSettings::ClearMidiContentSettings() { | 894 void TabSpecificContentSettings::ClearMidiContentSettings() { |
874 midi_usages_state_.ClearStateMap(); | 895 midi_usages_state_.ClearStateMap(); |
875 } | 896 } |
876 | 897 |
| 898 /* |
| 899 void TabSpecificContentSettings::ClearSensorContentSettings() { |
| 900 sensors_usages_state_.ClearStateMap(); |
| 901 } |
| 902 */ |
| 903 |
877 void TabSpecificContentSettings::GeolocationDidNavigate( | 904 void TabSpecificContentSettings::GeolocationDidNavigate( |
878 content::NavigationHandle* navigation_handle) { | 905 content::NavigationHandle* navigation_handle) { |
879 ContentSettingsUsagesState::CommittedDetails committed_details; | 906 ContentSettingsUsagesState::CommittedDetails committed_details; |
880 committed_details.current_url = navigation_handle->GetURL(); | 907 committed_details.current_url = navigation_handle->GetURL(); |
881 committed_details.previous_url = previous_url_; | 908 committed_details.previous_url = previous_url_; |
882 | 909 |
883 geolocation_usages_state_.DidNavigate(committed_details); | 910 geolocation_usages_state_.DidNavigate(committed_details); |
884 } | 911 } |
885 | 912 |
886 void TabSpecificContentSettings::MidiDidNavigate( | 913 void TabSpecificContentSettings::MidiDidNavigate( |
887 content::NavigationHandle* navigation_handle) { | 914 content::NavigationHandle* navigation_handle) { |
888 ContentSettingsUsagesState::CommittedDetails committed_details; | 915 ContentSettingsUsagesState::CommittedDetails committed_details; |
889 committed_details.current_url = navigation_handle->GetURL(); | 916 committed_details.current_url = navigation_handle->GetURL(); |
890 committed_details.previous_url = previous_url_; | 917 committed_details.previous_url = previous_url_; |
891 midi_usages_state_.DidNavigate(committed_details); | 918 midi_usages_state_.DidNavigate(committed_details); |
892 } | 919 } |
893 | 920 |
| 921 /* |
| 922 void TabSpecificContentSettings::SensorDidNavigate( |
| 923 content::NavigationHandle* navigation_handle) { |
| 924 ContentSettingsUsagesState::CommittedDetails committed_details; |
| 925 committed_details.current_url = navigation_handle->GetURL(); |
| 926 committed_details.previous_url = previous_url_; |
| 927 sensors_usages_state_.DidNavigate(committed_details); |
| 928 } |
| 929 */ |
| 930 |
894 void TabSpecificContentSettings::BlockAllContentForTesting() { | 931 void TabSpecificContentSettings::BlockAllContentForTesting() { |
895 content_settings::ContentSettingsRegistry* registry = | 932 content_settings::ContentSettingsRegistry* registry = |
896 content_settings::ContentSettingsRegistry::GetInstance(); | 933 content_settings::ContentSettingsRegistry::GetInstance(); |
897 for (const content_settings::ContentSettingsInfo* info : *registry) { | 934 for (const content_settings::ContentSettingsInfo* info : *registry) { |
898 ContentSettingsType type = info->website_settings_info()->type(); | 935 ContentSettingsType type = info->website_settings_info()->type(); |
899 if (type != CONTENT_SETTINGS_TYPE_GEOLOCATION && | 936 if (type != CONTENT_SETTINGS_TYPE_GEOLOCATION && |
900 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | 937 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && |
901 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | 938 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
902 OnContentBlocked(type); | 939 OnContentBlocked(type); |
903 } | 940 } |
904 } | 941 } |
905 | 942 |
906 // Geolocation and media must be blocked separately, as the generic | 943 // Geolocation and media must be blocked separately, as the generic |
907 // TabSpecificContentSettings::OnContentBlocked does not apply to them. | 944 // TabSpecificContentSettings::OnContentBlocked does not apply to them. |
908 OnGeolocationPermissionSet(web_contents()->GetLastCommittedURL(), false); | 945 OnGeolocationPermissionSet(web_contents()->GetLastCommittedURL(), false); |
909 MicrophoneCameraStateFlags media_blocked = | 946 MicrophoneCameraStateFlags media_blocked = |
910 static_cast<MicrophoneCameraStateFlags>( | 947 static_cast<MicrophoneCameraStateFlags>( |
911 TabSpecificContentSettings::MICROPHONE_ACCESSED | | 948 TabSpecificContentSettings::MICROPHONE_ACCESSED | |
912 TabSpecificContentSettings::MICROPHONE_BLOCKED | | 949 TabSpecificContentSettings::MICROPHONE_BLOCKED | |
913 TabSpecificContentSettings::CAMERA_ACCESSED | | 950 TabSpecificContentSettings::CAMERA_ACCESSED | |
914 TabSpecificContentSettings::CAMERA_BLOCKED); | 951 TabSpecificContentSettings::CAMERA_BLOCKED); |
915 OnMediaStreamPermissionSet( | 952 OnMediaStreamPermissionSet( |
916 web_contents()->GetLastCommittedURL(), | 953 web_contents()->GetLastCommittedURL(), |
917 media_blocked, | 954 media_blocked, |
918 std::string(), std::string(), std::string(), std::string()); | 955 std::string(), std::string(), std::string(), std::string()); |
919 } | 956 } |
OLD | NEW |