| 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/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" | 14 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" |
| 14 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" | 15 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" |
| 15 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" | 16 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" |
| 16 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" | 17 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" |
| 17 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" | 18 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" |
| 18 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" | 19 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
| 19 #include "chrome/browser/browsing_data/cookies_tree_model.h" | 20 #include "chrome/browser/browsing_data/cookies_tree_model.h" |
| 20 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
| 21 #include "chrome/browser/content_settings/chrome_content_settings_utils.h" | 22 #include "chrome/browser/content_settings/chrome_content_settings_utils.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 int render_frame_id, | 231 int render_frame_id, |
| 231 const GURL& url, | 232 const GURL& url, |
| 232 bool blocked_by_policy) { | 233 bool blocked_by_policy) { |
| 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 234 TabSpecificContentSettings* settings = GetForFrame( | 235 TabSpecificContentSettings* settings = GetForFrame( |
| 235 render_process_id, render_frame_id); | 236 render_process_id, render_frame_id); |
| 236 if (settings) | 237 if (settings) |
| 237 settings->OnFileSystemAccessed(url, blocked_by_policy); | 238 settings->OnFileSystemAccessed(url, blocked_by_policy); |
| 238 } | 239 } |
| 239 | 240 |
| 241 const base::string16 TabSpecificContentSettings::GetBlockedPluginNames() const { |
| 242 return JoinString(blocked_plugin_names_, base::ASCIIToUTF16(", ")); |
| 243 } |
| 244 |
| 240 bool TabSpecificContentSettings::IsContentBlocked( | 245 bool TabSpecificContentSettings::IsContentBlocked( |
| 241 ContentSettingsType content_type) const { | 246 ContentSettingsType content_type) const { |
| 242 DCHECK(content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION) | 247 DCHECK(content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 243 << "Geolocation settings handled by ContentSettingGeolocationImageModel"; | 248 << "Geolocation settings handled by ContentSettingGeolocationImageModel"; |
| 244 DCHECK(content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS) | 249 DCHECK(content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS) |
| 245 << "Notifications settings handled by " | 250 << "Notifications settings handled by " |
| 246 << "ContentSettingsNotificationsImageModel"; | 251 << "ContentSettingsNotificationsImageModel"; |
| 247 | 252 |
| 248 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES || | 253 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES || |
| 249 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || | 254 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 content_type != CONTENT_SETTINGS_TYPE_PPAPI_BROKER && | 289 content_type != CONTENT_SETTINGS_TYPE_PPAPI_BROKER && |
| 285 content_type != CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS && | 290 content_type != CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS && |
| 286 content_type != CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { | 291 content_type != CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { |
| 287 return false; | 292 return false; |
| 288 } | 293 } |
| 289 | 294 |
| 290 return content_allowed_[content_type]; | 295 return content_allowed_[content_type]; |
| 291 } | 296 } |
| 292 | 297 |
| 293 void TabSpecificContentSettings::OnContentBlocked(ContentSettingsType type) { | 298 void TabSpecificContentSettings::OnContentBlocked(ContentSettingsType type) { |
| 299 OnContentBlockedWithDetail(type, base::string16()); |
| 300 } |
| 301 |
| 302 void TabSpecificContentSettings::OnContentBlockedWithDetail( |
| 303 ContentSettingsType type, |
| 304 const base::string16& details) { |
| 294 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) | 305 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 295 << "Geolocation settings handled by OnGeolocationPermissionSet"; | 306 << "Geolocation settings handled by OnGeolocationPermissionSet"; |
| 296 DCHECK(type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | 307 DCHECK(type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && |
| 297 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | 308 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) |
| 298 << "Media stream settings handled by OnMediaStreamPermissionSet"; | 309 << "Media stream settings handled by OnMediaStreamPermissionSet"; |
| 299 if (type < 0 || type >= CONTENT_SETTINGS_NUM_TYPES) | 310 if (type < 0 || type >= CONTENT_SETTINGS_NUM_TYPES) |
| 300 return; | 311 return; |
| 301 | 312 |
| 302 // TODO(robwu): Should this be restricted to cookies only? | 313 // TODO(robwu): Should this be restricted to cookies only? |
| 303 // In the past, content_allowed_ was set to false, but this logic was inverted | 314 // In the past, content_allowed_ was set to false, but this logic was inverted |
| 304 // in https://codereview.chromium.org/13375004 to fix an issue with the cookie | 315 // in https://codereview.chromium.org/13375004 to fix an issue with the cookie |
| 305 // permission UI. This unconditional assignment seems incorrect, because the | 316 // permission UI. This unconditional assignment seems incorrect, because the |
| 306 // flag will now always be true after calling either OnContentBlocked or | 317 // flag will now always be true after calling either OnContentBlocked or |
| 307 // OnContentAllowed. Consequently IsContentAllowed will always return true | 318 // OnContentAllowed. Consequently IsContentAllowed will always return true |
| 308 // for every supported setting that is not handled elsewhere. | 319 // for every supported setting that is not handled elsewhere. |
| 309 content_allowed_[type] = true; | 320 content_allowed_[type] = true; |
| 310 | 321 |
| 311 #if defined(OS_ANDROID) | 322 #if defined(OS_ANDROID) |
| 312 if (type == CONTENT_SETTINGS_TYPE_POPUPS) { | 323 if (type == CONTENT_SETTINGS_TYPE_POPUPS) { |
| 313 // For Android we do not have a persistent button that will always be | 324 // For Android we do not have a persistent button that will always be |
| 314 // visible for blocked popups. Instead we have info bars which could be | 325 // visible for blocked popups. Instead we have info bars which could be |
| 315 // dismissed. Have to clear the blocked state so we properly notify the | 326 // dismissed. Have to clear the blocked state so we properly notify the |
| 316 // relevant pieces again. | 327 // relevant pieces again. |
| 317 content_blocked_[type] = false; | 328 content_blocked_[type] = false; |
| 318 content_blockage_indicated_to_user_[type] = false; | 329 content_blockage_indicated_to_user_[type] = false; |
| 319 } | 330 } |
| 320 #endif | 331 #endif |
| 321 | 332 |
| 333 if (type == CONTENT_SETTINGS_TYPE_PLUGINS && !details.empty() && |
| 334 std::find(blocked_plugin_names_.begin(), blocked_plugin_names_.end(), |
| 335 details) == blocked_plugin_names_.end()) { |
| 336 blocked_plugin_names_.push_back(details); |
| 337 } |
| 338 |
| 322 if (!content_blocked_[type]) { | 339 if (!content_blocked_[type]) { |
| 323 content_blocked_[type] = true; | 340 content_blocked_[type] = true; |
| 324 // TODO: it would be nice to have a way of mocking this in tests. | 341 // TODO: it would be nice to have a way of mocking this in tests. |
| 325 content::NotificationService::current()->Notify( | 342 content::NotificationService::current()->Notify( |
| 326 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 343 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
| 327 content::Source<WebContents>(web_contents()), | 344 content::Source<WebContents>(web_contents()), |
| 328 content::NotificationService::NoDetails()); | 345 content::NotificationService::NoDetails()); |
| 329 | 346 |
| 330 if (type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { | 347 if (type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { |
| 331 content_settings::RecordMixedScriptAction( | 348 content_settings::RecordMixedScriptAction( |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 // page. | 708 // page. |
| 692 render_frame_host->Send(new ChromeViewMsg_SetAsInterstitial( | 709 render_frame_host->Send(new ChromeViewMsg_SetAsInterstitial( |
| 693 render_frame_host->GetRoutingID())); | 710 render_frame_host->GetRoutingID())); |
| 694 } | 711 } |
| 695 | 712 |
| 696 bool TabSpecificContentSettings::OnMessageReceived( | 713 bool TabSpecificContentSettings::OnMessageReceived( |
| 697 const IPC::Message& message, | 714 const IPC::Message& message, |
| 698 content::RenderFrameHost* render_frame_host) { | 715 content::RenderFrameHost* render_frame_host) { |
| 699 bool handled = true; | 716 bool handled = true; |
| 700 IPC_BEGIN_MESSAGE_MAP(TabSpecificContentSettings, message) | 717 IPC_BEGIN_MESSAGE_MAP(TabSpecificContentSettings, message) |
| 701 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ContentBlocked, OnContentBlocked) | 718 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ContentBlocked, |
| 719 OnContentBlockedWithDetail) |
| 702 IPC_MESSAGE_UNHANDLED(handled = false) | 720 IPC_MESSAGE_UNHANDLED(handled = false) |
| 703 IPC_END_MESSAGE_MAP() | 721 IPC_END_MESSAGE_MAP() |
| 704 return handled; | 722 return handled; |
| 705 } | 723 } |
| 706 | 724 |
| 707 void TabSpecificContentSettings::DidNavigateMainFrame( | 725 void TabSpecificContentSettings::DidNavigateMainFrame( |
| 708 const content::LoadCommittedDetails& details, | 726 const content::LoadCommittedDetails& details, |
| 709 const content::FrameNavigateParams& params) { | 727 const content::FrameNavigateParams& params) { |
| 710 if (!details.is_in_page) { | 728 if (!details.is_in_page) { |
| 711 // Clear "blocked" flags. | 729 // Clear "blocked" flags. |
| 712 ClearBlockedContentSettingsExceptForCookies(); | 730 ClearBlockedContentSettingsExceptForCookies(); |
| 731 blocked_plugin_names_.clear(); |
| 713 GeolocationDidNavigate(details); | 732 GeolocationDidNavigate(details); |
| 714 MidiDidNavigate(details); | 733 MidiDidNavigate(details); |
| 715 } | 734 } |
| 716 } | 735 } |
| 717 | 736 |
| 718 void TabSpecificContentSettings::DidStartProvisionalLoadForFrame( | 737 void TabSpecificContentSettings::DidStartProvisionalLoadForFrame( |
| 719 content::RenderFrameHost* render_frame_host, | 738 content::RenderFrameHost* render_frame_host, |
| 720 const GURL& validated_url, | 739 const GURL& validated_url, |
| 721 bool is_error_page, | 740 bool is_error_page, |
| 722 bool is_iframe_srcdoc) { | 741 bool is_iframe_srcdoc) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 | 787 |
| 769 void TabSpecificContentSettings::GeolocationDidNavigate( | 788 void TabSpecificContentSettings::GeolocationDidNavigate( |
| 770 const content::LoadCommittedDetails& details) { | 789 const content::LoadCommittedDetails& details) { |
| 771 geolocation_usages_state_.DidNavigate(details); | 790 geolocation_usages_state_.DidNavigate(details); |
| 772 } | 791 } |
| 773 | 792 |
| 774 void TabSpecificContentSettings::MidiDidNavigate( | 793 void TabSpecificContentSettings::MidiDidNavigate( |
| 775 const content::LoadCommittedDetails& details) { | 794 const content::LoadCommittedDetails& details) { |
| 776 midi_usages_state_.DidNavigate(details); | 795 midi_usages_state_.DidNavigate(details); |
| 777 } | 796 } |
| OLD | NEW |