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

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

Issue 7432006: Add an experimental permissions API for extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 5 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/file_path.h" 14 #include "base/file_path.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/memory/linked_ptr.h" 16 #include "base/memory/linked_ptr.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/synchronization/lock.h"
19 #include "chrome/common/extensions/extension_constants.h" 20 #include "chrome/common/extensions/extension_constants.h"
20 #include "chrome/common/extensions/extension_icon_set.h" 21 #include "chrome/common/extensions/extension_icon_set.h"
21 #include "chrome/common/extensions/extension_permission_set.h" 22 #include "chrome/common/extensions/extension_permission_set.h"
22 #include "chrome/common/extensions/user_script.h" 23 #include "chrome/common/extensions/user_script.h"
23 #include "chrome/common/extensions/url_pattern.h" 24 #include "chrome/common/extensions/url_pattern.h"
24 #include "chrome/common/extensions/url_pattern_set.h" 25 #include "chrome/common/extensions/url_pattern_set.h"
25 #include "googleurl/src/gurl.h" 26 #include "googleurl/src/gurl.h"
26 #include "ui/gfx/size.h" 27 #include "ui/gfx/size.h"
27 28
28 class ExtensionAction; 29 class ExtensionAction;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 std::string* error); 199 std::string* error);
199 200
200 // Return the update url used by gallery/webstore extensions. 201 // Return the update url used by gallery/webstore extensions.
201 static GURL GalleryUpdateUrl(bool secure); 202 static GURL GalleryUpdateUrl(bool secure);
202 203
203 // Given two install sources, return the one which should take priority 204 // Given two install sources, return the one which should take priority
204 // over the other. If an extension is installed from two sources A and B, 205 // over the other. If an extension is installed from two sources A and B,
205 // its install source should be set to GetHigherPriorityLocation(A, B). 206 // its install source should be set to GetHigherPriorityLocation(A, B).
206 static Location GetHigherPriorityLocation(Location loc1, Location loc2); 207 static Location GetHigherPriorityLocation(Location loc1, Location loc2);
207 208
208 // Returns the full list of permission messages that this extension
209 // should display at install time.
210 ExtensionPermissionMessages GetPermissionMessages() const;
211
212 // Returns the full list of permission messages that this extension
213 // should display at install time. The messages are returned as strings
214 // for convenience.
215 std::vector<string16> GetPermissionMessageStrings() const;
216
217 // Icon sizes used by the extension system. 209 // Icon sizes used by the extension system.
218 static const int kIconSizes[]; 210 static const int kIconSizes[];
219 211
220 // Max size (both dimensions) for browser and page actions. 212 // Max size (both dimensions) for browser and page actions.
221 static const int kPageActionIconMaxSize; 213 static const int kPageActionIconMaxSize;
222 static const int kBrowserActionIconMaxSize; 214 static const int kBrowserActionIconMaxSize;
223 static const int kSidebarIconMaxSize; 215 static const int kSidebarIconMaxSize;
224 216
225 // Valid schemes for web extent URLPatterns. 217 // Valid schemes for web extent URLPatterns.
226 static const int kValidWebExtentSchemes; 218 static const int kValidWebExtentSchemes;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // --apps-gallery-url switch. The URL returned will not contain a trailing 356 // --apps-gallery-url switch. The URL returned will not contain a trailing
365 // slash. Do not use this as a prefix/extent for the store. Instead see 357 // slash. Do not use this as a prefix/extent for the store. Instead see
366 // ExtensionService::GetWebStoreApp or 358 // ExtensionService::GetWebStoreApp or
367 // ExtensionService::IsDownloadFromGallery 359 // ExtensionService::IsDownloadFromGallery
368 static std::string ChromeStoreLaunchURL(); 360 static std::string ChromeStoreLaunchURL();
369 361
370 // Adds an extension to the scripting whitelist. Used for testing only. 362 // Adds an extension to the scripting whitelist. Used for testing only.
371 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); 363 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist);
372 static const ScriptingWhitelist* GetScriptingWhitelist(); 364 static const ScriptingWhitelist* GetScriptingWhitelist();
373 365
366 // Parses the host and api permissions from the specified permission |key|
367 // in the manifest |source|.
368 bool ParsePermissions(const base::DictionaryValue* source,
369 const char* key,
370 int flags,
371 std::string* error,
372 ExtensionAPIPermissionSet* api_permissions,
373 URLPatternSet* host_permissions);
374
374 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const; 375 bool HasAPIPermission(ExtensionAPIPermission::ID permission) const;
375 bool HasAPIPermission(const std::string& function_name) const; 376 bool HasAPIPermission(const std::string& function_name) const;
376 377
377 const URLPatternSet& GetEffectiveHostPermissions() const; 378 const URLPatternSet& GetEffectiveHostPermissions() const;
378 379
379 // Whether or not the extension is allowed permission for a URL pattern from 380 // Whether or not the extension is allowed permission for a URL pattern from
380 // the manifest. http, https, and chrome://favicon/ is allowed for all 381 // the manifest. http, https, and chrome://favicon/ is allowed for all
381 // extensions, while component extensions are allowed access to 382 // extensions, while component extensions are allowed access to
382 // chrome://resources. 383 // chrome://resources.
383 bool CanSpecifyHostPermission(const URLPattern& pattern) const; 384 bool CanSpecifyHostPermission(const URLPattern& pattern) const;
384 385
385 // Whether the extension has access to the given URL. 386 // Whether the extension has access to the given URL.
386 bool HasHostPermission(const GURL& url) const; 387 bool HasHostPermission(const GURL& url) const;
387 388
388 // Whether the extension has effective access to all hosts. This is true if 389 // Whether the extension has effective access to all hosts. This is true if
389 // there is a content script that matches all hosts, if there is a host 390 // there is a content script that matches all hosts, if there is a host
390 // permission grants access to all hosts (like <all_urls>) or an api 391 // permission grants access to all hosts (like <all_urls>) or an api
391 // permission that effectively grants access to all hosts (e.g. proxy, 392 // permission that effectively grants access to all hosts (e.g. proxy,
392 // network, etc.) 393 // network, etc.)
393 bool HasEffectiveAccessToAllHosts() const; 394 bool HasEffectiveAccessToAllHosts() const;
394 395
395 // Whether the extension effectively has all permissions (for example, by 396 // Whether the extension effectively has all permissions (for example, by
396 // having an NPAPI plugin). 397 // having an NPAPI plugin).
397 bool HasFullPermissions() const; 398 bool HasFullPermissions() const;
398 399
400 // Returns the full list of permission messages that this extension
401 // should display at install time.
402 ExtensionPermissionMessages GetPermissionMessages() const;
403
404 // Returns the full list of permission messages that this extension
405 // should display at install time. The messages are returned as strings
406 // for convenience.
407 std::vector<string16> GetPermissionMessageStrings() const;
408
409 // Sets the active |permissions|.
410 void SetActivePermissions(const ExtensionPermissionSet* permissions) const;
411
412 // Gets the extension's active permission set.
413 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const;
414
399 // Whether context menu should be shown for page and browser actions. 415 // Whether context menu should be shown for page and browser actions.
400 bool ShowConfigureContextMenus() const; 416 bool ShowConfigureContextMenus() const;
401 417
402 // Returns the Homepage URL for this extension. If homepage_url was not 418 // Returns the Homepage URL for this extension. If homepage_url was not
403 // specified in the manifest, this returns the Google Gallery URL. For 419 // specified in the manifest, this returns the Google Gallery URL. For
404 // third-party extensions, this returns a blank GURL. 420 // third-party extensions, this returns a blank GURL.
405 GURL GetHomepageURL() const; 421 GURL GetHomepageURL() const;
406 422
407 // Returns a list of paths (relative to the extension dir) for images that 423 // Returns a list of paths (relative to the extension dir) for images that
408 // the browser might load (like themes and page action icons). 424 // the browser might load (like themes and page action icons).
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 const std::vector<NaClModuleInfo>& nacl_modules() const { 499 const std::vector<NaClModuleInfo>& nacl_modules() const {
484 return nacl_modules_; 500 return nacl_modules_;
485 } 501 }
486 const std::vector<InputComponentInfo>& input_components() const { 502 const std::vector<InputComponentInfo>& input_components() const {
487 return input_components_; 503 return input_components_;
488 } 504 }
489 const GURL& background_url() const { return background_url_; } 505 const GURL& background_url() const { return background_url_; }
490 const GURL& options_url() const { return options_url_; } 506 const GURL& options_url() const { return options_url_; }
491 const GURL& devtools_url() const { return devtools_url_; } 507 const GURL& devtools_url() const { return devtools_url_; }
492 const std::vector<GURL>& toolstrips() const { return toolstrips_; } 508 const std::vector<GURL>& toolstrips() const { return toolstrips_; }
493 const ExtensionPermissionSet* permission_set() const { 509 const ExtensionPermissionSet* optional_permission_set() const {
494 return permission_set_.get(); 510 return optional_permission_set_.get();
511 }
512 const ExtensionPermissionSet* required_permission_set() const {
513 return required_permission_set_.get();
495 } 514 }
496 const GURL& update_url() const { return update_url_; } 515 const GURL& update_url() const { return update_url_; }
497 const ExtensionIconSet& icons() const { return icons_; } 516 const ExtensionIconSet& icons() const { return icons_; }
498 const base::DictionaryValue* manifest_value() const { 517 const base::DictionaryValue* manifest_value() const {
499 return manifest_value_.get(); 518 return manifest_value_.get();
500 } 519 }
501 const std::string default_locale() const { return default_locale_; } 520 const std::string default_locale() const { return default_locale_; }
502 const URLOverrideMap& GetChromeURLOverrides() const { 521 const URLOverrideMap& GetChromeURLOverrides() const {
503 return chrome_url_overrides_; 522 return chrome_url_overrides_;
504 } 523 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 557
539 private: 558 private:
540 friend class base::RefCountedThreadSafe<Extension>; 559 friend class base::RefCountedThreadSafe<Extension>;
541 560
542 // We keep a cache of images loaded from extension resources based on their 561 // We keep a cache of images loaded from extension resources based on their
543 // path and a string representation of a size that may have been used to 562 // path and a string representation of a size that may have been used to
544 // scale it (or the empty string if the image is at its original size). 563 // scale it (or the empty string if the image is at its original size).
545 typedef std::pair<FilePath, std::string> ImageCacheKey; 564 typedef std::pair<FilePath, std::string> ImageCacheKey;
546 typedef std::map<ImageCacheKey, SkBitmap> ImageCache; 565 typedef std::map<ImageCacheKey, SkBitmap> ImageCache;
547 566
567 class RuntimeData : public base::RefCountedThreadSafe<RuntimeData> {
Mihai Parparita -not on Chrome 2011/07/21 21:18:13 I don't think making this ref counted buys you any
jstritar 2011/07/22 19:21:55 Done.
568 public:
569 RuntimeData();
570 explicit RuntimeData(const ExtensionPermissionSet* active);
571 ~RuntimeData();
572
573 void SetActivePermissions(const ExtensionPermissionSet* active);
574 scoped_refptr<const ExtensionPermissionSet> GetActivePermissions() const;
575
576 private:
577 friend class base::RefCountedThreadSafe<RuntimeData>;
578 scoped_refptr<const ExtensionPermissionSet> active_permissions_;
579 };
580
548 // Normalize the path for use by the extension. On Windows, this will make 581 // Normalize the path for use by the extension. On Windows, this will make
549 // sure the drive letter is uppercase. 582 // sure the drive letter is uppercase.
550 static FilePath MaybeNormalizePath(const FilePath& path); 583 static FilePath MaybeNormalizePath(const FilePath& path);
551 584
552 // Returns true if this extension id is from a trusted provider. 585 // Returns true if this extension id is from a trusted provider.
553 static bool IsTrustedId(const std::string& id); 586 static bool IsTrustedId(const std::string& id);
554 587
555 Extension(const FilePath& path, Location location); 588 Extension(const FilePath& path, Location location);
556 ~Extension(); 589 ~Extension();
557 590
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 // Default locale for fall back. Can be empty if extension is not localized. 693 // Default locale for fall back. Can be empty if extension is not localized.
661 std::string default_locale_; 694 std::string default_locale_;
662 695
663 // If true, a separate process will be used for the extension in incognito 696 // If true, a separate process will be used for the extension in incognito
664 // mode. 697 // mode.
665 bool incognito_split_mode_; 698 bool incognito_split_mode_;
666 699
667 // Defines the set of URLs in the extension's web content. 700 // Defines the set of URLs in the extension's web content.
668 URLPatternSet extent_; 701 URLPatternSet extent_;
669 702
670 // The set of permissions that the extension effectively has access to. 703 // The extension runtime data.
671 scoped_ptr<ExtensionPermissionSet> permission_set_; 704 mutable base::Lock runtime_data_lock_;
705 mutable RuntimeData runtime_data_;
jstritar 2011/07/19 17:10:53 I kept this in Extension to simplify these changes
706
707 // The set of permissions the extension can request at runtime.
708 scoped_ptr<const ExtensionPermissionSet> optional_permission_set_;
709
710 // The extension's required / default set of permissions.
711 scoped_ptr<const ExtensionPermissionSet> required_permission_set_;
672 712
673 // The icons for the extension. 713 // The icons for the extension.
674 ExtensionIconSet icons_; 714 ExtensionIconSet icons_;
675 715
676 // The base extension url for the extension. 716 // The base extension url for the extension.
677 GURL extension_url_; 717 GURL extension_url_;
678 718
679 // The location the extension was loaded from. 719 // The location the extension was loaded from.
680 Location location_; 720 Location location_;
681 721
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 897
858 // Was the extension already disabled? 898 // Was the extension already disabled?
859 bool already_disabled; 899 bool already_disabled;
860 900
861 // The extension being unloaded - this should always be non-NULL. 901 // The extension being unloaded - this should always be non-NULL.
862 const Extension* extension; 902 const Extension* extension;
863 903
864 UnloadedExtensionInfo(const Extension* extension, Reason reason); 904 UnloadedExtensionInfo(const Extension* extension, Reason reason);
865 }; 905 };
866 906
907 // The details sent for EXTENSION_PERMISSIONS_UPDATED notifications.
908 struct UpdatedExtensionPermissionsInfo {
909 enum Reason {
910 ADDED, // The permissions were added to the extension.
911 REMOVED, // The permissions were removed from the extension.
912 };
913
914 Reason reason;
915
916 // The extension who's permissions have changed.
917 const Extension* extension;
918
919 // The permissions that have changed. For Reason::ADDED, this would contain
920 // only the permissions that have added, and for Reason::REMOVED, this would
921 // only contain the removed permissions.
922 const ExtensionPermissionSet* permissions;
923
924 UpdatedExtensionPermissionsInfo(
925 const Extension* extension,
926 const ExtensionPermissionSet* permissions,
927 Reason reason);
928 };
929
867 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ 930 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698