| OLD | NEW |
| 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> |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // checks that URL patterns do not contain ports. This error | 126 // checks that URL patterns do not contain ports. This error |
| 127 // checking may find an error that a previous version of | 127 // checking may find an error that a previous version of |
| 128 // Chrome did not flag. To avoid errors in installed extensions | 128 // Chrome did not flag. To avoid errors in installed extensions |
| 129 // when Chrome is upgraded, strict error checking is only enabled | 129 // when Chrome is upgraded, strict error checking is only enabled |
| 130 // when loading extensions as a developer would (such as loading | 130 // when loading extensions as a developer would (such as loading |
| 131 // an unpacked extension), or when loading an extension that is | 131 // an unpacked extension), or when loading an extension that is |
| 132 // tied to a specific version of Chrome (such as a component | 132 // tied to a specific version of Chrome (such as a component |
| 133 // extension). Most callers will set the |STRICT_ERROR_CHECKS| bit when | 133 // extension). Most callers will set the |STRICT_ERROR_CHECKS| bit when |
| 134 // Extension::ShouldDoStrictErrorChecking(location) returns true. | 134 // Extension::ShouldDoStrictErrorChecking(location) returns true. |
| 135 STRICT_ERROR_CHECKS = 1 << 1, | 135 STRICT_ERROR_CHECKS = 1 << 1, |
| 136 |
| 137 // |ALLOW_FILE_ACCESS| indicates that the user is allowing this extension |
| 138 // to have file access. If it's not present, then permissions and content |
| 139 // scripts that match file:/// URLs will be filtered out. |
| 140 ALLOW_FILE_ACCESS = 1 << 2, |
| 136 }; | 141 }; |
| 137 | 142 |
| 138 static scoped_refptr<Extension> Create(const FilePath& path, | 143 static scoped_refptr<Extension> Create(const FilePath& path, |
| 139 Location location, | 144 Location location, |
| 140 const DictionaryValue& value, | 145 const DictionaryValue& value, |
| 141 int flags, | 146 int flags, |
| 142 std::string* error); | 147 std::string* error); |
| 143 | 148 |
| 144 // Return the update url used by gallery/webstore extensions. | 149 // Return the update url used by gallery/webstore extensions. |
| 145 static GURL GalleryUpdateUrl(bool secure); | 150 static GURL GalleryUpdateUrl(bool secure); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // error checking. Strict error checks may flag errors older versions | 281 // error checking. Strict error checks may flag errors older versions |
| 277 // of chrome did not detect. To avoid breaking installed extensions, | 282 // of chrome did not detect. To avoid breaking installed extensions, |
| 278 // strict checks are disabled unless the location indicates that the | 283 // strict checks are disabled unless the location indicates that the |
| 279 // developer is loading the extension, or the extension is a component | 284 // developer is loading the extension, or the extension is a component |
| 280 // of chrome. | 285 // of chrome. |
| 281 static inline bool ShouldDoStrictErrorChecking(Location location) { | 286 static inline bool ShouldDoStrictErrorChecking(Location location) { |
| 282 return location == Extension::LOAD || | 287 return location == Extension::LOAD || |
| 283 location == Extension::COMPONENT; | 288 location == Extension::COMPONENT; |
| 284 } | 289 } |
| 285 | 290 |
| 291 // Unpacked extensions start off with file access since they are a developer |
| 292 // feature. |
| 293 static inline bool ShouldAlwaysAllowFileAccess(Location location) { |
| 294 return location == Extension::LOAD; |
| 295 } |
| 296 |
| 286 // See Type definition above. | 297 // See Type definition above. |
| 287 Type GetType() const; | 298 Type GetType() const; |
| 288 | 299 |
| 289 // Returns an absolute url to a resource inside of an extension. The | 300 // Returns an absolute url to a resource inside of an extension. The |
| 290 // |extension_url| argument should be the url() from an Extension object. The | 301 // |extension_url| argument should be the url() from an Extension object. The |
| 291 // |relative_path| can be untrusted user input. The returned URL will either | 302 // |relative_path| can be untrusted user input. The returned URL will either |
| 292 // be invalid() or a child of |extension_url|. | 303 // be invalid() or a child of |extension_url|. |
| 293 // NOTE: Static so that it can be used from multiple threads. | 304 // NOTE: Static so that it can be used from multiple threads. |
| 294 static GURL GetResourceURL(const GURL& extension_url, | 305 static GURL GetResourceURL(const GURL& extension_url, |
| 295 const std::string& relative_path); | 306 const std::string& relative_path); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 const gfx::Size& max_size) const; | 444 const gfx::Size& max_size) const; |
| 434 | 445 |
| 435 // Returns true if this extension can execute script on a page. If a | 446 // Returns true if this extension can execute script on a page. If a |
| 436 // UserScript object is passed, permission to run that specific script is | 447 // UserScript object is passed, permission to run that specific script is |
| 437 // checked (using its matches list). Otherwise, permission to execute script | 448 // checked (using its matches list). Otherwise, permission to execute script |
| 438 // programmatically is checked (using the extension's host permission). | 449 // programmatically is checked (using the extension's host permission). |
| 439 // | 450 // |
| 440 // This method is also aware of certain special pages that extensions are | 451 // This method is also aware of certain special pages that extensions are |
| 441 // usually not allowed to run script on. | 452 // usually not allowed to run script on. |
| 442 bool CanExecuteScriptOnPage(const GURL& page_url, | 453 bool CanExecuteScriptOnPage(const GURL& page_url, |
| 443 UserScript* script, | 454 const UserScript* script, |
| 444 std::string* error) const; | 455 std::string* error) const; |
| 445 | 456 |
| 446 // Returns true if this extension is a COMPONENT extension, or if it is | 457 // Returns true if this extension is a COMPONENT extension, or if it is |
| 447 // on the whitelist of extensions that can script all pages. | 458 // on the whitelist of extensions that can script all pages. |
| 448 bool CanExecuteScriptEverywhere() const; | 459 bool CanExecuteScriptEverywhere() const; |
| 449 | 460 |
| 450 // Returns true if this extension is allowed to obtain the contents of a | 461 // Returns true if this extension is allowed to obtain the contents of a |
| 451 // page as an image. Since a page may contain sensitive information, this | 462 // page as an image. Since a page may contain sensitive information, this |
| 452 // is restricted to the extension's host permissions as well as the | 463 // is restricted to the extension's host permissions as well as the |
| 453 // extension page itself. | 464 // extension page itself. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 return manifest_value_.get(); | 506 return manifest_value_.get(); |
| 496 } | 507 } |
| 497 const std::string default_locale() const { return default_locale_; } | 508 const std::string default_locale() const { return default_locale_; } |
| 498 const URLOverrideMap& GetChromeURLOverrides() const { | 509 const URLOverrideMap& GetChromeURLOverrides() const { |
| 499 return chrome_url_overrides_; | 510 return chrome_url_overrides_; |
| 500 } | 511 } |
| 501 const std::string omnibox_keyword() const { return omnibox_keyword_; } | 512 const std::string omnibox_keyword() const { return omnibox_keyword_; } |
| 502 bool incognito_split_mode() const { return incognito_split_mode_; } | 513 bool incognito_split_mode() const { return incognito_split_mode_; } |
| 503 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; } | 514 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; } |
| 504 | 515 |
| 516 bool wants_file_access() const { return wants_file_access_; } |
| 517 |
| 505 // App-related. | 518 // App-related. |
| 506 bool is_app() const { return is_app_; } | 519 bool is_app() const { return is_app_; } |
| 507 bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); } | 520 bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); } |
| 508 bool is_packaged_app() const { return is_app() && web_extent().is_empty(); } | 521 bool is_packaged_app() const { return is_app() && web_extent().is_empty(); } |
| 509 bool is_storage_isolated() const { return is_app() && is_storage_isolated_; } | 522 bool is_storage_isolated() const { return is_app() && is_storage_isolated_; } |
| 510 const ExtensionExtent& web_extent() const { return extent_; } | 523 const ExtensionExtent& web_extent() const { return extent_; } |
| 511 const std::string& launch_local_path() const { return launch_local_path_; } | 524 const std::string& launch_local_path() const { return launch_local_path_; } |
| 512 const std::string& launch_web_url() const { return launch_web_url_; } | 525 const std::string& launch_web_url() const { return launch_web_url_; } |
| 513 extension_misc::LaunchContainer launch_container() const { | 526 extension_misc::LaunchContainer launch_container() const { |
| 514 return launch_container_; | 527 return launch_container_; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 // Helper function for implementing HasCachedImage/GetCachedImage. A return | 577 // Helper function for implementing HasCachedImage/GetCachedImage. A return |
| 565 // value of NULL means there is no matching image cached (we allow caching an | 578 // value of NULL means there is no matching image cached (we allow caching an |
| 566 // empty SkBitmap). | 579 // empty SkBitmap). |
| 567 SkBitmap* GetCachedImageImpl(const ExtensionResource& source, | 580 SkBitmap* GetCachedImageImpl(const ExtensionResource& source, |
| 568 const gfx::Size& max_size) const; | 581 const gfx::Size& max_size) const; |
| 569 | 582 |
| 570 // Helper method that loads a UserScript object from a | 583 // Helper method that loads a UserScript object from a |
| 571 // dictionary in the content_script list of the manifest. | 584 // dictionary in the content_script list of the manifest. |
| 572 bool LoadUserScriptHelper(const DictionaryValue* content_script, | 585 bool LoadUserScriptHelper(const DictionaryValue* content_script, |
| 573 int definition_index, | 586 int definition_index, |
| 574 URLPattern::ParseOption parse_strictness, | 587 int flags, |
| 575 std::string* error, | 588 std::string* error, |
| 576 UserScript* result); | 589 UserScript* result); |
| 577 | 590 |
| 578 // Helper method that loads either the include_globs or exclude_globs list | 591 // Helper method that loads either the include_globs or exclude_globs list |
| 579 // from an entry in the content_script lists of the manifest. | 592 // from an entry in the content_script lists of the manifest. |
| 580 bool LoadGlobsHelper(const DictionaryValue* content_script, | 593 bool LoadGlobsHelper(const DictionaryValue* content_script, |
| 581 int content_script_index, | 594 int content_script_index, |
| 582 const char* globs_property_name, | 595 const char* globs_property_name, |
| 583 std::string* error, | 596 std::string* error, |
| 584 void(UserScript::*add_method)(const std::string& glob), | 597 void(UserScript::*add_method)(const std::string& glob), |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 // containers like panels and windows. | 792 // containers like panels and windows. |
| 780 int launch_width_; | 793 int launch_width_; |
| 781 int launch_height_; | 794 int launch_height_; |
| 782 | 795 |
| 783 // The Omnibox keyword for this extension, or empty if there is none. | 796 // The Omnibox keyword for this extension, or empty if there is none. |
| 784 std::string omnibox_keyword_; | 797 std::string omnibox_keyword_; |
| 785 | 798 |
| 786 // List of text-to-speech voices that this extension provides, if any. | 799 // List of text-to-speech voices that this extension provides, if any. |
| 787 std::vector<TtsVoice> tts_voices_; | 800 std::vector<TtsVoice> tts_voices_; |
| 788 | 801 |
| 802 // Whether the extension has host permissions or user script patterns that |
| 803 // imply access to file:/// scheme URLs (the user may not have actually |
| 804 // granted it that access). |
| 805 bool wants_file_access_; |
| 806 |
| 789 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 807 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 790 UpdateExtensionPreservesLocation); | 808 UpdateExtensionPreservesLocation); |
| 791 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper); | 809 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper); |
| 792 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueInvalid); | 810 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueInvalid); |
| 793 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValid); | 811 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValid); |
| 794 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValidNameInRTL); | 812 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValidNameInRTL); |
| 795 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps); | 813 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps); |
| 796 | 814 |
| 797 DISALLOW_COPY_AND_ASSIGN(Extension); | 815 DISALLOW_COPY_AND_ASSIGN(Extension); |
| 798 }; | 816 }; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 // Was the extension already disabled? | 859 // Was the extension already disabled? |
| 842 bool already_disabled; | 860 bool already_disabled; |
| 843 | 861 |
| 844 // The extension being unloaded - this should always be non-NULL. | 862 // The extension being unloaded - this should always be non-NULL. |
| 845 const Extension* extension; | 863 const Extension* extension; |
| 846 | 864 |
| 847 UnloadedExtensionInfo(const Extension* extension, Reason reason); | 865 UnloadedExtensionInfo(const Extension* extension, Reason reason); |
| 848 }; | 866 }; |
| 849 | 867 |
| 850 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 868 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
| OLD | NEW |