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

Side by Side Diff: chrome/browser/extensions/extension_creator.h

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_CREATOR_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_CREATOR_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_CREATOR_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_CREATOR_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 12
13 namespace base {
14 class FilePath;
15 }
16
13 namespace crypto { 17 namespace crypto {
14 class RSAPrivateKey; 18 class RSAPrivateKey;
15 } 19 }
16 20
17 class FilePath;
18
19 namespace extensions { 21 namespace extensions {
20 22
21 // This class create an installable extension (.crx file) given an input 23 // This class create an installable extension (.crx file) given an input
22 // directory that contains a valid manifest.json and the extension's resources 24 // directory that contains a valid manifest.json and the extension's resources
23 // contained within that directory. The output .crx file is always signed with a 25 // contained within that directory. The output .crx file is always signed with a
24 // private key that is either provided in |private_key_path| or is internal 26 // private key that is either provided in |private_key_path| or is internal
25 // generated randomly (and optionally written to |output_private_key_path|. 27 // generated randomly (and optionally written to |output_private_key_path|.
26 class ExtensionCreator { 28 class ExtensionCreator {
27 public: 29 public:
28 ExtensionCreator(); 30 ExtensionCreator();
29 31
30 // Settings to specify treatment of special or ignorable error conditions. 32 // Settings to specify treatment of special or ignorable error conditions.
31 enum RunFlags { 33 enum RunFlags {
32 kNoRunFlags = 0x0, 34 kNoRunFlags = 0x0,
33 kOverwriteCRX = 0x1, 35 kOverwriteCRX = 0x1,
34 kRequireModernManifestVersion = 0x2, 36 kRequireModernManifestVersion = 0x2,
35 }; 37 };
36 38
37 // Categories of error that may need special handling on the UI end. 39 // Categories of error that may need special handling on the UI end.
38 enum ErrorType { kOtherError, kCRXExists }; 40 enum ErrorType { kOtherError, kCRXExists };
39 41
40 bool Run(const FilePath& extension_dir, 42 bool Run(const base::FilePath& extension_dir,
41 const FilePath& crx_path, 43 const base::FilePath& crx_path,
42 const FilePath& private_key_path, 44 const base::FilePath& private_key_path,
43 const FilePath& private_key_output_path, 45 const base::FilePath& private_key_output_path,
44 int run_flags); 46 int run_flags);
45 47
46 // Returns the error message that will be present if Run(...) returned false. 48 // Returns the error message that will be present if Run(...) returned false.
47 std::string error_message() { return error_message_; } 49 std::string error_message() { return error_message_; }
48 50
49 ErrorType error_type() { return error_type_; } 51 ErrorType error_type() { return error_type_; }
50 52
51 private: 53 private:
52 // Verifies input directory's existence. |extension_dir| is the source 54 // Verifies input directory's existence. |extension_dir| is the source
53 // directory that should contain all the extension resources. |crx_path| is 55 // directory that should contain all the extension resources. |crx_path| is
54 // the path to which final crx will be written. 56 // the path to which final crx will be written.
55 // |private_key_path| is the optional path to an existing private key to sign 57 // |private_key_path| is the optional path to an existing private key to sign
56 // the extension. If not provided, a random key will be created (in which case 58 // the extension. If not provided, a random key will be created (in which case
57 // it is written to |private_key_output_path| -- if provided). 59 // it is written to |private_key_output_path| -- if provided).
58 // |flags| is a bitset of RunFlags values. 60 // |flags| is a bitset of RunFlags values.
59 bool InitializeInput(const FilePath& extension_dir, 61 bool InitializeInput(const base::FilePath& extension_dir,
60 const FilePath& crx_path, 62 const base::FilePath& crx_path,
61 const FilePath& private_key_path, 63 const base::FilePath& private_key_path,
62 const FilePath& private_key_output_path, 64 const base::FilePath& private_key_output_path,
63 int run_flags); 65 int run_flags);
64 66
65 // Validates the manifest by trying to load the extension. 67 // Validates the manifest by trying to load the extension.
66 bool ValidateManifest(const FilePath& extension_dir, 68 bool ValidateManifest(const base::FilePath& extension_dir,
67 crypto::RSAPrivateKey* key_pair, 69 crypto::RSAPrivateKey* key_pair,
68 int run_flags); 70 int run_flags);
69 71
70 // Reads private key from |private_key_path|. 72 // Reads private key from |private_key_path|.
71 crypto::RSAPrivateKey* ReadInputKey(const FilePath& private_key_path); 73 crypto::RSAPrivateKey* ReadInputKey(const base::FilePath& private_key_path);
72 74
73 // Generates a key pair and writes the private key to |private_key_path| 75 // Generates a key pair and writes the private key to |private_key_path|
74 // if provided. 76 // if provided.
75 crypto::RSAPrivateKey* GenerateKey(const FilePath& private_key_path); 77 crypto::RSAPrivateKey* GenerateKey(const base::FilePath& private_key_path);
76 78
77 // Creates temporary zip file for the extension. 79 // Creates temporary zip file for the extension.
78 bool CreateZip(const FilePath& extension_dir, const FilePath& temp_path, 80 bool CreateZip(const base::FilePath& extension_dir, const base::FilePath& temp _path,
79 FilePath* zip_path); 81 base::FilePath* zip_path);
80 82
81 // Signs the temporary zip and returns the signature. 83 // Signs the temporary zip and returns the signature.
82 bool SignZip(const FilePath& zip_path, 84 bool SignZip(const base::FilePath& zip_path,
83 crypto::RSAPrivateKey* private_key, 85 crypto::RSAPrivateKey* private_key,
84 std::vector<uint8>* signature); 86 std::vector<uint8>* signature);
85 87
86 // Export installable .crx to |crx_path|. 88 // Export installable .crx to |crx_path|.
87 bool WriteCRX(const FilePath& zip_path, 89 bool WriteCRX(const base::FilePath& zip_path,
88 crypto::RSAPrivateKey* private_key, 90 crypto::RSAPrivateKey* private_key,
89 const std::vector<uint8>& signature, 91 const std::vector<uint8>& signature,
90 const FilePath& crx_path); 92 const base::FilePath& crx_path);
91 93
92 // Holds a message for any error that is raised during Run(...). 94 // Holds a message for any error that is raised during Run(...).
93 std::string error_message_; 95 std::string error_message_;
94 96
95 // Type of error that was raised, if any. 97 // Type of error that was raised, if any.
96 ErrorType error_type_; 98 ErrorType error_type_;
97 99
98 DISALLOW_COPY_AND_ASSIGN(ExtensionCreator); 100 DISALLOW_COPY_AND_ASSIGN(ExtensionCreator);
99 }; 101 };
100 102
101 } // namespace extensions 103 } // namespace extensions
102 104
103 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CREATOR_H_ 105 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CREATOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_apitest.h ('k') | chrome/browser/extensions/extension_creator_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698