Commit a000dc42 authored by Monica Basta's avatar Monica Basta Committed by Commit Bot

[ProfilePicker]: Add remove functionality.

This CL adds the remove button shown on the profile picker main view
functionality.

Bug: 1063856
Change-Id: If8733ffc50a474ccfceb5ee0a11c540752ca0676
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346810
Commit-Queue: Monica Basta <msalama@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797226}
parent e8e3bc0b
......@@ -9,7 +9,7 @@ import {addSingletonGetter, sendWithPromise} from 'chrome://resources/js/cr.m.js
* @typedef {{
* profilePath: string,
* localProfileName: string,
* isSignedIn: Boolean,
* isSignedIn: boolean,
* gaiaName: string,
* userName: string,
* avatarIcon: string,
......@@ -62,6 +62,12 @@ export class ManageProfilesBrowserProxy {
*/
getProfileStatistics(profilePath) {}
/**
* Removes profile.
* @param {string} profilePath
*/
removeProfile(profilePath) {}
/** Loads Google sign in page.*/
loadSignInProfileCreationFlow() {}
}
......@@ -93,6 +99,11 @@ export class ManageProfilesBrowserProxyImpl {
return sendWithPromise('getNewProfileSuggestedThemeInfo');
}
/** @override */
removeProfile(profilePath) {
chrome.send('removeProfile', [profilePath]);
}
/** @override */
getProfileStatistics(profilePath) {
chrome.send('getProfileStatistics', [profilePath]);
......
......@@ -18,6 +18,7 @@
}
#removeConfirmation {
color: var(--cr-primary-text-color);
margin-top: 16px;
pointer-events: none;
width: 234px;
......@@ -60,7 +61,7 @@
--bg-action: var(--google-red-700);
--hover-bg-action: rgba(var(--google-red-700-rgb), .9);
--hover-shadow-action-rgb: var(--google-red-500-rgb);
background-color: var(--google-red-700);
background-color: var(--bg-action);
border-radius: 4px;
color: var(--ink-color-action);
font-weight: 500;
......@@ -81,13 +82,13 @@
aria-label$="[[profileMenuText_]]">
</cr-icon-button>
<cr-action-menu id="actionMenu" role-description="menu">
<cr-action-menu id="actionMenu" role-description="$i18n{menu}">
<button class="dropdown-item" on-click="onRemoveButtonClicked_">
$i18n{profileMenuRemoveText}
</button>
</cr-action-menu>
<cr-action-menu id="removeActionMenu" role-description="menu">
<cr-action-menu id="removeActionMenu" role-description="$i18n{menu}">
<div id="removeConfirmation">
<div class="header">
$i18n{profileMenuRemoveText}
......
......@@ -86,11 +86,13 @@ Polymer({
],
},
/** @private */
profileMenuText_: {
type: String,
computed: 'computeProfileMenuText_(profileState)',
},
/** @private */
removeWarningText_: {
type: String,
computed: 'computeRemoveWarningText_(profileState)',
......@@ -108,6 +110,10 @@ Polymer({
/** @override */
attached() {
this.addWebUIListener(
'profiles-list-changed', () => this.handleProfilesUpdated_());
this.addWebUIListener(
'profile-removed', () => this.handleProfilesUpdated_());
this.addWebUIListener(
'profile-statistics-received',
this.handleProfileStatsReceived_.bind(this));
......@@ -126,10 +132,9 @@ Polymer({
* @private
*/
computeRemoveWarningText_() {
if (this.profileState.isSignedIn) {
return this.i18n('removeWarningSignedInProfile');
}
return this.i18n('removeWarningLocalProfile');
return this.i18n(
this.profileState.isSignedIn ? 'removeWarningSignedInProfile' :
'removeWarningLocalProfile');
},
/**
......@@ -168,7 +173,7 @@ Polymer({
},
/**
* @param {string} dataType
* @param {ProfileStatistics} dataType
* @return {string}
* @private
*/
......@@ -205,6 +210,16 @@ Polymer({
onRemoveComfirationClicked_(e) {
e.stopPropagation();
e.preventDefault();
// TODO(crbug.com/1063856): Add implementation.
this.manageProfilesBrowserProxy_.removeProfile(
this.profileState.profilePath);
},
/**
* Ensure any menu is closed on profile list updated.
* @private
*/
handleProfilesUpdated_() {
this.$.actionMenu.close();
this.$.removeActionMenu.close();
},
});
......@@ -56,6 +56,8 @@ Polymer({
attached() {
this.addWebUIListener(
'profiles-list-changed', this.handleProfilesListChanged_.bind(this));
this.addWebUIListener(
'profile-removed', this.handleProfileRemoved_.bind(this));
this.manageProfilesBrowserProxy_.initializeMainView();
},
......@@ -97,4 +99,15 @@ Polymer({
onLaunchGuestProfileClick_() {
this.manageProfilesBrowserProxy_.launchGuestProfile();
},
/** @private */
handleProfileRemoved_(profilePath) {
for (let i = 0; i < this.profilesList_.length; i += 1) {
if (this.profilesList_[i].profilePath === profilePath) {
// TODO(crbug.com/1063856): Add animation.
this.splice('profilesList_', i, 1);
break;
}
}
},
});
......@@ -19,6 +19,7 @@
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/profile_picker.h"
#include "chrome/browser/ui/webui/profile_helper.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/search/generated_colors_info.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -58,6 +59,10 @@ void ProfilePickerHandler::RegisterMessages() {
base::BindRepeating(
&ProfilePickerHandler::HandleGetNewProfileSuggestedThemeInfo,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"removeProfile",
base::BindRepeating(&ProfilePickerHandler::HandleRemoveProfile,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getProfileStatistics",
base::BindRepeating(&ProfilePickerHandler::HandleGetProfileStatistics,
......@@ -156,6 +161,20 @@ void ProfilePickerHandler::HandleGetNewProfileSuggestedThemeInfo(
ResolveJavascriptCallback(callback_id, std::move(dict));
}
void ProfilePickerHandler::HandleRemoveProfile(const base::ListValue* args) {
CHECK_EQ(1U, args->GetSize());
const base::Value& profile_path_value = args->GetList()[0];
base::Optional<base::FilePath> profile_path =
util::ValueToFilePath(profile_path_value);
if (!profile_path) {
NOTREACHED();
return;
}
webui::DeleteProfileAtPath(*profile_path,
ProfileMetrics::DELETE_PROFILE_USER_MANAGER);
}
void ProfilePickerHandler::HandleGetProfileStatistics(
const base::ListValue* args) {
AllowJavascript();
......@@ -259,7 +278,8 @@ void ProfilePickerHandler::OnProfileAdded(const base::FilePath& profile_path) {
void ProfilePickerHandler::OnProfileWasRemoved(
const base::FilePath& profile_path,
const base::string16& profile_name) {
PushProfilesList();
DCHECK(IsJavascriptAllowed());
FireWebUIListener("profile-removed", util::FilePathToValue(profile_path));
}
void ProfilePickerHandler::OnProfileAvatarChanged(
......
......@@ -30,6 +30,7 @@ class ProfilePickerHandler : public content::WebUIMessageHandler,
void HandleLaunchGuestProfile(const base::ListValue* args);
void HandleAskOnStartupChanged(const base::ListValue* args);
void HandleGetNewProfileSuggestedThemeInfo(const base::ListValue* args);
void HandleRemoveProfile(const base::ListValue* args);
void HandleGetProfileStatistics(const base::ListValue* args);
void HandleLoadSignInProfileCreationFlow(const base::ListValue* args);
......
......@@ -15,6 +15,7 @@
#include "chrome/grit/profile_picker_resources.h"
#include "chrome/grit/profile_picker_resources_map.h"
#include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/base/webui/web_ui_util.h"
......@@ -27,7 +28,7 @@ void AddStrings(content::WebUIDataSource* html_source) {
{"addSpaceButton", IDS_PROFILE_PICKER_ADD_SPACE_BUTTON},
{"askOnStartupCheckboxText", IDS_PROFILE_PICKER_ASK_ON_STARTUP},
{"browseAsGuestButton", IDS_PROFILE_PICKER_BROWSE_AS_GUEST_BUTTON},
{"backButtonLabel", IDS_PROFILE_PICKER_BACK_BUTTON_LABEL},
{"menu", IDS_MENU},
{"profileMenuName", IDS_PROFILE_PICKER_PROFILE_MENU_BUTTON_NAME},
{"profileMenuRemoveText", IDS_PROFILE_PICKER_PROFILE_MENU_REMOVE_TEXT},
{"removeWarningLocalProfile",
......@@ -40,6 +41,7 @@ void AddStrings(content::WebUIDataSource* html_source) {
{"removeWarningAutofill", IDS_PROFILE_PICKER_REMOVE_WARNING_AUTOFILL},
{"removeWarningCalculating",
IDS_PROFILE_PICKER_REMOVE_WARNING_CALCULATING},
{"backButtonLabel", IDS_PROFILE_PICKER_BACK_BUTTON_LABEL},
{"profileTypeChoiceTitle",
IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_PROFILE_TYPE_CHOICE_TITLE},
{"profileTypeChoiceSubtitle",
......
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