OLD | NEW |
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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
31 #include "ipc/ipc_message_utils.h" | 31 #include "ipc/ipc_message_utils.h" |
32 #include "net/base/file_stream.h" | 32 #include "net/base/file_stream.h" |
33 #include "third_party/skia/include/core/SkBitmap.h" | 33 #include "third_party/skia/include/core/SkBitmap.h" |
34 #include "third_party/zlib/google/zip.h" | 34 #include "third_party/zlib/google/zip.h" |
35 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
36 #include "ui/gfx/size.h" | 36 #include "ui/gfx/size.h" |
37 | 37 |
38 namespace errors = extension_manifest_errors; | 38 namespace errors = extension_manifest_errors; |
39 namespace keys = extension_manifest_keys; | 39 namespace keys = extension_manifest_keys; |
40 namespace filenames = extension_filenames; | |
41 | 40 |
42 namespace { | 41 namespace { |
43 | 42 |
44 // A limit to stop us passing dangerously large canvases to the browser. | 43 // A limit to stop us passing dangerously large canvases to the browser. |
45 const int kMaxImageCanvas = 4096 * 4096; | 44 const int kMaxImageCanvas = 4096 * 4096; |
46 | 45 |
47 SkBitmap DecodeImage(const base::FilePath& path) { | 46 SkBitmap DecodeImage(const base::FilePath& path) { |
48 // Read the file from disk. | 47 // Read the file from disk. |
49 std::string file_contents; | 48 std::string file_contents; |
50 if (!base::PathExists(path) || | 49 if (!base::PathExists(path) || |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 location_(location), | 101 location_(location), |
103 creation_flags_(creation_flags) { | 102 creation_flags_(creation_flags) { |
104 internal_data_.reset(new InternalData()); | 103 internal_data_.reset(new InternalData()); |
105 } | 104 } |
106 | 105 |
107 Unpacker::~Unpacker() { | 106 Unpacker::~Unpacker() { |
108 } | 107 } |
109 | 108 |
110 base::DictionaryValue* Unpacker::ReadManifest() { | 109 base::DictionaryValue* Unpacker::ReadManifest() { |
111 base::FilePath manifest_path = | 110 base::FilePath manifest_path = |
112 temp_install_dir_.Append(kManifestFilename); | 111 temp_install_dir_.Append(filenames::kManifestFilename); |
113 if (!base::PathExists(manifest_path)) { | 112 if (!base::PathExists(manifest_path)) { |
114 SetError(errors::kInvalidManifest); | 113 SetError(errors::kInvalidManifest); |
115 return NULL; | 114 return NULL; |
116 } | 115 } |
117 | 116 |
118 JSONFileValueSerializer serializer(manifest_path); | 117 JSONFileValueSerializer serializer(manifest_path); |
119 std::string error; | 118 std::string error; |
120 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error)); | 119 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error)); |
121 if (!root.get()) { | 120 if (!root.get()) { |
122 SetError(error); | 121 SetError(error); |
123 return NULL; | 122 return NULL; |
124 } | 123 } |
125 | 124 |
126 if (!root->IsType(base::Value::TYPE_DICTIONARY)) { | 125 if (!root->IsType(base::Value::TYPE_DICTIONARY)) { |
127 SetError(errors::kInvalidManifest); | 126 SetError(errors::kInvalidManifest); |
128 return NULL; | 127 return NULL; |
129 } | 128 } |
130 | 129 |
131 return static_cast<base::DictionaryValue*>(root.release()); | 130 return static_cast<base::DictionaryValue*>(root.release()); |
132 } | 131 } |
133 | 132 |
134 bool Unpacker::ReadAllMessageCatalogs(const std::string& default_locale) { | 133 bool Unpacker::ReadAllMessageCatalogs(const std::string& default_locale) { |
135 base::FilePath locales_path = | 134 base::FilePath locales_path = |
136 temp_install_dir_.Append(kLocaleFolder); | 135 temp_install_dir_.Append(filenames::kLocaleFolder); |
137 | 136 |
138 // Not all folders under _locales have to be valid locales. | 137 // Not all folders under _locales have to be valid locales. |
139 base::FileEnumerator locales(locales_path, | 138 base::FileEnumerator locales(locales_path, |
140 false, | 139 false, |
141 base::FileEnumerator::DIRECTORIES); | 140 base::FileEnumerator::DIRECTORIES); |
142 | 141 |
143 std::set<std::string> all_locales; | 142 std::set<std::string> all_locales; |
144 extension_l10n_util::GetAllLocales(&all_locales); | 143 extension_l10n_util::GetAllLocales(&all_locales); |
145 base::FilePath locale_path; | 144 base::FilePath locale_path; |
146 while (!(locale_path = locales.Next()).empty()) { | 145 while (!(locale_path = locales.Next()).empty()) { |
147 if (extension_l10n_util::ShouldSkipValidation(locales_path, locale_path, | 146 if (extension_l10n_util::ShouldSkipValidation(locales_path, locale_path, |
148 all_locales)) | 147 all_locales)) |
149 continue; | 148 continue; |
150 | 149 |
151 base::FilePath messages_path = locale_path.Append(kMessagesFilename); | 150 base::FilePath messages_path = |
| 151 locale_path.Append(filenames::kMessagesFilename); |
152 | 152 |
153 if (!ReadMessageCatalog(messages_path)) | 153 if (!ReadMessageCatalog(messages_path)) |
154 return false; | 154 return false; |
155 } | 155 } |
156 | 156 |
157 return true; | 157 return true; |
158 } | 158 } |
159 | 159 |
160 bool Unpacker::Run() { | 160 bool Unpacker::Run() { |
161 DVLOG(1) << "Installing extension " << extension_path_.value(); | 161 DVLOG(1) << "Installing extension " << extension_path_.value(); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 | 317 |
318 void Unpacker::SetError(const std::string &error) { | 318 void Unpacker::SetError(const std::string &error) { |
319 SetUTF16Error(UTF8ToUTF16(error)); | 319 SetUTF16Error(UTF8ToUTF16(error)); |
320 } | 320 } |
321 | 321 |
322 void Unpacker::SetUTF16Error(const string16 &error) { | 322 void Unpacker::SetUTF16Error(const string16 &error) { |
323 error_message_ = error; | 323 error_message_ = error; |
324 } | 324 } |
325 | 325 |
326 } // namespace extensions | 326 } // namespace extensions |
OLD | NEW |