Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / component_updater / component_unpacker.h
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_
6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/files/file_path.h"
13 #include "base/json/json_file_value_serializer.h"
14 #include "base/memory/scoped_ptr.h"
15
16 namespace component_updater {
17
18 class ComponentInstaller;
19 class ComponentPatcher;
20
21 // Deserializes the CRX manifest. The top level must be a dictionary.
22 scoped_ptr<base::DictionaryValue> ReadManifest(
23     const base::FilePath& unpack_path);
24
25 // In charge of unpacking the component CRX package and verifying that it is
26 // well formed and the cryptographic signature is correct. If there is no
27 // error the component specific installer will be invoked to proceed with
28 // the component installation or update.
29 //
30 // This class should be used only by the component updater. It is inspired
31 // and overlaps with code in the extension's SandboxedUnpacker.
32 // The main differences are:
33 // - The public key hash is full SHA256.
34 // - Does not use a sandboxed unpacker. A valid component is fully trusted.
35 // - The manifest can have different attributes and resources are not
36 //   transcoded.
37 class ComponentUnpacker {
38  public:
39   // Possible error conditions.
40   // Add only to the bottom of this enum; the order must be kept stable.
41   enum Error {
42     kNone,
43     kInvalidParams,
44     kInvalidFile,
45     kUnzipPathError,
46     kUnzipFailed,
47     kNoManifest,
48     kBadManifest,
49     kBadExtension,
50     kInvalidId,
51     kInstallerError,
52     kIoError,
53     kDeltaVerificationFailure,
54     kDeltaBadCommands,
55     kDeltaUnsupportedCommand,
56     kDeltaOperationFailure,
57     kDeltaPatchProcessFailure,
58     kDeltaMissingExistingFile,
59     kFingerprintWriteFailed,
60   };
61   // Unpacks, verifies and calls the installer. |pk_hash| is the expected
62   // public key SHA256 hash. |path| is the current location of the CRX.
63   ComponentUnpacker(const std::vector<uint8>& pk_hash,
64                     const base::FilePath& path,
65                     const std::string& fingerprint,
66                     ComponentPatcher* patcher,
67                     ComponentInstaller* installer);
68
69   // If something went wrong during unpacking or installer invocation, the
70   // destructor will delete the unpacked CRX files.
71   ~ComponentUnpacker();
72
73   Error error() const { return error_; }
74
75   int extended_error() const { return extended_error_; }
76
77  private:
78   base::FilePath unpack_path_;
79   Error error_;
80   int extended_error_;  // Provides additional error information.
81 };
82
83 }  // namespace component_updater
84
85 #endif  // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UNPACKER_H_