| 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/string16.h" | 12 #include "base/string16.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/extensions/user_script_master.h" | |
| 15 #include "googleurl/src/gurl.h" | |
| 16 | 14 |
| 17 // Represents a Chromium extension. | 15 // Represents a Chromium extension. |
| 18 class Extension { | 16 class Extension { |
| 19 public: | 17 public: |
| 20 Extension(const FilePath& path); | 18 Extension(){}; |
| 19 Extension(const FilePath& path) : path_(path) {}; |
| 21 | 20 |
| 22 // The format for extension manifests that this code understands. | 21 // The format for extension manifests that this code understands. |
| 23 static const int kExpectedFormatVersion = 1; | 22 static const int kExpectedFormatVersion = 1; |
| 24 | 23 |
| 25 // The name of the manifest inside an extension. | 24 // The name of the manifest inside an extension. |
| 26 static const char kManifestFilename[]; | 25 static const char kManifestFilename[]; |
| 27 | 26 |
| 28 // Keys used in JSON representation of extensions. | 27 // Keys used in JSON representation of extensions. |
| 29 static const wchar_t* kDescriptionKey; | |
| 30 static const wchar_t* kFilesKey; | |
| 31 static const wchar_t* kFormatVersionKey; | 28 static const wchar_t* kFormatVersionKey; |
| 32 static const wchar_t* kIdKey; | 29 static const wchar_t* kIdKey; |
| 33 static const wchar_t* kMatchesKey; | |
| 34 static const wchar_t* kNameKey; | 30 static const wchar_t* kNameKey; |
| 35 static const wchar_t* kUserScriptsKey; | 31 static const wchar_t* kDescriptionKey; |
| 32 static const wchar_t* kContentScriptsKey; |
| 36 static const wchar_t* kVersionKey; | 33 static const wchar_t* kVersionKey; |
| 37 | 34 |
| 38 // Error messages returned from InitFromValue(). | 35 // Error messages returned from InitFromValue(). |
| 36 static const char* kInvalidFormatVersionError; |
| 37 static const char* kInvalidManifestError; |
| 38 static const char* kInvalidIdError; |
| 39 static const char* kInvalidNameError; |
| 39 static const char* kInvalidDescriptionError; | 40 static const char* kInvalidDescriptionError; |
| 40 static const char* kInvalidFileCountError; | 41 static const char* kInvalidContentScriptsListError; |
| 41 static const char* kInvalidFileError; | 42 static const char* kInvalidContentScriptError; |
| 42 static const char* kInvalidFilesError; | |
| 43 static const char* kInvalidFormatVersionError; | |
| 44 static const char* kInvalidIdError; | |
| 45 static const char* kInvalidManifestError; | |
| 46 static const char* kInvalidMatchCountError; | |
| 47 static const char* kInvalidMatchError; | |
| 48 static const char* kInvalidMatchesError; | |
| 49 static const char* kInvalidNameError; | |
| 50 static const char* kInvalidUserScriptError; | |
| 51 static const char* kInvalidUserScriptsListError; | |
| 52 static const char* kInvalidVersionError; | 43 static const char* kInvalidVersionError; |
| 53 | 44 |
| 54 // Creates an absolute url to a resource inside an extension. The | |
| 55 // |extension_url| argument should be the url() from an Extension object. The | |
| 56 // |relative_path| can be untrusted user input. The returned URL will either | |
| 57 // be invalid() or a child of |extension_url|. | |
| 58 // NOTE: Static so that it can be used from multiple threads. | |
| 59 static GURL GetResourceURL(const GURL& extension_url, | |
| 60 const std::string& relative_path); | |
| 61 | |
| 62 // Creates an absolute path to a resource inside an extension. The | |
| 63 // |extension_path| argument should be the path() from an Extension object. | |
| 64 // The |relative_path| can be untrusted user input. The returned path will | |
| 65 // either be empty or a child of extension_path. | |
| 66 // NOTE: Static so that it can be used from multiple threads. | |
| 67 static FilePath GetResourcePath(const FilePath& extension_path, | |
| 68 const std::string& relative_path); | |
| 69 | |
| 70 // The path to the folder the extension is stored in. | 45 // The path to the folder the extension is stored in. |
| 71 const FilePath& path() const { return path_; } | 46 const FilePath& path() const { return path_; } |
| 72 | 47 |
| 73 // The base URL for the extension. | |
| 74 const GURL& url() const { return extension_url_; } | |
| 75 | |
| 76 // A human-readable ID for the extension. The convention is to use something | 48 // A human-readable ID for the extension. The convention is to use something |
| 77 // like 'com.example.myextension', but this is not currently enforced. An | 49 // like 'com.example.myextension', but this is not currently enforced. An |
| 78 // extension's ID is used in things like directory structures and URLs, and | 50 // extension's ID is used in things like directory structures and URLs, and |
| 79 // is expected to not change across versions. In the case of conflicts, | 51 // is expected to not change across versions. In the case of conflicts, |
| 80 // updates will only be allowed if the extension can be validated using the | 52 // updates will only be allowed if the extension can be validated using the |
| 81 // previous version's update key. | 53 // previous version's update key. |
| 82 const std::string& id() const { return id_; } | 54 const std::string& id() const { return id_; } |
| 83 | 55 |
| 84 // The version number for the extension. | 56 // The version number for the extension. |
| 85 const std::string& version() const { return version_; } | 57 const std::string& version() const { return version_; } |
| 86 | 58 |
| 87 // A human-readable name of the extension. | 59 // A human-readable name of the extension. |
| 88 const std::string& name() const { return name_; } | 60 const std::string& name() const { return name_; } |
| 89 | 61 |
| 90 // An optional longer description of the extension. | 62 // An optional longer description of the extension. |
| 91 const std::string& description() const { return description_; } | 63 const std::string& description() const { return description_; } |
| 92 | 64 |
| 93 // Paths to the content scripts that the extension contains. | 65 // Paths to the content scripts that the extension contains. |
| 94 const UserScriptList& user_scripts() const { | 66 const std::vector<std::string>& content_scripts() const { |
| 95 return user_scripts_; | 67 return content_scripts_; |
| 96 } | 68 } |
| 97 | 69 |
| 98 // Initialize the extension from a parsed manifest. | 70 // Initialize the extension from a parsed manifest. |
| 99 bool InitFromValue(const DictionaryValue& value, std::string* error); | 71 bool InitFromValue(const DictionaryValue& value, std::string* error); |
| 100 | 72 |
| 73 // Serialize the extension to a DictionaryValue. |
| 74 void CopyToValue(DictionaryValue* value); |
| 75 |
| 101 private: | 76 private: |
| 102 // The path to the directory the extension is stored in. | 77 // The path to the directory the extension is stored in. |
| 103 FilePath path_; | 78 FilePath path_; |
| 104 | 79 |
| 105 // The base extension url for the extension. | |
| 106 GURL extension_url_; | |
| 107 | |
| 108 // The extension's ID. | 80 // The extension's ID. |
| 109 std::string id_; | 81 std::string id_; |
| 110 | 82 |
| 111 // The extension's version. | 83 // The extension's version. |
| 112 std::string version_; | 84 std::string version_; |
| 113 | 85 |
| 114 // The extension's human-readable name. | 86 // The extension's human-readable name. |
| 115 std::string name_; | 87 std::string name_; |
| 116 | 88 |
| 117 // An optional description for the extension. | 89 // An optional description for the extension. |
| 118 std::string description_; | 90 std::string description_; |
| 119 | 91 |
| 120 // Paths to the content scripts the extension contains. | 92 // Paths to the content scripts the extension contains. |
| 121 UserScriptList user_scripts_; | 93 std::vector<std::string> content_scripts_; |
| 122 | 94 |
| 123 DISALLOW_COPY_AND_ASSIGN(Extension); | 95 DISALLOW_COPY_AND_ASSIGN(Extension); |
| 124 }; | 96 }; |
| 125 | 97 |
| 126 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_H_ | 98 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_H_ |
| OLD | NEW |