Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1330 } | 1330 } |
| 1331 } | 1331 } |
| 1332 | 1332 |
| 1333 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledInfoHelper( | 1333 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledInfoHelper( |
| 1334 const std::string& extension_id, | 1334 const std::string& extension_id, |
| 1335 const base::DictionaryValue* extension) const { | 1335 const base::DictionaryValue* extension) const { |
| 1336 int location_value; | 1336 int location_value; |
| 1337 if (!extension->GetInteger(kPrefLocation, &location_value)) | 1337 if (!extension->GetInteger(kPrefLocation, &location_value)) |
| 1338 return scoped_ptr<ExtensionInfo>(); | 1338 return scoped_ptr<ExtensionInfo>(); |
| 1339 | 1339 |
| 1340 base::FilePath::StringType path; | 1340 Manifest::Location location = static_cast<Manifest::Location>(location_value); |
| 1341 if (!extension->GetString(kPrefPath, &path)) | 1341 if (location == Manifest::COMPONENT) { |
| 1342 // Component extensions are ignored. Component extensions may have data | |
| 1343 // saved in preferences, but they are already loaded at this point (by | |
| 1344 // ComponentLoader) and shouldn't be populated into the result of | |
| 1345 // GetInstalledExtensionsInfo, otherwise InstalledLoader would also want to | |
| 1346 // load them. | |
| 1342 return scoped_ptr<ExtensionInfo>(); | 1347 return scoped_ptr<ExtensionInfo>(); |
| 1343 | |
| 1344 // Make path absolute. Unpacked extensions will already have absolute paths, | |
| 1345 // otherwise make it so. | |
| 1346 Manifest::Location location = static_cast<Manifest::Location>(location_value); | |
| 1347 #if !defined(OS_CHROMEOS) | |
| 1348 if (!Manifest::IsUnpackedLocation(location)) { | |
| 1349 DCHECK(location == Manifest::COMPONENT || | |
| 1350 !base::FilePath(path).IsAbsolute()); | |
| 1351 #else | |
| 1352 // On Chrome OS some extensions can be installed to shared location and | |
| 1353 // thus use absolute paths in prefs. | |
| 1354 if (!base::FilePath(path).IsAbsolute()) { | |
| 1355 #endif // !defined(OS_CHROMEOS) | |
| 1356 path = install_directory_.Append(path).value(); | |
| 1357 } | 1348 } |
| 1358 | 1349 |
| 1359 // Only the following extension types have data saved in the preferences. | 1350 // Only the following extension types have data saved in the preferences. |
| 1360 if (location != Manifest::INTERNAL && | 1351 if (location != Manifest::INTERNAL && |
| 1361 !Manifest::IsUnpackedLocation(location) && | 1352 !Manifest::IsUnpackedLocation(location) && |
| 1362 !Manifest::IsExternalLocation(location)) { | 1353 !Manifest::IsExternalLocation(location)) { |
| 1363 NOTREACHED(); | 1354 NOTREACHED(); |
| 1364 return scoped_ptr<ExtensionInfo>(); | 1355 return scoped_ptr<ExtensionInfo>(); |
| 1365 } | 1356 } |
| 1366 | 1357 |
| 1367 const base::DictionaryValue* manifest = NULL; | 1358 const base::DictionaryValue* manifest = NULL; |
| 1368 if (!Manifest::IsUnpackedLocation(location) && | 1359 if (!Manifest::IsUnpackedLocation(location) && |
| 1369 !extension->GetDictionary(kPrefManifest, &manifest)) { | 1360 !extension->GetDictionary(kPrefManifest, &manifest)) { |
| 1370 LOG(WARNING) << "Missing manifest for extension " << extension_id; | 1361 LOG(WARNING) << "Missing manifest for extension " << extension_id; |
| 1371 // Just a warning for now. | 1362 // Just a warning for now. |
| 1372 } | 1363 } |
| 1373 | 1364 |
| 1365 base::FilePath::StringType path; | |
| 1366 if (!extension->GetString(kPrefPath, &path)) | |
| 1367 return scoped_ptr<ExtensionInfo>(); | |
| 1368 | |
| 1369 // Make path absolute. Most (but not all) extension types don't have absolute | |
|
tapted
2014/08/13 03:06:55
optional nit: "don't have absolute paths" -> "have
Anand Mistry (off Chromium)
2014/08/13 03:12:56
Done.
| |
| 1370 // paths. | |
| 1371 if (!base::FilePath(path).IsAbsolute()) | |
| 1372 path = install_directory_.Append(path).value(); | |
| 1373 | |
| 1374 return scoped_ptr<ExtensionInfo>(new ExtensionInfo( | 1374 return scoped_ptr<ExtensionInfo>(new ExtensionInfo( |
| 1375 manifest, extension_id, base::FilePath(path), location)); | 1375 manifest, extension_id, base::FilePath(path), location)); |
| 1376 } | 1376 } |
| 1377 | 1377 |
| 1378 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo( | 1378 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo( |
| 1379 const std::string& extension_id) const { | 1379 const std::string& extension_id) const { |
| 1380 const base::DictionaryValue* ext = NULL; | 1380 const base::DictionaryValue* ext = NULL; |
| 1381 const base::DictionaryValue* extensions = | 1381 const base::DictionaryValue* extensions = |
| 1382 prefs_->GetDictionary(pref_names::kExtensions); | 1382 prefs_->GetDictionary(pref_names::kExtensions); |
| 1383 if (!extensions || | 1383 if (!extensions || |
| 1384 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext)) | 1384 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext)) |
| 1385 return scoped_ptr<ExtensionInfo>(); | 1385 return scoped_ptr<ExtensionInfo>(); |
| 1386 int state_value; | 1386 int state_value; |
| 1387 if (!ext->GetInteger(kPrefState, &state_value) || | 1387 if (ext->GetInteger(kPrefState, &state_value) && |
| 1388 state_value == Extension::ENABLED_COMPONENT) { | 1388 state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { |
| 1389 // Old preferences files may not have kPrefState for component extensions. | |
| 1390 return scoped_ptr<ExtensionInfo>(); | |
| 1391 } | |
| 1392 | |
| 1393 if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { | |
| 1394 LOG(WARNING) << "External extension with id " << extension_id | 1389 LOG(WARNING) << "External extension with id " << extension_id |
| 1395 << " has been uninstalled by the user"; | 1390 << " has been uninstalled by the user"; |
| 1396 return scoped_ptr<ExtensionInfo>(); | 1391 return scoped_ptr<ExtensionInfo>(); |
| 1397 } | 1392 } |
| 1398 | 1393 |
| 1399 return GetInstalledInfoHelper(extension_id, ext); | 1394 return GetInstalledInfoHelper(extension_id, ext); |
| 1400 } | 1395 } |
| 1401 | 1396 |
| 1402 scoped_ptr<ExtensionPrefs::ExtensionsInfo> | 1397 scoped_ptr<ExtensionPrefs::ExtensionsInfo> |
| 1403 ExtensionPrefs::GetInstalledExtensionsInfo() const { | 1398 ExtensionPrefs::GetInstalledExtensionsInfo() const { |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2051 } | 2046 } |
| 2052 } | 2047 } |
| 2053 | 2048 |
| 2054 void ExtensionPrefs::PopulateExtensionInfoPrefs( | 2049 void ExtensionPrefs::PopulateExtensionInfoPrefs( |
| 2055 const Extension* extension, | 2050 const Extension* extension, |
| 2056 const base::Time install_time, | 2051 const base::Time install_time, |
| 2057 Extension::State initial_state, | 2052 Extension::State initial_state, |
| 2058 int install_flags, | 2053 int install_flags, |
| 2059 const std::string& install_parameter, | 2054 const std::string& install_parameter, |
| 2060 base::DictionaryValue* extension_dict) { | 2055 base::DictionaryValue* extension_dict) { |
| 2061 // Leave the state blank for component extensions so that old chrome versions | 2056 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state)); |
| 2062 // loading new profiles do not fail in GetInstalledExtensionInfo. Older | |
| 2063 // Chrome versions would only check for an omitted state. | |
| 2064 if (initial_state != Extension::ENABLED_COMPONENT) | |
| 2065 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state)); | |
| 2066 | |
| 2067 extension_dict->Set(kPrefLocation, | 2057 extension_dict->Set(kPrefLocation, |
| 2068 new base::FundamentalValue(extension->location())); | 2058 new base::FundamentalValue(extension->location())); |
| 2069 extension_dict->Set(kPrefCreationFlags, | 2059 extension_dict->Set(kPrefCreationFlags, |
| 2070 new base::FundamentalValue(extension->creation_flags())); | 2060 new base::FundamentalValue(extension->creation_flags())); |
| 2071 extension_dict->Set(kPrefFromWebStore, | 2061 extension_dict->Set(kPrefFromWebStore, |
| 2072 new base::FundamentalValue(extension->from_webstore())); | 2062 new base::FundamentalValue(extension->from_webstore())); |
| 2073 extension_dict->Set(kPrefFromBookmark, | 2063 extension_dict->Set(kPrefFromBookmark, |
| 2074 new base::FundamentalValue(extension->from_bookmark())); | 2064 new base::FundamentalValue(extension->from_bookmark())); |
| 2075 extension_dict->Set( | 2065 extension_dict->Set( |
| 2076 kPrefWasInstalledByDefault, | 2066 kPrefWasInstalledByDefault, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2201 extension_pref_value_map_->RegisterExtension( | 2191 extension_pref_value_map_->RegisterExtension( |
| 2202 extension_id, install_time, is_enabled, is_incognito_enabled); | 2192 extension_id, install_time, is_enabled, is_incognito_enabled); |
| 2203 | 2193 |
| 2204 FOR_EACH_OBSERVER( | 2194 FOR_EACH_OBSERVER( |
| 2205 ExtensionPrefsObserver, | 2195 ExtensionPrefsObserver, |
| 2206 observer_list_, | 2196 observer_list_, |
| 2207 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 2197 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
| 2208 } | 2198 } |
| 2209 | 2199 |
| 2210 } // namespace extensions | 2200 } // namespace extensions |
| OLD | NEW |