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
,
32 base::DictionaryValue
* values
);
35 virtual ~NewTabPageHandler();
37 // WebUIMessageHandler implementation.
38 virtual 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 // Callback for "logTimeToClick".
62 void HandleLogTimeToClick(const base::ListValue
* args
);
64 // Tracks the number of times the user has switches pages (for UMA).
65 size_t page_switch_count_
;
67 // The purpose of this enum is to track which page on the NTP is showing.
68 // The lower 10 bits of kNtpShownPage are used for the index within the page
69 // group, and the rest of the bits are used for the page group ID (defined
71 static const int kPageIdOffset
= 10;
73 INDEX_MASK
= (1 << kPageIdOffset
) - 1,
74 MOST_VISITED_PAGE_ID
= 1 << kPageIdOffset
,
75 APPS_PAGE_ID
= 2 << kPageIdOffset
,
76 BOOKMARKS_PAGE_ID
= 3 << kPageIdOffset
,
77 SUGGESTIONS_PAGE_ID
= 4 << kPageIdOffset
,
78 LAST_PAGE_ID
= SUGGESTIONS_PAGE_ID
80 static const int kHistogramEnumerationMax
=
81 (LAST_PAGE_ID
>> kPageIdOffset
) + 1;
83 // Helper to send out promo resource change notification.
84 void Notify(chrome::NotificationType notification_type
);
86 DISALLOW_COPY_AND_ASSIGN(NewTabPageHandler
);
89 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_