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

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: Latest-er master merged in 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_pref_store.h" 12 #include "chrome/browser/extensions/extension_pref_store.h"
13 #include "chrome/browser/extensions/extension_sorting.h" 13 #include "chrome/browser/extensions/extension_sorting.h"
14 #include "chrome/browser/prefs/pref_notifier.h" 14 #include "chrome/browser/prefs/pref_notifier.h"
15 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/browser/prefs/scoped_user_pref_update.h" 16 #include "chrome/browser/prefs/scoped_user_pref_update.h"
17 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/extensions/extension_switch_utils.h" 18 #include "chrome/common/extensions/extension_switch_utils.h"
19 #include "chrome/common/extensions/manifest.h" 19 #include "chrome/common/extensions/manifest.h"
20 #include "chrome/common/extensions/permissions/permissions_info.h" 20 #include "chrome/common/extensions/permissions/permissions_info.h"
21 #include "chrome/common/extensions/url_pattern.h" 21 #include "chrome/common/extensions/url_pattern.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
24 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
25 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
26 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 27
28 using extensions::APIPermission; 28 namespace extensions {
29 using extensions::APIPermissionSet;
30 using extensions::Extension;
31 using extensions::ExtensionInfo;
32 using extensions::PermissionsInfo;
33 using extensions::PermissionSet;
34 29
35 namespace { 30 namespace {
36 31
37 // Additional preferences keys 32 // Additional preferences keys
38 33
39 // Where an extension was installed from. (see Extension::Location) 34 // Where an extension was installed from. (see Extension::Location)
40 const char kPrefLocation[] = "location"; 35 const char kPrefLocation[] = "location";
41 36
42 // Enabled, disabled, killed, etc. (see Extension::State) 37 // Enabled, disabled, killed, etc. (see Extension::State)
43 const char kPrefState[] = "state"; 38 const char kPrefState[] = "state";
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 265
271 ExtensionPrefs::ExtensionPrefs( 266 ExtensionPrefs::ExtensionPrefs(
272 PrefService* prefs, 267 PrefService* prefs,
273 const FilePath& root_dir, 268 const FilePath& root_dir,
274 ExtensionPrefValueMap* extension_pref_value_map) 269 ExtensionPrefValueMap* extension_pref_value_map)
275 : prefs_(prefs), 270 : prefs_(prefs),
276 install_directory_(root_dir), 271 install_directory_(root_dir),
277 extension_pref_value_map_(extension_pref_value_map), 272 extension_pref_value_map_(extension_pref_value_map),
278 ALLOW_THIS_IN_INITIALIZER_LIST(extension_sorting_( 273 ALLOW_THIS_IN_INITIALIZER_LIST(extension_sorting_(
279 new ExtensionSorting(this, prefs))), 274 new ExtensionSorting(this, prefs))),
280 content_settings_store_(new extensions::ContentSettingsStore()) { 275 content_settings_store_(new ContentSettingsStore()) {
281 } 276 }
282 277
283 ExtensionPrefs::~ExtensionPrefs() { 278 ExtensionPrefs::~ExtensionPrefs() {
284 } 279 }
285 280
286 void ExtensionPrefs::Init(bool extensions_disabled) { 281 void ExtensionPrefs::Init(bool extensions_disabled) {
287 MakePathsRelative(); 282 MakePathsRelative();
288 283
289 InitPrefStore(extensions_disabled); 284 InitPrefStore(extensions_disabled);
290 285
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 632
638 std::string ExtensionPrefs::GetDebugPolicyProviderName() const { 633 std::string ExtensionPrefs::GetDebugPolicyProviderName() const {
639 #ifdef NDEBUG 634 #ifdef NDEBUG
640 NOTREACHED(); 635 NOTREACHED();
641 return std::string(); 636 return std::string();
642 #else 637 #else
643 return "admin policy black/white/forcelist, via the ExtensionPrefs"; 638 return "admin policy black/white/forcelist, via the ExtensionPrefs";
644 #endif 639 #endif
645 } 640 }
646 641
647 bool ExtensionPrefs::UserMayLoad(const extensions::Extension* extension, 642 bool ExtensionPrefs::UserMayLoad(const Extension* extension,
648 string16* error) const { 643 string16* error) const {
649 644
650 const base::ListValue* blacklist = 645 const base::ListValue* blacklist =
651 prefs_->GetList(prefs::kExtensionInstallDenyList); 646 prefs_->GetList(prefs::kExtensionInstallDenyList);
652 const base::ListValue* whitelist = 647 const base::ListValue* whitelist =
653 prefs_->GetList(prefs::kExtensionInstallAllowList); 648 prefs_->GetList(prefs::kExtensionInstallAllowList);
654 return extensions::admin_policy::UserMayLoad(blacklist, whitelist, extension, 649 return admin_policy::UserMayLoad(blacklist, whitelist, extension,
655 error); 650 error);
656 } 651 }
657 652
658 bool ExtensionPrefs::UserMayModifySettings(const Extension* extension, 653 bool ExtensionPrefs::UserMayModifySettings(const Extension* extension,
659 string16* error) const { 654 string16* error) const {
660 return extensions::admin_policy::UserMayModifySettings(extension, error); 655 return admin_policy::UserMayModifySettings(extension, error);
661 } 656 }
662 657
663 bool ExtensionPrefs::MustRemainEnabled(const Extension* extension, 658 bool ExtensionPrefs::MustRemainEnabled(const Extension* extension,
664 string16* error) const { 659 string16* error) const {
665 return extensions::admin_policy::MustRemainEnabled(extension, error); 660 return admin_policy::MustRemainEnabled(extension, error);
666 } 661 }
667 662
668 bool ExtensionPrefs::ExtensionsBlacklistedByDefault() const { 663 bool ExtensionPrefs::ExtensionsBlacklistedByDefault() const {
669 return extensions::admin_policy::BlacklistedByDefault( 664 return admin_policy::BlacklistedByDefault(
670 prefs_->GetList(prefs::kExtensionInstallDenyList)); 665 prefs_->GetList(prefs::kExtensionInstallDenyList));
671 } 666 }
672 667
673 bool ExtensionPrefs::DidExtensionEscalatePermissions( 668 bool ExtensionPrefs::DidExtensionEscalatePermissions(
674 const std::string& extension_id) { 669 const std::string& extension_id) {
675 return ReadExtensionPrefBoolean(extension_id, 670 return ReadExtensionPrefBoolean(extension_id,
676 kExtensionDidEscalatePermissions); 671 kExtensionDidEscalatePermissions);
677 } 672 }
678 673
679 void ExtensionPrefs::SetDidExtensionEscalatePermissions( 674 void ExtensionPrefs::SetDidExtensionEscalatePermissions(
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 void ExtensionPrefs::SetRegisteredEvents( 1013 void ExtensionPrefs::SetRegisteredEvents(
1019 const std::string& extension_id, const std::set<std::string>& events) { 1014 const std::string& extension_id, const std::set<std::string>& events) {
1020 ListValue* value = new ListValue(); 1015 ListValue* value = new ListValue();
1021 for (std::set<std::string>::const_iterator it = events.begin(); 1016 for (std::set<std::string>::const_iterator it = events.begin();
1022 it != events.end(); ++it) { 1017 it != events.end(); ++it) {
1023 value->Append(new StringValue(*it)); 1018 value->Append(new StringValue(*it));
1024 } 1019 }
1025 UpdateExtensionPref(extension_id, kRegisteredEvents, value); 1020 UpdateExtensionPref(extension_id, kRegisteredEvents, value);
1026 } 1021 }
1027 1022
1028 extensions::ExtensionOmniboxSuggestion 1023 ExtensionOmniboxSuggestion
1029 ExtensionPrefs::GetOmniboxDefaultSuggestion(const std::string& extension_id) { 1024 ExtensionPrefs::GetOmniboxDefaultSuggestion(const std::string& extension_id) {
1030 extensions::ExtensionOmniboxSuggestion suggestion; 1025 ExtensionOmniboxSuggestion suggestion;
1031 1026
1032 const base::DictionaryValue* extension = GetExtensionPref(extension_id); 1027 const base::DictionaryValue* extension = GetExtensionPref(extension_id);
1033 base::DictionaryValue* dict = NULL; 1028 base::DictionaryValue* dict = NULL;
1034 if (extension && extension->GetDictionary(kOmniboxDefaultSuggestion, &dict)) 1029 if (extension && extension->GetDictionary(kOmniboxDefaultSuggestion, &dict))
1035 suggestion.Populate(*dict, false); 1030 suggestion.Populate(*dict, false);
1036 1031
1037 return suggestion; 1032 return suggestion;
1038 } 1033 }
1039 1034
1040 void ExtensionPrefs::SetOmniboxDefaultSuggestion( 1035 void ExtensionPrefs::SetOmniboxDefaultSuggestion(
1041 const std::string& extension_id, 1036 const std::string& extension_id,
1042 const extensions::ExtensionOmniboxSuggestion& suggestion) { 1037 const ExtensionOmniboxSuggestion& suggestion) {
1043 scoped_ptr<base::DictionaryValue> dict = suggestion.ToValue().Pass(); 1038 scoped_ptr<base::DictionaryValue> dict = suggestion.ToValue().Pass();
1044 UpdateExtensionPref(extension_id, kOmniboxDefaultSuggestion, dict.release()); 1039 UpdateExtensionPref(extension_id, kOmniboxDefaultSuggestion, dict.release());
1045 } 1040 }
1046 1041
1047 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { 1042 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) {
1048 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled); 1043 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled);
1049 } 1044 }
1050 1045
1051 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, 1046 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id,
1052 bool enabled) { 1047 bool enabled) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 void ExtensionPrefs::SetExtensionState(const std::string& extension_id, 1277 void ExtensionPrefs::SetExtensionState(const std::string& extension_id,
1283 Extension::State state) { 1278 Extension::State state) {
1284 UpdateExtensionPref(extension_id, kPrefState, 1279 UpdateExtensionPref(extension_id, kPrefState,
1285 Value::CreateIntegerValue(state)); 1280 Value::CreateIntegerValue(state));
1286 bool enabled = (state == Extension::ENABLED); 1281 bool enabled = (state == Extension::ENABLED);
1287 extension_pref_value_map_->SetExtensionState(extension_id, enabled); 1282 extension_pref_value_map_->SetExtensionState(extension_id, enabled);
1288 content_settings_store_->SetExtensionState(extension_id, enabled); 1283 content_settings_store_->SetExtensionState(extension_id, enabled);
1289 } 1284 }
1290 1285
1291 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) { 1286 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) {
1292 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); 1287 bool action_box_enabled = switch_utils::IsActionBoxEnabled();
1293 bool default_value = !action_box_enabled; 1288 bool default_value = !action_box_enabled;
1294 1289
1295 const DictionaryValue* extension_prefs = GetExtensionPref(extension->id()); 1290 const DictionaryValue* extension_prefs = GetExtensionPref(extension->id());
1296 if (!extension_prefs) 1291 if (!extension_prefs)
1297 return default_value; 1292 return default_value;
1298 1293
1299 bool visible = false; 1294 bool visible = false;
1300 const char* browser_action_pref = action_box_enabled ? kBrowserActionPinned : 1295 const char* browser_action_pref = action_box_enabled ? kBrowserActionPinned :
1301 kBrowserActionVisible; 1296 kBrowserActionVisible;
1302 bool pref_exists = extension_prefs->GetBoolean(browser_action_pref, &visible); 1297 bool pref_exists = extension_prefs->GetBoolean(browser_action_pref, &visible);
1303 if (!pref_exists) 1298 if (!pref_exists)
1304 return default_value; 1299 return default_value;
1305 1300
1306 return visible; 1301 return visible;
1307 } 1302 }
1308 1303
1309 void ExtensionPrefs::SetBrowserActionVisibility(const Extension* extension, 1304 void ExtensionPrefs::SetBrowserActionVisibility(const Extension* extension,
1310 bool visible) { 1305 bool visible) {
1311 if (GetBrowserActionVisibility(extension) == visible) 1306 if (GetBrowserActionVisibility(extension) == visible)
1312 return; 1307 return;
1313 1308
1314 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); 1309 bool action_box_enabled = switch_utils::IsActionBoxEnabled();
1315 const char* browser_action_pref = action_box_enabled ? kBrowserActionPinned : 1310 const char* browser_action_pref = action_box_enabled ? kBrowserActionPinned :
1316 kBrowserActionVisible; 1311 kBrowserActionVisible;
1317 UpdateExtensionPref(extension->id(), browser_action_pref, 1312 UpdateExtensionPref(extension->id(), browser_action_pref,
1318 Value::CreateBooleanValue(visible)); 1313 Value::CreateBooleanValue(visible));
1319 content::NotificationService::current()->Notify( 1314 content::NotificationService::current()->Notify(
1320 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, 1315 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
1321 content::Source<ExtensionPrefs>(this), 1316 content::Source<ExtensionPrefs>(this),
1322 content::Details<const Extension>(extension)); 1317 content::Details<const Extension>(extension));
1323 } 1318 }
1324 1319
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 PrefService::UNSYNCABLE_PREF); 1932 PrefService::UNSYNCABLE_PREF);
1938 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, 1933 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck,
1939 0, // default value 1934 0, // default value
1940 PrefService::UNSYNCABLE_PREF); 1935 PrefService::UNSYNCABLE_PREF);
1941 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, 1936 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck,
1942 0, // default value 1937 0, // default value
1943 PrefService::UNSYNCABLE_PREF); 1938 PrefService::UNSYNCABLE_PREF);
1944 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites, 1939 prefs->RegisterListPref(prefs::kExtensionAllowedInstallSites,
1945 PrefService::UNSYNCABLE_PREF); 1940 PrefService::UNSYNCABLE_PREF);
1946 } 1941 }
1942
1943 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_prefs_scope.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698