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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 287 |
288 // Expects base64 encoded |input| and formats into |output| including | 288 // Expects base64 encoded |input| and formats into |output| including |
289 // the appropriate header & footer. | 289 // the appropriate header & footer. |
290 static bool FormatPEMForFileOutput(const std::string& input, | 290 static bool FormatPEMForFileOutput(const std::string& input, |
291 std::string* output, | 291 std::string* output, |
292 bool is_public); | 292 bool is_public); |
293 | 293 |
294 // Given an extension, icon size, and match type, read a valid icon if present | 294 // Given an extension, icon size, and match type, read a valid icon if present |
295 // and decode it into result. In the browser process, this will DCHECK if not | 295 // and decode it into result. In the browser process, this will DCHECK if not |
296 // called on the file thread. To easily load extension images on the UI | 296 // called on the file thread. To easily load extension images on the UI |
297 // thread, see ImageLoadingTracker. | 297 // thread, see ImageLoader. |
298 static void DecodeIcon(const Extension* extension, | 298 static void DecodeIcon(const Extension* extension, |
299 int icon_size, | 299 int icon_size, |
300 ExtensionIconSet::MatchType match_type, | 300 ExtensionIconSet::MatchType match_type, |
301 scoped_ptr<SkBitmap>* result); | 301 scoped_ptr<SkBitmap>* result); |
302 | 302 |
303 // Given an extension and icon size, read it if present and decode it into | 303 // Given an extension and icon size, read it if present and decode it into |
304 // result. In the browser process, this will DCHECK if not called on the | 304 // result. In the browser process, this will DCHECK if not called on the |
305 // file thread. To easily load extension images on the UI thread, see | 305 // file thread. To easily load extension images on the UI thread, see |
306 // ImageLoadingTracker. | 306 // ImageLoader. |
307 static void DecodeIcon(const Extension* extension, | 307 static void DecodeIcon(const Extension* extension, |
308 int icon_size, | 308 int icon_size, |
309 scoped_ptr<SkBitmap>* result); | 309 scoped_ptr<SkBitmap>* result); |
310 | 310 |
311 // Given an icon_path and icon size, read it if present and decode it into | 311 // Given an icon_path and icon size, read it if present and decode it into |
312 // result. In the browser process, this will DCHECK if not called on the | 312 // result. In the browser process, this will DCHECK if not called on the |
313 // file thread. To easily load extension images on the UI thread, see | 313 // file thread. To easily load extension images on the UI thread, see |
314 // ImageLoadingTracker. | 314 // ImageLoader. |
315 static void DecodeIconFromPath(const base::FilePath& icon_path, | 315 static void DecodeIconFromPath(const base::FilePath& icon_path, |
316 int icon_size, | 316 int icon_size, |
317 scoped_ptr<SkBitmap>* result); | 317 scoped_ptr<SkBitmap>* result); |
318 | 318 |
319 // Returns the default extension/app icon (for extensions or apps that don't | 319 // Returns the default extension/app icon (for extensions or apps that don't |
320 // have one). | 320 // have one). |
321 static const gfx::ImageSkia& GetDefaultIcon(bool is_app); | 321 static const gfx::ImageSkia& GetDefaultIcon(bool is_app); |
322 | 322 |
323 // Returns the base extension url for a given |extension_id|. | 323 // Returns the base extension url for a given |extension_id|. |
324 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); | 324 static GURL GetBaseURLFromExtensionId(const std::string& extension_id); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 std::set<base::FilePath> GetBrowserImages() const; | 395 std::set<base::FilePath> GetBrowserImages() const; |
396 | 396 |
397 // Get an extension icon as a resource or URL. | 397 // Get an extension icon as a resource or URL. |
398 ExtensionResource GetIconResource( | 398 ExtensionResource GetIconResource( |
399 int size, ExtensionIconSet::MatchType match_type) const; | 399 int size, ExtensionIconSet::MatchType match_type) const; |
400 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const; | 400 GURL GetIconURL(int size, ExtensionIconSet::MatchType match_type) const; |
401 | 401 |
402 // Gets the fully resolved absolute launch URL. | 402 // Gets the fully resolved absolute launch URL. |
403 GURL GetFullLaunchURL() const; | 403 GURL GetFullLaunchURL() const; |
404 | 404 |
405 // Image cache related methods. These are only valid on the UI thread and | |
406 // not maintained by this class. See ImageLoadingTracker for usage. The | |
407 // |original_size| parameter should be the size of the image at |source| | |
408 // before any scaling may have been done to produce the pixels in |image|. | |
409 void SetCachedImage(const ExtensionResource& source, | |
410 const SkBitmap& image, | |
411 const gfx::Size& original_size) const; | |
412 bool HasCachedImage(const ExtensionResource& source, | |
413 const gfx::Size& max_size) const; | |
414 SkBitmap GetCachedImage(const ExtensionResource& source, | |
415 const gfx::Size& max_size) const; | |
416 | |
417 // Returns true if this extension can execute script on a page. If a | 405 // Returns true if this extension can execute script on a page. If a |
418 // UserScript object is passed, permission to run that specific script is | 406 // UserScript object is passed, permission to run that specific script is |
419 // checked (using its matches list). Otherwise, permission to execute script | 407 // checked (using its matches list). Otherwise, permission to execute script |
420 // programmatically is checked (using the extension's host permission). | 408 // programmatically is checked (using the extension's host permission). |
421 // | 409 // |
422 // This method is also aware of certain special pages that extensions are | 410 // This method is also aware of certain special pages that extensions are |
423 // usually not allowed to run script on. | 411 // usually not allowed to run script on. |
424 bool CanExecuteScriptOnPage(const GURL& document_url, | 412 bool CanExecuteScriptOnPage(const GURL& document_url, |
425 const GURL& top_document_url, | 413 const GURL& top_document_url, |
426 int tab_id, | 414 int tab_id, |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 | 580 |
593 // Content pack related. | 581 // Content pack related. |
594 bool is_content_pack() const; | 582 bool is_content_pack() const; |
595 ExtensionResource GetContentPackSiteList() const; | 583 ExtensionResource GetContentPackSiteList() const; |
596 | 584 |
597 GURL GetBackgroundURL() const; | 585 GURL GetBackgroundURL() const; |
598 | 586 |
599 private: | 587 private: |
600 friend class base::RefCountedThreadSafe<Extension>; | 588 friend class base::RefCountedThreadSafe<Extension>; |
601 | 589 |
602 // We keep a cache of images loaded from extension resources based on their | |
603 // path and a string representation of a size that may have been used to | |
604 // scale it (or the empty string if the image is at its original size). | |
605 typedef std::pair<base::FilePath, std::string> ImageCacheKey; | |
606 typedef std::map<ImageCacheKey, SkBitmap> ImageCache; | |
607 | |
608 class RuntimeData { | 590 class RuntimeData { |
609 public: | 591 public: |
610 RuntimeData(); | 592 RuntimeData(); |
611 explicit RuntimeData(const PermissionSet* active); | 593 explicit RuntimeData(const PermissionSet* active); |
612 ~RuntimeData(); | 594 ~RuntimeData(); |
613 | 595 |
614 void SetActivePermissions(const PermissionSet* active); | 596 void SetActivePermissions(const PermissionSet* active); |
615 scoped_refptr<const PermissionSet> GetActivePermissions() const; | 597 scoped_refptr<const PermissionSet> GetActivePermissions() const; |
616 | 598 |
617 scoped_refptr<const PermissionSet> GetTabSpecificPermissions(int tab_id) | 599 scoped_refptr<const PermissionSet> GetTabSpecificPermissions(int tab_id) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 bool LoadIncognitoMode(string16* error); | 693 bool LoadIncognitoMode(string16* error); |
712 bool LoadContentSecurityPolicy(string16* error); | 694 bool LoadContentSecurityPolicy(string16* error); |
713 bool LoadManagedModeFeatures(string16* error); | 695 bool LoadManagedModeFeatures(string16* error); |
714 bool LoadManagedModeSites( | 696 bool LoadManagedModeSites( |
715 const base::DictionaryValue* content_pack_value, | 697 const base::DictionaryValue* content_pack_value, |
716 string16* error); | 698 string16* error); |
717 bool LoadManagedModeConfigurations( | 699 bool LoadManagedModeConfigurations( |
718 const base::DictionaryValue* content_pack_value, | 700 const base::DictionaryValue* content_pack_value, |
719 string16* error); | 701 string16* error); |
720 | 702 |
721 // Helper function for implementing HasCachedImage/GetCachedImage. A return | |
722 // value of NULL means there is no matching image cached (we allow caching an | |
723 // empty SkBitmap). | |
724 SkBitmap* GetCachedImageImpl(const ExtensionResource& source, | |
725 const gfx::Size& max_size) const; | |
726 | |
727 // Helper method that loads a UserScript object from a | 703 // Helper method that loads a UserScript object from a |
728 // dictionary in the content_script list of the manifest. | 704 // dictionary in the content_script list of the manifest. |
729 bool LoadUserScriptHelper(const base::DictionaryValue* content_script, | 705 bool LoadUserScriptHelper(const base::DictionaryValue* content_script, |
730 int definition_index, | 706 int definition_index, |
731 string16* error, | 707 string16* error, |
732 UserScript* result); | 708 UserScript* result); |
733 | 709 |
734 // Helper method that loads either the include_globs or exclude_globs list | 710 // Helper method that loads either the include_globs or exclude_globs list |
735 // from an entry in the content_script lists of the manifest. | 711 // from an entry in the content_script lists of the manifest. |
736 bool LoadGlobsHelper(const base::DictionaryValue* content_script, | 712 bool LoadGlobsHelper(const base::DictionaryValue* content_script, |
(...skipping 21 matching lines...) Expand all Loading... |
758 const APIPermissionSet& permissions) const; | 734 const APIPermissionSet& permissions) const; |
759 | 735 |
760 bool CheckMinimumChromeVersion(string16* error) const; | 736 bool CheckMinimumChromeVersion(string16* error) const; |
761 | 737 |
762 // Check that platform app features are valid. Called after InitFromValue. | 738 // Check that platform app features are valid. Called after InitFromValue. |
763 bool CheckPlatformAppFeatures(std::string* utf8_error) const; | 739 bool CheckPlatformAppFeatures(std::string* utf8_error) const; |
764 | 740 |
765 // Check that features don't conflict. Called after InitFromValue. | 741 // Check that features don't conflict. Called after InitFromValue. |
766 bool CheckConflictingFeatures(std::string* utf8_error) const; | 742 bool CheckConflictingFeatures(std::string* utf8_error) const; |
767 | 743 |
768 // Cached images for this extension. This should only be touched on the UI | |
769 // thread. | |
770 mutable ImageCache image_cache_; | |
771 | |
772 // The extension's human-readable name. Name is used for display purpose. It | 744 // The extension's human-readable name. Name is used for display purpose. It |
773 // might be wrapped with unicode bidi control characters so that it is | 745 // might be wrapped with unicode bidi control characters so that it is |
774 // displayed correctly in RTL context. | 746 // displayed correctly in RTL context. |
775 // NOTE: Name is UTF-8 and may contain non-ascii characters. | 747 // NOTE: Name is UTF-8 and may contain non-ascii characters. |
776 std::string name_; | 748 std::string name_; |
777 | 749 |
778 // A non-localized version of the extension's name. This is useful for | 750 // A non-localized version of the extension's name. This is useful for |
779 // debug output. | 751 // debug output. |
780 std::string non_localized_name_; | 752 std::string non_localized_name_; |
781 | 753 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 | 967 |
996 UpdatedExtensionPermissionsInfo( | 968 UpdatedExtensionPermissionsInfo( |
997 const Extension* extension, | 969 const Extension* extension, |
998 const PermissionSet* permissions, | 970 const PermissionSet* permissions, |
999 Reason reason); | 971 Reason reason); |
1000 }; | 972 }; |
1001 | 973 |
1002 } // namespace extensions | 974 } // namespace extensions |
1003 | 975 |
1004 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 976 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
OLD | NEW |