blob: 319c88d904361d62a824d160ddde312a2d55abac [file] [log] [blame]
[email protected]97642ce2012-04-30 17:05:221// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]eb3a892e2009-05-12 18:38:412// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]fd42ac30f2011-02-27 19:33:365#ifndef CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_
6#define CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_
[email protected]eb3a892e2009-05-12 18:38:417
[email protected]19677192011-11-12 03:54:568#include <map>
[email protected]eb3a892e2009-05-12 18:38:419#include <string>
10
11#include "base/basictypes.h"
[email protected]3b63f8f42011-03-28 01:54:1512#include "base/memory/ref_counted.h"
[email protected]ee2ed42c2011-04-28 22:19:1413#include "chrome/browser/favicon/favicon_service.h"
[email protected]fd42ac30f2011-02-27 19:33:3614#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
[email protected]eb3a892e2009-05-12 18:38:4115
[email protected]eb3a892e2009-05-12 18:38:4116class Profile;
17
[email protected]16835e62011-03-16 14:13:0818// FaviconSource is the gateway between network-level chrome:
[email protected]eb3a892e2009-05-12 18:38:4119// requests for favicons and the history backend that serves these.
[email protected]16835e62011-03-16 14:13:0820class FaviconSource : public ChromeURLDataManager::DataSource {
[email protected]eb3a892e2009-05-12 18:38:4121 public:
[email protected]7c158cca2011-04-20 17:57:0622 // Defines the type of icon the FaviconSource will provide.
23 enum IconType {
24 FAVICON,
[email protected]2a023ab2011-05-20 16:08:2125 // Any available icon in the priority of TOUCH_ICON_PRECOMPOSED, TOUCH_ICON,
26 // FAVICON, and default favicon.
27 ANY
[email protected]7c158cca2011-04-20 17:57:0628 };
29
30 // |type| is the type of icon this FaviconSource will provide.
31 FaviconSource(Profile* profile, IconType type);
[email protected]eb3a892e2009-05-12 18:38:4132
[email protected]97642ce2012-04-30 17:05:2233 // Constructor allowing the source name to be specified.
34 FaviconSource(Profile* profile,
35 IconType type,
36 const std::string& source_name);
37
[email protected]eb3a892e2009-05-12 18:38:4138 // Called when the network layer has requested a resource underneath
39 // the path we registered.
[email protected]f09d93792009-11-17 00:10:3640 virtual void StartDataRequest(const std::string& path,
[email protected]d1c7d712011-03-29 22:35:3041 bool is_incognito,
[email protected]b32578342011-11-21 14:50:0142 int request_id) OVERRIDE;
[email protected]eb3a892e2009-05-12 18:38:4143
[email protected]b32578342011-11-21 14:50:0144 virtual std::string GetMimeType(const std::string&) const OVERRIDE;
[email protected]eb3a892e2009-05-12 18:38:4145
[email protected]b32578342011-11-21 14:50:0146 virtual bool ShouldReplaceExistingSource() const OVERRIDE;
[email protected]ffe3d6f2011-02-23 16:42:5247
[email protected]97642ce2012-04-30 17:05:2248 protected:
49 virtual ~FaviconSource();
50
51 Profile* profile_;
52
[email protected]ffe3d6f2011-02-23 16:42:5253 private:
[email protected]97642ce2012-04-30 17:05:2254 void Init(Profile* profile, IconType type);
55
[email protected]eb3a892e2009-05-12 18:38:4156 // Called when favicon data is available from the history backend.
[email protected]abc2f262011-03-15 21:15:4457 void OnFaviconDataAvailable(FaviconService::Handle request_handle,
[email protected]849ccee2011-03-16 17:05:3058 history::FaviconData favicon);
[email protected]eb3a892e2009-05-12 18:38:4159
[email protected]969894ab2010-08-29 00:35:0160 // Sends the default favicon.
61 void SendDefaultResponse(int request_id);
62
[email protected]eb3a892e2009-05-12 18:38:4163 CancelableRequestConsumerT<int, 0> cancelable_consumer_;
64
[email protected]abbd2f4b2011-07-05 18:53:1865 // 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]eb3a892e2009-05-12 18:38:4169 // Raw PNG representation of the favicon to show when the favicon
70 // database doesn't have a favicon for a webpage.
[email protected]abbd2f4b2011-07-05 18:53:1871 // 16x16
[email protected]68c7630b2012-05-02 22:37:4272 scoped_refptr<base::RefCountedMemory> default_favicon_;
[email protected]abbd2f4b2011-07-05 18:53:1873 // 32x32
[email protected]68c7630b2012-05-02 22:37:4274 scoped_refptr<base::RefCountedMemory> default_favicon_large_;
[email protected]eb3a892e2009-05-12 18:38:4175
[email protected]7c158cca2011-04-20 17:57:0676 // The history::IconTypes of icon that this FaviconSource handles.
[email protected]97642ce2012-04-30 17:05:2277 int icon_types_;
[email protected]7c158cca2011-04-20 17:57:0678
[email protected]16835e62011-03-16 14:13:0879 DISALLOW_COPY_AND_ASSIGN(FaviconSource);
[email protected]eb3a892e2009-05-12 18:38:4180};
81
[email protected]fd42ac30f2011-02-27 19:33:3682#endif // CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_