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, 32 base::DictionaryValue* values); 33 34 private: 35 virtual ~NewTabPageHandler(); 36 37 // WebUIMessageHandler implementation. 38 virtual void RegisterMessages() OVERRIDE; 39 40 // Callback for "notificationPromoClosed". No arguments. 41 void HandleNotificationPromoClosed(const base::ListValue* args); 42 43 // Callback for "notificationPromoViewed". No arguments. 44 void HandleNotificationPromoViewed(const base::ListValue* args); 45 46 // Callback for "notificationPromoLinkClicked". No arguments. 47 void HandleNotificationPromoLinkClicked(const base::ListValue* args); 48 49 // Callback for "bubblePromoClosed". No arguments. 50 void HandleBubblePromoClosed(const base::ListValue* args); 51 52 // Callback for "bubblePromoViewed". No arguments. 53 void HandleBubblePromoViewed(const base::ListValue* args); 54 55 // Callback for "bubblePromoLinkClicked". No arguments. 56 void HandleBubblePromoLinkClicked(const base::ListValue* args); 57 58 // Callback for "pageSelected". 59 void HandlePageSelected(const base::ListValue* args); 60 61 // Callback for "logTimeToClick". 62 void HandleLogTimeToClick(const base::ListValue* args); 63 64 // Tracks the number of times the user has switches pages (for UMA). 65 size_t page_switch_count_; 66 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 70 // here). 71 static const int kPageIdOffset = 10; 72 enum { 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 79 }; 80 static const int kHistogramEnumerationMax = 81 (LAST_PAGE_ID >> kPageIdOffset) + 1; 82 83 // Helper to send out promo resource change notification. 84 void Notify(chrome::NotificationType notification_type); 85 86 DISALLOW_COPY_AND_ASSIGN(NewTabPageHandler); 87 }; 88 89 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_ 90