1 // Copyright 2014 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/options/easy_unlock_handler.h"
10 #include "base/values.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/signin/easy_unlock_service.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "content/public/browser/web_ui.h"
18 EasyUnlockHandler::EasyUnlockHandler() {
21 EasyUnlockHandler::~EasyUnlockHandler() {
22 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this);
25 void EasyUnlockHandler::GetLocalizedValues(base::DictionaryValue
* values
) {
26 static OptionsStringResource resources
[] = {
27 {"easyUnlockTurnOffButton", IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_BUTTON
},
28 {"easyUnlockTurnOffTitle", IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_TITLE
},
29 {"easyUnlockTurnOffDescription",
30 IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_DESCRIPTION
},
31 {"easyUnlockTurnOffOfflineTitle",
32 IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_OFFLINE_TITLE
},
33 {"easyUnlockTurnOffOfflineMessage",
34 IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_OFFLINE_MESSAGE
},
35 {"easyUnlockTurnOffErrorTitle",
36 IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_ERROR_TITLE
},
37 {"easyUnlockTurnOffErrorMessage",
38 IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_ERROR_MESSAGE
},
39 {"easyUnlockTurnOffRetryButton",
40 IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_RETRY_BUTTON
},
43 RegisterStrings(values
, resources
, arraysize(resources
));
46 void EasyUnlockHandler::InitializeHandler() {
47 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->AddObserver(this);
50 void EasyUnlockHandler::RegisterMessages() {
51 web_ui()->RegisterMessageCallback(
52 "easyUnlockGetTurnOffFlowStatus",
53 base::Bind(&EasyUnlockHandler::HandleGetTurnOffFlowStatus
,
54 base::Unretained(this)));
55 web_ui()->RegisterMessageCallback(
56 "easyUnlockRequestTurnOff",
57 base::Bind(&EasyUnlockHandler::HandleRequestTurnOff
,
58 base::Unretained(this)));
59 web_ui()->RegisterMessageCallback(
60 "easyUnlockTurnOffOverlayDismissed",
61 base::Bind(&EasyUnlockHandler::HandlePageDismissed
,
62 base::Unretained(this)));
65 void EasyUnlockHandler::OnTurnOffOperationStatusChanged() {
66 SendTurnOffOperationStatus();
69 void EasyUnlockHandler::SendTurnOffOperationStatus() {
70 EasyUnlockService::TurnOffFlowStatus status
=
71 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))
72 ->GetTurnOffFlowStatus();
74 // Translate status into JS UI state string. Note the translated string
75 // should match UIState defined in easy_unlock_turn_off_overlay.js.
76 std::string status_string
;
78 case EasyUnlockService::IDLE
:
79 status_string
= "idle";
81 case EasyUnlockService::PENDING
:
82 status_string
= "pending";
84 case EasyUnlockService::FAIL
:
85 status_string
= "server-error";
88 LOG(ERROR
) << "Unknown Easy unlock turn-off operation status: " << status
;
89 status_string
= "idle";
92 web_ui()->CallJavascriptFunction("EasyUnlockTurnOffOverlay.updateUIState",
93 base::StringValue(status_string
));
96 void EasyUnlockHandler::HandleGetTurnOffFlowStatus(
97 const base::ListValue
* args
) {
98 SendTurnOffOperationStatus();
101 void EasyUnlockHandler::HandleRequestTurnOff(const base::ListValue
* args
) {
102 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->RunTurnOffFlow();
105 void EasyUnlockHandler::HandlePageDismissed(const base::ListValue
* args
) {
106 EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->ResetTurnOffFlow();
109 } // namespace options