blob: 3e0f2ecd3bc427828e9113208c3bad9b65ec7a18 [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]32b76ef2010-07-26 23:08:247#pragma once
[email protected]eb3a892e2009-05-12 18:38:418
[email protected]19677192011-11-12 03:54:569#include <map>
[email protected]eb3a892e2009-05-12 18:38:4110#include <string>
11
12#include "base/basictypes.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/ref_counted.h"
[email protected]ee2ed42c2011-04-28 22:19:1414#include "chrome/browser/favicon/favicon_service.h"
[email protected]fd42ac30f2011-02-27 19:33:3615#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
[email protected]eb3a892e2009-05-12 18:38:4116
[email protected]eb3a892e2009-05-12 18:38:4117class Profile;
18
[email protected]16835e62011-03-16 14:13:0819// FaviconSource is the gateway between network-level chrome:
[email protected]eb3a892e2009-05-12 18:38:4120// requests for favicons and the history backend that serves these.
[email protected]16835e62011-03-16 14:13:0821class FaviconSource : public ChromeURLDataManager::DataSource {
[email protected]eb3a892e2009-05-12 18:38:4122 public:
[email protected]7c158cca2011-04-20 17:57:0623 // Defines the type of icon the FaviconSource will provide.
24 enum IconType {
25 FAVICON,
[email protected]2a023ab2011-05-20 16:08:2126 // Any available icon in the priority of TOUCH_ICON_PRECOMPOSED, TOUCH_ICON,
27 // FAVICON, and default favicon.
28 ANY
[email protected]7c158cca2011-04-20 17:57:0629 };
30
31 // |type| is the type of icon this FaviconSource will provide.
32 FaviconSource(Profile* profile, IconType type);
[email protected]eb3a892e2009-05-12 18:38:4133
[email protected]97642ce2012-04-30 17:05:2234 // Constructor allowing the source name to be specified.
35 FaviconSource(Profile* profile,
36 IconType type,
37 const std::string& source_name);
38
[email protected]eb3a892e2009-05-12 18:38:4139 // Called when the network layer has requested a resource underneath
40 // the path we registered.
[email protected]f09d93792009-11-17 00:10:3641 virtual void StartDataRequest(const std::string& path,
[email protected]d1c7d712011-03-29 22:35:3042 bool is_incognito,
[email protected]b32578342011-11-21 14:50:0143 int request_id) OVERRIDE;
[email protected]eb3a892e2009-05-12 18:38:4144
[email protected]b32578342011-11-21 14:50:0145 virtual std::string GetMimeType(const std::string&) const OVERRIDE;
[email protected]eb3a892e2009-05-12 18:38:4146
[email protected]b32578342011-11-21 14:50:0147 virtual bool ShouldReplaceExistingSource() const OVERRIDE;
[email protected]ffe3d6f2011-02-23 16:42:5248
[email protected]97642ce2012-04-30 17:05:2249 protected:
50 virtual ~FaviconSource();
51
52 Profile* profile_;
53
[email protected]ffe3d6f2011-02-23 16:42:5254 private:
[email protected]97642ce2012-04-30 17:05:2255 void Init(Profile* profile, IconType type);
56
[email protected]eb3a892e2009-05-12 18:38:4157 // Called when favicon data is available from the history backend.
[email protected]abc2f262011-03-15 21:15:4458 void OnFaviconDataAvailable(FaviconService::Handle request_handle,
[email protected]849ccee2011-03-16 17:05:3059 history::FaviconData favicon);
[email protected]eb3a892e2009-05-12 18:38:4160
[email protected]969894ab2010-08-29 00:35:0161 // Sends the default favicon.
62 void SendDefaultResponse(int request_id);
63
[email protected]eb3a892e2009-05-12 18:38:4164 CancelableRequestConsumerT<int, 0> cancelable_consumer_;
65
[email protected]abbd2f4b2011-07-05 18:53:1866 // 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]eb3a892e2009-05-12 18:38:4170 // Raw PNG representation of the favicon to show when the favicon
71 // database doesn't have a favicon for a webpage.
[email protected]abbd2f4b2011-07-05 18:53:1872 // 16x16
[email protected]6de27992009-10-19 17:04:4673 scoped_refptr<RefCountedMemory> default_favicon_;
[email protected]abbd2f4b2011-07-05 18:53:1874 // 32x32
75 scoped_refptr<RefCountedMemory> default_favicon_large_;
[email protected]eb3a892e2009-05-12 18:38:4176
[email protected]7c158cca2011-04-20 17:57:0677 // The history::IconTypes of icon that this FaviconSource handles.
[email protected]97642ce2012-04-30 17:05:2278 int icon_types_;
[email protected]7c158cca2011-04-20 17:57:0679
[email protected]16835e62011-03-16 14:13:0880 DISALLOW_COPY_AND_ASSIGN(FaviconSource);
[email protected]eb3a892e2009-05-12 18:38:4181};
82
[email protected]fd42ac30f2011-02-27 19:33:3683#endif // CHROME_BROWSER_UI_WEBUI_FAVICON_SOURCE_H_