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