/
manage_profiles_browser_proxy.ts
297 lines (245 loc) · 7.83 KB
/
manage_profiles_browser_proxy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {AvatarIcon} from 'chrome://resources/cr_elements/cr_profile_avatar_selector/cr_profile_avatar_selector.js';
import {sendWithPromise} from 'chrome://resources/js/cr.js';
/**
* This is the data structure sent back and forth between C++ and JS.
*/
export interface ProfileState {
profilePath: string;
localProfileName: string;
isSyncing: boolean;
needsSignin: boolean;
gaiaName: string;
userName: string;
isManaged: boolean;
avatarIcon: string;
// <if expr="chromeos_lacros">
isPrimaryLacrosProfile: boolean;
// </if>
}
/**
* This is the data structure sent back and forth between C++ and JS.
* `colorId` has the following special values:
* - `-1` for the default theme.
* - `0` for a manually picked color theme.
*/
export interface AutogeneratedThemeColorInfo {
colorId: number;
color: number;
themeFrameColor: string;
themeShapeColor: string;
themeFrameTextColor: string;
themeGenericAvatar: string;
}
/**
* This is the data structure sent back and forth between C++ and JS.
* `colorId` has the following special values:
* - `-1` for the default theme..
* - `0` for a manually picked color theme
* `color` is defined only for manually picked themes.
*/
export interface UserThemeChoice {
colorId: number;
color?: number;
}
// <if expr="chromeos_lacros">
/**
* This is a data structure sent from C++ to JS, representing accounts present
* in the ChromeOS system, but not in any Lacros profile.
*/
export interface AvailableAccount {
gaiaId: string;
name: string;
email: string;
accountImageUrl: string;
}
// </if>
export interface ManageProfilesBrowserProxy {
/**
* Initializes profile picker main view.
*/
initializeMainView(): void;
/**
* Launches picked profile and closes the profile picker.
*/
launchSelectedProfile(profilePath: string): void;
/**
* Opens profile on manage profile settings sub page and closes the
* profile picker.
*/
openManageProfileSettingsSubPage(profilePath: string): void;
/** Launches Guest profile. */
launchGuestProfile(): void;
/**
* Inform native the user's choice on whether to show the profile picker
* on startup or not.
*/
askOnStartupChanged(shouldShow: boolean): void;
/**
* Retrieves suggested theme for the new profile.
* @return A promise firing with the suggested theme info, once it has been
* retrieved.
*/
getNewProfileSuggestedThemeInfo(): Promise<AutogeneratedThemeColorInfo>;
/**
* Retrieves all relevant theme information for the particular theme.
* @param theme A theme which info needs to be retrieved.
* @return A promise firing with the theme info, once it has been retrieved.
*/
getProfileThemeInfo(theme: UserThemeChoice):
Promise<AutogeneratedThemeColorInfo>;
/**
* Retrieves profile statistics to be shown in the remove profile warning.
*/
getProfileStatistics(profilePath: string): void;
/**
* Removes profile.
*/
removeProfile(profilePath: string): void;
/**
* Starts a signin flow to get a new account that will be added to a profile.
* On Dice platforms, this is only for new profiles, but on Lacros it may also
* be used with an existing profile.
*/
selectNewAccount(profileColor: number|null): void;
/**
* Retrieves custom avatar list for the select avatar dialog.
*/
getAvailableIcons(): Promise<AvatarIcon[]>;
/**
* Creates local profile.
*/
createProfile(
profileName: string, profileColor: number, avatarIndex: number,
createShortcut: boolean): void;
/**
* Creates local profile and opens a profile customization modal dialog on a
* browser window.
* TODO(https://crbug.com/1282157): Add createShortcut parameter.
*/
createProfileAndOpenCustomizationDialog(profileColor: number): void;
/**
* Sets the local profile name.
*/
setProfileName(profilePath: string, profileName: string): void;
/** Records impression of a sign-in promo to metrics. */
recordSignInPromoImpression(): void;
/**
* Gets a profile for which the profile switch screen is shown.
*/
getSwitchProfile(): Promise<ProfileState>;
/**
* Switches to an already existing profile at `profile_path`.
*/
confirmProfileSwitch(profilePath: string): void;
/**
* Cancels the profile switch which aborts the sign-in profile creation
* flow.
*/
cancelProfileSwitch(): void;
// <if expr="chromeos_lacros">
/**
* Gets the available accounts, through WebUIListener.
*/
getAvailableAccounts(): void;
/**
* Opens Ash Account settings page in a new window.
*/
openAshAccountSettingsPage(): void;
/**
* Select an existing account to be added in Chrome on Lacros.
*/
selectExistingAccountLacros(profileColor: number|null, gaiaId: string): void;
/**
* Called when the user clicks the 'use device guest' link in the Lacros
* account selection dialog. Opens a Ash dialog that allows the user to log
* out of their device session and explains how to select `Browse as Guest` on
* the login screen.
*/
openDeviceGuestLinkLacros(): void;
// </if>
}
/** @implements {ManageProfilesBrowserProxy} */
export class ManageProfilesBrowserProxyImpl {
initializeMainView() {
chrome.send('mainViewInitialize');
}
launchSelectedProfile(profilePath: string) {
chrome.send('launchSelectedProfile', [profilePath]);
}
openManageProfileSettingsSubPage(profilePath: string) {
chrome.send('openManageProfileSettingsSubPage', [profilePath]);
}
launchGuestProfile() {
chrome.send('launchGuestProfile');
}
askOnStartupChanged(shouldShow: boolean) {
chrome.send('askOnStartupChanged', [shouldShow]);
}
getNewProfileSuggestedThemeInfo() {
return sendWithPromise('getNewProfileSuggestedThemeInfo');
}
getProfileThemeInfo(theme: UserThemeChoice) {
return sendWithPromise('getProfileThemeInfo', theme);
}
removeProfile(profilePath: string) {
chrome.send('removeProfile', [profilePath]);
}
getProfileStatistics(profilePath: string) {
chrome.send('getProfileStatistics', [profilePath]);
}
selectNewAccount(profileColor: number|null) {
chrome.send('selectNewAccount', [profileColor]);
}
getAvailableIcons() {
return sendWithPromise('getAvailableIcons');
}
createProfile(
profileName: string, profileColor: number, avatarIndex: number,
createShortcut: boolean) {
chrome.send(
'createProfile',
[profileName, profileColor, avatarIndex, createShortcut]);
}
createProfileAndOpenCustomizationDialog(profileColor: number) {
chrome.send('createProfileAndOpenCustomizationDialog', [profileColor]);
}
setProfileName(profilePath: string, profileName: string) {
chrome.send('setProfileName', [profilePath, profileName]);
}
recordSignInPromoImpression() {
chrome.send('recordSignInPromoImpression');
}
getSwitchProfile() {
return sendWithPromise('getSwitchProfile');
}
confirmProfileSwitch(profilePath: string) {
chrome.send('confirmProfileSwitch', [profilePath]);
}
cancelProfileSwitch() {
chrome.send('cancelProfileSwitch');
}
// <if expr="chromeos_lacros">
getAvailableAccounts() {
chrome.send('getAvailableAccounts');
}
openAshAccountSettingsPage() {
chrome.send('openAshAccountSettingsPage');
}
selectExistingAccountLacros(profileColor: number|null, gaiaId: string) {
chrome.send('selectExistingAccountLacros', [profileColor, gaiaId]);
}
openDeviceGuestLinkLacros() {
chrome.send('openDeviceGuestLinkLacros');
}
// </if>
static getInstance(): ManageProfilesBrowserProxy {
return instance || (instance = new ManageProfilesBrowserProxyImpl());
}
static setInstance(obj: ManageProfilesBrowserProxy) {
instance = obj;
}
}
let instance: ManageProfilesBrowserProxy|null = null;