Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / webui / ntp / new_tab_page_handler.h
blobec2b29158795c04973f1266f7d369442f9e1a26f
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;
14 class Profile;
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> {
24 public:
25 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,
32 base::DictionaryValue* values);
34 private:
35 ~NewTabPageHandler() override;
37 // WebUIMessageHandler implementation.
38 void RegisterMessages() override;
40 // Callback for "notificationPromoClosed". No arguments.
41 void HandleNotificationPromoClosed(const base::ListValue* args);
43 // Callback for "notificationPromoViewed". No arguments.
44 void HandleNotificationPromoViewed(const base::ListValue* args);
46 // Callback for "notificationPromoLinkClicked". No arguments.
47 void HandleNotificationPromoLinkClicked(const base::ListValue* args);
49 // Callback for "bubblePromoClosed". No arguments.
50 void HandleBubblePromoClosed(const base::ListValue* args);
52 // Callback for "bubblePromoViewed". No arguments.
53 void HandleBubblePromoViewed(const base::ListValue* args);
55 // Callback for "bubblePromoLinkClicked". No arguments.
56 void HandleBubblePromoLinkClicked(const base::ListValue* args);
58 // Callback for "pageSelected".
59 void HandlePageSelected(const base::ListValue* args);
61 // Tracks the number of times the user has switches pages (for UMA).
62 size_t page_switch_count_;
64 // The purpose of this enum is to track which page on the NTP is showing.
65 // The lower 10 bits of kNtpShownPage are used for the index within the page
66 // group, and the rest of the bits are used for the page group ID (defined
67 // here).
68 static const int kPageIdOffset = 10;
69 enum {
70 INDEX_MASK = (1 << kPageIdOffset) - 1,
71 APPS_PAGE_ID = 2 << kPageIdOffset,
72 LAST_PAGE_ID = APPS_PAGE_ID,
74 static const int kHistogramEnumerationMax =
75 (LAST_PAGE_ID >> kPageIdOffset) + 1;
77 // Helper to send out promo resource change notification.
78 void Notify(chrome::NotificationType notification_type);
80 DISALLOW_COPY_AND_ASSIGN(NewTabPageHandler);
83 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_