| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_COMMON_EXTENSIONS_EXTENSION_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 #if defined(OS_WIN) | 99 #if defined(OS_WIN) |
| 100 static const char* kExtensionRegistryPath; | 100 static const char* kExtensionRegistryPath; |
| 101 #endif | 101 #endif |
| 102 | 102 |
| 103 // The number of bytes in a legal id. | 103 // The number of bytes in a legal id. |
| 104 static const size_t kIdSize; | 104 static const size_t kIdSize; |
| 105 | 105 |
| 106 // The mimetype used for extensions. | 106 // The mimetype used for extensions. |
| 107 static const char kMimeType[]; | 107 static const char kMimeType[]; |
| 108 | 108 |
| 109 Extension() | |
| 110 : location_(INVALID), is_theme_(false), | |
| 111 background_page_ready_(false) {} | |
| 112 explicit Extension(const FilePath& path); | 109 explicit Extension(const FilePath& path); |
| 113 virtual ~Extension(); | 110 virtual ~Extension(); |
| 114 | 111 |
| 115 // Resets the id counter. This is only useful for unit tests. | |
| 116 static void ResetGeneratedIdCounter() { | |
| 117 id_counter_ = 0; | |
| 118 } | |
| 119 | |
| 120 // Checks to see if the extension has a valid ID. | 112 // Checks to see if the extension has a valid ID. |
| 121 static bool IdIsValid(const std::string& id); | 113 static bool IdIsValid(const std::string& id); |
| 122 | 114 |
| 123 // Returns true if the specified file is an extension. | 115 // Returns true if the specified file is an extension. |
| 124 static bool IsExtension(const FilePath& file_name); | 116 static bool IsExtension(const FilePath& file_name); |
| 125 | 117 |
| 126 // Whether the |location| is external or not. | 118 // Whether the |location| is external or not. |
| 127 static inline bool IsExternalLocation(Location location) { | 119 static inline bool IsExternalLocation(Location location) { |
| 128 return location == Extension::EXTERNAL_PREF || | 120 return location == Extension::EXTERNAL_PREF || |
| 129 location == Extension::EXTERNAL_REGISTRY; | 121 location == Extension::EXTERNAL_REGISTRY; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 153 | 145 |
| 154 // |input| is expected to be the text of an rsa public or private key. It | 146 // |input| is expected to be the text of an rsa public or private key. It |
| 155 // tolerates the presence or absence of bracking header/footer like this: | 147 // tolerates the presence or absence of bracking header/footer like this: |
| 156 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY----- | 148 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY----- |
| 157 // and may contain newlines. | 149 // and may contain newlines. |
| 158 static bool ParsePEMKeyBytes(const std::string& input, std::string* output); | 150 static bool ParsePEMKeyBytes(const std::string& input, std::string* output); |
| 159 | 151 |
| 160 // Does a simple base64 encoding of |input| into |output|. | 152 // Does a simple base64 encoding of |input| into |output|. |
| 161 static bool ProducePEM(const std::string& input, std::string* output); | 153 static bool ProducePEM(const std::string& input, std::string* output); |
| 162 | 154 |
| 163 // Note: The result is coverted to lower-case because the browser enforces | 155 // Generates an extension ID from arbitrary input. The same input string will |
| 164 // hosts to be lower-case in omni-bar. | 156 // always generate the same output ID. |
| 165 static bool GenerateIdFromPublicKey(const std::string& input, | 157 static bool GenerateId(const std::string& input, std::string* output); |
| 166 std::string* output); | |
| 167 | 158 |
| 168 // Expects base64 encoded |input| and formats into |output| including | 159 // Expects base64 encoded |input| and formats into |output| including |
| 169 // the appropriate header & footer. | 160 // the appropriate header & footer. |
| 170 static bool FormatPEMForFileOutput(const std::string input, | 161 static bool FormatPEMForFileOutput(const std::string input, |
| 171 std::string* output, bool is_public); | 162 std::string* output, bool is_public); |
| 172 | 163 |
| 173 // Determine whether |new_extension| has increased privileges compared to | 164 // Determine whether |new_extension| has increased privileges compared to |
| 174 // |old_extension|. | 165 // |old_extension|. |
| 175 static bool IsPrivilegeIncrease(Extension* old_extension, | 166 static bool IsPrivilegeIncrease(Extension* old_extension, |
| 176 Extension* new_extension); | 167 Extension* new_extension); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 // Runtime data: | 265 // Runtime data: |
| 275 // Put dynamic data about the state of a running extension below. | 266 // Put dynamic data about the state of a running extension below. |
| 276 | 267 |
| 277 // Whether the background page, if any, is ready. We don't load other | 268 // Whether the background page, if any, is ready. We don't load other |
| 278 // components until then. If there is no background page, we consider it to | 269 // components until then. If there is no background page, we consider it to |
| 279 // be ready. | 270 // be ready. |
| 280 bool GetBackgroundPageReady(); | 271 bool GetBackgroundPageReady(); |
| 281 void SetBackgroundPageReady(); | 272 void SetBackgroundPageReady(); |
| 282 | 273 |
| 283 private: | 274 private: |
| 284 // Counter used to assign ids to extensions that are loaded using | |
| 285 // --load-extension. | |
| 286 static int id_counter_; | |
| 287 | |
| 288 // Returns the next counter id. Intentionally post-incrementing so that first | |
| 289 // value is 0. | |
| 290 static int NextGeneratedId() { return id_counter_++; } | |
| 291 | |
| 292 // Helper method that loads a UserScript object from a | 275 // Helper method that loads a UserScript object from a |
| 293 // dictionary in the content_script list of the manifest. | 276 // dictionary in the content_script list of the manifest. |
| 294 bool LoadUserScriptHelper(const DictionaryValue* content_script, | 277 bool LoadUserScriptHelper(const DictionaryValue* content_script, |
| 295 int definition_index, | 278 int definition_index, |
| 296 std::string* error, | 279 std::string* error, |
| 297 UserScript* result); | 280 UserScript* result); |
| 298 | 281 |
| 299 // Helper method that loads a ExtensionAction object from a | 282 // Helper method that loads a ExtensionAction object from a |
| 300 // dictionary in the page_action or browser_action section of the manifest. | 283 // dictionary in the page_action or browser_action section of the manifest. |
| 301 ExtensionAction* LoadExtensionActionHelper( | 284 ExtensionAction* LoadExtensionActionHelper( |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 | 387 |
| 405 // True if the background page is ready. | 388 // True if the background page is ready. |
| 406 bool background_page_ready_; | 389 bool background_page_ready_; |
| 407 | 390 |
| 408 FRIEND_TEST(ExtensionTest, LoadPageActionHelper); | 391 FRIEND_TEST(ExtensionTest, LoadPageActionHelper); |
| 409 | 392 |
| 410 DISALLOW_COPY_AND_ASSIGN(Extension); | 393 DISALLOW_COPY_AND_ASSIGN(Extension); |
| 411 }; | 394 }; |
| 412 | 395 |
| 413 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 396 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
| OLD | NEW |