Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Side by Side Diff: chrome/common/extensions/extension_unpacker.cc

Issue 10375021: Move Extension into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Take 6 Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/extensions/extension_unpacker.h" 5 #include "chrome/common/extensions/extension_unpacker.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/json/json_file_value_serializer.h" 10 #include "base/json/json_file_value_serializer.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 } 80 }
81 81
82 return false; 82 return false;
83 } 83 }
84 84
85 } // namespace 85 } // namespace
86 86
87 ExtensionUnpacker::ExtensionUnpacker(const FilePath& extension_path, 87 ExtensionUnpacker::ExtensionUnpacker(const FilePath& extension_path,
88 const std::string& extension_id, 88 const std::string& extension_id,
89 Extension::Location location, 89 extensions::Extension::Location location,
90 int creation_flags) 90 int creation_flags)
91 : extension_path_(extension_path), 91 : extension_path_(extension_path),
92 extension_id_(extension_id), 92 extension_id_(extension_id),
93 location_(location), 93 location_(location),
94 creation_flags_(creation_flags) { 94 creation_flags_(creation_flags) {
95 } 95 }
96 96
97 ExtensionUnpacker::~ExtensionUnpacker() { 97 ExtensionUnpacker::~ExtensionUnpacker() {
98 } 98 }
99 99
100 DictionaryValue* ExtensionUnpacker::ReadManifest() { 100 DictionaryValue* ExtensionUnpacker::ReadManifest() {
101 FilePath manifest_path = 101 FilePath manifest_path =
102 temp_install_dir_.Append(Extension::kManifestFilename); 102 temp_install_dir_.Append(extensions::Extension::kManifestFilename);
103 if (!file_util::PathExists(manifest_path)) { 103 if (!file_util::PathExists(manifest_path)) {
104 SetError(errors::kInvalidManifest); 104 SetError(errors::kInvalidManifest);
105 return NULL; 105 return NULL;
106 } 106 }
107 107
108 JSONFileValueSerializer serializer(manifest_path); 108 JSONFileValueSerializer serializer(manifest_path);
109 std::string error; 109 std::string error;
110 scoped_ptr<Value> root(serializer.Deserialize(NULL, &error)); 110 scoped_ptr<Value> root(serializer.Deserialize(NULL, &error));
111 if (!root.get()) { 111 if (!root.get()) {
112 SetError(error); 112 SetError(error);
113 return NULL; 113 return NULL;
114 } 114 }
115 115
116 if (!root->IsType(Value::TYPE_DICTIONARY)) { 116 if (!root->IsType(Value::TYPE_DICTIONARY)) {
117 SetError(errors::kInvalidManifest); 117 SetError(errors::kInvalidManifest);
118 return NULL; 118 return NULL;
119 } 119 }
120 120
121 return static_cast<DictionaryValue*>(root.release()); 121 return static_cast<DictionaryValue*>(root.release());
122 } 122 }
123 123
124 bool ExtensionUnpacker::ReadAllMessageCatalogs( 124 bool ExtensionUnpacker::ReadAllMessageCatalogs(
125 const std::string& default_locale) { 125 const std::string& default_locale) {
126 FilePath locales_path = 126 FilePath locales_path =
127 temp_install_dir_.Append(Extension::kLocaleFolder); 127 temp_install_dir_.Append(extensions::Extension::kLocaleFolder);
128 128
129 // Not all folders under _locales have to be valid locales. 129 // Not all folders under _locales have to be valid locales.
130 file_util::FileEnumerator locales(locales_path, 130 file_util::FileEnumerator locales(locales_path,
131 false, 131 false,
132 file_util::FileEnumerator::DIRECTORIES); 132 file_util::FileEnumerator::DIRECTORIES);
133 133
134 std::set<std::string> all_locales; 134 std::set<std::string> all_locales;
135 extension_l10n_util::GetAllLocales(&all_locales); 135 extension_l10n_util::GetAllLocales(&all_locales);
136 FilePath locale_path; 136 FilePath locale_path;
137 while (!(locale_path = locales.Next()).empty()) { 137 while (!(locale_path = locales.Next()).empty()) {
138 if (extension_l10n_util::ShouldSkipValidation(locales_path, locale_path, 138 if (extension_l10n_util::ShouldSkipValidation(locales_path, locale_path,
139 all_locales)) 139 all_locales))
140 continue; 140 continue;
141 141
142 FilePath messages_path = 142 FilePath messages_path =
143 locale_path.Append(Extension::kMessagesFilename); 143 locale_path.Append(extensions::Extension::kMessagesFilename);
144 144
145 if (!ReadMessageCatalog(messages_path)) 145 if (!ReadMessageCatalog(messages_path))
146 return false; 146 return false;
147 } 147 }
148 148
149 return true; 149 return true;
150 } 150 }
151 151
152 bool ExtensionUnpacker::Run() { 152 bool ExtensionUnpacker::Run() {
153 DVLOG(1) << "Installing extension " << extension_path_.value(); 153 DVLOG(1) << "Installing extension " << extension_path_.value();
(...skipping 17 matching lines...) Expand all
171 SetError(kCouldNotUnzipExtension); 171 SetError(kCouldNotUnzipExtension);
172 return false; 172 return false;
173 } 173 }
174 174
175 // Parse the manifest. 175 // Parse the manifest.
176 parsed_manifest_.reset(ReadManifest()); 176 parsed_manifest_.reset(ReadManifest());
177 if (!parsed_manifest_.get()) 177 if (!parsed_manifest_.get())
178 return false; // Error was already reported. 178 return false; // Error was already reported.
179 179
180 std::string error; 180 std::string error;
181 scoped_refptr<Extension> extension(Extension::Create( 181 scoped_refptr<extensions::Extension> extension(extensions::Extension::Create(
182 temp_install_dir_, 182 temp_install_dir_,
183 location_, 183 location_,
184 *parsed_manifest_, 184 *parsed_manifest_,
185 creation_flags_, 185 creation_flags_,
186 extension_id_, 186 extension_id_,
187 &error)); 187 &error));
188 if (!extension.get()) { 188 if (!extension.get()) {
189 SetError(error); 189 SetError(error);
190 return false; 190 return false;
191 } 191 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 return false; 319 return false;
320 } 320 }
321 parsed_catalogs_->Set(dir_name, root.release()); 321 parsed_catalogs_->Set(dir_name, root.release());
322 322
323 return true; 323 return true;
324 } 324 }
325 325
326 void ExtensionUnpacker::SetError(const std::string &error) { 326 void ExtensionUnpacker::SetError(const std::string &error) {
327 error_message_ = UTF8ToUTF16(error); 327 error_message_ = UTF8ToUTF16(error);
328 } 328 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_unpacker.h ('k') | chrome/common/extensions/extension_unpacker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698