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

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

Issue 196663003: Introduce an extension parameter which is used to customize the extension. It's available for exter… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Modified test parameters Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « extensions/browser/extension_prefs.h ('k') | extensions/browser/external_provider_interface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/extension_prefs.h" 5 #include "extensions/browser/extension_prefs.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/prefs/pref_notifier.h" 10 #include "base/prefs/pref_notifier.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // A preference that indicates whether the extension was installed as an 172 // A preference that indicates whether the extension was installed as an
173 // OEM app. 173 // OEM app.
174 const char kPrefWasInstalledByOem[] = "was_installed_by_oem"; 174 const char kPrefWasInstalledByOem[] = "was_installed_by_oem";
175 175
176 // Key for Geometry Cache preference. 176 // Key for Geometry Cache preference.
177 const char kPrefGeometryCache[] = "geometry_cache"; 177 const char kPrefGeometryCache[] = "geometry_cache";
178 178
179 // A preference that indicates when an extension is last launched. 179 // A preference that indicates when an extension is last launched.
180 const char kPrefLastLaunchTime[] = "last_launch_time"; 180 const char kPrefLastLaunchTime[] = "last_launch_time";
181 181
182 // Am installation parameter bundled with an extension.
183 const char kPrefInstallParam[] = "install_parameter";
184
182 // A list of installed ids and a signature. 185 // A list of installed ids and a signature.
183 const char kInstallSignature[] = "extensions.install_signature"; 186 const char kInstallSignature[] = "extensions.install_signature";
184 187
185 // Provider of write access to a dictionary storing extension prefs. 188 // Provider of write access to a dictionary storing extension prefs.
186 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { 189 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate {
187 public: 190 public:
188 ScopedExtensionPrefUpdate(PrefService* service, 191 ScopedExtensionPrefUpdate(PrefService* service,
189 const std::string& extension_id) : 192 const std::string& extension_id) :
190 DictionaryPrefUpdate(service, pref_names::kExtensions), 193 DictionaryPrefUpdate(service, pref_names::kExtensions),
191 extension_id_(extension_id) {} 194 extension_id_(extension_id) {}
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 } 1103 }
1101 1104
1102 void ExtensionPrefs::SetKnownDisabled(const ExtensionIdSet& extension_ids) { 1105 void ExtensionPrefs::SetKnownDisabled(const ExtensionIdSet& extension_ids) {
1103 SetExtensionPrefFromContainer(pref_names::kKnownDisabled, extension_ids); 1106 SetExtensionPrefFromContainer(pref_names::kKnownDisabled, extension_ids);
1104 } 1107 }
1105 1108
1106 void ExtensionPrefs::OnExtensionInstalled( 1109 void ExtensionPrefs::OnExtensionInstalled(
1107 const Extension* extension, 1110 const Extension* extension,
1108 Extension::State initial_state, 1111 Extension::State initial_state,
1109 bool blacklisted_for_malware, 1112 bool blacklisted_for_malware,
1110 const syncer::StringOrdinal& page_ordinal) { 1113 const syncer::StringOrdinal& page_ordinal,
1114 const std::string& install_parameter) {
1111 ScopedExtensionPrefUpdate update(prefs_, extension->id()); 1115 ScopedExtensionPrefUpdate update(prefs_, extension->id());
1112 base::DictionaryValue* extension_dict = update.Get(); 1116 base::DictionaryValue* extension_dict = update.Get();
1113 const base::Time install_time = time_provider_->GetCurrentTime(); 1117 const base::Time install_time = time_provider_->GetCurrentTime();
1114 PopulateExtensionInfoPrefs(extension, install_time, initial_state, 1118 PopulateExtensionInfoPrefs(extension,
1115 blacklisted_for_malware, extension_dict); 1119 install_time,
1120 initial_state,
1121 blacklisted_for_malware,
1122 install_parameter,
1123 extension_dict);
1116 FinishExtensionInfoPrefs(extension->id(), install_time, 1124 FinishExtensionInfoPrefs(extension->id(), install_time,
1117 extension->RequiresSortOrdinal(), 1125 extension->RequiresSortOrdinal(),
1118 page_ordinal, extension_dict); 1126 page_ordinal, extension_dict);
1119 } 1127 }
1120 1128
1121 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, 1129 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id,
1122 const Manifest::Location& location, 1130 const Manifest::Location& location,
1123 bool external_uninstall) { 1131 bool external_uninstall) {
1124 app_sorting_->ClearOrdinals(extension_id); 1132 app_sorting_->ClearOrdinals(extension_id);
1125 1133
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 } 1319 }
1312 1320
1313 return extensions_info.Pass(); 1321 return extensions_info.Pass();
1314 } 1322 }
1315 1323
1316 void ExtensionPrefs::SetDelayedInstallInfo( 1324 void ExtensionPrefs::SetDelayedInstallInfo(
1317 const Extension* extension, 1325 const Extension* extension,
1318 Extension::State initial_state, 1326 Extension::State initial_state,
1319 bool blacklisted_for_malware, 1327 bool blacklisted_for_malware,
1320 DelayReason delay_reason, 1328 DelayReason delay_reason,
1321 const syncer::StringOrdinal& page_ordinal) { 1329 const syncer::StringOrdinal& page_ordinal,
1330 const std::string& install_parameter) {
1322 base::DictionaryValue* extension_dict = new base::DictionaryValue(); 1331 base::DictionaryValue* extension_dict = new base::DictionaryValue();
1323 PopulateExtensionInfoPrefs(extension, time_provider_->GetCurrentTime(), 1332 PopulateExtensionInfoPrefs(extension,
1324 initial_state, blacklisted_for_malware, 1333 time_provider_->GetCurrentTime(),
1334 initial_state,
1335 blacklisted_for_malware,
1336 install_parameter,
1325 extension_dict); 1337 extension_dict);
1326 1338
1327 // Add transient data that is needed by FinishDelayedInstallInfo(), but 1339 // Add transient data that is needed by FinishDelayedInstallInfo(), but
1328 // should not be in the final extension prefs. All entries here should have 1340 // should not be in the final extension prefs. All entries here should have
1329 // a corresponding Remove() call in FinishDelayedInstallInfo(). 1341 // a corresponding Remove() call in FinishDelayedInstallInfo().
1330 if (extension->RequiresSortOrdinal()) { 1342 if (extension->RequiresSortOrdinal()) {
1331 extension_dict->SetString( 1343 extension_dict->SetString(
1332 kPrefSuggestedPageOrdinal, 1344 kPrefSuggestedPageOrdinal,
1333 page_ordinal.IsValid() ? page_ordinal.ToInternalValue() 1345 page_ordinal.IsValid() ? page_ordinal.ToInternalValue()
1334 : std::string()); 1346 : std::string());
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 const base::DictionaryValue* signature) { 1702 const base::DictionaryValue* signature) {
1691 if (signature) { 1703 if (signature) {
1692 prefs_->Set(kInstallSignature, *signature); 1704 prefs_->Set(kInstallSignature, *signature);
1693 DVLOG(1) << "SetInstallSignature - saving"; 1705 DVLOG(1) << "SetInstallSignature - saving";
1694 } else { 1706 } else {
1695 DVLOG(1) << "SetInstallSignature - clearing"; 1707 DVLOG(1) << "SetInstallSignature - clearing";
1696 prefs_->ClearPref(kInstallSignature); 1708 prefs_->ClearPref(kInstallSignature);
1697 } 1709 }
1698 } 1710 }
1699 1711
1712 std::string ExtensionPrefs::GetInstallParam(
1713 const std::string& extension_id) const {
1714 const base::DictionaryValue* extension = GetExtensionPref(extension_id);
1715 if (!extension) {
1716 NOTREACHED();
1717 return std::string();
1718 }
1719 std::string install_parameter;
1720 if (!extension->GetString(kPrefInstallParam, &install_parameter))
1721 return std::string();
1722 return install_parameter;
1723 }
1724
1725 void ExtensionPrefs::SetInstallParam(const std::string& extension_id,
1726 const std::string& install_parameter) {
1727 UpdateExtensionPref(extension_id,
1728 kPrefInstallParam,
1729 new base::StringValue(install_parameter));
1730 }
1700 1731
1701 ExtensionPrefs::ExtensionPrefs( 1732 ExtensionPrefs::ExtensionPrefs(
1702 PrefService* prefs, 1733 PrefService* prefs,
1703 const base::FilePath& root_dir, 1734 const base::FilePath& root_dir,
1704 ExtensionPrefValueMap* extension_pref_value_map, 1735 ExtensionPrefValueMap* extension_pref_value_map,
1705 scoped_ptr<AppSorting> app_sorting, 1736 scoped_ptr<AppSorting> app_sorting,
1706 scoped_ptr<TimeProvider> time_provider, 1737 scoped_ptr<TimeProvider> time_provider,
1707 bool extensions_disabled) 1738 bool extensions_disabled)
1708 : prefs_(prefs), 1739 : prefs_(prefs),
1709 install_directory_(root_dir), 1740 install_directory_(root_dir),
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 iter != strings.end(); ++iter) { 1856 iter != strings.end(); ++iter) {
1826 list_of_values->Append(new base::StringValue(*iter)); 1857 list_of_values->Append(new base::StringValue(*iter));
1827 } 1858 }
1828 } 1859 }
1829 1860
1830 void ExtensionPrefs::PopulateExtensionInfoPrefs( 1861 void ExtensionPrefs::PopulateExtensionInfoPrefs(
1831 const Extension* extension, 1862 const Extension* extension,
1832 const base::Time install_time, 1863 const base::Time install_time,
1833 Extension::State initial_state, 1864 Extension::State initial_state,
1834 bool blacklisted_for_malware, 1865 bool blacklisted_for_malware,
1866 const std::string& install_parameter,
1835 base::DictionaryValue* extension_dict) { 1867 base::DictionaryValue* extension_dict) {
1836 // Leave the state blank for component extensions so that old chrome versions 1868 // Leave the state blank for component extensions so that old chrome versions
1837 // loading new profiles do not fail in GetInstalledExtensionInfo. Older 1869 // loading new profiles do not fail in GetInstalledExtensionInfo. Older
1838 // Chrome versions would only check for an omitted state. 1870 // Chrome versions would only check for an omitted state.
1839 if (initial_state != Extension::ENABLED_COMPONENT) 1871 if (initial_state != Extension::ENABLED_COMPONENT)
1840 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state)); 1872 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state));
1841 1873
1842 extension_dict->Set(kPrefLocation, 1874 extension_dict->Set(kPrefLocation,
1843 new base::FundamentalValue(extension->location())); 1875 new base::FundamentalValue(extension->location()));
1844 extension_dict->Set(kPrefCreationFlags, 1876 extension_dict->Set(kPrefCreationFlags,
(...skipping 10 matching lines...) Expand all
1855 new base::FundamentalValue(extension->was_installed_by_oem())); 1887 new base::FundamentalValue(extension->was_installed_by_oem()));
1856 extension_dict->Set(kPrefInstallTime, 1888 extension_dict->Set(kPrefInstallTime,
1857 new base::StringValue( 1889 new base::StringValue(
1858 base::Int64ToString(install_time.ToInternalValue()))); 1890 base::Int64ToString(install_time.ToInternalValue())));
1859 if (blacklisted_for_malware) 1891 if (blacklisted_for_malware)
1860 extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true)); 1892 extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true));
1861 1893
1862 base::FilePath::StringType path = MakePathRelative(install_directory_, 1894 base::FilePath::StringType path = MakePathRelative(install_directory_,
1863 extension->path()); 1895 extension->path());
1864 extension_dict->Set(kPrefPath, new base::StringValue(path)); 1896 extension_dict->Set(kPrefPath, new base::StringValue(path));
1897 if (!install_parameter.empty()) {
1898 extension_dict->Set(kPrefInstallParam,
1899 new base::StringValue(install_parameter));
1900 }
1865 // We store prefs about LOAD extensions, but don't cache their manifest 1901 // We store prefs about LOAD extensions, but don't cache their manifest
1866 // since it may change on disk. 1902 // since it may change on disk.
1867 if (!Manifest::IsUnpackedLocation(extension->location())) { 1903 if (!Manifest::IsUnpackedLocation(extension->location())) {
1868 extension_dict->Set(kPrefManifest, 1904 extension_dict->Set(kPrefManifest,
1869 extension->manifest()->value()->DeepCopy()); 1905 extension->manifest()->value()->DeepCopy());
1870 } 1906 }
1871 } 1907 }
1872 1908
1873 void ExtensionPrefs::FinishExtensionInfoPrefs( 1909 void ExtensionPrefs::FinishExtensionInfoPrefs(
1874 const std::string& extension_id, 1910 const std::string& extension_id,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 } 1957 }
1922 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); 1958 bool is_incognito_enabled = IsIncognitoEnabled(extension_id);
1923 1959
1924 extension_pref_value_map_->RegisterExtension( 1960 extension_pref_value_map_->RegisterExtension(
1925 extension_id, install_time, is_enabled, is_incognito_enabled); 1961 extension_id, install_time, is_enabled, is_incognito_enabled);
1926 content_settings_store_->RegisterExtension(extension_id, install_time, 1962 content_settings_store_->RegisterExtension(extension_id, install_time,
1927 is_enabled); 1963 is_enabled);
1928 } 1964 }
1929 1965
1930 } // namespace extensions 1966 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/extension_prefs.h ('k') | extensions/browser/external_provider_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698