1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_UTIL_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_UTIL_H_
10 #include "base/memory/scoped_ptr.h"
14 class DictionaryValue
;
27 namespace extensions
{
35 // Returns true if |extension_id| can run in an incognito window.
36 bool IsIncognitoEnabled(const std::string
& extension_id
,
37 content::BrowserContext
* context
);
39 // Sets whether |extension_id| can run in an incognito window. Reloads the
40 // extension if it's enabled since this permission is applied at loading time
41 // only. Note that an ExtensionService must exist.
42 void SetIsIncognitoEnabled(const std::string
& extension_id
,
43 content::BrowserContext
* context
,
46 // Returns true if |extension| can see events and data from another sub-profile
47 // (incognito to original profile, or vice versa).
48 bool CanCrossIncognito(const extensions::Extension
* extension
,
49 content::BrowserContext
* context
);
51 // Returns true if |extension| can be loaded in incognito.
52 bool CanLoadInIncognito(const extensions::Extension
* extension
,
53 content::BrowserContext
* context
);
55 // Returns true if this extension can inject scripts into pages with file URLs.
56 bool AllowFileAccess(const std::string
& extension_id
,
57 content::BrowserContext
* context
);
59 // Sets whether |extension_id| can inject scripts into pages with file URLs.
60 // Reloads the extension if it's enabled since this permission is applied at
61 // loading time only. Note than an ExtensionService must exist.
62 void SetAllowFileAccess(const std::string
& extension_id
,
63 content::BrowserContext
* context
,
66 // Returns true if the extension with |extension_id| is allowed to execute
67 // scripts on all urls (exempting chrome:// urls, etc) without explicit
69 // This should only be used with FeatureSwitch::scripts_require_action()
71 bool AllowedScriptingOnAllUrls(const std::string
& extension_id
,
72 content::BrowserContext
* context
);
74 // Returns the default value for being allowed to script on all urls.
75 bool DefaultAllowedScriptingOnAllUrls();
77 // Sets whether the extension with |extension_id| is allowed to execute scripts
78 // on all urls (exempting chrome:// urls, etc) without explicit user consent.
79 // This should only be used with FeatureSwitch::scripts_require_action()
81 void SetAllowedScriptingOnAllUrls(const std::string
& extension_id
,
82 content::BrowserContext
* context
,
85 // Returns true if the user has set an explicit preference for the specified
86 // extension being allowed to script on all urls; this is set to be true
87 // whenever SetAllowedScriptingOnAllUrls() is called.
88 bool HasSetAllowedScriptingOnAllUrls(const std::string
& extension_id
,
89 content::BrowserContext
* context
);
91 // Returns true if |extension_id| can be launched (possibly only after being
93 bool IsAppLaunchable(const std::string
& extension_id
,
94 content::BrowserContext
* context
);
96 // Returns true if |extension_id| can be launched without being enabled first.
97 bool IsAppLaunchableWithoutEnabling(const std::string
& extension_id
,
98 content::BrowserContext
* context
);
100 // Returns true if |extension| should be synced.
101 bool ShouldSyncExtension(const Extension
* extension
,
102 content::BrowserContext
* context
);
104 // Returns true if |app| should be synced.
105 bool ShouldSyncApp(const Extension
* app
, content::BrowserContext
* context
);
107 // Returns true if |extension_id| is idle and it is safe to perform actions such
109 bool IsExtensionIdle(const std::string
& extension_id
,
110 content::BrowserContext
* context
);
112 // Returns the site of the |extension_id|, given the associated |context|.
113 // Suitable for use with BrowserContext::GetStoragePartitionForSite().
114 GURL
GetSiteForExtensionId(const std::string
& extension_id
,
115 content::BrowserContext
* context
);
117 // Sets the name, id, and icon resource path of the given extension into the
118 // returned dictionary.
119 scoped_ptr
<base::DictionaryValue
> GetExtensionInfo(const Extension
* extension
);
121 // Returns true if the extension has isolated storage.
122 bool HasIsolatedStorage(const ExtensionInfo
& info
);
124 // Returns true if the site URL corresponds to an extension or app and has
126 bool SiteHasIsolatedStorage(const GURL
& extension_site_url
,
127 content::BrowserContext
* context
);
129 // Returns the default extension/app icon (for extensions or apps that don't
131 const gfx::ImageSkia
& GetDefaultExtensionIcon();
132 const gfx::ImageSkia
& GetDefaultAppIcon();
134 // Returns true if the bookmark apps feature is enabled.
136 // TODO(benwells): http://crbug.com/441128: Remove this entirely once the
137 // feature is stable.
138 bool IsNewBookmarkAppsEnabled();
140 // Returns true for custodian-installed extensions in a supervised profile.
141 bool IsExtensionSupervised(const Extension
* extension
, Profile
* profile
);
144 } // namespace extensions
146 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_UTIL_H_