Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / ntp / favicon_webui_handler.h
blob6d0e29dbb5c5d33c60ac2e0a39fb8bdbd90aaf8c
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_FAVICON_WEBUI_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_FAVICON_WEBUI_HANDLER_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/task/cancelable_task_tracker.h"
14 #include "components/favicon_base/favicon_types.h"
15 #include "content/public/browser/web_ui_message_handler.h"
17 class ExtensionIconColorManager;
19 namespace base {
20 class ListValue;
23 class FaviconWebUIHandler : public content::WebUIMessageHandler {
24 public:
25 FaviconWebUIHandler();
26 ~FaviconWebUIHandler() override;
28 // WebUIMessageHandler
29 void RegisterMessages() override;
31 // Called from the JS to get the dominant color of a favicon. The first
32 // argument is a favicon URL, the second is the ID of the DOM node that is
33 // asking for it.
34 void HandleGetFaviconDominantColor(const base::ListValue* args);
36 // As above, but for an app tile. The sole argument is the extension ID.
37 void HandleGetAppIconDominantColor(const base::ListValue* args);
39 // Callback getting signal that an app icon is loaded.
40 void NotifyAppIconReady(const std::string& extension_id);
42 private:
43 // Called when favicon data is available from the history backend.
44 void OnFaviconDataAvailable(
45 int request_handle,
46 const favicon_base::FaviconRawBitmapResult& bitmap_result);
48 base::CancelableTaskTracker cancelable_task_tracker_;
50 // Map from request ID to DOM ID so we can make the appropriate callback when
51 // the favicon request comes back. This map exists because
52 // CancelableRequestConsumerTSimple only takes POD keys.
53 std::map<int, std::string> dom_id_map_;
54 // A counter to track ID numbers as we use them.
55 int id_;
57 // Raw PNG representation of the favicon to show when the favicon
58 // database doesn't have a favicon for a webpage.
59 scoped_refptr<base::RefCountedMemory> default_favicon_;
61 // Manage retrieval of icons from apps.
62 scoped_ptr<ExtensionIconColorManager> app_icon_color_manager_;
64 DISALLOW_COPY_AND_ASSIGN(FaviconWebUIHandler);
67 #endif // CHROME_BROWSER_UI_WEBUI_NTP_FAVICON_WEBUI_HANDLER_H_