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

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

Issue 7259019: Move base/values.h into the base namespace. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months 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 "chrome/common/extensions/extension_constants.h" 19 #include "chrome/common/extensions/extension_constants.h"
20 #include "chrome/common/extensions/extension_icon_set.h" 20 #include "chrome/common/extensions/extension_icon_set.h"
21 #include "chrome/common/extensions/extension_permission_set.h" 21 #include "chrome/common/extensions/extension_permission_set.h"
22 #include "chrome/common/extensions/user_script.h" 22 #include "chrome/common/extensions/user_script.h"
23 #include "chrome/common/extensions/url_pattern.h" 23 #include "chrome/common/extensions/url_pattern.h"
24 #include "chrome/common/extensions/url_pattern_set.h" 24 #include "chrome/common/extensions/url_pattern_set.h"
25 #include "googleurl/src/gurl.h" 25 #include "googleurl/src/gurl.h"
26 #include "ui/gfx/size.h" 26 #include "ui/gfx/size.h"
27 27
28 class DictionaryValue;
29 class ExtensionAction; 28 class ExtensionAction;
30 class ExtensionResource; 29 class ExtensionResource;
31 class ExtensionSidebarDefaults; 30 class ExtensionSidebarDefaults;
32 class FileBrowserHandler; 31 class FileBrowserHandler;
33 class ListValue;
34 class SkBitmap; 32 class SkBitmap;
35 class Version; 33 class Version;
36 34
35 namespace base {
36 class DictionaryValue;
37 class ListValue;
38 }
39
37 // Represents a Chrome extension. 40 // Represents a Chrome extension.
38 class Extension : public base::RefCountedThreadSafe<Extension> { 41 class Extension : public base::RefCountedThreadSafe<Extension> {
39 public: 42 public:
40 typedef std::map<const std::string, GURL> URLOverrideMap; 43 typedef std::map<const std::string, GURL> URLOverrideMap;
41 typedef std::vector<std::string> ScriptingWhitelist; 44 typedef std::vector<std::string> ScriptingWhitelist;
42 typedef std::vector<linked_ptr<FileBrowserHandler> > FileBrowserHandlerList; 45 typedef std::vector<linked_ptr<FileBrowserHandler> > FileBrowserHandlerList;
43 46
44 // What an extension was loaded from. 47 // What an extension was loaded from.
45 // NOTE: These values are stored as integers in the preferences and used 48 // NOTE: These values are stored as integers in the preferences and used
46 // in histograms so don't remove or reorder existing items. Just append 49 // in histograms so don't remove or reorder existing items. Just append
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 STRICT_ERROR_CHECKS = 1 << 1, 172 STRICT_ERROR_CHECKS = 1 << 1,
170 173
171 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension 174 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension
172 // to have file access. If it's not present, then permissions and content 175 // to have file access. If it's not present, then permissions and content
173 // scripts that match file:/// URLs will be filtered out. 176 // scripts that match file:/// URLs will be filtered out.
174 ALLOW_FILE_ACCESS = 1 << 2, 177 ALLOW_FILE_ACCESS = 1 << 2,
175 }; 178 };
176 179
177 static scoped_refptr<Extension> Create(const FilePath& path, 180 static scoped_refptr<Extension> Create(const FilePath& path,
178 Location location, 181 Location location,
179 const DictionaryValue& value, 182 const base::DictionaryValue& value,
180 int flags, 183 int flags,
181 std::string* error); 184 std::string* error);
182 185
183 // In a few special circumstances, we want to create an Extension and give it 186 // In a few special circumstances, we want to create an Extension and give it
184 // an explicit id. Most consumers should just use the plain Create() method. 187 // an explicit id. Most consumers should just use the plain Create() method.
185 static scoped_refptr<Extension> CreateWithId(const FilePath& path, 188 static scoped_refptr<Extension> CreateWithId(
186 Location location, 189 const FilePath& path,
187 const DictionaryValue& value, 190 Location location,
188 int flags, 191 const base::DictionaryValue& value,
189 const std::string& explicit_id, 192 int flags,
190 std::string* error); 193 const std::string& explicit_id,
194 std::string* error);
191 195
192 // Return the update url used by gallery/webstore extensions. 196 // Return the update url used by gallery/webstore extensions.
193 static GURL GalleryUpdateUrl(bool secure); 197 static GURL GalleryUpdateUrl(bool secure);
194 198
195 // Given two install sources, return the one which should take priority 199 // Given two install sources, return the one which should take priority
196 // over the other. If an extension is installed from two sources A and B, 200 // over the other. If an extension is installed from two sources A and B,
197 // its install source should be set to GetHigherPriorityLocation(A, B). 201 // its install source should be set to GetHigherPriorityLocation(A, B).
198 static Location GetHigherPriorityLocation(Location loc1, Location loc2); 202 static Location GetHigherPriorityLocation(Location loc1, Location loc2);
199 203
200 // Returns the full list of permission messages that this extension 204 // Returns the full list of permission messages that this extension
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 } 484 }
481 const GURL& background_url() const { return background_url_; } 485 const GURL& background_url() const { return background_url_; }
482 const GURL& options_url() const { return options_url_; } 486 const GURL& options_url() const { return options_url_; }
483 const GURL& devtools_url() const { return devtools_url_; } 487 const GURL& devtools_url() const { return devtools_url_; }
484 const std::vector<GURL>& toolstrips() const { return toolstrips_; } 488 const std::vector<GURL>& toolstrips() const { return toolstrips_; }
485 const ExtensionPermissionSet* permission_set() const { 489 const ExtensionPermissionSet* permission_set() const {
486 return permission_set_.get(); 490 return permission_set_.get();
487 } 491 }
488 const GURL& update_url() const { return update_url_; } 492 const GURL& update_url() const { return update_url_; }
489 const ExtensionIconSet& icons() const { return icons_; } 493 const ExtensionIconSet& icons() const { return icons_; }
490 const DictionaryValue* manifest_value() const { 494 const base::DictionaryValue* manifest_value() const {
491 return manifest_value_.get(); 495 return manifest_value_.get();
492 } 496 }
493 const std::string default_locale() const { return default_locale_; } 497 const std::string default_locale() const { return default_locale_; }
494 const URLOverrideMap& GetChromeURLOverrides() const { 498 const URLOverrideMap& GetChromeURLOverrides() const {
495 return chrome_url_overrides_; 499 return chrome_url_overrides_;
496 } 500 }
497 const std::string omnibox_keyword() const { return omnibox_keyword_; } 501 const std::string omnibox_keyword() const { return omnibox_keyword_; }
498 bool incognito_split_mode() const { return incognito_split_mode_; } 502 bool incognito_split_mode() const { return incognito_split_mode_; }
499 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; } 503 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; }
500 504
(...skipping 12 matching lines...) Expand all
513 const std::string& launch_local_path() const { return launch_local_path_; } 517 const std::string& launch_local_path() const { return launch_local_path_; }
514 const std::string& launch_web_url() const { return launch_web_url_; } 518 const std::string& launch_web_url() const { return launch_web_url_; }
515 extension_misc::LaunchContainer launch_container() const { 519 extension_misc::LaunchContainer launch_container() const {
516 return launch_container_; 520 return launch_container_;
517 } 521 }
518 int launch_width() const { return launch_width_; } 522 int launch_width() const { return launch_width_; }
519 int launch_height() const { return launch_height_; } 523 int launch_height() const { return launch_height_; }
520 524
521 // Theme-related. 525 // Theme-related.
522 bool is_theme() const { return is_theme_; } 526 bool is_theme() const { return is_theme_; }
523 DictionaryValue* GetThemeImages() const { return theme_images_.get(); } 527 base::DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
524 DictionaryValue* GetThemeColors() const {return theme_colors_.get(); } 528 base::DictionaryValue* GetThemeColors() const {return theme_colors_.get(); }
525 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } 529 base::DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
526 DictionaryValue* GetThemeDisplayProperties() const { 530 base::DictionaryValue* GetThemeDisplayProperties() const {
527 return theme_display_properties_.get(); 531 return theme_display_properties_.get();
528 } 532 }
529 533
530 private: 534 private:
531 friend class base::RefCountedThreadSafe<Extension>; 535 friend class base::RefCountedThreadSafe<Extension>;
532 536
533 // We keep a cache of images loaded from extension resources based on their 537 // We keep a cache of images loaded from extension resources based on their
534 // path and a string representation of a size that may have been used to 538 // path and a string representation of a size that may have been used to
535 // scale it (or the empty string if the image is at its original size). 539 // scale it (or the empty string if the image is at its original size).
536 typedef std::pair<FilePath, std::string> ImageCacheKey; 540 typedef std::pair<FilePath, std::string> ImageCacheKey;
(...skipping 19 matching lines...) Expand all
556 static std::vector<std::string> GetDistinctHosts( 560 static std::vector<std::string> GetDistinctHosts(
557 const URLPatternList& host_patterns, bool include_rcd); 561 const URLPatternList& host_patterns, bool include_rcd);
558 562
559 // Returns true if this extension id is from a trusted provider. 563 // Returns true if this extension id is from a trusted provider.
560 static bool IsTrustedId(const std::string& id); 564 static bool IsTrustedId(const std::string& id);
561 565
562 Extension(const FilePath& path, Location location); 566 Extension(const FilePath& path, Location location);
563 ~Extension(); 567 ~Extension();
564 568
565 // Initialize the extension from a parsed manifest. 569 // Initialize the extension from a parsed manifest.
566 bool InitFromValue(const DictionaryValue& value, int flags, 570 bool InitFromValue(const base::DictionaryValue& value, int flags,
567 std::string* error); 571 std::string* error);
568 572
569 // Helper function for implementing HasCachedImage/GetCachedImage. A return 573 // Helper function for implementing HasCachedImage/GetCachedImage. A return
570 // value of NULL means there is no matching image cached (we allow caching an 574 // value of NULL means there is no matching image cached (we allow caching an
571 // empty SkBitmap). 575 // empty SkBitmap).
572 SkBitmap* GetCachedImageImpl(const ExtensionResource& source, 576 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
573 const gfx::Size& max_size) const; 577 const gfx::Size& max_size) const;
574 578
575 // Helper method that loads a UserScript object from a 579 // Helper method that loads a UserScript object from a
576 // dictionary in the content_script list of the manifest. 580 // dictionary in the content_script list of the manifest.
577 bool LoadUserScriptHelper(const DictionaryValue* content_script, 581 bool LoadUserScriptHelper(const base::DictionaryValue* content_script,
578 int definition_index, 582 int definition_index,
579 int flags, 583 int flags,
580 std::string* error, 584 std::string* error,
581 UserScript* result); 585 UserScript* result);
582 586
583 // Helper method that loads either the include_globs or exclude_globs list 587 // Helper method that loads either the include_globs or exclude_globs list
584 // from an entry in the content_script lists of the manifest. 588 // from an entry in the content_script lists of the manifest.
585 bool LoadGlobsHelper(const DictionaryValue* content_script, 589 bool LoadGlobsHelper(const base::DictionaryValue* content_script,
586 int content_script_index, 590 int content_script_index,
587 const char* globs_property_name, 591 const char* globs_property_name,
588 std::string* error, 592 std::string* error,
589 void(UserScript::*add_method)(const std::string& glob), 593 void(UserScript::*add_method)(const std::string& glob),
590 UserScript *instance); 594 UserScript *instance);
591 595
592 // Helpers to load various chunks of the manifest. 596 // Helpers to load various chunks of the manifest.
593 bool LoadIsApp(const DictionaryValue* manifest, std::string* error); 597 bool LoadIsApp(const base::DictionaryValue* manifest, std::string* error);
594 bool LoadExtent(const DictionaryValue* manifest, 598 bool LoadExtent(const base::DictionaryValue* manifest,
595 const char* key, 599 const char* key,
596 URLPatternSet* extent, 600 URLPatternSet* extent,
597 const char* list_error, 601 const char* list_error,
598 const char* value_error, 602 const char* value_error,
599 URLPattern::ParseOption parse_strictness, 603 URLPattern::ParseOption parse_strictness,
600 std::string* error); 604 std::string* error);
601 bool LoadLaunchContainer(const DictionaryValue* manifest, std::string* error); 605 bool LoadLaunchContainer(const base::DictionaryValue* manifest,
602 bool LoadLaunchURL(const DictionaryValue* manifest, std::string* error); 606 std::string* error);
603 bool LoadAppIsolation(const DictionaryValue* manifest, std::string* error); 607 bool LoadLaunchURL(const base::DictionaryValue* manifest,
604 bool EnsureNotHybridApp(const DictionaryValue* manifest, std::string* error); 608 std::string* error);
609 bool LoadAppIsolation(const base::DictionaryValue* manifest,
610 std::string* error);
611 bool EnsureNotHybridApp(const base::DictionaryValue* manifest,
612 std::string* error);
605 613
606 // Helper method to load an ExtensionAction from the page_action or 614 // Helper method to load an ExtensionAction from the page_action or
607 // browser_action entries in the manifest. 615 // browser_action entries in the manifest.
608 ExtensionAction* LoadExtensionActionHelper( 616 ExtensionAction* LoadExtensionActionHelper(
609 const DictionaryValue* extension_action, std::string* error); 617 const base::DictionaryValue* extension_action, std::string* error);
610 618
611 // Helper method to load an FileBrowserHandlerList from the manifest. 619 // Helper method to load an FileBrowserHandlerList from the manifest.
612 FileBrowserHandlerList* LoadFileBrowserHandlers( 620 FileBrowserHandlerList* LoadFileBrowserHandlers(
613 const ListValue* extension_actions, std::string* error); 621 const base::ListValue* extension_actions, std::string* error);
614 // Helper method to load an FileBrowserHandler from manifest. 622 // Helper method to load an FileBrowserHandler from manifest.
615 FileBrowserHandler* LoadFileBrowserHandler( 623 FileBrowserHandler* LoadFileBrowserHandler(
616 const DictionaryValue* file_browser_handlers, std::string* error); 624 const base::DictionaryValue* file_browser_handlers, std::string* error);
617 625
618 // Helper method to load an ExtensionSidebarDefaults from the sidebar manifest 626 // Helper method to load an ExtensionSidebarDefaults from the sidebar manifest
619 // entry. 627 // entry.
620 ExtensionSidebarDefaults* LoadExtensionSidebarDefaults( 628 ExtensionSidebarDefaults* LoadExtensionSidebarDefaults(
621 const DictionaryValue* sidebar, std::string* error); 629 const base::DictionaryValue* sidebar, std::string* error);
622 630
623 // Returns true if the extension has more than one "UI surface". For example, 631 // Returns true if the extension has more than one "UI surface". For example,
624 // an extension that has a browser action and a page action. 632 // an extension that has a browser action and a page action.
625 bool HasMultipleUISurfaces() const; 633 bool HasMultipleUISurfaces() const;
626 634
627 // Figures out if a source contains keys not associated with themes - we 635 // Figures out if a source contains keys not associated with themes - we
628 // don't want to allow scripts and such to be bundled with themes. 636 // don't want to allow scripts and such to be bundled with themes.
629 bool ContainsNonThemeKeys(const DictionaryValue& source) const; 637 bool ContainsNonThemeKeys(const base::DictionaryValue& source) const;
630 638
631 // Only allow the experimental API permission if the command line 639 // Only allow the experimental API permission if the command line
632 // flag is present. 640 // flag is present.
633 bool IsDisallowedExperimentalPermission( 641 bool IsDisallowedExperimentalPermission(
634 ExtensionAPIPermission::ID permission) const; 642 ExtensionAPIPermission::ID permission) const;
635 643
636 // Returns true if this is a component, or we are not attempting to access a 644 // Returns true if this is a component, or we are not attempting to access a
637 // component-private permission. 645 // component-private permission.
638 bool IsComponentOnlyPermission(const ExtensionAPIPermission* api) const; 646 bool IsComponentOnlyPermission(const ExtensionAPIPermission* api) const;
639 647
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 // Optional URL to a devtools extension page. 730 // Optional URL to a devtools extension page.
723 GURL devtools_url_; 731 GURL devtools_url_;
724 732
725 // Optional list of toolstrips and associated properties. 733 // Optional list of toolstrips and associated properties.
726 std::vector<GURL> toolstrips_; 734 std::vector<GURL> toolstrips_;
727 735
728 // The public key used to sign the contents of the crx package. 736 // The public key used to sign the contents of the crx package.
729 std::string public_key_; 737 std::string public_key_;
730 738
731 // A map of resource id's to relative file paths. 739 // A map of resource id's to relative file paths.
732 scoped_ptr<DictionaryValue> theme_images_; 740 scoped_ptr<base::DictionaryValue> theme_images_;
733 741
734 // A map of color names to colors. 742 // A map of color names to colors.
735 scoped_ptr<DictionaryValue> theme_colors_; 743 scoped_ptr<base::DictionaryValue> theme_colors_;
736 744
737 // A map of color names to colors. 745 // A map of color names to colors.
738 scoped_ptr<DictionaryValue> theme_tints_; 746 scoped_ptr<base::DictionaryValue> theme_tints_;
739 747
740 // A map of display properties. 748 // A map of display properties.
741 scoped_ptr<DictionaryValue> theme_display_properties_; 749 scoped_ptr<base::DictionaryValue> theme_display_properties_;
742 750
743 // Whether the extension is a theme. 751 // Whether the extension is a theme.
744 bool is_theme_; 752 bool is_theme_;
745 753
746 // The homepage for this extension. Useful if it is not hosted by Google and 754 // The homepage for this extension. Useful if it is not hosted by Google and
747 // therefore does not have a Gallery URL. 755 // therefore does not have a Gallery URL.
748 GURL homepage_url_; 756 GURL homepage_url_;
749 757
750 // URL for fetching an update manifest 758 // URL for fetching an update manifest
751 GURL update_url_; 759 GURL update_url_;
752 760
753 // A copy of the manifest that this extension was created from. 761 // A copy of the manifest that this extension was created from.
754 scoped_ptr<DictionaryValue> manifest_value_; 762 scoped_ptr<base::DictionaryValue> manifest_value_;
755 763
756 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs 764 // A map of chrome:// hostnames (newtab, downloads, etc.) to Extension URLs
757 // which override the handling of those URLs. (see ExtensionOverrideUI). 765 // which override the handling of those URLs. (see ExtensionOverrideUI).
758 URLOverrideMap chrome_url_overrides_; 766 URLOverrideMap chrome_url_overrides_;
759 767
760 // Whether this extension uses app features. 768 // Whether this extension uses app features.
761 bool is_app_; 769 bool is_app_;
762 770
763 // Whether this extension requests isolated storage. 771 // Whether this extension requests isolated storage.
764 bool is_storage_isolated_; 772 bool is_storage_isolated_;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps); 812 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps);
805 813
806 DISALLOW_COPY_AND_ASSIGN(Extension); 814 DISALLOW_COPY_AND_ASSIGN(Extension);
807 }; 815 };
808 816
809 typedef std::vector< scoped_refptr<const Extension> > ExtensionList; 817 typedef std::vector< scoped_refptr<const Extension> > ExtensionList;
810 typedef std::set<std::string> ExtensionIdSet; 818 typedef std::set<std::string> ExtensionIdSet;
811 819
812 // Handy struct to pass core extension info around. 820 // Handy struct to pass core extension info around.
813 struct ExtensionInfo { 821 struct ExtensionInfo {
814 ExtensionInfo(const DictionaryValue* manifest, 822 ExtensionInfo(const base::DictionaryValue* manifest,
815 const std::string& id, 823 const std::string& id,
816 const FilePath& path, 824 const FilePath& path,
817 Extension::Location location); 825 Extension::Location location);
818 ~ExtensionInfo(); 826 ~ExtensionInfo();
819 827
820 scoped_ptr<DictionaryValue> extension_manifest; 828 scoped_ptr<base::DictionaryValue> extension_manifest;
821 std::string extension_id; 829 std::string extension_id;
822 FilePath extension_path; 830 FilePath extension_path;
823 Extension::Location extension_location; 831 Extension::Location extension_location;
824 832
825 private: 833 private:
826 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo); 834 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
827 }; 835 };
828 836
829 // Struct used for the details of the EXTENSION_UNINSTALLED 837 // Struct used for the details of the EXTENSION_UNINSTALLED
830 // notification. 838 // notification.
(...skipping 23 matching lines...) Expand all
854 // Was the extension already disabled? 862 // Was the extension already disabled?
855 bool already_disabled; 863 bool already_disabled;
856 864
857 // The extension being unloaded - this should always be non-NULL. 865 // The extension being unloaded - this should always be non-NULL.
858 const Extension* extension; 866 const Extension* extension;
859 867
860 UnloadedExtensionInfo(const Extension* extension, Reason reason); 868 UnloadedExtensionInfo(const Extension* extension, Reason reason);
861 }; 869 };
862 870
863 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ 871 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_
OLDNEW
« no previous file with comments | « chrome/browser/web_resource/web_resource_service.h ('k') | chrome/common/extensions/extension_l10n_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698