| 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 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 int render_process_id, | 77 int render_process_id, |
| 78 int render_view_id, | 78 int render_view_id, |
| 79 const content::URLDataSource::GotDataCallback& callback) OVERRIDE; | 79 const content::URLDataSource::GotDataCallback& callback) OVERRIDE; |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 // Encapsulates the request parameters for |request_id|. | 82 // Encapsulates the request parameters for |request_id|. |
| 83 struct ExtensionIconRequest; | 83 struct ExtensionIconRequest; |
| 84 | 84 |
| 85 virtual ~ExtensionIconSource(); | 85 virtual ~ExtensionIconSource(); |
| 86 | 86 |
| 87 // Returns the bitmap for the default app image. | 87 // Loads the extension's icon for the given |request_id| and returns the |
| 88 const SkBitmap* GetDefaultAppImage(); | 88 // image to the client. |
| 89 void LoadExtensionImage(int request_id); |
| 89 | 90 |
| 90 // Returns the bitmap for the default extension. | 91 // LoadExtensionImage() will load the icon using |
| 91 const SkBitmap* GetDefaultExtensionImage(); | 92 // ImageLoader::LoadExtensionIconAsync(). OnIconLoaded will be called when |
| 92 | 93 // the icon has been loaded. |
| 93 // Performs any remaining transformations (like desaturating the |image|), | 94 void OnIconLoaded(int request_id, const gfx::Image& image); |
| 94 // then returns the |image| to the client and clears up any temporary data | |
| 95 // associated with the |request_id|. | |
| 96 void FinalizeImage(const SkBitmap* image, int request_id); | |
| 97 | |
| 98 // Loads the default image for |request_id| and returns to the client. | |
| 99 void LoadDefaultImage(int request_id); | |
| 100 | |
| 101 // Loads the extension's |icon| for the given |request_id| and returns the | |
| 102 // image to the client. | |
| 103 void LoadExtensionImage(const ExtensionResource& icon, | |
| 104 int request_id); | |
| 105 | |
| 106 // 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. | |
| 108 void LoadFaviconImage(int request_id); | |
| 109 | |
| 110 // FaviconService callback | |
| 111 void OnFaviconDataAvailable( | |
| 112 int request_id, | |
| 113 const chrome::FaviconBitmapResult& bitmap_result); | |
| 114 | |
| 115 // ImageLoader callback | |
| 116 void OnImageLoaded(int request_id, const gfx::Image& image); | |
| 117 | |
| 118 // Called when the extension doesn't have an icon. We fall back to multiple | |
| 119 // sources, using the following order: | |
| 120 // 1) The icons as listed in the extension / app manifests. | |
| 121 // 2) If a 16px icon and the extension has a launch URL, see if Chrome | |
| 122 // has a corresponding favicon. | |
| 123 // 3) If still no matches, load the default extension / application icon. | |
| 124 void LoadIconFailed(int request_id); | |
| 125 | 95 |
| 126 // Parses and savse an ExtensionIconRequest for the URL |path| for the | 96 // Parses and savse an ExtensionIconRequest for the URL |path| for the |
| 127 // specified |request_id|. | 97 // specified |request_id|. |
| 128 bool ParseData(const std::string& path, | 98 bool ParseData(const std::string& path, |
| 129 int request_id, | 99 int request_id, |
| 130 const content::URLDataSource::GotDataCallback& callback); | 100 const content::URLDataSource::GotDataCallback& callback); |
| 131 | 101 |
| 132 // Stores the parameters associated with the |request_id|, making them | 102 // Stores the parameters associated with the |request_id|, making them |
| 133 // as an ExtensionIconRequest via GetData. | 103 // as an ExtensionIconRequest via GetData. |
| 134 void SetData(int request_id, | 104 void SetData(int request_id, |
| 135 const content::URLDataSource::GotDataCallback& callback, | 105 const content::URLDataSource::GotDataCallback& callback, |
| 136 const Extension* extension, | 106 const Extension* extension, |
| 137 bool grayscale, | 107 bool grayscale, |
| 138 int size, | 108 int size, |
| 139 ExtensionIconSet::MatchType match); | 109 ExtensionIconSet::MatchType match); |
| 140 | 110 |
| 141 // Returns the ExtensionIconRequest for the given |request_id|. | 111 // Returns the ExtensionIconRequest for the given |request_id|. |
| 142 ExtensionIconRequest* GetData(int request_id); | 112 ExtensionIconRequest* GetData(int request_id); |
| 143 | 113 |
| 144 // Removes temporary data associated with |request_id|. | 114 // Removes temporary data associated with |request_id|. |
| 145 void ClearData(int request_id); | 115 void ClearData(int request_id); |
| 146 | 116 |
| 147 Profile* profile_; | 117 Profile* profile_; |
| 148 | 118 |
| 149 // Maps tracker ids to request ids. | |
| 150 std::map<int, int> tracker_map_; | |
| 151 | |
| 152 // Maps request_ids to ExtensionIconRequests. | 119 // Maps request_ids to ExtensionIconRequests. |
| 153 std::map<int, ExtensionIconRequest*> request_map_; | 120 std::map<int, ExtensionIconRequest*> request_map_; |
| 154 | 121 |
| 155 scoped_ptr<SkBitmap> default_app_data_; | |
| 156 | |
| 157 scoped_ptr<SkBitmap> default_extension_data_; | |
| 158 | |
| 159 CancelableTaskTracker cancelable_task_tracker_; | |
| 160 | |
| 161 DISALLOW_COPY_AND_ASSIGN(ExtensionIconSource); | 122 DISALLOW_COPY_AND_ASSIGN(ExtensionIconSource); |
| 162 }; | 123 }; |
| 163 | 124 |
| 164 } // namespace extensions | 125 } // namespace extensions |
| 165 | 126 |
| 166 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ | 127 #endif // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_ICON_SOURCE_H_ |
| OLD | NEW |