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