Commit 98b10b51 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

MD User Manager: Remove Supervised User creation logic

Supervised Users are deprecated, and creation has been disabled for a
while. Time to get rid of the code.

Bug: 828890
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ib95d138a5bdfa8fa150c99c1f85b8d2688ee3a27
Reviewed-on: https://chromium-review.googlesource.com/1029952Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556766}
parent 73cedc1c
This diff is collapsed.
......@@ -502,14 +502,8 @@
<include name="IDR_MD_CREATE_PROFILE_JS" file="resources\md_user_manager\create_profile.js" type="BINDATA" />
<include name="IDR_MD_ERROR_DIALOG_HTML" file="resources\md_user_manager\error_dialog.html" type="BINDATA" />
<include name="IDR_MD_ERROR_DIALOG_JS" file="resources\md_user_manager\error_dialog.js" type="BINDATA" />
<include name="IDR_MD_IMPORT_SUPERVISED_USER_HTML" file="resources\md_user_manager\import_supervised_user.html" type="BINDATA" />
<include name="IDR_MD_IMPORT_SUPERVISED_USER_JS" file="resources\md_user_manager\import_supervised_user.js" type="BINDATA" />
<include name="IDR_MD_PROFILE_BROWSER_PROXY_HTML" file="resources\md_user_manager\profile_browser_proxy.html" type="BINDATA" />
<include name="IDR_MD_PROFILE_BROWSER_PROXY_JS" file="resources\md_user_manager\profile_browser_proxy.js" type="BINDATA" />
<include name="IDR_MD_SUPERVISED_USER_CREATE_CONFIRM_HTML" file="resources\md_user_manager\supervised_user_create_confirm.html" type="BINDATA" />
<include name="IDR_MD_SUPERVISED_USER_CREATE_CONFIRM_JS" file="resources\md_user_manager\supervised_user_create_confirm.js" type="BINDATA" />
<include name="IDR_MD_SUPERVISED_USER_LEARN_MORE_HTML" file="resources\md_user_manager\supervised_user_learn_more.html" type="BINDATA" />
<include name="IDR_MD_SUPERVISED_USER_LEARN_MORE_JS" file="resources\md_user_manager\supervised_user_learn_more.js" type="BINDATA" />
<include name="IDR_MD_USER_MANAGER_HTML" file="resources\md_user_manager\user_manager.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
<include name="IDR_MD_USER_MANAGER_JS" file="resources\md_user_manager\user_manager.js" flattenhtml="true" type="BINDATA" />
<include name="IDR_MD_USER_MANAGER_PAGES_HTML" file="resources\md_user_manager\user_manager_pages.html" type="BINDATA" />
......
......@@ -9,10 +9,7 @@ js_type_check("closure_compile") {
":control_bar",
":create_profile",
":error_dialog",
":import_supervised_user",
":profile_browser_proxy",
":supervised_user_create_confirm",
":supervised_user_learn_more",
":user_manager_pages",
":user_manager_tutorial",
]
......@@ -39,13 +36,6 @@ js_library("create_profile") {
js_library("error_dialog") {
}
js_library("import_supervised_user") {
deps = [
":profile_browser_proxy",
"//ui/webui/resources/js:i18n_behavior",
]
}
js_library("profile_browser_proxy") {
deps = [
"//ui/webui/resources/js:assert",
......@@ -53,20 +43,6 @@ js_library("profile_browser_proxy") {
]
}
js_library("supervised_user_create_confirm") {
deps = [
":profile_browser_proxy",
"//ui/webui/resources/js:i18n_behavior",
"//ui/webui/resources/js:util",
]
}
js_library("supervised_user_learn_more") {
deps = [
":profile_browser_proxy",
]
}
js_library("user_manager_pages") {
}
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="/import_supervised_user.html">
<link rel="import" href="/profile_browser_proxy.html">
<link rel="import" href="/shared_styles.html">
<link rel="import" href="chrome://resources/cr_elements/cr_profile_avatar_selector/cr_profile_avatar_selector.html">
......@@ -103,27 +102,6 @@
margin-top: 16px;
}
#supervised-user-container {
-webkit-padding-start: 32px;
}
#supervised-user-container #learn-more {
line-height: 20px;
}
#supervised-user-container .md-select-wrapper {
-webkit-margin-start: calc(-1 * var(--md-select-side-padding));
margin-top: 4px;
}
#supervised-user-container #import-user {
-webkit-margin-start: 16px;
}
#supervised-user-container #sign-in-howto-message {
margin-top: 12px;
}
#actions {
bottom: 16px;
display: flex;
......@@ -159,57 +137,18 @@
hidden="[[!isProfileShortcutsEnabled_]]">
$i18n{createDesktopShortcutLabel}
</paper-checkbox>
<template is="dom-if" if="[[isSupervisedUserCreationEnabled_]]">
<paper-checkbox id="makeSupervisedCheckbox" checked="{{isSupervised_}}">
$i18n{manageProfilesSupervisedSignedInLabel}
</paper-checkbox>
<div id="supervised-user-container">
<div id="learn-more" >
<a is="action-link" on-tap="onLearnMoreTap_">$i18n{learnMore}</a>
</div>
<template is="dom-if" if="[[isSupervised_]]">
<template is="dom-if" if="[[isSignedIn_(signedInUsers_)]]">
<div class="md-select-wrapper">
<select class="md-select" on-change="onAccountChanged_">
<option disabled selected>$i18n{selectAnAccount}</option>
<template is="dom-repeat" items="[[signedInUsers_]]">
<option value="[[index]]">
[[item.username]]
</option>
</template>
</select>
<span class="md-select-underline"></span>
</div>
<a id="import-user" is="action-link" on-tap="onImportUserTap_"
hidden="[[isImportUserLinkHidden_(createInProgress_,
loadingSupervisedUsers_,
signedInUserIndex_)]]">
$i18n{importExistingSupervisedUserLink}
</a>
</template>
<div id="sign-in-howto-message"
hidden="[[isSignedIn_(signedInUsers_)]]"
inner-h-t-m-l="[[i18nAllowIDAttr_('noSignedInUserMessage')]]">
</div>
</template>
</div>
</template>
<div id="actions">
<paper-spinner-lite active="[[isSpinnerActive_(
createInProgress_, loadingSupervisedUsers_)]]">
<paper-spinner-lite active="[[isSpinnerActive_(createInProgress_)]]">
</paper-spinner-lite>
<paper-button id="cancel" class="action secondary"
on-tap="onCancelTap_">
$i18n{cancel}
</paper-button>
<paper-button id="save" class="action primary" on-tap="onSaveTap_"
disabled="[[isSaveDisabled_(createInProgress_,
loadingSupervisedUsers_,
profileName_)]]">
disabled="[[isSaveDisabled_(createInProgress_, profileName_)]]">
$i18n{createProfileConfirm}
</paper-button>
</div>
<import-supervised-user id="importUserPopup"></import-supervised-user>
</div>
</template>
<script src="create_profile.js"></script>
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="/shared_styles.html">
<link rel="import" href="chrome://resources/cr_elements/cr_dialog/cr_dialog.html">
<link rel="import" href="chrome://resources/cr_elements/shared_style_css.html">
<link rel="import" href="chrome://resources/html/i18n_behavior.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-item/paper-item.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-listbox/paper-listbox.html">
<dom-module id="import-supervised-user">
<template>
<style include="shared-styles cr-shared-style iron-flex iron-flex-alignment iron-positioning">
:host {
--item-height: 52px;
--items-container-max-height: calc(var(--item-height) * 4);
}
#message {
margin-bottom: 16px;
margin-top: 20px;
white-space: pre-wrap;
word-wrap: break-word;
}
paper-listbox {
max-height: var(--items-container-max-height);
overflow: auto;
}
paper-listbox paper-item {
--paper-item: {
font-size: inherit;
height: var(--item-height);
line-height: inherit;
};
--paper-item-disabled: {
color: inherit;
};
--paper-item-focused: {
background: rgba(0, 0, 0, .04);
};
--paper-item-focused-before: {
background: none;
};
}
paper-listbox paper-item .profile-img {
flex-shrink: 0;
}
paper-listbox paper-item .profile-name {
-webkit-margin-start: 10px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
paper-listbox paper-item .on-device {
-webkit-margin-start: 10px;
flex-shrink: 0;
}
</style>
<cr-dialog id="dialog">
<div slot="title">$i18n{supervisedUserImportTitle}</div>
<div slot="body">
<div id="message">$i18n{supervisedUserImportText}</div>
<paper-listbox class="no-padding" selected="{{supervisedUserIndex_}}">
<template is="dom-repeat" items="[[supervisedUsers_]]">
<paper-item disabled="[[item.onCurrentDevice]]">
<img class="profile-img" src="[[item.iconURL]]">
<div class="profile-name">[[item.name]]</div>
<div class="on-device" hidden="[[!item.onCurrentDevice]]">
$i18n{supervisedUserAlreadyOnThisDevice}
</div>
</paper-item>
</template>
</paper-listbox>
</div>
<div slot="button-container">
<paper-button id="cancel" class="cancel-button" on-tap="onCancelTap_">
$i18n{cancel}
</paper-button>
<paper-button id="import" class="action-button"
on-tap="onImportTap_"
disabled="[[isImportDisabled_(supervisedUserIndex_)]]">
$i18n{supervisedUserImportOk}
</paper-button>
</div>
</cr-dialog>
</template>
<script src="import_supervised_user.js"></script>
</dom-module>
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview 'import-supervised-user' is a dialog that allows user to select
* a supervised profile from a list of profiles to import on the current device.
*/
(function() {
/**
* It means no supervised user is selected.
* @type {number}
*/
const NO_USER_SELECTED = -1;
Polymer({
is: 'import-supervised-user',
behaviors: [
I18nBehavior,
],
properties: {
/**
* The currently signed in user and the custodian.
* @private {?SignedInUser}
*/
signedInUser_: {
type: Object,
value: function() {
return null;
}
},
/**
* The list of supervised users managed by signedInUser_.
* @private {!Array<!SupervisedUser>}
*/
supervisedUsers_: {
type: Array,
value: function() {
return [];
}
},
/**
* Index of the selected supervised user.
* @private {number}
*/
supervisedUserIndex_: {type: Number, value: NO_USER_SELECTED}
},
/**
* Displays the dialog.
* @param {(!SignedInUser|undefined)} signedInUser
* @param {!Array<!SupervisedUser>} supervisedUsers
*/
show: function(signedInUser, supervisedUsers) {
this.supervisedUsers_ = supervisedUsers;
this.supervisedUsers_.sort(function(a, b) {
if (a.onCurrentDevice != b.onCurrentDevice)
return a.onCurrentDevice ? 1 : -1;
return a.name.localeCompare(b.name);
});
this.supervisedUserIndex_ = NO_USER_SELECTED;
this.signedInUser_ = signedInUser || null;
if (this.signedInUser_)
this.$.dialog.showModal();
},
/**
* @param {number} supervisedUserIndex Index of the selected supervised user.
* @return {boolean} Whether the 'Import' button should be disabled.
* @private
*/
isImportDisabled_: function(supervisedUserIndex) {
return supervisedUserIndex == NO_USER_SELECTED;
},
/**
* Called when the user clicks the 'Import' button. it proceeds with importing
* the supervised user.
* @private
*/
onImportTap_: function() {
const supervisedUser = this.supervisedUsers_[this.supervisedUserIndex_];
if (this.signedInUser_ && supervisedUser) {
this.$.dialog.close();
// Event is caught by create-profile.
this.fire(
'import',
{supervisedUser: supervisedUser, signedInUser: this.signedInUser_});
}
},
/** @private */
onCancelTap_: function() {
this.$.dialog.close();
},
});
})();
......@@ -7,26 +7,12 @@
* between JS and C++ for creating/importing profiles in the user-manager page.
*/
/** @typedef {{username: string, profilePath: string}} */
let SignedInUser;
/**
* @typedef {{name: string,
* filePath: string,
* isSupervised: boolean,
* custodianUsername: string,
* showConfirmation: boolean}}
* filePath: string}}
*/
let ProfileInfo;
/**
* @typedef {{id: string,
* name: string,
* iconURL: string,
* onCurrentDevice: boolean}}
*/
let SupervisedUser;
cr.define('signin', function() {
/** @interface */
function ProfileBrowserProxy() {}
......@@ -39,13 +25,6 @@ cr.define('signin', function() {
assertNotReached();
},
/**
* Gets the current signed-in users.
*/
getSignedInUsers: function() {
assertNotReached();
},
/**
* Launches the guest user.
*/
......@@ -53,15 +32,6 @@ cr.define('signin', function() {
assertNotReached();
},
/**
* @param {string} profilePath Profile Path of the custodian.
* @return {!Promise<!Array<!SupervisedUser>>} The list of existing
* supervised users.
*/
getExistingSupervisedUsers: function(profilePath) {
assertNotReached();
},
/**
* Creates a profile.
* @param {string} profileName Name of the new profile.
......@@ -69,29 +39,8 @@ cr.define('signin', function() {
* profile.
* @param {boolean} createShortcut if true a desktop shortcut will be
* created.
* @param {boolean} isSupervised True if the new profile is supervised.
* @param {string} supervisedUserId ID of the supervised user to be
* imported.
* @param {string} custodianProfilePath Profile path of the custodian if
* the new profile is supervised.
*/
createProfile: function(
profileName, profileIconUrl, createShortcut, isSupervised,
supervisedUserId, custodianProfilePath) {
assertNotReached();
},
/**
* Cancels creation of the new profile.
*/
cancelCreateProfile: function() {
assertNotReached();
},
/**
* Cancels loading supervised users.
*/
cancelLoadingSupervisedUsers: function() {
createProfile: function(profileName, profileIconUrl, createShortcut) {
assertNotReached();
},
......@@ -162,39 +111,15 @@ cr.define('signin', function() {
chrome.send('requestDefaultProfileIcons');
},
/** @override */
getSignedInUsers: function() {
chrome.send('requestSignedInProfiles');
},
/** @override */
launchGuestUser: function() {
chrome.send('launchGuest');
},
/** @override */
getExistingSupervisedUsers: function(profilePath) {
return cr.sendWithPromise('getExistingSupervisedUsers', profilePath);
},
/** @override */
createProfile: function(
profileName, profileIconUrl, createShortcut, isSupervised,
supervisedUserId, custodianProfilePath) {
chrome.send('createProfile', [
profileName, profileIconUrl, createShortcut, isSupervised,
supervisedUserId, custodianProfilePath
]);
},
/** @override */
cancelCreateProfile: function() {
chrome.send('cancelCreateProfile');
},
/** @override */
cancelLoadingSupervisedUsers: function() {
chrome.send('cancelLoadingSupervisedUsers');
createProfile: function(profileName, profileIconUrl, createShortcut) {
chrome.send(
'createProfile', [profileName, profileIconUrl, createShortcut]);
},
/** @override */
......
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="/profile_browser_proxy.html">
<link rel="import" href="/shared_styles.html">
<link rel="import" href="chrome://resources/html/util.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html">
<dom-module id="supervised-user-create-confirm">
<template>
<style include="shared-styles iron-flex iron-flex-alignment iron-positioning">
:host {
align-self: center;
}
#container {
color: var(--primary-text-color);
line-height: 20px;
width: var(--page-width);
}
#title-area {
font-size: 16px;
font-weight: 500;
}
.content-area {
padding-top: 32px;
white-space: pre-wrap;
word-wrap: break-word;
}
#actions {
bottom: 16px;
position: absolute;
right: 16px;
}
:host-context([dir='rtl']) #actions {
left: 16px;
right: auto;
}
</style>
<div id="container">
<div id="title-area" class="horizontal justified layout">
<span id="title">[[titleText_(profileInfo)]]</span>
</div>
<div class="content-area"
inner-h-t-m-l="[[confirmationMessage_(profileInfo)]]">
</div>
<div id="actions">
<paper-button id="ok" class="action secondary" on-tap="onOkTap_">
$i18n{supervisedUserCreatedDone}
</paper-button>
<paper-button id="switchUser" class="action primary"
on-tap="onSwitchUserTap_">
[[switchUserText_(profileInfo)]]
</paper-button>
</div>
</div>
</template>
<script src="supervised_user_create_confirm.js"></script>
</dom-module>
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview 'supervised-user-create-confirm' is a page that is displayed
* upon successful creation of a supervised user. It contains information for
* the custodian on where to configure browsing restrictions as well as how to
* exit and childlock their profile.
*/
(function() {
/**
* Maximum length of the supervised user profile name or custodian's username.
* @type {number}
*/
const MAX_NAME_LENGTH = 50;
Polymer({
is: 'supervised-user-create-confirm',
behaviors: [I18nBehavior],
properties: {
/**
* Profile Info of the supervised user that is passed to the page.
* @type {?ProfileInfo}
*/
profileInfo: {
type: Object,
value: function() {
return null;
}
},
/** @private {!signin.ProfileBrowserProxy} */
browserProxy_: Object
},
listeners: {'tap': 'onTap_'},
/** @override */
created: function() {
this.browserProxy_ = signin.ProfileBrowserProxyImpl.getInstance();
},
/**
* Handles tap events from dynamically created links in the
* supervisedUserCreatedText i18n string.
* @param {!Event} event
* @private
*/
onTap_: function(event) {
const element = Polymer.dom(event).rootTarget;
// Handle the tap event only if the target is a '<a>' element.
if (element.nodeName == 'A') {
this.browserProxy_.openUrlInLastActiveProfileBrowser(element.href);
event.preventDefault();
}
},
/**
* Returns the shortened profile name or empty string if |profileInfo| is
* null.
* @param {?ProfileInfo} profileInfo
* @return {string}
* @private
*/
elideProfileName_: function(profileInfo) {
const name = profileInfo ? profileInfo.name : '';
return elide(name, MAX_NAME_LENGTH);
},
/**
* Returns the shortened custodian username or empty string if |profileInfo|
* is null.
* @param {?ProfileInfo} profileInfo
* @return {string}
* @private
*/
elideCustodianUsername_: function(profileInfo) {
const name = profileInfo ? profileInfo.custodianUsername : '';
return elide(name, MAX_NAME_LENGTH);
},
/**
* Computed binding returning the text of the title section.
* @param {?ProfileInfo} profileInfo
* @return {string}
* @private
*/
titleText_: function(profileInfo) {
return this.i18n(
'supervisedUserCreatedTitle', this.elideProfileName_(profileInfo));
},
/**
* Computed binding returning the sanitized confirmation HTML message that is
* safe to set as innerHTML.
* @param {?ProfileInfo} profileInfo
* @return {string}
* @private
*/
confirmationMessage_: function(profileInfo) {
return this.i18nAdvanced('supervisedUserCreatedText', {
substitutions: [
this.elideProfileName_(profileInfo),
this.elideCustodianUsername_(profileInfo)
],
});
},
/**
* Computed binding returning the text of the 'Switch To User' button.
* @param {?ProfileInfo} profileInfo
* @return {string}
* @private
*/
switchUserText_: function(profileInfo) {
return this.i18n(
'supervisedUserCreatedSwitch', this.elideProfileName_(profileInfo));
},
/**
* Handler for the 'Ok' button tap event.
* @param {!Event} event
* @private
*/
onOkTap_: function(event) {
// Event is caught by user-manager-pages.
this.fire('change-page', {page: 'user-pods-page'});
},
/**
* Handler for the 'Switch To User' button tap event.
* @param {!Event} event
* @private
*/
onSwitchUserTap_: function(event) {
this.browserProxy_.switchToProfile(this.profileInfo.filePath);
// Event is caught by user-manager-pages.
this.fire('change-page', {page: 'user-pods-page'});
}
});
})();
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="/shared_styles.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html">
<dom-module id="supervised-user-learn-more">
<template>
<style include="shared-styles iron-flex iron-flex-alignment iron-positioning">
:host {
align-self: center;
}
#container {
color: var(--primary-text-color);
line-height: 20px;
width: var(--page-width);
}
#title-area {
font-size: 16px;
font-weight: 500;
}
.content-area {
padding-top: 32px;
white-space: pre-wrap;
word-wrap: break-word;
}
#actions {
bottom: 16px;
position: absolute;
right: 16px;
}
:host-context([dir='rtl']) #actions {
left: 16px;
right: auto;
}
</style>
<div id="container">
<div id="title-area" class="horizontal justified layout">
<span id="title">$i18n{supervisedUserLearnMoreTitle}</span>
</div>
<div class="content-area">$i18nRaw{supervisedUserLearnMoreText}</div>
<div id="actions">
<paper-button id="done" class="action primary" on-tap="onDoneTap_">
$i18n{supervisedUserLearnMoreDone}
</paper-button>
</div>
</div>
</template>
<script src="supervised_user_learn_more.js"></script>
</dom-module>
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview 'supervised-user-learn-more' is a page that contains
* information about what a supervised user is, what happens when a supervised
* user is created, and a link to the help center for more information.
*/
Polymer({
is: 'supervised-user-learn-more',
properties: {
/** @private {!signin.ProfileBrowserProxy} */
browserProxy_: Object
},
listeners: {'tap': 'onTap_'},
/** @override */
created: function() {
this.browserProxy_ = signin.ProfileBrowserProxyImpl.getInstance();
},
/**
* Handles tap events from dynamically created links in the
* supervisedUserLearnMoreText i18n string.
* @param {!Event} event
* @private
*/
onTap_: function(event) {
const element = Polymer.dom(event).rootTarget;
// Handle the tap event only if the target is a '<a>' element.
if (element.nodeName == 'A') {
this.browserProxy_.openUrlInLastActiveProfileBrowser(element.href);
event.preventDefault();
}
},
/**
* Handler for the 'Done' button tap event.
* @param {!Event} event
* @private
*/
onDoneTap_: function(event) {
// Event is caught by user-manager-pages.
this.fire('change-page', {page: 'create-user-page'});
}
});
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="/create_profile.html">
<link rel="import" href="/supervised_user_create_confirm.html">
<link rel="import" href="/supervised_user_learn_more.html">
<link rel="import" href="chrome://resources/polymer/v1_0/neon-animation/animations/fade-in-animation.html">
<link rel="import" href="chrome://resources/polymer/v1_0/neon-animation/animations/fade-out-animation.html">
<link rel="import" href="chrome://resources/polymer/v1_0/neon-animation/neon-animatable.html">
......
......@@ -2218,8 +2218,6 @@ split_static_library("ui") {
"webui/signin/signin_error_handler.h",
"webui/signin/signin_error_ui.cc",
"webui/signin/signin_error_ui.h",
"webui/signin/signin_supervised_user_import_handler.cc",
"webui/signin/signin_supervised_user_import_handler.h",
"webui/signin/signin_utils_desktop.cc",
"webui/signin/signin_utils_desktop.h",
"webui/signin/signin_web_dialog_ui.cc",
......
......@@ -26,10 +26,6 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/webui/web_ui_util.h"
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
#include "chrome/browser/ui/webui/signin/signin_supervised_user_import_handler.h"
#endif
MDUserManagerUI::MDUserManagerUI(content::WebUI* web_ui)
: WebUIController(web_ui) {
auto signin_create_profile_handler =
......@@ -40,13 +36,6 @@ MDUserManagerUI::MDUserManagerUI(content::WebUI* web_ui)
std::make_unique<UserManagerScreenHandler>();
user_manager_screen_handler_ = user_manager_screen_handler.get();
web_ui->AddMessageHandler(std::move(user_manager_screen_handler));
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
auto signin_supervised_user_import_handler =
std::make_unique<SigninSupervisedUserImportHandler>();
signin_supervised_user_import_handler_ =
signin_supervised_user_import_handler.get();
web_ui->AddMessageHandler(std::move(signin_supervised_user_import_handler));
#endif
base::DictionaryValue localized_strings;
GetLocalizedStrings(&localized_strings);
......@@ -71,7 +60,6 @@ content::WebUIDataSource* MDUserManagerUI::CreateUIDataSource(
ProfileShortcutManager::IsFeatureEnabled());
source->AddBoolean("isForceSigninEnabled",
signin_util::IsForceSigninEnabled());
source->AddBoolean("isSupervisedUserCreationEnabled", false);
source->SetJsonPath("strings.js");
......@@ -81,10 +69,6 @@ content::WebUIDataSource* MDUserManagerUI::CreateUIDataSource(
source->AddResourcePath("create_profile.js", IDR_MD_CREATE_PROFILE_JS);
source->AddResourcePath("error_dialog.html", IDR_MD_ERROR_DIALOG_HTML);
source->AddResourcePath("error_dialog.js", IDR_MD_ERROR_DIALOG_JS);
source->AddResourcePath("import_supervised_user.html",
IDR_MD_IMPORT_SUPERVISED_USER_HTML);
source->AddResourcePath("import_supervised_user.js",
IDR_MD_IMPORT_SUPERVISED_USER_JS);
source->AddResourcePath("profile_browser_proxy.html",
IDR_MD_PROFILE_BROWSER_PROXY_HTML);
source->AddResourcePath("profile_browser_proxy.js",
......@@ -92,14 +76,6 @@ content::WebUIDataSource* MDUserManagerUI::CreateUIDataSource(
source->AddResourcePath("shared_styles.html",
IDR_MD_USER_MANAGER_SHARED_STYLES_HTML);
source->AddResourcePath("strings.html", IDR_MD_USER_MANAGER_STRINGS_HTML);
source->AddResourcePath("supervised_user_create_confirm.html",
IDR_MD_SUPERVISED_USER_CREATE_CONFIRM_HTML);
source->AddResourcePath("supervised_user_create_confirm.js",
IDR_MD_SUPERVISED_USER_CREATE_CONFIRM_JS);
source->AddResourcePath("supervised_user_learn_more.html",
IDR_MD_SUPERVISED_USER_LEARN_MORE_HTML);
source->AddResourcePath("supervised_user_learn_more.js",
IDR_MD_SUPERVISED_USER_LEARN_MORE_JS);
source->AddResourcePath("user_manager.js", IDR_MD_USER_MANAGER_JS);
source->AddResourcePath("user_manager_pages.html",
IDR_MD_USER_MANAGER_PAGES_HTML);
......@@ -119,9 +95,6 @@ void MDUserManagerUI::GetLocalizedStrings(
base::DictionaryValue* localized_strings) {
user_manager_screen_handler_->GetLocalizedValues(localized_strings);
signin_create_profile_handler_->GetLocalizedValues(localized_strings);
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
signin_supervised_user_import_handler_->GetLocalizedValues(localized_strings);
#endif
const std::string& app_locale = g_browser_process->GetApplicationLocale();
webui::SetLoadTimeDataDefaults(app_locale, localized_strings);
......
......@@ -6,16 +6,11 @@
#define CHROME_BROWSER_UI_WEBUI_SIGNIN_MD_USER_MANAGER_UI_H_
#include "base/macros.h"
#include "chrome/common/buildflags.h"
#include "content/public/browser/web_ui_controller.h"
class SigninCreateProfileHandler;
class UserManagerScreenHandler;
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
class SigninSupervisedUserImportHandler;
#endif
namespace base {
class DictionaryValue;
}
......@@ -37,10 +32,6 @@ class MDUserManagerUI : public content::WebUIController {
SigninCreateProfileHandler* signin_create_profile_handler_ = nullptr;
UserManagerScreenHandler* user_manager_screen_handler_ = nullptr;
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
SigninSupervisedUserImportHandler* signin_supervised_user_import_handler_;
#endif
DISALLOW_COPY_AND_ASSIGN(MDUserManagerUI);
};
......
......@@ -11,7 +11,6 @@
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/common/buildflags.h"
#include "content/public/browser/notification_observer.h"
......@@ -26,8 +25,7 @@ class ListValue;
// Handler for the 'create profile' page.
class SigninCreateProfileHandler : public content::WebUIMessageHandler,
public content::NotificationObserver,
public ProfileAttributesStorage::Observer {
public content::NotificationObserver {
public:
SigninCreateProfileHandler();
~SigninCreateProfileHandler() override;
......@@ -52,9 +50,6 @@ class SigninCreateProfileHandler : public content::WebUIMessageHandler,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// ProfileAttributesStorage::Observer implementation:
void OnProfileAuthInfoChanged(const base::FilePath& profile_path) override;
// Represents the final profile creation status. It is used to map
// the status to the javascript method to be called.
enum ProfileCreationStatus {
......@@ -78,43 +73,27 @@ class SigninCreateProfileHandler : public content::WebUIMessageHandler,
// "requestDefaultProfileIcons" is fulfilled.
void SendNewProfileDefaults();
// Callback for the "requestSignedInProfiles" message.
// Sends the email address of the signed-in user, or an empty string if the
// user is not signed in.
void RequestSignedInProfiles(const base::ListValue* args);
// Asynchronously creates and initializes a new profile.
// The arguments are as follows:
// 0: name (string)
// 1: icon (string)
// 2: a flag stating whether we should create a profile desktop shortcut
// (optional, boolean)
// 3: a flag stating whether the user should be supervised
// (optional, boolean)
// 4: a string representing the supervised user ID.
// 5: a string representing the custodian profile path.
void CreateProfile(const base::ListValue* args);
// If a local error occurs during profile creation, then show an appropriate
// error message. However, if profile creation succeeded and the
// profile being created/imported is a supervised user profile,
// then proceed with the registration step. Otherwise, update the UI
// as the final task after a new profile has been created.
// error message. Otherwise, update the UI as the final task after a new
// profile has been created.
void OnProfileCreated(bool create_shortcut,
const std::string& supervised_user_id,
Profile* custodian_profile,
Profile* profile,
Profile::CreateStatus status);
void HandleProfileCreationSuccess(bool create_shortcut,
const std::string& supervised_user_id,
Profile* custodian_profile,
Profile* profile);
// Creates desktop shortcut and updates the UI to indicate success
// when creating a profile.
void CreateShortcutAndShowSuccess(bool create_shortcut,
Profile* custodian_profile,
Profile* profile);
// Opens a new window for |profile|.
......@@ -153,21 +132,7 @@ class SigninCreateProfileHandler : public content::WebUIMessageHandler,
// Asynchronously creates and initializes a new profile.
virtual void DoCreateProfile(const base::string16& name,
const std::string& icon_url,
bool create_shortcut,
const std::string& supervised_user_id,
Profile* custodian_profile);
#if BUILDFLAG(ENABLE_SUPERVISED_USERS)
// Cancels creation of a supervised-user profile currently in progress, as
// indicated by profile_path_being_created_, removing the object and files
// and canceling supervised-user registration. This is the handler for the
// "cancelCreateProfile" message. |args| is not used.
void HandleCancelProfileCreation(const base::ListValue* args);
// Callback for the "switchToProfile" message. Opens a new window for the
// profile. The profile file path is passed as a string argument.
void SwitchToProfile(const base::ListValue* args);
#endif
bool create_shortcut);
content::NotificationRegistrar registrar_;
......
......@@ -39,12 +39,6 @@ namespace {
const char kTestProfileName[] = "test-profile-name";
const char kTestGaiaId1[] = "test-gaia-id-1";
const char kTestEmail1[] = "foo1@bar.com";
const char kTestGaiaId2[] = "test-gaia-id-2";
const char kTestEmail2[] = "foo2@bar.com";
const char kTestWebUIResponse[] = "cr.webUIListenerCallback";
} // namespace
......@@ -60,25 +54,21 @@ class TestSigninCreateProfileHandler : public SigninCreateProfileHandler {
// Mock this method since it tries to create a profile asynchronously and the
// test terminates before the callback gets called.
MOCK_METHOD5(DoCreateProfile,
MOCK_METHOD3(DoCreateProfile,
void(const base::string16& name,
const std::string& icon_url,
bool create_shortcut,
const std::string& supervised_user_id,
Profile* custodian_profile));
bool create_shortcut));
// Creates the profile synchronously, sets the appropriate flag and calls the
// callback method to resume profile creation flow.
void RealDoCreateProfile(const base::string16& name,
const std::string& icon_url,
bool create_shortcut,
const std::string& supervised_user_id,
Profile* custodian_profile) {
bool create_shortcut) {
// Create the profile synchronously.
Profile* profile = profile_manager_->CreateTestingProfile(
kTestProfileName,
std::unique_ptr<sync_preferences::TestingPrefServiceSyncable>(), name,
0, supervised_user_id, TestingProfile::TestingFactories());
0, std::string(), TestingProfile::TestingFactories());
// Set the flag used to track the state of the creation flow.
profile_path_being_created_ = profile->GetPath();
......@@ -86,14 +76,12 @@ class TestSigninCreateProfileHandler : public SigninCreateProfileHandler {
// Call the callback method to resume profile creation flow.
SigninCreateProfileHandler::OnProfileCreated(
create_shortcut,
supervised_user_id,
custodian_profile,
profile,
Profile::CREATE_STATUS_INITIALIZED);
}
// Mock this method to track when an attempt to open a new browser window for
// the newly created/imported profile is made.
// the newly created profile is made.
MOCK_METHOD2(OpenNewWindowForProfile,
void(Profile* profile, Profile::CreateStatus status));
......@@ -101,14 +89,6 @@ class TestSigninCreateProfileHandler : public SigninCreateProfileHandler {
// the test.
MOCK_METHOD1(OpenSigninDialogForProfile, void(Profile* profile));
// We don't actually need to register supervised users in the test. Mock this
// method to fake the registration part.
MOCK_METHOD4(RegisterSupervisedUser,
void(bool create_shortcut,
const std::string& supervised_user_id,
Profile* custodian_profile,
Profile* new_profile));
private:
TestingProfileManager* profile_manager_;
DISALLOW_COPY_AND_ASSIGN(TestSigninCreateProfileHandler);
......@@ -129,16 +109,6 @@ class SigninCreateProfileHandlerTest : public BrowserWithTestWindowTest {
TestingProfile::TestingFactories factories;
factories.push_back(std::make_pair(SigninManagerFactory::GetInstance(),
BuildFakeSigninManagerBase));
custodian_ = profile_manager()->CreateTestingProfile(
"custodian-profile",
std::unique_ptr<sync_preferences::TestingPrefServiceSyncable>(),
base::UTF8ToUTF16("custodian-profile"), 0, std::string(), factories);
// Authenticate the custodian profile.
fake_signin_manager_ = static_cast<FakeSigninManagerForTesting*>(
SigninManagerFactory::GetForProfile(custodian_));
fake_signin_manager_->SetAuthenticatedAccountInfo(kTestGaiaId1,
kTestEmail1);
}
void TearDown() override {
......@@ -154,17 +124,12 @@ class SigninCreateProfileHandlerTest : public BrowserWithTestWindowTest {
return handler_.get();
}
TestingProfile* custodian() {
return custodian_;
}
FakeSigninManagerForTesting* signin_manager() {
return fake_signin_manager_;
}
private:
std::unique_ptr<content::TestWebUI> web_ui_;
TestingProfile* custodian_;
FakeSigninManagerForTesting* fake_signin_manager_;
std::unique_ptr<TestSigninCreateProfileHandler> handler_;
};
......@@ -200,64 +165,23 @@ TEST_F(SigninCreateProfileHandlerTest, ReturnDefaultProfileNameAndIcons) {
EXPECT_NE("", profile_name);
}
TEST_F(SigninCreateProfileHandlerTest, ReturnSignedInProfiles) {
// Create two test profiles.
Profile* profile_1 = profile_manager()->CreateTestingProfile("profile_1");
ASSERT_TRUE(profile_1);
Profile* profile_2 = profile_manager()->CreateTestingProfile("profile_2");
ASSERT_TRUE(profile_2);
// Set Auth Info only for profile_2.
ProfileAttributesEntry* entry;
ASSERT_TRUE(profile_manager()->profile_attributes_storage()->
GetProfileAttributesWithPath(profile_2->GetPath(), &entry));
entry->SetAuthInfo(kTestGaiaId2, base::UTF8ToUTF16(kTestEmail2));
// Expect a JS callback with a list containing profile_2.
EXPECT_EQ(1U, web_ui()->call_data().size());
EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name());
std::string callback_name;
ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name));
EXPECT_EQ("signedin-users-received", callback_name);
const base::ListValue* signed_in_profiles;
ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsList(&signed_in_profiles));
EXPECT_EQ(1U, signed_in_profiles->GetSize());
const base::DictionaryValue* signed_in_profile;
ASSERT_TRUE(signed_in_profiles->GetDictionary(0, &signed_in_profile));
std::string user_name;
ASSERT_TRUE(signed_in_profile->GetString("username", &user_name));
EXPECT_EQ(kTestEmail2, user_name);
base::string16 profile_path;
ASSERT_TRUE(signed_in_profile->GetString("profilePath", &profile_path));
EXPECT_EQ(profile_2->GetPath().AsUTF16Unsafe(), profile_path);
}
TEST_F(SigninCreateProfileHandlerTest, CreateProfile) {
// Expect the call to create the profile.
EXPECT_CALL(*handler(), DoCreateProfile(_, _, _, _, _))
EXPECT_CALL(*handler(), DoCreateProfile(_, _, _))
.WillOnce(Invoke(handler(),
&TestSigninCreateProfileHandler::RealDoCreateProfile));
// Expect no calls to register a supervised user.
EXPECT_CALL(*handler(), RegisterSupervisedUser(_, _, _, _)).Times(0);
// Expect a new browser window for the new profile to be opened.
EXPECT_CALL(*handler(), OpenNewWindowForProfile(_, _));
// Expect no signin dialog opened for the new profile.
EXPECT_CALL(*handler(), OpenSigninDialogForProfile(_)).Times(0);
// Create a non-supervised profile.
// Create a profile.
base::ListValue list_args;
list_args.AppendString(kTestProfileName);
list_args.AppendString(profiles::GetDefaultAvatarIconUrl(0));
list_args.AppendBoolean(false); // create_shortcut
list_args.AppendBoolean(false); // is_supervised
handler()->CreateProfile(&list_args);
// Expect a JS callbacks with the new profile information.
......@@ -268,18 +192,6 @@ TEST_F(SigninCreateProfileHandlerTest, CreateProfile) {
std::string callback_name;
ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name));
EXPECT_EQ("create-profile-success", callback_name);
const base::DictionaryValue* profile;
ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsDictionary(&profile));
std::string profile_name;
ASSERT_TRUE(profile->GetString("name", &profile_name));
EXPECT_NE("", profile_name);
std::string profile_path;
ASSERT_TRUE(profile->GetString("filePath", &profile_path));
EXPECT_NE("", profile_path);
bool is_supervised;
ASSERT_TRUE(profile->GetBoolean("isSupervised", &is_supervised));
ASSERT_FALSE(is_supervised);
}
TEST_F(SigninCreateProfileHandlerTest, CreateProfileWithForceSignin) {
......@@ -287,13 +199,10 @@ TEST_F(SigninCreateProfileHandlerTest, CreateProfileWithForceSignin) {
ASSERT_TRUE(signin_util::IsForceSigninEnabled());
// Expect the call to create the profile.
EXPECT_CALL(*handler(), DoCreateProfile(_, _, _, _, _))
EXPECT_CALL(*handler(), DoCreateProfile(_, _, _))
.WillOnce(Invoke(handler(),
&TestSigninCreateProfileHandler::RealDoCreateProfile));
// Expect no calls to register a supervised user.
EXPECT_CALL(*handler(), RegisterSupervisedUser(_, _, _, _)).Times(0);
// Expect no new browser window for the new profile.
EXPECT_CALL(*handler(), OpenNewWindowForProfile(_, _)).Times(0);
......@@ -304,7 +213,6 @@ TEST_F(SigninCreateProfileHandlerTest, CreateProfileWithForceSignin) {
list_args.AppendString(kTestProfileName);
list_args.AppendString(profiles::GetDefaultAvatarIconUrl(0));
list_args.AppendBoolean(false); // create_shortcut
list_args.AppendBoolean(false); // is_supervised
handler()->CreateProfile(&list_args);
// Expect a JS callbacks with the new profile information.
......@@ -316,19 +224,5 @@ TEST_F(SigninCreateProfileHandlerTest, CreateProfileWithForceSignin) {
ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_name));
EXPECT_EQ("create-profile-success", callback_name);
const base::DictionaryValue* profile;
ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsDictionary(&profile));
std::string profile_name;
ASSERT_TRUE(profile->GetString("name", &profile_name));
EXPECT_NE("", profile_name);
std::string profile_path;
ASSERT_TRUE(profile->GetString("filePath", &profile_path));
EXPECT_NE("", profile_path);
bool is_supervised;
ASSERT_TRUE(profile->GetBoolean("isSupervised", &is_supervised));
ASSERT_FALSE(is_supervised);
bool show_confirmation;
ASSERT_TRUE(profile->GetBoolean("showConfirmation", &show_confirmation));
ASSERT_FALSE(show_confirmation);
signin_util::SetForceSigninForTesting(false);
}
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/signin/signin_supervised_user_import_handler.h"
#include <stddef.h>
#include <memory>
#include <set>
#include <utility>
#include <vector>
#include "base/bind.h"
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/value_conversions.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/supervised_user/supervised_user_constants.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/user_manager.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "components/prefs/pref_service.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_ui.h"
#include "content/public/common/referrer.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
SigninSupervisedUserImportHandler::SigninSupervisedUserImportHandler()
: weak_ptr_factory_(this) {
}
SigninSupervisedUserImportHandler::~SigninSupervisedUserImportHandler() {
}
void SigninSupervisedUserImportHandler::GetLocalizedValues(
base::DictionaryValue* localized_strings) {
DCHECK(localized_strings);
localized_strings->SetString("supervisedUserImportTitle",
l10n_util::GetStringUTF16(
IDS_IMPORT_EXISTING_LEGACY_SUPERVISED_USER_TITLE));
localized_strings->SetString("supervisedUserImportText",
l10n_util::GetStringUTF16(
IDS_IMPORT_EXISTING_LEGACY_SUPERVISED_USER_TEXT));
localized_strings->SetString("noSupervisedUserImportText",
l10n_util::GetStringUTF16(IDS_IMPORT_NO_EXISTING_SUPERVISED_USER_TEXT));
localized_strings->SetString("supervisedUserImportOk",
l10n_util::GetStringUTF16(IDS_IMPORT_EXISTING_LEGACY_SUPERVISED_USER_OK));
localized_strings->SetString("supervisedUserAlreadyOnThisDevice",
l10n_util::GetStringUTF16(
IDS_LEGACY_SUPERVISED_USER_ALREADY_ON_THIS_DEVICE));
}
void SigninSupervisedUserImportHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"getExistingSupervisedUsers",
base::BindRepeating(
&SigninSupervisedUserImportHandler::GetExistingSupervisedUsers,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"openUrlInLastActiveProfileBrowser",
base::BindRepeating(
&SigninSupervisedUserImportHandler::OpenUrlInLastActiveProfileBrowser,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"authenticateCustodian",
base::BindRepeating(
&SigninSupervisedUserImportHandler::AuthenticateCustodian,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"cancelLoadingSupervisedUsers",
base::BindRepeating(
&SigninSupervisedUserImportHandler::HandleCancelLoadSupervisedUsers,
base::Unretained(this)));
}
void SigninSupervisedUserImportHandler::AssignWebUICallbackId(
const base::ListValue* args) {
CHECK_LE(1U, args->GetSize());
CHECK(webui_callback_id_.empty());
CHECK(args->GetString(0, &webui_callback_id_));
AllowJavascript();
}
void SigninSupervisedUserImportHandler::OpenUrlInLastActiveProfileBrowser(
const base::ListValue* args) {
CHECK_EQ(1U, args->GetSize());
std::string url;
bool success = args->GetString(0, &url);
DCHECK(success);
content::OpenURLParams params(GURL(url), content::Referrer(),
WindowOpenDisposition::NEW_FOREGROUND_TAB,
ui::PAGE_TRANSITION_LINK, false);
// ProfileManager::GetLastUsedProfile() will attempt to load the default
// profile if there is no last used profile. If the default profile is not
// fully loaded and initialized, it will attempt to do so synchronously.
// Therefore we cannot use that method here. If the last used profile is not
// loaded, we do nothing. This is an edge case and should not happen often.
ProfileManager* profile_manager = g_browser_process->profile_manager();
base::FilePath last_used_profile_dir =
profile_manager->GetLastUsedProfileDir(profile_manager->user_data_dir());
Profile* last_used_profile =
profile_manager->GetProfileByPath(last_used_profile_dir);
if (last_used_profile) {
// Last used profile may be the Guest Profile.
if (ProfileManager::IncognitoModeForced(last_used_profile))
last_used_profile = last_used_profile->GetOffTheRecordProfile();
// Get the browser owned by the last used profile or create a new one if
// it doesn't exist.
Browser* browser = chrome::FindLastActiveWithProfile(last_used_profile);
if (!browser)
browser = new Browser(
Browser::CreateParams(Browser::TYPE_TABBED, last_used_profile, true));
browser->OpenURL(params);
}
}
void SigninSupervisedUserImportHandler::AuthenticateCustodian(
const base::ListValue* args) {
CHECK_EQ(1U, args->GetSize());
std::string email;
bool success = args->GetString(0, &email);
DCHECK(success);
UserManagerProfileDialog::ShowReauthDialog(
web_ui()->GetWebContents()->GetBrowserContext(), email,
signin_metrics::Reason::REASON_REAUTHENTICATION);
}
void SigninSupervisedUserImportHandler::GetExistingSupervisedUsers(
const base::ListValue* args) {
CHECK_EQ(2U, args->GetSize());
AssignWebUICallbackId(args);
base::FilePath custodian_profile_path;
const base::Value* profile_path_value;
bool success = args->Get(1, &profile_path_value);
DCHECK(success);
success = base::GetValueAsFilePath(*profile_path_value,
&custodian_profile_path);
DCHECK(success);
// Load custodian profile.
g_browser_process->profile_manager()->CreateProfileAsync(
custodian_profile_path,
base::Bind(
&SigninSupervisedUserImportHandler::LoadCustodianProfileCallback,
weak_ptr_factory_.GetWeakPtr()),
base::string16(), std::string(), std::string());
}
void SigninSupervisedUserImportHandler::HandleCancelLoadSupervisedUsers(
const base::ListValue* args) {
webui_callback_id_.clear();
}
void SigninSupervisedUserImportHandler::LoadCustodianProfileCallback(
Profile* profile, Profile::CreateStatus status) {
// This method gets called once before with Profile::CREATE_STATUS_CREATED.
switch (status) {
case Profile::CREATE_STATUS_LOCAL_FAIL: {
RejectCallback(GetLocalErrorMessage());
break;
}
case Profile::CREATE_STATUS_CREATED: {
// Ignore the intermediate status.
break;
}
case Profile::CREATE_STATUS_INITIALIZED: {
// We are only interested in Profile::CREATE_STATUS_INITIALIZED when
// everything is ready.
if (profile->IsSupervised()) {
webui_callback_id_.clear();
return;
}
if (!IsAccountConnected(profile) || HasAuthError(profile)) {
RejectCallback(GetAuthErrorMessage(profile));
return;
}
break;
}
case Profile::CREATE_STATUS_CANCELED:
case Profile::CREATE_STATUS_REMOTE_FAIL:
case Profile::MAX_CREATE_STATUS: {
NOTREACHED();
break;
}
}
}
void SigninSupervisedUserImportHandler::RejectCallback(
const base::string16& error) {
RejectJavascriptCallback(base::Value(webui_callback_id_), base::Value(error));
webui_callback_id_.clear();
}
base::string16 SigninSupervisedUserImportHandler::GetLocalErrorMessage() const {
return l10n_util::GetStringUTF16(
IDS_LEGACY_SUPERVISED_USER_IMPORT_LOCAL_ERROR);
}
base::string16 SigninSupervisedUserImportHandler::GetAuthErrorMessage(
Profile* profile) const {
return l10n_util::GetStringFUTF16(
IDS_PROFILES_CREATE_CUSTODIAN_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR,
base::ASCIIToUTF16(profile->GetProfileUserName()));
}
bool SigninSupervisedUserImportHandler::IsAccountConnected(
Profile* profile) const {
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile);
return signin_manager && signin_manager->IsAuthenticated();
}
bool SigninSupervisedUserImportHandler::HasAuthError(Profile* profile) const {
SigninErrorController* error_controller =
SigninErrorControllerFactory::GetForProfile(profile);
if (!error_controller)
return true;
GoogleServiceAuthError::State state = error_controller->auth_error().state();
return state != GoogleServiceAuthError::NONE;
}
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_SUPERVISED_USER_IMPORT_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_SUPERVISED_USER_IMPORT_HANDLER_H_
#include <string>
#include "base/callback_list.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "base/strings/string16.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/supervised_user/supervised_users.h"
#include "content/public/browser/web_ui_message_handler.h"
namespace base {
class DictionaryValue;
class ListValue;
}
// Handler for the 'import existing supervised user' dialog.
class SigninSupervisedUserImportHandler : public content::WebUIMessageHandler {
public:
SigninSupervisedUserImportHandler();
~SigninSupervisedUserImportHandler() override;
void GetLocalizedValues(base::DictionaryValue* localized_strings);
// WebUIMessageHandler implementation.
void RegisterMessages() override;
private:
FRIEND_TEST_ALL_PREFIXES(SigninSupervisedUserImportHandlerTest,
NotAuthenticated);
FRIEND_TEST_ALL_PREFIXES(SigninSupervisedUserImportHandlerTest, AuthError);
FRIEND_TEST_ALL_PREFIXES(SigninSupervisedUserImportHandlerTest,
CustodianIsSupervised);
// Assigns a new |webui_callback_id_|. Ensures that previous in-flight request
// has been fulfilled.
void AssignWebUICallbackId(const base::ListValue* args);
// Callback for the "openUrlInLastActiveProfileBrowser" message. Opens the
// given url in a new background tab in the browser owned by the last active
// profile. Hyperlinks don't work in the user manager since the system profile
// browser is not tabbed.
void OpenUrlInLastActiveProfileBrowser(const base::ListValue* args);
// Used to cancel loading existing supervised users. Resets WebUI callback ID
// of the last in-flight async request.
void HandleCancelLoadSupervisedUsers(const base::ListValue* args);
// Callback for the "getExistingSupervisedUsers" message. Returns a list of
// supervised users attached to the given custodian profile.
void GetExistingSupervisedUsers(const base::ListValue* args);
// Callback for the "authenticateCustodian" message. Authenticates the
// custodian profile with the given email address.
void AuthenticateCustodian(const base::ListValue* args);
void LoadCustodianProfileCallback(Profile* custodian_profile,
Profile::CreateStatus status);
// Reject the WebUI callback with an error message.
void RejectCallback(const base::string16& error);
base::string16 GetLocalErrorMessage() const;
base::string16 GetAuthErrorMessage(Profile* profile) const;
bool IsAccountConnected(Profile* profile) const;
bool HasAuthError(Profile* profile) const;
// The WebUI callback ID of the last in-flight async request. There is always
// only one in-flight such request.
std::string webui_callback_id_;
Profile* last_used_profile;
base::WeakPtrFactory<SigninSupervisedUserImportHandler> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(SigninSupervisedUserImportHandler);
};
#endif // CHROME_BROWSER_UI_WEBUI_SIGNIN_SIGNIN_SUPERVISED_USER_IMPORT_HANDLER_H_
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/signin/signin_supervised_user_import_handler.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/signin/fake_signin_manager_builder.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "content/public/test/test_web_ui.h"
#include "google_apis/gaia/oauth2_token_service_delegate.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
const char kTestGaiaId[] = "test-gaia-id";
const char kTestEmail[] = "foo@bar.com";
const char kTestWebUIResponse[] = "cr.webUIResponse";
const char kTestCallbackId[] = "test-callback-id";
} // namespace
class TestSigninSupervisedUserImportHandler :
public SigninSupervisedUserImportHandler {
public:
explicit TestSigninSupervisedUserImportHandler(content::WebUI* web_ui) {
set_web_ui(web_ui);
}
};
class SigninSupervisedUserImportHandlerTest : public BrowserWithTestWindowTest {
public:
SigninSupervisedUserImportHandlerTest() : web_ui_(new content::TestWebUI) {}
void SetUp() override {
BrowserWithTestWindowTest::SetUp();
handler_.reset(new TestSigninSupervisedUserImportHandler(web_ui()));
// Authenticate the test profile.
fake_signin_manager_ = static_cast<FakeSigninManagerForTesting*>(
SigninManagerFactory::GetForProfile(profile()));
fake_signin_manager_->SetAuthenticatedAccountInfo(kTestGaiaId, kTestEmail);
}
void TearDown() override {
handler_.reset();
web_ui_.reset();
BrowserWithTestWindowTest::TearDown();
}
TestingProfile::TestingFactories GetTestingFactories() override {
return {{SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase}};
}
content::TestWebUI* web_ui() {
return web_ui_.get();
}
TestSigninSupervisedUserImportHandler* handler() {
return handler_.get();
}
FakeSigninManagerForTesting* signin_manager() {
return fake_signin_manager_;
}
void VerifyResponse(size_t expected_total_calls,
const std::string& expected_callback_id,
bool expected_fulfilled) {
EXPECT_EQ(expected_total_calls, web_ui()->call_data().size());
EXPECT_EQ(kTestWebUIResponse, web_ui()->call_data()[0]->function_name());
std::string callback_id;
ASSERT_TRUE(web_ui()->call_data()[0]->arg1()->GetAsString(&callback_id));
EXPECT_EQ(expected_callback_id, callback_id);
bool fulfilled;
ASSERT_TRUE(web_ui()->call_data()[0]->arg2()->GetAsBoolean(&fulfilled));
EXPECT_EQ(expected_fulfilled, fulfilled);
}
private:
std::unique_ptr<content::TestWebUI> web_ui_;
std::unique_ptr<TestSigninSupervisedUserImportHandler> handler_;
FakeSigninManagerForTesting* fake_signin_manager_;
};
TEST_F(SigninSupervisedUserImportHandlerTest, NotAuthenticated) {
// Sign out the user.
signin_manager()->ForceSignOut();
// Test the JS -> C++ -> JS callback path.
base::ListValue list_args;
list_args.AppendString(kTestCallbackId);
list_args.AppendString(profile()->GetPath().AsUTF16Unsafe());
handler()->GetExistingSupervisedUsers(&list_args);
// Expect an error response.
VerifyResponse(1U, kTestCallbackId, false);
base::string16 expected_error_message = l10n_util::GetStringFUTF16(
IDS_PROFILES_CREATE_CUSTODIAN_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR,
base::ASCIIToUTF16(profile()->GetProfileUserName()));
base::string16 error_message;
ASSERT_TRUE(web_ui()->call_data()[0]->arg3()->GetAsString(&error_message));
EXPECT_EQ(expected_error_message, error_message);
}
TEST_F(SigninSupervisedUserImportHandlerTest, AuthError) {
// Set Auth Error.
const GoogleServiceAuthError error(
GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile());
token_service->UpdateCredentials(kTestGaiaId, "refresh_token");
// TODO(https://crbug.com/836212): Do not use the delegate directly, because
// it is internal API.
token_service->GetDelegate()->UpdateAuthError(kTestGaiaId, error);
// Test the JS -> C++ -> JS callback path.
base::ListValue list_args;
list_args.AppendString(kTestCallbackId);
list_args.AppendString(profile()->GetPath().AsUTF16Unsafe());
handler()->GetExistingSupervisedUsers(&list_args);
// Expect an error response.
VerifyResponse(1U, kTestCallbackId, false);
base::string16 expected_error_message = l10n_util::GetStringFUTF16(
IDS_PROFILES_CREATE_CUSTODIAN_ACCOUNT_DETAILS_OUT_OF_DATE_ERROR,
base::ASCIIToUTF16(profile()->GetProfileUserName()));
base::string16 error_message;
ASSERT_TRUE(web_ui()->call_data()[0]->arg3()->GetAsString(&error_message));
EXPECT_EQ(expected_error_message, error_message);
}
TEST_F(SigninSupervisedUserImportHandlerTest, CustodianIsSupervised) {
// Build a supervised test profile.
TestingProfile* supervised_profile = profile_manager()->CreateTestingProfile(
"supervised-test-profile", nullptr,
base::UTF8ToUTF16("supervised-test-profile"), 0,
"12345", // supervised_user_id
TestingProfile::TestingFactories());
// Test the JS -> C++ -> JS callback path.
base::ListValue list_args;
list_args.AppendString(kTestCallbackId);
list_args.AppendString(supervised_profile->GetPath().AsUTF16Unsafe());
handler()->GetExistingSupervisedUsers(&list_args);
// Expect to do nothing.
EXPECT_EQ(0U, web_ui()->call_data().size());
}
......@@ -4350,10 +4350,7 @@ test("unit_tests") {
]
}
if (enable_supervised_users && !is_android && !is_chromeos) {
sources += [
"../browser/supervised_user/supervised_user_creation_policy_handler_unittest.cc",
"../browser/ui/webui/signin/signin_supervised_user_import_handler_unittest.cc",
]
sources += [ "../browser/supervised_user/supervised_user_creation_policy_handler_unittest.cc" ]
}
if (safe_browsing_mode == 1 && enable_extensions) {
sources += [ "../browser/extensions/blacklist_unittest.cc" ]
......
......@@ -17,13 +17,6 @@ cr.define('user_manager.create_profile_tests', function() {
/** @type {?CreateProfileElement} */
let createProfileElement = null;
// Helper to select first signed in user from a dropdown menu.
const selectFirstSignedInUser = function(dropdownMenu) {
const option = dropdownMenu.querySelector('option:not([disabled])');
dropdownMenu.value = option.value;
dropdownMenu.dispatchEvent(new Event('change'));
};
suite('CreateProfileTests', function() {
setup(function() {
browserProxy = new TestProfileBrowserProxy();
......@@ -33,12 +26,6 @@ cr.define('user_manager.create_profile_tests', function() {
browserProxy.setDefaultProfileInfo({name: 'profile name'});
browserProxy.setIcons([{url: 'icon1.png', label: 'icon1'},
{url: 'icon2.png', label: 'icon2'}]);
browserProxy.setSignedInUsers([{username: 'username',
profilePath: 'path/to/profile'}]);
browserProxy.setExistingSupervisedUsers([{name: 'existing name 1',
onCurrentDevice: true},
{name: 'existing name 2',
onCurrentDevice: false}]);
createProfileElement = createElement();
......@@ -88,29 +75,6 @@ cr.define('user_manager.create_profile_tests', function() {
assertEquals('profile name', args.profileName);
assertEquals('icon1.png', args.profileIconUrl);
assertFalse(args.createShortcut);
assertFalse(args.isSupervised);
assertEquals('', args.supervisedUserId);
assertEquals('', args.custodianProfilePath);
});
});
test('Cancel creating a profile', function() {
// Simulate clicking 'Create'.
MockInteractions.tap(createProfileElement.$.save);
return browserProxy.whenCalled('createProfile').then(function(args) {
// The 'Save' button is disabled when create is in progress.
assertTrue(createProfileElement.createInProgress_);
assertTrue(createProfileElement.$.save.disabled);
// Simulate clicking 'Cancel'.
MockInteractions.tap(createProfileElement.$.cancel);
return browserProxy.whenCalled('cancelCreateProfile').then(
function() {
// The 'Save' button is enabled when create is not in progress.
assertFalse(createProfileElement.createInProgress_);
assertFalse(createProfileElement.$.save.disabled);
});
});
});
......@@ -118,9 +82,7 @@ cr.define('user_manager.create_profile_tests', function() {
return new Promise(function(resolve, reject) {
// Create is not in progress. We expect to leave the page.
createProfileElement.addEventListener('change-page', function(event) {
// This should not be called if create is not in progress.
if (!browserProxy.cancelCreateProfileCalled &&
event.detail.page == 'user-pods-page') {
if (event.detail.page == 'user-pods-page') {
resolve();
}
});
......@@ -146,9 +108,7 @@ cr.define('user_manager.create_profile_tests', function() {
assertTrue(createProfileElement.createInProgress_);
assertTrue(createProfileElement.$$('paper-spinner-lite').active);
cr.webUIListenerCallback('create-profile-success',
{name: 'profile name',
filePath: 'path/to/profile'});
cr.webUIListenerCallback('create-profile-success');
// The paper-spinner is not active when create is not in progress.
assertFalse(createProfileElement.createInProgress_);
......@@ -260,9 +220,6 @@ cr.define('user_manager.create_profile_tests', function() {
assertEquals('profile name', args.profileName);
assertEquals('icon1.png', args.profileIconUrl);
assertFalse(args.createShortcut);
assertFalse(args.isSupervised);
assertEquals('', args.supervisedUserId);
assertEquals('', args.custodianProfilePath);
});
});
......@@ -282,9 +239,6 @@ cr.define('user_manager.create_profile_tests', function() {
assertEquals('profile name', args.profileName);
assertEquals('icon1.png', args.profileIconUrl);
assertTrue(args.createShortcut);
assertFalse(args.isSupervised);
assertEquals('', args.supervisedUserId);
assertEquals('', args.custodianProfilePath);
});
});
});
......
......@@ -10,28 +10,19 @@ class TestProfileBrowserProxy extends TestBrowserProxy {
constructor() {
super([
'getAvailableIcons',
'getSignedInUsers',
'launchGuestUser',
'createProfile',
'cancelCreateProfile',
'initializeUserManager',
'launchUser',
'getExistingSupervisedUsers',
'areAllProfilesLocked',
]);
/** @private {!Array<!AvatarIcon>} */
this.icons_ = [];
/** @private {!Array<SignedInUser>} */
this.signedInUsers_ = [];
/** @private {!ProfileInfo} */
this.defaultProfileInfo_ = {};
/** @private {!Array<SupervisedUser>} */
this.existingSupervisedUsers_ = [];
/** @private {boolean} */
this.allProfilesLocked_ = false;
}
......@@ -43,13 +34,6 @@ class TestProfileBrowserProxy extends TestBrowserProxy {
this.icons_ = icons;
}
/**
* @param {!Array<SignedInUser>} signedInUsers
*/
setSignedInUsers(signedInUsers) {
this.signedInUsers_ = signedInUsers;
}
/**
* @param {!ProfileInfo} profileInfo
*/
......@@ -57,13 +41,6 @@ class TestProfileBrowserProxy extends TestBrowserProxy {
this.defaultProfileInfo_ = profileInfo;
}
/**
* @param {!Array<SupervisedUser>} supervisedUsers
*/
setExistingSupervisedUsers(supervisedUsers) {
this.existingSupervisedUsers_ = supervisedUsers;
}
/**
* @param {boolean} allProfilesLocked
*/
......@@ -80,37 +57,11 @@ class TestProfileBrowserProxy extends TestBrowserProxy {
}
/** @override */
getSignedInUsers() {
this.methodCalled('getSignedInUsers');
cr.webUIListenerCallback('signedin-users-received', this.signedInUsers_);
}
/** @override */
cancelCreateProfile() {
/**
* Flag used to test whether this method was not called.
* @type {boolean}
*/
this.cancelCreateProfileCalled = true;
this.methodCalled('cancelCreateProfile');
}
/** @override */
createProfile(
profileName,
profileIconUrl,
createShortcut,
isSupervised,
supervisedUserId,
custodianProfilePath
) {
createProfile(profileName, profileIconUrl, createShortcut) {
this.methodCalled('createProfile',
{profileName: profileName,
profileIconUrl: profileIconUrl,
createShortcut: createShortcut,
isSupervised: isSupervised,
supervisedUserId: supervisedUserId,
custodianProfilePath: custodianProfilePath});
createShortcut: createShortcut});
}
/** @override */
......@@ -118,12 +69,6 @@ class TestProfileBrowserProxy extends TestBrowserProxy {
this.methodCalled('launchGuestUser');
}
/** @override */
getExistingSupervisedUsers() {
this.methodCalled('getExistingSupervisedUsers');
return Promise.resolve(this.existingSupervisedUsers_);
}
/** @override */
areAllProfilesLocked() {
this.methodCalled('areAllProfilesLocked');
......
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