| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 // error checking. Strict error checks may flag errors older versions | 273 // error checking. Strict error checks may flag errors older versions |
| 269 // of chrome did not detect. To avoid breaking installed extensions, | 274 // of chrome did not detect. To avoid breaking installed extensions, |
| 270 // strict checks are disabled unless the location indicates that the | 275 // strict checks are disabled unless the location indicates that the |
| 271 // developer is loading the extension, or the extension is a component | 276 // developer is loading the extension, or the extension is a component |
| 272 // of chrome. | 277 // of chrome. |
| 273 static inline bool ShouldDoStrictErrorChecking(Location location) { | 278 static inline bool ShouldDoStrictErrorChecking(Location location) { |
| 274 return location == Extension::LOAD || | 279 return location == Extension::LOAD || |
| 275 location == Extension::COMPONENT; | 280 location == Extension::COMPONENT; |
| 276 } | 281 } |
| 277 | 282 |
| 283 // Unpacked extensions start off with file access since they are a developer |
| 284 // feature. |
| 285 static inline bool ShouldAlwaysAllowFileAccess(Location location) { |
| 286 return location == Extension::LOAD; |
| 287 } |
| 288 |
| 278 // See Type definition above. | 289 // See Type definition above. |
| 279 Type GetType() const; | 290 Type GetType() const; |
| 280 | 291 |
| 281 // Returns an absolute url to a resource inside of an extension. The | 292 // Returns an absolute url to a resource inside of an extension. The |
| 282 // |extension_url| argument should be the url() from an Extension object. The | 293 // |extension_url| argument should be the url() from an Extension object. The |
| 283 // |relative_path| can be untrusted user input. The returned URL will either | 294 // |relative_path| can be untrusted user input. The returned URL will either |
| 284 // be invalid() or a child of |extension_url|. | 295 // be invalid() or a child of |extension_url|. |
| 285 // NOTE: Static so that it can be used from multiple threads. | 296 // NOTE: Static so that it can be used from multiple threads. |
| 286 static GURL GetResourceURL(const GURL& extension_url, | 297 static GURL GetResourceURL(const GURL& extension_url, |
| 287 const std::string& relative_path); | 298 const std::string& relative_path); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 const gfx::Size& max_size) const; | 436 const gfx::Size& max_size) const; |
| 426 | 437 |
| 427 // Returns true if this extension can execute script on a page. If a | 438 // Returns true if this extension can execute script on a page. If a |
| 428 // UserScript object is passed, permission to run that specific script is | 439 // UserScript object is passed, permission to run that specific script is |
| 429 // checked (using its matches list). Otherwise, permission to execute script | 440 // checked (using its matches list). Otherwise, permission to execute script |
| 430 // programmatically is checked (using the extension's host permission). | 441 // programmatically is checked (using the extension's host permission). |
| 431 // | 442 // |
| 432 // This method is also aware of certain special pages that extensions are | 443 // This method is also aware of certain special pages that extensions are |
| 433 // usually not allowed to run script on. | 444 // usually not allowed to run script on. |
| 434 bool CanExecuteScriptOnPage(const GURL& page_url, | 445 bool CanExecuteScriptOnPage(const GURL& page_url, |
| 435 UserScript* script, | 446 const UserScript* script, |
| 436 std::string* error) const; | 447 std::string* error) const; |
| 437 | 448 |
| 438 // Returns true if this extension is a COMPONENT extension, or if it is | 449 // Returns true if this extension is a COMPONENT extension, or if it is |
| 439 // on the whitelist of extensions that can script all pages. | 450 // on the whitelist of extensions that can script all pages. |
| 440 bool CanExecuteScriptEverywhere() const; | 451 bool CanExecuteScriptEverywhere() const; |
| 441 | 452 |
| 442 // Returns true if this extension is allowed to obtain the contents of a | 453 // Returns true if this extension is allowed to obtain the contents of a |
| 443 // page as an image. Since a page may contain sensitive information, this | 454 // page as an image. Since a page may contain sensitive information, this |
| 444 // is restricted to the extension's host permissions as well as the | 455 // is restricted to the extension's host permissions as well as the |
| 445 // extension page itself. | 456 // extension page itself. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 return manifest_value_.get(); | 498 return manifest_value_.get(); |
| 488 } | 499 } |
| 489 const std::string default_locale() const { return default_locale_; } | 500 const std::string default_locale() const { return default_locale_; } |
| 490 const URLOverrideMap& GetChromeURLOverrides() const { | 501 const URLOverrideMap& GetChromeURLOverrides() const { |
| 491 return chrome_url_overrides_; | 502 return chrome_url_overrides_; |
| 492 } | 503 } |
| 493 const std::string omnibox_keyword() const { return omnibox_keyword_; } | 504 const std::string omnibox_keyword() const { return omnibox_keyword_; } |
| 494 bool incognito_split_mode() const { return incognito_split_mode_; } | 505 bool incognito_split_mode() const { return incognito_split_mode_; } |
| 495 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; } | 506 const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; } |
| 496 | 507 |
| 508 bool wants_file_access() const { return wants_file_access_; } |
| 509 |
| 497 // App-related. | 510 // App-related. |
| 498 bool is_app() const { return is_app_; } | 511 bool is_app() const { return is_app_; } |
| 499 bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); } | 512 bool is_hosted_app() const { return is_app() && !web_extent().is_empty(); } |
| 500 bool is_packaged_app() const { return is_app() && web_extent().is_empty(); } | 513 bool is_packaged_app() const { return is_app() && web_extent().is_empty(); } |
| 501 bool is_storage_isolated() const { return is_app() && is_storage_isolated_; } | 514 bool is_storage_isolated() const { return is_app() && is_storage_isolated_; } |
| 502 const ExtensionExtent& web_extent() const { return extent_; } | 515 const ExtensionExtent& web_extent() const { return extent_; } |
| 503 const std::string& launch_local_path() const { return launch_local_path_; } | 516 const std::string& launch_local_path() const { return launch_local_path_; } |
| 504 const std::string& launch_web_url() const { return launch_web_url_; } | 517 const std::string& launch_web_url() const { return launch_web_url_; } |
| 505 extension_misc::LaunchContainer launch_container() const { | 518 extension_misc::LaunchContainer launch_container() const { |
| 506 return launch_container_; | 519 return launch_container_; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 // Helper function for implementing HasCachedImage/GetCachedImage. A return | 569 // Helper function for implementing HasCachedImage/GetCachedImage. A return |
| 557 // value of NULL means there is no matching image cached (we allow caching an | 570 // value of NULL means there is no matching image cached (we allow caching an |
| 558 // empty SkBitmap). | 571 // empty SkBitmap). |
| 559 SkBitmap* GetCachedImageImpl(const ExtensionResource& source, | 572 SkBitmap* GetCachedImageImpl(const ExtensionResource& source, |
| 560 const gfx::Size& max_size) const; | 573 const gfx::Size& max_size) const; |
| 561 | 574 |
| 562 // Helper method that loads a UserScript object from a | 575 // Helper method that loads a UserScript object from a |
| 563 // dictionary in the content_script list of the manifest. | 576 // dictionary in the content_script list of the manifest. |
| 564 bool LoadUserScriptHelper(const DictionaryValue* content_script, | 577 bool LoadUserScriptHelper(const DictionaryValue* content_script, |
| 565 int definition_index, | 578 int definition_index, |
| 566 URLPattern::ParseOption parse_strictness, | 579 int flags, |
| 567 std::string* error, | 580 std::string* error, |
| 568 UserScript* result); | 581 UserScript* result); |
| 569 | 582 |
| 570 // Helper method that loads either the include_globs or exclude_globs list | 583 // Helper method that loads either the include_globs or exclude_globs list |
| 571 // from an entry in the content_script lists of the manifest. | 584 // from an entry in the content_script lists of the manifest. |
| 572 bool LoadGlobsHelper(const DictionaryValue* content_script, | 585 bool LoadGlobsHelper(const DictionaryValue* content_script, |
| 573 int content_script_index, | 586 int content_script_index, |
| 574 const char* globs_property_name, | 587 const char* globs_property_name, |
| 575 std::string* error, | 588 std::string* error, |
| 576 void(UserScript::*add_method)(const std::string& glob), | 589 void(UserScript::*add_method)(const std::string& glob), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 593 // Helper method to load an ExtensionAction from the page_action or | 606 // Helper method to load an ExtensionAction from the page_action or |
| 594 // browser_action entries in the manifest. | 607 // browser_action entries in the manifest. |
| 595 ExtensionAction* LoadExtensionActionHelper( | 608 ExtensionAction* LoadExtensionActionHelper( |
| 596 const DictionaryValue* extension_action, std::string* error); | 609 const DictionaryValue* extension_action, std::string* error); |
| 597 | 610 |
| 598 // Helper method to load an ExtensionSidebarDefaults from the sidebar manifest | 611 // Helper method to load an ExtensionSidebarDefaults from the sidebar manifest |
| 599 // entry. | 612 // entry. |
| 600 ExtensionSidebarDefaults* LoadExtensionSidebarDefaults( | 613 ExtensionSidebarDefaults* LoadExtensionSidebarDefaults( |
| 601 const DictionaryValue* sidebar, std::string* error); | 614 const DictionaryValue* sidebar, std::string* error); |
| 602 | 615 |
| 616 void InitWantsFileAccess(const std::string& host_str, |
| 617 URLPattern::ParseOption parse_strictness); |
| 618 |
| 603 // Calculates the effective host permissions from the permissions and content | 619 // Calculates the effective host permissions from the permissions and content |
| 604 // script petterns. | 620 // script petterns. |
| 605 void InitEffectiveHostPermissions(); | 621 void InitEffectiveHostPermissions(); |
| 606 | 622 |
| 607 // Returns true if the extension has more than one "UI surface". For example, | 623 // Returns true if the extension has more than one "UI surface". For example, |
| 608 // an extension that has a browser action and a page action. | 624 // an extension that has a browser action and a page action. |
| 609 bool HasMultipleUISurfaces() const; | 625 bool HasMultipleUISurfaces() const; |
| 610 | 626 |
| 611 // Figures out if a source contains keys not associated with themes - we | 627 // Figures out if a source contains keys not associated with themes - we |
| 612 // don't want to allow scripts and such to be bundled with themes. | 628 // don't want to allow scripts and such to be bundled with themes. |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 // containers like panels and windows. | 787 // containers like panels and windows. |
| 772 int launch_width_; | 788 int launch_width_; |
| 773 int launch_height_; | 789 int launch_height_; |
| 774 | 790 |
| 775 // The Omnibox keyword for this extension, or empty if there is none. | 791 // The Omnibox keyword for this extension, or empty if there is none. |
| 776 std::string omnibox_keyword_; | 792 std::string omnibox_keyword_; |
| 777 | 793 |
| 778 // List of text-to-speech voices that this extension provides, if any. | 794 // List of text-to-speech voices that this extension provides, if any. |
| 779 std::vector<TtsVoice> tts_voices_; | 795 std::vector<TtsVoice> tts_voices_; |
| 780 | 796 |
| 797 // Whether the extension has host permissions or user script patterns that |
| 798 // imply access to file:/// scheme URLs (the user may not have actually |
| 799 // granted it that access). |
| 800 bool wants_file_access_; |
| 801 |
| 781 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, | 802 FRIEND_TEST_ALL_PREFIXES(ExtensionServiceTest, |
| 782 UpdateExtensionPreservesLocation); | 803 UpdateExtensionPreservesLocation); |
| 783 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper); | 804 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, LoadPageActionHelper); |
| 784 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueInvalid); | 805 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueInvalid); |
| 785 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValid); | 806 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValid); |
| 786 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValidNameInRTL); | 807 FRIEND_TEST_ALL_PREFIXES(ExtensionTest, InitFromValueValidNameInRTL); |
| 787 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps); | 808 FRIEND_TEST_ALL_PREFIXES(TabStripModelTest, Apps); |
| 788 | 809 |
| 789 DISALLOW_COPY_AND_ASSIGN(Extension); | 810 DISALLOW_COPY_AND_ASSIGN(Extension); |
| 790 }; | 811 }; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 // Was the extension already disabled? | 854 // Was the extension already disabled? |
| 834 bool already_disabled; | 855 bool already_disabled; |
| 835 | 856 |
| 836 // The extension being unloaded - this should always be non-NULL. | 857 // The extension being unloaded - this should always be non-NULL. |
| 837 const Extension* extension; | 858 const Extension* extension; |
| 838 | 859 |
| 839 UnloadedExtensionInfo(const Extension* extension, Reason reason); | 860 UnloadedExtensionInfo(const Extension* extension, Reason reason); |
| 840 }; | 861 }; |
| 841 | 862 |
| 842 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 863 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
| OLD | NEW |