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 base::FilePath::StringType path; |
tapted
2014/08/13 00:25:07
nit: `path` isn't used until the very end of the f
Anand Mistry (off Chromium)
2014/08/13 01:53:15
Done.
| |
1341 if (!extension->GetString(kPrefPath, &path)) | 1341 if (!extension->GetString(kPrefPath, &path)) |
1342 return scoped_ptr<ExtensionInfo>(); | 1342 return scoped_ptr<ExtensionInfo>(); |
1343 | 1343 |
1344 // Make path absolute. Unpacked extensions will already have absolute paths, | 1344 // Make path absolute. Unpacked extensions will already have absolute paths, |
1345 // otherwise make it so. | 1345 // otherwise make it so. |
1346 Manifest::Location location = static_cast<Manifest::Location>(location_value); | 1346 Manifest::Location location = static_cast<Manifest::Location>(location_value); |
1347 #if !defined(OS_CHROMEOS) | 1347 // Most (but not all) extension types don't have absolute paths. |
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()) { | 1348 if (!base::FilePath(path).IsAbsolute()) { |
tapted
2014/08/13 00:25:07
nit: no curlies
Anand Mistry (off Chromium)
2014/08/13 01:53:15
Yuk! I prefer braces.
| |
1355 #endif // !defined(OS_CHROMEOS) | |
1356 path = install_directory_.Append(path).value(); | 1349 path = install_directory_.Append(path).value(); |
1357 } | 1350 } |
1358 | 1351 |
1352 if (location == Manifest::COMPONENT) { | |
1353 // Component extensions are ignored. Replicates the state before this | |
1354 // change. | |
1355 // TODO(amistry): Is this what we want? | |
tapted
2014/08/13 00:25:07
yep! But I think the sentiment we want is: Compone
Anand Mistry (off Chromium)
2014/08/13 01:53:15
Done.
| |
1356 return scoped_ptr<ExtensionInfo>(); | |
1357 } | |
1358 | |
1359 // Only the following extension types have data saved in the preferences. | 1359 // Only the following extension types have data saved in the preferences. |
1360 if (location != Manifest::INTERNAL && | 1360 if (location != Manifest::INTERNAL && |
1361 !Manifest::IsUnpackedLocation(location) && | 1361 !Manifest::IsUnpackedLocation(location) && |
1362 !Manifest::IsExternalLocation(location)) { | 1362 !Manifest::IsExternalLocation(location)) { |
1363 NOTREACHED(); | 1363 NOTREACHED(); |
1364 return scoped_ptr<ExtensionInfo>(); | 1364 return scoped_ptr<ExtensionInfo>(); |
1365 } | 1365 } |
1366 | 1366 |
1367 const base::DictionaryValue* manifest = NULL; | 1367 const base::DictionaryValue* manifest = NULL; |
1368 if (!Manifest::IsUnpackedLocation(location) && | 1368 if (!Manifest::IsUnpackedLocation(location) && |
1369 !extension->GetDictionary(kPrefManifest, &manifest)) { | 1369 !extension->GetDictionary(kPrefManifest, &manifest)) { |
1370 LOG(WARNING) << "Missing manifest for extension " << extension_id; | 1370 LOG(WARNING) << "Missing manifest for extension " << extension_id; |
1371 // Just a warning for now. | 1371 // Just a warning for now. |
1372 } | 1372 } |
1373 | 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)) { |
tapted
2014/08/13 00:25:07
I'd probably combine this with the statement below
Anand Mistry (off Chromium)
2014/08/13 01:53:15
Done.
| |
1388 state_value == Extension::ENABLED_COMPONENT) { | |
1389 // Old preferences files may not have kPrefState for component extensions. | 1388 // Old preferences files may not have kPrefState for component extensions. |
1390 return scoped_ptr<ExtensionInfo>(); | 1389 return scoped_ptr<ExtensionInfo>(); |
1391 } | 1390 } |
1392 | 1391 |
1393 if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { | 1392 if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { |
1394 LOG(WARNING) << "External extension with id " << extension_id | 1393 LOG(WARNING) << "External extension with id " << extension_id |
1395 << " has been uninstalled by the user"; | 1394 << " has been uninstalled by the user"; |
1396 return scoped_ptr<ExtensionInfo>(); | 1395 return scoped_ptr<ExtensionInfo>(); |
1397 } | 1396 } |
1398 | 1397 |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2054 void ExtensionPrefs::PopulateExtensionInfoPrefs( | 2053 void ExtensionPrefs::PopulateExtensionInfoPrefs( |
2055 const Extension* extension, | 2054 const Extension* extension, |
2056 const base::Time install_time, | 2055 const base::Time install_time, |
2057 Extension::State initial_state, | 2056 Extension::State initial_state, |
2058 int install_flags, | 2057 int install_flags, |
2059 const std::string& install_parameter, | 2058 const std::string& install_parameter, |
2060 base::DictionaryValue* extension_dict) { | 2059 base::DictionaryValue* extension_dict) { |
2061 // Leave the state blank for component extensions so that old chrome versions | 2060 // Leave the state blank for component extensions so that old chrome versions |
2062 // loading new profiles do not fail in GetInstalledExtensionInfo. Older | 2061 // loading new profiles do not fail in GetInstalledExtensionInfo. Older |
2063 // Chrome versions would only check for an omitted state. | 2062 // Chrome versions would only check for an omitted state. |
2064 if (initial_state != Extension::ENABLED_COMPONENT) | 2063 if (extension->manifest()->location() != Manifest::COMPONENT) |
tapted
2014/08/13 00:25:07
This extra check can probably be removed (i.e. wri
Anand Mistry (off Chromium)
2014/08/13 01:53:15
Done.
tapted
2014/08/13 03:06:55
so yeah - looks like this can't tickle a crash out
| |
2065 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state)); | 2064 extension_dict->Set(kPrefState, new base::FundamentalValue(initial_state)); |
2066 | 2065 |
2067 extension_dict->Set(kPrefLocation, | 2066 extension_dict->Set(kPrefLocation, |
2068 new base::FundamentalValue(extension->location())); | 2067 new base::FundamentalValue(extension->location())); |
2069 extension_dict->Set(kPrefCreationFlags, | 2068 extension_dict->Set(kPrefCreationFlags, |
2070 new base::FundamentalValue(extension->creation_flags())); | 2069 new base::FundamentalValue(extension->creation_flags())); |
2071 extension_dict->Set(kPrefFromWebStore, | 2070 extension_dict->Set(kPrefFromWebStore, |
2072 new base::FundamentalValue(extension->from_webstore())); | 2071 new base::FundamentalValue(extension->from_webstore())); |
2073 extension_dict->Set(kPrefFromBookmark, | 2072 extension_dict->Set(kPrefFromBookmark, |
2074 new base::FundamentalValue(extension->from_bookmark())); | 2073 new base::FundamentalValue(extension->from_bookmark())); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2201 extension_pref_value_map_->RegisterExtension( | 2200 extension_pref_value_map_->RegisterExtension( |
2202 extension_id, install_time, is_enabled, is_incognito_enabled); | 2201 extension_id, install_time, is_enabled, is_incognito_enabled); |
2203 | 2202 |
2204 FOR_EACH_OBSERVER( | 2203 FOR_EACH_OBSERVER( |
2205 ExtensionPrefsObserver, | 2204 ExtensionPrefsObserver, |
2206 observer_list_, | 2205 observer_list_, |
2207 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 2206 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
2208 } | 2207 } |
2209 | 2208 |
2210 } // namespace extensions | 2209 } // namespace extensions |
OLD | NEW |