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