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/browser/prefs/pref_service.h" | 7 #include "chrome/browser/prefs/pref_service.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/sync/profile_sync_service.h" | 9 #include "chrome/browser/sync/profile_sync_service.h" |
10 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 10 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 11 #include "chrome/browser/web_resource/notification_promo.h" |
11 #include "chrome/common/chrome_notification_types.h" | 12 #include "chrome/common/chrome_notification_types.h" |
12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
13 #include "content/common/notification_service.h" | 14 #include "content/common/notification_service.h" |
14 #include "grit/chromium_strings.h" | 15 #include "grit/chromium_strings.h" |
15 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
17 | 18 |
18 static const int kIntroDisplayMax = 10; | 19 static const int kIntroDisplayMax = 10; |
19 | 20 |
20 // The URL of a knowledge-base article about the new NTP. | 21 // The URL of a knowledge-base article about the new NTP. |
21 static const char kNTP4IntroURL[] = | 22 static const char kNTP4IntroURL[] = |
22 "http://www.google.com/support/chrome/bin/answer.py?answer=95451"; | 23 "http://www.google.com/support/chrome/bin/answer.py?answer=95451"; |
23 | 24 |
24 void NewTabPageHandler::RegisterMessages() { | 25 void NewTabPageHandler::RegisterMessages() { |
25 web_ui_->RegisterMessageCallback("closePromo", NewCallback( | 26 web_ui_->RegisterMessageCallback("closeNotificationPromo", NewCallback( |
26 this, &NewTabPageHandler::HandleClosePromo)); | 27 this, &NewTabPageHandler::HandleCloseNotificationPromo)); |
| 28 web_ui_->RegisterMessageCallback("notificationPromoViewed", NewCallback( |
| 29 this, &NewTabPageHandler::HandleNotificationPromoViewed)); |
27 web_ui_->RegisterMessageCallback("pageSelected", NewCallback( | 30 web_ui_->RegisterMessageCallback("pageSelected", NewCallback( |
28 this, &NewTabPageHandler::HandlePageSelected)); | 31 this, &NewTabPageHandler::HandlePageSelected)); |
29 web_ui_->RegisterMessageCallback("introMessageDismissed", NewCallback( | 32 web_ui_->RegisterMessageCallback("introMessageDismissed", NewCallback( |
30 this, &NewTabPageHandler::HandleIntroMessageDismissed)); | 33 this, &NewTabPageHandler::HandleIntroMessageDismissed)); |
31 web_ui_->RegisterMessageCallback("introMessageSeen", NewCallback( | 34 web_ui_->RegisterMessageCallback("introMessageSeen", NewCallback( |
32 this, &NewTabPageHandler::HandleIntroMessageSeen)); | 35 this, &NewTabPageHandler::HandleIntroMessageSeen)); |
33 } | 36 } |
34 | 37 |
35 void NewTabPageHandler::HandleClosePromo(const ListValue* args) { | 38 void NewTabPageHandler::HandleCloseNotificationPromo(const ListValue* args) { |
36 Profile::FromWebUI(web_ui_)->GetPrefs()->SetBoolean(prefs::kNTPPromoClosed, | 39 NotificationPromo notification_promo( |
37 true); | 40 Profile::FromWebUI(web_ui_)->GetPrefs(), NULL); |
38 NotificationService* service = NotificationService::current(); | 41 notification_promo.HandleClosed(); |
39 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, | 42 NotifyPromoResourceChanged(); |
40 Source<NewTabPageHandler>(this), | 43 } |
41 NotificationService::NoDetails()); | 44 |
| 45 void NewTabPageHandler::HandleNotificationPromoViewed(const ListValue* args) { |
| 46 NotificationPromo notification_promo( |
| 47 Profile::FromWebUI(web_ui_)->GetPrefs(), NULL); |
| 48 if (notification_promo.HandleViewed()) { |
| 49 NotifyPromoResourceChanged(); |
| 50 } |
42 } | 51 } |
43 | 52 |
44 void NewTabPageHandler::HandlePageSelected(const ListValue* args) { | 53 void NewTabPageHandler::HandlePageSelected(const ListValue* args) { |
45 double page_id_double; | 54 double page_id_double; |
46 CHECK(args->GetDouble(0, &page_id_double)); | 55 CHECK(args->GetDouble(0, &page_id_double)); |
47 int page_id = static_cast<int>(page_id_double); | 56 int page_id = static_cast<int>(page_id_double); |
48 | 57 |
49 double index_double; | 58 double index_double; |
50 CHECK(args->GetDouble(1, &index_double)); | 59 CHECK(args->GetDouble(1, &index_double)); |
51 int index = static_cast<int>(index_double); | 60 int index = static_cast<int>(index_double); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 values->SetString("ntp4_intro_url", kNTP4IntroURL); | 105 values->SetString("ntp4_intro_url", kNTP4IntroURL); |
97 values->SetString("learn_more", | 106 values->SetString("learn_more", |
98 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | 107 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
99 } | 108 } |
100 } | 109 } |
101 | 110 |
102 // static | 111 // static |
103 void NewTabPageHandler::DismissIntroMessage(PrefService* prefs) { | 112 void NewTabPageHandler::DismissIntroMessage(PrefService* prefs) { |
104 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1); | 113 prefs->SetInteger(prefs::kNTP4IntroDisplayCount, kIntroDisplayMax + 1); |
105 } | 114 } |
| 115 |
| 116 void NewTabPageHandler::NotifyPromoResourceChanged() { |
| 117 NotificationService* service = NotificationService::current(); |
| 118 service->Notify(chrome::NOTIFICATION_PROMO_RESOURCE_STATE_CHANGED, |
| 119 Source<NewTabPageHandler>(this), |
| 120 NotificationService::NoDetails()); |
| 121 } |
OLD | NEW |