Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/common/extensions/extension.h

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

Powered by Google App Engine
This is Rietveld 408576698