| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/common/pref_names.h" | 7 #include "chrome/common/pref_names.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/sync/profile_sync_service.h" |
| 10 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 11 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 11 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
| 12 #include "content/common/notification_service.h" | 13 #include "content/common/notification_service.h" |
| 13 | 14 |
| 14 void NewTabPageHandler::RegisterMessages() { | 15 void NewTabPageHandler::RegisterMessages() { |
| 15 web_ui_->RegisterMessageCallback("closePromo", NewCallback( | 16 web_ui_->RegisterMessageCallback("closePromo", NewCallback( |
| 16 this, &NewTabPageHandler::HandleClosePromo)); | 17 this, &NewTabPageHandler::HandleClosePromo)); |
| 18 web_ui_->RegisterMessageCallback("closeSyncNotification", NewCallback( |
| 19 this, &NewTabPageHandler::HandleCloseSyncNotification)); |
| 17 web_ui_->RegisterMessageCallback("pageSelected", NewCallback( | 20 web_ui_->RegisterMessageCallback("pageSelected", NewCallback( |
| 18 this, &NewTabPageHandler::HandlePageSelected)); | 21 this, &NewTabPageHandler::HandlePageSelected)); |
| 19 } | 22 } |
| 20 | 23 |
| 21 void NewTabPageHandler::HandleClosePromo(const ListValue* args) { | 24 void NewTabPageHandler::HandleClosePromo(const ListValue* args) { |
| 22 web_ui_->GetProfile()->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed, true); | 25 web_ui_->GetProfile()->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed, true); |
| 23 NotificationService* service = NotificationService::current(); | 26 NotificationService* service = NotificationService::current(); |
| 24 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, | 27 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
| 25 Source<NewTabPageHandler>(this), | 28 Source<NewTabPageHandler>(this), |
| 26 NotificationService::NoDetails()); | 29 NotificationService::NoDetails()); |
| 27 } | 30 } |
| 28 | 31 |
| 32 void NewTabPageHandler::HandleCloseSyncNotification(const ListValue* args) { |
| 33 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); |
| 34 if (service) |
| 35 service->AcknowledgeSyncedTypes(); |
| 36 } |
| 37 |
| 29 void NewTabPageHandler::HandlePageSelected(const ListValue* args) { | 38 void NewTabPageHandler::HandlePageSelected(const ListValue* args) { |
| 30 double page_id_double; | 39 double page_id_double; |
| 31 CHECK(args->GetDouble(0, &page_id_double)); | 40 CHECK(args->GetDouble(0, &page_id_double)); |
| 32 int page_id = static_cast<int>(page_id_double); | 41 int page_id = static_cast<int>(page_id_double); |
| 33 | 42 |
| 34 double index_double; | 43 double index_double; |
| 35 CHECK(args->GetDouble(1, &index_double)); | 44 CHECK(args->GetDouble(1, &index_double)); |
| 36 int index = static_cast<int>(index_double); | 45 int index = static_cast<int>(index_double); |
| 37 | 46 |
| 38 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 47 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 54 | 63 |
| 55 values->SetInteger("most_visited_page_id", MOST_VISITED_PAGE_ID); | 64 values->SetInteger("most_visited_page_id", MOST_VISITED_PAGE_ID); |
| 56 values->SetInteger("apps_page_id", APPS_PAGE_ID); | 65 values->SetInteger("apps_page_id", APPS_PAGE_ID); |
| 57 values->SetInteger("bookmarks_page_id", BOOKMARKS_PAGE_ID); | 66 values->SetInteger("bookmarks_page_id", BOOKMARKS_PAGE_ID); |
| 58 | 67 |
| 59 PrefService* prefs = profile->GetPrefs(); | 68 PrefService* prefs = profile->GetPrefs(); |
| 60 int shown_page = prefs->GetInteger(prefs::kNTPShownPage); | 69 int shown_page = prefs->GetInteger(prefs::kNTPShownPage); |
| 61 values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK); | 70 values->SetInteger("shown_page_type", shown_page & ~INDEX_MASK); |
| 62 values->SetInteger("shown_page_index", shown_page & INDEX_MASK); | 71 values->SetInteger("shown_page_index", shown_page & INDEX_MASK); |
| 63 } | 72 } |
| OLD | NEW |