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

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

Issue 173463: Update of the extension install UI: (Closed)
Patch Set: mpcompelte comments Created 11 years, 3 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "base/version.h" 16 #include "base/version.h"
17 #include "chrome/common/extensions/user_script.h" 17 #include "chrome/common/extensions/user_script.h"
18 #include "chrome/browser/extensions/user_script_master.h" 18 #include "chrome/browser/extensions/user_script_master.h"
19 #include "chrome/common/extensions/url_pattern.h" 19 #include "chrome/common/extensions/url_pattern.h"
20 #include "chrome/common/page_action.h" 20 #include "chrome/common/page_action.h"
21 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
22 22
23 // Represents a Chrome extension. 23 // Represents a Chrome extension.
24 class Extension { 24 class Extension {
25 public: 25 public:
26 typedef std::vector<URLPattern> HostPermissions;
27
26 // What an extension was loaded from. 28 // What an extension was loaded from.
27 enum Location { 29 enum Location {
28 INVALID, 30 INVALID,
29 INTERNAL, // A crx file from the internal Extensions directory. 31 INTERNAL, // A crx file from the internal Extensions directory.
30 EXTERNAL_PREF, // A crx file from an external directory (via prefs). 32 EXTERNAL_PREF, // A crx file from an external directory (via prefs).
31 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the 33 EXTERNAL_REGISTRY, // A crx file from an external directory (via eg the
32 // registry on Windows). 34 // registry on Windows).
33 LOAD // --load-extension. 35 LOAD // --load-extension.
34 }; 36 };
35 37
(...skipping 22 matching lines...) Expand all
58 EXTENSION_ICON_BITTY = 16, 60 EXTENSION_ICON_BITTY = 16,
59 }; 61 };
60 62
61 // Icon sizes used by the extension system. 63 // Icon sizes used by the extension system.
62 static const int kIconSizes[]; 64 static const int kIconSizes[];
63 65
64 // Each permission is a module that the extension is permitted to use. 66 // Each permission is a module that the extension is permitted to use.
65 static const char* kPermissionNames[]; 67 static const char* kPermissionNames[];
66 static const size_t kNumPermissions; 68 static const size_t kNumPermissions;
67 69
68 // A classification of how dangerous an extension can be, based on what it has
69 // access to.
70 enum PermissionClass {
71 PERMISSION_CLASS_LOW = 0, // green
72 PERMISSION_CLASS_MEDIUM, // yellow
73 PERMISSION_CLASS_HIGH, // orange
74 PERMISSION_CLASS_FULL, // red
75 };
76
77 struct PrivacyBlacklistInfo { 70 struct PrivacyBlacklistInfo {
78 FilePath path; // Path to the plain-text blacklist. 71 FilePath path; // Path to the plain-text blacklist.
79 }; 72 };
80 73
81 // An NPAPI plugin included in the extension. 74 // An NPAPI plugin included in the extension.
82 struct PluginInfo { 75 struct PluginInfo {
83 FilePath path; // Path to the plugin. 76 FilePath path; // Path to the plugin.
84 bool is_public; // False if only this extension can load this plugin. 77 bool is_public; // False if only this extension can load this plugin.
85 }; 78 };
86 79
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // Note: The result is coverted to lower-case because the browser enforces 161 // Note: The result is coverted to lower-case because the browser enforces
169 // hosts to be lower-case in omni-bar. 162 // hosts to be lower-case in omni-bar.
170 static bool GenerateIdFromPublicKey(const std::string& input, 163 static bool GenerateIdFromPublicKey(const std::string& input,
171 std::string* output); 164 std::string* output);
172 165
173 // Expects base64 encoded |input| and formats into |output| including 166 // Expects base64 encoded |input| and formats into |output| including
174 // the appropriate header & footer. 167 // the appropriate header & footer.
175 static bool FormatPEMForFileOutput(const std::string input, 168 static bool FormatPEMForFileOutput(const std::string input,
176 std::string* output, bool is_public); 169 std::string* output, bool is_public);
177 170
171 // Determine whether we should allow a silent upgrade from |old_extension| to
172 // |new_extension|. If not, the user will have to approve the upgrade.
173 static bool AllowSilentUpgrade(Extension* old_extension,
174 Extension* new_extension);
175
178 // Initialize the extension from a parsed manifest. 176 // Initialize the extension from a parsed manifest.
179 // If |require_id| is true, will return an error if the "id" key is missing 177 // If |require_id| is true, will return an error if the "id" key is missing
180 // from the value. 178 // from the value.
181 bool InitFromValue(const DictionaryValue& value, bool require_id, 179 bool InitFromValue(const DictionaryValue& value, bool require_id,
182 std::string* error); 180 std::string* error);
183 181
184 const FilePath& path() const { return path_; } 182 const FilePath& path() const { return path_; }
185 void set_path(const FilePath& path) { path_ = path; } 183 void set_path(const FilePath& path) { path_ = path; }
186 const GURL& url() const { return extension_url_; } 184 const GURL& url() const { return extension_url_; }
187 const Location location() const { return location_; } 185 const Location location() const { return location_; }
188 void set_location(Location location) { location_ = location; } 186 void set_location(Location location) { location_ = location; }
189 const std::string& id() const { return id_; } 187 const std::string& id() const { return id_; }
190 const Version* version() const { return version_.get(); } 188 const Version* version() const { return version_.get(); }
191 // String representation of the version number. 189 // String representation of the version number.
192 const std::string VersionString() const; 190 const std::string VersionString() const;
193 const std::string& name() const { return name_; } 191 const std::string& name() const { return name_; }
194 const std::string& public_key() const { return public_key_; } 192 const std::string& public_key() const { return public_key_; }
195 const std::string& description() const { return description_; } 193 const std::string& description() const { return description_; }
196 const UserScriptList& content_scripts() const { return content_scripts_; } 194 const UserScriptList& content_scripts() const { return content_scripts_; }
197 const PageActionMap& page_actions() const { return page_actions_; } 195 const PageActionMap& page_actions() const { return page_actions_; }
198 const std::vector<PrivacyBlacklistInfo>& privacy_blacklists() const { 196 const std::vector<PrivacyBlacklistInfo>& privacy_blacklists() const {
199 return privacy_blacklists_; 197 return privacy_blacklists_;
200 } 198 }
201 const std::vector<PluginInfo>& plugins() const { return plugins_; } 199 const std::vector<PluginInfo>& plugins() const { return plugins_; }
202 const GURL& background_url() const { return background_url_; } 200 const GURL& background_url() const { return background_url_; }
203 const std::vector<ToolstripInfo>& toolstrips() const { return toolstrips_; } 201 const std::vector<ToolstripInfo>& toolstrips() const { return toolstrips_; }
204 const std::vector<URLPattern>& host_permissions() const { 202 const HostPermissions& host_permissions() const {
205 return host_permissions_; 203 return host_permissions_;
206 } 204 }
207 const std::vector<std::string>& api_permissions() const { 205 const std::vector<std::string>& api_permissions() const {
208 return api_permissions_; 206 return api_permissions_;
209 } 207 }
208
209 // Returns the set of hosts that the extension effectively has access to. This
210 // is used in the permissions UI and is a combination of the hosts accessible
211 // through content scripts and the hosts accessible through XHR.
212 const std::set<std::string> GetEffectiveHostPermissions() const;
213
214 // Whether the extension has access to all hosts. This is true if there is
215 // a content script that matches all hosts, or if there is a host permission
216 // for all hosts.
217 bool HasAccessToAllHosts() const;
218
210 const GURL& update_url() const { return update_url_; } 219 const GURL& update_url() const { return update_url_; }
211 const std::map<int, std::string>& icons() { return icons_; } 220 const std::map<int, std::string>& icons() { return icons_; }
212 221
213 // Retrieves a page action by |id|. 222 // Retrieves a page action by |id|.
214 const PageAction* GetPageAction(std::string id) const; 223 const PageAction* GetPageAction(std::string id) const;
215 224
216 // Returns the origin of this extension. This function takes a |registry_path| 225 // Returns the origin of this extension. This function takes a |registry_path|
217 // so that the registry location can be overwritten during testing. 226 // so that the registry location can be overwritten during testing.
218 Location ExternalExtensionInstallType(std::string registry_path); 227 Location ExternalExtensionInstallType(std::string registry_path);
219 228
220 // Theme-related. 229 // Theme-related.
221 DictionaryValue* GetThemeImages() const { return theme_images_.get(); } 230 DictionaryValue* GetThemeImages() const { return theme_images_.get(); }
222 DictionaryValue* GetThemeColors() const { return theme_colors_.get(); } 231 DictionaryValue* GetThemeColors() const { return theme_colors_.get(); }
223 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } 232 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); }
224 DictionaryValue* GetThemeDisplayProperties() const { 233 DictionaryValue* GetThemeDisplayProperties() const {
225 return theme_display_properties_.get(); 234 return theme_display_properties_.get();
226 } 235 }
227 bool IsTheme() { return is_theme_; } 236 bool IsTheme() { return is_theme_; }
228 237
229 // Returns a list of paths (relative to the extension dir) for images that 238 // Returns a list of paths (relative to the extension dir) for images that
230 // the browser might load (like themes and page action icons). 239 // the browser might load (like themes and page action icons).
231 std::set<FilePath> GetBrowserImages(); 240 std::set<FilePath> GetBrowserImages();
232 241
233 // Calculates and returns the permission class this extension is in.
234 PermissionClass GetPermissionClass();
235
236 // Returns an absolute path to the given icon inside of the extension. Returns 242 // Returns an absolute path to the given icon inside of the extension. Returns
237 // an empty FilePath if the extension does not have that icon. 243 // an empty FilePath if the extension does not have that icon.
238 FilePath GetIconPath(Icons icon); 244 FilePath GetIconPath(Icons icon);
239 245
240 const DictionaryValue* manifest_value() const { 246 const DictionaryValue* manifest_value() const {
241 return manifest_value_.get(); 247 return manifest_value_.get();
242 } 248 }
243 249
244 // Returns a list of all locales supported by the extension. 250 // Returns a list of all locales supported by the extension.
245 const std::set<std::string>& supported_locales() const { 251 const std::set<std::string>& supported_locales() const {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 // A map of display properties. 358 // A map of display properties.
353 scoped_ptr<DictionaryValue> theme_display_properties_; 359 scoped_ptr<DictionaryValue> theme_display_properties_;
354 360
355 // Whether the extension is a theme - if it is, certain things are disabled. 361 // Whether the extension is a theme - if it is, certain things are disabled.
356 bool is_theme_; 362 bool is_theme_;
357 363
358 // The set of module-level APIs this extension can use. 364 // The set of module-level APIs this extension can use.
359 std::vector<std::string> api_permissions_; 365 std::vector<std::string> api_permissions_;
360 366
361 // The sites this extension has permission to talk to (using XHR, etc). 367 // The sites this extension has permission to talk to (using XHR, etc).
362 std::vector<URLPattern> host_permissions_; 368 HostPermissions host_permissions_;
363 369
364 // The paths to the icons the extension contains mapped by their width. 370 // The paths to the icons the extension contains mapped by their width.
365 std::map<int, std::string> icons_; 371 std::map<int, std::string> icons_;
366 372
367 // URL for fetching an update manifest 373 // URL for fetching an update manifest
368 GURL update_url_; 374 GURL update_url_;
369 375
370 // A copy of the manifest that this extension was created from. 376 // A copy of the manifest that this extension was created from.
371 scoped_ptr<DictionaryValue> manifest_value_; 377 scoped_ptr<DictionaryValue> manifest_value_;
372 378
373 // List of all locales extension supports. 379 // List of all locales extension supports.
374 std::set<std::string> supported_locales_; 380 std::set<std::string> supported_locales_;
375 381
376 // Default locale, used for fallback. 382 // Default locale, used for fallback.
377 std::string default_locale_; 383 std::string default_locale_;
378 384
379 // Runtime data: 385 // Runtime data:
380 386
381 // True if the background page is ready. 387 // True if the background page is ready.
382 bool background_page_ready_; 388 bool background_page_ready_;
383 389
384 FRIEND_TEST(ExtensionTest, LoadPageActionHelper); 390 FRIEND_TEST(ExtensionTest, LoadPageActionHelper);
385 391
386 DISALLOW_COPY_AND_ASSIGN(Extension); 392 DISALLOW_COPY_AND_ASSIGN(Extension);
387 }; 393 };
388 394
389 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ 395 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698