| 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 "apps/app_launcher.h" | 7 #include "apps/app_launcher.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 base::Unretained(this))); | 68 base::Unretained(this))); |
| 69 web_ui()->RegisterMessageCallback("bubblePromoLinkClicked", | 69 web_ui()->RegisterMessageCallback("bubblePromoLinkClicked", |
| 70 base::Bind(&NewTabPageHandler::HandleBubblePromoLinkClicked, | 70 base::Bind(&NewTabPageHandler::HandleBubblePromoLinkClicked, |
| 71 base::Unretained(this))); | 71 base::Unretained(this))); |
| 72 web_ui()->RegisterMessageCallback("pageSelected", | 72 web_ui()->RegisterMessageCallback("pageSelected", |
| 73 base::Bind(&NewTabPageHandler::HandlePageSelected, | 73 base::Bind(&NewTabPageHandler::HandlePageSelected, |
| 74 base::Unretained(this))); | 74 base::Unretained(this))); |
| 75 web_ui()->RegisterMessageCallback("logTimeToClick", | 75 web_ui()->RegisterMessageCallback("logTimeToClick", |
| 76 base::Bind(&NewTabPageHandler::HandleLogTimeToClick, | 76 base::Bind(&NewTabPageHandler::HandleLogTimeToClick, |
| 77 base::Unretained(this))); | 77 base::Unretained(this))); |
| 78 web_ui()->RegisterMessageCallback("getShouldShowApps", | |
| 79 base::Bind(&NewTabPageHandler::HandleGetShouldShowApps, | |
| 80 base::Unretained(this))); | |
| 81 } | 78 } |
| 82 | 79 |
| 83 void NewTabPageHandler::HandleNotificationPromoClosed(const ListValue* args) { | 80 void NewTabPageHandler::HandleNotificationPromoClosed(const ListValue* args) { |
| 84 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Promo.Notification", | 81 UMA_HISTOGRAM_ENUMERATION("NewTabPage.Promo.Notification", |
| 85 PROMO_CLOSED, PROMO_ACTION_MAX); | 82 PROMO_CLOSED, PROMO_ACTION_MAX); |
| 86 NotificationPromo::HandleClosed(NotificationPromo::NTP_NOTIFICATION_PROMO); | 83 NotificationPromo::HandleClosed(NotificationPromo::NTP_NOTIFICATION_PROMO); |
| 87 Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED); | 84 Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED); |
| 88 } | 85 } |
| 89 | 86 |
| 90 void NewTabPageHandler::HandleNotificationPromoViewed(const ListValue* args) { | 87 void NewTabPageHandler::HandleNotificationPromoViewed(const ListValue* args) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 UMA_HISTOGRAM_LONG_TIMES( | 162 UMA_HISTOGRAM_LONG_TIMES( |
| 166 "ExtendedNewTabPage.TimeToClickMostVisited", delta); | 163 "ExtendedNewTabPage.TimeToClickMostVisited", delta); |
| 167 } else if (histogram_name == "ExtendedNewTabPage.TimeToClickRecentlyClosed") { | 164 } else if (histogram_name == "ExtendedNewTabPage.TimeToClickRecentlyClosed") { |
| 168 UMA_HISTOGRAM_LONG_TIMES( | 165 UMA_HISTOGRAM_LONG_TIMES( |
| 169 "ExtendedNewTabPage.TimeToClickRecentlyClosed", delta); | 166 "ExtendedNewTabPage.TimeToClickRecentlyClosed", delta); |
| 170 } else { | 167 } else { |
| 171 NOTREACHED(); | 168 NOTREACHED(); |
| 172 } | 169 } |
| 173 } | 170 } |
| 174 | 171 |
| 175 void NewTabPageHandler::HandleGetShouldShowApps(const ListValue* args) { | |
| 176 apps::GetIsAppLauncherEnabled( | |
| 177 base::Bind(&NewTabPageHandler::GotIsAppLauncherEnabled, | |
| 178 AsWeakPtr())); | |
| 179 } | |
| 180 | |
| 181 void NewTabPageHandler::GotIsAppLauncherEnabled(bool is_enabled) { | |
| 182 base::FundamentalValue should_show_apps(!is_enabled); | |
| 183 web_ui()->CallJavascriptFunction("ntp.gotShouldShowApps", should_show_apps); | |
| 184 } | |
| 185 | |
| 186 // static | 172 // static |
| 187 void NewTabPageHandler::RegisterUserPrefs(PrefRegistrySyncable* registry) { | 173 void NewTabPageHandler::RegisterUserPrefs(PrefRegistrySyncable* registry) { |
| 188 // TODO(estade): should be syncable. | 174 // TODO(estade): should be syncable. |
| 189 registry->RegisterIntegerPref(prefs::kNtpShownPage, APPS_PAGE_ID, | 175 registry->RegisterIntegerPref(prefs::kNtpShownPage, APPS_PAGE_ID, |
| 190 PrefRegistrySyncable::UNSYNCABLE_PREF); | 176 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 191 } | 177 } |
| 192 | 178 |
| 193 // static | 179 // static |
| 194 void NewTabPageHandler::GetLocalizedValues(Profile* profile, | 180 void NewTabPageHandler::GetLocalizedValues(Profile* profile, |
| 195 DictionaryValue* values) { | 181 DictionaryValue* values) { |
| 196 values->SetInteger("most_visited_page_id", MOST_VISITED_PAGE_ID); | 182 values->SetInteger("most_visited_page_id", MOST_VISITED_PAGE_ID); |
| 197 values->SetInteger("apps_page_id", APPS_PAGE_ID); | 183 values->SetInteger("apps_page_id", APPS_PAGE_ID); |
| 198 values->SetInteger("suggestions_page_id", SUGGESTIONS_PAGE_ID); | 184 values->SetInteger("suggestions_page_id", SUGGESTIONS_PAGE_ID); |
| 199 | 185 |
| 200 PrefService* prefs = profile->GetPrefs(); | 186 PrefService* prefs = profile->GetPrefs(); |
| 201 int shown_page = prefs->GetInteger(prefs::kNtpShownPage); | 187 int shown_page = prefs->GetInteger(prefs::kNtpShownPage); |
| 202 values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK); | 188 values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK); |
| 203 values->SetInteger("shown_page_index", shown_page & INDEX_MASK); | 189 values->SetInteger("shown_page_index", shown_page & INDEX_MASK); |
| 204 } | 190 } |
| 205 | 191 |
| 206 void NewTabPageHandler::Notify(chrome::NotificationType notification_type) { | 192 void NewTabPageHandler::Notify(chrome::NotificationType notification_type) { |
| 207 content::NotificationService* service = | 193 content::NotificationService* service = |
| 208 content::NotificationService::current(); | 194 content::NotificationService::current(); |
| 209 service->Notify(notification_type, | 195 service->Notify(notification_type, |
| 210 content::Source<NewTabPageHandler>(this), | 196 content::Source<NewTabPageHandler>(this), |
| 211 content::NotificationService::NoDetails()); | 197 content::NotificationService::NoDetails()); |
| 212 } | 198 } |
| OLD | NEW |