| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <algorithm> | 8 #include <algorithm> |
| 9 #include <iosfwd> | 9 #include <iosfwd> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/hash_tables.h" | 17 #include "base/hash_tables.h" |
| 18 #include "base/memory/linked_ptr.h" | 18 #include "base/memory/linked_ptr.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 22 #include "base/threading/thread_checker.h" | 22 #include "base/threading/thread_checker.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | 23 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "chrome/common/extensions/extension_icon_set.h" | 24 #include "chrome/common/extensions/extension_icon_set.h" |
| 25 #include "chrome/common/extensions/extension_resource.h" | |
| 26 #include "chrome/common/extensions/manifest.h" | 25 #include "chrome/common/extensions/manifest.h" |
| 27 #include "chrome/common/extensions/permissions/api_permission.h" | 26 #include "chrome/common/extensions/permissions/api_permission.h" |
| 28 #include "chrome/common/extensions/permissions/permission_message.h" | 27 #include "chrome/common/extensions/permissions/permission_message.h" |
| 29 #include "chrome/common/extensions/user_script.h" | 28 #include "chrome/common/extensions/user_script.h" |
| 29 #include "extensions/common/extension_resource.h" |
| 30 #include "extensions/common/install_warning.h" | 30 #include "extensions/common/install_warning.h" |
| 31 #include "extensions/common/url_pattern.h" | 31 #include "extensions/common/url_pattern.h" |
| 32 #include "extensions/common/url_pattern_set.h" | 32 #include "extensions/common/url_pattern_set.h" |
| 33 #include "googleurl/src/gurl.h" | 33 #include "googleurl/src/gurl.h" |
| 34 #include "ui/base/accelerators/accelerator.h" | 34 #include "ui/base/accelerators/accelerator.h" |
| 35 #include "ui/gfx/size.h" | 35 #include "ui/gfx/size.h" |
| 36 | 36 |
| 37 class ExtensionAction; | 37 class ExtensionAction; |
| 38 class SkBitmap; | 38 class SkBitmap; |
| 39 class Version; | 39 class Version; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 int flags, | 184 int flags, |
| 185 const std::string& explicit_id, | 185 const std::string& explicit_id, |
| 186 std::string* error); | 186 std::string* error); |
| 187 | 187 |
| 188 // Valid schemes for web extent URLPatterns. | 188 // Valid schemes for web extent URLPatterns. |
| 189 static const int kValidWebExtentSchemes; | 189 static const int kValidWebExtentSchemes; |
| 190 | 190 |
| 191 // Valid schemes for host permission URLPatterns. | 191 // Valid schemes for host permission URLPatterns. |
| 192 static const int kValidHostPermissionSchemes; | 192 static const int kValidHostPermissionSchemes; |
| 193 | 193 |
| 194 // The name of the manifest inside an extension. | |
| 195 static const base::FilePath::CharType kManifestFilename[]; | |
| 196 | |
| 197 // The name of locale folder inside an extension. | |
| 198 static const base::FilePath::CharType kLocaleFolder[]; | |
| 199 | |
| 200 // The name of the messages file inside an extension. | |
| 201 static const base::FilePath::CharType kMessagesFilename[]; | |
| 202 | |
| 203 // The base directory for subdirectories with platform-specific code. | |
| 204 static const base::FilePath::CharType kPlatformSpecificFolder[]; | |
| 205 | |
| 206 #if defined(OS_WIN) | 194 #if defined(OS_WIN) |
| 207 static const char kExtensionRegistryPath[]; | 195 static const char kExtensionRegistryPath[]; |
| 208 #endif | 196 #endif |
| 209 | 197 |
| 210 // The number of bytes in a legal id. | |
| 211 static const size_t kIdSize; | |
| 212 | |
| 213 // The mimetype used for extensions. | 198 // The mimetype used for extensions. |
| 214 static const char kMimeType[]; | 199 static const char kMimeType[]; |
| 215 | 200 |
| 216 // Checks to see if the extension has a valid ID. | 201 // Checks to see if the extension has a valid ID. |
| 217 static bool IdIsValid(const std::string& id); | 202 static bool IdIsValid(const std::string& id); |
| 218 | 203 |
| 219 // Generate an ID for an extension in the given path. | |
| 220 // Used while developing extensions, before they have a key. | |
| 221 static std::string GenerateIdForPath(const base::FilePath& file_name); | |
| 222 | |
| 223 // Returns true if the specified file is an extension. | 204 // Returns true if the specified file is an extension. |
| 224 static bool IsExtension(const base::FilePath& file_name); | 205 static bool IsExtension(const base::FilePath& file_name); |
| 225 | 206 |
| 226 // Fills the |info| dictionary with basic information about the extension. | 207 // Fills the |info| dictionary with basic information about the extension. |
| 227 // |enabled| is injected for easier testing. | 208 // |enabled| is injected for easier testing. |
| 228 void GetBasicInfo(bool enabled, base::DictionaryValue* info) const; | 209 void GetBasicInfo(bool enabled, base::DictionaryValue* info) const; |
| 229 | 210 |
| 230 // See Type definition in Manifest. | 211 // See Type definition in Manifest. |
| 231 Manifest::Type GetType() const; | 212 Manifest::Type GetType() const; |
| 232 | 213 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 263 | 244 |
| 264 // |input| is expected to be the text of an rsa public or private key. It | 245 // |input| is expected to be the text of an rsa public or private key. It |
| 265 // tolerates the presence or absence of bracking header/footer like this: | 246 // tolerates the presence or absence of bracking header/footer like this: |
| 266 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY----- | 247 // -----(BEGIN|END) [RSA PUBLIC/PRIVATE] KEY----- |
| 267 // and may contain newlines. | 248 // and may contain newlines. |
| 268 static bool ParsePEMKeyBytes(const std::string& input, std::string* output); | 249 static bool ParsePEMKeyBytes(const std::string& input, std::string* output); |
| 269 | 250 |
| 270 // Does a simple base64 encoding of |input| into |output|. | 251 // Does a simple base64 encoding of |input| into |output|. |
| 271 static bool ProducePEM(const std::string& input, std::string* output); | 252 static bool ProducePEM(const std::string& input, std::string* output); |
| 272 | 253 |
| 273 // Generates an extension ID from arbitrary input. The same input string will | |
| 274 // always generate the same output ID. | |
| 275 static bool GenerateId(const std::string& input, | |
| 276 std::string* output) WARN_UNUSED_RESULT; | |
| 277 | |
| 278 // Expects base64 encoded |input| and formats into |output| including | 254 // Expects base64 encoded |input| and formats into |output| including |
| 279 // the appropriate header & footer. | 255 // the appropriate header & footer. |
| 280 static bool FormatPEMForFileOutput(const std::string& input, | 256 static bool FormatPEMForFileOutput(const std::string& input, |
| 281 std::string* output, | 257 std::string* output, |
| 282 bool is_public); | 258 bool is_public); |
| 283 | 259 |
| 284 // Returns the base extension url for a given |extension_id|. | 260 // Returns the base extension url for a given |extension_id|. |
| 285 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); | 261 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); |
| 286 | 262 |
| 287 // Adds an extension to the scripting whitelist. Used for testing only. | 263 // Adds an extension to the scripting whitelist. Used for testing only. |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 }; | 528 }; |
| 553 | 529 |
| 554 // Chooses the extension ID for an extension based on a variety of criteria. | 530 // Chooses the extension ID for an extension based on a variety of criteria. |
| 555 // The chosen ID will be set in |manifest|. | 531 // The chosen ID will be set in |manifest|. |
| 556 static bool InitExtensionID(extensions::Manifest* manifest, | 532 static bool InitExtensionID(extensions::Manifest* manifest, |
| 557 const base::FilePath& path, | 533 const base::FilePath& path, |
| 558 const std::string& explicit_id, | 534 const std::string& explicit_id, |
| 559 int creation_flags, | 535 int creation_flags, |
| 560 string16* error); | 536 string16* error); |
| 561 | 537 |
| 562 // Normalize the path for use by the extension. On Windows, this will make | |
| 563 // sure the drive letter is uppercase. | |
| 564 static base::FilePath MaybeNormalizePath(const base::FilePath& path); | |
| 565 | |
| 566 // Returns true if this extension id is from a trusted provider. | 538 // Returns true if this extension id is from a trusted provider. |
| 567 static bool IsTrustedId(const std::string& id); | 539 static bool IsTrustedId(const std::string& id); |
| 568 | 540 |
| 569 Extension(const base::FilePath& path, | 541 Extension(const base::FilePath& path, |
| 570 scoped_ptr<extensions::Manifest> manifest); | 542 scoped_ptr<extensions::Manifest> manifest); |
| 571 virtual ~Extension(); | 543 virtual ~Extension(); |
| 572 | 544 |
| 573 // Initialize the extension from a parsed manifest. | 545 // Initialize the extension from a parsed manifest. |
| 574 // TODO(aa): Rename to just Init()? There's no Value here anymore. | 546 // TODO(aa): Rename to just Init()? There's no Value here anymore. |
| 575 // TODO(aa): It is really weird the way this class essentially contains a copy | 547 // TODO(aa): It is really weird the way this class essentially contains a copy |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 | 830 |
| 859 UpdatedExtensionPermissionsInfo( | 831 UpdatedExtensionPermissionsInfo( |
| 860 const Extension* extension, | 832 const Extension* extension, |
| 861 const PermissionSet* permissions, | 833 const PermissionSet* permissions, |
| 862 Reason reason); | 834 Reason reason); |
| 863 }; | 835 }; |
| 864 | 836 |
| 865 } // namespace extensions | 837 } // namespace extensions |
| 866 | 838 |
| 867 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 839 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
| OLD | NEW |