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

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

Issue 10868050: Remove "theme" in extension/app unpacker error messages, make those messages localizable, and add u… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Applied suggestions in patch set 2 comments and added paths in errors. Created 8 years, 3 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 | Annotate | Revision Log
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/unpacker.h" 5 #include "chrome/common/extensions/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/i18n/rtl.h"
10 #include "base/json/json_file_value_serializer.h" 11 #include "base/json/json_file_value_serializer.h"
11 #include "base/memory/scoped_handle.h" 12 #include "base/memory/scoped_handle.h"
12 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
13 #include "base/string_util.h" 14 #include "base/string_util.h"
14 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
15 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/extensions/extension_manifest_constants.h" 19 #include "chrome/common/extensions/extension_manifest_constants.h"
19 #include "chrome/common/extensions/extension_file_util.h" 20 #include "chrome/common/extensions/extension_file_util.h"
20 #include "chrome/common/extensions/extension_l10n_util.h" 21 #include "chrome/common/extensions/extension_l10n_util.h"
21 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
22 #include "chrome/common/zip.h" 23 #include "chrome/common/zip.h"
23 #include "content/public/common/common_param_traits.h" 24 #include "content/public/common/common_param_traits.h"
25 #include "grit/generated_resources.h"
24 #include "ipc/ipc_message_utils.h" 26 #include "ipc/ipc_message_utils.h"
25 #include "net/base/file_stream.h" 27 #include "net/base/file_stream.h"
26 #include "third_party/skia/include/core/SkBitmap.h" 28 #include "third_party/skia/include/core/SkBitmap.h"
29 #include "ui/base/l10n/l10n_util.h"
27 #include "webkit/glue/image_decoder.h" 30 #include "webkit/glue/image_decoder.h"
28 31
29 namespace errors = extension_manifest_errors; 32 namespace errors = extension_manifest_errors;
30 namespace keys = extension_manifest_keys; 33 namespace keys = extension_manifest_keys;
31 namespace filenames = extension_filenames; 34 namespace filenames = extension_filenames;
32 35
33 namespace { 36 namespace {
34 37
35 // Errors
36 const char* kCouldNotCreateDirectoryError =
37 "Could not create directory for unzipping: ";
38 const char* kCouldNotDecodeImageError = "Could not decode theme image.";
39 const char* kCouldNotUnzipExtension = "Could not unzip extension.";
40 const char* kPathNamesMustBeAbsoluteOrLocalError =
41 "Path names must not be absolute or contain '..'.";
42
43 // A limit to stop us passing dangerously large canvases to the browser. 38 // A limit to stop us passing dangerously large canvases to the browser.
44 const int kMaxImageCanvas = 4096 * 4096; 39 const int kMaxImageCanvas = 4096 * 4096;
45 40
46 SkBitmap DecodeImage(const FilePath& path) { 41 SkBitmap DecodeImage(const FilePath& path) {
47 // Read the file from disk. 42 // Read the file from disk.
48 std::string file_contents; 43 std::string file_contents;
49 if (!file_util::PathExists(path) || 44 if (!file_util::PathExists(path) ||
50 !file_util::ReadFileToString(path, &file_contents)) { 45 !file_util::ReadFileToString(path, &file_contents)) {
51 return SkBitmap(); 46 return SkBitmap();
52 } 47 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 if (!ReadMessageCatalog(messages_path)) 141 if (!ReadMessageCatalog(messages_path))
147 return false; 142 return false;
148 } 143 }
149 144
150 return true; 145 return true;
151 } 146 }
152 147
153 bool Unpacker::Run() { 148 bool Unpacker::Run() {
154 DVLOG(1) << "Installing extension " << extension_path_.value(); 149 DVLOG(1) << "Installing extension " << extension_path_.value();
155 150
156 // <profile>/Extensions/INSTALL_TEMP/<version> 151 // <profile>/Extensions/CRX_INSTALL
dharcourt 2012/08/27 17:55:55 Corrected comment: Temporary installation director
157 temp_install_dir_ = 152 temp_install_dir_ =
158 extension_path_.DirName().AppendASCII(filenames::kTempExtensionName); 153 extension_path_.DirName().AppendASCII(filenames::kTempExtensionName);
dharcourt 2012/08/27 17:55:55 Corrected indentation: 4 spaces for continuation l
159 154
160 if (!file_util::CreateDirectory(temp_install_dir_)) { 155 if (!file_util::CreateDirectory(temp_install_dir_)) {
161 #if defined(OS_WIN) 156 SetUTF16Error(
162 std::string dir_string = WideToUTF8(temp_install_dir_.value()); 157 l10n_util::GetStringFUTF16(
163 #else 158 IDS_EXTENSION_PACKAGE_DIRECTORY_ERROR,
164 std::string dir_string = temp_install_dir_.value(); 159 base::i18n::GetDisplayStringInLTRDirectionality(
165 #endif 160 temp_install_dir_.LossyDisplayName())));
dharcourt 2012/08/27 17:55:55 Replacing the not-used-anywhere-else WrapPathWithL
166
167 SetError(kCouldNotCreateDirectoryError + dir_string);
168 return false; 161 return false;
169 } 162 }
170 163
171 if (!zip::Unzip(extension_path_, temp_install_dir_)) { 164 if (!zip::Unzip(extension_path_, temp_install_dir_)) {
172 SetError(kCouldNotUnzipExtension); 165 SetUTF16Error(l10n_util::GetStringUTF16(IDS_EXTENSION_PACKAGE_UNZIP_ERROR));
dharcourt 2012/08/27 17:55:55 Made error message localizable.
173 return false; 166 return false;
174 } 167 }
175 168
176 // Parse the manifest. 169 // Parse the manifest.
177 parsed_manifest_.reset(ReadManifest()); 170 parsed_manifest_.reset(ReadManifest());
178 if (!parsed_manifest_.get()) 171 if (!parsed_manifest_.get())
179 return false; // Error was already reported. 172 return false; // Error was already reported.
180 173
181 std::string error; 174 std::string error;
182 scoped_refptr<Extension> extension(Extension::Create( 175 scoped_refptr<Extension> extension(Extension::Create(
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 return false; 263 return false;
271 264
272 IPC::Message pickle(file_str.data(), file_str.size()); 265 IPC::Message pickle(file_str.data(), file_str.size());
273 PickleIterator iter(pickle); 266 PickleIterator iter(pickle);
274 return IPC::ReadParam(&pickle, &iter, catalogs); 267 return IPC::ReadParam(&pickle, &iter, catalogs);
275 } 268 }
276 269
277 bool Unpacker::AddDecodedImage(const FilePath& path) { 270 bool Unpacker::AddDecodedImage(const FilePath& path) {
278 // Make sure it's not referencing a file outside the extension's subdir. 271 // Make sure it's not referencing a file outside the extension's subdir.
279 if (path.IsAbsolute() || PathContainsParentDirectory(path)) { 272 if (path.IsAbsolute() || PathContainsParentDirectory(path)) {
280 SetError(kPathNamesMustBeAbsoluteOrLocalError); 273 SetUTF16Error(
274 l10n_util::GetStringFUTF16(
275 IDS_EXTENSION_PACKAGE_IMAGE_PATH_ERROR,
276 base::i18n::GetDisplayStringInLTRDirectionality(
277 path.LossyDisplayName())));
dharcourt 2012/08/27 17:55:55 Added path to the error message because that could
281 return false; 278 return false;
282 } 279 }
283 280
284 SkBitmap image_bitmap = DecodeImage(temp_install_dir_.Append(path)); 281 SkBitmap image_bitmap = DecodeImage(temp_install_dir_.Append(path));
285 if (image_bitmap.isNull()) { 282 if (image_bitmap.isNull()) {
286 SetError(kCouldNotDecodeImageError); 283 SetUTF16Error(
284 l10n_util::GetStringFUTF16(
285 IDS_EXTENSION_PACKAGE_IMAGE_ERROR,
286 base::i18n::GetDisplayStringInLTRDirectionality(
287 path.BaseName().LossyDisplayName())));
dharcourt 2012/08/27 17:55:55 Added the name of the problematic image to the err
287 return false; 288 return false;
288 } 289 }
289 290
290 decoded_images_.push_back(MakeTuple(image_bitmap, path)); 291 decoded_images_.push_back(MakeTuple(image_bitmap, path));
291 return true; 292 return true;
292 } 293 }
293 294
294 bool Unpacker::ReadMessageCatalog(const FilePath& message_path) { 295 bool Unpacker::ReadMessageCatalog(const FilePath& message_path) {
295 std::string error; 296 std::string error;
296 JSONFileValueSerializer serializer(message_path); 297 JSONFileValueSerializer serializer(message_path);
(...skipping 24 matching lines...) Expand all
321 if (dir_name.empty()) { 322 if (dir_name.empty()) {
322 NOTREACHED(); 323 NOTREACHED();
323 return false; 324 return false;
324 } 325 }
325 parsed_catalogs_->Set(dir_name, root.release()); 326 parsed_catalogs_->Set(dir_name, root.release());
326 327
327 return true; 328 return true;
328 } 329 }
329 330
330 void Unpacker::SetError(const std::string &error) { 331 void Unpacker::SetError(const std::string &error) {
331 error_message_ = UTF8ToUTF16(error); 332 SetUTF16Error(UTF8ToUTF16(error));
333 }
334
335 void Unpacker::SetUTF16Error(const string16 &error) {
336 error_message_ = error;
dharcourt 2012/08/27 17:55:55 Added to avoid unnecessary UTF16->UTF8->UTF16 conv
332 } 337 }
333 338
334 } // namespace extensions 339 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698