[email protected] | 97642ce | 2012-04-30 17:05:22 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | fd42ac30f | 2011-02-27 19:33:36 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_ |
| 6 | #define CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_ |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 7 | |
[email protected] | 1967719 | 2011-11-12 03:54:56 | [diff] [blame] | 8 | #include <map> |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 9 | #include <string> |
| 10 | |
| 11 | #include "base/basictypes.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
[email protected] | ee2ed42c | 2011-04-28 22:19:14 | [diff] [blame] | 13 | #include "chrome/browser/favicon/favicon_service.h" |
[email protected] | fd42ac30f | 2011-02-27 19:33:36 | [diff] [blame] | 14 | #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 15 | |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 16 | class Profile; |
| 17 | |
[email protected] | 16835e6 | 2011-03-16 14:13:08 | [diff] [blame] | 18 | // FaviconSource is the gateway between network-level chrome: |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 19 | // requests for favicons and the history backend that serves these. |
[email protected] | 16835e6 | 2011-03-16 14:13:08 | [diff] [blame] | 20 | class FaviconSource : public ChromeURLDataManager::DataSource { |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 21 | public: |
[email protected] | 7c158cca | 2011-04-20 17:57:06 | [diff] [blame] | 22 | // Defines the type of icon the FaviconSource will provide. |
| 23 | enum IconType { |
| 24 | FAVICON, |
[email protected] | 2a023ab | 2011-05-20 16:08:21 | [diff] [blame] | 25 | // Any available icon in the priority of TOUCH_ICON_PRECOMPOSED, TOUCH_ICON, |
| 26 | // FAVICON, and default favicon. |
| 27 | ANY |
[email protected] | 7c158cca | 2011-04-20 17:57:06 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | // |type| is the type of icon this FaviconSource will provide. |
| 31 | FaviconSource(Profile* profile, IconType type); |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 32 | |
[email protected] | 97642ce | 2012-04-30 17:05:22 | [diff] [blame] | 33 | // Constructor allowing the source name to be specified. |
| 34 | FaviconSource(Profile* profile, |
| 35 | IconType type, |
| 36 | const std::string& source_name); |
| 37 | |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 38 | // Called when the network layer has requested a resource underneath |
| 39 | // the path we registered. |
[email protected] | f09d9379 | 2009-11-17 00:10:36 | [diff] [blame] | 40 | virtual void StartDataRequest(const std::string& path, |
[email protected] | d1c7d71 | 2011-03-29 22:35:30 | [diff] [blame] | 41 | bool is_incognito, |
[email protected] | b3257834 | 2011-11-21 14:50:01 | [diff] [blame] | 42 | int request_id) OVERRIDE; |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 43 | |
[email protected] | b3257834 | 2011-11-21 14:50:01 | [diff] [blame] | 44 | virtual std::string GetMimeType(const std::string&) const OVERRIDE; |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 45 | |
[email protected] | b3257834 | 2011-11-21 14:50:01 | [diff] [blame] | 46 | virtual bool ShouldReplaceExistingSource() const OVERRIDE; |
[email protected] | ffe3d6f | 2011-02-23 16:42:52 | [diff] [blame] | 47 | |
[email protected] | 97642ce | 2012-04-30 17:05:22 | [diff] [blame] | 48 | protected: |
| 49 | virtual ~FaviconSource(); |
| 50 | |
| 51 | Profile* profile_; |
| 52 | |
[email protected] | ffe3d6f | 2011-02-23 16:42:52 | [diff] [blame] | 53 | private: |
[email protected] | 97642ce | 2012-04-30 17:05:22 | [diff] [blame] | 54 | void Init(Profile* profile, IconType type); |
| 55 | |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 56 | // Called when favicon data is available from the history backend. |
[email protected] | abc2f26 | 2011-03-15 21:15:44 | [diff] [blame] | 57 | void OnFaviconDataAvailable(FaviconService::Handle request_handle, |
[email protected] | 849ccee | 2011-03-16 17:05:30 | [diff] [blame] | 58 | history::FaviconData favicon); |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 59 | |
[email protected] | 969894ab | 2010-08-29 00:35:01 | [diff] [blame] | 60 | // Sends the default favicon. |
| 61 | void SendDefaultResponse(int request_id); |
| 62 | |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 63 | CancelableRequestConsumerT<int, 0> cancelable_consumer_; |
| 64 | |
[email protected] | abbd2f4b | 2011-07-05 18:53:18 | [diff] [blame] | 65 | // Map from request ID to size requested (in pixels). TODO(estade): Get rid of |
| 66 | // this map when we properly support multiple favicon sizes. |
| 67 | std::map<int, int> request_size_map_; |
| 68 | |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 69 | // Raw PNG representation of the favicon to show when the favicon |
| 70 | // database doesn't have a favicon for a webpage. |
[email protected] | abbd2f4b | 2011-07-05 18:53:18 | [diff] [blame] | 71 | // 16x16 |
[email protected] | 68c7630b | 2012-05-02 22:37:42 | [diff] [blame] | 72 | scoped_refptr<base::RefCountedMemory> default_favicon_; |
[email protected] | abbd2f4b | 2011-07-05 18:53:18 | [diff] [blame] | 73 | // 32x32 |
[email protected] | 68c7630b | 2012-05-02 22:37:42 | [diff] [blame] | 74 | scoped_refptr<base::RefCountedMemory> default_favicon_large_; |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 75 | |
[email protected] | 7c158cca | 2011-04-20 17:57:06 | [diff] [blame] | 76 | // The history::IconTypes of icon that this FaviconSource handles. |
[email protected] | 97642ce | 2012-04-30 17:05:22 | [diff] [blame] | 77 | int icon_types_; |
[email protected] | 7c158cca | 2011-04-20 17:57:06 | [diff] [blame] | 78 | |
[email protected] | 16835e6 | 2011-03-16 14:13:08 | [diff] [blame] | 79 | DISALLOW_COPY_AND_ASSIGN(FaviconSource); |
[email protected] | eb3a892e | 2009-05-12 18:38:41 | [diff] [blame] | 80 | }; |
| 81 | |
[email protected] | fd42ac30f | 2011-02-27 19:33:36 | [diff] [blame] | 82 | #endif // CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_ |