| 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/file_path.h" | 16 #include "base/file_path.h" |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/hash_tables.h" | 18 #include "base/hash_tables.h" |
| 19 #include "base/memory/linked_ptr.h" | 19 #include "base/memory/linked_ptr.h" |
| 20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
| 22 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
| 23 #include "base/threading/thread_checker.h" | 23 #include "base/threading/thread_checker.h" |
| 24 #include "chrome/common/extensions/api/extension_action/action_info.h" | 24 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 25 #include "chrome/common/extensions/extension_constants.h" | 25 #include "chrome/common/extensions/extension_constants.h" |
| 26 #include "chrome/common/extensions/extension_icon_set.h" | 26 #include "chrome/common/extensions/extension_icon_set.h" |
| 27 #include "chrome/common/extensions/extension_resource.h" |
| 27 #include "chrome/common/extensions/permissions/api_permission.h" | 28 #include "chrome/common/extensions/permissions/api_permission.h" |
| 28 #include "chrome/common/extensions/permissions/api_permission_set.h" | 29 #include "chrome/common/extensions/permissions/api_permission_set.h" |
| 29 #include "chrome/common/extensions/permissions/permission_message.h" | 30 #include "chrome/common/extensions/permissions/permission_message.h" |
| 30 #include "chrome/common/extensions/user_script.h" | 31 #include "chrome/common/extensions/user_script.h" |
| 31 #include "extensions/common/url_pattern.h" | 32 #include "extensions/common/url_pattern.h" |
| 32 #include "extensions/common/url_pattern_set.h" | 33 #include "extensions/common/url_pattern_set.h" |
| 33 #include "googleurl/src/gurl.h" | 34 #include "googleurl/src/gurl.h" |
| 34 #include "ui/base/accelerators/accelerator.h" | 35 #include "ui/base/accelerators/accelerator.h" |
| 35 #include "ui/gfx/size.h" | 36 #include "ui/gfx/size.h" |
| 36 | 37 |
| 37 class ExtensionAction; | 38 class ExtensionAction; |
| 38 class ExtensionResource; | |
| 39 class SkBitmap; | 39 class SkBitmap; |
| 40 class Version; | 40 class Version; |
| 41 | 41 |
| 42 namespace base { | 42 namespace base { |
| 43 class DictionaryValue; | 43 class DictionaryValue; |
| 44 class ListValue; | 44 class ListValue; |
| 45 } | 45 } |
| 46 | 46 |
| 47 namespace gfx { | 47 namespace gfx { |
| 48 class ImageSkia; | 48 class ImageSkia; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 const base::DictionaryValue& value, | 258 const base::DictionaryValue& value, |
| 259 int flags, | 259 int flags, |
| 260 const std::string& explicit_id, | 260 const std::string& explicit_id, |
| 261 std::string* error); | 261 std::string* error); |
| 262 | 262 |
| 263 // Given two install sources, return the one which should take priority | 263 // Given two install sources, return the one which should take priority |
| 264 // over the other. If an extension is installed from two sources A and B, | 264 // over the other. If an extension is installed from two sources A and B, |
| 265 // its install source should be set to GetHigherPriorityLocation(A, B). | 265 // its install source should be set to GetHigherPriorityLocation(A, B). |
| 266 static Location GetHigherPriorityLocation(Location loc1, Location loc2); | 266 static Location GetHigherPriorityLocation(Location loc1, Location loc2); |
| 267 | 267 |
| 268 // Max size (both dimensions) for browser and page actions. | |
| 269 static const int kPageActionIconMaxSize; | |
| 270 static const int kBrowserActionIconMaxSize; | |
| 271 | |
| 272 // Valid schemes for web extent URLPatterns. | 268 // Valid schemes for web extent URLPatterns. |
| 273 static const int kValidWebExtentSchemes; | 269 static const int kValidWebExtentSchemes; |
| 274 | 270 |
| 275 // Valid schemes for host permission URLPatterns. | 271 // Valid schemes for host permission URLPatterns. |
| 276 static const int kValidHostPermissionSchemes; | 272 static const int kValidHostPermissionSchemes; |
| 277 | 273 |
| 278 // The name of the manifest inside an extension. | 274 // The name of the manifest inside an extension. |
| 279 static const FilePath::CharType kManifestFilename[]; | 275 static const FilePath::CharType kManifestFilename[]; |
| 280 | 276 |
| 281 // The name of locale folder inside an extension. | 277 // The name of locale folder inside an extension. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 // always generate the same output ID. | 372 // always generate the same output ID. |
| 377 static bool GenerateId(const std::string& input, | 373 static bool GenerateId(const std::string& input, |
| 378 std::string* output) WARN_UNUSED_RESULT; | 374 std::string* output) WARN_UNUSED_RESULT; |
| 379 | 375 |
| 380 // Expects base64 encoded |input| and formats into |output| including | 376 // Expects base64 encoded |input| and formats into |output| including |
| 381 // the appropriate header & footer. | 377 // the appropriate header & footer. |
| 382 static bool FormatPEMForFileOutput(const std::string& input, | 378 static bool FormatPEMForFileOutput(const std::string& input, |
| 383 std::string* output, | 379 std::string* output, |
| 384 bool is_public); | 380 bool is_public); |
| 385 | 381 |
| 386 // Given an extension, icon size, and match type, read a valid icon if present | |
| 387 // and decode it into result. In the browser process, this will DCHECK if not | |
| 388 // called on the file thread. To easily load extension images on the UI | |
| 389 // thread, see ImageLoadingTracker. | |
| 390 static void DecodeIcon(const Extension* extension, | |
| 391 int icon_size, | |
| 392 ExtensionIconSet::MatchType match_type, | |
| 393 scoped_ptr<SkBitmap>* result); | |
| 394 | |
| 395 // Given an extension and icon size, read it if present and decode it into | |
| 396 // result. In the browser process, this will DCHECK if not called on the | |
| 397 // file thread. To easily load extension images on the UI thread, see | |
| 398 // ImageLoadingTracker. | |
| 399 static void DecodeIcon(const Extension* extension, | |
| 400 int icon_size, | |
| 401 scoped_ptr<SkBitmap>* result); | |
| 402 | |
| 403 // Given an icon_path and icon size, read it if present and decode it into | |
| 404 // result. In the browser process, this will DCHECK if not called on the | |
| 405 // file thread. To easily load extension images on the UI thread, see | |
| 406 // ImageLoadingTracker. | |
| 407 static void DecodeIconFromPath(const FilePath& icon_path, | |
| 408 int icon_size, | |
| 409 scoped_ptr<SkBitmap>* result); | |
| 410 | |
| 411 // Returns the default extension/app icon (for extensions or apps that don't | |
| 412 // have one). | |
| 413 static const gfx::ImageSkia& GetDefaultIcon(bool is_app); | |
| 414 | |
| 415 // Returns the base extension url for a given |extension_id|. | 382 // Returns the base extension url for a given |extension_id|. |
| 416 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); | 383 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); |
| 417 | 384 |
| 418 // Adds an extension to the scripting whitelist. Used for testing only. | 385 // Adds an extension to the scripting whitelist. Used for testing only. |
| 419 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); | 386 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); |
| 420 static const ScriptingWhitelist* GetScriptingWhitelist(); | 387 static const ScriptingWhitelist* GetScriptingWhitelist(); |
| 421 | 388 |
| 422 // Parses the host and api permissions from the specified permission |key| | 389 // Parses the host and api permissions from the specified permission |key| |
| 423 // from |manifest_|. | 390 // from |manifest_|. |
| 424 bool ParsePermissions(const char* key, | 391 bool ParsePermissions(const char* key, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 // Gets the extension's active permission set. | 446 // Gets the extension's active permission set. |
| 480 scoped_refptr<const PermissionSet> GetActivePermissions() const; | 447 scoped_refptr<const PermissionSet> GetActivePermissions() const; |
| 481 | 448 |
| 482 // Whether context menu should be shown for page and browser actions. | 449 // Whether context menu should be shown for page and browser actions. |
| 483 bool ShowConfigureContextMenus() const; | 450 bool ShowConfigureContextMenus() const; |
| 484 | 451 |
| 485 // Returns a list of paths (relative to the extension dir) for images that | 452 // Returns a list of paths (relative to the extension dir) for images that |
| 486 // the browser might load (like themes and page action icons). | 453 // the browser might load (like themes and page action icons). |
| 487 std::set<FilePath> GetBrowserImages() const; | 454 std::set<FilePath> GetBrowserImages() const; |
| 488 | 455 |
| 489 // Get an extension icon as a resource or URL. | |
| 490 ExtensionResource GetIconResource( | |
| 491 int size, ExtensionIconSet::MatchType match_type) const; | |
| 492 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const; | |
| 493 | |
| 494 // Gets the fully resolved absolute launch URL. | 456 // Gets the fully resolved absolute launch URL. |
| 495 GURL GetFullLaunchURL() const; | 457 GURL GetFullLaunchURL() const; |
| 496 | 458 |
| 497 // Image cache related methods. These are only valid on the UI thread and | 459 // Image cache related methods. These are only valid on the UI thread and |
| 498 // not maintained by this class. See ImageLoadingTracker for usage. The | 460 // not maintained by this class. See ImageLoadingTracker for usage. The |
| 499 // |original_size| parameter should be the size of the image at |source| | 461 // |original_size| parameter should be the size of the image at |source| |
| 500 // before any scaling may have been done to produce the pixels in |image|. | 462 // before any scaling may have been done to produce the pixels in |image|. |
| 501 void SetCachedImage(const ExtensionResource& source, | 463 void SetCachedImage(const ExtensionResource& source, |
| 502 const SkBitmap& image, | 464 const SkBitmap& image, |
| 503 const gfx::Size& original_size) const; | 465 const gfx::Size& original_size) const; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 } | 598 } |
| 637 const PermissionSet* required_permission_set() const { | 599 const PermissionSet* required_permission_set() const { |
| 638 return required_permission_set_.get(); | 600 return required_permission_set_.get(); |
| 639 } | 601 } |
| 640 // Appends |new_warning[s]| to install_warnings_. | 602 // Appends |new_warning[s]| to install_warnings_. |
| 641 void AddInstallWarning(const InstallWarning& new_warning); | 603 void AddInstallWarning(const InstallWarning& new_warning); |
| 642 void AddInstallWarnings(const InstallWarningVector& new_warnings); | 604 void AddInstallWarnings(const InstallWarningVector& new_warnings); |
| 643 const InstallWarningVector& install_warnings() const { | 605 const InstallWarningVector& install_warnings() const { |
| 644 return install_warnings_; | 606 return install_warnings_; |
| 645 } | 607 } |
| 646 const ExtensionIconSet& icons() const { return icons_; } | |
| 647 const extensions::Manifest* manifest() const { | 608 const extensions::Manifest* manifest() const { |
| 648 return manifest_.get(); | 609 return manifest_.get(); |
| 649 } | 610 } |
| 650 const std::string default_locale() const { return default_locale_; } | 611 const std::string default_locale() const { return default_locale_; } |
| 651 bool incognito_split_mode() const { return incognito_split_mode_; } | 612 bool incognito_split_mode() const { return incognito_split_mode_; } |
| 652 bool offline_enabled() const { return offline_enabled_; } | 613 bool offline_enabled() const { return offline_enabled_; } |
| 653 const OAuth2Info& oauth2_info() const { return oauth2_info_; } | 614 const OAuth2Info& oauth2_info() const { return oauth2_info_; } |
| 654 bool wants_file_access() const { return wants_file_access_; } | 615 bool wants_file_access() const { return wants_file_access_; } |
| 655 int creation_flags() const { return creation_flags_; } | 616 int creation_flags() const { return creation_flags_; } |
| 656 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; } | 617 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 const char* list_error, | 737 const char* list_error, |
| 777 const char* value_error, | 738 const char* value_error, |
| 778 string16* error); | 739 string16* error); |
| 779 bool LoadLaunchContainer(string16* error); | 740 bool LoadLaunchContainer(string16* error); |
| 780 bool LoadLaunchURL(string16* error); | 741 bool LoadLaunchURL(string16* error); |
| 781 | 742 |
| 782 bool LoadSharedFeatures(const APIPermissionSet& api_permissions, | 743 bool LoadSharedFeatures(const APIPermissionSet& api_permissions, |
| 783 string16* error); | 744 string16* error); |
| 784 bool LoadDescription(string16* error); | 745 bool LoadDescription(string16* error); |
| 785 bool LoadManifestVersion(string16* error); | 746 bool LoadManifestVersion(string16* error); |
| 786 bool LoadIcons(string16* error); | |
| 787 bool LoadPlugins(string16* error); | 747 bool LoadPlugins(string16* error); |
| 788 bool LoadNaClModules(string16* error); | 748 bool LoadNaClModules(string16* error); |
| 789 bool LoadSandboxedPages(string16* error); | 749 bool LoadSandboxedPages(string16* error); |
| 790 // Must be called after LoadPlugins(). | 750 // Must be called after LoadPlugins(). |
| 791 bool LoadRequirements(string16* error); | 751 bool LoadRequirements(string16* error); |
| 792 bool LoadDefaultLocale(string16* error); | 752 bool LoadDefaultLocale(string16* error); |
| 793 bool LoadOfflineEnabled(string16* error); | 753 bool LoadOfflineEnabled(string16* error); |
| 794 bool LoadBackgroundScripts(string16* error); | 754 bool LoadBackgroundScripts(string16* error); |
| 795 bool LoadBackgroundScripts(const std::string& key, string16* error); | 755 bool LoadBackgroundScripts(const std::string& key, string16* error); |
| 796 bool LoadBackgroundPage(const APIPermissionSet& api_permissions, | 756 bool LoadBackgroundPage(const APIPermissionSet& api_permissions, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 | 890 |
| 931 // The set of permissions the extension can request at runtime. | 891 // The set of permissions the extension can request at runtime. |
| 932 scoped_refptr<const PermissionSet> optional_permission_set_; | 892 scoped_refptr<const PermissionSet> optional_permission_set_; |
| 933 | 893 |
| 934 // The extension's required / default set of permissions. | 894 // The extension's required / default set of permissions. |
| 935 scoped_refptr<const PermissionSet> required_permission_set_; | 895 scoped_refptr<const PermissionSet> required_permission_set_; |
| 936 | 896 |
| 937 // Any warnings that occurred when trying to create/parse the extension. | 897 // Any warnings that occurred when trying to create/parse the extension. |
| 938 InstallWarningVector install_warnings_; | 898 InstallWarningVector install_warnings_; |
| 939 | 899 |
| 940 // The icons for the extension. | |
| 941 ExtensionIconSet icons_; | |
| 942 | |
| 943 // The base extension url for the extension. | 900 // The base extension url for the extension. |
| 944 GURL extension_url_; | 901 GURL extension_url_; |
| 945 | 902 |
| 946 // The extension's version. | 903 // The extension's version. |
| 947 scoped_ptr<Version> version_; | 904 scoped_ptr<Version> version_; |
| 948 | 905 |
| 949 // An optional longer description of the extension. | 906 // An optional longer description of the extension. |
| 950 std::string description_; | 907 std::string description_; |
| 951 | 908 |
| 952 // True if the extension was generated from a user script. (We show slightly | 909 // True if the extension was generated from a user script. (We show slightly |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 | 1094 |
| 1138 UpdatedExtensionPermissionsInfo( | 1095 UpdatedExtensionPermissionsInfo( |
| 1139 const Extension* extension, | 1096 const Extension* extension, |
| 1140 const PermissionSet* permissions, | 1097 const PermissionSet* permissions, |
| 1141 Reason reason); | 1098 Reason reason); |
| 1142 }; | 1099 }; |
| 1143 | 1100 |
| 1144 } // namespace extensions | 1101 } // namespace extensions |
| 1145 | 1102 |
| 1146 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 1103 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
| OLD | NEW |