| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/memory/linked_ptr.h" | 16 #include "base/memory/linked_ptr.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "chrome/common/extensions/extension_icon_set.h" | 21 #include "chrome/common/extensions/extension_icon_set.h" |
| 22 #include "chrome/common/extensions/extension_permission_set.h" | 22 #include "chrome/common/extensions/extension_permission_set.h" |
| 23 #include "chrome/common/extensions/manifest.h" | |
| 24 #include "chrome/common/extensions/user_script.h" | 23 #include "chrome/common/extensions/user_script.h" |
| 25 #include "chrome/common/extensions/url_pattern.h" | 24 #include "chrome/common/extensions/url_pattern.h" |
| 26 #include "chrome/common/extensions/url_pattern_set.h" | 25 #include "chrome/common/extensions/url_pattern_set.h" |
| 27 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 28 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
| 29 #include "webkit/glue/web_intent_service_data.h" | 28 #include "webkit/glue/web_intent_service_data.h" |
| 30 | 29 |
| 31 class ExtensionAction; | 30 class ExtensionAction; |
| 32 class ExtensionResource; | 31 class ExtensionResource; |
| 33 class ExtensionSidebarDefaults; | 32 class ExtensionSidebarDefaults; |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 367 |
| 369 // Returns the base extension url for a given |extension_id|. | 368 // Returns the base extension url for a given |extension_id|. |
| 370 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); | 369 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); |
| 371 | 370 |
| 372 // Adds an extension to the scripting whitelist. Used for testing only. | 371 // Adds an extension to the scripting whitelist. Used for testing only. |
| 373 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); | 372 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); |
| 374 static const ScriptingWhitelist* GetScriptingWhitelist(); | 373 static const ScriptingWhitelist* GetScriptingWhitelist(); |
| 375 | 374 |
| 376 // Parses the host and api permissions from the specified permission |key| | 375 // Parses the host and api permissions from the specified permission |key| |
| 377 // in the manifest |source|. | 376 // in the manifest |source|. |
| 378 bool ParsePermissions(const extensions::Manifest* source, | 377 bool ParsePermissions(const base::DictionaryValue* source, |
| 379 const char* key, | 378 const char* key, |
| 380 int flags, | 379 int flags, |
| 381 std::string* error, | 380 std::string* error, |
| 382 ExtensionAPIPermissionSet* api_permissions, | 381 ExtensionAPIPermissionSet* api_permissions, |
| 383 URLPatternSet* host_permissions); | 382 URLPatternSet* host_permissions); |
| 384 | 383 |
| 385 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const; | 384 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const; |
| 386 bool HasAPIPermission(const std::string& function_name) const; | 385 bool HasAPIPermission(const std::string& function_name) const; |
| 387 | 386 |
| 388 const URLPatternSet& GetEffectiveHostPermissions() const; | 387 const URLPatternSet& GetEffectiveHostPermissions() const; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 const GURL& options_url() const { return options_url_; } | 524 const GURL& options_url() const { return options_url_; } |
| 526 const GURL& devtools_url() const { return devtools_url_; } | 525 const GURL& devtools_url() const { return devtools_url_; } |
| 527 const ExtensionPermissionSet* optional_permission_set() const { | 526 const ExtensionPermissionSet* optional_permission_set() const { |
| 528 return optional_permission_set_.get(); | 527 return optional_permission_set_.get(); |
| 529 } | 528 } |
| 530 const ExtensionPermissionSet* required_permission_set() const { | 529 const ExtensionPermissionSet* required_permission_set() const { |
| 531 return required_permission_set_.get(); | 530 return required_permission_set_.get(); |
| 532 } | 531 } |
| 533 const GURL& update_url() const { return update_url_; } | 532 const GURL& update_url() const { return update_url_; } |
| 534 const ExtensionIconSet& icons() const { return icons_; } | 533 const ExtensionIconSet& icons() const { return icons_; } |
| 535 const extensions::Manifest* manifest() const { | 534 const base::DictionaryValue* manifest_value() const { |
| 536 return manifest_.get(); | 535 return manifest_value_.get(); |
| 537 } | 536 } |
| 538 const std::string default_locale() const { return default_locale_; } | 537 const std::string default_locale() const { return default_locale_; } |
| 539 const URLOverrideMap& GetChromeURLOverrides() const { | 538 const URLOverrideMap& GetChromeURLOverrides() const { |
| 540 return chrome_url_overrides_; | 539 return chrome_url_overrides_; |
| 541 } | 540 } |
| 542 const std::string omnibox_keyword() const { return omnibox_keyword_; } | 541 const std::string omnibox_keyword() const { return omnibox_keyword_; } |
| 543 bool incognito_split_mode() const { return incognito_split_mode_; } | 542 bool incognito_split_mode() const { return incognito_split_mode_; } |
| 544 bool offline_enabled() const { return offline_enabled_; } | 543 bool offline_enabled() const { return offline_enabled_; } |
| 545 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; } | 544 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; } |
| 546 const std::vector<webkit_glue::WebIntentServiceData>& | 545 const std::vector<webkit_glue::WebIntentServiceData>& |
| 547 intents_services() const { | 546 intents_services() const { |
| 548 return intents_services_; | 547 return intents_services_; |
| 549 } | 548 } |
| 550 | 549 |
| 551 bool wants_file_access() const { return wants_file_access_; } | 550 bool wants_file_access() const { return wants_file_access_; } |
| 552 int creation_flags() const { return creation_flags_; } | 551 int creation_flags() const { return creation_flags_; } |
| 553 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; } | 552 bool from_webstore() const { return (creation_flags_ & FROM_WEBSTORE) != 0; } |
| 554 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; } | 553 bool from_bookmark() const { return (creation_flags_ & FROM_BOOKMARK) != 0; } |
| 555 | 554 |
| 556 const std::string& content_security_policy() const { | 555 const std::string& content_security_policy() const { |
| 557 return content_security_policy_; | 556 return content_security_policy_; |
| 558 } | 557 } |
| 559 | 558 |
| 560 // App-related. | 559 // App-related. |
| 561 bool is_app() const { | 560 bool is_app() const { return is_app_; } |
| 562 return is_packaged_app() || is_hosted_app() || is_platform_app(); | 561 bool is_platform_app() const { return is_platform_app_; } |
| 562 bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); } |
| 563 bool is_packaged_app() const { |
| 564 return !is_platform_app() && is_app() && web_extent().is_empty(); |
| 563 } | 565 } |
| 564 bool is_platform_app() const { return manifest()->IsPlatformApp(); } | |
| 565 bool is_hosted_app() const { return manifest()->IsHostedApp(); } | |
| 566 bool is_packaged_app() const { return manifest()->IsPackagedApp(); } | |
| 567 bool is_storage_isolated() const { return is_app() && is_storage_isolated_; } | 566 bool is_storage_isolated() const { return is_app() && is_storage_isolated_; } |
| 568 const URLPatternSet& web_extent() const { return extent_; } | 567 const URLPatternSet& web_extent() const { return extent_; } |
| 569 const std::string& launch_local_path() const { return launch_local_path_; } | 568 const std::string& launch_local_path() const { return launch_local_path_; } |
| 570 const std::string& launch_web_url() const { return launch_web_url_; } | 569 const std::string& launch_web_url() const { return launch_web_url_; } |
| 571 extension_misc::LaunchContainer launch_container() const { | 570 extension_misc::LaunchContainer launch_container() const { |
| 572 return launch_container_; | 571 return launch_container_; |
| 573 } | 572 } |
| 574 int launch_width() const { return launch_width_; } | 573 int launch_width() const { return launch_width_; } |
| 575 int launch_height() const { return launch_height_; } | 574 int launch_height() const { return launch_height_; } |
| 576 | 575 |
| 577 // Theme-related. | 576 // Theme-related. |
| 578 bool is_theme() const { return manifest()->IsTheme(); } | 577 bool is_theme() const { return is_theme_; } |
| 579 base::DictionaryValue* GetThemeImages() const { return theme_images_.get(); } | 578 base::DictionaryValue* GetThemeImages() const { return theme_images_.get(); } |
| 580 base::DictionaryValue* GetThemeColors() const {return theme_colors_.get(); } | 579 base::DictionaryValue* GetThemeColors() const {return theme_colors_.get(); } |
| 581 base::DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } | 580 base::DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } |
| 582 base::DictionaryValue* GetThemeDisplayProperties() const { | 581 base::DictionaryValue* GetThemeDisplayProperties() const { |
| 583 return theme_display_properties_.get(); | 582 return theme_display_properties_.get(); |
| 584 } | 583 } |
| 585 | 584 |
| 586 private: | 585 private: |
| 587 friend class base::RefCountedThreadSafe<Extension>; | 586 friend class base::RefCountedThreadSafe<Extension>; |
| 588 | 587 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 610 // sure the drive letter is uppercase. | 609 // sure the drive letter is uppercase. |
| 611 static FilePath MaybeNormalizePath(const FilePath& path); | 610 static FilePath MaybeNormalizePath(const FilePath& path); |
| 612 | 611 |
| 613 // Returns true if this extension id is from a trusted provider. | 612 // Returns true if this extension id is from a trusted provider. |
| 614 static bool IsTrustedId(const std::string& id); | 613 static bool IsTrustedId(const std::string& id); |
| 615 | 614 |
| 616 Extension(const FilePath& path, Location location); | 615 Extension(const FilePath& path, Location location); |
| 617 ~Extension(); | 616 ~Extension(); |
| 618 | 617 |
| 619 // Initialize the extension from a parsed manifest. | 618 // Initialize the extension from a parsed manifest. |
| 620 // Takes ownership of the manifest |value|. | 619 bool InitFromValue(const base::DictionaryValue& value, int flags, |
| 621 bool InitFromValue(extensions::Manifest* value, int flags, | |
| 622 std::string* error); | 620 std::string* error); |
| 623 | 621 |
| 624 // Helper function for implementing HasCachedImage/GetCachedImage. A return | 622 // Helper function for implementing HasCachedImage/GetCachedImage. A return |
| 625 // value of NULL means there is no matching image cached (we allow caching an | 623 // value of NULL means there is no matching image cached (we allow caching an |
| 626 // empty SkBitmap). | 624 // empty SkBitmap). |
| 627 SkBitmap* GetCachedImageImpl(const ExtensionResource& source, | 625 SkBitmap* GetCachedImageImpl(const ExtensionResource& source, |
| 628 const gfx::Size& max_size) const; | 626 const gfx::Size& max_size) const; |
| 629 | 627 |
| 630 // Helper method that loads a UserScript object from a | 628 // Helper method that loads a UserScript object from a |
| 631 // dictionary in the content_script list of the manifest. | 629 // dictionary in the content_script list of the manifest. |
| 632 bool LoadUserScriptHelper(const base::DictionaryValue* content_script, | 630 bool LoadUserScriptHelper(const base::DictionaryValue* content_script, |
| 633 int definition_index, | 631 int definition_index, |
| 634 int flags, | 632 int flags, |
| 635 std::string* error, | 633 std::string* error, |
| 636 UserScript* result); | 634 UserScript* result); |
| 637 | 635 |
| 638 // Helper method that loads either the include_globs or exclude_globs list | 636 // Helper method that loads either the include_globs or exclude_globs list |
| 639 // from an entry in the content_script lists of the manifest. | 637 // from an entry in the content_script lists of the manifest. |
| 640 bool LoadGlobsHelper(const base::DictionaryValue* content_script, | 638 bool LoadGlobsHelper(const base::DictionaryValue* content_script, |
| 641 int content_script_index, | 639 int content_script_index, |
| 642 const char* globs_property_name, | 640 const char* globs_property_name, |
| 643 std::string* error, | 641 std::string* error, |
| 644 void(UserScript::*add_method)(const std::string& glob), | 642 void(UserScript::*add_method)(const std::string& glob), |
| 645 UserScript *instance); | 643 UserScript *instance); |
| 646 | 644 |
| 647 // Helpers to load various chunks of the manifest. | 645 // Helpers to load various chunks of the manifest. |
| 648 bool LoadExtent(const extensions::Manifest* manifest, | 646 bool LoadIsApp(const base::DictionaryValue* manifest, std::string* error); |
| 647 bool LoadExtent(const base::DictionaryValue* manifest, |
| 649 const char* key, | 648 const char* key, |
| 650 URLPatternSet* extent, | 649 URLPatternSet* extent, |
| 651 const char* list_error, | 650 const char* list_error, |
| 652 const char* value_error, | 651 const char* value_error, |
| 653 URLPattern::ParseOption parse_strictness, | 652 URLPattern::ParseOption parse_strictness, |
| 654 std::string* error); | 653 std::string* error); |
| 655 bool LoadLaunchContainer(const extensions::Manifest* manifest, | 654 bool LoadLaunchContainer(const base::DictionaryValue* manifest, |
| 656 std::string* error); | 655 std::string* error); |
| 657 bool LoadLaunchURL(const extensions::Manifest* manifest, | 656 bool LoadLaunchURL(const base::DictionaryValue* manifest, |
| 658 std::string* error); | 657 std::string* error); |
| 659 bool LoadAppIsolation(const extensions::Manifest* manifest, | 658 bool LoadAppIsolation(const base::DictionaryValue* manifest, |
| 660 std::string* error); | 659 std::string* error); |
| 661 bool LoadWebIntentServices(const extensions::Manifest* manifest, | 660 bool LoadWebIntentServices(const base::DictionaryValue& manifest, |
| 662 std::string* error); | 661 std::string* error); |
| 662 bool EnsureNotHybridApp(const base::DictionaryValue* manifest, |
| 663 std::string* error); |
| 663 | 664 |
| 664 // Helper method to load an ExtensionAction from the page_action or | 665 // Helper method to load an ExtensionAction from the page_action or |
| 665 // browser_action entries in the manifest. | 666 // browser_action entries in the manifest. |
| 666 ExtensionAction* LoadExtensionActionHelper( | 667 ExtensionAction* LoadExtensionActionHelper( |
| 667 const base::DictionaryValue* extension_action, std::string* error); | 668 const base::DictionaryValue* extension_action, std::string* error); |
| 668 | 669 |
| 669 // Helper method to load an FileBrowserHandlerList from the manifest. | 670 // Helper method to load an FileBrowserHandlerList from the manifest. |
| 670 FileBrowserHandlerList* LoadFileBrowserHandlers( | 671 FileBrowserHandlerList* LoadFileBrowserHandlers( |
| 671 const base::ListValue* extension_actions, std::string* error); | 672 const base::ListValue* extension_actions, std::string* error); |
| 672 // Helper method to load an FileBrowserHandler from manifest. | 673 // Helper method to load an FileBrowserHandler from manifest. |
| 673 FileBrowserHandler* LoadFileBrowserHandler( | 674 FileBrowserHandler* LoadFileBrowserHandler( |
| 674 const base::DictionaryValue* file_browser_handlers, std::string* error); | 675 const base::DictionaryValue* file_browser_handlers, std::string* error); |
| 675 | 676 |
| 676 // Helper method to load an ExtensionSidebarDefaults from the sidebar manifest | 677 // Helper method to load an ExtensionSidebarDefaults from the sidebar manifest |
| 677 // entry. | 678 // entry. |
| 678 ExtensionSidebarDefaults* LoadExtensionSidebarDefaults( | 679 ExtensionSidebarDefaults* LoadExtensionSidebarDefaults( |
| 679 const base::DictionaryValue* sidebar, std::string* error); | 680 const base::DictionaryValue* sidebar, std::string* error); |
| 680 | 681 |
| 681 // Returns true if the extension has more than one "UI surface". For example, | 682 // Returns true if the extension has more than one "UI surface". For example, |
| 682 // an extension that has a browser action and a page action. | 683 // an extension that has a browser action and a page action. |
| 683 bool HasMultipleUISurfaces() const; | 684 bool HasMultipleUISurfaces() const; |
| 684 | 685 |
| 686 // Figures out if a source contains keys not associated with themes - we |
| 687 // don't want to allow scripts and such to be bundled with themes. |
| 688 bool ContainsNonThemeKeys(const base::DictionaryValue& source) const; |
| 689 |
| 685 // Updates the launch URL and extents for the extension using the given | 690 // Updates the launch URL and extents for the extension using the given |
| 686 // |override_url|. | 691 // |override_url|. |
| 687 void OverrideLaunchUrl(const GURL& override_url); | 692 void OverrideLaunchUrl(const GURL& override_url); |
| 688 | 693 |
| 689 // Returns true if this extension can specify |api|. | 694 // Returns true if this extension can specify |api|. |
| 690 bool CanSpecifyAPIPermission(const ExtensionAPIPermission* api, | 695 bool CanSpecifyAPIPermission(const ExtensionAPIPermission* api, |
| 691 std::string* error) const; | 696 std::string* error) const; |
| 692 bool CanSpecifyComponentOnlyPermission() const; | 697 bool CanSpecifyComponentOnlyPermission() const; |
| 693 bool CanSpecifyExperimentalPermission() const; | 698 bool CanSpecifyExperimentalPermission() const; |
| 694 | 699 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 | 813 |
| 809 // A map of color names to colors. | 814 // A map of color names to colors. |
| 810 scoped_ptr<base::DictionaryValue> theme_colors_; | 815 scoped_ptr<base::DictionaryValue> theme_colors_; |
| 811 | 816 |
| 812 // A map of color names to colors. | 817 // A map of color names to colors. |
| 813 scoped_ptr<base::DictionaryValue> theme_tints_; | 818 scoped_ptr<base::DictionaryValue> theme_tints_; |
| 814 | 819 |
| 815 // A map of display properties. | 820 // A map of display properties. |
| 816 scoped_ptr<base::DictionaryValue> theme_display_properties_; | 821 scoped_ptr<base::DictionaryValue> theme_display_properties_; |
| 817 | 822 |
| 823 // Whether the extension is a theme. |
| 824 bool is_theme_; |
| 825 |
| 818 // The homepage for this extension. Useful if it is not hosted by Google and | 826 // The homepage for this extension. Useful if it is not hosted by Google and |
| 819 // therefore does not have a Gallery URL. | 827 // therefore does not have a Gallery URL. |
| 820 GURL homepage_url_; | 828 GURL homepage_url_; |
| 821 | 829 |
| 822 // URL for fetching an update manifest | 830 // URL for fetching an update manifest |
| 823 GURL update_url_; | 831 GURL update_url_; |
| 824 | 832 |
| 825 // The manifest that this extension was created from. | 833 // A copy of the manifest that this extension was created from. |
| 826 scoped_ptr<extensions::Manifest> manifest_; | 834 scoped_ptr<base::DictionaryValue> manifest_value_; |
| 827 | 835 |
| 828 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs | 836 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs |
| 829 // which override the handling of those URLs. (see ExtensionOverrideUI). | 837 // which override the handling of those URLs. (see ExtensionOverrideUI). |
| 830 URLOverrideMap chrome_url_overrides_; | 838 URLOverrideMap chrome_url_overrides_; |
| 831 | 839 |
| 840 // Whether this extension uses app features. |
| 841 bool is_app_; |
| 842 |
| 843 // Whether this app uses platform features. |
| 844 bool is_platform_app_; |
| 845 |
| 832 // Whether this extension requests isolated storage. | 846 // Whether this extension requests isolated storage. |
| 833 bool is_storage_isolated_; | 847 bool is_storage_isolated_; |
| 834 | 848 |
| 835 // The local path inside the extension to use with the launcher. | 849 // The local path inside the extension to use with the launcher. |
| 836 std::string launch_local_path_; | 850 std::string launch_local_path_; |
| 837 | 851 |
| 838 // A web url to use with the launcher. Note that this might be relative or | 852 // A web url to use with the launcher. Note that this might be relative or |
| 839 // absolute. If relative, it is relative to web_origin. | 853 // absolute. If relative, it is relative to web_origin. |
| 840 std::string launch_web_url_; | 854 std::string launch_web_url_; |
| 841 | 855 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 // only contain the removed permissions. | 946 // only contain the removed permissions. |
| 933 const ExtensionPermissionSet* permissions; | 947 const ExtensionPermissionSet* permissions; |
| 934 | 948 |
| 935 UpdatedExtensionPermissionsInfo( | 949 UpdatedExtensionPermissionsInfo( |
| 936 const Extension* extension, | 950 const Extension* extension, |
| 937 const ExtensionPermissionSet* permissions, | 951 const ExtensionPermissionSet* permissions, |
| 938 Reason reason); | 952 Reason reason); |
| 939 }; | 953 }; |
| 940 | 954 |
| 941 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 955 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
| OLD | NEW |