OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "base/version.h" | 15 #include "base/version.h" |
16 #include "chrome/browser/extensions/user_script_master.h" | 16 #include "chrome/browser/extensions/user_script_master.h" |
17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
18 | 18 |
19 // Represents a Chromium extension. | 19 // Represents a Chromium extension. |
20 class Extension { | 20 class Extension { |
21 public: | 21 public: |
22 Extension() {} | 22 Extension() {} |
23 explicit Extension(const FilePath& path); | 23 explicit Extension(const FilePath& path); |
24 explicit Extension(const Extension& path); | |
24 | 25 |
25 // The format for extension manifests that this code understands. | 26 // The format for extension manifests that this code understands. |
26 static const unsigned int kExpectedFormatVersion = 1; | 27 static const unsigned int kExpectedFormatVersion = 1; |
27 | 28 |
28 // The name of the manifest inside an extension. | 29 // The name of the manifest inside an extension. |
29 static const char kManifestFilename[]; | 30 static const char kManifestFilename[]; |
30 | 31 |
31 // Keys used in JSON representation of extensions. | 32 // Keys used in JSON representation of extensions. |
32 static const wchar_t* kContentScriptsKey; | 33 static const wchar_t* kContentScriptsKey; |
33 static const wchar_t* kDescriptionKey; | 34 static const wchar_t* kDescriptionKey; |
34 static const wchar_t* kFormatVersionKey; | 35 static const wchar_t* kFormatVersionKey; |
35 static const wchar_t* kIdKey; | 36 static const wchar_t* kIdKey; |
36 static const wchar_t* kJsKey; | 37 static const wchar_t* kJsKey; |
37 static const wchar_t* kMatchesKey; | 38 static const wchar_t* kMatchesKey; |
38 static const wchar_t* kNameKey; | 39 static const wchar_t* kNameKey; |
39 static const wchar_t* kRunAtKey; | 40 static const wchar_t* kRunAtKey; |
40 static const wchar_t* kVersionKey; | 41 static const wchar_t* kVersionKey; |
41 static const wchar_t* kZipHashKey; | 42 static const wchar_t* kZipHashKey; |
42 static const wchar_t* kPluginsDirKey; | 43 static const wchar_t* kPluginsDirKey; |
44 static const wchar_t* kThemeKey; | |
43 | 45 |
44 // Some values expected in manifests. | 46 // Some values expected in manifests. |
45 static const char* kRunAtDocumentStartValue; | 47 static const char* kRunAtDocumentStartValue; |
46 static const char* kRunAtDocumentEndValue; | 48 static const char* kRunAtDocumentEndValue; |
47 | 49 |
48 // Error messages returned from InitFromValue(). | 50 // Error messages returned from InitFromValue(). |
49 static const char* kInvalidContentScriptError; | 51 static const char* kInvalidContentScriptError; |
50 static const char* kInvalidContentScriptsListError; | 52 static const char* kInvalidContentScriptsListError; |
51 static const char* kInvalidDescriptionError; | 53 static const char* kInvalidDescriptionError; |
52 static const char* kInvalidFormatVersionError; | 54 static const char* kInvalidFormatVersionError; |
53 static const char* kInvalidIdError; | 55 static const char* kInvalidIdError; |
54 static const char* kInvalidJsCountError; | 56 static const char* kInvalidJsCountError; |
55 static const char* kInvalidJsError; | 57 static const char* kInvalidJsError; |
56 static const char* kInvalidJsListError; | 58 static const char* kInvalidJsListError; |
57 static const char* kInvalidManifestError; | 59 static const char* kInvalidManifestError; |
58 static const char* kInvalidMatchCountError; | 60 static const char* kInvalidMatchCountError; |
59 static const char* kInvalidMatchError; | 61 static const char* kInvalidMatchError; |
60 static const char* kInvalidMatchesError; | 62 static const char* kInvalidMatchesError; |
61 static const char* kInvalidNameError; | 63 static const char* kInvalidNameError; |
62 static const char* kInvalidRunAtError; | 64 static const char* kInvalidRunAtError; |
63 static const char* kInvalidVersionError; | 65 static const char* kInvalidVersionError; |
64 static const char* kInvalidZipHashError; | 66 static const char* kInvalidZipHashError; |
65 static const char* kInvalidPluginsDirError; | 67 static const char* kInvalidPluginsDirError; |
66 | 68 |
67 // The number of bytes in a legal id. | 69 // The number of bytes in a legal id. |
68 static const size_t kIdSize; | 70 static const size_t kIdSize; |
69 | 71 |
70 // Creates an absolute url to a resource inside an extension. The | 72 // Returns an absolute url to a resource inside of an extension. The |
71 // |extension_url| argument should be the url() from an Extension object. The | 73 // |extension_url| argument should be the url() from an Extension object. The |
72 // |relative_path| can be untrusted user input. The returned URL will either | 74 // |relative_path| can be untrusted user input. The returned URL will either |
73 // be invalid() or a child of |extension_url|. | 75 // be invalid() or a child of |extension_url|. |
74 // NOTE: Static so that it can be used from multiple threads. | 76 // NOTE: Static so that it can be used from multiple threads. |
75 static GURL GetResourceURL(const GURL& extension_url, | 77 static GURL GetResourceURL(const GURL& extension_url, |
76 const std::string& relative_path); | 78 const std::string& relative_path); |
77 | 79 |
78 // Creates an absolute path to a resource inside an extension. The | 80 // Returns an absolute path to a resource inside of an extension. The |
79 // |extension_path| argument should be the path() from an Extension object. | 81 // |extension_path| argument should be the path() from an Extension object. |
80 // The |relative_path| can be untrusted user input. The returned path will | 82 // The |relative_path| can be untrusted user input. The returned path will |
81 // either be empty or a child of extension_path. | 83 // either be empty or a child of extension_path. |
82 // NOTE: Static so that it can be used from multiple threads. | 84 // NOTE: Static so that it can be used from multiple threads. |
83 static FilePath GetResourcePath(const FilePath& extension_path, | 85 static FilePath GetResourcePath(const FilePath& extension_path, |
84 const std::string& relative_path); | 86 const std::string& relative_path); |
85 | 87 |
88 // Returns an absolute path to a resource inside of an extension if the | |
89 // extension has a theme defined with the given |resource_id|. Otherwise | |
90 // the path will be empty. Note that this method is not static as it is | |
91 // only intended to be called on an extension which has registered itself | |
92 // as providing a theme. | |
93 FilePath GetThemeResourcePath(const int resource_id); | |
94 | |
86 // The path to the folder the extension is stored in. | 95 // The path to the folder the extension is stored in. |
87 const FilePath& path() const { return path_; } | 96 const FilePath& path() const { return path_; } |
88 | 97 |
89 // The base URL for the extension. | 98 // The base URL for the extension. |
90 const GURL& url() const { return extension_url_; } | 99 const GURL& url() const { return extension_url_; } |
91 | 100 |
92 // A human-readable ID for the extension. The convention is to use something | 101 // A human-readable ID for the extension. The convention is to use something |
93 // like 'com.example.myextension', but this is not currently enforced. An | 102 // like 'com.example.myextension', but this is not currently enforced. An |
94 // extension's ID is used in things like directory structures and URLs, and | 103 // extension's ID is used in things like directory structures and URLs, and |
95 // is expected to not change across versions. In the case of conflicts, | 104 // is expected to not change across versions. In the case of conflicts, |
96 // updates will only be allowed if the extension can be validated using the | 105 // updates will only be allowed if the extension can be validated using the |
97 // previous version's update key. | 106 // previous version's update key. |
98 const std::string& id() const { return id_; } | 107 const std::string& id() const { return id_; } |
99 | 108 |
100 // The version number for the extension. | 109 // The version number for the extension. |
101 const Version* version() const { return version_.get(); } | 110 Version* version() const { return version_.get(); } |
Aaron Boodman
2009/03/04 20:19:27
Did you mean to change this to a mutable instance?
Erik does not do reviews
2009/03/04 20:21:55
nope, good catch. fixed and committing (when the
| |
102 | 111 |
103 // String representation of the version number. | 112 // String representation of the version number. |
104 const std::string VersionString() const; | 113 const std::string VersionString() const; |
105 | 114 |
106 // A human-readable name of the extension. | 115 // A human-readable name of the extension. |
107 const std::string& name() const { return name_; } | 116 const std::string& name() const { return name_; } |
108 | 117 |
109 // An optional longer description of the extension. | 118 // An optional longer description of the extension. |
110 const std::string& description() const { return description_; } | 119 const std::string& description() const { return description_; } |
111 | 120 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 UserScriptList content_scripts_; | 154 UserScriptList content_scripts_; |
146 | 155 |
147 // Path to the directory of NPAPI plugins that the extension contains. | 156 // Path to the directory of NPAPI plugins that the extension contains. |
148 FilePath plugins_dir_; | 157 FilePath plugins_dir_; |
149 | 158 |
150 // A SHA1 hash of the contents of the zip file. Note that this key is only | 159 // A SHA1 hash of the contents of the zip file. Note that this key is only |
151 // present in the manifest that's prepended to the zip. The inner manifest | 160 // present in the manifest that's prepended to the zip. The inner manifest |
152 // will not have this key. | 161 // will not have this key. |
153 std::string zip_hash_; | 162 std::string zip_hash_; |
154 | 163 |
155 DISALLOW_COPY_AND_ASSIGN(Extension); | 164 // A map of resource id's to relative file paths. |
165 std::map<const std::wstring, std::string> theme_paths_; | |
166 | |
167 // We implement copy, but not assign. | |
168 void operator=(const Extension&); | |
156 }; | 169 }; |
157 | 170 |
158 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_H_ | 171 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_H_ |
OLD | NEW |