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

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

Issue 1582022: Unpack extensions inside chrome's directory. (Closed)
Patch Set: Final rebase. Created 10 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
« no previous file with comments | « chrome/common/extensions/extension_file_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/scoped_handle.h" 8 #include "base/scoped_handle.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/thread.h" 11 #include "base/thread.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "net/base/file_stream.h" 13 #include "net/base/file_stream.h"
14 #include "chrome/common/common_param_traits.h" 14 #include "chrome/common/common_param_traits.h"
15 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
16 #include "chrome/common/extensions/extension_constants.h" 16 #include "chrome/common/extensions/extension_constants.h"
17 #include "chrome/common/extensions/extension_file_util.h" 17 #include "chrome/common/extensions/extension_file_util.h"
18 #include "chrome/common/extensions/extension_l10n_util.h" 18 #include "chrome/common/extensions/extension_l10n_util.h"
19 #include "chrome/common/json_value_serializer.h" 19 #include "chrome/common/json_value_serializer.h"
20 #include "chrome/common/notification_service.h" 20 #include "chrome/common/notification_service.h"
21 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
22 #include "chrome/common/zip.h" 22 #include "chrome/common/zip.h"
23 #include "ipc/ipc_message_utils.h" 23 #include "ipc/ipc_message_utils.h"
24 #include "third_party/skia/include/core/SkBitmap.h" 24 #include "third_party/skia/include/core/SkBitmap.h"
25 #include "webkit/glue/image_decoder.h" 25 #include "webkit/glue/image_decoder.h"
26 26
27 namespace errors = extension_manifest_errors; 27 namespace errors = extension_manifest_errors;
28 namespace keys = extension_manifest_keys; 28 namespace keys = extension_manifest_keys;
29 namespace filenames = extension_filenames;
29 30
30 namespace { 31 namespace {
31 // The name of a temporary directory to install an extension into for
32 // validation before finalizing install.
33 const char kTempExtensionName[] = "TEMP_INSTALL";
34
35 // The file to write our decoded images to, relative to the extension_path.
36 const char kDecodedImagesFilename[] = "DECODED_IMAGES";
37
38 // The file to write our decoded message catalogs to, relative to the
39 // extension_path.
40 const char kDecodedMessageCatalogsFilename[] = "DECODED_MESSAGE_CATALOGS";
41 32
42 // Errors 33 // Errors
43 const char* kCouldNotCreateDirectoryError = 34 const char* kCouldNotCreateDirectoryError =
44 "Could not create directory for unzipping: "; 35 "Could not create directory for unzipping: ";
45 const char* kCouldNotDecodeImageError = "Could not decode theme image."; 36 const char* kCouldNotDecodeImageError = "Could not decode theme image.";
46 const char* kCouldNotUnzipExtension = "Could not unzip extension."; 37 const char* kCouldNotUnzipExtension = "Could not unzip extension.";
47 const char* kPathNamesMustBeAbsoluteOrLocalError = 38 const char* kPathNamesMustBeAbsoluteOrLocalError =
48 "Path names must not be absolute or contain '..'."; 39 "Path names must not be absolute or contain '..'.";
49 40
50 // A limit to stop us passing dangerously large canvases to the browser. 41 // A limit to stop us passing dangerously large canvases to the browser.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 132 }
142 133
143 return true; 134 return true;
144 } 135 }
145 136
146 bool ExtensionUnpacker::Run() { 137 bool ExtensionUnpacker::Run() {
147 LOG(INFO) << "Installing extension " << extension_path_.value(); 138 LOG(INFO) << "Installing extension " << extension_path_.value();
148 139
149 // <profile>/Extensions/INSTALL_TEMP/<version> 140 // <profile>/Extensions/INSTALL_TEMP/<version>
150 temp_install_dir_ = 141 temp_install_dir_ =
151 extension_path_.DirName().AppendASCII(kTempExtensionName); 142 extension_path_.DirName().AppendASCII(filenames::kTempExtensionName);
152 if (!file_util::CreateDirectory(temp_install_dir_)) { 143 if (!file_util::CreateDirectory(temp_install_dir_)) {
153 #if defined(OS_WIN) 144 #if defined(OS_WIN)
154 std::string dir_string = WideToUTF8(temp_install_dir_.value()); 145 std::string dir_string = WideToUTF8(temp_install_dir_.value());
155 #else 146 #else
156 std::string dir_string = temp_install_dir_.value(); 147 std::string dir_string = temp_install_dir_.value();
157 #endif 148 #endif
158 SetError(kCouldNotCreateDirectoryError + dir_string); 149 SetError(kCouldNotCreateDirectoryError + dir_string);
159 return false; 150 return false;
160 } 151 }
161 152
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 return false; // Error was already reported. 193 return false; // Error was already reported.
203 } 194 }
204 195
205 return true; 196 return true;
206 } 197 }
207 198
208 bool ExtensionUnpacker::DumpImagesToFile() { 199 bool ExtensionUnpacker::DumpImagesToFile() {
209 IPC::Message pickle; // We use a Message so we can use WriteParam. 200 IPC::Message pickle; // We use a Message so we can use WriteParam.
210 IPC::WriteParam(&pickle, decoded_images_); 201 IPC::WriteParam(&pickle, decoded_images_);
211 202
212 FilePath path = extension_path_.DirName().AppendASCII(kDecodedImagesFilename); 203 FilePath path = extension_path_.DirName().AppendASCII(
204 filenames::kDecodedImagesFilename);
213 if (!file_util::WriteFile(path, static_cast<const char*>(pickle.data()), 205 if (!file_util::WriteFile(path, static_cast<const char*>(pickle.data()),
214 pickle.size())) { 206 pickle.size())) {
215 SetError("Could not write image data to disk."); 207 SetError("Could not write image data to disk.");
216 return false; 208 return false;
217 } 209 }
218 210
219 return true; 211 return true;
220 } 212 }
221 213
222 bool ExtensionUnpacker::DumpMessageCatalogsToFile() { 214 bool ExtensionUnpacker::DumpMessageCatalogsToFile() {
223 IPC::Message pickle; 215 IPC::Message pickle;
224 IPC::WriteParam(&pickle, *parsed_catalogs_.get()); 216 IPC::WriteParam(&pickle, *parsed_catalogs_.get());
225 217
226 FilePath path = extension_path_.DirName().AppendASCII( 218 FilePath path = extension_path_.DirName().AppendASCII(
227 kDecodedMessageCatalogsFilename); 219 filenames::kDecodedMessageCatalogsFilename);
228 if (!file_util::WriteFile(path, static_cast<const char*>(pickle.data()), 220 if (!file_util::WriteFile(path, static_cast<const char*>(pickle.data()),
229 pickle.size())) { 221 pickle.size())) {
230 SetError("Could not write message catalogs to disk."); 222 SetError("Could not write message catalogs to disk.");
231 return false; 223 return false;
232 } 224 }
233 225
234 return true; 226 return true;
235 } 227 }
236 228
237 // static 229 // static
238 bool ExtensionUnpacker::ReadImagesFromFile(const FilePath& extension_path, 230 bool ExtensionUnpacker::ReadImagesFromFile(const FilePath& extension_path,
239 DecodedImages* images) { 231 DecodedImages* images) {
240 FilePath path = extension_path.AppendASCII(kDecodedImagesFilename); 232 FilePath path = extension_path.AppendASCII(filenames::kDecodedImagesFilename);
241 std::string file_str; 233 std::string file_str;
242 if (!file_util::ReadFileToString(path, &file_str)) 234 if (!file_util::ReadFileToString(path, &file_str))
243 return false; 235 return false;
244 236
245 IPC::Message pickle(file_str.data(), file_str.size()); 237 IPC::Message pickle(file_str.data(), file_str.size());
246 void* iter = NULL; 238 void* iter = NULL;
247 return IPC::ReadParam(&pickle, &iter, images); 239 return IPC::ReadParam(&pickle, &iter, images);
248 } 240 }
249 241
250 // static 242 // static
251 bool ExtensionUnpacker::ReadMessageCatalogsFromFile( 243 bool ExtensionUnpacker::ReadMessageCatalogsFromFile(
252 const FilePath& extension_path, DictionaryValue* catalogs) { 244 const FilePath& extension_path, DictionaryValue* catalogs) {
253 FilePath path = extension_path.AppendASCII(kDecodedMessageCatalogsFilename); 245 FilePath path = extension_path.AppendASCII(
246 filenames::kDecodedMessageCatalogsFilename);
254 std::string file_str; 247 std::string file_str;
255 if (!file_util::ReadFileToString(path, &file_str)) 248 if (!file_util::ReadFileToString(path, &file_str))
256 return false; 249 return false;
257 250
258 IPC::Message pickle(file_str.data(), file_str.size()); 251 IPC::Message pickle(file_str.data(), file_str.size());
259 void* iter = NULL; 252 void* iter = NULL;
260 return IPC::ReadParam(&pickle, &iter, catalogs); 253 return IPC::ReadParam(&pickle, &iter, catalogs);
261 } 254 }
262 255
263 bool ExtensionUnpacker::AddDecodedImage(const FilePath& path) { 256 bool ExtensionUnpacker::AddDecodedImage(const FilePath& path) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 294
302 parsed_catalogs_->Set(relative_path.DirName().ToWStringHack(), 295 parsed_catalogs_->Set(relative_path.DirName().ToWStringHack(),
303 root.release()); 296 root.release());
304 297
305 return true; 298 return true;
306 } 299 }
307 300
308 void ExtensionUnpacker::SetError(const std::string &error) { 301 void ExtensionUnpacker::SetError(const std::string &error) {
309 error_message_ = error; 302 error_message_ = error;
310 } 303 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_file_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698