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

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

Issue 12578008: Move CrxFile, FileReader, ExtensionResource to src/extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 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/common/extensions/extension_unittest.cc ('k') | extensions/DEPS » ('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/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/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/json/json_file_value_serializer.h" 12 #include "base/json/json_file_value_serializer.h"
13 #include "base/memory/scoped_handle.h" 13 #include "base/memory/scoped_handle.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" 18 #include "chrome/common/extensions/api/i18n/default_locale_handler.h"
19 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/extension_file_util.h" 20 #include "chrome/common/extensions/extension_file_util.h"
21 #include "chrome/common/extensions/extension_l10n_util.h" 21 #include "chrome/common/extensions/extension_l10n_util.h"
22 #include "chrome/common/extensions/extension_manifest_constants.h" 22 #include "chrome/common/extensions/extension_manifest_constants.h"
23 #include "chrome/common/extensions/manifest.h" 23 #include "chrome/common/extensions/manifest.h"
24 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
25 #include "chrome/common/zip.h" 25 #include "chrome/common/zip.h"
26 #include "content/public/common/common_param_traits.h" 26 #include "content/public/common/common_param_traits.h"
27 #include "extensions/common/constants.h"
27 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
28 #include "ipc/ipc_message_utils.h" 29 #include "ipc/ipc_message_utils.h"
29 #include "net/base/file_stream.h" 30 #include "net/base/file_stream.h"
30 #include "third_party/skia/include/core/SkBitmap.h" 31 #include "third_party/skia/include/core/SkBitmap.h"
31 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
32 #include "webkit/glue/image_decoder.h" 33 #include "webkit/glue/image_decoder.h"
33 34
34 namespace errors = extension_manifest_errors; 35 namespace errors = extension_manifest_errors;
35 namespace keys = extension_manifest_keys; 36 namespace keys = extension_manifest_keys;
36 namespace filenames = extension_filenames; 37 namespace filenames = extension_filenames;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 extension_id_(extension_id), 93 extension_id_(extension_id),
93 location_(location), 94 location_(location),
94 creation_flags_(creation_flags) { 95 creation_flags_(creation_flags) {
95 } 96 }
96 97
97 Unpacker::~Unpacker() { 98 Unpacker::~Unpacker() {
98 } 99 }
99 100
100 DictionaryValue* Unpacker::ReadManifest() { 101 DictionaryValue* Unpacker::ReadManifest() {
101 base::FilePath manifest_path = 102 base::FilePath manifest_path =
102 temp_install_dir_.Append(Extension::kManifestFilename); 103 temp_install_dir_.Append(kManifestFilename);
103 if (!file_util::PathExists(manifest_path)) { 104 if (!file_util::PathExists(manifest_path)) {
104 SetError(errors::kInvalidManifest); 105 SetError(errors::kInvalidManifest);
105 return NULL; 106 return NULL;
106 } 107 }
107 108
108 JSONFileValueSerializer serializer(manifest_path); 109 JSONFileValueSerializer serializer(manifest_path);
109 std::string error; 110 std::string error;
110 scoped_ptr<Value> root(serializer.Deserialize(NULL, &error)); 111 scoped_ptr<Value> root(serializer.Deserialize(NULL, &error));
111 if (!root.get()) { 112 if (!root.get()) {
112 SetError(error); 113 SetError(error);
113 return NULL; 114 return NULL;
114 } 115 }
115 116
116 if (!root->IsType(Value::TYPE_DICTIONARY)) { 117 if (!root->IsType(Value::TYPE_DICTIONARY)) {
117 SetError(errors::kInvalidManifest); 118 SetError(errors::kInvalidManifest);
118 return NULL; 119 return NULL;
119 } 120 }
120 121
121 return static_cast<DictionaryValue*>(root.release()); 122 return static_cast<DictionaryValue*>(root.release());
122 } 123 }
123 124
124 bool Unpacker::ReadAllMessageCatalogs(const std::string& default_locale) { 125 bool Unpacker::ReadAllMessageCatalogs(const std::string& default_locale) {
125 base::FilePath locales_path = 126 base::FilePath locales_path =
126 temp_install_dir_.Append(Extension::kLocaleFolder); 127 temp_install_dir_.Append(kLocaleFolder);
127 128
128 // Not all folders under _locales have to be valid locales. 129 // Not all folders under _locales have to be valid locales.
129 file_util::FileEnumerator locales(locales_path, 130 file_util::FileEnumerator locales(locales_path,
130 false, 131 false,
131 file_util::FileEnumerator::DIRECTORIES); 132 file_util::FileEnumerator::DIRECTORIES);
132 133
133 std::set<std::string> all_locales; 134 std::set<std::string> all_locales;
134 extension_l10n_util::GetAllLocales(&all_locales); 135 extension_l10n_util::GetAllLocales(&all_locales);
135 base::FilePath locale_path; 136 base::FilePath locale_path;
136 while (!(locale_path = locales.Next()).empty()) { 137 while (!(locale_path = locales.Next()).empty()) {
137 if (extension_l10n_util::ShouldSkipValidation(locales_path, locale_path, 138 if (extension_l10n_util::ShouldSkipValidation(locales_path, locale_path,
138 all_locales)) 139 all_locales))
139 continue; 140 continue;
140 141
141 base::FilePath messages_path = 142 base::FilePath messages_path = locale_path.Append(kMessagesFilename);
142 locale_path.Append(Extension::kMessagesFilename);
143 143
144 if (!ReadMessageCatalog(messages_path)) 144 if (!ReadMessageCatalog(messages_path))
145 return false; 145 return false;
146 } 146 }
147 147
148 return true; 148 return true;
149 } 149 }
150 150
151 bool Unpacker::Run() { 151 bool Unpacker::Run() {
152 DVLOG(1) << "Installing extension " << extension_path_.value(); 152 DVLOG(1) << "Installing extension " << extension_path_.value();
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 334
335 void Unpacker::SetError(const std::string &error) { 335 void Unpacker::SetError(const std::string &error) {
336 SetUTF16Error(UTF8ToUTF16(error)); 336 SetUTF16Error(UTF8ToUTF16(error));
337 } 337 }
338 338
339 void Unpacker::SetUTF16Error(const string16 &error) { 339 void Unpacker::SetUTF16Error(const string16 &error) {
340 error_message_ = error; 340 error_message_ = error;
341 } 341 }
342 342
343 } // namespace extensions 343 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_unittest.cc ('k') | extensions/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698