summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/ui/webui')
-rw-r--r--chrome/browser/ui/webui/options/browser_options_handler.cc19
-rw-r--r--chrome/browser/ui/webui/options/easy_unlock_handler.cc107
-rw-r--r--chrome/browser/ui/webui/options/easy_unlock_handler.h43
-rw-r--r--chrome/browser/ui/webui/options/options_ui.cc2
4 files changed, 155 insertions, 16 deletions
diff --git a/chrome/browser/ui/webui/options/browser_options_handler.cc b/chrome/browser/ui/webui/options/browser_options_handler.cc
index d33ad33..1863c7d 100644
--- a/chrome/browser/ui/webui/options/browser_options_handler.cc
+++ b/chrome/browser/ui/webui/options/browser_options_handler.cc
@@ -250,20 +250,6 @@ void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue* values) {
{ "easyUnlockSectionTitle", IDS_OPTIONS_EASY_UNLOCK_SECTION_TITLE },
{ "easyUnlockSetupButton", IDS_OPTIONS_EASY_UNLOCK_SETUP_BUTTON },
{ "easyUnlockSetupIntro", IDS_OPTIONS_EASY_UNLOCK_SETUP_INTRO },
- { "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 },
{ "extensionControlled", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED },
{ "extensionDisable", IDS_OPTIONS_TAB_EXTENSION_CONTROLLED_DISABLE },
{ "fontSettingsCustomizeFontsButton",
@@ -1838,8 +1824,9 @@ void BrowserOptionsHandler::SetupManagingSupervisedUsers() {
void BrowserOptionsHandler::SetupEasyUnlock() {
// TODO(xiyuan): Update when pairing data is really availble.
- bool has_pairing = !Profile::FromWebUI(web_ui())->GetPrefs()
- ->GetDictionary(prefs::kEasyUnlockPairing)->empty();
+ const base::ListValue* devices =
+ EasyUnlockService::Get(Profile::FromWebUI(web_ui()))->GetRemoteDevices();
+ bool has_pairing = devices && !devices->empty();
base::FundamentalValue has_pairing_value(has_pairing);
web_ui()->CallJavascriptFunction(
"BrowserOptions.updateEasyUnlock",
diff --git a/chrome/browser/ui/webui/options/easy_unlock_handler.cc b/chrome/browser/ui/webui/options/easy_unlock_handler.cc
new file mode 100644
index 0000000..493a6d7
--- /dev/null
+++ b/chrome/browser/ui/webui/options/easy_unlock_handler.cc
@@ -0,0 +1,107 @@
+// 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 "base/bind.h"
+#include "base/values.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/signin/easy_unlock_service.h"
+#include "content/public/browser/web_ui.h"
+#include "grit/generated_resources.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()))
+ ->turn_off_flow_status();
+
+ // 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
diff --git a/chrome/browser/ui/webui/options/easy_unlock_handler.h b/chrome/browser/ui/webui/options/easy_unlock_handler.h
new file mode 100644
index 0000000..24173fa
--- /dev/null
+++ b/chrome/browser/ui/webui/options/easy_unlock_handler.h
@@ -0,0 +1,43 @@
+// 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.
+
+#ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_EASY_UNLOCK_HANDLER_H_
+#define CHROME_BROWSER_UI_WEBUI_OPTIONS_EASY_UNLOCK_HANDLER_H_
+
+#include "base/macros.h"
+#include "chrome/browser/signin/easy_unlock_service_observer.h"
+#include "chrome/browser/ui/webui/options/options_ui.h"
+
+namespace options {
+
+class EasyUnlockHandler : public OptionsPageUIHandler,
+ public EasyUnlockServiceObserver {
+ public:
+ EasyUnlockHandler();
+ virtual ~EasyUnlockHandler();
+
+ // OptionsPageUIHandler
+ virtual void InitializeHandler() OVERRIDE;
+ virtual void GetLocalizedValues(base::DictionaryValue* values) OVERRIDE;
+
+ // WebUIMessageHandler
+ virtual void RegisterMessages() OVERRIDE;
+
+ // EasyUnlockServiceObserver
+ virtual void OnTurnOffOperationStatusChanged() OVERRIDE;
+
+ private:
+ void SendTurnOffOperationStatus();
+
+ // JS callbacks.
+ void HandleGetTurnOffFlowStatus(const base::ListValue* args);
+ void HandleRequestTurnOff(const base::ListValue* args);
+ void HandlePageDismissed(const base::ListValue* args);
+
+ DISALLOW_COPY_AND_ASSIGN(EasyUnlockHandler);
+};
+
+} // namespace options
+
+#endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_EASY_UNLOCK_HANDLER_H_
diff --git a/chrome/browser/ui/webui/options/options_ui.cc b/chrome/browser/ui/webui/options/options_ui.cc
index 14a49f3..4a703e2 100644
--- a/chrome/browser/ui/webui/options/options_ui.cc
+++ b/chrome/browser/ui/webui/options/options_ui.cc
@@ -30,6 +30,7 @@
#include "chrome/browser/ui/webui/options/cookies_view_handler.h"
#include "chrome/browser/ui/webui/options/core_options_handler.h"
#include "chrome/browser/ui/webui/options/create_profile_handler.h"
+#include "chrome/browser/ui/webui/options/easy_unlock_handler.h"
#include "chrome/browser/ui/webui/options/font_settings_handler.h"
#include "chrome/browser/ui/webui/options/handler_options_handler.h"
#include "chrome/browser/ui/webui/options/home_page_overlay_handler.h"
@@ -273,6 +274,7 @@ OptionsUI::OptionsUI(content::WebUI* web_ui)
AddOptionsPageUIHandler(localized_strings, new ContentSettingsHandler());
AddOptionsPageUIHandler(localized_strings, new CookiesViewHandler());
AddOptionsPageUIHandler(localized_strings, new CreateProfileHandler());
+ AddOptionsPageUIHandler(localized_strings, new EasyUnlockHandler());
AddOptionsPageUIHandler(localized_strings, new FontSettingsHandler());
#if defined(ENABLE_GOOGLE_NOW)
AddOptionsPageUIHandler(localized_strings, new GeolocationOptionsHandler());