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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 241 |
242 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES || | 242 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES || |
243 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || | 243 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || |
244 content_type == CONTENT_SETTINGS_TYPE_PLUGINS || | 244 content_type == CONTENT_SETTINGS_TYPE_PLUGINS || |
245 content_type == CONTENT_SETTINGS_TYPE_COOKIES || | 245 content_type == CONTENT_SETTINGS_TYPE_COOKIES || |
246 content_type == CONTENT_SETTINGS_TYPE_POPUPS || | 246 content_type == CONTENT_SETTINGS_TYPE_POPUPS || |
247 content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT || | 247 content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT || |
248 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | 248 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
249 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA || | 249 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA || |
250 content_type == CONTENT_SETTINGS_TYPE_PPAPI_BROKER || | 250 content_type == CONTENT_SETTINGS_TYPE_PPAPI_BROKER || |
251 content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX || | 251 content_type == CONTENT_SETTINGS_TYPE_SENSORS || |
252 content_type == CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER) { | 252 content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { |
253 const auto& it = content_settings_status_.find(content_type); | 253 const auto& it = content_settings_status_.find(content_type); |
254 if (it != content_settings_status_.end()) | 254 if (it != content_settings_status_.end()) |
255 return it->second.blocked; | 255 return it->second.blocked; |
256 } | 256 } |
257 | 257 |
258 return false; | 258 return false; |
259 } | 259 } |
260 | 260 |
261 bool TabSpecificContentSettings::IsBlockageIndicated( | 261 bool TabSpecificContentSettings::IsBlockageIndicated( |
262 ContentSettingsType content_type) const { | 262 ContentSettingsType content_type) const { |
(...skipping 12 matching lines...) Expand all Loading... |
275 ContentSettingsType content_type) const { | 275 ContentSettingsType content_type) const { |
276 DCHECK_NE(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, content_type) | 276 DCHECK_NE(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, content_type) |
277 << "Automatic downloads handled by DownloadRequestLimiter"; | 277 << "Automatic downloads handled by DownloadRequestLimiter"; |
278 | 278 |
279 // This method currently only returns meaningful values for the content type | 279 // This method currently only returns meaningful values for the content type |
280 // cookies, media, PPAPI broker, downloads, and MIDI sysex. | 280 // cookies, media, PPAPI broker, downloads, and MIDI sysex. |
281 if (content_type != CONTENT_SETTINGS_TYPE_COOKIES && | 281 if (content_type != CONTENT_SETTINGS_TYPE_COOKIES && |
282 content_type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | 282 content_type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && |
283 content_type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA && | 283 content_type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA && |
284 content_type != CONTENT_SETTINGS_TYPE_PPAPI_BROKER && | 284 content_type != CONTENT_SETTINGS_TYPE_PPAPI_BROKER && |
| 285 content_type != CONTENT_SETTINGS_TYPE_SENSORS && |
285 content_type != CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { | 286 content_type != CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { |
286 return false; | 287 return false; |
287 } | 288 } |
288 | 289 |
289 const auto& it = content_settings_status_.find(content_type); | 290 const auto& it = content_settings_status_.find(content_type); |
290 if (it != content_settings_status_.end()) | 291 if (it != content_settings_status_.end()) |
291 return it->second.allowed; | 292 return it->second.allowed; |
292 return false; | 293 return false; |
293 } | 294 } |
294 | 295 |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 midi_usages_state_.OnPermissionSet(requesting_origin, true); | 640 midi_usages_state_.OnPermissionSet(requesting_origin, true); |
640 OnContentAllowed(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 641 OnContentAllowed(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
641 } | 642 } |
642 | 643 |
643 void TabSpecificContentSettings::OnMidiSysExAccessBlocked( | 644 void TabSpecificContentSettings::OnMidiSysExAccessBlocked( |
644 const GURL& requesting_origin) { | 645 const GURL& requesting_origin) { |
645 midi_usages_state_.OnPermissionSet(requesting_origin, false); | 646 midi_usages_state_.OnPermissionSet(requesting_origin, false); |
646 OnContentBlocked(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 647 OnContentBlocked(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
647 } | 648 } |
648 | 649 |
| 650 void TabSpecificContentSettings::OnSensorAccessed( |
| 651 const GURL& requesting_origin) { |
| 652 OnContentAllowed(CONTENT_SETTINGS_TYPE_SENSORS); |
| 653 } |
| 654 |
| 655 void TabSpecificContentSettings::OnSensorAccessBlocked( |
| 656 const GURL& requesting_origin) { |
| 657 OnContentBlocked(CONTENT_SETTINGS_TYPE_SENSORS); |
| 658 } |
| 659 |
649 void TabSpecificContentSettings:: | 660 void TabSpecificContentSettings:: |
650 ClearContentSettingsExceptForNavigationRelatedSettings() { | 661 ClearContentSettingsExceptForNavigationRelatedSettings() { |
651 for (auto& status : content_settings_status_) { | 662 for (auto& status : content_settings_status_) { |
652 if (status.first == CONTENT_SETTINGS_TYPE_COOKIES || | 663 if (status.first == CONTENT_SETTINGS_TYPE_COOKIES || |
653 status.first == CONTENT_SETTINGS_TYPE_JAVASCRIPT) | 664 status.first == CONTENT_SETTINGS_TYPE_JAVASCRIPT) |
654 continue; | 665 continue; |
655 status.second.blocked = false; | 666 status.second.blocked = false; |
656 status.second.blockage_indicated_to_user = false; | 667 status.second.blockage_indicated_to_user = false; |
657 status.second.allowed = false; | 668 status.second.allowed = false; |
658 } | 669 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 if (last_committed_entry) | 796 if (last_committed_entry) |
786 previous_url_ = last_committed_entry->GetURL(); | 797 previous_url_ = last_committed_entry->GetURL(); |
787 | 798 |
788 // If we're displaying a network error page do not reset the content | 799 // If we're displaying a network error page do not reset the content |
789 // settings delegate's cookies so the user has a chance to modify cookie | 800 // settings delegate's cookies so the user has a chance to modify cookie |
790 // settings. | 801 // settings. |
791 if (!navigation_handle->IsErrorPage()) | 802 if (!navigation_handle->IsErrorPage()) |
792 ClearNavigationRelatedContentSettings(); | 803 ClearNavigationRelatedContentSettings(); |
793 ClearGeolocationContentSettings(); | 804 ClearGeolocationContentSettings(); |
794 ClearMidiContentSettings(); | 805 ClearMidiContentSettings(); |
| 806 // ClearSensorContentSettings(); |
795 ClearPendingProtocolHandler(); | 807 ClearPendingProtocolHandler(); |
796 } | 808 } |
797 | 809 |
798 void TabSpecificContentSettings::DidFinishNavigation( | 810 void TabSpecificContentSettings::DidFinishNavigation( |
799 content::NavigationHandle* navigation_handle) { | 811 content::NavigationHandle* navigation_handle) { |
800 if (!navigation_handle->IsInMainFrame() || | 812 if (!navigation_handle->IsInMainFrame() || |
801 !navigation_handle->HasCommitted() || | 813 !navigation_handle->HasCommitted() || |
802 navigation_handle->IsSameDocument()) { | 814 navigation_handle->IsSameDocument()) { |
803 return; | 815 return; |
804 } | 816 } |
805 | 817 |
806 // Clear "blocked" flags. | 818 // Clear "blocked" flags. |
807 ClearContentSettingsExceptForNavigationRelatedSettings(); | 819 ClearContentSettingsExceptForNavigationRelatedSettings(); |
808 blocked_plugin_names_.clear(); | 820 blocked_plugin_names_.clear(); |
809 GeolocationDidNavigate(navigation_handle); | 821 GeolocationDidNavigate(navigation_handle); |
810 MidiDidNavigate(navigation_handle); | 822 MidiDidNavigate(navigation_handle); |
| 823 // SensorDidNavigate(navigation_handle); |
811 | 824 |
812 if (web_contents()->GetVisibleURL().SchemeIsHTTPOrHTTPS()) { | 825 if (web_contents()->GetVisibleURL().SchemeIsHTTPOrHTTPS()) { |
813 content_settings::RecordPluginsAction( | 826 content_settings::RecordPluginsAction( |
814 content_settings::PLUGINS_ACTION_TOTAL_NAVIGATIONS); | 827 content_settings::PLUGINS_ACTION_TOTAL_NAVIGATIONS); |
815 } | 828 } |
816 } | 829 } |
817 | 830 |
818 void TabSpecificContentSettings::AppCacheAccessed(const GURL& manifest_url, | 831 void TabSpecificContentSettings::AppCacheAccessed(const GURL& manifest_url, |
819 bool blocked_by_policy) { | 832 bool blocked_by_policy) { |
820 if (blocked_by_policy) { | 833 if (blocked_by_policy) { |
(...skipping 21 matching lines...) Expand all Loading... |
842 } | 855 } |
843 | 856 |
844 void TabSpecificContentSettings::ClearGeolocationContentSettings() { | 857 void TabSpecificContentSettings::ClearGeolocationContentSettings() { |
845 geolocation_usages_state_.ClearStateMap(); | 858 geolocation_usages_state_.ClearStateMap(); |
846 } | 859 } |
847 | 860 |
848 void TabSpecificContentSettings::ClearMidiContentSettings() { | 861 void TabSpecificContentSettings::ClearMidiContentSettings() { |
849 midi_usages_state_.ClearStateMap(); | 862 midi_usages_state_.ClearStateMap(); |
850 } | 863 } |
851 | 864 |
| 865 /* |
| 866 void TabSpecificContentSettings::ClearSensorContentSettings() { |
| 867 sensors_usages_state_.ClearStateMap(); |
| 868 } |
| 869 */ |
| 870 |
852 void TabSpecificContentSettings::GeolocationDidNavigate( | 871 void TabSpecificContentSettings::GeolocationDidNavigate( |
853 content::NavigationHandle* navigation_handle) { | 872 content::NavigationHandle* navigation_handle) { |
854 ContentSettingsUsagesState::CommittedDetails committed_details; | 873 ContentSettingsUsagesState::CommittedDetails committed_details; |
855 committed_details.current_url = navigation_handle->GetURL(); | 874 committed_details.current_url = navigation_handle->GetURL(); |
856 committed_details.previous_url = previous_url_; | 875 committed_details.previous_url = previous_url_; |
857 | 876 |
858 geolocation_usages_state_.DidNavigate(committed_details); | 877 geolocation_usages_state_.DidNavigate(committed_details); |
859 } | 878 } |
860 | 879 |
861 void TabSpecificContentSettings::MidiDidNavigate( | 880 void TabSpecificContentSettings::MidiDidNavigate( |
862 content::NavigationHandle* navigation_handle) { | 881 content::NavigationHandle* navigation_handle) { |
863 ContentSettingsUsagesState::CommittedDetails committed_details; | 882 ContentSettingsUsagesState::CommittedDetails committed_details; |
864 committed_details.current_url = navigation_handle->GetURL(); | 883 committed_details.current_url = navigation_handle->GetURL(); |
865 committed_details.previous_url = previous_url_; | 884 committed_details.previous_url = previous_url_; |
866 midi_usages_state_.DidNavigate(committed_details); | 885 midi_usages_state_.DidNavigate(committed_details); |
867 } | 886 } |
868 | 887 |
| 888 /* |
| 889 void TabSpecificContentSettings::SensorDidNavigate( |
| 890 content::NavigationHandle* navigation_handle) { |
| 891 ContentSettingsUsagesState::CommittedDetails committed_details; |
| 892 committed_details.current_url = navigation_handle->GetURL(); |
| 893 committed_details.previous_url = previous_url_; |
| 894 sensors_usages_state_.DidNavigate(committed_details); |
| 895 } |
| 896 */ |
| 897 |
869 void TabSpecificContentSettings::BlockAllContentForTesting() { | 898 void TabSpecificContentSettings::BlockAllContentForTesting() { |
870 content_settings::ContentSettingsRegistry* registry = | 899 content_settings::ContentSettingsRegistry* registry = |
871 content_settings::ContentSettingsRegistry::GetInstance(); | 900 content_settings::ContentSettingsRegistry::GetInstance(); |
872 for (const content_settings::ContentSettingsInfo* info : *registry) { | 901 for (const content_settings::ContentSettingsInfo* info : *registry) { |
873 ContentSettingsType type = info->website_settings_info()->type(); | 902 ContentSettingsType type = info->website_settings_info()->type(); |
874 if (type != CONTENT_SETTINGS_TYPE_GEOLOCATION && | 903 if (type != CONTENT_SETTINGS_TYPE_GEOLOCATION && |
875 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | 904 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && |
876 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { | 905 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
877 OnContentBlocked(type); | 906 OnContentBlocked(type); |
878 } | 907 } |
879 } | 908 } |
880 | 909 |
881 // Geolocation and media must be blocked separately, as the generic | 910 // Geolocation and media must be blocked separately, as the generic |
882 // TabSpecificContentSettings::OnContentBlocked does not apply to them. | 911 // TabSpecificContentSettings::OnContentBlocked does not apply to them. |
883 OnGeolocationPermissionSet(web_contents()->GetLastCommittedURL(), false); | 912 OnGeolocationPermissionSet(web_contents()->GetLastCommittedURL(), false); |
884 MicrophoneCameraStateFlags media_blocked = | 913 MicrophoneCameraStateFlags media_blocked = |
885 static_cast<MicrophoneCameraStateFlags>( | 914 static_cast<MicrophoneCameraStateFlags>( |
886 TabSpecificContentSettings::MICROPHONE_ACCESSED | | 915 TabSpecificContentSettings::MICROPHONE_ACCESSED | |
887 TabSpecificContentSettings::MICROPHONE_BLOCKED | | 916 TabSpecificContentSettings::MICROPHONE_BLOCKED | |
888 TabSpecificContentSettings::CAMERA_ACCESSED | | 917 TabSpecificContentSettings::CAMERA_ACCESSED | |
889 TabSpecificContentSettings::CAMERA_BLOCKED); | 918 TabSpecificContentSettings::CAMERA_BLOCKED); |
890 OnMediaStreamPermissionSet( | 919 OnMediaStreamPermissionSet( |
891 web_contents()->GetLastCommittedURL(), | 920 web_contents()->GetLastCommittedURL(), |
892 media_blocked, | 921 media_blocked, |
893 std::string(), std::string(), std::string(), std::string()); | 922 std::string(), std::string(), std::string(), std::string()); |
894 } | 923 } |
OLD | NEW |