| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/component_loader.h" | 5 #include "chrome/browser/extensions/component_loader.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 std::string GenerateId(const DictionaryValue* manifest, | 61 std::string GenerateId(const DictionaryValue* manifest, |
| 62 const base::FilePath& path) { | 62 const base::FilePath& path) { |
| 63 std::string raw_key; | 63 std::string raw_key; |
| 64 std::string id_input; | 64 std::string id_input; |
| 65 CHECK(manifest->GetString(extension_manifest_keys::kPublicKey, &raw_key)); | 65 CHECK(manifest->GetString(extension_manifest_keys::kPublicKey, &raw_key)); |
| 66 CHECK(Extension::ParsePEMKeyBytes(raw_key, &id_input)); | 66 CHECK(Extension::ParsePEMKeyBytes(raw_key, &id_input)); |
| 67 std::string id = id_util::GenerateId(id_input); | 67 std::string id = id_util::GenerateId(id_input); |
| 68 return id; | 68 return id; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void AbsolutizeRelativeToResourceDir(base::FilePath* directory) { |
| 72 if (!directory->IsAbsolute()) { |
| 73 base::FilePath root_directory; |
| 74 CHECK(PathService::Get(chrome::DIR_RESOURCES, &root_directory)); |
| 75 *directory = root_directory.Append(*directory); |
| 76 } |
| 77 } |
| 78 |
| 71 } // namespace | 79 } // namespace |
| 72 | 80 |
| 73 ComponentLoader::ComponentExtensionInfo::ComponentExtensionInfo( | 81 ComponentLoader::ComponentExtensionInfo::ComponentExtensionInfo( |
| 74 const DictionaryValue* manifest, const base::FilePath& directory) | 82 const DictionaryValue* manifest, const base::FilePath& directory) |
| 75 : manifest(manifest), | 83 : manifest(manifest), |
| 76 root_directory(directory) { | 84 root_directory(directory) { |
| 77 if (!root_directory.IsAbsolute()) { | 85 AbsolutizeRelativeToResourceDir(&root_directory); |
| 78 CHECK(PathService::Get(chrome::DIR_RESOURCES, &root_directory)); | |
| 79 root_directory = root_directory.Append(directory); | |
| 80 } | |
| 81 extension_id = GenerateId(manifest, root_directory); | 86 extension_id = GenerateId(manifest, root_directory); |
| 82 } | 87 } |
| 83 | 88 |
| 84 ComponentLoader::ComponentLoader(ExtensionServiceInterface* extension_service, | 89 ComponentLoader::ComponentLoader(ExtensionServiceInterface* extension_service, |
| 85 PrefService* profile_prefs, | 90 PrefService* profile_prefs, |
| 86 PrefService* local_state) | 91 PrefService* local_state) |
| 87 : profile_prefs_(profile_prefs), | 92 : profile_prefs_(profile_prefs), |
| 88 local_state_(local_state), | 93 local_state_(local_state), |
| 89 extension_service_(extension_service) { | 94 extension_service_(extension_service) { |
| 90 pref_change_registrar_.Init(profile_prefs); | 95 pref_change_registrar_.Init(profile_prefs); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 return; | 284 return; |
| 280 } | 285 } |
| 281 #endif // NDEBUG | 286 #endif // NDEBUG |
| 282 Add(IDR_IMAGE_LOADER_MANIFEST, | 287 Add(IDR_IMAGE_LOADER_MANIFEST, |
| 283 base::FilePath(FILE_PATH_LITERAL("image_loader"))); | 288 base::FilePath(FILE_PATH_LITERAL("image_loader"))); |
| 284 #endif // defined(IMAGE_LOADER_EXTENSION) | 289 #endif // defined(IMAGE_LOADER_EXTENSION) |
| 285 } | 290 } |
| 286 | 291 |
| 287 void ComponentLoader::AddOrReloadEnterpriseWebStore() { | 292 void ComponentLoader::AddOrReloadEnterpriseWebStore() { |
| 288 base::FilePath path(FILE_PATH_LITERAL("enterprise_web_store")); | 293 base::FilePath path(FILE_PATH_LITERAL("enterprise_web_store")); |
| 294 AbsolutizeRelativeToResourceDir(&path); |
| 289 | 295 |
| 290 // Remove the extension if it was already loaded. | 296 // Remove the extension if it was already loaded. |
| 291 Remove(path); | 297 Remove(path); |
| 292 | 298 |
| 293 std::string enterprise_webstore_url = | 299 std::string enterprise_webstore_url = |
| 294 profile_prefs_->GetString(prefs::kEnterpriseWebStoreURL); | 300 profile_prefs_->GetString(prefs::kEnterpriseWebStoreURL); |
| 295 | 301 |
| 296 // Load the extension only if the URL preference is set. | 302 // Load the extension only if the URL preference is set. |
| 297 if (!enterprise_webstore_url.empty()) { | 303 if (!enterprise_webstore_url.empty()) { |
| 298 std::string manifest_contents = | 304 std::string manifest_contents = |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 prefs::kEnterpriseWebStoreURL, | 498 prefs::kEnterpriseWebStoreURL, |
| 493 std::string() /* default_value */, | 499 std::string() /* default_value */, |
| 494 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 500 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 495 registry->RegisterStringPref( | 501 registry->RegisterStringPref( |
| 496 prefs::kEnterpriseWebStoreName, | 502 prefs::kEnterpriseWebStoreName, |
| 497 std::string() /* default_value */, | 503 std::string() /* default_value */, |
| 498 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 504 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 499 } | 505 } |
| 500 | 506 |
| 501 } // namespace extensions | 507 } // namespace extensions |
| OLD | NEW |