Commit 88de962c authored by James Cook's avatar James Cook Committed by Commit Bot

chromeos: Refactor quick unlock WebUI handler out of PeopleHandler

PeopleHandler handles the browser settings "People" section and mostly
deals with sync. Long-term, we should not use it in OS settings.
Refactor the quick unlock settings WebUI handler into its own class.

Bug: 1013466
Test: manual, PIN unlock settings still work
Change-Id: I3601fcf56a899889710a607d2dd145e52be07f54
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2062793
Commit-Queue: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742458}
parent 6d28b0fe
......@@ -1995,6 +1995,8 @@ jumbo_static_library("ui") {
"webui/settings/chromeos/plugin_vm_handler.h",
"webui/settings/chromeos/pref_names.cc",
"webui/settings/chromeos/pref_names.h",
"webui/settings/chromeos/quick_unlock_handler.cc",
"webui/settings/chromeos/quick_unlock_handler.h",
"webui/settings/chromeos/search/settings_user_action_tracker.cc",
"webui/settings/chromeos/search/settings_user_action_tracker.h",
"webui/settings/chromeos/wallpaper_handler.cc",
......
......@@ -64,6 +64,7 @@
#include "chrome/browser/ui/webui/settings/chromeos/parental_controls_handler.h"
#include "chrome/browser/ui/webui/settings/chromeos/plugin_vm_handler.h"
#include "chrome/browser/ui/webui/settings/chromeos/pref_names.h"
#include "chrome/browser/ui/webui/settings/chromeos/quick_unlock_handler.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/settings_user_action_tracker.h"
#include "chrome/browser/ui/webui/settings/chromeos/wallpaper_handler.h"
#include "chrome/browser/ui/webui/settings/downloads_handler.h"
......@@ -316,6 +317,8 @@ void OSSettingsUI::InitOSWebUIHandlers(content::WebUIDataSource* html_source) {
}
web_ui()->AddMessageHandler(
std::make_unique<chromeos::settings::PointerHandler>());
web_ui()->AddMessageHandler(
std::make_unique<chromeos::settings::QuickUnlockHandler>());
web_ui()->AddMessageHandler(
std::make_unique<chromeos::settings::StorageHandler>(profile,
html_source));
......
// Copyright 2020 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/settings/chromeos/quick_unlock_handler.h"
#include "base/bind.h"
#include "chrome/browser/chromeos/login/quick_unlock/pin_backend.h"
#include "content/public/browser/web_ui.h"
namespace chromeos {
namespace settings {
QuickUnlockHandler::QuickUnlockHandler() = default;
QuickUnlockHandler::~QuickUnlockHandler() = default;
void QuickUnlockHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"RequestPinLoginState",
base::BindRepeating(&QuickUnlockHandler::HandleRequestPinLoginState,
base::Unretained(this)));
}
void QuickUnlockHandler::HandleRequestPinLoginState(
const base::ListValue* args) {
AllowJavascript();
quick_unlock::PinBackend::GetInstance()->HasLoginSupport(
base::BindOnce(&QuickUnlockHandler::OnPinLoginAvailable,
weak_ptr_factory_.GetWeakPtr()));
}
void QuickUnlockHandler::OnPinLoginAvailable(bool is_available) {
FireWebUIListener("pin-login-available-changed", base::Value(is_available));
}
} // namespace settings
} // namespace chromeos
// Copyright 2020 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_SETTINGS_CHROMEOS_QUICK_UNLOCK_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_QUICK_UNLOCK_HANDLER_H_
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
namespace base {
class ListValue;
} // namespace base
namespace chromeos {
namespace settings {
// Settings WebUI handler for quick unlock settings.
class QuickUnlockHandler : public ::settings::SettingsPageUIHandler {
public:
QuickUnlockHandler();
QuickUnlockHandler(const QuickUnlockHandler&) = delete;
QuickUnlockHandler& operator=(const QuickUnlockHandler&) = delete;
~QuickUnlockHandler() override;
// SettingsPageUIHandler:
void RegisterMessages() override;
void OnJavascriptAllowed() override {}
void OnJavascriptDisallowed() override {}
private:
void HandleRequestPinLoginState(const base::ListValue* args);
void OnPinLoginAvailable(bool is_available);
base::WeakPtrFactory<QuickUnlockHandler> weak_ptr_factory_{this};
};
} // namespace settings
} // namespace chromeos
#endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_QUICK_UNLOCK_HANDLER_H_
......@@ -63,7 +63,6 @@
#include "ui/gfx/image/image.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/login/quick_unlock/pin_backend.h"
#include "chromeos/constants/chromeos_features.h"
#else
#include "chrome/browser/signin/signin_util.h"
......@@ -318,10 +317,6 @@ void PeopleHandler::RegisterMessages() {
"AttemptUserExit",
base::BindRepeating(&PeopleHandler::HandleAttemptUserExit,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"RequestPinLoginState",
base::BindRepeating(&PeopleHandler::HandleRequestPinLoginState,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"TurnOnSync", base::BindRepeating(&PeopleHandler::HandleTurnOnSync,
base::Unretained(this)));
......@@ -430,12 +425,6 @@ void PeopleHandler::DisplayGaiaLoginInNewTabOrWindow(
}
#endif
#if defined(OS_CHROMEOS)
void PeopleHandler::OnPinLoginAvailable(bool is_available) {
FireWebUIListener("pin-login-available-changed", base::Value(is_available));
}
#endif
void PeopleHandler::OnDidClosePage(const base::ListValue* args) {
// Don't mark setup as complete if "didAbort" is true, or if authentication
// is still needed.
......@@ -730,13 +719,6 @@ void PeopleHandler::HandleAttemptUserExit(const base::ListValue* args) {
chrome::AttemptUserExit();
}
void PeopleHandler::HandleRequestPinLoginState(const base::ListValue* args) {
AllowJavascript();
chromeos::quick_unlock::PinBackend::GetInstance()->HasLoginSupport(
base::BindOnce(&PeopleHandler::OnPinLoginAvailable,
weak_factory_.GetWeakPtr()));
}
void PeopleHandler::HandleTurnOnSync(const base::ListValue* args) {
// TODO(https://crbug.com/1050677)
NOTIMPLEMENTED();
......
......@@ -157,7 +157,6 @@ class PeopleHandler : public SettingsPageUIHandler,
const base::ListValue* args);
#if defined(OS_CHROMEOS)
void HandleAttemptUserExit(const base::ListValue* args);
void HandleRequestPinLoginState(const base::ListValue* args);
void HandleTurnOnSync(const base::ListValue* args);
void HandleTurnOffSync(const base::ListValue* args);
#endif
......@@ -179,10 +178,6 @@ class PeopleHandler : public SettingsPageUIHandler,
signin_metrics::AccessPoint access_point);
#endif
#if defined(OS_CHROMEOS)
void OnPinLoginAvailable(bool is_available);
#endif
void OnQueryHistoryRecordingCompletion(
const std::string& webui_callback_id,
history::WebHistoryService::Request* request,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment