1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/chromeos/charger_replacement_handler.h"
8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/pref_service.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chromeos/charger_replace/charger_link_dialog.h"
14 #include "chrome/browser/chromeos/charger_replace/charger_replacement_dialog.h"
15 #include "chrome/common/pref_names.h"
16 #include "content/public/browser/user_metrics.h"
17 #include "content/public/browser/web_ui.h"
18 #include "grit/generated_resources.h"
19 #include "ui/base/l10n/l10n_util.h"
25 const char kFaqLink
[] = "http://chromebook.com/hp11charger";
29 ChargerReplacementHandler::ChargerReplacementHandler(
30 ChargerReplacementDialog
* dialog
)
31 : charger_window_(NULL
),
35 ChargerReplacementHandler::~ChargerReplacementHandler() {
38 void ChargerReplacementHandler::RegisterMessages() {
39 web_ui()->RegisterMessageCallback("confirmSafeCharger",
40 base::Bind(&ChargerReplacementHandler::ConfirmSafeCharger
,
41 base::Unretained(this)));
42 web_ui()->RegisterMessageCallback("confirmNotOrderNewCharger",
43 base::Bind(&ChargerReplacementHandler::ConfirmNotOrderNewCharger
,
44 base::Unretained(this)));
45 web_ui()->RegisterMessageCallback("confirmChargerOrderedOnline",
46 base::Bind(&ChargerReplacementHandler::ConfirmChargerOrderedOnline
,
47 base::Unretained(this)));
48 web_ui()->RegisterMessageCallback("confirmChargerOrderByPhone",
49 base::Bind(&ChargerReplacementHandler::ConfirmChargerOrderByPhone
,
50 base::Unretained(this)));
51 web_ui()->RegisterMessageCallback("confirmStillUseBadCharger",
52 base::Bind(&ChargerReplacementHandler::ConfirmStillUseBadCharger
,
53 base::Unretained(this)));
54 web_ui()->RegisterMessageCallback("showLink",
55 base::Bind(&ChargerReplacementHandler::ShowLink
,
56 base::Unretained(this)));
60 void ChargerReplacementHandler::GetLocalizedValues(
61 base::DictionaryValue
* localized_strings
) {
62 localized_strings
->SetString(
64 l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_CHECK_CHARGER_TITLE
));
65 localized_strings
->SetString(
67 l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_CHECK_CHARGER_DAMAGE
));
68 localized_strings
->SetString(
69 "checkOriginalCharger",
70 l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_CHECK_ORIGNAL_CHARGER
));
71 localized_strings
->SetString(
72 "whereDevicePurchased",
73 l10n_util::GetStringUTF16(
74 IDS_CHARGER_REPLACEMENT_WHERE_DEVICE_PURCHASED
));
75 localized_strings
->SetString(
77 l10n_util::GetStringUTF16(
78 IDS_CHARGER_REPLACEMENT_SELECT_A_COUNTRY
));
79 localized_strings
->SetString(
81 l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_US
));
82 localized_strings
->SetString(
84 l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_CA
));
85 localized_strings
->SetString(
87 l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_UK
));
88 localized_strings
->SetString(
90 l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_AU
));
91 localized_strings
->SetString(
93 l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_IRE
));
94 localized_strings
->SetString(
95 "checkChargerSelectCharger",
96 l10n_util::GetStringUTF16(
97 IDS_CHARGER_REPLACEMENT_CHECK_CHARGER_SELECT_CHARGER
));
98 localized_strings
->SetString(
100 l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_NEXT_STEP
));
101 localized_strings
->SetString(
102 "confirmSafeChargerTitle",
103 l10n_util::GetStringUTF16(
104 IDS_CHARGER_REPLACEMENT_CONFIRM_SAFE_CHARGER_TITLE
));
105 localized_strings
->SetString(
107 l10n_util::GetStringUTF16(
108 IDS_CHARGER_REPLACEMENT_CONFIRM_SAFE_CHARGER_TO_GO
));
109 localized_strings
->SetString(
111 l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_PREVIOUS_STEP
));
112 localized_strings
->SetString(
114 l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_FINISH
));
115 localized_strings
->SetString(
116 "chargerUpdateTitle",
117 l10n_util::GetStringUTF16(
118 IDS_CHARGER_REPLACEMENT_CHARGER_UPDATE_TITLE
));
119 localized_strings
->SetString(
121 l10n_util::GetStringUTF16(
122 IDS_CHARGER_REPLACEMENT_CHARGER_UPDATE_P1
));
123 localized_strings
->SetString(
124 "stopUsingRecalledCharger",
125 l10n_util::GetStringUTF16(
126 IDS_CHARGER_REPLACEMENT_CHARGER_STOP_USING_RECALLED_CHARGER
));
127 localized_strings
->SetString(
129 l10n_util::GetStringUTF16(
130 IDS_CHARGER_REPLACEMENT_CHARGER_UPDATE_P2
));
131 localized_strings
->SetString(
133 l10n_util::GetStringUTF16(
134 IDS_CHARGER_REPLACEMENT_CHARGER_UPDATE_FAQ
));
135 localized_strings
->SetString(
137 l10n_util::GetStringUTF16(
138 IDS_CHARGER_REPLACEMENT_CHARGER_ORDER_NEW_CHARGER
));
139 localized_strings
->SetString(
140 "notOrderNewCharger",
141 l10n_util::GetStringUTF16(
142 IDS_CHARGER_REPLACEMENT_CHARGER_NOT_ORDER_NEW_CHARGER
));
143 localized_strings
->SetString(
144 "confirmNotOrderNewCharger",
145 l10n_util::GetStringUTF16(
146 IDS_CHARGER_REPLACEMENT_CHARGER_CONIFRM_NOT_ORDER_CHARGER
));
147 localized_strings
->SetString(
149 l10n_util::GetStringUTF16(
150 IDS_CHARGER_REPLACEMENT_NO_MOPE_MESSAGE_SHOW
));
151 localized_strings
->SetString(
152 "finishNotOrderChargerTitle",
153 l10n_util::GetStringUTF16(
154 IDS_CHARGER_REPLACEMENT_FINISH_NOT_ORDER_CHARGER_TITLE
));
155 localized_strings
->SetString(
156 "finishNotOrderChargerP2",
157 l10n_util::GetStringUTF16(
158 IDS_CHARGER_REPLACEMENT_FINISH_NOT_ORDER_CHARGER_P2
));
159 localized_strings
->SetString(
160 "finishNotOrderChargerMoreInfo",
161 l10n_util::GetStringUTF16(
162 IDS_CHARGER_REPLACEMENT_FINISH_NOT_ORDER_CHARGER_MORE_INFO
));
164 localized_strings
->SetString(
165 "confirmOnlineOrder",
166 l10n_util::GetStringUTF16(
167 IDS_CHARGER_REPLACEMENT_ONLINE_ORDER_CONFIRMATION_TITLE
));
168 localized_strings
->SetString(
169 "confirmReceivingOnlineOrder",
170 l10n_util::GetStringUTF16(
171 IDS_CHARGER_REPLACEMENT_ONLINE_ORDER_CONFIRMATION_MESSAGE
));
172 localized_strings
->SetString(
173 "needMoreInformation",
174 l10n_util::GetStringUTF16(IDS_CHARGER_REPLACEMENT_FIND_MORE_INFORMATION
));
175 localized_strings
->SetString(
176 "orderChargerOfflineTitle",
177 l10n_util::GetStringUTF16(
178 IDS_CHARGER_REPLACEMENT_OFFLINE_ORDER_TITLE
));
179 localized_strings
->SetString(
180 "offlineChargerOrderParagraph1",
181 l10n_util::GetStringUTF16(
182 IDS_CHARGER_REPLACEMENT_OFFLINE_ORDER_P1
));
183 localized_strings
->SetString(
184 "offlineChargerOrderParagraph2",
185 l10n_util::GetStringUTF16(
186 IDS_CHARGER_REPLACEMENT_OFFLINE_ORDER_P2
));
187 localized_strings
->SetString(
188 "offlineSafeChargerConfirmationText",
189 l10n_util::GetStringUTF16(
190 IDS_CHARGER_REPLACEMENT_OFFLINE_ORDER_CONFIRM
));
191 localized_strings
->SetString(
193 l10n_util::GetStringUTF16(
194 IDS_CHARGER_REPLACEMENT_TEXT_PRIVACY_POLICY
));
195 localized_strings
->SetString(
196 "offlineOrderPhoneNumber",
197 l10n_util::GetStringUTF16(
198 IDS_CHARGER_REPLACEMENT_OFFLINE_ORDER_PHONE_NUMBER
));
199 localized_strings
->SetString(
200 "offlineOrderPhoneNumber",
201 l10n_util::GetStringUTF16(
202 IDS_CHARGER_REPLACEMENT_OFFLINE_ORDER_PHONE_NUMBER
));
203 localized_strings
->SetString(
204 "chargerStillBadTitle",
205 l10n_util::GetStringUTF16(
206 IDS_CHARGER_REPLACEMENT_CHARGER_STILL_BAD
));
207 localized_strings
->SetString(
209 l10n_util::GetStringUTF16(
210 IDS_CHARGER_REPLACEMENT_CHARGER_ORDERED
));
211 localized_strings
->SetString(
213 l10n_util::GetStringUTF16(
214 IDS_CHARGER_REPLACEMENT_CHARGER_MORE_INFO
));
215 localized_strings
->SetString("faqLink", kFaqLink
);
219 void ChargerReplacementHandler::RegisterPrefs(PrefRegistrySimple
* registry
) {
220 registry
->RegisterIntegerPref(prefs::kSpringChargerCheck
, CHARGER_UNKNOWN
);
224 ChargerReplacementHandler::SpringChargerStatus
225 ChargerReplacementHandler::GetChargerStatusPref() {
226 ChargerReplacementHandler::SpringChargerStatus charger_status
=
227 static_cast<ChargerReplacementHandler::SpringChargerStatus
>(
228 g_browser_process
->local_state()->GetInteger(prefs::kSpringChargerCheck
));
229 return charger_status
;
233 void ChargerReplacementHandler::SetChargerStatusPref(
234 SpringChargerStatus status
) {
235 g_browser_process
->local_state()->SetInteger(prefs::kSpringChargerCheck
,
239 void ChargerReplacementHandler::ConfirmSafeCharger(
240 const base::ListValue
* args
) {
241 content::RecordAction(
242 base::UserMetricsAction("ConfirmSafeSpringCharger"));
244 SetChargerStatusPref(CONFIRM_SAFE_CHARGER
);
245 dialog_
->set_can_close(true);
248 void ChargerReplacementHandler::ConfirmNotOrderNewCharger(
249 const base::ListValue
* args
) {
250 content::RecordAction(
251 base::UserMetricsAction("ConfirmNotToOrderSpringCharger"));
253 SetChargerStatusPref(CONFIRM_NOT_ORDER_NEW_CHARGER
);
254 dialog_
->set_can_close(true);
257 void ChargerReplacementHandler::ConfirmChargerOrderedOnline(
258 const base::ListValue
* args
) {
259 content::RecordAction(
260 base::UserMetricsAction("ConfirmOrderSpringChargerOnline"));
261 content::RecordAction(
262 base::UserMetricsAction("ConfirmOrderSpringCharger"));
264 SetChargerStatusPref(CONFIRM_NEW_CHARGER_ORDERED_ONLINE
);
265 dialog_
->set_can_close(true);
268 void ChargerReplacementHandler::ConfirmChargerOrderByPhone(
269 const base::ListValue
* args
) {
270 content::RecordAction(
271 base::UserMetricsAction("ConfirmOrderSpringChargerByPhone"));
272 content::RecordAction(
273 base::UserMetricsAction("ConfirmOrderSpringCharger"));
275 SetChargerStatusPref(CONFIRM_ORDER_NEW_CHARGER_BY_PHONE
);
276 dialog_
->set_can_close(true);
279 void ChargerReplacementHandler::ConfirmStillUseBadCharger(
280 const base::ListValue
* args
) {
281 content::RecordAction(
282 base::UserMetricsAction("ConfirmStillUseOriginalChargerAfterOrder"));
284 if (GetChargerStatusPref() == CONFIRM_NEW_CHARGER_ORDERED_ONLINE
) {
285 SetChargerStatusPref(USE_BAD_CHARGER_AFTER_ORDER_ONLINE
);
287 DCHECK(GetChargerStatusPref() == CONFIRM_ORDER_NEW_CHARGER_BY_PHONE
);
288 SetChargerStatusPref(USE_BAD_CHARGER_AFTER_ORDER_BY_PHONE
);
290 dialog_
->set_can_close(true);
293 void ChargerReplacementHandler::ShowLink(const base::ListValue
* args
) {
294 std::string url
= base::UTF16ToUTF8(ExtractStringValue(args
));
295 ChargerLinkDialog
* dialog
= new ChargerLinkDialog(charger_window_
, url
);
299 } // namespace chromeos