Skip to content

Commit

Permalink
Convert some instances of WebUI::DeprecatedMessageCallback to
Browse files Browse the repository at this point in the history
WebUI::MessageCallback

Part of code health rotation

Split of https://crrev.com/c/3529288, converts instances
in /chrome/browser/ui/webui/signin

Also remove ListValue forward declaration as per presubmit checks

This does not fix all usages of the deprecated interface

This CL was uploaded by git cl split.

R=msarda@chromium.org

Bug: 1243386
Change-Id: I1f732d7c4d127545fd350e13f345dfbcd00addb5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3546059
Reviewed-by: Mihai Sardarescu <msarda@chromium.org>
Auto-Submit: Michael Wilson <mjwilson@chromium.org>
Commit-Queue: Michael Wilson <mjwilson@chromium.org>
Cr-Commit-Position: refs/heads/main@{#985055}
  • Loading branch information
Michael Wilson authored and Chromium LUCI CQ committed Mar 24, 2022
1 parent 9ae4de4 commit faeef00
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 52 deletions.
Expand Up @@ -60,18 +60,18 @@ DiceWebSigninInterceptHandler::DiceWebSigninInterceptHandler(
DiceWebSigninInterceptHandler::~DiceWebSigninInterceptHandler() = default;

void DiceWebSigninInterceptHandler::RegisterMessages() {
web_ui()->RegisterDeprecatedMessageCallback(
web_ui()->RegisterMessageCallback(
"accept",
base::BindRepeating(&DiceWebSigninInterceptHandler::HandleAccept,
base::Unretained(this)));
web_ui()->RegisterDeprecatedMessageCallback(
web_ui()->RegisterMessageCallback(
"cancel",
base::BindRepeating(&DiceWebSigninInterceptHandler::HandleCancel,
base::Unretained(this)));
web_ui()->RegisterDeprecatedMessageCallback(
web_ui()->RegisterMessageCallback(
"guest", base::BindRepeating(&DiceWebSigninInterceptHandler::HandleGuest,
base::Unretained(this)));
web_ui()->RegisterDeprecatedMessageCallback(
web_ui()->RegisterMessageCallback(
"pageLoaded",
base::BindRepeating(&DiceWebSigninInterceptHandler::HandlePageLoaded,
base::Unretained(this)));
Expand Down Expand Up @@ -115,23 +115,25 @@ const AccountInfo& DiceWebSigninInterceptHandler::intercepted_account() {
return bubble_parameters_.intercepted_account;
}

void DiceWebSigninInterceptHandler::HandleAccept(const base::ListValue* args) {
void DiceWebSigninInterceptHandler::HandleAccept(
const base::Value::List& args) {
if (callback_)
std::move(callback_).Run(SigninInterceptionUserChoice::kAccept);
}

void DiceWebSigninInterceptHandler::HandleCancel(const base::ListValue* args) {
void DiceWebSigninInterceptHandler::HandleCancel(
const base::Value::List& args) {
if (callback_)
std::move(callback_).Run(SigninInterceptionUserChoice::kDecline);
}

void DiceWebSigninInterceptHandler::HandleGuest(const base::ListValue* args) {
void DiceWebSigninInterceptHandler::HandleGuest(const base::Value::List& args) {
if (callback_)
std::move(callback_).Run(SigninInterceptionUserChoice::kGuest);
}

void DiceWebSigninInterceptHandler::HandlePageLoaded(
const base::ListValue* args) {
const base::Value::List& args) {
AllowJavascript();

// Update the account info and the images.
Expand All @@ -153,7 +155,8 @@ void DiceWebSigninInterceptHandler::HandlePageLoaded(
if (primary_account().given_name.empty())
bubble_parameters_.primary_account.given_name = primary_account().email;

const base::Value& callback_id = args->GetListDeprecated()[0];
DCHECK(!args.empty());
const base::Value& callback_id = args[0];
ResolveJavascriptCallback(callback_id, GetInterceptionParametersValue());
}

Expand Down
Expand Up @@ -16,10 +16,6 @@
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"

namespace base {
class ListValue;
}

// WebUI message handler for the Dice web signin intercept bubble.
class DiceWebSigninInterceptHandler : public content::WebUIMessageHandler,
public signin::IdentityManager::Observer {
Expand All @@ -46,10 +42,10 @@ class DiceWebSigninInterceptHandler : public content::WebUIMessageHandler,
const AccountInfo& primary_account();
const AccountInfo& intercepted_account();

void HandleAccept(const base::ListValue* args);
void HandleCancel(const base::ListValue* args);
void HandleGuest(const base::ListValue* args);
void HandlePageLoaded(const base::ListValue* args);
void HandleAccept(const base::Value::List& args);
void HandleCancel(const base::Value::List& args);
void HandleGuest(const base::Value::List& args);
void HandlePageLoaded(const base::Value::List& args);

// Gets the values sent to javascript.
base::Value GetAccountInfoValue(const AccountInfo& info);
Expand Down
17 changes: 8 additions & 9 deletions chrome/browser/ui/webui/signin/profile_customization_handler.cc
Expand Up @@ -40,11 +40,11 @@ ProfileCustomizationHandler::~ProfileCustomizationHandler() = default;

void ProfileCustomizationHandler::RegisterMessages() {
profile_path_ = Profile::FromWebUI(web_ui())->GetPath();
web_ui()->RegisterDeprecatedMessageCallback(
web_ui()->RegisterMessageCallback(
"initialized",
base::BindRepeating(&ProfileCustomizationHandler::HandleInitialized,
base::Unretained(this)));
web_ui()->RegisterDeprecatedMessageCallback(
web_ui()->RegisterMessageCallback(
"done", base::BindRepeating(&ProfileCustomizationHandler::HandleDone,
base::Unretained(this)));
}
Expand Down Expand Up @@ -85,17 +85,16 @@ void ProfileCustomizationHandler::OnProfileNameChanged(
}

void ProfileCustomizationHandler::HandleInitialized(
const base::ListValue* args) {
CHECK_EQ(1u, args->GetListDeprecated().size());
const base::Value::List& args) {
CHECK_EQ(1u, args.size());
AllowJavascript();
const base::Value& callback_id = args->GetListDeprecated()[0];
const base::Value& callback_id = args[0];
ResolveJavascriptCallback(callback_id, GetProfileInfoValue());
}

void ProfileCustomizationHandler::HandleDone(const base::ListValue* args) {
CHECK_EQ(1u, args->GetListDeprecated().size());
std::u16string profile_name =
base::UTF8ToUTF16(args->GetListDeprecated()[0].GetString());
void ProfileCustomizationHandler::HandleDone(const base::Value::List& args) {
CHECK_EQ(1u, args.size());
std::u16string profile_name = base::UTF8ToUTF16(args[0].GetString());

base::TrimWhitespace(profile_name, base::TRIM_ALL, &profile_name);
DCHECK(!profile_name.empty());
Expand Down
Expand Up @@ -12,10 +12,6 @@
#include "base/scoped_observation.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"

namespace base {
class ListValue;
}

class ProfileAttributesEntry;

// WebUI message handler for the profile customization bubble.
Expand Down Expand Up @@ -46,8 +42,8 @@ class ProfileCustomizationHandler : public content::WebUIMessageHandler,

private:
// Handlers for messages from javascript.
void HandleInitialized(const base::ListValue* args);
void HandleDone(const base::ListValue* args);
void HandleInitialized(const base::Value::List& args);
void HandleDone(const base::Value::List& args);

// Sends an updated profile info (avatar and colors) to the WebUI.
// `profile_path` is the path of the profile being updated, this function does
Expand Down
22 changes: 10 additions & 12 deletions chrome/browser/ui/webui/signin/signin_reauth_handler.cc
Expand Up @@ -25,13 +25,13 @@ SigninReauthHandler::SigninReauthHandler(
SigninReauthHandler::~SigninReauthHandler() = default;

void SigninReauthHandler::RegisterMessages() {
web_ui()->RegisterDeprecatedMessageCallback(
web_ui()->RegisterMessageCallback(
"initialize", base::BindRepeating(&SigninReauthHandler::HandleInitialize,
base::Unretained(this)));
web_ui()->RegisterDeprecatedMessageCallback(
web_ui()->RegisterMessageCallback(
"confirm", base::BindRepeating(&SigninReauthHandler::HandleConfirm,
base::Unretained(this)));
web_ui()->RegisterDeprecatedMessageCallback(
web_ui()->RegisterMessageCallback(
"cancel", base::BindRepeating(&SigninReauthHandler::HandleCancel,
base::Unretained(this)));
}
Expand Down Expand Up @@ -61,27 +61,25 @@ void SigninReauthHandler::OnGaiaReauthTypeDetermined(
FireWebUIListener("reauth-type-determined");
}

void SigninReauthHandler::HandleInitialize(const base::ListValue* args) {
void SigninReauthHandler::HandleInitialize(const base::Value::List& args) {
AllowJavascript();
}

void SigninReauthHandler::HandleConfirm(const base::ListValue* args) {
void SigninReauthHandler::HandleConfirm(const base::Value::List& args) {
if (controller_)
controller_->OnReauthConfirmed(BuildConsent(args));
}

void SigninReauthHandler::HandleCancel(const base::ListValue* args) {
void SigninReauthHandler::HandleCancel(const base::Value::List& args) {
if (controller_)
controller_->OnReauthDismissed();
}

sync_pb::UserConsentTypes::AccountPasswordsConsent
SigninReauthHandler::BuildConsent(const base::ListValue* args) const {
CHECK_EQ(2U, args->GetListDeprecated().size());
base::Value::ConstListView consent_description =
args->GetListDeprecated()[0].GetListDeprecated();
const std::string& consent_confirmation =
args->GetListDeprecated()[1].GetString();
SigninReauthHandler::BuildConsent(const base::Value::List& args) const {
CHECK_EQ(2U, args.size());
base::Value::ConstListView consent_description = args[0].GetListDeprecated();
const std::string& consent_confirmation = args[1].GetString();

// The strings returned by the WebUI are not free-form, they must belong into
// a pre-determined set of strings (stored in |string_to_grd_id_map_|). As
Expand Down
12 changes: 4 additions & 8 deletions chrome/browser/ui/webui/signin/signin_reauth_handler.h
Expand Up @@ -11,10 +11,6 @@
#include "chrome/browser/ui/signin_reauth_view_controller.h"
#include "content/public/browser/web_ui_message_handler.h"

namespace base {
class ListValue;
}

// WebUI message handler for the signin reauth dialog.
class SigninReauthHandler : public content::WebUIMessageHandler,
public SigninReauthViewController::Observer {
Expand All @@ -38,20 +34,20 @@ class SigninReauthHandler : public content::WebUIMessageHandler,

protected:
// Handles "initialize" message from the page. No arguments.
virtual void HandleInitialize(const base::ListValue* args);
virtual void HandleInitialize(const base::Value::List& args);

// Handles "confirm" message from the page. No arguments.
// This message is sent when the user confirms that they want complete the
// reauth flow.
virtual void HandleConfirm(const base::ListValue* args);
virtual void HandleConfirm(const base::Value::List& args);

// Handles "cancel" message from the page. No arguments. This message is sent
// when the user cancels the reauth flow.
virtual void HandleCancel(const base::ListValue* args);
virtual void HandleCancel(const base::Value::List& args);

private:
sync_pb::UserConsentTypes::AccountPasswordsConsent BuildConsent(
const base::ListValue* args) const;
const base::Value::List& args) const;

// May be null if |controller_| gets destroyed earlier than |this|.
raw_ptr<SigninReauthViewController> controller_;
Expand Down

0 comments on commit faeef00

Please sign in to comment.