| 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 "extensions/utility/unpacker.h" | 5 #include "extensions/utility/unpacker.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 scoped_ptr<base::DictionaryValue> Unpacker::ReadManifest() { | 115 scoped_ptr<base::DictionaryValue> Unpacker::ReadManifest() { |
| 116 base::FilePath manifest_path = extension_dir_.Append(kManifestFilename); | 116 base::FilePath manifest_path = extension_dir_.Append(kManifestFilename); |
| 117 if (!base::PathExists(manifest_path)) { | 117 if (!base::PathExists(manifest_path)) { |
| 118 SetError(errors::kInvalidManifest); | 118 SetError(errors::kInvalidManifest); |
| 119 return NULL; | 119 return NULL; |
| 120 } | 120 } |
| 121 | 121 |
| 122 JSONFileValueDeserializer deserializer(manifest_path); | 122 JSONFileValueDeserializer deserializer(manifest_path); |
| 123 std::string error; | 123 std::string error; |
| 124 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, &error)); | 124 scoped_ptr<base::Value> root = deserializer.Deserialize(NULL, &error); |
| 125 if (!root.get()) { | 125 if (!root.get()) { |
| 126 SetError(error); | 126 SetError(error); |
| 127 return NULL; | 127 return NULL; |
| 128 } | 128 } |
| 129 | 129 |
| 130 if (!root->IsType(base::Value::TYPE_DICTIONARY)) { | 130 if (!root->IsType(base::Value::TYPE_DICTIONARY)) { |
| 131 SetError(errors::kInvalidManifest); | 131 SetError(errors::kInvalidManifest); |
| 132 return NULL; | 132 return NULL; |
| 133 } | 133 } |
| 134 | 134 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 return false; | 246 return false; |
| 247 } | 247 } |
| 248 | 248 |
| 249 internal_data_->decoded_images.push_back(base::MakeTuple(image_bitmap, path)); | 249 internal_data_->decoded_images.push_back(base::MakeTuple(image_bitmap, path)); |
| 250 return true; | 250 return true; |
| 251 } | 251 } |
| 252 | 252 |
| 253 bool Unpacker::ReadMessageCatalog(const base::FilePath& message_path) { | 253 bool Unpacker::ReadMessageCatalog(const base::FilePath& message_path) { |
| 254 std::string error; | 254 std::string error; |
| 255 JSONFileValueDeserializer deserializer(message_path); | 255 JSONFileValueDeserializer deserializer(message_path); |
| 256 scoped_ptr<base::DictionaryValue> root = base::DictionaryValue::From( | 256 scoped_ptr<base::DictionaryValue> root = |
| 257 make_scoped_ptr(deserializer.Deserialize(NULL, &error))); | 257 base::DictionaryValue::From(deserializer.Deserialize(NULL, &error)); |
| 258 if (!root.get()) { | 258 if (!root.get()) { |
| 259 base::string16 messages_file = message_path.LossyDisplayName(); | 259 base::string16 messages_file = message_path.LossyDisplayName(); |
| 260 if (error.empty()) { | 260 if (error.empty()) { |
| 261 // If file is missing, Deserialize will fail with empty error. | 261 // If file is missing, Deserialize will fail with empty error. |
| 262 SetError(base::StringPrintf("%s %s", errors::kLocalesMessagesFileMissing, | 262 SetError(base::StringPrintf("%s %s", errors::kLocalesMessagesFileMissing, |
| 263 base::UTF16ToUTF8(messages_file).c_str())); | 263 base::UTF16ToUTF8(messages_file).c_str())); |
| 264 } else { | 264 } else { |
| 265 SetError(base::StringPrintf( | 265 SetError(base::StringPrintf( |
| 266 "%s: %s", base::UTF16ToUTF8(messages_file).c_str(), error.c_str())); | 266 "%s: %s", base::UTF16ToUTF8(messages_file).c_str(), error.c_str())); |
| 267 } | 267 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 287 | 287 |
| 288 void Unpacker::SetError(const std::string& error) { | 288 void Unpacker::SetError(const std::string& error) { |
| 289 SetUTF16Error(base::UTF8ToUTF16(error)); | 289 SetUTF16Error(base::UTF8ToUTF16(error)); |
| 290 } | 290 } |
| 291 | 291 |
| 292 void Unpacker::SetUTF16Error(const base::string16& error) { | 292 void Unpacker::SetUTF16Error(const base::string16& error) { |
| 293 error_message_ = error; | 293 error_message_ = error; |
| 294 } | 294 } |
| 295 | 295 |
| 296 } // namespace extensions | 296 } // namespace extensions |
| OLD | NEW |