Skip to content

Commit

Permalink
[Lacros] Add Guest mode link to account selection screen
Browse files Browse the repository at this point in the history
Screenshot:
https://storage.cloud.google.com/chromium-translation-screenshots/fa5fb0a2593865f41d36b11029a4be79a85ca3f2

Bug: 1411310
Change-Id: Ica34c01cd1dc67f4e4af78af9bb416b1c6f3ebfd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4208852
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
Commit-Queue: David Roger <droger@chromium.org>
Reviewed-by: Monica Basta <msalama@chromium.org>
Reviewed-by: Anastasiia N <anastasiian@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1116275}
  • Loading branch information
David Roger authored and Chromium LUCI CQ committed Mar 13, 2023
1 parent dd857f2 commit bc7ef6c
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 11 deletions.
3 changes: 3 additions & 0 deletions chrome/app/chromium_strings.grd
Expand Up @@ -1397,6 +1397,9 @@ Permissions you've already given to websites and apps may apply to this account.
<message name="IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_ACCOUNT_SELECTION_LACROS_SUBTITLE" desc="Profile picker, account selection screen subtitle">
Sign in to Chromium
</message>
<message name="IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_ACCOUNT_SELECTION_LACROS_SUBTITLE_WITH_GUEST" desc="Profile picker, account selection screen subtitle">
Sign in to Chromium. If you want to sign in an account one-time only, you can <ph name="GUEST_LINK_BEGIN">&lt;a id="guestModeLink" href="#"&gt;</ph>use the device as guest<ph name="GUEST_LINK_END">&lt;/a&gt;</ph>.
</message>
</if>
<if expr="not chromeos_lacros">
<message name="IDS_PROFILE_PICKER_MAIN_VIEW_TITLE" desc="Profile picker main view title">
Expand Down
@@ -0,0 +1 @@
fa5fb0a2593865f41d36b11029a4be79a85ca3f2
4 changes: 3 additions & 1 deletion chrome/app/google_chrome_strings.grd
Expand Up @@ -1478,10 +1478,12 @@ Permissions you've already given to websites and apps may apply to this account.
<message name="IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_PROFILE_TYPE_CHOICE_SUBTITLE_LACROS" desc="Profile picker profile type choice subtitle">
To access your Chrome browser stuff across all your devices, sign in, then turn on sync
</message>

<message name="IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_ACCOUNT_SELECTION_LACROS_SUBTITLE" desc="Profile picker, account selection screen subtitle">
Sign in to Chrome
</message>
<message name="IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_ACCOUNT_SELECTION_LACROS_SUBTITLE_WITH_GUEST" desc="Profile picker, account selection screen subtitle">
Sign in to Chrome. If you want to sign in an account one-time only, you can <ph name="GUEST_LINK_BEGIN">&lt;a id="guestModeLink" href="#"&gt;</ph>use the device as guest<ph name="GUEST_LINK_END">&lt;/a&gt;</ph>.
</message>
</if>
<if expr="not chromeos_lacros">
<message name="IDS_PROFILE_PICKER_MAIN_VIEW_TITLE" desc="Profile picker main view title">
Expand Down
@@ -0,0 +1 @@
fa5fb0a2593865f41d36b11029a4be79a85ca3f2
8 changes: 8 additions & 0 deletions chrome/browser/ash/crosapi/crosapi_util.cc
Expand Up @@ -813,6 +813,14 @@ mojom::DeviceSettingsPtr GetDeviceSettings() {
result->device_variations_restrict_parameter =
device_variations_restrict_parameter;
}

bool device_guest_mode_enabled = false;
if (cros_settings->GetBoolean(ash::kAccountsPrefAllowGuest,
&device_guest_mode_enabled)) {
result->device_guest_mode_enabled = device_guest_mode_enabled
? MojoOptionalBool::kTrue
: MojoOptionalBool::kFalse;
}
} else {
LOG(WARNING) << "Unexpected crossettings trusted values status: "
<< trusted_result;
Expand Down
Expand Up @@ -164,7 +164,9 @@ export interface ManageProfilesBrowserProxy {
cancelProfileSwitch(): void;

// <if expr="chromeos_lacros">
/** Gets the available accounts, through WebUIListener. */
/**
* Gets the available accounts, through WebUIListener.
*/
getAvailableAccounts(): void;

/**
Expand All @@ -176,6 +178,14 @@ export interface ManageProfilesBrowserProxy {
* 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>
}

Expand Down Expand Up @@ -269,6 +279,10 @@ export class ManageProfilesBrowserProxyImpl {
selectExistingAccountLacros(profileColor: number|null, gaiaId: string) {
chrome.send('selectExistingAccountLacros', [profileColor, gaiaId]);
}

openDeviceGuestLinkLacros() {
chrome.send('openDeviceGuestLinkLacros');
}
// </if>

static getInstance(): ManageProfilesBrowserProxy {
Expand Down
Expand Up @@ -3,6 +3,11 @@
--account-button-hover-color: var(--md-background-color);
}

a {
color: var(--cr-link-color);
text-decoration: none;
}

#accountsContainer {
--account-container-min-width: 416px;
--account-container-max-width: 582px;
Expand Down Expand Up @@ -180,7 +185,7 @@
role="presentation">
<div id="textContainer">
<h1 class="title">$i18n{accountSelectionLacrosTitle}</h1>
<div class="subtitle">$i18n{accountSelectionLacrosSubtitle}</div>
<div class="subtitle" inner-h-t-m-l="[[getSubtitle_()]]"></div>
</div>
<button id="other-account-button" class="account-button"
on-click="onOtherAccountClick_" disabled$="[[accountSelected_]]">
Expand Down
Expand Up @@ -6,10 +6,12 @@ import 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.js';
import 'chrome://resources/cr_elements/cr_shared_vars.css.js';
import './profile_creation_shared.css.js';

import {assert} from 'chrome://resources/js/assert_ts.js';
import {focusWithoutInk} from 'chrome://resources/js/focus_without_ink.js';
import {I18nMixin} from 'chrome://resources/cr_elements/i18n_mixin.js';
import {WebUiListenerMixin} from 'chrome://resources/cr_elements/web_ui_listener_mixin.js';
import {assert} from 'chrome://resources/js/assert_ts.js';
import {focusWithoutInk} from 'chrome://resources/js/focus_without_ink.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.js';
import {sanitizeInnerHtml} from 'chrome://resources/js/parse_html_subset.js';
import {afterNextRender, DomRepeatEvent, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {AutogeneratedThemeColorInfo, AvailableAccount, ManageProfilesBrowserProxy, ManageProfilesBrowserProxyImpl} from '../manage_profiles_browser_proxy.js';
Expand Down Expand Up @@ -80,6 +82,12 @@ export class AccountSelectionLacrosElement extends
override ready() {
super.ready();
this.addEventListener('view-enter-start', this.onViewEnterStart_);

const guestModeLink = this.shadowRoot!.querySelector('#guestModeLink');
if (guestModeLink) {
guestModeLink.addEventListener(
'click', (e: Event) => this.openGuestLink_(e));
}
}

private onViewEnterStart_() {
Expand All @@ -101,6 +109,13 @@ export class AccountSelectionLacrosElement extends
'backButtonAriaLabel', this.i18n('accountSelectionLacrosTitle'));
}

private getSubtitle_(): TrustedHTML {
return sanitizeInnerHtml(
loadTimeData.getString('accountSelectionLacrosSubtitle'), {
attrs: ['id'],
});
}

private onProductLogoTap_() {
this.$['product-logo'].animate(
{
Expand All @@ -124,6 +139,11 @@ export class AccountSelectionLacrosElement extends
this.profileThemeInfo.color);
}

private openGuestLink_(e: Event) {
e.preventDefault(); // Block the navigation.
this.manageProfilesBrowserProxy_.openDeviceGuestLinkLacros();
}

private handleAvailableAccountsChanged_(availableAccounts:
AvailableAccount[]) {
this.availableAccounts_ = availableAccounts;
Expand Down
14 changes: 12 additions & 2 deletions chrome/browser/ui/webui/signin/profile_picker_handler.cc
Expand Up @@ -469,6 +469,11 @@ void ProfilePickerHandler::RegisterMessages() {
base::BindRepeating(
&ProfilePickerHandler::HandleSelectExistingAccountLacros,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"openDeviceGuestLinkLacros",
base::BindRepeating(
&ProfilePickerHandler::HandleOpenDeviceGuestLinkLacros,
base::Unretained(this)));
#endif
Profile* profile = Profile::FromWebUI(web_ui());
content::URLDataSource::Add(profile, std::make_unique<ThemeSource>(profile));
Expand Down Expand Up @@ -623,8 +628,7 @@ void ProfilePickerHandler::HandleGetNewProfileSuggestedThemeInfo(
// The picker offers secondary accounts for a given existing profile.
// Extract the color from the current profile (where this is rendered).
ThemeService* theme_service =
ThemeServiceFactory::GetForProfile(Profile::FromBrowserContext(
web_ui()->GetWebContents()->GetBrowserContext()));
ThemeServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
base::Value::Dict profile_dict;
if (theme_service->UsingAutogeneratedTheme()) {
// We'll never use `profile_dict` for showing the color picker so we can
Expand Down Expand Up @@ -1249,6 +1253,12 @@ void ProfilePickerHandler::HandleOpenAshAccountSettingsPage(
lacros_url_handling::NavigateInAsh(GURL(settings_url));
}

void ProfilePickerHandler::HandleOpenDeviceGuestLinkLacros(
const base::Value::List& args) {
// TODO(https://crbug.com/1411310): Handle the user action.
NOTIMPLEMENTED();
}

void ProfilePickerHandler::HandleGetAvailableAccounts(
const base::Value::List& args) {
AllowJavascript();
Expand Down
4 changes: 4 additions & 0 deletions chrome/browser/ui/webui/signin/profile_picker_handler.h
Expand Up @@ -161,6 +161,10 @@ class ProfilePickerHandler : public content::WebUIMessageHandler,
// Opens the Ash account settings page in a new window.
void HandleOpenAshAccountSettingsPage(const base::Value::List& args);

// Called when the user clicks the "use device guest" link in the account
// selection dialog.
void HandleOpenDeviceGuestLinkLacros(const base::Value::List& args);

// List of available accounts used by the profile choice and the account
// selection screens.
void HandleGetAvailableAccounts(const base::Value::List& args);
Expand Down
21 changes: 19 additions & 2 deletions chrome/browser/ui/webui/signin/profile_picker_ui.cc
Expand Up @@ -10,6 +10,7 @@
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/policy/browser_signin_policy_handler.h"
#include "chrome/browser/policy/chrome_browser_policy_connector.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_shortcut_manager.h"
Expand Down Expand Up @@ -45,6 +46,7 @@
#include "url/gurl.h"

#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/crosapi/mojom/device_settings_service.mojom.h"
#include "ui/chromeos/devicetype_utils.h"
#endif

Expand Down Expand Up @@ -178,8 +180,6 @@ void AddStrings(content::WebUIDataSource* html_source) {
#if BUILDFLAG(IS_CHROMEOS_LACROS)
{"accountSelectionLacrosTitle",
IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_ACCOUNT_SELECTION_LACROS_TITLE},
{"accountSelectionLacrosSubtitle",
IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_ACCOUNT_SELECTION_LACROS_SUBTITLE},
{"accountSelectionLacrosOtherAccountButtonLabel",
IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_ACCOUNT_SELECTION_LACROS_OTHER_ACCOUNT_BUTTON_LABEL},
{"lacrosPrimaryProfileDeletionWarningTitle",
Expand Down Expand Up @@ -243,6 +243,23 @@ void AddStrings(content::WebUIDataSource* html_source) {
l10n_util::GetStringUTF16(IDS_OS_SETTINGS_PEOPLE_V2));
html_source->AddString("removeWarningProfileLacros", remove_warning_profile);
html_source->AddString("deviceType", ui::GetChromeOSDeviceName());

bool guest_mode_enabled = true;
// Device settings may be nullptr in tests.
if (crosapi::mojom::DeviceSettings* device_settings =
g_browser_process->browser_policy_connector()->GetDeviceSettings()) {
if (device_settings->device_guest_mode_enabled ==
crosapi::mojom::DeviceSettings::OptionalBool::kFalse) {
guest_mode_enabled = false;
}
}
const int account_selection_lacros_subtitle =
guest_mode_enabled
? IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_ACCOUNT_SELECTION_LACROS_SUBTITLE_WITH_GUEST
: IDS_PROFILE_PICKER_PROFILE_CREATION_FLOW_ACCOUNT_SELECTION_LACROS_SUBTITLE;
html_source->AddLocalizedString("accountSelectionLacrosSubtitle",
account_selection_lacros_subtitle);

#endif

// Add policies.
Expand Down
Expand Up @@ -74,6 +74,12 @@ import {TestManageProfilesBrowserProxy} from './test_manage_profiles_browser_pro
assertEquals(isChildVisible(testElement, '#backButton'), withinFlow);
});

test('GuestLink', async function() {
testElement.shadowRoot!.querySelector<HTMLElement>(
'#guestModeLink')!.click();
return browserProxy.whenCalled('openDeviceGuestLinkLacros');
});

test('accountButtons', async function() {
// There are no accounts initially, only "Use another account".
flushTasks();
Expand Down
Expand Up @@ -23,7 +23,7 @@ export class TestManageProfilesBrowserProxy extends TestBrowserProxy implements
'confirmProfileSwitch', 'cancelProfileSwitch',
// <if expr="chromeos_lacros">
'getAvailableAccounts', 'openAshAccountSettingsPage',
'selectExistingAccountLacros',
'selectExistingAccountLacros', 'openDeviceGuestLinkLacros',
// </if>
]);

Expand Down Expand Up @@ -179,5 +179,9 @@ export class TestManageProfilesBrowserProxy extends TestBrowserProxy implements
selectExistingAccountLacros(profileColor: number|null, gaiaId: string) {
this.methodCalled('selectExistingAccountLacros', [profileColor, gaiaId]);
}

openDeviceGuestLinkLacros() {
this.methodCalled('openDeviceGuestLinkLacros');
}
// </if>
}
6 changes: 5 additions & 1 deletion chromeos/crosapi/mojom/device_settings_service.mojom
Expand Up @@ -31,7 +31,7 @@ struct UsbDeviceId {

// All the device settings data that are needed in Lacros should be here.
//
// Next MinVersion: 5
// Next MinVersion: 6
[Stable]
struct DeviceSettings {
// The value of AttestationForContentProtectionEnabled device setting.
Expand Down Expand Up @@ -66,6 +66,10 @@ struct DeviceSettings {
[MinVersion=4]
string? device_variations_restrict_parameter@8;

// The value of DeviceGuestModeEnabled device policy.
[MinVersion=5]
OptionalBool? device_guest_mode_enabled@9;

[Stable]
enum OptionalBool {
kUnset,
Expand Down

0 comments on commit bc7ef6c

Please sign in to comment.