- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / ntp / new_tab_page_handler.h
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.
4
5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_
7
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"
12
13 class PrefRegistrySimple;
14 class Profile;
15
16 namespace user_prefs {
17 class PrefRegistrySyncable;
18 }
19
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();
26
27   // Register NTP per-profile preferences.
28   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
29
30   // Registers values (strings etc.) for the page.
31   static void GetLocalizedValues(Profile* profile, DictionaryValue* values);
32
33  private:
34   virtual ~NewTabPageHandler();
35
36   // WebUIMessageHandler implementation.
37   virtual void RegisterMessages() OVERRIDE;
38
39   // Callback for "notificationPromoClosed". No arguments.
40   void HandleNotificationPromoClosed(const ListValue* args);
41
42   // Callback for "notificationPromoViewed". No arguments.
43   void HandleNotificationPromoViewed(const ListValue* args);
44
45   // Callback for "notificationPromoLinkClicked". No arguments.
46   void HandleNotificationPromoLinkClicked(const ListValue* args);
47
48   // Callback for "bubblePromoClosed". No arguments.
49   void HandleBubblePromoClosed(const ListValue* args);
50
51   // Callback for "bubblePromoViewed". No arguments.
52   void HandleBubblePromoViewed(const ListValue* args);
53
54   // Callback for "bubblePromoLinkClicked". No arguments.
55   void HandleBubblePromoLinkClicked(const ListValue* args);
56
57   // Callback for "pageSelected".
58   void HandlePageSelected(const ListValue* args);
59
60   // Callback for "logTimeToClick".
61   void HandleLogTimeToClick(const base::ListValue* args);
62
63   // Tracks the number of times the user has switches pages (for UMA).
64   size_t page_switch_count_;
65
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
69   // here).
70   static const int kPageIdOffset = 10;
71   enum {
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
78   };
79   static const int kHistogramEnumerationMax =
80       (LAST_PAGE_ID >> kPageIdOffset) + 1;
81
82   // Helper to send out promo resource change notification.
83   void Notify(chrome::NotificationType notification_type);
84
85   DISALLOW_COPY_AND_ASSIGN(NewTabPageHandler);
86 };
87
88 #endif  // CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_