OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 TYPE_HOSTED_APP, | 93 TYPE_HOSTED_APP, |
94 TYPE_PACKAGED_APP | 94 TYPE_PACKAGED_APP |
95 }; | 95 }; |
96 | 96 |
97 // An NPAPI plugin included in the extension. | 97 // An NPAPI plugin included in the extension. |
98 struct PluginInfo { | 98 struct PluginInfo { |
99 FilePath path; // Path to the plugin. | 99 FilePath path; // Path to the plugin. |
100 bool is_public; // False if only this extension can load this plugin. | 100 bool is_public; // False if only this extension can load this plugin. |
101 }; | 101 }; |
102 | 102 |
103 // Contains the subset of the extension's (private) data that can be modified | |
104 // after initialization. This class should only be accessed on the UI thread. | |
105 struct RuntimeData { | |
106 // We keep a cache of images loaded from extension resources based on their | |
107 // path and a string representation of a size that may have been used to | |
108 // scale it (or the empty string if the image is at its original size). | |
109 typedef std::pair<FilePath, std::string> ImageCacheKey; | |
110 typedef std::map<ImageCacheKey, SkBitmap> ImageCache; | |
111 | |
112 RuntimeData(); | |
113 ~RuntimeData(); | |
114 | |
115 // True if the background page is ready. | |
116 bool background_page_ready; | |
117 | |
118 // True while the extension is being upgraded. | |
119 bool being_upgraded; | |
120 | |
121 // Cached images for this extension. | |
122 ImageCache image_cache_; | |
123 }; | |
124 | |
125 // A permission is defined by its |name| (what is used in the manifest), | 103 // A permission is defined by its |name| (what is used in the manifest), |
126 // and the |message_id| that's used by install/update UI. | 104 // and the |message_id| that's used by install/update UI. |
127 struct Permission { | 105 struct Permission { |
128 const char* const name; | 106 const char* const name; |
129 const int message_id; | 107 const int message_id; |
130 }; | 108 }; |
131 | 109 |
132 static scoped_refptr<Extension> Create(const FilePath& path, | 110 static scoped_refptr<Extension> Create(const FilePath& path, |
133 Location location, | 111 Location location, |
134 const DictionaryValue& value, | 112 const DictionaryValue& value, |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 411 |
434 // Theme-related. | 412 // Theme-related. |
435 bool is_theme() const { return is_theme_; } | 413 bool is_theme() const { return is_theme_; } |
436 DictionaryValue* GetThemeImages() const { return theme_images_.get(); } | 414 DictionaryValue* GetThemeImages() const { return theme_images_.get(); } |
437 DictionaryValue* GetThemeColors() const {return theme_colors_.get(); } | 415 DictionaryValue* GetThemeColors() const {return theme_colors_.get(); } |
438 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } | 416 DictionaryValue* GetThemeTints() const { return theme_tints_.get(); } |
439 DictionaryValue* GetThemeDisplayProperties() const { | 417 DictionaryValue* GetThemeDisplayProperties() const { |
440 return theme_display_properties_.get(); | 418 return theme_display_properties_.get(); |
441 } | 419 } |
442 | 420 |
443 // Whether the background page, if any, is ready. We don't load other | |
444 // components until then. If there is no background page, we consider it to | |
445 // be ready. | |
446 bool GetBackgroundPageReady() const; | |
447 void SetBackgroundPageReady() const; | |
448 | |
449 // Getter and setter for the flag that specifies whether the extension is | |
450 // being upgraded. | |
451 bool being_upgraded() const { return GetRuntimeData()->being_upgraded; } | |
452 void set_being_upgraded(bool value) const { | |
453 GetRuntimeData()->being_upgraded = value; | |
454 } | |
455 | |
456 private: | 421 private: |
457 friend class base::RefCountedThreadSafe<Extension>; | 422 friend class base::RefCountedThreadSafe<Extension>; |
458 | 423 |
| 424 // We keep a cache of images loaded from extension resources based on their |
| 425 // path and a string representation of a size that may have been used to |
| 426 // scale it (or the empty string if the image is at its original size). |
| 427 typedef std::pair<FilePath, std::string> ImageCacheKey; |
| 428 typedef std::map<ImageCacheKey, SkBitmap> ImageCache; |
| 429 |
459 // Normalize the path for use by the extension. On Windows, this will make | 430 // Normalize the path for use by the extension. On Windows, this will make |
460 // sure the drive letter is uppercase. | 431 // sure the drive letter is uppercase. |
461 static FilePath MaybeNormalizePath(const FilePath& path); | 432 static FilePath MaybeNormalizePath(const FilePath& path); |
462 | 433 |
463 Extension(const FilePath& path, Location location); | 434 Extension(const FilePath& path, Location location); |
464 ~Extension(); | 435 ~Extension(); |
465 | 436 |
466 // Initialize the extension from a parsed manifest. | 437 // Initialize the extension from a parsed manifest. |
467 // Usually, the id of an extension is generated by the "key" property of | 438 // Usually, the id of an extension is generated by the "key" property of |
468 // its manifest, but if |require_key| is |false|, a temporary ID will be | 439 // its manifest, but if |require_key| is |false|, a temporary ID will be |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 // The set of unique API install messages that the extension has. | 496 // The set of unique API install messages that the extension has. |
526 // NOTE: This only includes messages related to permissions declared in the | 497 // NOTE: This only includes messages related to permissions declared in the |
527 // "permissions" key in the manifest. Permissions implied from other features | 498 // "permissions" key in the manifest. Permissions implied from other features |
528 // of the manifest, like plugins and content scripts are not included. | 499 // of the manifest, like plugins and content scripts are not included. |
529 std::set<string16> GetSimplePermissionMessages() const; | 500 std::set<string16> GetSimplePermissionMessages() const; |
530 | 501 |
531 // The permission message displayed related to the host permissions for | 502 // The permission message displayed related to the host permissions for |
532 // this extension. | 503 // this extension. |
533 string16 GetHostPermissionMessage() const; | 504 string16 GetHostPermissionMessage() const; |
534 | 505 |
535 // Returns a mutable pointer to our runtime data. Can only be called on | 506 // Cached images for this extension. This should only be touched on the UI |
536 // the UI thread. | 507 // thread. |
537 RuntimeData* GetRuntimeData() const; | 508 mutable ImageCache image_cache_; |
538 | |
539 // Runtime data. | |
540 const RuntimeData runtime_data_; | |
541 | 509 |
542 // A persistent, globally unique ID. An extension's ID is used in things | 510 // A persistent, globally unique ID. An extension's ID is used in things |
543 // like directory structures and URLs, and is expected to not change across | 511 // like directory structures and URLs, and is expected to not change across |
544 // versions. It is generated as a SHA-256 hash of the extension's public | 512 // versions. It is generated as a SHA-256 hash of the extension's public |
545 // key, or as a hash of the path in the case of unpacked extensions. | 513 // key, or as a hash of the path in the case of unpacked extensions. |
546 std::string id_; | 514 std::string id_; |
547 | 515 |
548 // The extension's human-readable name. Name is used for display purpose. It | 516 // The extension's human-readable name. Name is used for display purpose. It |
549 // might be wrapped with unicode bidi control characters so that it is | 517 // might be wrapped with unicode bidi control characters so that it is |
550 // displayed correctly in RTL context. | 518 // displayed correctly in RTL context. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 std::set<std::string> extension_api_permissions; | 681 std::set<std::string> extension_api_permissions; |
714 // TODO(akalin): Once we have a unified ExtensionType, replace the | 682 // TODO(akalin): Once we have a unified ExtensionType, replace the |
715 // below member variables with a member of that type. | 683 // below member variables with a member of that type. |
716 bool is_theme; | 684 bool is_theme; |
717 bool is_app; | 685 bool is_app; |
718 bool converted_from_user_script; | 686 bool converted_from_user_script; |
719 GURL update_url; | 687 GURL update_url; |
720 }; | 688 }; |
721 | 689 |
722 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ | 690 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_H_ |
OLD | NEW |