| 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 "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "chrome/browser/extensions/app_launcher.h" | 11 #include "chrome/browser/extensions/app_launcher.h" |
| 12 #include "chrome/browser/prefs/pref_registry_syncable.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/sync/profile_sync_service.h" | 15 #include "chrome/browser/sync/profile_sync_service.h" |
| 15 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 16 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 16 #include "chrome/browser/web_resource/notification_promo.h" | 17 #include "chrome/browser/web_resource/notification_promo.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/web_ui.h" | 20 #include "content/public/browser/web_ui.h" |
| 20 #include "grit/chromium_strings.h" | 21 #include "grit/chromium_strings.h" |
| 21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 base::Bind(&NewTabPageHandler::GotIsAppLauncherEnabled, | 177 base::Bind(&NewTabPageHandler::GotIsAppLauncherEnabled, |
| 177 AsWeakPtr())); | 178 AsWeakPtr())); |
| 178 } | 179 } |
| 179 | 180 |
| 180 void NewTabPageHandler::GotIsAppLauncherEnabled(bool is_enabled) { | 181 void NewTabPageHandler::GotIsAppLauncherEnabled(bool is_enabled) { |
| 181 base::FundamentalValue should_show_apps(!is_enabled); | 182 base::FundamentalValue should_show_apps(!is_enabled); |
| 182 web_ui()->CallJavascriptFunction("ntp.gotShouldShowApps", should_show_apps); | 183 web_ui()->CallJavascriptFunction("ntp.gotShouldShowApps", should_show_apps); |
| 183 } | 184 } |
| 184 | 185 |
| 185 // static | 186 // static |
| 186 void NewTabPageHandler::RegisterUserPrefs(PrefServiceSyncable* prefs) { | 187 void NewTabPageHandler::RegisterUserPrefs(PrefRegistrySyncable* registry) { |
| 187 // TODO(estade): should be syncable. | 188 // TODO(estade): should be syncable. |
| 188 prefs->RegisterIntegerPref(prefs::kNtpShownPage, APPS_PAGE_ID, | 189 registry->RegisterIntegerPref(prefs::kNtpShownPage, APPS_PAGE_ID, |
| 189 PrefServiceSyncable::UNSYNCABLE_PREF); | 190 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 190 } | 191 } |
| 191 | 192 |
| 192 // static | 193 // static |
| 193 void NewTabPageHandler::GetLocalizedValues(Profile* profile, | 194 void NewTabPageHandler::GetLocalizedValues(Profile* profile, |
| 194 DictionaryValue* values) { | 195 DictionaryValue* values) { |
| 195 values->SetInteger("most_visited_page_id", MOST_VISITED_PAGE_ID); | 196 values->SetInteger("most_visited_page_id", MOST_VISITED_PAGE_ID); |
| 196 values->SetInteger("apps_page_id", APPS_PAGE_ID); | 197 values->SetInteger("apps_page_id", APPS_PAGE_ID); |
| 197 values->SetInteger("suggestions_page_id", SUGGESTIONS_PAGE_ID); | 198 values->SetInteger("suggestions_page_id", SUGGESTIONS_PAGE_ID); |
| 198 // TODO(jeremycho): Add this to histograms.xml (see issue 144067). | 199 // TODO(jeremycho): Add this to histograms.xml (see issue 144067). |
| 199 values->SetInteger("recently_closed_page_id", RECENTLY_CLOSED_PAGE_ID); | 200 values->SetInteger("recently_closed_page_id", RECENTLY_CLOSED_PAGE_ID); |
| 200 // TODO(vadimt): Add this to histograms.xml (see issue 148871). | 201 // TODO(vadimt): Add this to histograms.xml (see issue 148871). |
| 201 values->SetInteger("other_devices_page_id", OTHER_DEVICES_PAGE_ID); | 202 values->SetInteger("other_devices_page_id", OTHER_DEVICES_PAGE_ID); |
| 202 | 203 |
| 203 PrefService* prefs = profile->GetPrefs(); | 204 PrefService* prefs = profile->GetPrefs(); |
| 204 int shown_page = prefs->GetInteger(prefs::kNtpShownPage); | 205 int shown_page = prefs->GetInteger(prefs::kNtpShownPage); |
| 205 values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK); | 206 values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK); |
| 206 values->SetInteger("shown_page_index", shown_page & INDEX_MASK); | 207 values->SetInteger("shown_page_index", shown_page & INDEX_MASK); |
| 207 } | 208 } |
| 208 | 209 |
| 209 void NewTabPageHandler::Notify(chrome::NotificationType notification_type) { | 210 void NewTabPageHandler::Notify(chrome::NotificationType notification_type) { |
| 210 content::NotificationService* service = | 211 content::NotificationService* service = |
| 211 content::NotificationService::current(); | 212 content::NotificationService::current(); |
| 212 service->Notify(notification_type, | 213 service->Notify(notification_type, |
| 213 content::Source<NewTabPageHandler>(this), | 214 content::Source<NewTabPageHandler>(this), |
| 214 content::NotificationService::NoDetails()); | 215 content::NotificationService::NoDetails()); |
| 215 } | 216 } |
| OLD | NEW |