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

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

Issue 19547009: Move ".crx"/".pem" constants and extension_filenames constants into extensions/common/constants.cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: todo Created 7 years, 5 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
« no previous file with comments | « chrome/installer/setup/uninstall.cc ('k') | chrome/utility/extensions/unpacker_unittest.cc » ('j') | 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) 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/utility/extensions/unpacker.h" 5 #include "chrome/utility/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/files/file_enumerator.h" 10 #include "base/files/file_enumerator.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "base/json/json_file_value_serializer.h" 13 #include "base/json/json_file_value_serializer.h"
14 #include "base/memory/scoped_handle.h" 14 #include "base/memory/scoped_handle.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/common/chrome_utility_messages.h" 19 #include "chrome/common/chrome_utility_messages.h"
20 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" 20 #include "chrome/common/extensions/api/i18n/default_locale_handler.h"
21 #include "chrome/common/extensions/extension.h" 21 #include "chrome/common/extensions/extension.h"
22 #include "chrome/common/extensions/extension_file_util.h" 22 #include "chrome/common/extensions/extension_file_util.h"
23 #include "chrome/common/extensions/extension_l10n_util.h" 23 #include "chrome/common/extensions/extension_l10n_util.h"
24 #include "chrome/common/extensions/extension_manifest_constants.h" 24 #include "chrome/common/extensions/extension_manifest_constants.h"
25 #include "chrome/common/extensions/manifest.h" 25 #include "chrome/common/extensions/manifest.h"
26 #include "chrome/common/url_constants.h"
27 #include "content/public/child/image_decoder_utils.h" 26 #include "content/public/child/image_decoder_utils.h"
28 #include "content/public/common/common_param_traits.h" 27 #include "content/public/common/common_param_traits.h"
29 #include "extensions/common/constants.h" 28 #include "extensions/common/constants.h"
30 #include "grit/generated_resources.h" 29 #include "grit/generated_resources.h"
31 #include "ipc/ipc_message_utils.h" 30 #include "ipc/ipc_message_utils.h"
32 #include "net/base/file_stream.h" 31 #include "net/base/file_stream.h"
33 #include "third_party/skia/include/core/SkBitmap.h" 32 #include "third_party/skia/include/core/SkBitmap.h"
34 #include "third_party/zlib/google/zip.h" 33 #include "third_party/zlib/google/zip.h"
35 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
36 #include "ui/gfx/size.h" 35 #include "ui/gfx/size.h"
37 36
38 namespace errors = extension_manifest_errors; 37 namespace errors = extension_manifest_errors;
39 namespace keys = extension_manifest_keys; 38 namespace keys = extension_manifest_keys;
40 namespace filenames = extension_filenames;
41 39
42 namespace { 40 namespace {
43 41
44 // A limit to stop us passing dangerously large canvases to the browser. 42 // A limit to stop us passing dangerously large canvases to the browser.
45 const int kMaxImageCanvas = 4096 * 4096; 43 const int kMaxImageCanvas = 4096 * 4096;
46 44
47 SkBitmap DecodeImage(const base::FilePath& path) { 45 SkBitmap DecodeImage(const base::FilePath& path) {
48 // Read the file from disk. 46 // Read the file from disk.
49 std::string file_contents; 47 std::string file_contents;
50 if (!base::PathExists(path) || 48 if (!base::PathExists(path) ||
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 153 }
156 154
157 return true; 155 return true;
158 } 156 }
159 157
160 bool Unpacker::Run() { 158 bool Unpacker::Run() {
161 DVLOG(1) << "Installing extension " << extension_path_.value(); 159 DVLOG(1) << "Installing extension " << extension_path_.value();
162 160
163 // <profile>/Extensions/CRX_INSTALL 161 // <profile>/Extensions/CRX_INSTALL
164 temp_install_dir_ = 162 temp_install_dir_ =
165 extension_path_.DirName().AppendASCII(filenames::kTempExtensionName); 163 extension_path_.DirName().AppendASCII(kTempExtensionName);
166 164
167 if (!file_util::CreateDirectory(temp_install_dir_)) { 165 if (!file_util::CreateDirectory(temp_install_dir_)) {
168 SetUTF16Error( 166 SetUTF16Error(
169 l10n_util::GetStringFUTF16( 167 l10n_util::GetStringFUTF16(
170 IDS_EXTENSION_PACKAGE_DIRECTORY_ERROR, 168 IDS_EXTENSION_PACKAGE_DIRECTORY_ERROR,
171 base::i18n::GetDisplayStringInLTRDirectionality( 169 base::i18n::GetDisplayStringInLTRDirectionality(
172 temp_install_dir_.LossyDisplayName()))); 170 temp_install_dir_.LossyDisplayName())));
173 return false; 171 return false;
174 } 172 }
175 173
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 220 }
223 221
224 return true; 222 return true;
225 } 223 }
226 224
227 bool Unpacker::DumpImagesToFile() { 225 bool Unpacker::DumpImagesToFile() {
228 IPC::Message pickle; // We use a Message so we can use WriteParam. 226 IPC::Message pickle; // We use a Message so we can use WriteParam.
229 IPC::WriteParam(&pickle, internal_data_->decoded_images); 227 IPC::WriteParam(&pickle, internal_data_->decoded_images);
230 228
231 base::FilePath path = extension_path_.DirName().AppendASCII( 229 base::FilePath path = extension_path_.DirName().AppendASCII(
232 filenames::kDecodedImagesFilename); 230 kDecodedImagesFilename);
233 if (!file_util::WriteFile(path, static_cast<const char*>(pickle.data()), 231 if (!file_util::WriteFile(path, static_cast<const char*>(pickle.data()),
234 pickle.size())) { 232 pickle.size())) {
235 SetError("Could not write image data to disk."); 233 SetError("Could not write image data to disk.");
236 return false; 234 return false;
237 } 235 }
238 236
239 return true; 237 return true;
240 } 238 }
241 239
242 bool Unpacker::DumpMessageCatalogsToFile() { 240 bool Unpacker::DumpMessageCatalogsToFile() {
243 IPC::Message pickle; 241 IPC::Message pickle;
244 IPC::WriteParam(&pickle, *parsed_catalogs_.get()); 242 IPC::WriteParam(&pickle, *parsed_catalogs_.get());
245 243
246 base::FilePath path = extension_path_.DirName().AppendASCII( 244 base::FilePath path = extension_path_.DirName().AppendASCII(
247 filenames::kDecodedMessageCatalogsFilename); 245 kDecodedMessageCatalogsFilename);
248 if (!file_util::WriteFile(path, static_cast<const char*>(pickle.data()), 246 if (!file_util::WriteFile(path, static_cast<const char*>(pickle.data()),
249 pickle.size())) { 247 pickle.size())) {
250 SetError("Could not write message catalogs to disk."); 248 SetError("Could not write message catalogs to disk.");
251 return false; 249 return false;
252 } 250 }
253 251
254 return true; 252 return true;
255 } 253 }
256 254
257 bool Unpacker::AddDecodedImage(const base::FilePath& path) { 255 bool Unpacker::AddDecodedImage(const base::FilePath& path) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 315
318 void Unpacker::SetError(const std::string &error) { 316 void Unpacker::SetError(const std::string &error) {
319 SetUTF16Error(UTF8ToUTF16(error)); 317 SetUTF16Error(UTF8ToUTF16(error));
320 } 318 }
321 319
322 void Unpacker::SetUTF16Error(const string16 &error) { 320 void Unpacker::SetUTF16Error(const string16 &error) {
323 error_message_ = error; 321 error_message_ = error;
324 } 322 }
325 323
326 } // namespace extensions 324 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/installer/setup/uninstall.cc ('k') | chrome/utility/extensions/unpacker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698