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

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

Issue 189123005: Define the ExtensionId typedef, and use it in extension.h. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add comment suggested by Antony Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 EXTENSIONS_COMMON_EXTENSION_H_ 5 #ifndef EXTENSIONS_COMMON_EXTENSION_H_
6 #define EXTENSIONS_COMMON_EXTENSION_H_ 6 #define EXTENSIONS_COMMON_EXTENSION_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <iosfwd> 9 #include <iosfwd>
10 #include <map> 10 #include <map>
(...skipping 30 matching lines...) Expand all
41 namespace gfx { 41 namespace gfx {
42 class ImageSkia; 42 class ImageSkia;
43 } 43 }
44 44
45 namespace extensions { 45 namespace extensions {
46 class PermissionsData; 46 class PermissionsData;
47 class APIPermissionSet; 47 class APIPermissionSet;
48 class ManifestPermissionSet; 48 class ManifestPermissionSet;
49 class PermissionSet; 49 class PermissionSet;
50 50
51 // Uniquely identifies an Extension, using 32 characters from the alphabet
52 // 'a'-'p'. An empty string represents "no extension".
53 //
54 // Note: If this gets used heavily in files that don't otherwise need to include
55 // extension.h, we should pull it into a dedicated header.
56 typedef std::string ExtensionId;
57
51 // Represents a Chrome extension. 58 // Represents a Chrome extension.
52 // Once created, an Extension object is immutable, with the exception of its 59 // Once created, an Extension object is immutable, with the exception of its
53 // RuntimeData. This makes it safe to use on any thread, since access to the 60 // RuntimeData. This makes it safe to use on any thread, since access to the
54 // RuntimeData is protected by a lock. 61 // RuntimeData is protected by a lock.
55 class Extension : public base::RefCountedThreadSafe<Extension> { 62 class Extension : public base::RefCountedThreadSafe<Extension> {
56 public: 63 public:
57 struct ManifestData; 64 struct ManifestData;
58 65
59 typedef std::map<const std::string, linked_ptr<ManifestData> > 66 typedef std::map<const std::string, linked_ptr<ManifestData> >
60 ManifestDataMap; 67 ManifestDataMap;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 const base::DictionaryValue& value, 171 const base::DictionaryValue& value,
165 int flags, 172 int flags,
166 std::string* error); 173 std::string* error);
167 174
168 // In a few special circumstances, we want to create an Extension and give it 175 // In a few special circumstances, we want to create an Extension and give it
169 // an explicit id. Most consumers should just use the other Create() method. 176 // an explicit id. Most consumers should just use the other Create() method.
170 static scoped_refptr<Extension> Create(const base::FilePath& path, 177 static scoped_refptr<Extension> Create(const base::FilePath& path,
171 Manifest::Location location, 178 Manifest::Location location,
172 const base::DictionaryValue& value, 179 const base::DictionaryValue& value,
173 int flags, 180 int flags,
174 const std::string& explicit_id, 181 const ExtensionId& explicit_id,
175 std::string* error); 182 std::string* error);
176 183
177 // Valid schemes for web extent URLPatterns. 184 // Valid schemes for web extent URLPatterns.
178 static const int kValidWebExtentSchemes; 185 static const int kValidWebExtentSchemes;
179 186
180 // Valid schemes for host permission URLPatterns. 187 // Valid schemes for host permission URLPatterns.
181 static const int kValidHostPermissionSchemes; 188 static const int kValidHostPermissionSchemes;
182 189
183 // The mimetype used for extensions. 190 // The mimetype used for extensions.
184 static const char kMimeType[]; 191 static const char kMimeType[];
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // Does a simple base64 encoding of |input| into |output|. 227 // Does a simple base64 encoding of |input| into |output|.
221 static bool ProducePEM(const std::string& input, std::string* output); 228 static bool ProducePEM(const std::string& input, std::string* output);
222 229
223 // Expects base64 encoded |input| and formats into |output| including 230 // Expects base64 encoded |input| and formats into |output| including
224 // the appropriate header & footer. 231 // the appropriate header & footer.
225 static bool FormatPEMForFileOutput(const std::string& input, 232 static bool FormatPEMForFileOutput(const std::string& input,
226 std::string* output, 233 std::string* output,
227 bool is_public); 234 bool is_public);
228 235
229 // Returns the base extension url for a given |extension_id|. 236 // Returns the base extension url for a given |extension_id|.
230 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); 237 static GURL GetBaseURLFromExtensionId(const ExtensionId& extension_id);
231 238
232 // DEPRECATED: These methods have been moved to PermissionsData. 239 // DEPRECATED: These methods have been moved to PermissionsData.
233 // TODO(rdevlin.cronin): remove these once all calls have been updated. 240 // TODO(rdevlin.cronin): remove these once all calls have been updated.
234 bool HasAPIPermission(APIPermission::ID permission) const; 241 bool HasAPIPermission(APIPermission::ID permission) const;
235 bool HasAPIPermission(const std::string& permission_name) const; 242 bool HasAPIPermission(const std::string& permission_name) const;
236 scoped_refptr<const PermissionSet> GetActivePermissions() const; 243 scoped_refptr<const PermissionSet> GetActivePermissions() const;
237 244
238 // Whether context menu should be shown for page and browser actions. 245 // Whether context menu should be shown for page and browser actions.
239 bool ShowConfigureContextMenus() const; 246 bool ShowConfigureContextMenus() const;
240 247
(...skipping 26 matching lines...) Expand all
267 // Sets |data| to be associated with the key. Takes ownership of |data|. 274 // Sets |data| to be associated with the key. Takes ownership of |data|.
268 // Can only be called before InitValue is finished. Not thread-safe; 275 // Can only be called before InitValue is finished. Not thread-safe;
269 // all SetManifestData calls should be on only one thread. 276 // all SetManifestData calls should be on only one thread.
270 void SetManifestData(const std::string& key, ManifestData* data); 277 void SetManifestData(const std::string& key, ManifestData* data);
271 278
272 // Accessors: 279 // Accessors:
273 280
274 const base::FilePath& path() const { return path_; } 281 const base::FilePath& path() const { return path_; }
275 const GURL& url() const { return extension_url_; } 282 const GURL& url() const { return extension_url_; }
276 Manifest::Location location() const; 283 Manifest::Location location() const;
277 const std::string& id() const; 284 const ExtensionId& id() const;
278 const base::Version* version() const { return version_.get(); } 285 const base::Version* version() const { return version_.get(); }
279 const std::string VersionString() const; 286 const std::string VersionString() const;
280 const std::string& name() const { return name_; } 287 const std::string& name() const { return name_; }
281 const std::string& short_name() const { return short_name_; } 288 const std::string& short_name() const { return short_name_; }
282 const std::string& non_localized_name() const { return non_localized_name_; } 289 const std::string& non_localized_name() const { return non_localized_name_; }
283 // Base64-encoded version of the key used to sign this extension. 290 // Base64-encoded version of the key used to sign this extension.
284 // In pseudocode, returns 291 // In pseudocode, returns
285 // base::Base64Encode(RSAPrivateKey(pem_file).ExportPublicKey()). 292 // base::Base64Encode(RSAPrivateKey(pem_file).ExportPublicKey()).
286 const std::string& public_key() const { return public_key_; } 293 const std::string& public_key() const { return public_key_; }
287 const std::string& description() const { return description_; } 294 const std::string& description() const { return description_; }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // Theme-related. 340 // Theme-related.
334 bool is_theme() const; 341 bool is_theme() const;
335 342
336 private: 343 private:
337 friend class base::RefCountedThreadSafe<Extension>; 344 friend class base::RefCountedThreadSafe<Extension>;
338 345
339 // Chooses the extension ID for an extension based on a variety of criteria. 346 // Chooses the extension ID for an extension based on a variety of criteria.
340 // The chosen ID will be set in |manifest|. 347 // The chosen ID will be set in |manifest|.
341 static bool InitExtensionID(extensions::Manifest* manifest, 348 static bool InitExtensionID(extensions::Manifest* manifest,
342 const base::FilePath& path, 349 const base::FilePath& path,
343 const std::string& explicit_id, 350 const ExtensionId& explicit_id,
344 int creation_flags, 351 int creation_flags,
345 base::string16* error); 352 base::string16* error);
346 353
347 Extension(const base::FilePath& path, 354 Extension(const base::FilePath& path,
348 scoped_ptr<extensions::Manifest> manifest); 355 scoped_ptr<extensions::Manifest> manifest);
349 virtual ~Extension(); 356 virtual ~Extension();
350 357
351 // Initialize the extension from a parsed manifest. 358 // Initialize the extension from a parsed manifest.
352 // TODO(aa): Rename to just Init()? There's no Value here anymore. 359 // TODO(aa): Rename to just Init()? There's no Value here anymore.
353 // TODO(aa): It is really weird the way this class essentially contains a copy 360 // TODO(aa): It is really weird the way this class essentially contains a copy
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 // granted it that access). 460 // granted it that access).
454 bool wants_file_access_; 461 bool wants_file_access_;
455 462
456 // The flags that were passed to InitFromValue. 463 // The flags that were passed to InitFromValue.
457 int creation_flags_; 464 int creation_flags_;
458 465
459 DISALLOW_COPY_AND_ASSIGN(Extension); 466 DISALLOW_COPY_AND_ASSIGN(Extension);
460 }; 467 };
461 468
462 typedef std::vector<scoped_refptr<const Extension> > ExtensionList; 469 typedef std::vector<scoped_refptr<const Extension> > ExtensionList;
463 typedef std::set<std::string> ExtensionIdSet; 470 typedef std::set<ExtensionId> ExtensionIdSet;
464 typedef std::vector<std::string> ExtensionIdList; 471 typedef std::vector<ExtensionId> ExtensionIdList;
465 472
466 // Handy struct to pass core extension info around. 473 // Handy struct to pass core extension info around.
467 struct ExtensionInfo { 474 struct ExtensionInfo {
468 ExtensionInfo(const base::DictionaryValue* manifest, 475 ExtensionInfo(const base::DictionaryValue* manifest,
469 const std::string& id, 476 const ExtensionId& id,
470 const base::FilePath& path, 477 const base::FilePath& path,
471 Manifest::Location location); 478 Manifest::Location location);
472 ~ExtensionInfo(); 479 ~ExtensionInfo();
473 480
474 scoped_ptr<base::DictionaryValue> extension_manifest; 481 scoped_ptr<base::DictionaryValue> extension_manifest;
475 std::string extension_id; 482 ExtensionId extension_id;
476 base::FilePath extension_path; 483 base::FilePath extension_path;
477 Manifest::Location extension_location; 484 Manifest::Location extension_location;
478 485
479 private: 486 private:
480 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo); 487 DISALLOW_COPY_AND_ASSIGN(ExtensionInfo);
481 }; 488 };
482 489
483 struct InstalledExtensionInfo { 490 struct InstalledExtensionInfo {
484 // The extension being installed - this should always be non-NULL. 491 // The extension being installed - this should always be non-NULL.
485 const Extension* extension; 492 const Extension* extension;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 539
533 UpdatedExtensionPermissionsInfo( 540 UpdatedExtensionPermissionsInfo(
534 const Extension* extension, 541 const Extension* extension,
535 const PermissionSet* permissions, 542 const PermissionSet* permissions,
536 Reason reason); 543 Reason reason);
537 }; 544 };
538 545
539 } // namespace extensions 546 } // namespace extensions
540 547
541 #endif // EXTENSIONS_COMMON_EXTENSION_H_ 548 #endif // EXTENSIONS_COMMON_EXTENSION_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698