| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.LoadAllComponentTime"); | 143 SCOPED_UMA_HISTOGRAM_TIMER("Extensions.LoadAllComponentTime"); |
| 144 | 144 |
| 145 for (RegisteredComponentExtensions::iterator it = | 145 for (RegisteredComponentExtensions::iterator it = |
| 146 component_extensions_.begin(); | 146 component_extensions_.begin(); |
| 147 it != component_extensions_.end(); ++it) { | 147 it != component_extensions_.end(); ++it) { |
| 148 Load(*it); | 148 Load(*it); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 base::DictionaryValue* ComponentLoader::ParseManifest( | 152 base::DictionaryValue* ComponentLoader::ParseManifest( |
| 153 const std::string& manifest_contents) const { | 153 base::StringPiece manifest_contents) const { |
| 154 JSONStringValueDeserializer deserializer(manifest_contents); | 154 JSONStringValueDeserializer deserializer(manifest_contents); |
| 155 std::unique_ptr<base::Value> manifest = deserializer.Deserialize(NULL, NULL); | 155 std::unique_ptr<base::Value> manifest = deserializer.Deserialize(NULL, NULL); |
| 156 | 156 |
| 157 if (!manifest.get() || !manifest->IsType(base::Value::TYPE_DICTIONARY)) { | 157 if (!manifest.get() || !manifest->IsType(base::Value::TYPE_DICTIONARY)) { |
| 158 LOG(ERROR) << "Failed to parse extension manifest."; | 158 LOG(ERROR) << "Failed to parse extension manifest."; |
| 159 return NULL; | 159 return NULL; |
| 160 } | 160 } |
| 161 // Transfer ownership to the caller. | 161 // Transfer ownership to the caller. |
| 162 return static_cast<base::DictionaryValue*>(manifest.release()); | 162 return static_cast<base::DictionaryValue*>(manifest.release()); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void ComponentLoader::ClearAllRegistered() { | 165 void ComponentLoader::ClearAllRegistered() { |
| 166 for (RegisteredComponentExtensions::iterator it = | 166 for (RegisteredComponentExtensions::iterator it = |
| 167 component_extensions_.begin(); | 167 component_extensions_.begin(); |
| 168 it != component_extensions_.end(); ++it) { | 168 it != component_extensions_.end(); ++it) { |
| 169 delete it->manifest; | 169 delete it->manifest; |
| 170 } | 170 } |
| 171 | 171 |
| 172 component_extensions_.clear(); | 172 component_extensions_.clear(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 std::string ComponentLoader::GetExtensionID( | 175 std::string ComponentLoader::GetExtensionID( |
| 176 int manifest_resource_id, | 176 int manifest_resource_id, |
| 177 const base::FilePath& root_directory) { | 177 const base::FilePath& root_directory) { |
| 178 std::string manifest_contents = ResourceBundle::GetSharedInstance(). | 178 base::DictionaryValue* manifest = |
| 179 GetRawDataResource(manifest_resource_id).as_string(); | 179 ParseManifest(ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 180 base::DictionaryValue* manifest = ParseManifest(manifest_contents); | 180 manifest_resource_id)); |
| 181 if (!manifest) | 181 if (!manifest) |
| 182 return std::string(); | 182 return std::string(); |
| 183 | 183 |
| 184 ComponentExtensionInfo info(manifest, root_directory); | 184 ComponentExtensionInfo info(manifest, root_directory); |
| 185 return info.extension_id; | 185 return info.extension_id; |
| 186 } | 186 } |
| 187 | 187 |
| 188 std::string ComponentLoader::Add(int manifest_resource_id, | 188 std::string ComponentLoader::Add(int manifest_resource_id, |
| 189 const base::FilePath& root_directory) { | 189 const base::FilePath& root_directory) { |
| 190 if (!ignore_whitelist_for_testing_ && | 190 if (!ignore_whitelist_for_testing_ && |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 | 411 |
| 412 void ComponentLoader::AddWithNameAndDescription( | 412 void ComponentLoader::AddWithNameAndDescription( |
| 413 int manifest_resource_id, | 413 int manifest_resource_id, |
| 414 const base::FilePath& root_directory, | 414 const base::FilePath& root_directory, |
| 415 const std::string& name_string, | 415 const std::string& name_string, |
| 416 const std::string& description_string) { | 416 const std::string& description_string) { |
| 417 if (!ignore_whitelist_for_testing_ && | 417 if (!ignore_whitelist_for_testing_ && |
| 418 !IsComponentExtensionWhitelisted(manifest_resource_id)) | 418 !IsComponentExtensionWhitelisted(manifest_resource_id)) |
| 419 return; | 419 return; |
| 420 | 420 |
| 421 std::string manifest_contents = | 421 base::StringPiece manifest_contents = |
| 422 ResourceBundle::GetSharedInstance().GetRawDataResource( | 422 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 423 manifest_resource_id).as_string(); | 423 manifest_resource_id); |
| 424 | 424 |
| 425 // The Value is kept for the lifetime of the ComponentLoader. This is | 425 // The Value is kept for the lifetime of the ComponentLoader. This is |
| 426 // required in case LoadAll() is called again. | 426 // required in case LoadAll() is called again. |
| 427 base::DictionaryValue* manifest = ParseManifest(manifest_contents); | 427 base::DictionaryValue* manifest = ParseManifest(manifest_contents); |
| 428 | 428 |
| 429 if (manifest) { | 429 if (manifest) { |
| 430 manifest->SetString(manifest_keys::kName, name_string); | 430 manifest->SetString(manifest_keys::kName, name_string); |
| 431 manifest->SetString(manifest_keys::kDescription, description_string); | 431 manifest->SetString(manifest_keys::kDescription, description_string); |
| 432 Add(manifest, root_directory, true); | 432 Add(manifest, root_directory, true); |
| 433 } | 433 } |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 manifest.release(), | 718 manifest.release(), |
| 719 root_directory, | 719 root_directory, |
| 720 false); | 720 false); |
| 721 CHECK_EQ(extension_id, actual_extension_id); | 721 CHECK_EQ(extension_id, actual_extension_id); |
| 722 if (!done_cb.is_null()) | 722 if (!done_cb.is_null()) |
| 723 done_cb.Run(); | 723 done_cb.Run(); |
| 724 } | 724 } |
| 725 #endif | 725 #endif |
| 726 | 726 |
| 727 } // namespace extensions | 727 } // namespace extensions |
| OLD | NEW |