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

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: addressed @finnur comments 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
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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // A preference that indicates whether the extension was installed as 168 // A preference that indicates whether the extension was installed as
169 // default apps. 169 // default apps.
170 const char kPrefWasInstalledByDefault[] = "was_installed_by_default"; 170 const char kPrefWasInstalledByDefault[] = "was_installed_by_default";
171 171
172 // Key for Geometry Cache preference. 172 // Key for Geometry Cache preference.
173 const char kPrefGeometryCache[] = "geometry_cache"; 173 const char kPrefGeometryCache[] = "geometry_cache";
174 174
175 // A preference that indicates when an extension is last launched. 175 // A preference that indicates when an extension is last launched.
176 const char kPrefLastLaunchTime[] = "last_launch_time"; 176 const char kPrefLastLaunchTime[] = "last_launch_time";
177 177
178 // Am installation parameter bundled with an extension.
179 const char kPrefInstallParam[] = "install_parameter";
180
178 // A list of installed ids and a signature. 181 // A list of installed ids and a signature.
179 const char kInstallSignature[] = "extensions.install_signature"; 182 const char kInstallSignature[] = "extensions.install_signature";
180 183
181 // Provider of write access to a dictionary storing extension prefs. 184 // Provider of write access to a dictionary storing extension prefs.
182 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { 185 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate {
183 public: 186 public:
184 ScopedExtensionPrefUpdate(PrefService* service, 187 ScopedExtensionPrefUpdate(PrefService* service,
185 const std::string& extension_id) : 188 const std::string& extension_id) :
186 DictionaryPrefUpdate(service, pref_names::kExtensions), 189 DictionaryPrefUpdate(service, pref_names::kExtensions),
187 extension_id_(extension_id) {} 190 extension_id_(extension_id) {}
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 } 1099 }
1097 1100
1098 void ExtensionPrefs::SetKnownDisabled(const ExtensionIdSet& extension_ids) { 1101 void ExtensionPrefs::SetKnownDisabled(const ExtensionIdSet& extension_ids) {
1099 SetExtensionPrefFromContainer(pref_names::kKnownDisabled, extension_ids); 1102 SetExtensionPrefFromContainer(pref_names::kKnownDisabled, extension_ids);
1100 } 1103 }
1101 1104
1102 void ExtensionPrefs::OnExtensionInstalled( 1105 void ExtensionPrefs::OnExtensionInstalled(
1103 const Extension* extension, 1106 const Extension* extension,
1104 Extension::State initial_state, 1107 Extension::State initial_state,
1105 bool blacklisted_for_malware, 1108 bool blacklisted_for_malware,
1106 const syncer::StringOrdinal& page_ordinal) { 1109 const syncer::StringOrdinal& page_ordinal,
1110 const std::string& install_parameter) {
1107 ScopedExtensionPrefUpdate update(prefs_, extension->id()); 1111 ScopedExtensionPrefUpdate update(prefs_, extension->id());
1108 base::DictionaryValue* extension_dict = update.Get(); 1112 base::DictionaryValue* extension_dict = update.Get();
1109 const base::Time install_time = time_provider_->GetCurrentTime(); 1113 const base::Time install_time = time_provider_->GetCurrentTime();
1110 PopulateExtensionInfoPrefs(extension, install_time, initial_state, 1114 PopulateExtensionInfoPrefs(extension,
1111 blacklisted_for_malware, extension_dict); 1115 install_time,
1116 initial_state,
1117 blacklisted_for_malware,
1118 install_parameter,
1119 extension_dict);
1112 FinishExtensionInfoPrefs(extension->id(), install_time, 1120 FinishExtensionInfoPrefs(extension->id(), install_time,
1113 extension->RequiresSortOrdinal(), 1121 extension->RequiresSortOrdinal(),
1114 page_ordinal, extension_dict); 1122 page_ordinal, extension_dict);
1115 } 1123 }
1116 1124
1117 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, 1125 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id,
1118 const Manifest::Location& location, 1126 const Manifest::Location& location,
1119 bool external_uninstall) { 1127 bool external_uninstall) {
1120 app_sorting_->ClearOrdinals(extension_id); 1128 app_sorting_->ClearOrdinals(extension_id);
1121 1129
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 } 1315 }
1308 1316
1309 return extensions_info.Pass(); 1317 return extensions_info.Pass();
1310 } 1318 }
1311 1319
1312 void ExtensionPrefs::SetDelayedInstallInfo( 1320 void ExtensionPrefs::SetDelayedInstallInfo(
1313 const Extension* extension, 1321 const Extension* extension,
1314 Extension::State initial_state, 1322 Extension::State initial_state,
1315 bool blacklisted_for_malware, 1323 bool blacklisted_for_malware,
1316 DelayReason delay_reason, 1324 DelayReason delay_reason,
1317 const syncer::StringOrdinal& page_ordinal) { 1325 const syncer::StringOrdinal& page_ordinal,
1326 const std::string& install_parameter) {
1318 base::DictionaryValue* extension_dict = new base::DictionaryValue(); 1327 base::DictionaryValue* extension_dict = new base::DictionaryValue();
1319 PopulateExtensionInfoPrefs(extension, time_provider_->GetCurrentTime(), 1328 PopulateExtensionInfoPrefs(extension,
1320 initial_state, blacklisted_for_malware, 1329 time_provider_->GetCurrentTime(),
1330 initial_state,
1331 blacklisted_for_malware,
1332 install_parameter,
1321 extension_dict); 1333 extension_dict);
1322 1334
1323 // Add transient data that is needed by FinishDelayedInstallInfo(), but 1335 // Add transient data that is needed by FinishDelayedInstallInfo(), but
1324 // should not be in the final extension prefs. All entries here should have 1336 // should not be in the final extension prefs. All entries here should have
1325 // a corresponding Remove() call in FinishDelayedInstallInfo(). 1337 // a corresponding Remove() call in FinishDelayedInstallInfo().
1326 if (extension->RequiresSortOrdinal()) { 1338 if (extension->RequiresSortOrdinal()) {
1327 extension_dict->SetString( 1339 extension_dict->SetString(
1328 kPrefSuggestedPageOrdinal, 1340 kPrefSuggestedPageOrdinal,
1329 page_ordinal.IsValid() ? page_ordinal.ToInternalValue() 1341 page_ordinal.IsValid() ? page_ordinal.ToInternalValue()
1330 : std::string()); 1342 : std::string());
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 const base::DictionaryValue* signature) { 1688 const base::DictionaryValue* signature) {
1677 if (signature) { 1689 if (signature) {
1678 prefs_->Set(kInstallSignature, *signature); 1690 prefs_->Set(kInstallSignature, *signature);
1679 DVLOG(1) << "SetInstallSignature - saving"; 1691 DVLOG(1) << "SetInstallSignature - saving";
1680 } else { 1692 } else {
1681 DVLOG(1) << "SetInstallSignature - clearing"; 1693 DVLOG(1) << "SetInstallSignature - clearing";
1682 prefs_->ClearPref(kInstallSignature); 1694 prefs_->ClearPref(kInstallSignature);
1683 } 1695 }
1684 } 1696 }
1685 1697
1698 std::string ExtensionPrefs::GetInstallParam(
1699 const std::string& extension_id) const {
1700 const base::DictionaryValue* extension = GetExtensionPref(extension_id);
1701 if (!extension) {
1702 NOTREACHED();
1703 return std::string();
1704 }
1705 std::string install_parameter;
1706 if (!extension->GetString(kPrefInstallParam, &install_parameter))
1707 return std::string();
1708 return install_parameter;
1709 }
1710
1711 void ExtensionPrefs::SetInstallParam(const std::string& extension_id,
1712 const std::string& install_parameter) {
1713 UpdateExtensionPref(extension_id,
1714 kPrefInstallParam,
1715 new base::StringValue(install_parameter));
1716 }
1686 1717
1687 ExtensionPrefs::ExtensionPrefs( 1718 ExtensionPrefs::ExtensionPrefs(
1688 PrefService* prefs, 1719 PrefService* prefs,
1689 const base::FilePath& root_dir, 1720 const base::FilePath& root_dir,
1690 ExtensionPrefValueMap* extension_pref_value_map, 1721 ExtensionPrefValueMap* extension_pref_value_map,
1691 scoped_ptr<AppSorting> app_sorting, 1722 scoped_ptr<AppSorting> app_sorting,
1692 scoped_ptr<TimeProvider> time_provider, 1723 scoped_ptr<TimeProvider> time_provider,
1693 bool extensions_disabled) 1724 bool extensions_disabled)
1694 : prefs_(prefs), 1725 : prefs_(prefs),
1695 install_directory_(root_dir), 1726 install_directory_(root_dir),
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 iter != strings.end(); ++iter) { 1842 iter != strings.end(); ++iter) {
1812 list_of_values->Append(new base::StringValue(*iter)); 1843 list_of_values->Append(new base::StringValue(*iter));
1813 } 1844 }
1814 } 1845 }
1815 1846
1816 void ExtensionPrefs::PopulateExtensionInfoPrefs( 1847 void ExtensionPrefs::PopulateExtensionInfoPrefs(
1817 const Extension* extension, 1848 const Extension* extension,
1818 const base::Time install_time, 1849 const base::Time install_time,
1819 Extension::State initial_state, 1850 Extension::State initial_state,
1820 bool blacklisted_for_malware, 1851 bool blacklisted_for_malware,
1852 const std::string& install_parameter,
1821 base::DictionaryValue* extension_dict) { 1853 base::DictionaryValue* extension_dict) {
1822 // Leave the state blank for component extensions so that old chrome versions 1854 // Leave the state blank for component extensions so that old chrome versions
1823 // loading new profiles do not fail in GetInstalledExtensionInfo. Older 1855 // loading new profiles do not fail in GetInstalledExtensionInfo. Older
1824 // Chrome versions would only check for an omitted state. 1856 // Chrome versions would only check for an omitted state.
1825 if (initial_state != Extension::ENABLED_COMPONENT) 1857 if (initial_state != Extension::ENABLED_COMPONENT)
1826 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state)); 1858 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state));
1827 1859
1828 extension_dict->Set(kPrefLocation, 1860 extension_dict->Set(kPrefLocation,
1829 new base::FundamentalValue(extension->location())); 1861 new base::FundamentalValue(extension->location()));
1830 extension_dict->Set(kPrefCreationFlags, 1862 extension_dict->Set(kPrefCreationFlags,
1831 new base::FundamentalValue(extension->creation_flags())); 1863 new base::FundamentalValue(extension->creation_flags()));
1832 extension_dict->Set(kPrefFromWebStore, 1864 extension_dict->Set(kPrefFromWebStore,
1833 new base::FundamentalValue(extension->from_webstore())); 1865 new base::FundamentalValue(extension->from_webstore()));
1834 extension_dict->Set(kPrefFromBookmark, 1866 extension_dict->Set(kPrefFromBookmark,
1835 new base::FundamentalValue(extension->from_bookmark())); 1867 new base::FundamentalValue(extension->from_bookmark()));
1836 extension_dict->Set( 1868 extension_dict->Set(
1837 kPrefWasInstalledByDefault, 1869 kPrefWasInstalledByDefault,
1838 new base::FundamentalValue(extension->was_installed_by_default())); 1870 new base::FundamentalValue(extension->was_installed_by_default()));
1839 extension_dict->Set(kPrefInstallTime, 1871 extension_dict->Set(kPrefInstallTime,
1840 new base::StringValue( 1872 new base::StringValue(
1841 base::Int64ToString(install_time.ToInternalValue()))); 1873 base::Int64ToString(install_time.ToInternalValue())));
1842 if (blacklisted_for_malware) 1874 if (blacklisted_for_malware)
1843 extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true)); 1875 extension_dict->Set(kPrefBlacklist, new base::FundamentalValue(true));
1844 1876
1845 base::FilePath::StringType path = MakePathRelative(install_directory_, 1877 base::FilePath::StringType path = MakePathRelative(install_directory_,
1846 extension->path()); 1878 extension->path());
1847 extension_dict->Set(kPrefPath, new base::StringValue(path)); 1879 extension_dict->Set(kPrefPath, new base::StringValue(path));
1880 if (!install_parameter.empty()) {
1881 extension_dict->Set(kPrefInstallParam,
1882 new base::StringValue(install_parameter));
1883 }
1848 // We store prefs about LOAD extensions, but don't cache their manifest 1884 // We store prefs about LOAD extensions, but don't cache their manifest
1849 // since it may change on disk. 1885 // since it may change on disk.
1850 if (!Manifest::IsUnpackedLocation(extension->location())) { 1886 if (!Manifest::IsUnpackedLocation(extension->location())) {
1851 extension_dict->Set(kPrefManifest, 1887 extension_dict->Set(kPrefManifest,
1852 extension->manifest()->value()->DeepCopy()); 1888 extension->manifest()->value()->DeepCopy());
1853 } 1889 }
1854 } 1890 }
1855 1891
1856 void ExtensionPrefs::FinishExtensionInfoPrefs( 1892 void ExtensionPrefs::FinishExtensionInfoPrefs(
1857 const std::string& extension_id, 1893 const std::string& extension_id,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 } 1940 }
1905 bool is_incognito_enabled = IsIncognitoEnabled(extension_id); 1941 bool is_incognito_enabled = IsIncognitoEnabled(extension_id);
1906 1942
1907 extension_pref_value_map_->RegisterExtension( 1943 extension_pref_value_map_->RegisterExtension(
1908 extension_id, install_time, is_enabled, is_incognito_enabled); 1944 extension_id, install_time, is_enabled, is_incognito_enabled);
1909 content_settings_store_->RegisterExtension(extension_id, install_time, 1945 content_settings_store_->RegisterExtension(extension_id, install_time,
1910 is_enabled); 1946 is_enabled);
1911 } 1947 }
1912 1948
1913 } // namespace extensions 1949 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698