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 "chrome/browser/favicon/favicon_service.h" | 13 #include "chrome/browser/favicon/favicon_service.h" |
13 #include "chrome/browser/ui/webui/chrome_url_data_manager.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 "third_party/skia/include/core/SkBitmap.h" | 18 #include "third_party/skia/include/core/SkBitmap.h" |
18 | 19 |
19 class ExtensionIconSet; | 20 class ExtensionIconSet; |
20 class Profile; | 21 class Profile; |
21 | 22 |
22 namespace extensions { | 23 namespace extensions { |
23 class Extension; | 24 class Extension; |
24 } | 25 } |
25 | 26 |
26 // ExtensionIconSource serves extension icons through network level chrome: | 27 // ExtensionIconSource serves extension icons through network level chrome: |
(...skipping 15 matching lines...) Expand all Loading... |
42 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/32/1?grayscale=true | 43 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/32/1?grayscale=true |
43 // (ICON_SMALL, MATCH_BIGGER, grayscale) | 44 // (ICON_SMALL, MATCH_BIGGER, grayscale) |
44 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/128/0 | 45 // chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/128/0 |
45 // (ICON_LARGE, MATCH_EXACTLY) | 46 // (ICON_LARGE, MATCH_EXACTLY) |
46 // | 47 // |
47 // We attempt to load icons from the following sources in order: | 48 // We attempt to load icons from the following sources in order: |
48 // 1) The icons as listed in the extension / app manifests. | 49 // 1) The icons as listed in the extension / app manifests. |
49 // 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. |
50 // 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. |
51 // | 52 // |
52 class ExtensionIconSource : public ChromeURLDataManager::DataSource { | 53 class ExtensionIconSource : public content::URLDataSourceDelegate, |
| 54 public base::SupportsWeakPtr<ExtensionIconSource> { |
53 public: | 55 public: |
54 explicit ExtensionIconSource(Profile* profile); | 56 explicit ExtensionIconSource(Profile* profile); |
55 | 57 |
56 // 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 |
57 // 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 |
58 // 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 |
59 // 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 |
60 // image. | 62 // image. |
61 static GURL GetIconURL(const extensions::Extension* extension, | 63 static GURL GetIconURL(const extensions::Extension* extension, |
62 int icon_size, | 64 int icon_size, |
63 ExtensionIconSet::MatchType match, | 65 ExtensionIconSet::MatchType match, |
64 bool grayscale, | 66 bool grayscale, |
65 bool* exists); | 67 bool* exists); |
66 | 68 |
67 // 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 |
68 // by |resource_id|. | 70 // by |resource_id|. |
69 static SkBitmap* LoadImageByResourceId(int resource_id); | 71 static SkBitmap* LoadImageByResourceId(int resource_id); |
70 | 72 |
71 // ChromeURLDataManager::DataSource | 73 // content::URLDataSourceDelegate implementation. |
72 | 74 virtual std::string GetSource() OVERRIDE; |
73 virtual std::string GetMimeType(const std::string&) const OVERRIDE; | 75 virtual std::string GetMimeType(const std::string&) const OVERRIDE; |
74 | |
75 virtual void StartDataRequest(const std::string& path, | 76 virtual void StartDataRequest(const std::string& path, |
76 bool is_incognito, | 77 bool is_incognito, |
77 int request_id) OVERRIDE; | 78 int request_id) OVERRIDE; |
78 | 79 |
79 private: | 80 private: |
80 // Encapsulates the request parameters for |request_id|. | 81 // Encapsulates the request parameters for |request_id|. |
81 struct ExtensionIconRequest; | 82 struct ExtensionIconRequest; |
82 | 83 |
83 virtual ~ExtensionIconSource(); | 84 virtual ~ExtensionIconSource(); |
84 | 85 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 scoped_ptr<SkBitmap> default_app_data_; | 153 scoped_ptr<SkBitmap> default_app_data_; |
153 | 154 |
154 scoped_ptr<SkBitmap> default_extension_data_; | 155 scoped_ptr<SkBitmap> default_extension_data_; |
155 | 156 |
156 CancelableTaskTracker cancelable_task_tracker_; | 157 CancelableTaskTracker cancelable_task_tracker_; |
157 | 158 |
158 DISALLOW_COPY_AND_ASSIGN(ExtensionIconSource); | 159 DISALLOW_COPY_AND_ASSIGN(ExtensionIconSource); |
159 }; | 160 }; |
160 | 161 |
161 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ | 162 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ |
OLD | NEW |