OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/json/json_value_serializer.h" | 9 #include "base/json/json_value_serializer.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 local_state_(local_state), | 35 local_state_(local_state), |
36 extension_service_(extension_service) { | 36 extension_service_(extension_service) { |
37 pref_change_registrar_.Init(prefs); | 37 pref_change_registrar_.Init(prefs); |
38 | 38 |
39 // This pref is set by policy. We have to watch it for change because on | 39 // This pref is set by policy. We have to watch it for change because on |
40 // ChromeOS, policy isn't loaded until after the browser process is started. | 40 // ChromeOS, policy isn't loaded until after the browser process is started. |
41 pref_change_registrar_.Add(prefs::kEnterpriseWebStoreURL, this); | 41 pref_change_registrar_.Add(prefs::kEnterpriseWebStoreURL, this); |
42 } | 42 } |
43 | 43 |
44 ComponentLoader::~ComponentLoader() { | 44 ComponentLoader::~ComponentLoader() { |
| 45 ClearAllRegistered(); |
45 } | 46 } |
46 | 47 |
47 void ComponentLoader::LoadAll() { | 48 void ComponentLoader::LoadAll() { |
48 for (RegisteredComponentExtensions::iterator it = | 49 for (RegisteredComponentExtensions::iterator it = |
49 component_extensions_.begin(); | 50 component_extensions_.begin(); |
50 it != component_extensions_.end(); ++it) { | 51 it != component_extensions_.end(); ++it) { |
51 Load(*it); | 52 Load(*it); |
52 } | 53 } |
53 } | 54 } |
54 | 55 |
55 DictionaryValue* ComponentLoader::ParseManifest( | 56 DictionaryValue* ComponentLoader::ParseManifest( |
56 const std::string& manifest_contents) const { | 57 const std::string& manifest_contents) const { |
57 JSONStringValueSerializer serializer(manifest_contents); | 58 JSONStringValueSerializer serializer(manifest_contents); |
58 scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL)); | 59 scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL)); |
59 | 60 |
60 if (!manifest.get() || !manifest->IsType(Value::TYPE_DICTIONARY)) { | 61 if (!manifest.get() || !manifest->IsType(Value::TYPE_DICTIONARY)) { |
61 LOG(ERROR) << "Failed to parse extension manifest."; | 62 LOG(ERROR) << "Failed to parse extension manifest."; |
62 return NULL; | 63 return NULL; |
63 } | 64 } |
64 // Transfer ownership to the caller. | 65 // Transfer ownership to the caller. |
65 return static_cast<DictionaryValue*>(manifest.release()); | 66 return static_cast<DictionaryValue*>(manifest.release()); |
66 } | 67 } |
67 | 68 |
| 69 void ComponentLoader::ClearAllRegistered() { |
| 70 for (RegisteredComponentExtensions::iterator it = |
| 71 component_extensions_.begin(); |
| 72 it != component_extensions_.end(); ++it) { |
| 73 delete it->manifest; |
| 74 } |
| 75 |
| 76 component_extensions_.clear(); |
| 77 } |
| 78 |
68 const Extension* ComponentLoader::Add( | 79 const Extension* ComponentLoader::Add( |
69 int manifest_resource_id, | 80 int manifest_resource_id, |
70 const FilePath& root_directory) { | 81 const FilePath& root_directory) { |
71 std::string manifest_contents = | 82 std::string manifest_contents = |
72 ResourceBundle::GetSharedInstance().GetRawDataResource( | 83 ResourceBundle::GetSharedInstance().GetRawDataResource( |
73 manifest_resource_id).as_string(); | 84 manifest_resource_id).as_string(); |
74 return Add(manifest_contents, root_directory); | 85 return Add(manifest_contents, root_directory); |
75 } | 86 } |
76 | 87 |
77 const Extension* ComponentLoader::Add( | 88 const Extension* ComponentLoader::Add( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // Find the ComponentExtensionInfo for the extension. | 139 // Find the ComponentExtensionInfo for the extension. |
129 RegisteredComponentExtensions::iterator it = component_extensions_.begin(); | 140 RegisteredComponentExtensions::iterator it = component_extensions_.begin(); |
130 for (; it != component_extensions_.end(); ++it) { | 141 for (; it != component_extensions_.end(); ++it) { |
131 if (it->root_directory == root_directory) | 142 if (it->root_directory == root_directory) |
132 break; | 143 break; |
133 } | 144 } |
134 // If the extension is not in the list, there's nothing to do. | 145 // If the extension is not in the list, there's nothing to do. |
135 if (it == component_extensions_.end()) | 146 if (it == component_extensions_.end()) |
136 return; | 147 return; |
137 | 148 |
138 const DictionaryValue* manifest = it->manifest; | 149 // The list owns the dictionary, so it must be deleted after removal. |
| 150 scoped_ptr<const DictionaryValue> manifest(it->manifest); |
139 | 151 |
140 // Remove the extension from the list of registered extensions. | 152 // Remove the extension from the list of registered extensions. |
141 *it = component_extensions_.back(); | 153 *it = component_extensions_.back(); |
142 component_extensions_.pop_back(); | 154 component_extensions_.pop_back(); |
143 | 155 |
144 // Determine the extension id and unload the extension. | 156 // Determine the extension id and unload the extension. |
145 std::string public_key; | 157 std::string public_key; |
146 std::string public_key_bytes; | 158 std::string public_key_bytes; |
147 std::string id; | 159 std::string id; |
148 if (!manifest->GetString( | 160 if (!manifest->GetString( |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) { | 285 void ComponentLoader::RegisterUserPrefs(PrefService* prefs) { |
274 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL, | 286 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreURL, |
275 std::string() /* default_value */, | 287 std::string() /* default_value */, |
276 PrefService::UNSYNCABLE_PREF); | 288 PrefService::UNSYNCABLE_PREF); |
277 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName, | 289 prefs->RegisterStringPref(prefs::kEnterpriseWebStoreName, |
278 std::string() /* default_value */, | 290 std::string() /* default_value */, |
279 PrefService::UNSYNCABLE_PREF); | 291 PrefService::UNSYNCABLE_PREF); |
280 } | 292 } |
281 | 293 |
282 } // namespace extensions | 294 } // namespace extensions |
OLD | NEW |