OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "chrome/browser/extensions/image_loading_tracker.h" | |
13 #include "chrome/browser/favicon/favicon_service.h" | 12 #include "chrome/browser/favicon/favicon_service.h" |
14 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 13 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
15 #include "chrome/common/extensions/extension_icon_set.h" | 14 #include "chrome/common/extensions/extension_icon_set.h" |
| 15 #include "chrome/common/extensions/extension_resource.h" |
16 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
17 | 17 |
18 class ExtensionIconSet; | 18 class ExtensionIconSet; |
19 class Profile; | 19 class Profile; |
20 | 20 |
21 namespace extensions { | 21 namespace extensions { |
22 class Extension; | 22 class Extension; |
23 } | 23 } |
24 | 24 |
25 // ExtensionIconSource serves extension icons through network level chrome: | 25 // ExtensionIconSource serves extension icons through network level chrome: |
(...skipping 15 matching lines...) Expand all Loading... |
41 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/32/1?grayscale=true | 41 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/32/1?grayscale=true |
42 // (ICON_SMALL, MATCH_BIGGER, grayscale) | 42 // (ICON_SMALL, MATCH_BIGGER, grayscale) |
43 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/128/0 | 43 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/128/0 |
44 // (ICON_LARGE, MATCH_EXACTLY) | 44 // (ICON_LARGE, MATCH_EXACTLY) |
45 // | 45 // |
46 // We attempt to load icons from the following sources in order: | 46 // We attempt to load icons from the following sources in order: |
47 // 1) The icons as listed in the extension / app manifests. | 47 // 1) The icons as listed in the extension / app manifests. |
48 // 2) If a 16px icon was requested, the favicon for extension's launch URL. | 48 // 2) If a 16px icon was requested, the favicon for extension's launch URL. |
49 // 3) The default extension / application icon if there are still no matches. | 49 // 3) The default extension / application icon if there are still no matches. |
50 // | 50 // |
51 class ExtensionIconSource : public ChromeURLDataManager::DataSource, | 51 class ExtensionIconSource : public ChromeURLDataManager::DataSource { |
52 public ImageLoadingTracker::Observer { | |
53 public: | 52 public: |
54 explicit ExtensionIconSource(Profile* profile); | 53 explicit ExtensionIconSource(Profile* profile); |
55 | 54 |
56 // Gets the URL of the |extension| icon in the given |icon_size|, falling back | 55 // Gets the URL of the |extension| icon in the given |icon_size|, falling back |
57 // based on the |match| type. If |grayscale|, the URL will be for the | 56 // based on the |match| type. If |grayscale|, the URL will be for the |
58 // desaturated version of the icon. |exists|, if non-NULL, will be set to true | 57 // desaturated version of the icon. |exists|, if non-NULL, will be set to true |
59 // if the icon exists; false if it will lead to a default or not-present | 58 // if the icon exists; false if it will lead to a default or not-present |
60 // image. | 59 // image. |
61 static GURL GetIconURL(const extensions::Extension* extension, | 60 static GURL GetIconURL(const extensions::Extension* extension, |
62 int icon_size, | 61 int icon_size, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 104 |
106 // Loads the favicon image for the app associated with the |request_id|. If | 105 // Loads the favicon image for the app associated with the |request_id|. If |
107 // the image does not exist, we fall back to the default image. | 106 // the image does not exist, we fall back to the default image. |
108 void LoadFaviconImage(int request_id); | 107 void LoadFaviconImage(int request_id); |
109 | 108 |
110 // FaviconService callback | 109 // FaviconService callback |
111 void OnFaviconDataAvailable( | 110 void OnFaviconDataAvailable( |
112 FaviconService::Handle request_handle, | 111 FaviconService::Handle request_handle, |
113 const history::FaviconBitmapResult& bitmap_result); | 112 const history::FaviconBitmapResult& bitmap_result); |
114 | 113 |
115 // ImageLoadingTracker::Observer | 114 // extension_image_utils callback |
116 virtual void OnImageLoaded(const gfx::Image& image, | 115 void OnImageLoaded(int request_id, const gfx::Image& image); |
117 const std::string& extension_id, | |
118 int id) OVERRIDE; | |
119 | 116 |
120 // Called when the extension doesn't have an icon. We fall back to multiple | 117 // Called when the extension doesn't have an icon. We fall back to multiple |
121 // sources, using the following order: | 118 // sources, using the following order: |
122 // 1) The icons as listed in the extension / app manifests. | 119 // 1) The icons as listed in the extension / app manifests. |
123 // 2) If a 16px icon and the extension has a launch URL, see if Chrome | 120 // 2) If a 16px icon and the extension has a launch URL, see if Chrome |
124 // has a corresponding favicon. | 121 // has a corresponding favicon. |
125 // 3) If still no matches, load the default extension / application icon. | 122 // 3) If still no matches, load the default extension / application icon. |
126 void LoadIconFailed(int request_id); | 123 void LoadIconFailed(int request_id); |
127 | 124 |
128 // Parses and savse an ExtensionIconRequest for the URL |path| for the | 125 // Parses and savse an ExtensionIconRequest for the URL |path| for the |
(...skipping 18 matching lines...) Expand all Loading... |
147 void ClearData(int request_id); | 144 void ClearData(int request_id); |
148 | 145 |
149 Profile* profile_; | 146 Profile* profile_; |
150 | 147 |
151 // Maps tracker ids to request ids. | 148 // Maps tracker ids to request ids. |
152 std::map<int, int> tracker_map_; | 149 std::map<int, int> tracker_map_; |
153 | 150 |
154 // Maps request_ids to ExtensionIconRequests. | 151 // Maps request_ids to ExtensionIconRequests. |
155 std::map<int, ExtensionIconRequest*> request_map_; | 152 std::map<int, ExtensionIconRequest*> request_map_; |
156 | 153 |
157 scoped_ptr<ImageLoadingTracker> tracker_; | |
158 | |
159 int next_tracker_id_; | |
160 | |
161 scoped_ptr<SkBitmap> web_store_icon_data_; | 154 scoped_ptr<SkBitmap> web_store_icon_data_; |
162 | 155 |
163 scoped_ptr<SkBitmap> default_app_data_; | 156 scoped_ptr<SkBitmap> default_app_data_; |
164 | 157 |
165 scoped_ptr<SkBitmap> default_extension_data_; | 158 scoped_ptr<SkBitmap> default_extension_data_; |
166 | 159 |
167 CancelableRequestConsumerT<int, 0> cancelable_consumer_; | 160 CancelableRequestConsumerT<int, 0> cancelable_consumer_; |
168 | 161 |
169 DISALLOW_COPY_AND_ASSIGN(ExtensionIconSource); | 162 DISALLOW_COPY_AND_ASSIGN(ExtensionIconSource); |
170 }; | 163 }; |
171 | 164 |
172 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ | 165 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ |
OLD | NEW |