| OLD | NEW |
| 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 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 <algorithm> | 8 #include <algorithm> |
| 9 #include <iosfwd> | 9 #include <iosfwd> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 std::string* output, | 240 std::string* output, |
| 241 bool is_public); | 241 bool is_public); |
| 242 | 242 |
| 243 // Returns the base extension url for a given |extension_id|. | 243 // Returns the base extension url for a given |extension_id|. |
| 244 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); | 244 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); |
| 245 | 245 |
| 246 // Adds an extension to the scripting whitelist. Used for testing only. | 246 // Adds an extension to the scripting whitelist. Used for testing only. |
| 247 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); | 247 static void SetScriptingWhitelist(const ScriptingWhitelist& whitelist); |
| 248 static const ScriptingWhitelist* GetScriptingWhitelist(); | 248 static const ScriptingWhitelist* GetScriptingWhitelist(); |
| 249 | 249 |
| 250 // Returns true if this extension has the given permission. Prefer | 250 // DEPRECATED: These methods have been moved to PermissionsData. |
| 251 // IsExtensionWithPermissionOrSuggestInConsole when developers may be using an | 251 // TODO(rdevlin.cronin): remove these once all calls have been updated. |
| 252 // api that requires a permission they didn't know about, e.g. open web apis. | |
| 253 bool HasAPIPermission(APIPermission::ID permission) const; | 252 bool HasAPIPermission(APIPermission::ID permission) const; |
| 254 bool HasAPIPermission(const std::string& function_name) const; | 253 bool HasAPIPermission(const std::string& function_name) const; |
| 255 bool HasAPIPermissionForTab(int tab_id, APIPermission::ID permission) const; | |
| 256 | |
| 257 bool CheckAPIPermissionWithParam( | |
| 258 APIPermission::ID permission, | |
| 259 const APIPermission::CheckParam* param) const; | |
| 260 | |
| 261 const URLPatternSet& GetEffectiveHostPermissions() const; | |
| 262 | |
| 263 // Returns true if the extension can silently increase its permission level. | |
| 264 // Users must approve permissions for unpacked and packed extensions in the | |
| 265 // following situations: | |
| 266 // - when installing or upgrading packed extensions | |
| 267 // - when installing unpacked extensions that have NPAPI plugins | |
| 268 // - when either type of extension requests optional permissions | |
| 269 bool CanSilentlyIncreasePermissions() const; | |
| 270 | |
| 271 // Whether the extension has access to the given URL. | |
| 272 bool HasHostPermission(const GURL& url) const; | |
| 273 | |
| 274 // Whether the extension has effective access to all hosts. This is true if | |
| 275 // there is a content script that matches all hosts, if there is a host | |
| 276 // permission grants access to all hosts (like <all_urls>) or an api | |
| 277 // permission that effectively grants access to all hosts (e.g. proxy, | |
| 278 // network, etc.) | |
| 279 bool HasEffectiveAccessToAllHosts() const; | |
| 280 | |
| 281 // Whether the extension effectively has all permissions (for example, by | |
| 282 // having an NPAPI plugin). | |
| 283 bool HasFullPermissions() const; | |
| 284 | |
| 285 // Returns the full list of permission messages that this extension | |
| 286 // should display at install time. | |
| 287 PermissionMessages GetPermissionMessages() const; | |
| 288 | |
| 289 // Returns the full list of permission messages that this extension | |
| 290 // should display at install time. The messages are returned as strings | |
| 291 // for convenience. | |
| 292 std::vector<string16> GetPermissionMessageStrings() const; | |
| 293 | |
| 294 // Returns true if the extension does not require permission warnings | |
| 295 // to be displayed at install time. | |
| 296 bool ShouldSkipPermissionWarnings() const; | |
| 297 | |
| 298 // Sets the active |permissions|. | |
| 299 void SetActivePermissions(const PermissionSet* permissions) const; | |
| 300 | |
| 301 // Gets the extension's active permission set. | |
| 302 scoped_refptr<const PermissionSet> GetActivePermissions() const; | 254 scoped_refptr<const PermissionSet> GetActivePermissions() const; |
| 303 | 255 |
| 304 // Whether context menu should be shown for page and browser actions. | 256 // Whether context menu should be shown for page and browser actions. |
| 305 bool ShowConfigureContextMenus() const; | 257 bool ShowConfigureContextMenus() const; |
| 306 | 258 |
| 307 // Gets the fully resolved absolute launch URL. | 259 // Gets the fully resolved absolute launch URL. |
| 308 GURL GetFullLaunchURL() const; | 260 GURL GetFullLaunchURL() const; |
| 309 | 261 |
| 310 // Returns true if this extension can execute script on a page. If a | |
| 311 // UserScript object is passed, permission to run that specific script is | |
| 312 // checked (using its matches list). Otherwise, permission to execute script | |
| 313 // programmatically is checked (using the extension's host permission). | |
| 314 // | |
| 315 // This method is also aware of certain special pages that extensions are | |
| 316 // usually not allowed to run script on. | |
| 317 bool CanExecuteScriptOnPage(const GURL& document_url, | |
| 318 const GURL& top_document_url, | |
| 319 int tab_id, | |
| 320 const UserScript* script, | |
| 321 std::string* error) const; | |
| 322 | |
| 323 // Returns true if this extension is a COMPONENT extension, or if it is | |
| 324 // on the whitelist of extensions that can script all pages. | |
| 325 bool CanExecuteScriptEverywhere() const; | |
| 326 | |
| 327 // Returns true if this extension is allowed to obtain the contents of a | |
| 328 // page as an image. Since a page may contain sensitive information, this | |
| 329 // is restricted to the extension's host permissions as well as the | |
| 330 // extension page itself. | |
| 331 bool CanCaptureVisiblePage(const GURL& page_url, | |
| 332 int tab_id, | |
| 333 std::string* error) const; | |
| 334 | |
| 335 // Returns true if this extension updates itself using the extension | 262 // Returns true if this extension updates itself using the extension |
| 336 // gallery. | 263 // gallery. |
| 337 bool UpdatesFromGallery() const; | 264 bool UpdatesFromGallery() const; |
| 338 | 265 |
| 339 // Returns true if this extension or app includes areas within |origin|. | 266 // Returns true if this extension or app includes areas within |origin|. |
| 340 bool OverlapsWithOrigin(const GURL& origin) const; | 267 bool OverlapsWithOrigin(const GURL& origin) const; |
| 341 | 268 |
| 342 // Returns the sync bucket to use for this extension. | 269 // Returns the sync bucket to use for this extension. |
| 343 SyncType GetSyncType() const; | 270 SyncType GetSyncType() const; |
| 344 | 271 |
| 345 // Returns true if the extension should be synced. | 272 // Returns true if the extension should be synced. |
| 346 bool IsSyncable() const; | 273 bool IsSyncable() const; |
| 347 | 274 |
| 348 // Returns true if the extension requires a valid ordinal for sorting, e.g., | 275 // Returns true if the extension requires a valid ordinal for sorting, e.g., |
| 349 // for displaying in a launcher or new tab page. | 276 // for displaying in a launcher or new tab page. |
| 350 bool RequiresSortOrdinal() const; | 277 bool RequiresSortOrdinal() const; |
| 351 | 278 |
| 352 // Returns true if the extension should be displayed in the app launcher. | 279 // Returns true if the extension should be displayed in the app launcher. |
| 353 bool ShouldDisplayInAppLauncher() const; | 280 bool ShouldDisplayInAppLauncher() const; |
| 354 | 281 |
| 355 // Returns true if the extension should be displayed in the browser NTP. | 282 // Returns true if the extension should be displayed in the browser NTP. |
| 356 bool ShouldDisplayInNewTabPage() const; | 283 bool ShouldDisplayInNewTabPage() const; |
| 357 | 284 |
| 358 // Returns true if the extension should be displayed in the extension | 285 // Returns true if the extension should be displayed in the extension |
| 359 // settings page (i.e. chrome://extensions). | 286 // settings page (i.e. chrome://extensions). |
| 360 bool ShouldDisplayInExtensionSettings() const; | 287 bool ShouldDisplayInExtensionSettings() const; |
| 361 | 288 |
| 362 // Gets the tab-specific host permissions of |tab_id|, or NULL if there | |
| 363 // aren't any. | |
| 364 scoped_refptr<const PermissionSet> GetTabSpecificPermissions(int tab_id) | |
| 365 const; | |
| 366 | |
| 367 // Updates the tab-specific permissions of |tab_id| to include those from | |
| 368 // |permissions|. | |
| 369 void UpdateTabSpecificPermissions( | |
| 370 int tab_id, | |
| 371 scoped_refptr<const PermissionSet> permissions) const; | |
| 372 | |
| 373 // Clears the tab-specific permissions of |tab_id|. | |
| 374 void ClearTabSpecificPermissions(int tab_id) const; | |
| 375 | |
| 376 // Get the manifest data associated with the key, or NULL if there is none. | 289 // Get the manifest data associated with the key, or NULL if there is none. |
| 377 // Can only be called after InitValue is finished. | 290 // Can only be called after InitValue is finished. |
| 378 ManifestData* GetManifestData(const std::string& key) const; | 291 ManifestData* GetManifestData(const std::string& key) const; |
| 379 | 292 |
| 380 // Sets |data| to be associated with the key. Takes ownership of |data|. | 293 // Sets |data| to be associated with the key. Takes ownership of |data|. |
| 381 // Can only be called before InitValue is finished. Not thread-safe; | 294 // Can only be called before InitValue is finished. Not thread-safe; |
| 382 // all SetManifestData calls should be on only one thread. | 295 // all SetManifestData calls should be on only one thread. |
| 383 void SetManifestData(const std::string& key, ManifestData* data); | 296 void SetManifestData(const std::string& key, ManifestData* data); |
| 384 | 297 |
| 385 // Accessors: | 298 // Accessors: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 } | 361 } |
| 449 int launch_width() const { return launch_width_; } | 362 int launch_width() const { return launch_width_; } |
| 450 int launch_height() const { return launch_height_; } | 363 int launch_height() const { return launch_height_; } |
| 451 | 364 |
| 452 // Theme-related. | 365 // Theme-related. |
| 453 bool is_theme() const; | 366 bool is_theme() const; |
| 454 | 367 |
| 455 private: | 368 private: |
| 456 friend class base::RefCountedThreadSafe<Extension>; | 369 friend class base::RefCountedThreadSafe<Extension>; |
| 457 | 370 |
| 458 class RuntimeData { | |
| 459 public: | |
| 460 RuntimeData(); | |
| 461 explicit RuntimeData(const PermissionSet* active); | |
| 462 ~RuntimeData(); | |
| 463 | |
| 464 void SetActivePermissions(const PermissionSet* active); | |
| 465 scoped_refptr<const PermissionSet> GetActivePermissions() const; | |
| 466 | |
| 467 scoped_refptr<const PermissionSet> GetTabSpecificPermissions(int tab_id) | |
| 468 const; | |
| 469 void UpdateTabSpecificPermissions( | |
| 470 int tab_id, | |
| 471 scoped_refptr<const PermissionSet> permissions); | |
| 472 void ClearTabSpecificPermissions(int tab_id); | |
| 473 | |
| 474 private: | |
| 475 friend class base::RefCountedThreadSafe<RuntimeData>; | |
| 476 | |
| 477 scoped_refptr<const PermissionSet> active_permissions_; | |
| 478 | |
| 479 typedef std::map<int, scoped_refptr<const PermissionSet> > | |
| 480 TabPermissionsMap; | |
| 481 TabPermissionsMap tab_specific_permissions_; | |
| 482 }; | |
| 483 | |
| 484 // Chooses the extension ID for an extension based on a variety of criteria. | 371 // Chooses the extension ID for an extension based on a variety of criteria. |
| 485 // The chosen ID will be set in |manifest|. | 372 // The chosen ID will be set in |manifest|. |
| 486 static bool InitExtensionID(extensions::Manifest* manifest, | 373 static bool InitExtensionID(extensions::Manifest* manifest, |
| 487 const base::FilePath& path, | 374 const base::FilePath& path, |
| 488 const std::string& explicit_id, | 375 const std::string& explicit_id, |
| 489 int creation_flags, | 376 int creation_flags, |
| 490 string16* error); | 377 string16* error); |
| 491 | 378 |
| 492 // Returns true if this extension id is from a trusted provider. | |
| 493 static bool IsTrustedId(const std::string& id); | |
| 494 | |
| 495 Extension(const base::FilePath& path, | 379 Extension(const base::FilePath& path, |
| 496 scoped_ptr<extensions::Manifest> manifest); | 380 scoped_ptr<extensions::Manifest> manifest); |
| 497 virtual ~Extension(); | 381 virtual ~Extension(); |
| 498 | 382 |
| 499 // Initialize the extension from a parsed manifest. | 383 // Initialize the extension from a parsed manifest. |
| 500 // TODO(aa): Rename to just Init()? There's no Value here anymore. | 384 // TODO(aa): Rename to just Init()? There's no Value here anymore. |
| 501 // TODO(aa): It is really weird the way this class essentially contains a copy | 385 // TODO(aa): It is really weird the way this class essentially contains a copy |
| 502 // of the underlying DictionaryValue in its members. We should decide to | 386 // of the underlying DictionaryValue in its members. We should decide to |
| 503 // either wrap the DictionaryValue and go with that only, or we should parse | 387 // either wrap the DictionaryValue and go with that only, or we should parse |
| 504 // into strong types and discard the value. But doing both is bad. | 388 // into strong types and discard the value. But doing both is bad. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 // this member variable to 0 to distinguish the "uninitialized" case from | 444 // this member variable to 0 to distinguish the "uninitialized" case from |
| 561 // the case when we know the manifest version actually is 1. | 445 // the case when we know the manifest version actually is 1. |
| 562 int manifest_version_; | 446 int manifest_version_; |
| 563 | 447 |
| 564 // The absolute path to the directory the extension is stored in. | 448 // The absolute path to the directory the extension is stored in. |
| 565 base::FilePath path_; | 449 base::FilePath path_; |
| 566 | 450 |
| 567 // Defines the set of URLs in the extension's web content. | 451 // Defines the set of URLs in the extension's web content. |
| 568 URLPatternSet extent_; | 452 URLPatternSet extent_; |
| 569 | 453 |
| 570 // The extension runtime data. | |
| 571 mutable base::Lock runtime_data_lock_; | |
| 572 mutable RuntimeData runtime_data_; | |
| 573 | |
| 574 scoped_ptr<PermissionsData> permissions_data_; | 454 scoped_ptr<PermissionsData> permissions_data_; |
| 575 | 455 |
| 576 // Any warnings that occurred when trying to create/parse the extension. | 456 // Any warnings that occurred when trying to create/parse the extension. |
| 577 std::vector<InstallWarning> install_warnings_; | 457 std::vector<InstallWarning> install_warnings_; |
| 578 | 458 |
| 579 // The base extension url for the extension. | 459 // The base extension url for the extension. |
| 580 GURL extension_url_; | 460 GURL extension_url_; |
| 581 | 461 |
| 582 // The extension's version. | 462 // The extension's version. |
| 583 scoped_ptr<base::Version> version_; | 463 scoped_ptr<base::Version> version_; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 | 589 |
| 710 UpdatedExtensionPermissionsInfo( | 590 UpdatedExtensionPermissionsInfo( |
| 711 const Extension* extension, | 591 const Extension* extension, |
| 712 const PermissionSet* permissions, | 592 const PermissionSet* permissions, |
| 713 Reason reason); | 593 Reason reason); |
| 714 }; | 594 }; |
| 715 | 595 |
| 716 } // namespace extensions | 596 } // namespace extensions |
| 717 | 597 |
| 718 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 598 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
| OLD | NEW |