| 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 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/new_tab_page_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 12 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 13 #include "chrome/browser/web_resource/notification_promo_helper.h" | |
| 14 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 15 #include "components/browser_sync/browser/profile_sync_service.h" | 14 #include "components/browser_sync/browser/profile_sync_service.h" |
| 16 #include "components/pref_registry/pref_registry_syncable.h" | 15 #include "components/pref_registry/pref_registry_syncable.h" |
| 17 #include "components/prefs/pref_service.h" | 16 #include "components/prefs/pref_service.h" |
| 18 #include "content/public/browser/notification_service.h" | |
| 19 #include "content/public/browser/web_ui.h" | 17 #include "content/public/browser/web_ui.h" |
| 20 | 18 |
| 21 namespace { | |
| 22 | |
| 23 enum PromoAction { | |
| 24 PROMO_VIEWED = 0, | |
| 25 PROMO_CLOSED, | |
| 26 PROMO_LINK_CLICKED, | |
| 27 PROMO_ACTION_MAX, | |
| 28 }; | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 NewTabPageHandler::NewTabPageHandler() : page_switch_count_(0) { | 19 NewTabPageHandler::NewTabPageHandler() : page_switch_count_(0) { |
| 33 } | 20 } |
| 34 | 21 |
| 35 NewTabPageHandler::~NewTabPageHandler() {} | 22 NewTabPageHandler::~NewTabPageHandler() {} |
| 36 | 23 |
| 37 void NewTabPageHandler::RegisterMessages() { | 24 void NewTabPageHandler::RegisterMessages() { |
| 38 web_ui()->RegisterMessageCallback("notificationPromoClosed", | |
| 39 base::Bind(&NewTabPageHandler::HandleNotificationPromoClosed, | |
| 40 base::Unretained(this))); | |
| 41 web_ui()->RegisterMessageCallback("notificationPromoViewed", | |
| 42 base::Bind(&NewTabPageHandler::HandleNotificationPromoViewed, | |
| 43 base::Unretained(this))); | |
| 44 web_ui()->RegisterMessageCallback("notificationPromoLinkClicked", | |
| 45 base::Bind(&NewTabPageHandler::HandleNotificationPromoLinkClicked, | |
| 46 base::Unretained(this))); | |
| 47 web_ui()->RegisterMessageCallback("bubblePromoClosed", | |
| 48 base::Bind(&NewTabPageHandler::HandleBubblePromoClosed, | |
| 49 base::Unretained(this))); | |
| 50 web_ui()->RegisterMessageCallback("bubblePromoViewed", | |
| 51 base::Bind(&NewTabPageHandler::HandleBubblePromoViewed, | |
| 52 base::Unretained(this))); | |
| 53 web_ui()->RegisterMessageCallback("bubblePromoLinkClicked", | |
| 54 base::Bind(&NewTabPageHandler::HandleBubblePromoLinkClicked, | |
| 55 base::Unretained(this))); | |
| 56 web_ui()->RegisterMessageCallback("pageSelected", | 25 web_ui()->RegisterMessageCallback("pageSelected", |
| 57 base::Bind(&NewTabPageHandler::HandlePageSelected, | 26 base::Bind(&NewTabPageHandler::HandlePageSelected, |
| 58 base::Unretained(this))); | 27 base::Unretained(this))); |
| 59 } | 28 } |
| 60 | 29 |
| 61 void NewTabPageHandler::HandleNotificationPromoClosed( | |
| 62 const base::ListValue* args) { | |
| 63 web_resource::HandleNotificationPromoClosed( | |
| 64 web_resource::NotificationPromo::NTP_NOTIFICATION_PROMO); | |
| 65 Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED); | |
| 66 } | |
| 67 | |
| 68 void NewTabPageHandler::HandleNotificationPromoViewed( | |
| 69 const base::ListValue* args) { | |
| 70 if (web_resource::HandleNotificationPromoViewed( | |
| 71 web_resource::NotificationPromo::NTP_NOTIFICATION_PROMO)) { | |
| 72 Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 void NewTabPageHandler::HandleNotificationPromoLinkClicked( | |
| 77 const base::ListValue* args) { | |
| 78 DVLOG(1) << "HandleNotificationPromoLinkClicked"; | |
| 79 } | |
| 80 | |
| 81 void NewTabPageHandler::HandleBubblePromoClosed(const base::ListValue* args) { | |
| 82 web_resource::HandleNotificationPromoClosed( | |
| 83 web_resource::NotificationPromo::NTP_BUBBLE_PROMO); | |
| 84 Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED); | |
| 85 } | |
| 86 | |
| 87 void NewTabPageHandler::HandleBubblePromoViewed(const base::ListValue* args) { | |
| 88 if (web_resource::HandleNotificationPromoViewed( | |
| 89 web_resource::NotificationPromo::NTP_BUBBLE_PROMO)) | |
| 90 Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED); | |
| 91 } | |
| 92 | |
| 93 void NewTabPageHandler::HandleBubblePromoLinkClicked( | |
| 94 const base::ListValue* args) { | |
| 95 DVLOG(1) << "HandleBubblePromoLinkClicked"; | |
| 96 } | |
| 97 | |
| 98 void NewTabPageHandler::HandlePageSelected(const base::ListValue* args) { | 30 void NewTabPageHandler::HandlePageSelected(const base::ListValue* args) { |
| 99 page_switch_count_++; | 31 page_switch_count_++; |
| 100 | 32 |
| 101 double page_id_double; | 33 double page_id_double; |
| 102 CHECK(args->GetDouble(0, &page_id_double)); | 34 CHECK(args->GetDouble(0, &page_id_double)); |
| 103 int page_id = static_cast<int>(page_id_double); | 35 int page_id = static_cast<int>(page_id_double); |
| 104 | 36 |
| 105 double index_double; | 37 double index_double; |
| 106 CHECK(args->GetDouble(1, &index_double)); | 38 CHECK(args->GetDouble(1, &index_double)); |
| 107 int index = static_cast<int>(index_double); | 39 int index = static_cast<int>(index_double); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 120 // static | 52 // static |
| 121 void NewTabPageHandler::GetLocalizedValues(Profile* profile, | 53 void NewTabPageHandler::GetLocalizedValues(Profile* profile, |
| 122 base::DictionaryValue* values) { | 54 base::DictionaryValue* values) { |
| 123 values->SetInteger("apps_page_id", APPS_PAGE_ID); | 55 values->SetInteger("apps_page_id", APPS_PAGE_ID); |
| 124 | 56 |
| 125 PrefService* prefs = profile->GetPrefs(); | 57 PrefService* prefs = profile->GetPrefs(); |
| 126 int shown_page = prefs->GetInteger(prefs::kNtpShownPage); | 58 int shown_page = prefs->GetInteger(prefs::kNtpShownPage); |
| 127 values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK); | 59 values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK); |
| 128 values->SetInteger("shown_page_index", shown_page & INDEX_MASK); | 60 values->SetInteger("shown_page_index", shown_page & INDEX_MASK); |
| 129 } | 61 } |
| 130 | |
| 131 void NewTabPageHandler::Notify(chrome::NotificationType notification_type) { | |
| 132 content::NotificationService* service = | |
| 133 content::NotificationService::current(); | |
| 134 service->Notify(notification_type, | |
| 135 content::Source<NewTabPageHandler>(this), | |
| 136 content::NotificationService::NoDetails()); | |
| 137 } | |
| OLD | NEW |