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 ...@@ -9,7 +9,7 @@ import {addSingletonGetter, sendWithPromise} from 'chrome://resources/js/cr.m.js
* @typedef {{ * @typedef {{
* profilePath: string, * profilePath: string,
* localProfileName: string, * localProfileName: string,
* isSignedIn: Boolean, * isSignedIn: boolean,
* gaiaName: string, * gaiaName: string,
* userName: string, * userName: string,
* avatarIcon: string, * avatarIcon: string,
...@@ -62,6 +62,12 @@ export class ManageProfilesBrowserProxy { ...@@ -62,6 +62,12 @@ export class ManageProfilesBrowserProxy {
*/ */
getProfileStatistics(profilePath) {} getProfileStatistics(profilePath) {}
/**
* Removes profile.
* @param {string} profilePath
*/
removeProfile(profilePath) {}
/** Loads Google sign in page.*/ /** Loads Google sign in page.*/
loadSignInProfileCreationFlow() {} loadSignInProfileCreationFlow() {}
} }
...@@ -93,6 +99,11 @@ export class ManageProfilesBrowserProxyImpl { ...@@ -93,6 +99,11 @@ export class ManageProfilesBrowserProxyImpl {
return sendWithPromise('getNewProfileSuggestedThemeInfo'); return sendWithPromise('getNewProfileSuggestedThemeInfo');
} }
/** @override */
removeProfile(profilePath) {
chrome.send('removeProfile', [profilePath]);
}
/** @override */ /** @override */
getProfileStatistics(profilePath) { getProfileStatistics(profilePath) {
chrome.send('getProfileStatistics', [profilePath]); chrome.send('getProfileStatistics', [profilePath]);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
} }
#removeConfirmation { #removeConfirmation {
color: var(--cr-primary-text-color);
margin-top: 16px; margin-top: 16px;
pointer-events: none; pointer-events: none;
width: 234px; width: 234px;
...@@ -60,7 +61,7 @@ ...@@ -60,7 +61,7 @@
--bg-action: var(--google-red-700); --bg-action: var(--google-red-700);
--hover-bg-action: rgba(var(--google-red-700-rgb), .9); --hover-bg-action: rgba(var(--google-red-700-rgb), .9);
--hover-shadow-action-rgb: var(--google-red-500-rgb); --hover-shadow-action-rgb: var(--google-red-500-rgb);
background-color: var(--google-red-700); background-color: var(--bg-action);
border-radius: 4px; border-radius: 4px;
color: var(--ink-color-action); color: var(--ink-color-action);
font-weight: 500; font-weight: 500;
...@@ -81,13 +82,13 @@ ...@@ -81,13 +82,13 @@
aria-label$="[[profileMenuText_]]"> aria-label$="[[profileMenuText_]]">
</cr-icon-button> </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_"> <button class="dropdown-item" on-click="onRemoveButtonClicked_">
$i18n{profileMenuRemoveText} $i18n{profileMenuRemoveText}
</button> </button>
</cr-action-menu> </cr-action-menu>
<cr-action-menu id="removeActionMenu" role-description="menu"> <cr-action-menu id="removeActionMenu" role-description="$i18n{menu}">
<div id="removeConfirmation"> <div id="removeConfirmation">
<div class="header"> <div class="header">
$i18n{profileMenuRemoveText} $i18n{profileMenuRemoveText}
......
...@@ -86,11 +86,13 @@ Polymer({ ...@@ -86,11 +86,13 @@ Polymer({
], ],
}, },
/** @private */
profileMenuText_: { profileMenuText_: {
type: String, type: String,
computed: 'computeProfileMenuText_(profileState)', computed: 'computeProfileMenuText_(profileState)',
}, },
/** @private */
removeWarningText_: { removeWarningText_: {
type: String, type: String,
computed: 'computeRemoveWarningText_(profileState)', computed: 'computeRemoveWarningText_(profileState)',
...@@ -108,6 +110,10 @@ Polymer({ ...@@ -108,6 +110,10 @@ Polymer({
/** @override */ /** @override */
attached() { attached() {
this.addWebUIListener(
'profiles-list-changed', () => this.handleProfilesUpdated_());
this.addWebUIListener(
'profile-removed', () => this.handleProfilesUpdated_());
this.addWebUIListener( this.addWebUIListener(
'profile-statistics-received', 'profile-statistics-received',
this.handleProfileStatsReceived_.bind(this)); this.handleProfileStatsReceived_.bind(this));
...@@ -126,10 +132,9 @@ Polymer({ ...@@ -126,10 +132,9 @@ Polymer({
* @private * @private
*/ */
computeRemoveWarningText_() { computeRemoveWarningText_() {
if (this.profileState.isSignedIn) { return this.i18n(
return this.i18n('removeWarningSignedInProfile'); this.profileState.isSignedIn ? 'removeWarningSignedInProfile' :
} 'removeWarningLocalProfile');
return this.i18n('removeWarningLocalProfile');
}, },
/** /**
...@@ -168,7 +173,7 @@ Polymer({ ...@@ -168,7 +173,7 @@ Polymer({
}, },
/** /**
* @param {string} dataType * @param {ProfileStatistics} dataType
* @return {string} * @return {string}
* @private * @private
*/ */
...@@ -205,6 +210,16 @@ Polymer({ ...@@ -205,6 +210,16 @@ Polymer({
onRemoveComfirationClicked_(e) { onRemoveComfirationClicked_(e) {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); 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({ ...@@ -56,6 +56,8 @@ Polymer({
attached() { attached() {
this.addWebUIListener( this.addWebUIListener(
'profiles-list-changed', this.handleProfilesListChanged_.bind(this)); 'profiles-list-changed', this.handleProfilesListChanged_.bind(this));
this.addWebUIListener(
'profile-removed', this.handleProfileRemoved_.bind(this));
this.manageProfilesBrowserProxy_.initializeMainView(); this.manageProfilesBrowserProxy_.initializeMainView();
}, },
...@@ -97,4 +99,15 @@ Polymer({ ...@@ -97,4 +99,15 @@ Polymer({
onLaunchGuestProfileClick_() { onLaunchGuestProfileClick_() {
this.manageProfilesBrowserProxy_.launchGuestProfile(); 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 @@ ...@@ -19,6 +19,7 @@
#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/profile_picker.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/pref_names.h"
#include "chrome/common/search/generated_colors_info.h" #include "chrome/common/search/generated_colors_info.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -58,6 +59,10 @@ void ProfilePickerHandler::RegisterMessages() { ...@@ -58,6 +59,10 @@ void ProfilePickerHandler::RegisterMessages() {
base::BindRepeating( base::BindRepeating(
&ProfilePickerHandler::HandleGetNewProfileSuggestedThemeInfo, &ProfilePickerHandler::HandleGetNewProfileSuggestedThemeInfo,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"removeProfile",
base::BindRepeating(&ProfilePickerHandler::HandleRemoveProfile,
base::Unretained(this)));
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"getProfileStatistics", "getProfileStatistics",
base::BindRepeating(&ProfilePickerHandler::HandleGetProfileStatistics, base::BindRepeating(&ProfilePickerHandler::HandleGetProfileStatistics,
...@@ -156,6 +161,20 @@ void ProfilePickerHandler::HandleGetNewProfileSuggestedThemeInfo( ...@@ -156,6 +161,20 @@ void ProfilePickerHandler::HandleGetNewProfileSuggestedThemeInfo(
ResolveJavascriptCallback(callback_id, std::move(dict)); 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( void ProfilePickerHandler::HandleGetProfileStatistics(
const base::ListValue* args) { const base::ListValue* args) {
AllowJavascript(); AllowJavascript();
...@@ -259,7 +278,8 @@ void ProfilePickerHandler::OnProfileAdded(const base::FilePath& profile_path) { ...@@ -259,7 +278,8 @@ void ProfilePickerHandler::OnProfileAdded(const base::FilePath& profile_path) {
void ProfilePickerHandler::OnProfileWasRemoved( void ProfilePickerHandler::OnProfileWasRemoved(
const base::FilePath& profile_path, const base::FilePath& profile_path,
const base::string16& profile_name) { const base::string16& profile_name) {
PushProfilesList(); DCHECK(IsJavascriptAllowed());
FireWebUIListener("profile-removed", util::FilePathToValue(profile_path));
} }
void ProfilePickerHandler::OnProfileAvatarChanged( void ProfilePickerHandler::OnProfileAvatarChanged(
......
...@@ -30,6 +30,7 @@ class ProfilePickerHandler : public content::WebUIMessageHandler, ...@@ -30,6 +30,7 @@ class ProfilePickerHandler : public content::WebUIMessageHandler,
void HandleLaunchGuestProfile(const base::ListValue* args); void HandleLaunchGuestProfile(const base::ListValue* args);
void HandleAskOnStartupChanged(const base::ListValue* args); void HandleAskOnStartupChanged(const base::ListValue* args);
void HandleGetNewProfileSuggestedThemeInfo(const base::ListValue* args); void HandleGetNewProfileSuggestedThemeInfo(const base::ListValue* args);
void HandleRemoveProfile(const base::ListValue* args);
void HandleGetProfileStatistics(const base::ListValue* args); void HandleGetProfileStatistics(const base::ListValue* args);
void HandleLoadSignInProfileCreationFlow(const base::ListValue* args); void HandleLoadSignInProfileCreationFlow(const base::ListValue* args);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/grit/profile_picker_resources.h" #include "chrome/grit/profile_picker_resources.h"
#include "chrome/grit/profile_picker_resources_map.h" #include "chrome/grit/profile_picker_resources_map.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
#include "ui/base/webui/web_ui_util.h" #include "ui/base/webui/web_ui_util.h"
...@@ -27,7 +28,7 @@ void AddStrings(content::WebUIDataSource* html_source) { ...@@ -27,7 +28,7 @@ void AddStrings(content::WebUIDataSource* html_source) {
{"addSpaceButton", IDS_PROFILE_PICKER_ADD_SPACE_BUTTON}, {"addSpaceButton", IDS_PROFILE_PICKER_ADD_SPACE_BUTTON},
{"askOnStartupCheckboxText", IDS_PROFILE_PICKER_ASK_ON_STARTUP}, {"askOnStartupCheckboxText", IDS_PROFILE_PICKER_ASK_ON_STARTUP},
{"browseAsGuestButton", IDS_PROFILE_PICKER_BROWSE_AS_GUEST_BUTTON}, {"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}, {"profileMenuName", IDS_PROFILE_PICKER_PROFILE_MENU_BUTTON_NAME},
{"profileMenuRemoveText", IDS_PROFILE_PICKER_PROFILE_MENU_REMOVE_TEXT}, {"profileMenuRemoveText", IDS_PROFILE_PICKER_PROFILE_MENU_REMOVE_TEXT},
{"removeWarningLocalProfile", {"removeWarningLocalProfile",
...@@ -40,6 +41,7 @@ void AddStrings(content::WebUIDataSource* html_source) { ...@@ -40,6 +41,7 @@ void AddStrings(content::WebUIDataSource* html_source) {
{"removeWarningAutofill", IDS_PROFILE_PICKER_REMOVE_WARNING_AUTOFILL}, {"removeWarningAutofill", IDS_PROFILE_PICKER_REMOVE_WARNING_AUTOFILL},
{"removeWarningCalculating", {"removeWarningCalculating",
IDS_PROFILE_PICKER_REMOVE_WARNING_CALCULATING}, IDS_PROFILE_PICKER_REMOVE_WARNING_CALCULATING},
{"backButtonLabel", IDS_PROFILE_PICKER_BACK_BUTTON_LABEL},
{"profileTypeChoiceTitle", {"profileTypeChoiceTitle",
IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_PROFILE_TYPE_CHOICE_TITLE}, IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_PROFILE_TYPE_CHOICE_TITLE},
{"profileTypeChoiceSubtitle", {"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