Chromium Code Reviews| 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 int render_frame_id, | 230 int render_frame_id, |
| 231 const GURL& url, | 231 const GURL& url, |
| 232 bool blocked_by_policy) { | 232 bool blocked_by_policy) { |
| 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 234 TabSpecificContentSettings* settings = GetForFrame( | 234 TabSpecificContentSettings* settings = GetForFrame( |
| 235 render_process_id, render_frame_id); | 235 render_process_id, render_frame_id); |
| 236 if (settings) | 236 if (settings) |
| 237 settings->OnFileSystemAccessed(url, blocked_by_policy); | 237 settings->OnFileSystemAccessed(url, blocked_by_policy); |
| 238 } | 238 } |
| 239 | 239 |
| 240 const base::string16 TabSpecificContentSettings::blocked_plugin_names() const { | |
| 241 const base::string16 kComma = base::string16(base::ASCIIToUTF16(", ")); | |
|
Lei Zhang
2014/12/05 22:18:05
You don't need to call base::string16().
Will Harris
2014/12/08 00:21:11
Done.
| |
| 242 | |
| 243 base::string16 names; | |
| 244 base::hash_set<base::string16>::const_iterator it = | |
|
Lei Zhang
2014/12/05 22:18:05
You can probably just make this a C++11 Range-Base
Will Harris
2014/12/08 00:21:11
left using iterator as it's the fastest way to che
| |
| 245 blocked_plugin_names_.begin(); | |
| 246 while (it != blocked_plugin_names_.end()) { | |
| 247 names.append(*it); | |
| 248 it++; | |
|
Lei Zhang
2014/12/05 22:18:05
++it;
Will Harris
2014/12/08 00:21:11
Done.
| |
| 249 if (it != blocked_plugin_names_.end()) | |
| 250 names.append(kComma); | |
| 251 else | |
| 252 break; | |
| 253 } | |
| 254 | |
| 255 return names; | |
| 256 } | |
| 257 | |
| 240 bool TabSpecificContentSettings::IsContentBlocked( | 258 bool TabSpecificContentSettings::IsContentBlocked( |
| 241 ContentSettingsType content_type) const { | 259 ContentSettingsType content_type) const { |
| 242 DCHECK(content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION) | 260 DCHECK(content_type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 243 << "Geolocation settings handled by ContentSettingGeolocationImageModel"; | 261 << "Geolocation settings handled by ContentSettingGeolocationImageModel"; |
| 244 DCHECK(content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS) | 262 DCHECK(content_type != CONTENT_SETTINGS_TYPE_NOTIFICATIONS) |
| 245 << "Notifications settings handled by " | 263 << "Notifications settings handled by " |
| 246 << "ContentSettingsNotificationsImageModel"; | 264 << "ContentSettingsNotificationsImageModel"; |
| 247 | 265 |
| 248 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES || | 266 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES || |
| 249 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || | 267 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 && | 302 content_type != CONTENT_SETTINGS_TYPE_PPAPI_BROKER && |
| 285 content_type != CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS && | 303 content_type != CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS && |
| 286 content_type != CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { | 304 content_type != CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { |
| 287 return false; | 305 return false; |
| 288 } | 306 } |
| 289 | 307 |
| 290 return content_allowed_[content_type]; | 308 return content_allowed_[content_type]; |
| 291 } | 309 } |
| 292 | 310 |
| 293 void TabSpecificContentSettings::OnContentBlocked(ContentSettingsType type) { | 311 void TabSpecificContentSettings::OnContentBlocked(ContentSettingsType type) { |
| 312 OnContentBlockedWithDetail(type, base::string16()); | |
| 313 } | |
| 314 | |
| 315 void TabSpecificContentSettings::OnContentBlockedWithDetail( | |
| 316 ContentSettingsType type, | |
| 317 const base::string16& details) { | |
| 294 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) | 318 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION) |
| 295 << "Geolocation settings handled by OnGeolocationPermissionSet"; | 319 << "Geolocation settings handled by OnGeolocationPermissionSet"; |
| 296 DCHECK(type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && | 320 DCHECK(type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC && |
| 297 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) | 321 type != CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) |
| 298 << "Media stream settings handled by OnMediaStreamPermissionSet"; | 322 << "Media stream settings handled by OnMediaStreamPermissionSet"; |
| 299 if (type < 0 || type >= CONTENT_SETTINGS_NUM_TYPES) | 323 if (type < 0 || type >= CONTENT_SETTINGS_NUM_TYPES) |
| 300 return; | 324 return; |
| 301 | 325 |
| 302 // TODO(robwu): Should this be restricted to cookies only? | 326 // TODO(robwu): Should this be restricted to cookies only? |
| 303 // In the past, content_allowed_ was set to false, but this logic was inverted | 327 // 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 | 328 // in https://codereview.chromium.org/13375004 to fix an issue with the cookie |
| 305 // permission UI. This unconditional assignment seems incorrect, because the | 329 // permission UI. This unconditional assignment seems incorrect, because the |
| 306 // flag will now always be true after calling either OnContentBlocked or | 330 // flag will now always be true after calling either OnContentBlocked or |
| 307 // OnContentAllowed. Consequently IsContentAllowed will always return true | 331 // OnContentAllowed. Consequently IsContentAllowed will always return true |
| 308 // for every supported setting that is not handled elsewhere. | 332 // for every supported setting that is not handled elsewhere. |
| 309 content_allowed_[type] = true; | 333 content_allowed_[type] = true; |
| 310 | 334 |
| 311 #if defined(OS_ANDROID) | 335 #if defined(OS_ANDROID) |
| 312 if (type == CONTENT_SETTINGS_TYPE_POPUPS) { | 336 if (type == CONTENT_SETTINGS_TYPE_POPUPS) { |
| 313 // For Android we do not have a persistent button that will always be | 337 // 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 | 338 // 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 | 339 // dismissed. Have to clear the blocked state so we properly notify the |
| 316 // relevant pieces again. | 340 // relevant pieces again. |
| 317 content_blocked_[type] = false; | 341 content_blocked_[type] = false; |
| 318 content_blockage_indicated_to_user_[type] = false; | 342 content_blockage_indicated_to_user_[type] = false; |
| 319 } | 343 } |
| 320 #endif | 344 #endif |
| 321 | 345 |
| 346 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) { | |
| 347 blocked_plugin_names_.insert(details); | |
| 348 } | |
| 349 | |
| 322 if (!content_blocked_[type]) { | 350 if (!content_blocked_[type]) { |
| 323 content_blocked_[type] = true; | 351 content_blocked_[type] = true; |
| 324 // TODO: it would be nice to have a way of mocking this in tests. | 352 // TODO: it would be nice to have a way of mocking this in tests. |
| 325 content::NotificationService::current()->Notify( | 353 content::NotificationService::current()->Notify( |
| 326 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 354 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
| 327 content::Source<WebContents>(web_contents()), | 355 content::Source<WebContents>(web_contents()), |
| 328 content::NotificationService::NoDetails()); | 356 content::NotificationService::NoDetails()); |
| 329 | 357 |
| 330 if (type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { | 358 if (type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { |
| 331 content_settings::RecordMixedScriptAction( | 359 content_settings::RecordMixedScriptAction( |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 691 // page. | 719 // page. |
| 692 render_frame_host->Send(new ChromeViewMsg_SetAsInterstitial( | 720 render_frame_host->Send(new ChromeViewMsg_SetAsInterstitial( |
| 693 render_frame_host->GetRoutingID())); | 721 render_frame_host->GetRoutingID())); |
| 694 } | 722 } |
| 695 | 723 |
| 696 bool TabSpecificContentSettings::OnMessageReceived( | 724 bool TabSpecificContentSettings::OnMessageReceived( |
| 697 const IPC::Message& message, | 725 const IPC::Message& message, |
| 698 content::RenderFrameHost* render_frame_host) { | 726 content::RenderFrameHost* render_frame_host) { |
| 699 bool handled = true; | 727 bool handled = true; |
| 700 IPC_BEGIN_MESSAGE_MAP(TabSpecificContentSettings, message) | 728 IPC_BEGIN_MESSAGE_MAP(TabSpecificContentSettings, message) |
| 701 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ContentBlocked, OnContentBlocked) | 729 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ContentBlocked, |
|
Lei Zhang
2014/12/05 22:18:05
Is OnContentBlocked() still used?
Will Harris
2014/12/08 00:21:11
used by the tests
Lei Zhang
2014/12/08 20:08:19
If it's the case that only tests call it, it's pro
Will Harris
2014/12/08 21:11:46
Actually, changing the default function signature
| |
| 730 OnContentBlockedWithDetail) | |
| 702 IPC_MESSAGE_UNHANDLED(handled = false) | 731 IPC_MESSAGE_UNHANDLED(handled = false) |
| 703 IPC_END_MESSAGE_MAP() | 732 IPC_END_MESSAGE_MAP() |
| 704 return handled; | 733 return handled; |
| 705 } | 734 } |
| 706 | 735 |
| 707 void TabSpecificContentSettings::DidNavigateMainFrame( | 736 void TabSpecificContentSettings::DidNavigateMainFrame( |
| 708 const content::LoadCommittedDetails& details, | 737 const content::LoadCommittedDetails& details, |
| 709 const content::FrameNavigateParams& params) { | 738 const content::FrameNavigateParams& params) { |
| 710 if (!details.is_in_page) { | 739 if (!details.is_in_page) { |
| 711 // Clear "blocked" flags. | 740 // Clear "blocked" flags. |
| 712 ClearBlockedContentSettingsExceptForCookies(); | 741 ClearBlockedContentSettingsExceptForCookies(); |
| 742 blocked_plugin_names_.clear(); | |
| 713 GeolocationDidNavigate(details); | 743 GeolocationDidNavigate(details); |
| 714 MidiDidNavigate(details); | 744 MidiDidNavigate(details); |
| 715 } | 745 } |
| 716 } | 746 } |
| 717 | 747 |
| 718 void TabSpecificContentSettings::DidStartProvisionalLoadForFrame( | 748 void TabSpecificContentSettings::DidStartProvisionalLoadForFrame( |
| 719 content::RenderFrameHost* render_frame_host, | 749 content::RenderFrameHost* render_frame_host, |
| 720 const GURL& validated_url, | 750 const GURL& validated_url, |
| 721 bool is_error_page, | 751 bool is_error_page, |
| 722 bool is_iframe_srcdoc) { | 752 bool is_iframe_srcdoc) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 768 | 798 |
| 769 void TabSpecificContentSettings::GeolocationDidNavigate( | 799 void TabSpecificContentSettings::GeolocationDidNavigate( |
| 770 const content::LoadCommittedDetails& details) { | 800 const content::LoadCommittedDetails& details) { |
| 771 geolocation_usages_state_.DidNavigate(details); | 801 geolocation_usages_state_.DidNavigate(details); |
| 772 } | 802 } |
| 773 | 803 |
| 774 void TabSpecificContentSettings::MidiDidNavigate( | 804 void TabSpecificContentSettings::MidiDidNavigate( |
| 775 const content::LoadCommittedDetails& details) { | 805 const content::LoadCommittedDetails& details) { |
| 776 midi_usages_state_.DidNavigate(details); | 806 midi_usages_state_.DidNavigate(details); |
| 777 } | 807 } |
| OLD | NEW |