• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_UTIL_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_UTIL_H_
7 
8 #include <string>
9 
10 #include "base/memory/scoped_ptr.h"
11 #include "url/gurl.h"
12 
13 namespace base {
14 class DictionaryValue;
15 }
16 
17 namespace content {
18 class BrowserContext;
19 }
20 
21 namespace gfx {
22 class ImageSkia;
23 }
24 
25 namespace extensions {
26 
27 class Extension;
28 struct ExtensionInfo;
29 
30 namespace util {
31 
32 // Returns true if |extension_id| can run in an incognito window.
33 bool IsIncognitoEnabled(const std::string& extension_id,
34                         content::BrowserContext* context);
35 
36 // Sets whether |extension_id| can run in an incognito window. Reloads the
37 // extension if it's enabled since this permission is applied at loading time
38 // only. Note that an ExtensionService must exist.
39 void SetIsIncognitoEnabled(const std::string& extension_id,
40                            content::BrowserContext* context,
41                            bool enabled);
42 
43 // Returns true if |extension| can see events and data from another sub-profile
44 // (incognito to original profile, or vice versa).
45 bool CanCrossIncognito(const extensions::Extension* extension,
46                        content::BrowserContext* context);
47 
48 // Returns true if |extension| can be loaded in incognito.
49 bool CanLoadInIncognito(const extensions::Extension* extension,
50                         content::BrowserContext* context);
51 
52 // Returns true if this extension can inject scripts into pages with file URLs.
53 bool AllowFileAccess(const std::string& extension_id,
54                      content::BrowserContext* context);
55 
56 // Sets whether |extension_id| can inject scripts into pages with file URLs.
57 // Reloads the extension if it's enabled since this permission is applied at
58 // loading time only. Note than an ExtensionService must exist.
59 void SetAllowFileAccess(const std::string& extension_id,
60                         content::BrowserContext* context,
61                         bool allow);
62 
63 // Returns true if the extension with |extension_id| is allowed to execute
64 // scripts on all urls (exempting chrome:// urls, etc) without explicit
65 // user consent.
66 // This should only be used with FeatureSwitch::scripts_require_action()
67 // enabled.
68 bool AllowedScriptingOnAllUrls(const std::string& extension_id,
69                                content::BrowserContext* context);
70 
71 // Sets whether the extension with |extension_id| is allowed to execute scripts
72 // on all urls (exempting chrome:// urls, etc) without explicit user consent.
73 // This should only be used with FeatureSwitch::scripts_require_action()
74 // enabled.
75 void SetAllowedScriptingOnAllUrls(const std::string& extension_id,
76                                   content::BrowserContext* context,
77                                   bool allowed);
78 
79 // Returns true if the --scripts-require-action flag would possibly affect
80 // the given |extension|.
81 bool ScriptsMayRequireActionForExtension(const Extension* extension);
82 
83 // Returns true if |extension_id| can be launched (possibly only after being
84 // enabled).
85 bool IsAppLaunchable(const std::string& extension_id,
86                      content::BrowserContext* context);
87 
88 // Returns true if |extension_id| can be launched without being enabled first.
89 bool IsAppLaunchableWithoutEnabling(const std::string& extension_id,
90                                     content::BrowserContext* context);
91 
92 // Returns true if |extension| should be synced.
93 bool ShouldSyncExtension(const Extension* extension,
94                          content::BrowserContext* context);
95 
96 // Returns true if |app| should be synced.
97 bool ShouldSyncApp(const Extension* app, content::BrowserContext* context);
98 
99 // Returns true if |extension_id| is idle and it is safe to perform actions such
100 // as updating.
101 bool IsExtensionIdle(const std::string& extension_id,
102                      content::BrowserContext* context);
103 
104 // Returns the site of the |extension_id|, given the associated |context|.
105 // Suitable for use with BrowserContext::GetStoragePartitionForSite().
106 GURL GetSiteForExtensionId(const std::string& extension_id,
107                            content::BrowserContext* context);
108 
109 // Sets the name, id, and icon resource path of the given extension into the
110 // returned dictionary.
111 scoped_ptr<base::DictionaryValue> GetExtensionInfo(const Extension* extension);
112 
113 // Returns true if the extension has isolated storage.
114 bool HasIsolatedStorage(const ExtensionInfo& info);
115 
116 // Returns true if the site URL corresponds to an extension or app and has
117 // isolated storage.
118 bool SiteHasIsolatedStorage(const GURL& extension_site_url,
119                             content::BrowserContext* context);
120 
121 // Returns the default extension/app icon (for extensions or apps that don't
122 // have one).
123 const gfx::ImageSkia& GetDefaultExtensionIcon();
124 const gfx::ImageSkia& GetDefaultAppIcon();
125 
126 // Returns true if the experimental streamlined hosted apps feature is enabled.
127 bool IsStreamlinedHostedAppsEnabled();
128 
129 }  // namespace util
130 }  // namespace extensions
131 
132 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_UTIL_H_
133