| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 CONTENT_SETTINGS_TYPE_GEOLOCATION), | 98 CONTENT_SETTINGS_TYPE_GEOLOCATION), |
| 99 midi_usages_state_( | 99 midi_usages_state_( |
| 100 HostContentSettingsMapFactory::GetForProfile( | 100 HostContentSettingsMapFactory::GetForProfile( |
| 101 Profile::FromBrowserContext(tab->GetBrowserContext())), | 101 Profile::FromBrowserContext(tab->GetBrowserContext())), |
| 102 CONTENT_SETTINGS_TYPE_MIDI_SYSEX), | 102 CONTENT_SETTINGS_TYPE_MIDI_SYSEX), |
| 103 pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), | 103 pending_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), |
| 104 previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), | 104 previous_protocol_handler_(ProtocolHandler::EmptyProtocolHandler()), |
| 105 pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT), | 105 pending_protocol_handler_setting_(CONTENT_SETTING_DEFAULT), |
| 106 load_plugins_link_enabled_(true), | 106 load_plugins_link_enabled_(true), |
| 107 microphone_camera_state_(MICROPHONE_CAMERA_NOT_ACCESSED), | 107 microphone_camera_state_(MICROPHONE_CAMERA_NOT_ACCESSED), |
| 108 subresource_filter_enabled_(false), | |
| 109 subresource_filter_blockage_indicated_(false), | |
| 110 observer_(this) { | 108 observer_(this) { |
| 111 ClearContentSettingsExceptForNavigationRelatedSettings(); | 109 ClearContentSettingsExceptForNavigationRelatedSettings(); |
| 112 ClearNavigationRelatedContentSettings(); | 110 ClearNavigationRelatedContentSettings(); |
| 113 | 111 |
| 114 observer_.Add(HostContentSettingsMapFactory::GetForProfile( | 112 observer_.Add(HostContentSettingsMapFactory::GetForProfile( |
| 115 Profile::FromBrowserContext(tab->GetBrowserContext()))); | 113 Profile::FromBrowserContext(tab->GetBrowserContext()))); |
| 116 } | 114 } |
| 117 | 115 |
| 118 TabSpecificContentSettings::~TabSpecificContentSettings() { | 116 TabSpecificContentSettings::~TabSpecificContentSettings() { |
| 119 for (SiteDataObserver& observer : observer_list_) | 117 for (SiteDataObserver& observer : observer_list_) |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 241 |
| 244 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES || | 242 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES || |
| 245 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || | 243 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || |
| 246 content_type == CONTENT_SETTINGS_TYPE_PLUGINS || | 244 content_type == CONTENT_SETTINGS_TYPE_PLUGINS || |
| 247 content_type == CONTENT_SETTINGS_TYPE_COOKIES || | 245 content_type == CONTENT_SETTINGS_TYPE_COOKIES || |
| 248 content_type == CONTENT_SETTINGS_TYPE_POPUPS || | 246 content_type == CONTENT_SETTINGS_TYPE_POPUPS || |
| 249 content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT || | 247 content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT || |
| 250 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || | 248 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC || |
| 251 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA || | 249 content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA || |
| 252 content_type == CONTENT_SETTINGS_TYPE_PPAPI_BROKER || | 250 content_type == CONTENT_SETTINGS_TYPE_PPAPI_BROKER || |
| 253 content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { | 251 content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX || |
| 252 content_type == CONTENT_SETTINGS_TYPE_SUBRESOURCE_FILTER) { |
| 254 const auto& it = content_settings_status_.find(content_type); | 253 const auto& it = content_settings_status_.find(content_type); |
| 255 if (it != content_settings_status_.end()) | 254 if (it != content_settings_status_.end()) |
| 256 return it->second.blocked; | 255 return it->second.blocked; |
| 257 } | 256 } |
| 258 | 257 |
| 259 return false; | 258 return false; |
| 260 } | 259 } |
| 261 | 260 |
| 262 bool TabSpecificContentSettings::IsSubresourceBlocked() const { | |
| 263 return subresource_filter_enabled_; | |
| 264 } | |
| 265 | |
| 266 bool TabSpecificContentSettings::IsBlockageIndicated( | 261 bool TabSpecificContentSettings::IsBlockageIndicated( |
| 267 ContentSettingsType content_type) const { | 262 ContentSettingsType content_type) const { |
| 268 const auto& it = content_settings_status_.find(content_type); | 263 const auto& it = content_settings_status_.find(content_type); |
| 269 if (it != content_settings_status_.end()) | 264 if (it != content_settings_status_.end()) |
| 270 return it->second.blockage_indicated_to_user; | 265 return it->second.blockage_indicated_to_user; |
| 271 return false; | 266 return false; |
| 272 } | 267 } |
| 273 | 268 |
| 274 bool TabSpecificContentSettings::IsSubresourceBlockageIndicated() const { | |
| 275 return subresource_filter_blockage_indicated_; | |
| 276 } | |
| 277 | |
| 278 void TabSpecificContentSettings::SetBlockageHasBeenIndicated( | 269 void TabSpecificContentSettings::SetBlockageHasBeenIndicated( |
| 279 ContentSettingsType content_type) { | 270 ContentSettingsType content_type) { |
| 280 content_settings_status_[content_type].blockage_indicated_to_user = true; | 271 content_settings_status_[content_type].blockage_indicated_to_user = true; |
| 281 } | 272 } |
| 282 | 273 |
| 283 void TabSpecificContentSettings::SetSubresourceBlockageIndicated() { | |
| 284 subresource_filter_blockage_indicated_ = true; | |
| 285 } | |
| 286 | |
| 287 bool TabSpecificContentSettings::IsContentAllowed( | 274 bool TabSpecificContentSettings::IsContentAllowed( |
| 288 ContentSettingsType content_type) const { | 275 ContentSettingsType content_type) const { |
| 289 DCHECK_NE(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, content_type) | 276 DCHECK_NE(CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, content_type) |
| 290 << "Automatic downloads handled by DownloadRequestLimiter"; | 277 << "Automatic downloads handled by DownloadRequestLimiter"; |
| 291 | 278 |
| 292 // This method currently only returns meaningful values for the content type | 279 // This method currently only returns meaningful values for the content type |
| 293 // cookies, media, PPAPI broker, downloads, and MIDI sysex. | 280 // cookies, media, PPAPI broker, downloads, and MIDI sysex. |
| 294 if (content_type != CONTENT_SETTINGS_TYPE_COOKIES && | 281 if (content_type != CONTENT_SETTINGS_TYPE_COOKIES && |
| 295 content_type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | 282 content_type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && |
| 296 content_type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA && | 283 content_type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA && |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 ContentSettingsStatus& status = | 690 ContentSettingsStatus& status = |
| 704 content_settings_status_[CONTENT_SETTINGS_TYPE_POPUPS]; | 691 content_settings_status_[CONTENT_SETTINGS_TYPE_POPUPS]; |
| 705 status.blocked = blocked; | 692 status.blocked = blocked; |
| 706 status.blockage_indicated_to_user = false; | 693 status.blockage_indicated_to_user = false; |
| 707 content::NotificationService::current()->Notify( | 694 content::NotificationService::current()->Notify( |
| 708 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 695 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
| 709 content::Source<WebContents>(web_contents()), | 696 content::Source<WebContents>(web_contents()), |
| 710 content::NotificationService::NoDetails()); | 697 content::NotificationService::NoDetails()); |
| 711 } | 698 } |
| 712 | 699 |
| 713 void TabSpecificContentSettings::SetSubresourceBlocked(bool enabled) { | |
| 714 subresource_filter_enabled_ = enabled; | |
| 715 } | |
| 716 | |
| 717 void TabSpecificContentSettings::SetPepperBrokerAllowed(bool allowed) { | 700 void TabSpecificContentSettings::SetPepperBrokerAllowed(bool allowed) { |
| 718 if (allowed) { | 701 if (allowed) { |
| 719 OnContentAllowed(CONTENT_SETTINGS_TYPE_PPAPI_BROKER); | 702 OnContentAllowed(CONTENT_SETTINGS_TYPE_PPAPI_BROKER); |
| 720 } else { | 703 } else { |
| 721 OnContentBlocked(CONTENT_SETTINGS_TYPE_PPAPI_BROKER); | 704 OnContentBlocked(CONTENT_SETTINGS_TYPE_PPAPI_BROKER); |
| 722 } | 705 } |
| 723 } | 706 } |
| 724 | 707 |
| 725 void TabSpecificContentSettings::OnContentSettingChanged( | 708 void TabSpecificContentSettings::OnContentSettingChanged( |
| 726 const ContentSettingsPattern& primary_pattern, | 709 const ContentSettingsPattern& primary_pattern, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 static_cast<MicrophoneCameraStateFlags>( | 885 static_cast<MicrophoneCameraStateFlags>( |
| 903 TabSpecificContentSettings::MICROPHONE_ACCESSED | | 886 TabSpecificContentSettings::MICROPHONE_ACCESSED | |
| 904 TabSpecificContentSettings::MICROPHONE_BLOCKED | | 887 TabSpecificContentSettings::MICROPHONE_BLOCKED | |
| 905 TabSpecificContentSettings::CAMERA_ACCESSED | | 888 TabSpecificContentSettings::CAMERA_ACCESSED | |
| 906 TabSpecificContentSettings::CAMERA_BLOCKED); | 889 TabSpecificContentSettings::CAMERA_BLOCKED); |
| 907 OnMediaStreamPermissionSet( | 890 OnMediaStreamPermissionSet( |
| 908 web_contents()->GetLastCommittedURL(), | 891 web_contents()->GetLastCommittedURL(), |
| 909 media_blocked, | 892 media_blocked, |
| 910 std::string(), std::string(), std::string(), std::string()); | 893 std::string(), std::string(), std::string(), std::string()); |
| 911 } | 894 } |
| OLD | NEW |