Index: chrome/browser/resources/md_user_manager/profile_api.js |
diff --git a/chrome/browser/resources/md_user_manager/profile_api.js b/chrome/browser/resources/md_user_manager/profile_api.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ea9fe0a3efa51146ada6312d4fe3f8a6da9e6f3b |
--- /dev/null |
+++ b/chrome/browser/resources/md_user_manager/profile_api.js |
@@ -0,0 +1,159 @@ |
+// 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. |
+ |
+/** @typedef {{username:(string), profilePath:(string)}} */ |
+var SignedInUser; |
+ |
+/** @typedef {{name:(string), filePath:(string), isSupervised:(boolean)}} */ |
+var ProfileInfo; |
+ |
+cr.define('signin', function() { |
+ /** |
+ * API that encapsulates messaging between JS and C++ for creating/importing |
+ * profiles in the user-manager page. |
+ * @constructor |
+ */ |
+ function ProfileApi() {} |
+ |
+ /** @private {?function(!Array<string>)} */ |
+ ProfileApi.getAvailableIconsCallback_ = null; |
+ |
+ /** @private {?function(!Array<SignedInUser>)} */ |
+ ProfileApi.getSignedInUsersCallback_ = null; |
+ |
+ /** @private {?function(!string)} */ |
+ ProfileApi.profileCreateErrorCallback_ = null; |
+ |
+ /** @private {?function(!string)} */ |
+ ProfileApi.profileCreateWarningCallback_ = null; |
+ |
+ /** @private {?function(!ProfileInfo)} */ |
+ ProfileApi.profileCreateSuccessCallback_ = null; |
+ |
+ /** |
+ * Sets the profile create success callback. |
+ * @param {?function(!ProfileInfo)} callback |
+ */ |
+ ProfileApi.setProfileCreateSuccessCallback = function(callback) { |
+ ProfileApi.profileCreateSuccessCallback_ = callback; |
+ }; |
+ |
+ /** |
+ * Sets the profile create warning callback. |
+ * @param {?function(!string)} callback |
+ */ |
+ ProfileApi.setProfileCreateWarningCallback = function(callback) { |
+ ProfileApi.profileCreateWarningCallback_ = callback; |
+ }; |
+ |
+ /** |
+ * Sets the profile create error callback. |
+ * @param {?function(!string)} callback |
+ */ |
+ ProfileApi.setProfileCreateErrorCallback = function(callback) { |
+ ProfileApi.profileCreateErrorCallback_ = callback; |
+ }; |
+ |
+ /** |
+ * Called from JavaScript. Gets the available profile icons to choose from. |
+ * @param {!function(!Array<string>)} callback |
+ */ |
+ ProfileApi.getAvailableIcons = function(callback) { |
+ ProfileApi.getAvailableIconsCallback_ = callback; |
+ chrome.send('requestDefaultProfileIcons'); |
+ }; |
+ |
+ /** |
+ * Called from JavaScript. Gets the current signed-in users. |
+ * @param {!function(!Array<SignedInUser>)} callback |
+ */ |
+ ProfileApi.getSignedInUsers = function(callback) { |
+ ProfileApi.getSignedInUsersCallback_ = callback; |
+ chrome.send('requestSignedInProfiles'); |
+ }; |
+ |
+ /** |
+ * Called from JavaScript. Launches the guest user. |
+ */ |
+ ProfileApi.launchGuestUser = function() { |
+ chrome.send('launchGuest'); |
+ }; |
+ |
+ /** |
+ * Called from JavaScript. Creates a profile. |
+ * @param {string} ProfileName Name of the new profile. |
+ * @param {string} profileIconUrl URL of the selected icon of the new profile. |
+ * @param {boolean} isSupervised True if the new profile is supervised. |
+ * @param {string|undefined} supervisorProfilePath Profile path of the |
+ * supervisor if the new profile is supervised. |
+ */ |
+ ProfileApi.createProfile = function(profileName, profileIconUrl, isSupervised, |
+ supervisorProfilePath) { |
+ chrome.send('createProfile', |
+ [profileName, profileIconUrl, false, isSupervised, '', |
+ supervisorProfilePath]); |
+ }; |
+ |
+ /** |
+ * Called from JavaScript. Cancels creation of the new profile. |
+ */ |
+ ProfileApi.cancelCreateProfile = function() { |
+ cchrome.send('cancelCreateProfile'); |
+ }; |
+ |
+ /** |
+ * Called from C++ as a response to getAvailableIcons. |
+ * @param {!Array<string>} iconUrls An array of icon URLs. |
+ * @private |
+ */ |
+ ProfileApi.updateAvailableIcons = function(iconUrls) { |
+ if (ProfileApi.getAvailableIconsCallback_) |
+ ProfileApi.getAvailableIconsCallback_(iconUrls); |
+ }; |
+ |
+ /** |
+ * Called from C++ in response to 'requestSignedInProfiles'. |
+ * @param {!Array<SignedInUser>} signedInUsers An array of email addresses of |
+ * signed in users and the corresponding profile path. |
+ * @private |
+ */ |
+ ProfileApi.updateSignedInUsers = function(signedInUsers) { |
+ if (ProfileApi.getSignedInUsersCallback_) |
+ ProfileApi.getSignedInUsersCallback_(signedInUsers); |
+ }; |
+ |
+ /** |
+ * Called from C++ to report supervised profile create errors. |
+ * @param {string} error The error raised while creating a profile. |
+ * @private |
+ */ |
+ ProfileApi.onCreateProfileError = function(error) { |
+ if (ProfileApi.profileCreateErrorCallback_) |
+ ProfileApi.profileCreateErrorCallback_(error); |
+ }; |
+ |
+ /** |
+ * Called from C++ to report supervised profile create warnings. |
+ * @param {string} warning The warning issued while creating a profile. |
+ * @private |
+ */ |
+ ProfileApi.onCreateProfileWarning = function(warning) { |
+ if (ProfileApi.profileCreateWarningCallback_) |
+ ProfileApi.profileCreateWarningCallback_(warning); |
+ }; |
+ |
+ /** |
+ * Called from C++ to report successful creation of a profile. |
+ * @param {!ProfileInfo} profileInfo |
+ * @private |
+ */ |
+ ProfileApi.onCreateProfileSuccess = function(profileInfo) { |
+ if (ProfileApi.profileCreateSuccessCallback_) |
+ ProfileApi.profileCreateSuccessCallback_(profileInfo); |
+ }; |
+ |
+ return { |
+ ProfileApi: ProfileApi, |
+ }; |
+}); |