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