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/browser/component_updater/component_unpacker.h" | 5 #include "chrome/browser/component_updater/component_unpacker.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/json/json_file_value_serializer.h" | 11 #include "base/json/json_file_value_serializer.h" |
12 #include "base/memory/scoped_handle.h" | 12 #include "base/memory/scoped_handle.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/values.h" | |
15 #include "chrome/browser/component_updater/component_patcher.h" | 16 #include "chrome/browser/component_updater/component_patcher.h" |
16 #include "chrome/browser/component_updater/component_updater_service.h" | 17 #include "chrome/browser/component_updater/component_updater_service.h" |
17 #include "chrome/common/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
18 #include "crypto/secure_hash.h" | 19 #include "crypto/secure_hash.h" |
19 #include "crypto/signature_verifier.h" | 20 #include "crypto/signature_verifier.h" |
20 #include "extensions/common/crx_file.h" | 21 #include "extensions/common/crx_file.h" |
21 #include "third_party/zlib/google/zip.h" | 22 #include "third_party/zlib/google/zip.h" |
22 | 23 |
23 using crypto::SecureHash; | 24 using crypto::SecureHash; |
24 | 25 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 bool delta() const { return delta_; } | 79 bool delta() const { return delta_; } |
79 | 80 |
80 const std::vector<uint8>& public_key() const { return public_key_; } | 81 const std::vector<uint8>& public_key() const { return public_key_; } |
81 | 82 |
82 private: | 83 private: |
83 bool valid_; | 84 bool valid_; |
84 bool delta_; | 85 bool delta_; |
85 std::vector<uint8> public_key_; | 86 std::vector<uint8> public_key_; |
86 }; | 87 }; |
87 | 88 |
88 // Deserialize the CRX manifest. The top level must be a dictionary. | 89 } // namespace. |
90 | |
89 // TODO(cpu): add a specific attribute check to a component json that the | 91 // TODO(cpu): add a specific attribute check to a component json that the |
90 // extension unpacker will reject, so that a component cannot be installed | 92 // extension unpacker will reject, so that a component cannot be installed |
91 // as an extension. | 93 // as an extension. |
92 base::DictionaryValue* ReadManifest(const base::FilePath& unpack_path) { | 94 scoped_ptr<base::DictionaryValue> ReadManifest( |
ddorwin
2013/10/25 19:03:40
I put this function back where it was, so you may
| |
95 const base::FilePath& unpack_path) { | |
93 base::FilePath manifest = | 96 base::FilePath manifest = |
94 unpack_path.Append(FILE_PATH_LITERAL("manifest.json")); | 97 unpack_path.Append(FILE_PATH_LITERAL("manifest.json")); |
95 if (!base::PathExists(manifest)) | 98 if (!base::PathExists(manifest)) |
96 return NULL; | 99 return scoped_ptr<base::DictionaryValue>(); |
97 JSONFileValueSerializer serializer(manifest); | 100 JSONFileValueSerializer serializer(manifest); |
98 std::string error; | 101 std::string error; |
99 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error)); | 102 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error)); |
100 if (!root.get()) | 103 if (!root.get()) { |
101 return NULL; | 104 DLOG(ERROR) << "Failed to deserialize " << manifest.MaybeAsASCII() << ": " |
cpu_(ooo_6.6-7.5)
2013/10/25 23:06:23
please remove the DLOG
ddorwin
2013/10/25 23:27:27
I removed it in the interest of time, but I'd like
| |
102 if (!root->IsType(base::Value::TYPE_DICTIONARY)) | 105 << error; |
103 return NULL; | 106 return scoped_ptr<base::DictionaryValue>(); |
104 return static_cast<base::DictionaryValue*>(root.release()); | 107 } |
108 if (!root->IsType(base::Value::TYPE_DICTIONARY)) { | |
109 return scoped_ptr<base::DictionaryValue>(); | |
110 } | |
111 return scoped_ptr<base::DictionaryValue>( | |
cpu_(ooo_6.6-7.5)
2013/10/25 23:06:23
With more pointer safety comes great verbosity. No
| |
112 static_cast<base::DictionaryValue*>(root.release())).Pass(); | |
105 } | 113 } |
106 | 114 |
107 } // namespace. | |
108 | |
109 ComponentUnpacker::ComponentUnpacker(const std::vector<uint8>& pk_hash, | 115 ComponentUnpacker::ComponentUnpacker(const std::vector<uint8>& pk_hash, |
110 const base::FilePath& path, | 116 const base::FilePath& path, |
111 const std::string& fingerprint, | 117 const std::string& fingerprint, |
112 ComponentPatcher* patcher, | 118 ComponentPatcher* patcher, |
113 ComponentInstaller* installer) | 119 ComponentInstaller* installer) |
114 : error_(kNone), | 120 : error_(kNone), |
115 extended_error_(0) { | 121 extended_error_(0) { |
116 if (pk_hash.empty() || path.empty()) { | 122 if (pk_hash.empty() || path.empty()) { |
117 error_ = kInvalidParams; | 123 error_ = kInvalidParams; |
118 return; | 124 return; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 return; | 204 return; |
199 } | 205 } |
200 // Installation successful. The directory is not our concern now. | 206 // Installation successful. The directory is not our concern now. |
201 unpack_path_.clear(); | 207 unpack_path_.clear(); |
202 } | 208 } |
203 | 209 |
204 ComponentUnpacker::~ComponentUnpacker() { | 210 ComponentUnpacker::~ComponentUnpacker() { |
205 if (!unpack_path_.empty()) | 211 if (!unpack_path_.empty()) |
206 base::DeleteFile(unpack_path_, true); | 212 base::DeleteFile(unpack_path_, true); |
207 } | 213 } |
OLD | NEW |