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

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

Issue 1120006: detect preferences errors (Closed)
Patch Set: changes from review Created 10 years, 8 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
« no previous file with comments | « chrome/common/extensions/extension_unittest.cc ('k') | chrome/common/json_value_serializer.h » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/extension_unpacker.h" 5 #include "chrome/common/extensions/extension_unpacker.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/scoped_handle.h" 8 #include "base/scoped_handle.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 DictionaryValue* ExtensionUnpacker::ReadManifest() { 94 DictionaryValue* ExtensionUnpacker::ReadManifest() {
95 FilePath manifest_path = 95 FilePath manifest_path =
96 temp_install_dir_.Append(Extension::kManifestFilename); 96 temp_install_dir_.Append(Extension::kManifestFilename);
97 if (!file_util::PathExists(manifest_path)) { 97 if (!file_util::PathExists(manifest_path)) {
98 SetError(errors::kInvalidManifest); 98 SetError(errors::kInvalidManifest);
99 return NULL; 99 return NULL;
100 } 100 }
101 101
102 JSONFileValueSerializer serializer(manifest_path); 102 JSONFileValueSerializer serializer(manifest_path);
103 std::string error; 103 std::string error;
104 scoped_ptr<Value> root(serializer.Deserialize(&error)); 104 scoped_ptr<Value> root(serializer.Deserialize(NULL, &error));
105 if (!root.get()) { 105 if (!root.get()) {
106 SetError(error); 106 SetError(error);
107 return NULL; 107 return NULL;
108 } 108 }
109 109
110 if (!root->IsType(Value::TYPE_DICTIONARY)) { 110 if (!root->IsType(Value::TYPE_DICTIONARY)) {
111 SetError(errors::kInvalidManifest); 111 SetError(errors::kInvalidManifest);
112 return NULL; 112 return NULL;
113 } 113 }
114 114
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 269 }
270 270
271 decoded_images_.push_back(MakeTuple(image_bitmap, path)); 271 decoded_images_.push_back(MakeTuple(image_bitmap, path));
272 return true; 272 return true;
273 } 273 }
274 274
275 bool ExtensionUnpacker::ReadMessageCatalog(const FilePath& message_path) { 275 bool ExtensionUnpacker::ReadMessageCatalog(const FilePath& message_path) {
276 std::string error; 276 std::string error;
277 JSONFileValueSerializer serializer(message_path); 277 JSONFileValueSerializer serializer(message_path);
278 scoped_ptr<DictionaryValue> root( 278 scoped_ptr<DictionaryValue> root(
279 static_cast<DictionaryValue*>(serializer.Deserialize(&error))); 279 static_cast<DictionaryValue*>(serializer.Deserialize(NULL, &error)));
280 if (!root.get()) { 280 if (!root.get()) {
281 std::string messages_file = WideToASCII(message_path.ToWStringHack()); 281 std::string messages_file = WideToASCII(message_path.ToWStringHack());
282 if (error.empty()) { 282 if (error.empty()) {
283 // If file is missing, Deserialize will fail with empty error. 283 // If file is missing, Deserialize will fail with empty error.
284 SetError(StringPrintf("%s %s", errors::kLocalesMessagesFileMissing, 284 SetError(StringPrintf("%s %s", errors::kLocalesMessagesFileMissing,
285 messages_file.c_str())); 285 messages_file.c_str()));
286 } else { 286 } else {
287 SetError(StringPrintf("%s: %s", messages_file.c_str(), error.c_str())); 287 SetError(StringPrintf("%s: %s", messages_file.c_str(), error.c_str()));
288 } 288 }
289 return false; 289 return false;
290 } 290 }
291 291
292 FilePath relative_path; 292 FilePath relative_path;
293 // message_path was created from temp_install_dir. This should never fail. 293 // message_path was created from temp_install_dir. This should never fail.
294 if (!temp_install_dir_.AppendRelativePath(message_path, &relative_path)) 294 if (!temp_install_dir_.AppendRelativePath(message_path, &relative_path))
295 NOTREACHED(); 295 NOTREACHED();
296 296
297 parsed_catalogs_->Set(relative_path.DirName().ToWStringHack(), 297 parsed_catalogs_->Set(relative_path.DirName().ToWStringHack(),
298 root.release()); 298 root.release());
299 299
300 return true; 300 return true;
301 } 301 }
302 302
303 void ExtensionUnpacker::SetError(const std::string &error) { 303 void ExtensionUnpacker::SetError(const std::string &error) {
304 error_message_ = error; 304 error_message_ = error;
305 } 305 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_unittest.cc ('k') | chrome/common/json_value_serializer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698