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 have relative paths. |
| 1370 if (!base::FilePath(path).IsAbsolute()) |
| 1371 path = install_directory_.Append(path).value(); |
| 1372 |
1374 return scoped_ptr<ExtensionInfo>(new ExtensionInfo( | 1373 return scoped_ptr<ExtensionInfo>(new ExtensionInfo( |
1375 manifest, extension_id, base::FilePath(path), location)); | 1374 manifest, extension_id, base::FilePath(path), location)); |
1376 } | 1375 } |
1377 | 1376 |
1378 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo( | 1377 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo( |
1379 const std::string& extension_id) const { | 1378 const std::string& extension_id) const { |
1380 const base::DictionaryValue* ext = NULL; | 1379 const base::DictionaryValue* ext = NULL; |
1381 const base::DictionaryValue* extensions = | 1380 const base::DictionaryValue* extensions = |
1382 prefs_->GetDictionary(pref_names::kExtensions); | 1381 prefs_->GetDictionary(pref_names::kExtensions); |
1383 if (!extensions || | 1382 if (!extensions || |
1384 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext)) | 1383 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext)) |
1385 return scoped_ptr<ExtensionInfo>(); | 1384 return scoped_ptr<ExtensionInfo>(); |
1386 int state_value; | 1385 int state_value; |
1387 if (!ext->GetInteger(kPrefState, &state_value) || | 1386 if (ext->GetInteger(kPrefState, &state_value) && |
1388 state_value == Extension::ENABLED_COMPONENT) { | 1387 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 | 1388 LOG(WARNING) << "External extension with id " << extension_id |
1395 << " has been uninstalled by the user"; | 1389 << " has been uninstalled by the user"; |
1396 return scoped_ptr<ExtensionInfo>(); | 1390 return scoped_ptr<ExtensionInfo>(); |
1397 } | 1391 } |
1398 | 1392 |
1399 return GetInstalledInfoHelper(extension_id, ext); | 1393 return GetInstalledInfoHelper(extension_id, ext); |
1400 } | 1394 } |
1401 | 1395 |
1402 scoped_ptr<ExtensionPrefs::ExtensionsInfo> | 1396 scoped_ptr<ExtensionPrefs::ExtensionsInfo> |
1403 ExtensionPrefs::GetInstalledExtensionsInfo() const { | 1397 ExtensionPrefs::GetInstalledExtensionsInfo() const { |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2051 } | 2045 } |
2052 } | 2046 } |
2053 | 2047 |
2054 void ExtensionPrefs::PopulateExtensionInfoPrefs( | 2048 void ExtensionPrefs::PopulateExtensionInfoPrefs( |
2055 const Extension* extension, | 2049 const Extension* extension, |
2056 const base::Time install_time, | 2050 const base::Time install_time, |
2057 Extension::State initial_state, | 2051 Extension::State initial_state, |
2058 int install_flags, | 2052 int install_flags, |
2059 const std::string& install_parameter, | 2053 const std::string& install_parameter, |
2060 base::DictionaryValue* extension_dict) { | 2054 base::DictionaryValue* extension_dict) { |
2061 // Leave the state blank for component extensions so that old chrome versions | 2055 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, | 2056 extension_dict->Set(kPrefLocation, |
2068 new base::FundamentalValue(extension->location())); | 2057 new base::FundamentalValue(extension->location())); |
2069 extension_dict->Set(kPrefCreationFlags, | 2058 extension_dict->Set(kPrefCreationFlags, |
2070 new base::FundamentalValue(extension->creation_flags())); | 2059 new base::FundamentalValue(extension->creation_flags())); |
2071 extension_dict->Set(kPrefFromWebStore, | 2060 extension_dict->Set(kPrefFromWebStore, |
2072 new base::FundamentalValue(extension->from_webstore())); | 2061 new base::FundamentalValue(extension->from_webstore())); |
2073 extension_dict->Set(kPrefFromBookmark, | 2062 extension_dict->Set(kPrefFromBookmark, |
2074 new base::FundamentalValue(extension->from_bookmark())); | 2063 new base::FundamentalValue(extension->from_bookmark())); |
2075 extension_dict->Set( | 2064 extension_dict->Set( |
2076 kPrefWasInstalledByDefault, | 2065 kPrefWasInstalledByDefault, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2201 extension_pref_value_map_->RegisterExtension( | 2190 extension_pref_value_map_->RegisterExtension( |
2202 extension_id, install_time, is_enabled, is_incognito_enabled); | 2191 extension_id, install_time, is_enabled, is_incognito_enabled); |
2203 | 2192 |
2204 FOR_EACH_OBSERVER( | 2193 FOR_EACH_OBSERVER( |
2205 ExtensionPrefsObserver, | 2194 ExtensionPrefsObserver, |
2206 observer_list_, | 2195 observer_list_, |
2207 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 2196 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
2208 } | 2197 } |
2209 | 2198 |
2210 } // namespace extensions | 2199 } // namespace extensions |
OLD | NEW |