Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: chrome/browser/host_content_settings_map.cc

Issue 4643007: Move click-to-play to about:flags. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/host_content_settings_map.h" 5 #include "chrome/browser/host_content_settings_map.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/browser_thread.h" 10 #include "chrome/browser/browser_thread.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // true for various internal objects like chrome:// URLs, so UI and other 93 // true for various internal objects like chrome:// URLs, so UI and other
94 // things users think of as "not webpages" don't break. 94 // things users think of as "not webpages" don't break.
95 static bool ShouldAllowAllContent(const GURL& url) { 95 static bool ShouldAllowAllContent(const GURL& url) {
96 return url.SchemeIs(chrome::kChromeDevToolsScheme) || 96 return url.SchemeIs(chrome::kChromeDevToolsScheme) ||
97 url.SchemeIs(chrome::kChromeInternalScheme) || 97 url.SchemeIs(chrome::kChromeInternalScheme) ||
98 url.SchemeIs(chrome::kChromeUIScheme) || 98 url.SchemeIs(chrome::kChromeUIScheme) ||
99 url.SchemeIs(chrome::kExtensionScheme) || 99 url.SchemeIs(chrome::kExtensionScheme) ||
100 url.SchemeIs(chrome::kGearsScheme) || 100 url.SchemeIs(chrome::kGearsScheme) ||
101 url.SchemeIs(chrome::kUserScriptScheme); 101 url.SchemeIs(chrome::kUserScriptScheme);
102 } 102 }
103
104 // Map ASK for the plugins content type to BLOCK if click-to-play is
105 // not enabled.
106 ContentSetting ClickToPlayFixup(ContentSettingsType content_type,
107 ContentSetting setting) {
108 if (setting == CONTENT_SETTING_ASK &&
109 content_type == CONTENT_SETTINGS_TYPE_PLUGINS &&
110 !CommandLine::ForCurrentProcess()->HasSwitch(
111 switches::kEnableClickToPlay)) {
112 return CONTENT_SETTING_BLOCK;
113 }
114 return setting;
115 }
116
103 } // namespace 117 } // namespace
104 118
105 119
106 struct HostContentSettingsMap::ExtendedContentSettings { 120 struct HostContentSettingsMap::ExtendedContentSettings {
107 ContentSettings content_settings; 121 ContentSettings content_settings;
108 ResourceContentSettings content_settings_for_resources; 122 ResourceContentSettings content_settings_for_resources;
109 }; 123 };
110 124
111 // static 125 // static
112 HostContentSettingsMap::Pattern HostContentSettingsMap::Pattern::FromURL( 126 HostContentSettingsMap::Pattern HostContentSettingsMap::Pattern::FromURL(
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 settings->push_back(std::make_pair(Pattern(i->first), setting)); 439 settings->push_back(std::make_pair(Pattern(i->first), setting));
426 } 440 }
427 } 441 }
428 } 442 }
429 443
430 void HostContentSettingsMap::SetDefaultContentSetting( 444 void HostContentSettingsMap::SetDefaultContentSetting(
431 ContentSettingsType content_type, 445 ContentSettingsType content_type,
432 ContentSetting setting) { 446 ContentSetting setting) {
433 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. 447 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation.
434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
449 DCHECK(content_type != CONTENT_SETTINGS_TYPE_PLUGINS ||
450 setting != CONTENT_SETTING_ASK ||
451 CommandLine::ForCurrentProcess()->HasSwitch(
452 switches::kEnableClickToPlay));
435 PrefService* prefs = profile_->GetPrefs(); 453 PrefService* prefs = profile_->GetPrefs();
436 454
437 // The default settings may not be directly modified for OTR sessions. 455 // The default settings may not be directly modified for OTR sessions.
438 // Instead, they are synced to the main profile's setting. 456 // Instead, they are synced to the main profile's setting.
439 if (is_off_the_record_) { 457 if (is_off_the_record_) {
440 NOTREACHED(); 458 NOTREACHED();
441 return; 459 return;
442 } 460 }
443 461
444 DictionaryValue* default_settings_dictionary = 462 DictionaryValue* default_settings_dictionary =
(...skipping 22 matching lines...) Expand all
467 485
468 void HostContentSettingsMap::SetContentSetting( 486 void HostContentSettingsMap::SetContentSetting(
469 const Pattern& original_pattern, 487 const Pattern& original_pattern,
470 ContentSettingsType content_type, 488 ContentSettingsType content_type,
471 const std::string& resource_identifier, 489 const std::string& resource_identifier,
472 ContentSetting setting) { 490 ContentSetting setting) {
473 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. 491 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation.
474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
475 DCHECK_NE(RequiresResourceIdentifier(content_type), 493 DCHECK_NE(RequiresResourceIdentifier(content_type),
476 resource_identifier.empty()); 494 resource_identifier.empty());
495 DCHECK(content_type != CONTENT_SETTINGS_TYPE_PLUGINS ||
496 setting != CONTENT_SETTING_ASK ||
497 CommandLine::ForCurrentProcess()->HasSwitch(
498 switches::kEnableClickToPlay));
477 499
478 const Pattern pattern(original_pattern.CanonicalizePattern()); 500 const Pattern pattern(original_pattern.CanonicalizePattern());
479 501
480 bool early_exit = false; 502 bool early_exit = false;
481 std::string pattern_str(pattern.AsString()); 503 std::string pattern_str(pattern.AsString());
482 PrefService* prefs = NULL; 504 PrefService* prefs = NULL;
483 DictionaryValue* all_settings_dictionary = NULL; 505 DictionaryValue* all_settings_dictionary = NULL;
484 HostContentSettings* map_to_modify = &off_the_record_settings_; 506 HostContentSettings* map_to_modify = &off_the_record_settings_;
485 if (!is_off_the_record_) { 507 if (!is_off_the_record_) {
486 prefs = profile_->GetPrefs(); 508 prefs = profile_->GetPrefs();
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 DCHECK(found); 811 DCHECK(found);
790 settings->settings[type] = IntToContentSetting(setting); 812 settings->settings[type] = IntToContentSetting(setting);
791 break; 813 break;
792 } 814 }
793 } 815 }
794 } 816 }
795 // Migrate obsolete cookie prompt mode. 817 // Migrate obsolete cookie prompt mode.
796 if (settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] == 818 if (settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] ==
797 CONTENT_SETTING_ASK) 819 CONTENT_SETTING_ASK)
798 settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK; 820 settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK;
821
822 settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS] =
823 ClickToPlayFixup(CONTENT_SETTINGS_TYPE_PLUGINS,
824 settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS]);
799 } 825 }
800 826
801 void HostContentSettingsMap::GetResourceSettingsFromDictionary( 827 void HostContentSettingsMap::GetResourceSettingsFromDictionary(
802 const DictionaryValue* dictionary, 828 const DictionaryValue* dictionary,
803 ResourceContentSettings* settings) { 829 ResourceContentSettings* settings) {
804 for (DictionaryValue::key_iterator i(dictionary->begin_keys()); 830 for (DictionaryValue::key_iterator i(dictionary->begin_keys());
805 i != dictionary->end_keys(); ++i) { 831 i != dictionary->end_keys(); ++i) {
806 const std::string& content_type(*i); 832 const std::string& content_type(*i);
807 for (size_t type = 0; type < arraysize(kResourceTypeNames); ++type) { 833 for (size_t type = 0; type < arraysize(kResourceTypeNames); ++type) {
808 if ((kResourceTypeNames[type] != NULL) && 834 if ((kResourceTypeNames[type] != NULL) &&
809 (kResourceTypeNames[type] == content_type)) { 835 (kResourceTypeNames[type] == content_type)) {
810 DictionaryValue* resource_dictionary = NULL; 836 DictionaryValue* resource_dictionary = NULL;
811 bool found = dictionary->GetDictionary(content_type, 837 bool found = dictionary->GetDictionary(content_type,
812 &resource_dictionary); 838 &resource_dictionary);
813 DCHECK(found); 839 DCHECK(found);
814 for (DictionaryValue::key_iterator j(resource_dictionary->begin_keys()); 840 for (DictionaryValue::key_iterator j(resource_dictionary->begin_keys());
815 j != resource_dictionary->end_keys(); ++j) { 841 j != resource_dictionary->end_keys(); ++j) {
816 const std::string& resource_identifier(*j); 842 const std::string& resource_identifier(*j);
817 int setting = CONTENT_SETTING_DEFAULT; 843 int setting = CONTENT_SETTING_DEFAULT;
818 bool found = resource_dictionary->GetIntegerWithoutPathExpansion( 844 bool found = resource_dictionary->GetIntegerWithoutPathExpansion(
819 resource_identifier, &setting); 845 resource_identifier, &setting);
820 DCHECK(found); 846 DCHECK(found);
821 (*settings)[ContentSettingsTypeResourceIdentifierPair( 847 (*settings)[ContentSettingsTypeResourceIdentifierPair(
822 ContentSettingsType(type), resource_identifier)] = 848 ContentSettingsType(type), resource_identifier)] =
823 ContentSetting(setting); 849 ClickToPlayFixup(ContentSettingsType(type),
850 ContentSetting(setting));
824 } 851 }
825 852
826 break; 853 break;
827 } 854 }
828 } 855 }
829 } 856 }
830 } 857 }
831 858
832 void HostContentSettingsMap::ForceDefaultsToBeExplicit() { 859 void HostContentSettingsMap::ForceDefaultsToBeExplicit() {
833 DCHECK_EQ(arraysize(kDefaultSettings), 860 DCHECK_EQ(arraysize(kDefaultSettings),
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 } 1033 }
1007 1034
1008 for (size_t i = 0; i < move_items.size(); ++i) { 1035 for (size_t i = 0; i < move_items.size(); ++i) {
1009 Value* pattern_settings_dictionary = NULL; 1036 Value* pattern_settings_dictionary = NULL;
1010 all_settings_dictionary->RemoveWithoutPathExpansion( 1037 all_settings_dictionary->RemoveWithoutPathExpansion(
1011 move_items[i].first, &pattern_settings_dictionary); 1038 move_items[i].first, &pattern_settings_dictionary);
1012 all_settings_dictionary->SetWithoutPathExpansion( 1039 all_settings_dictionary->SetWithoutPathExpansion(
1013 move_items[i].second, pattern_settings_dictionary); 1040 move_items[i].second, pattern_settings_dictionary);
1014 } 1041 }
1015 } 1042 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/options/content_filter_page_gtk.cc ('k') | chrome/browser/host_content_settings_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698