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_NEW_TAB_PAGE_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_
8 #include "base/memory/weak_ptr.h"
9 #include "base/values.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "content/public/browser/web_ui_message_handler.h"
13 class PrefRegistrySimple;
16 namespace user_prefs {
17 class PrefRegistrySyncable;
20 // Handler for general New Tab Page functionality that does not belong in a
21 // more specialized handler.
22 class NewTabPageHandler : public content::WebUIMessageHandler,
23 public base::SupportsWeakPtr<NewTabPageHandler> {
27 // Register NTP per-profile preferences.
28 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
30 // Registers values (strings etc.) for the page.
31 static void GetLocalizedValues(Profile* profile, DictionaryValue* values);
34 virtual ~NewTabPageHandler();
36 // WebUIMessageHandler implementation.
37 virtual void RegisterMessages() OVERRIDE;
39 // Callback for "notificationPromoClosed". No arguments.
40 void HandleNotificationPromoClosed(const ListValue* args);
42 // Callback for "notificationPromoViewed". No arguments.
43 void HandleNotificationPromoViewed(const ListValue* args);
45 // Callback for "notificationPromoLinkClicked". No arguments.
46 void HandleNotificationPromoLinkClicked(const ListValue* args);
48 // Callback for "bubblePromoClosed". No arguments.
49 void HandleBubblePromoClosed(const ListValue* args);
51 // Callback for "bubblePromoViewed". No arguments.
52 void HandleBubblePromoViewed(const ListValue* args);
54 // Callback for "bubblePromoLinkClicked". No arguments.
55 void HandleBubblePromoLinkClicked(const ListValue* args);
57 // Callback for "pageSelected".
58 void HandlePageSelected(const ListValue* args);
60 // Callback for "logTimeToClick".
61 void HandleLogTimeToClick(const base::ListValue* args);
63 // Tracks the number of times the user has switches pages (for UMA).
64 size_t page_switch_count_;
66 // The purpose of this enum is to track which page on the NTP is showing.
67 // The lower 10 bits of kNtpShownPage are used for the index within the page
68 // group, and the rest of the bits are used for the page group ID (defined
70 static const int kPageIdOffset = 10;
72 INDEX_MASK = (1 << kPageIdOffset) - 1,
73 MOST_VISITED_PAGE_ID = 1 << kPageIdOffset,
74 APPS_PAGE_ID = 2 << kPageIdOffset,
75 BOOKMARKS_PAGE_ID = 3 << kPageIdOffset,
76 SUGGESTIONS_PAGE_ID = 4 << kPageIdOffset,
77 LAST_PAGE_ID = SUGGESTIONS_PAGE_ID
79 static const int kHistogramEnumerationMax =
80 (LAST_PAGE_ID >> kPageIdOffset) + 1;
82 // Helper to send out promo resource change notification.
83 void Notify(chrome::NotificationType notification_type);
85 DISALLOW_COPY_AND_ASSIGN(NewTabPageHandler);
88 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_