Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / extensions / common / extension.h
index c7b8458..4c76478 100644 (file)
 #include "extensions/common/extension_resource.h"
 #include "extensions/common/install_warning.h"
 #include "extensions/common/manifest.h"
-#include "extensions/common/permissions/api_permission.h"
-#include "extensions/common/url_pattern.h"
 #include "extensions/common/url_pattern_set.h"
 #include "ui/base/accelerators/accelerator.h"
 #include "ui/gfx/size.h"
 #include "url/gurl.h"
 
-class ExtensionAction;
-class SkBitmap;
+#if !defined(ENABLE_EXTENSIONS)
+#error "Extensions must be enabled"
+#endif
 
 namespace base {
 class DictionaryValue;
 class Version;
 }
 
-namespace gfx {
-class ImageSkia;
-}
-
 namespace extensions {
-class PermissionsData;
-class APIPermissionSet;
-class ManifestPermissionSet;
 class PermissionSet;
+class PermissionsData;
+class PermissionsParser;
 
 // Uniquely identifies an Extension, using 32 characters from the alphabet
 // 'a'-'p'.  An empty string represents "no extension".
@@ -72,9 +66,9 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
     // An external extension that the user uninstalled. We should not reinstall
     // such extensions on startup.
     EXTERNAL_EXTENSION_UNINSTALLED,
-    // Special state for component extensions, since they are always loaded by
-    // the component loader, and should never be auto-installed on startup.
-    ENABLED_COMPONENT,
+    // DEPRECATED: Special state for component extensions.
+    // Maintained as a placeholder since states may be stored to disk.
+    ENABLED_COMPONENT_DEPRECATED,
     NUM_STATES
   };
 
@@ -87,6 +81,10 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
     DEPRECATED_DISABLE_LAST,  // Not used.
   };
 
+  // Reasons an extension may be disabled. These are used in histograms, so do
+  // not remove/reorder entries - only add at the end just before
+  // DISABLE_REASON_LAST (and update the shift value for it). Also remember to
+  // update the enum listing in tools/metrics/histograms.xml.
   enum DisableReason {
     DISABLE_NONE = 0,
     DISABLE_USER_ACTION = 1 << 0,
@@ -95,19 +93,16 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
     DISABLE_UNSUPPORTED_REQUIREMENT = 1 << 3,
     DISABLE_SIDELOAD_WIPEOUT = 1 << 4,
     DISABLE_UNKNOWN_FROM_SYNC = 1 << 5,
-    DISABLE_PERMISSIONS_CONSENT = 1 << 6,  // Unused - abandoned experiment.
-    DISABLE_KNOWN_DISABLED = 1 << 7,
+    // DISABLE_PERMISSIONS_CONSENT = 1 << 6,  // Deprecated.
+    // DISABLE_KNOWN_DISABLED = 1 << 7,  // Deprecated.
     DISABLE_NOT_VERIFIED = 1 << 8,  // Disabled because we could not verify
                                     // the install.
-    DISABLE_GREYLIST = 1 << 9
-  };
-
-  enum InstallType {
-    INSTALL_ERROR,
-    DOWNGRADE,
-    REINSTALL,
-    UPGRADE,
-    NEW_INSTALL
+    DISABLE_GREYLIST = 1 << 9,
+    DISABLE_CORRUPTED = 1 << 10,
+    DISABLE_REMOTE_INSTALL = 1 << 11,
+    DISABLE_INACTIVE_EPHEMERAL_APP = 1 << 12,  // Cached ephemeral apps are
+                                               // disabled to prevent activity.
+    DISABLE_REASON_LAST = 1 << 13,  // This should always be the last value
   };
 
   // A base class for parsed manifest data that APIs want to store on
@@ -117,6 +112,8 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
     virtual ~ManifestData() {}
   };
 
+  // Do not change the order of entries or remove entries in this list
+  // as this is used in UMA_HISTOGRAM_ENUMERATIONs about extensions.
   enum InitFromValueFlags {
     NO_FLAGS = 0,
 
@@ -161,16 +158,30 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
     // Unused - was part of an abandoned experiment.
     REQUIRE_PERMISSIONS_CONSENT = 1 << 8,
 
-    // |IS_EPHEMERAL| identifies ephemeral apps (experimental), which are not
-    // permanently installed.
+    // Unused - this flag has been moved to ExtensionPrefs.
     IS_EPHEMERAL = 1 << 9,
 
     // |WAS_INSTALLED_BY_OEM| installed by an OEM (e.g on Chrome OS) and should
     // be placed in a special OEM folder in the App Launcher. Note: OEM apps are
     // also installed by Default (i.e. WAS_INSTALLED_BY_DEFAULT is also true).
     WAS_INSTALLED_BY_OEM = 1 << 10,
+
+    // |WAS_INSTALLED_BY_CUSTODIAN| means this extension was installed by the
+    // custodian of a supervised user.
+    WAS_INSTALLED_BY_CUSTODIAN = 1 << 11,
+
+    // |MAY_BE_UNTRUSTED| indicates that this extension came from a potentially
+    // unsafe source (e.g., sideloaded from a local CRX file via the Windows
+    // registry). Such extensions may be subjected to additional constraints
+    // before they are fully installed and enabled.
+    MAY_BE_UNTRUSTED = 1 << 12,
+
+    // When adding new flags, make sure to update kInitFromValueFlagBits.
   };
 
+  // This is the highest bit index of the flags defined above.
+  static const int kInitFromValueFlagBits;
+
   static scoped_refptr<Extension> Create(const base::FilePath& path,
                                          Manifest::Location location,
                                          const base::DictionaryValue& value,
@@ -195,9 +206,6 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
   // The mimetype used for extensions.
   static const char kMimeType[];
 
-  // Checks to see if the extension has a valid ID.
-  static bool IdIsValid(const std::string& id);
-
   // See Type definition in Manifest.
   Manifest::Type GetType() const;
 
@@ -241,12 +249,6 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
   // Returns the base extension url for a given |extension_id|.
   static GURL GetBaseURLFromExtensionId(const ExtensionId& extension_id);
 
-  // DEPRECATED: These methods have been moved to PermissionsData.
-  // TODO(rdevlin.cronin): remove these once all calls have been updated.
-  bool HasAPIPermission(APIPermission::ID permission) const;
-  bool HasAPIPermission(const std::string& permission_name) const;
-  scoped_refptr<const PermissionSet> GetActivePermissions() const;
-
   // Whether context menu should be shown for page and browser actions.
   bool ShowConfigureContextMenus() const;
 
@@ -301,7 +303,11 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
   bool converted_from_user_script() const {
     return converted_from_user_script_;
   }
-  PermissionsData* permissions_data() { return permissions_data_.get(); }
+  PermissionsParser* permissions_parser() { return permissions_parser_.get(); }
+  const PermissionsParser* permissions_parser() const {
+    return permissions_parser_.get();
+  }
+
   const PermissionsData* permissions_data() const {
     return permissions_data_.get();
   }
@@ -331,22 +337,24 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
   bool was_installed_by_oem() const {
     return (creation_flags_ & WAS_INSTALLED_BY_OEM) != 0;
   }
-  bool is_ephemeral() const { return (creation_flags_ & IS_EPHEMERAL) != 0; }
+  bool was_installed_by_custodian() const {
+    return (creation_flags_ & WAS_INSTALLED_BY_CUSTODIAN) != 0;
+  }
 
-  // App-related.
+  // Type-related queries.
   bool is_app() const;
   bool is_platform_app() const;
   bool is_hosted_app() const;
   bool is_legacy_packaged_app() const;
   bool is_extension() const;
+  bool is_shared_module() const;
+  bool is_theme() const;
+
   bool can_be_incognito_enabled() const;
 
   void AddWebExtentPattern(const URLPattern& pattern);
   const URLPatternSet& web_extent() const { return extent_; }
 
-  // Theme-related.
-  bool is_theme() const;
-
  private:
   friend class base::RefCountedThreadSafe<Extension>;
 
@@ -421,6 +429,12 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
   // Defines the set of URLs in the extension's web content.
   URLPatternSet extent_;
 
+  // The parser for the manifest's permissions. This is NULL anytime not during
+  // initialization.
+  // TODO(rdevlin.cronin): This doesn't really belong here.
+  scoped_ptr<PermissionsParser> permissions_parser_;
+
+  // The active permissions for the extension.
   scoped_ptr<PermissionsData> permissions_data_;
 
   // Any warnings that occurred when trying to create/parse the extension.
@@ -501,22 +515,30 @@ struct InstalledExtensionInfo {
   // True if the extension is being updated; false if it is being installed.
   bool is_update;
 
+  // True if the extension was previously installed ephemerally and is now
+  // a regular installed extension.
+  bool from_ephemeral;
+
   // The name of the extension prior to this update. Will be empty if
   // |is_update| is false.
   std::string old_name;
 
   InstalledExtensionInfo(const Extension* extension,
                          bool is_update,
+                         bool from_ephemeral,
                          const std::string& old_name);
 };
 
 struct UnloadedExtensionInfo {
+  // TODO(DHNishi): Move this enum to ExtensionRegistryObserver.
   enum Reason {
-    REASON_DISABLE,    // Extension is being disabled.
-    REASON_UPDATE,     // Extension is being updated to a newer version.
-    REASON_UNINSTALL,  // Extension is being uninstalled.
-    REASON_TERMINATE,  // Extension has terminated.
-    REASON_BLACKLIST,  // Extension has been blacklisted.
+    REASON_UNDEFINED,         // Undefined state used to initialize variables.
+    REASON_DISABLE,           // Extension is being disabled.
+    REASON_UPDATE,            // Extension is being updated to a newer version.
+    REASON_UNINSTALL,         // Extension is being uninstalled.
+    REASON_TERMINATE,         // Extension has terminated.
+    REASON_BLACKLIST,         // Extension has been blacklisted.
+    REASON_PROFILE_SHUTDOWN,  // Profile is being shut down.
   };
 
   Reason reason;