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

Side by Side Diff: chrome/browser/extensions/sandboxed_unpacker.cc

Issue 19547009: Move ".crx"/".pem" constants and extension_filenames constants into extensions/common/constants.cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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
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/browser/extensions/sandboxed_unpacker.h" 5 #include "chrome/browser/extensions/sandboxed_unpacker.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 << "remote drives or read-only. Installation can not complete!"; 175 << "remote drives or read-only. Installation can not complete!";
176 return false; 176 return false;
177 } 177 }
178 178
179 // Read the decoded images back from the file we saved them to. 179 // Read the decoded images back from the file we saved them to.
180 // |extension_path| is the path to the extension we unpacked that wrote the 180 // |extension_path| is the path to the extension we unpacked that wrote the
181 // data. Returns true on success. 181 // data. Returns true on success.
182 bool ReadImagesFromFile(const base::FilePath& extension_path, 182 bool ReadImagesFromFile(const base::FilePath& extension_path,
183 DecodedImages* images) { 183 DecodedImages* images) {
184 base::FilePath path = 184 base::FilePath path =
185 extension_path.AppendASCII(extension_filenames::kDecodedImagesFilename); 185 extension_path.AppendASCII(filenames::kDecodedImagesFilename);
186 std::string file_str; 186 std::string file_str;
187 if (!file_util::ReadFileToString(path, &file_str)) 187 if (!file_util::ReadFileToString(path, &file_str))
188 return false; 188 return false;
189 189
190 IPC::Message pickle(file_str.data(), file_str.size()); 190 IPC::Message pickle(file_str.data(), file_str.size());
191 PickleIterator iter(pickle); 191 PickleIterator iter(pickle);
192 return IPC::ReadParam(&pickle, &iter, images); 192 return IPC::ReadParam(&pickle, &iter, images);
193 } 193 }
194 194
195 // Read the decoded message catalogs back from the file we saved them to. 195 // Read the decoded message catalogs back from the file we saved them to.
196 // |extension_path| is the path to the extension we unpacked that wrote the 196 // |extension_path| is the path to the extension we unpacked that wrote the
197 // data. Returns true on success. 197 // data. Returns true on success.
198 bool ReadMessageCatalogsFromFile(const base::FilePath& extension_path, 198 bool ReadMessageCatalogsFromFile(const base::FilePath& extension_path,
199 base::DictionaryValue* catalogs) { 199 base::DictionaryValue* catalogs) {
200 base::FilePath path = extension_path.AppendASCII( 200 base::FilePath path = extension_path.AppendASCII(
201 extension_filenames::kDecodedMessageCatalogsFilename); 201 filenames::kDecodedMessageCatalogsFilename);
202 std::string file_str; 202 std::string file_str;
203 if (!file_util::ReadFileToString(path, &file_str)) 203 if (!file_util::ReadFileToString(path, &file_str))
204 return false; 204 return false;
205 205
206 IPC::Message pickle(file_str.data(), file_str.size()); 206 IPC::Message pickle(file_str.data(), file_str.size());
207 PickleIterator iter(pickle); 207 PickleIterator iter(pickle);
208 return IPC::ReadParam(&pickle, &iter, catalogs); 208 return IPC::ReadParam(&pickle, &iter, catalogs);
209 } 209 }
210 210
211 } // namespace 211 } // namespace
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); 257 CHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread());
258 258
259 unpack_start_time_ = base::TimeTicks::Now(); 259 unpack_start_time_ = base::TimeTicks::Now();
260 260
261 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackInitialCrxPathLength", 261 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackInitialCrxPathLength",
262 crx_path_); 262 crx_path_);
263 if (!CreateTempDirectory()) 263 if (!CreateTempDirectory())
264 return; // ReportFailure() already called. 264 return; // ReportFailure() already called.
265 265
266 // Initialize the path that will eventually contain the unpacked extension. 266 // Initialize the path that will eventually contain the unpacked extension.
267 extension_root_ = temp_dir_.path().AppendASCII( 267 extension_root_ = temp_dir_.path().AppendASCII(filenames::kTempExtensionName);
268 extension_filenames::kTempExtensionName);
269 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackUnpackedCrxPathLength", 268 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackUnpackedCrxPathLength",
270 extension_root_); 269 extension_root_);
271 270
272 // Extract the public key and validate the package. 271 // Extract the public key and validate the package.
273 if (!ValidateSignature()) 272 if (!ValidateSignature())
274 return; // ValidateSignature() already reported the error. 273 return; // ValidateSignature() already reported the error.
275 274
276 // Copy the crx file into our working directory. 275 // Copy the crx file into our working directory.
277 base::FilePath temp_crx_path = temp_dir_.path().Append(crx_path_.BaseName()); 276 base::FilePath temp_crx_path = temp_dir_.path().Append(crx_path_.BaseName());
278 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackTempCrxPathLength", 277 PATH_LENGTH_HISTOGRAM("Extensions.SandboxUnpackTempCrxPathLength",
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 // Error serializing manifest.json. 617 // Error serializing manifest.json.
619 ReportFailure( 618 ReportFailure(
620 ERROR_SERIALIZING_MANIFEST_JSON, 619 ERROR_SERIALIZING_MANIFEST_JSON,
621 l10n_util::GetStringFUTF16( 620 l10n_util::GetStringFUTF16(
622 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 621 IDS_EXTENSION_PACKAGE_INSTALL_ERROR,
623 ASCIIToUTF16("ERROR_SERIALIZING_MANIFEST_JSON"))); 622 ASCIIToUTF16("ERROR_SERIALIZING_MANIFEST_JSON")));
624 return NULL; 623 return NULL;
625 } 624 }
626 625
627 base::FilePath manifest_path = 626 base::FilePath manifest_path =
628 extension_root_.Append(kManifestFilename); 627 extension_root_.Append(filenames::kManifestFilename);
629 if (!file_util::WriteFile(manifest_path, 628 if (!file_util::WriteFile(manifest_path,
630 manifest_json.data(), manifest_json.size())) { 629 manifest_json.data(), manifest_json.size())) {
631 // Error saving manifest.json. 630 // Error saving manifest.json.
632 ReportFailure( 631 ReportFailure(
633 ERROR_SAVING_MANIFEST_JSON, 632 ERROR_SAVING_MANIFEST_JSON,
634 l10n_util::GetStringFUTF16( 633 l10n_util::GetStringFUTF16(
635 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 634 IDS_EXTENSION_PACKAGE_INSTALL_ERROR,
636 ASCIIToUTF16("ERROR_SAVING_MANIFEST_JSON"))); 635 ASCIIToUTF16("ERROR_SAVING_MANIFEST_JSON")));
637 return NULL; 636 return NULL;
638 } 637 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 l10n_util::GetStringFUTF16( 774 l10n_util::GetStringFUTF16(
776 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 775 IDS_EXTENSION_PACKAGE_INSTALL_ERROR,
777 ASCIIToUTF16("INVALID_CATALOG_DATA"))); 776 ASCIIToUTF16("INVALID_CATALOG_DATA")));
778 return false; 777 return false;
779 } 778 }
780 779
781 // TODO(viettrungluu): Fix the |FilePath::FromWStringHack(UTF8ToWide())| 780 // TODO(viettrungluu): Fix the |FilePath::FromWStringHack(UTF8ToWide())|
782 // hack and remove the corresponding #include. 781 // hack and remove the corresponding #include.
783 base::FilePath relative_path = 782 base::FilePath relative_path =
784 base::FilePath::FromWStringHack(UTF8ToWide(it.key())); 783 base::FilePath::FromWStringHack(UTF8ToWide(it.key()));
785 relative_path = relative_path.Append(kMessagesFilename); 784 relative_path = relative_path.Append(filenames::kMessagesFilename);
786 if (relative_path.IsAbsolute() || relative_path.ReferencesParent()) { 785 if (relative_path.IsAbsolute() || relative_path.ReferencesParent()) {
787 // Invalid path for catalog. 786 // Invalid path for catalog.
788 ReportFailure( 787 ReportFailure(
789 INVALID_PATH_FOR_CATALOG, 788 INVALID_PATH_FOR_CATALOG,
790 l10n_util::GetStringFUTF16( 789 l10n_util::GetStringFUTF16(
791 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, 790 IDS_EXTENSION_PACKAGE_INSTALL_ERROR,
792 ASCIIToUTF16("INVALID_PATH_FOR_CATALOG"))); 791 ASCIIToUTF16("INVALID_PATH_FOR_CATALOG")));
793 return false; 792 return false;
794 } 793 }
795 base::FilePath path = extension_root_.Append(relative_path); 794 base::FilePath path = extension_root_.Append(relative_path);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 826
828 void SandboxedUnpacker::Cleanup() { 827 void SandboxedUnpacker::Cleanup() {
829 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); 828 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread());
830 if (!temp_dir_.Delete()) { 829 if (!temp_dir_.Delete()) {
831 LOG(WARNING) << "Can not delete temp directory at " 830 LOG(WARNING) << "Can not delete temp directory at "
832 << temp_dir_.path().value(); 831 << temp_dir_.path().value();
833 } 832 }
834 } 833 }
835 834
836 } // namespace extensions 835 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698