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

Side by Side Diff: chrome/browser/extensions/extension_prefs.cc

Issue 10704023: Moved ExtensionPrefs and related into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 months 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
OLDNEW
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/extensions/extension_prefs.h" 5 #include "chrome/browser/extensions/extension_prefs.h"
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.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/extensions/admin_policy.h" 10 #include "chrome/browser/extensions/admin_policy.h"
11 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" 11 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
12 #include "chrome/browser/extensions/extension_menu_manager.h" 12 #include "chrome/browser/extensions/extension_menu_manager.h"
13 #include "chrome/browser/extensions/extension_pref_store.h" 13 #include "chrome/browser/extensions/extension_pref_store.h"
14 #include "chrome/browser/extensions/extension_sorting.h" 14 #include "chrome/browser/extensions/extension_sorting.h"
15 #include "chrome/browser/prefs/pref_notifier.h" 15 #include "chrome/browser/prefs/pref_notifier.h"
16 #include "chrome/browser/prefs/pref_service.h" 16 #include "chrome/browser/prefs/pref_service.h"
17 #include "chrome/browser/prefs/scoped_user_pref_update.h" 17 #include "chrome/browser/prefs/scoped_user_pref_update.h"
18 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/common/extensions/extension_switch_utils.h" 19 #include "chrome/common/extensions/extension_switch_utils.h"
20 #include "chrome/common/extensions/manifest.h" 20 #include "chrome/common/extensions/manifest.h"
21 #include "chrome/common/extensions/permissions/permissions_info.h" 21 #include "chrome/common/extensions/permissions/permissions_info.h"
22 #include "chrome/common/extensions/url_pattern.h" 22 #include "chrome/common/extensions/url_pattern.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
25 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
26 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
27 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
28 28
29 using extensions::APIPermission; 29 namespace extensions {
30 using extensions::APIPermissionSet;
31 using extensions::Extension;
32 using extensions::ExtensionInfo;
33 using extensions::OAuth2Scopes;
34 using extensions::PermissionsInfo;
35 using extensions::PermissionSet;
36 30
37 namespace { 31 namespace {
38 32
39 // Additional preferences keys 33 // Additional preferences keys
40 34
41 // Where an extension was installed from. (see Extension::Location) 35 // Where an extension was installed from. (see Extension::Location)
42 const char kPrefLocation[] = "location"; 36 const char kPrefLocation[] = "location";
43 37
44 // Enabled, disabled, killed, etc. (see Extension::State) 38 // Enabled, disabled, killed, etc. (see Extension::State)
45 const char kPrefState[] = "state"; 39 const char kPrefState[] = "state";
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 267
274 ExtensionPrefs::ExtensionPrefs( 268 ExtensionPrefs::ExtensionPrefs(
275 PrefService* prefs, 269 PrefService* prefs,
276 const FilePath& root_dir, 270 const FilePath& root_dir,
277 ExtensionPrefValueMap* extension_pref_value_map) 271 ExtensionPrefValueMap* extension_pref_value_map)
278 : prefs_(prefs), 272 : prefs_(prefs),
279 install_directory_(root_dir), 273 install_directory_(root_dir),
280 extension_pref_value_map_(extension_pref_value_map), 274 extension_pref_value_map_(extension_pref_value_map),
281 ALLOW_THIS_IN_INITIALIZER_LIST(extension_sorting_( 275 ALLOW_THIS_IN_INITIALIZER_LIST(extension_sorting_(
282 new ExtensionSorting(this, prefs))), 276 new ExtensionSorting(this, prefs))),
283 content_settings_store_(new extensions::ContentSettingsStore()) { 277 content_settings_store_(new ContentSettingsStore()) {
284 } 278 }
285 279
286 ExtensionPrefs::~ExtensionPrefs() { 280 ExtensionPrefs::~ExtensionPrefs() {
287 } 281 }
288 282
289 void ExtensionPrefs::Init(bool extensions_disabled) { 283 void ExtensionPrefs::Init(bool extensions_disabled) {
290 MakePathsRelative(); 284 MakePathsRelative();
291 285
292 InitPrefStore(extensions_disabled); 286 InitPrefStore(extensions_disabled);
293 287
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 659
666 std::string ExtensionPrefs::GetDebugPolicyProviderName() const { 660 std::string ExtensionPrefs::GetDebugPolicyProviderName() const {
667 #ifdef NDEBUG 661 #ifdef NDEBUG
668 NOTREACHED(); 662 NOTREACHED();
669 return std::string(); 663 return std::string();
670 #else 664 #else
671 return "admin policy black/white/forcelist, via the ExtensionPrefs"; 665 return "admin policy black/white/forcelist, via the ExtensionPrefs";
672 #endif 666 #endif
673 } 667 }
674 668
675 bool ExtensionPrefs::UserMayLoad(const extensions::Extension* extension, 669 bool ExtensionPrefs::UserMayLoad(const Extension* extension,
676 string16* error) const { 670 string16* error) const {
677 671
678 const base::ListValue* blacklist = 672 const base::ListValue* blacklist =
679 prefs_->GetList(prefs::kExtensionInstallDenyList); 673 prefs_->GetList(prefs::kExtensionInstallDenyList);
680 const base::ListValue* whitelist = 674 const base::ListValue* whitelist =
681 prefs_->GetList(prefs::kExtensionInstallAllowList); 675 prefs_->GetList(prefs::kExtensionInstallAllowList);
682 return extensions::admin_policy::UserMayLoad(blacklist, whitelist, extension, 676 return admin_policy::UserMayLoad(blacklist, whitelist, extension,
683 error); 677 error);
684 } 678 }
685 679
686 bool ExtensionPrefs::UserMayModifySettings(const Extension* extension, 680 bool ExtensionPrefs::UserMayModifySettings(const Extension* extension,
687 string16* error) const { 681 string16* error) const {
688 return extensions::admin_policy::UserMayModifySettings(extension, error); 682 return admin_policy::UserMayModifySettings(extension, error);
689 } 683 }
690 684
691 bool ExtensionPrefs::MustRemainEnabled(const Extension* extension, 685 bool ExtensionPrefs::MustRemainEnabled(const Extension* extension,
692 string16* error) const { 686 string16* error) const {
693 return extensions::admin_policy::MustRemainEnabled(extension, error); 687 return admin_policy::MustRemainEnabled(extension, error);
694 } 688 }
695 689
696 bool ExtensionPrefs::ExtensionsBlacklistedByDefault() const { 690 bool ExtensionPrefs::ExtensionsBlacklistedByDefault() const {
697 return extensions::admin_policy::BlacklistedByDefault( 691 return admin_policy::BlacklistedByDefault(
698 prefs_->GetList(prefs::kExtensionInstallDenyList)); 692 prefs_->GetList(prefs::kExtensionInstallDenyList));
699 } 693 }
700 694
701 bool ExtensionPrefs::DidExtensionEscalatePermissions( 695 bool ExtensionPrefs::DidExtensionEscalatePermissions(
702 const std::string& extension_id) { 696 const std::string& extension_id) {
703 return ReadExtensionPrefBoolean(extension_id, 697 return ReadExtensionPrefBoolean(extension_id,
704 kExtensionDidEscalatePermissions); 698 kExtensionDidEscalatePermissions);
705 } 699 }
706 700
707 void ExtensionPrefs::SetDidExtensionEscalatePermissions( 701 void ExtensionPrefs::SetDidExtensionEscalatePermissions(
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 void ExtensionPrefs::SetRegisteredEvents( 1040 void ExtensionPrefs::SetRegisteredEvents(
1047 const std::string& extension_id, const std::set<std::string>& events) { 1041 const std::string& extension_id, const std::set<std::string>& events) {
1048 ListValue* value = new ListValue(); 1042 ListValue* value = new ListValue();
1049 for (std::set<std::string>::const_iterator it = events.begin(); 1043 for (std::set<std::string>::const_iterator it = events.begin();
1050 it != events.end(); ++it) { 1044 it != events.end(); ++it) {
1051 value->Append(new StringValue(*it)); 1045 value->Append(new StringValue(*it));
1052 } 1046 }
1053 UpdateExtensionPref(extension_id, kRegisteredEvents, value); 1047 UpdateExtensionPref(extension_id, kRegisteredEvents, value);
1054 } 1048 }
1055 1049
1056 extensions::ExtensionOmniboxSuggestion 1050 ExtensionOmniboxSuggestion
1057 ExtensionPrefs::GetOmniboxDefaultSuggestion(const std::string& extension_id) { 1051 ExtensionPrefs::GetOmniboxDefaultSuggestion(const std::string& extension_id) {
1058 extensions::ExtensionOmniboxSuggestion suggestion; 1052 ExtensionOmniboxSuggestion suggestion;
1059 1053
1060 const base::DictionaryValue* extension = GetExtensionPref(extension_id); 1054 const base::DictionaryValue* extension = GetExtensionPref(extension_id);
1061 base::DictionaryValue* dict = NULL; 1055 base::DictionaryValue* dict = NULL;
1062 if (extension && extension->GetDictionary(kOmniboxDefaultSuggestion, &dict)) 1056 if (extension && extension->GetDictionary(kOmniboxDefaultSuggestion, &dict))
1063 suggestion.Populate(*dict, false); 1057 suggestion.Populate(*dict, false);
1064 1058
1065 return suggestion; 1059 return suggestion;
1066 } 1060 }
1067 1061
1068 void ExtensionPrefs::SetOmniboxDefaultSuggestion( 1062 void ExtensionPrefs::SetOmniboxDefaultSuggestion(
1069 const std::string& extension_id, 1063 const std::string& extension_id,
1070 const extensions::ExtensionOmniboxSuggestion& suggestion) { 1064 const ExtensionOmniboxSuggestion& suggestion) {
1071 scoped_ptr<base::DictionaryValue> dict = suggestion.ToValue().Pass(); 1065 scoped_ptr<base::DictionaryValue> dict = suggestion.ToValue().Pass();
1072 UpdateExtensionPref(extension_id, kOmniboxDefaultSuggestion, dict.release()); 1066 UpdateExtensionPref(extension_id, kOmniboxDefaultSuggestion, dict.release());
1073 } 1067 }
1074 1068
1075 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { 1069 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) {
1076 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled); 1070 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled);
1077 } 1071 }
1078 1072
1079 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, 1073 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id,
1080 bool enabled) { 1074 bool enabled) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, 1304 void ExtensionPrefs::SetExtensionState(const std::string& extension_id,
1311 Extension::State state) { 1305 Extension::State state) {
1312 UpdateExtensionPref(extension_id, kPrefState, 1306 UpdateExtensionPref(extension_id, kPrefState,
1313 Value::CreateIntegerValue(state)); 1307 Value::CreateIntegerValue(state));
1314 bool enabled = (state == Extension::ENABLED); 1308 bool enabled = (state == Extension::ENABLED);
1315 extension_pref_value_map_->SetExtensionState(extension_id, enabled); 1309 extension_pref_value_map_->SetExtensionState(extension_id, enabled);
1316 content_settings_store_->SetExtensionState(extension_id, enabled); 1310 content_settings_store_->SetExtensionState(extension_id, enabled);
1317 } 1311 }
1318 1312
1319 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) { 1313 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) {
1320 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); 1314 bool action_box_enabled = switch_utils::IsActionBoxEnabled();
1321 bool default_value = !action_box_enabled; 1315 bool default_value = !action_box_enabled;
1322 1316
1323 const DictionaryValue* extension_prefs = GetExtensionPref(extension->id()); 1317 const DictionaryValue* extension_prefs = GetExtensionPref(extension->id());
1324 if (!extension_prefs) 1318 if (!extension_prefs)
1325 return default_value; 1319 return default_value;
1326 1320
1327 bool visible = false; 1321 bool visible = false;
1328 const char* browser_action_pref = action_box_enabled ? kBrowserActionPinned : 1322 const char* browser_action_pref = action_box_enabled ? kBrowserActionPinned :
1329 kBrowserActionVisible; 1323 kBrowserActionVisible;
1330 bool pref_exists = extension_prefs->GetBoolean(browser_action_pref, &visible); 1324 bool pref_exists = extension_prefs->GetBoolean(browser_action_pref, &visible);
1331 if (!pref_exists) 1325 if (!pref_exists)
1332 return default_value; 1326 return default_value;
1333 1327
1334 return visible; 1328 return visible;
1335 } 1329 }
1336 1330
1337 void ExtensionPrefs::SetBrowserActionVisibility(const Extension* extension, 1331 void ExtensionPrefs::SetBrowserActionVisibility(const Extension* extension,
1338 bool visible) { 1332 bool visible) {
1339 if (GetBrowserActionVisibility(extension) == visible) 1333 if (GetBrowserActionVisibility(extension) == visible)
1340 return; 1334 return;
1341 1335
1342 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); 1336 bool action_box_enabled = switch_utils::IsActionBoxEnabled();
1343 const char* browser_action_pref = action_box_enabled ? kBrowserActionPinned : 1337 const char* browser_action_pref = action_box_enabled ? kBrowserActionPinned :
1344 kBrowserActionVisible; 1338 kBrowserActionVisible;
1345 UpdateExtensionPref(extension->id(), browser_action_pref, 1339 UpdateExtensionPref(extension->id(), browser_action_pref,
1346 Value::CreateBooleanValue(visible)); 1340 Value::CreateBooleanValue(visible));
1347 content::NotificationService::current()->Notify( 1341 content::NotificationService::current()->Notify(
1348 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, 1342 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
1349 content::Source<ExtensionPrefs>(this), 1343 content::Source<ExtensionPrefs>(this),
1350 content::Details<const Extension>(extension)); 1344 content::Details<const Extension>(extension));
1351 } 1345 }
1352 1346
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 PrefService::UNSYNCABLE_PREF); 1959 PrefService::UNSYNCABLE_PREF);
1966 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, 1960 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck,
1967 0, // default value 1961 0, // default value
1968 PrefService::UNSYNCABLE_PREF); 1962 PrefService::UNSYNCABLE_PREF);
1969 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, 1963 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck,
1970 0, // default value 1964 0, // default value
1971 PrefService::UNSYNCABLE_PREF); 1965 PrefService::UNSYNCABLE_PREF);
1972 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, 1966 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites,
1973 PrefService::UNSYNCABLE_PREF); 1967 PrefService::UNSYNCABLE_PREF);
1974 } 1968 }
1969
1970 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698