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

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

Issue 9424009: Cleaning up Extension::InitFromValue() (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Final update with requested changes, latest versions of extension.* Created 8 years, 9 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
« no previous file with comments | « no previous file | chrome/common/extensions/extension.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <utility>
12 #include <vector> 13 #include <vector>
13 #include <algorithm> 14 #include <algorithm>
14 15
15 #include "base/file_path.h" 16 #include "base/file_path.h"
16 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
17 #include "base/hash_tables.h" 18 #include "base/hash_tables.h"
18 #include "base/memory/linked_ptr.h" 19 #include "base/memory/linked_ptr.h"
19 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
20 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
21 #include "base/synchronization/lock.h" 22 #include "base/synchronization/lock.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 225
225 static scoped_refptr<Extension> Create(const FilePath& path, 226 static scoped_refptr<Extension> Create(const FilePath& path,
226 Location location, 227 Location location,
227 const base::DictionaryValue& value, 228 const base::DictionaryValue& value,
228 int flags, 229 int flags,
229 std::string* error); 230 std::string* error);
230 231
231 // In a few special circumstances, we want to create an Extension and give it 232 // In a few special circumstances, we want to create an Extension and give it
232 // an explicit id. Most consumers should just use the other Create() method. 233 // an explicit id. Most consumers should just use the other Create() method.
233 static scoped_refptr<Extension> Create(const FilePath& path, 234 static scoped_refptr<Extension> Create(const FilePath& path,
234 Location location, 235 Location location,
235 const base::DictionaryValue& value, 236 const base::DictionaryValue& value,
236 int flags, 237 int flags,
237 const std::string& explicit_id, 238 const std::string& explicit_id,
238 std::string* error); 239 std::string* error);
239 240
240 // Given two install sources, return the one which should take priority 241 // Given two install sources, return the one which should take priority
241 // over the other. If an extension is installed from two sources A and B, 242 // over the other. If an extension is installed from two sources A and B,
242 // its install source should be set to GetHigherPriorityLocation(A, B). 243 // its install source should be set to GetHigherPriorityLocation(A, B).
243 static Location GetHigherPriorityLocation(Location loc1, Location loc2); 244 static Location GetHigherPriorityLocation(Location loc1, Location loc2);
244 245
245 // Max size (both dimensions) for browser and page actions. 246 // Max size (both dimensions) for browser and page actions.
246 static const int kPageActionIconMaxSize; 247 static const int kPageActionIconMaxSize;
247 static const int kBrowserActionIconMaxSize; 248 static const int kBrowserActionIconMaxSize;
248 249
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 // always generate the same output ID. 362 // always generate the same output ID.
362 static bool GenerateId(const std::string& input, 363 static bool GenerateId(const std::string& input,
363 std::string* output) WARN_UNUSED_RESULT; 364 std::string* output) WARN_UNUSED_RESULT;
364 365
365 // Expects base64 encoded |input| and formats into |output| including 366 // Expects base64 encoded |input| and formats into |output| including
366 // the appropriate header & footer. 367 // the appropriate header & footer.
367 static bool FormatPEMForFileOutput(const std::string& input, 368 static bool FormatPEMForFileOutput(const std::string& input,
368 std::string* output, 369 std::string* output,
369 bool is_public); 370 bool is_public);
370 371
371 // Given an extension, icon size and match type, read a valid icon if present 372 // Given an extension, icon size, and match type, read a valid icon if present
372 // and decode it into result. In the browser process, this will DCHECK if not 373 // and decode it into result. In the browser process, this will DCHECK if not
373 // called on the file thread. To easily load extension images on the UI 374 // called on the file thread. To easily load extension images on the UI
374 // thread, see ImageLoadingTracker. 375 // thread, see ImageLoadingTracker.
375 static void DecodeIcon(const Extension* extension, 376 static void DecodeIcon(const Extension* extension,
376 ExtensionIconSet::Icons icon_size, 377 ExtensionIconSet::Icons icon_size,
377 ExtensionIconSet::MatchType match_type, 378 ExtensionIconSet::MatchType match_type,
378 scoped_ptr<SkBitmap>* result); 379 scoped_ptr<SkBitmap>* result);
379 380
380 // Given an extension and icon size, read it if present and decode it into 381 // Given an extension and icon size, read it if present and decode it into
381 // result. In the browser process, this will DCHECK if not called on the 382 // result. In the browser process, this will DCHECK if not called on the
(...skipping 18 matching lines...) Expand all
400 // Returns the base extension url for a given |extension_id|. 401 // Returns the base extension url for a given |extension_id|.
401 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); 402 static GURL GetBaseURLFromExtensionId(const std::string& extension_id);
402 403
403 // Adds an extension to the scripting whitelist. Used for testing only. 404 // Adds an extension to the scripting whitelist. Used for testing only.
404 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); 405 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
405 static const ScriptingWhitelist* GetScriptingWhitelist(); 406 static const ScriptingWhitelist* GetScriptingWhitelist();
406 407
407 // Parses the host and api permissions from the specified permission |key| 408 // Parses the host and api permissions from the specified permission |key|
408 // from |manifest_|. 409 // from |manifest_|.
409 bool ParsePermissions(const char* key, 410 bool ParsePermissions(const char* key,
410 int flags,
411 string16* error, 411 string16* error,
412 ExtensionAPIPermissionSet* api_permissions, 412 ExtensionAPIPermissionSet* api_permissions,
413 URLPatternSet* host_permissions); 413 URLPatternSet* host_permissions);
414 414
415 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const; 415 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const;
416 bool HasAPIPermission(const std::string& function_name) const; 416 bool HasAPIPermission(const std::string& function_name) const;
417 417
418 const URLPatternSet& GetEffectiveHostPermissions() const; 418 const URLPatternSet& GetEffectiveHostPermissions() const;
419 419
420 // Returns true if the extension can silently increase its permission level. 420 // Returns true if the extension can silently increase its permission level.
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 ~Extension(); 683 ~Extension();
684 684
685 // Initialize the extension from a parsed manifest. 685 // Initialize the extension from a parsed manifest.
686 // TODO(aa): Rename to just Init()? There's no Value here anymore. 686 // TODO(aa): Rename to just Init()? There's no Value here anymore.
687 // TODO(aa): It is really weird the way this class essentially contains a copy 687 // TODO(aa): It is really weird the way this class essentially contains a copy
688 // of the underlying DictionaryValue in its members. We should decide to 688 // of the underlying DictionaryValue in its members. We should decide to
689 // either wrap the DictionaryValue and go with that only, or we should parse 689 // either wrap the DictionaryValue and go with that only, or we should parse
690 // into strong types and discard the value. But doing both is bad. 690 // into strong types and discard the value. But doing both is bad.
691 bool InitFromValue(int flags, string16* error); 691 bool InitFromValue(int flags, string16* error);
692 692
693 // Helpers to load various chunks of the manifest. 693 // The following are helpers for InitFromValue to load various features of the
694 bool LoadManifestVersion(string16* error); 694 // extension from the manifest.
695
696 bool CheckMinimumChromeVersion(string16* error);
697 bool LoadAppIsolation(string16* error);
698
699 bool LoadRequiredFeatures(string16* error);
700 bool LoadName(string16* error);
701 bool LoadVersion(string16* error);
702
703 bool LoadAppFeatures(string16* error);
695 bool LoadExtent(const char* key, 704 bool LoadExtent(const char* key,
696 URLPatternSet* extent, 705 URLPatternSet* extent,
697 const char* list_error, 706 const char* list_error,
698 const char* value_error, 707 const char* value_error,
699 string16* error); 708 string16* error);
700 bool LoadLaunchContainer(string16* error); 709 bool LoadLaunchContainer(string16* error);
701 bool LoadLaunchURL(string16* error); 710 bool LoadLaunchURL(string16* error);
702 bool LoadAppIsolation(string16* error);
703 711
704 // Parses a single action in the manifest. 712 bool LoadSharedFeatures(const ExtensionAPIPermissionSet& api_permissions,
705 bool LoadWebIntentAction(const std::string& action_name, 713 string16* error);
706 const base::DictionaryValue& intent_service, 714 bool LoadDescription(string16* error);
707 string16* error); 715 bool LoadManifestVersion(string16* error);
708 bool LoadWebIntentServices(string16* error); 716 bool LoadHomepageURL(string16* error);
717 bool LoadUpdateURL(string16* error);
718 bool LoadIcons(string16* error);
719 bool LoadCommands(string16* error);
720 bool LoadPlugins(string16* error);
721 bool LoadNaClModules(string16* error);
722 bool LoadWebAccessibleResources(string16* error);
723 bool CheckRequirements(string16* error);
724 bool LoadDefaultLocale(string16* error);
725 bool LoadOfflineEnabled(string16* error);
726 bool LoadOptionsPage(string16* error);
709 bool LoadBackgroundScripts(string16* error); 727 bool LoadBackgroundScripts(string16* error);
710 bool LoadBackgroundPage(const ExtensionAPIPermissionSet& api_permissions, 728 bool LoadBackgroundPage(const ExtensionAPIPermissionSet& api_permissions,
711 string16* error); 729 string16* error);
712 bool LoadBackgroundPersistent( 730 bool LoadBackgroundPersistent(
713 const ExtensionAPIPermissionSet& api_permissions, 731 const ExtensionAPIPermissionSet& api_permissions,
714 string16* error); 732 string16* error);
715 bool LoadBackgroundAllowJsAccess( 733 bool LoadBackgroundAllowJSAccess(
716 const ExtensionAPIPermissionSet& api_permissions, 734 const ExtensionAPIPermissionSet& api_permissions,
717 string16* error); 735 string16* error);
736 // Parses a single action in the manifest.
737 bool LoadWebIntentAction(const std::string& action_name,
738 const base::DictionaryValue& intent_service,
739 string16* error);
740 bool LoadWebIntentServices(string16* error);
741 bool LoadExtensionFeatures(const ExtensionAPIPermissionSet& api_permissions,
742 string16* error);
743 bool LoadDevToolsPage(string16* error);
744 bool LoadInputComponents(const ExtensionAPIPermissionSet& api_permissions,
745 string16* error);
746 bool LoadContentScripts(string16* error);
747 bool LoadPageAction(string16* error);
748 bool LoadBrowserAction(string16* error);
749 bool LoadFileBrowserHandlers(string16* error);
750 // Helper method to load a FileBrowserHandlerList from the manifest.
751 FileBrowserHandlerList* LoadFileBrowserHandlersHelper(
752 const base::ListValue* extension_actions, string16* error);
753 // Helper method to load an FileBrowserHandler from manifest.
754 FileBrowserHandler* LoadFileBrowserHandler(
755 const base::DictionaryValue* file_browser_handlers, string16* error);
756 bool LoadChromeURLOverrides(string16* error);
757 bool LoadOmnibox(string16* error);
758 bool LoadTextToSpeechVoices(string16* error);
759 bool LoadIncognitoMode(string16* error);
760 bool LoadContentSecurityPolicy(string16* error);
761
762 bool LoadThemeFeatures(string16* error);
763 bool LoadThemeImages(const base::DictionaryValue* theme_value,
764 string16* error);
765 bool LoadThemeColors(const base::DictionaryValue* theme_value,
766 string16* error);
767 bool LoadThemeTints(const base::DictionaryValue* theme_value,
768 string16* error);
769 bool LoadThemeDisplayProperties(const base::DictionaryValue* theme_value,
770 string16* error);
771
772 // Helper function for implementing HasCachedImage/GetCachedImage. A return
773 // value of NULL means there is no matching image cached (we allow caching an
774 // empty SkBitmap).
775 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
776 const gfx::Size& max_size) const;
718 777
719 // Helper method that loads a UserScript object from a 778 // Helper method that loads a UserScript object from a
720 // dictionary in the content_script list of the manifest. 779 // dictionary in the content_script list of the manifest.
721 bool LoadUserScriptHelper(const base::DictionaryValue* content_script, 780 bool LoadUserScriptHelper(const base::DictionaryValue* content_script,
722 int definition_index, 781 int definition_index,
723 int flags,
724 string16* error, 782 string16* error,
725 UserScript* result); 783 UserScript* result);
726 784
727 // Helper method that loads either the include_globs or exclude_globs list 785 // Helper method that loads either the include_globs or exclude_globs list
728 // from an entry in the content_script lists of the manifest. 786 // from an entry in the content_script lists of the manifest.
729 bool LoadGlobsHelper(const base::DictionaryValue* content_script, 787 bool LoadGlobsHelper(const base::DictionaryValue* content_script,
730 int content_script_index, 788 int content_script_index,
731 const char* globs_property_name, 789 const char* globs_property_name,
732 string16* error, 790 string16* error,
733 void(UserScript::*add_method)(const std::string& glob), 791 void(UserScript::*add_method)(const std::string& glob),
734 UserScript *instance); 792 UserScript *instance);
735 793
736 // Helper method to load an ExtensionAction from the page_action or 794 // Helper method to load an ExtensionAction from the page_action or
737 // browser_action entries in the manifest. 795 // browser_action entries in the manifest.
738 ExtensionAction* LoadExtensionActionHelper( 796 ExtensionAction* LoadExtensionActionHelper(
739 const base::DictionaryValue* extension_action, string16* error); 797 const base::DictionaryValue* extension_action, string16* error);
740 798
741 // Helper method to load an FileBrowserHandlerList from the manifest.
742 FileBrowserHandlerList* LoadFileBrowserHandlers(
743 const base::ListValue* extension_actions, string16* error);
744 // Helper method to load an FileBrowserHandler from manifest.
745 FileBrowserHandler* LoadFileBrowserHandler(
746 const base::DictionaryValue* file_browser_handlers, string16* error);
747
748 // Returns true if the extension has more than one "UI surface". For example, 799 // Returns true if the extension has more than one "UI surface". For example,
749 // an extension that has a browser action and a page action. 800 // an extension that has a browser action and a page action.
750 bool HasMultipleUISurfaces() const; 801 bool HasMultipleUISurfaces() const;
751 802
752 // Updates the launch URL and extents for the extension using the given 803 // Updates the launch URL and extents for the extension using the given
753 // |override_url|. 804 // |override_url|.
754 void OverrideLaunchUrl(const GURL& override_url); 805 void OverrideLaunchUrl(const GURL& override_url);
755 806
756 // Returns true if this extension can specify |api|. 807 // Returns true if this extension can specify |api|.
757 bool CanSpecifyAPIPermission(const ExtensionAPIPermission* api, 808 bool CanSpecifyAPIPermission(const ExtensionAPIPermission* api,
758 string16* error) const; 809 string16* error) const;
759 bool CanSpecifyExperimentalPermission() const; 810 bool CanSpecifyExperimentalPermission() const;
760 811
761 // Checks whether the host |pattern| is allowed for this extension, given API 812 // Checks whether the host |pattern| is allowed for this extension, given API
762 // permissions |permissions|. 813 // permissions |permissions|.
763 bool CanSpecifyHostPermission(const URLPattern& pattern, 814 bool CanSpecifyHostPermission(const URLPattern& pattern,
764 const ExtensionAPIPermissionSet& permissions) const; 815 const ExtensionAPIPermissionSet& permissions) const;
765 816
766 // Helper function for implementing HasCachedImage/GetCachedImage. A return
767 // value of NULL means there is no matching image cached (we allow caching an
768 // empty SkBitmap).
769 SkBitmap* GetCachedImageImpl(const ExtensionResource& source,
770 const gfx::Size& max_size) const;
771
772 // Cached images for this extension. This should only be touched on the UI 817 // Cached images for this extension. This should only be touched on the UI
773 // thread. 818 // thread.
774 mutable ImageCache image_cache_; 819 mutable ImageCache image_cache_;
775 820
776 // The extension's human-readable name. Name is used for display purpose. It 821 // The extension's human-readable name. Name is used for display purpose. It
777 // might be wrapped with unicode bidi control characters so that it is 822 // might be wrapped with unicode bidi control characters so that it is
778 // displayed correctly in RTL context. 823 // displayed correctly in RTL context.
779 // NOTE: Name is UTF-8 and may contain non-ascii characters. 824 // NOTE: Name is UTF-8 and may contain non-ascii characters.
780 std::string name_; 825 std::string name_;
781 826
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 // A map of display properties. 940 // A map of display properties.
896 scoped_ptr<base::DictionaryValue> theme_display_properties_; 941 scoped_ptr<base::DictionaryValue> theme_display_properties_;
897 942
898 // The homepage for this extension. Useful if it is not hosted by Google and 943 // The homepage for this extension. Useful if it is not hosted by Google and
899 // therefore does not have a Gallery URL. 944 // therefore does not have a Gallery URL.
900 GURL homepage_url_; 945 GURL homepage_url_;
901 946
902 // URL for fetching an update manifest 947 // URL for fetching an update manifest
903 GURL update_url_; 948 GURL update_url_;
904 949
905 // The manifest that this extension was created from. 950 // The manifest from which this extension was created.
906 // 951 //
907 // NOTE: This is an owned pointer, but can't use scoped_ptr because that would 952 // NOTE: This is an owned pointer, but can't use scoped_ptr because that would
908 // require manifest.h, which would in turn create a circulate dependency 953 // require manifest.h, which would in turn create a circulate dependency
909 // between extension.h and manifest.h. 954 // between extension.h and manifest.h.
910 // 955 //
911 // TODO(aa): Pull Extension::Type and Extension::Location out into their own 956 // TODO(aa): Pull Extension::Type and Extension::Location out into their own
912 // files so that manifest.h can rely on them and not get all of extension.h 957 // files so that manifest.h can rely on them and not get all of extension.h
913 // too, and then change this back to a scoped_ptr. 958 // too, and then change this back to a scoped_ptr.
914 extensions::Manifest* manifest_; 959 extensions::Manifest* manifest_;
915 960
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 // only contain the removed permissions. 1070 // only contain the removed permissions.
1026 const ExtensionPermissionSet* permissions; 1071 const ExtensionPermissionSet* permissions;
1027 1072
1028 UpdatedExtensionPermissionsInfo( 1073 UpdatedExtensionPermissionsInfo(
1029 const Extension* extension, 1074 const Extension* extension,
1030 const ExtensionPermissionSet* permissions, 1075 const ExtensionPermissionSet* permissions,
1031 Reason reason); 1076 Reason reason);
1032 }; 1077 };
1033 1078
1034 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ 1079 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698