1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/options/easy_unlock_handler.h"
#include <string>
#include "base/bind.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/easy_unlock_service.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/web_ui.h"
namespace options {
EasyUnlockHandler::EasyUnlockHandler() {
}
EasyUnlockHandler::~EasyUnlockHandler() {
EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->RemoveObserver(this);
}
void EasyUnlockHandler::GetLocalizedValues(base::DictionaryValue* values) {
static OptionsStringResource resources[] = {
{"easyUnlockTurnOffButton", IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_BUTTON},
{"easyUnlockTurnOffTitle", IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_TITLE},
{"easyUnlockTurnOffDescription",
IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_DESCRIPTION},
{"easyUnlockTurnOffOfflineTitle",
IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_OFFLINE_TITLE},
{"easyUnlockTurnOffOfflineMessage",
IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_OFFLINE_MESSAGE},
{"easyUnlockTurnOffErrorTitle",
IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_ERROR_TITLE},
{"easyUnlockTurnOffErrorMessage",
IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_ERROR_MESSAGE},
{"easyUnlockTurnOffRetryButton",
IDS_OPTIONS_EASY_UNLOCK_TURN_OFF_RETRY_BUTTON},
};
RegisterStrings(values, resources, arraysize(resources));
}
void EasyUnlockHandler::InitializeHandler() {
EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->AddObserver(this);
}
void EasyUnlockHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"easyUnlockGetTurnOffFlowStatus",
base::Bind(&EasyUnlockHandler::HandleGetTurnOffFlowStatus,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"easyUnlockRequestTurnOff",
base::Bind(&EasyUnlockHandler::HandleRequestTurnOff,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"easyUnlockTurnOffOverlayDismissed",
base::Bind(&EasyUnlockHandler::HandlePageDismissed,
base::Unretained(this)));
}
void EasyUnlockHandler::OnTurnOffOperationStatusChanged() {
SendTurnOffOperationStatus();
}
void EasyUnlockHandler::SendTurnOffOperationStatus() {
EasyUnlockService::TurnOffFlowStatus status =
EasyUnlockService::Get(Profile::FromWebUI(web_ui()))
->GetTurnOffFlowStatus();
// Translate status into JS UI state string. Note the translated string
// should match UIState defined in easy_unlock_turn_off_overlay.js.
std::string status_string;
switch (status) {
case EasyUnlockService::IDLE:
status_string = "idle";
break;
case EasyUnlockService::PENDING:
status_string = "pending";
break;
case EasyUnlockService::FAIL:
status_string = "server-error";
break;
default:
LOG(ERROR) << "Unknown Easy unlock turn-off operation status: " << status;
status_string = "idle";
break;
}
web_ui()->CallJavascriptFunction("EasyUnlockTurnOffOverlay.updateUIState",
base::StringValue(status_string));
}
void EasyUnlockHandler::HandleGetTurnOffFlowStatus(
const base::ListValue* args) {
SendTurnOffOperationStatus();
}
void EasyUnlockHandler::HandleRequestTurnOff(const base::ListValue* args) {
EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->RunTurnOffFlow();
}
void EasyUnlockHandler::HandlePageDismissed(const base::ListValue* args) {
EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->ResetTurnOffFlow();
}
} // namespace options
|