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 "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "chrome/browser/favicon/favicon_service.h" | 13 #include "chrome/browser/favicon/favicon_service.h" |
14 #include "chrome/common/cancelable_task_tracker.h" | 14 #include "chrome/common/cancelable_task_tracker.h" |
15 #include "chrome/common/extensions/extension_icon_set.h" | 15 #include "chrome/common/extensions/extension_icon_set.h" |
16 #include "chrome/common/extensions/extension_resource.h" | 16 #include "chrome/common/extensions/extension_resource.h" |
17 #include "content/public/browser/url_data_source_delegate.h" | 17 #include "content/public/browser/url_data_source.h" |
18 #include "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
19 | 19 |
20 class ExtensionIconSet; | 20 class ExtensionIconSet; |
21 class Profile; | 21 class Profile; |
22 | 22 |
23 namespace extensions { | 23 namespace extensions { |
24 class Extension; | 24 class Extension; |
25 } | 25 } |
26 | 26 |
27 // ExtensionIconSource serves extension icons through network level chrome: | 27 // ExtensionIconSource serves extension icons through network level chrome: |
(...skipping 15 matching lines...) Expand all Loading... |
43 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/32/1?grayscale=true | 43 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/32/1?grayscale=true |
44 // (ICON_SMALL, MATCH_BIGGER, grayscale) | 44 // (ICON_SMALL, MATCH_BIGGER, grayscale) |
45 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/128/0 | 45 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/128/0 |
46 // (ICON_LARGE, MATCH_EXACTLY) | 46 // (ICON_LARGE, MATCH_EXACTLY) |
47 // | 47 // |
48 // We attempt to load icons from the following sources in order: | 48 // We attempt to load icons from the following sources in order: |
49 // 1) The icons as listed in the extension / app manifests. | 49 // 1) The icons as listed in the extension / app manifests. |
50 // 2) If a 16px icon was requested, the favicon for extension's launch URL. | 50 // 2) If a 16px icon was requested, the favicon for extension's launch URL. |
51 // 3) The default extension / application icon if there are still no matches. | 51 // 3) The default extension / application icon if there are still no matches. |
52 // | 52 // |
53 class ExtensionIconSource : public content::URLDataSourceDelegate, | 53 class ExtensionIconSource : public content::URLDataSource, |
54 public base::SupportsWeakPtr<ExtensionIconSource> { | 54 public base::SupportsWeakPtr<ExtensionIconSource> { |
55 public: | 55 public: |
56 explicit ExtensionIconSource(Profile* profile); | 56 explicit ExtensionIconSource(Profile* profile); |
57 | 57 |
58 // Gets the URL of the |extension| icon in the given |icon_size|, falling back | 58 // Gets the URL of the |extension| icon in the given |icon_size|, falling back |
59 // based on the |match| type. If |grayscale|, the URL will be for the | 59 // based on the |match| type. If |grayscale|, the URL will be for the |
60 // desaturated version of the icon. |exists|, if non-NULL, will be set to true | 60 // desaturated version of the icon. |exists|, if non-NULL, will be set to true |
61 // if the icon exists; false if it will lead to a default or not-present | 61 // if the icon exists; false if it will lead to a default or not-present |
62 // image. | 62 // image. |
63 static GURL GetIconURL(const extensions::Extension* extension, | 63 static GURL GetIconURL(const extensions::Extension* extension, |
64 int icon_size, | 64 int icon_size, |
65 ExtensionIconSet::MatchType match, | 65 ExtensionIconSet::MatchType match, |
66 bool grayscale, | 66 bool grayscale, |
67 bool* exists); | 67 bool* exists); |
68 | 68 |
69 // A public utility function for accessing the bitmap of the image specified | 69 // A public utility function for accessing the bitmap of the image specified |
70 // by |resource_id|. | 70 // by |resource_id|. |
71 static SkBitmap* LoadImageByResourceId(int resource_id); | 71 static SkBitmap* LoadImageByResourceId(int resource_id); |
72 | 72 |
73 // content::URLDataSourceDelegate implementation. | 73 // content::URLDataSource implementation. |
74 virtual std::string GetSource() OVERRIDE; | 74 virtual std::string GetSource() OVERRIDE; |
75 virtual std::string GetMimeType(const std::string&) const OVERRIDE; | 75 virtual std::string GetMimeType(const std::string&) const OVERRIDE; |
76 virtual void StartDataRequest(const std::string& path, | 76 virtual void StartDataRequest( |
77 bool is_incognito, | 77 const std::string& path, |
78 int request_id) OVERRIDE; | 78 bool is_incognito, |
| 79 const content::URLDataSource::GotDataCallback& callback) OVERRIDE; |
79 | 80 |
80 private: | 81 private: |
81 // Encapsulates the request parameters for |request_id|. | 82 // Encapsulates the request parameters for |request_id|. |
82 struct ExtensionIconRequest; | 83 struct ExtensionIconRequest; |
83 | 84 |
84 virtual ~ExtensionIconSource(); | 85 virtual ~ExtensionIconSource(); |
85 | 86 |
86 // Returns the bitmap for the default app image. | 87 // Returns the bitmap for the default app image. |
87 const SkBitmap* GetDefaultAppImage(); | 88 const SkBitmap* GetDefaultAppImage(); |
88 | 89 |
(...skipping 27 matching lines...) Expand all Loading... |
116 // 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 |
117 // sources, using the following order: | 118 // sources, using the following order: |
118 // 1) The icons as listed in the extension / app manifests. | 119 // 1) The icons as listed in the extension / app manifests. |
119 // 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 |
120 // has a corresponding favicon. | 121 // has a corresponding favicon. |
121 // 3) If still no matches, load the default extension / application icon. | 122 // 3) If still no matches, load the default extension / application icon. |
122 void LoadIconFailed(int request_id); | 123 void LoadIconFailed(int request_id); |
123 | 124 |
124 // Parses and savse an ExtensionIconRequest for the URL |path| for the | 125 // Parses and savse an ExtensionIconRequest for the URL |path| for the |
125 // specified |request_id|. | 126 // specified |request_id|. |
126 bool ParseData(const std::string& path, int request_id); | 127 bool ParseData(const std::string& path, |
| 128 int request_id, |
| 129 const content::URLDataSource::GotDataCallback& callback); |
127 | 130 |
128 // Sends the default response to |request_id|, used for invalid requests. | 131 // Sends the default response to |request_id|, used for invalid requests. |
129 void SendDefaultResponse(int request_id); | 132 void SendDefaultResponse(int request_id); |
130 | 133 |
131 // Stores the parameters associated with the |request_id|, making them | 134 // Stores the parameters associated with the |request_id|, making them |
132 // as an ExtensionIconRequest via GetData. | 135 // as an ExtensionIconRequest via GetData. |
133 void SetData(int request_id, | 136 void SetData(int request_id, |
| 137 const content::URLDataSource::GotDataCallback& callback, |
134 const extensions::Extension* extension, | 138 const extensions::Extension* extension, |
135 bool grayscale, | 139 bool grayscale, |
136 int size, | 140 int size, |
137 ExtensionIconSet::MatchType match); | 141 ExtensionIconSet::MatchType match); |
138 | 142 |
139 // Returns the ExtensionIconRequest for the given |request_id|. | 143 // Returns the ExtensionIconRequest for the given |request_id|. |
140 ExtensionIconRequest* GetData(int request_id); | 144 ExtensionIconRequest* GetData(int request_id); |
141 | 145 |
142 // Removes temporary data associated with |request_id|. | 146 // Removes temporary data associated with |request_id|. |
143 void ClearData(int request_id); | 147 void ClearData(int request_id); |
144 | 148 |
145 Profile* profile_; | 149 Profile* profile_; |
146 | 150 |
147 // Maps tracker ids to request ids. | 151 // Maps tracker ids to request ids. |
148 std::map<int, int> tracker_map_; | 152 std::map<int, int> tracker_map_; |
149 | 153 |
150 // Maps request_ids to ExtensionIconRequests. | 154 // Maps request_ids to ExtensionIconRequests. |
151 std::map<int, ExtensionIconRequest*> request_map_; | 155 std::map<int, ExtensionIconRequest*> request_map_; |
152 | 156 |
153 scoped_ptr<SkBitmap> default_app_data_; | 157 scoped_ptr<SkBitmap> default_app_data_; |
154 | 158 |
155 scoped_ptr<SkBitmap> default_extension_data_; | 159 scoped_ptr<SkBitmap> default_extension_data_; |
156 | 160 |
157 CancelableTaskTracker cancelable_task_tracker_; | 161 CancelableTaskTracker cancelable_task_tracker_; |
158 | 162 |
159 DISALLOW_COPY_AND_ASSIGN(ExtensionIconSource); | 163 DISALLOW_COPY_AND_ASSIGN(ExtensionIconSource); |
160 }; | 164 }; |
161 | 165 |
162 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ | 166 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ |
OLD | NEW |