| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | |
| 14 #include "content/public/browser/web_ui_message_handler.h" | 13 #include "content/public/browser/web_ui_message_handler.h" |
| 15 | 14 |
| 16 class PrefRegistrySimple; | 15 class PrefRegistrySimple; |
| 17 class Profile; | 16 class Profile; |
| 18 | 17 |
| 19 namespace user_prefs { | 18 namespace user_prefs { |
| 20 class PrefRegistrySyncable; | 19 class PrefRegistrySyncable; |
| 21 } | 20 } |
| 22 | 21 |
| 23 // Handler for general New Tab Page functionality that does not belong in a | 22 // Handler for general New Tab Page functionality that does not belong in a |
| 24 // more specialized handler. | 23 // more specialized handler. |
| 25 class NewTabPageHandler : public content::WebUIMessageHandler, | 24 class NewTabPageHandler : public content::WebUIMessageHandler, |
| 26 public base::SupportsWeakPtr<NewTabPageHandler> { | 25 public base::SupportsWeakPtr<NewTabPageHandler> { |
| 27 public: | 26 public: |
| 28 NewTabPageHandler(); | 27 NewTabPageHandler(); |
| 29 | 28 |
| 30 // Register NTP per-profile preferences. | 29 // Register NTP per-profile preferences. |
| 31 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 30 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 32 | 31 |
| 33 // Registers values (strings etc.) for the page. | 32 // Registers values (strings etc.) for the page. |
| 34 static void GetLocalizedValues(Profile* profile, | 33 static void GetLocalizedValues(Profile* profile, |
| 35 base::DictionaryValue* values); | 34 base::DictionaryValue* values); |
| 36 | 35 |
| 37 private: | 36 private: |
| 38 ~NewTabPageHandler() override; | 37 ~NewTabPageHandler() override; |
| 39 | 38 |
| 40 // WebUIMessageHandler implementation. | 39 // WebUIMessageHandler implementation. |
| 41 void RegisterMessages() override; | 40 void RegisterMessages() override; |
| 42 | 41 |
| 43 // Callback for "notificationPromoClosed". No arguments. | |
| 44 void HandleNotificationPromoClosed(const base::ListValue* args); | |
| 45 | |
| 46 // Callback for "notificationPromoViewed". No arguments. | |
| 47 void HandleNotificationPromoViewed(const base::ListValue* args); | |
| 48 | |
| 49 // Callback for "notificationPromoLinkClicked". No arguments. | |
| 50 void HandleNotificationPromoLinkClicked(const base::ListValue* args); | |
| 51 | |
| 52 // Callback for "bubblePromoClosed". No arguments. | |
| 53 void HandleBubblePromoClosed(const base::ListValue* args); | |
| 54 | |
| 55 // Callback for "bubblePromoViewed". No arguments. | |
| 56 void HandleBubblePromoViewed(const base::ListValue* args); | |
| 57 | |
| 58 // Callback for "bubblePromoLinkClicked". No arguments. | |
| 59 void HandleBubblePromoLinkClicked(const base::ListValue* args); | |
| 60 | |
| 61 // Callback for "pageSelected". | 42 // Callback for "pageSelected". |
| 62 void HandlePageSelected(const base::ListValue* args); | 43 void HandlePageSelected(const base::ListValue* args); |
| 63 | 44 |
| 64 // Tracks the number of times the user has switches pages (for UMA). | 45 // Tracks the number of times the user has switches pages (for UMA). |
| 65 size_t page_switch_count_; | 46 size_t page_switch_count_; |
| 66 | 47 |
| 67 // The purpose of this enum is to track which page on the NTP is showing. | 48 // 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 | 49 // 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 | 50 // group, and the rest of the bits are used for the page group ID (defined |
| 70 // here). | 51 // here). |
| 71 static const int kPageIdOffset = 10; | 52 static const int kPageIdOffset = 10; |
| 72 enum { | 53 enum { |
| 73 INDEX_MASK = (1 << kPageIdOffset) - 1, | 54 INDEX_MASK = (1 << kPageIdOffset) - 1, |
| 74 APPS_PAGE_ID = 2 << kPageIdOffset, | 55 APPS_PAGE_ID = 2 << kPageIdOffset, |
| 75 LAST_PAGE_ID = APPS_PAGE_ID, | 56 LAST_PAGE_ID = APPS_PAGE_ID, |
| 76 }; | 57 }; |
| 77 static const int kHistogramEnumerationMax = | 58 static const int kHistogramEnumerationMax = |
| 78 (LAST_PAGE_ID >> kPageIdOffset) + 1; | 59 (LAST_PAGE_ID >> kPageIdOffset) + 1; |
| 79 | 60 |
| 80 // Helper to send out promo resource change notification. | |
| 81 void Notify(chrome::NotificationType notification_type); | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(NewTabPageHandler); | 61 DISALLOW_COPY_AND_ASSIGN(NewTabPageHandler); |
| 84 }; | 62 }; |
| 85 | 63 |
| 86 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_ | 64 #endif // CHROME_BROWSER_UI_WEBUI_NTP_NEW_TAB_PAGE_HANDLER_H_ |
| OLD | NEW |