OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** @typedef {{username:(string), profilePath:(string)}} */ |
| 6 var SignedInUser; |
| 7 |
| 8 /** @typedef {{name:(string), filePath:(string), isSupervised:(boolean)}} */ |
| 9 var ProfileInfo; |
| 10 |
| 11 cr.define('signin', function() { |
| 12 /** |
| 13 * API that encapsulates messaging between JS and C++ for creating/importing |
| 14 * profiles in the user-manager page. |
| 15 * @constructor |
| 16 */ |
| 17 function ProfileApi() {} |
| 18 |
| 19 /** @private {?function(!Array<string>)} */ |
| 20 ProfileApi.getAvailableIconsCallback_ = null; |
| 21 |
| 22 /** @private {?function(!Array<SignedInUser>)} */ |
| 23 ProfileApi.getSignedInUsersCallback_ = null; |
| 24 |
| 25 /** @private {?function(!string)} */ |
| 26 ProfileApi.profileCreateErrorCallback_ = null; |
| 27 |
| 28 /** @private {?function(!string)} */ |
| 29 ProfileApi.profileCreateWarningCallback_ = null; |
| 30 |
| 31 /** @private {?function(!ProfileInfo)} */ |
| 32 ProfileApi.profileCreateSuccessCallback_ = null; |
| 33 |
| 34 /** |
| 35 * Sets the profile create success callback. |
| 36 * @param {?function(!ProfileInfo)} callback |
| 37 */ |
| 38 ProfileApi.setProfileCreateSuccessCallback = function(callback) { |
| 39 ProfileApi.profileCreateSuccessCallback_ = callback; |
| 40 }; |
| 41 |
| 42 /** |
| 43 * Sets the profile create warning callback. |
| 44 * @param {?function(!string)} callback |
| 45 */ |
| 46 ProfileApi.setProfileCreateWarningCallback = function(callback) { |
| 47 ProfileApi.profileCreateWarningCallback_ = callback; |
| 48 }; |
| 49 |
| 50 /** |
| 51 * Sets the profile create error callback. |
| 52 * @param {?function(!string)} callback |
| 53 */ |
| 54 ProfileApi.setProfileCreateErrorCallback = function(callback) { |
| 55 ProfileApi.profileCreateErrorCallback_ = callback; |
| 56 }; |
| 57 |
| 58 /** |
| 59 * Called from JavaScript. Gets the available profile icons to choose from. |
| 60 * @param {!function(!Array<string>)} callback |
| 61 */ |
| 62 ProfileApi.getAvailableIcons = function(callback) { |
| 63 ProfileApi.getAvailableIconsCallback_ = callback; |
| 64 chrome.send('requestDefaultProfileIcons'); |
| 65 }; |
| 66 |
| 67 /** |
| 68 * Called from JavaScript. Gets the current signed-in users. |
| 69 * @param {!function(!Array<SignedInUser>)} callback |
| 70 */ |
| 71 ProfileApi.getSignedInUsers = function(callback) { |
| 72 ProfileApi.getSignedInUsersCallback_ = callback; |
| 73 chrome.send('requestSignedInProfiles'); |
| 74 }; |
| 75 |
| 76 /** |
| 77 * Called from JavaScript. Launches the guest user. |
| 78 */ |
| 79 ProfileApi.launchGuestUser = function() { |
| 80 chrome.send('launchGuest'); |
| 81 }; |
| 82 |
| 83 /** |
| 84 * Called from JavaScript. Creates a profile. |
| 85 * @param {string} ProfileName Name of the new profile. |
| 86 * @param {string} profileIconUrl URL of the selected icon of the new profile. |
| 87 * @param {boolean} isSupervised True if the new profile is supervised. |
| 88 * @param {string|undefined} supervisorProfilePath Profile path of the |
| 89 * supervisor if the new profile is supervised. |
| 90 */ |
| 91 ProfileApi.createProfile = function(profileName, profileIconUrl, isSupervised, |
| 92 supervisorProfilePath) { |
| 93 chrome.send('createProfile', |
| 94 [profileName, profileIconUrl, false, isSupervised, '', |
| 95 supervisorProfilePath]); |
| 96 }; |
| 97 |
| 98 /** |
| 99 * Called from JavaScript. Cancels creation of the new profile. |
| 100 */ |
| 101 ProfileApi.cancelCreateProfile = function() { |
| 102 cchrome.send('cancelCreateProfile'); |
| 103 }; |
| 104 |
| 105 /** |
| 106 * Called from C++ as a response to getAvailableIcons. |
| 107 * @param {!Array<string>} iconUrls An array of icon URLs. |
| 108 * @private |
| 109 */ |
| 110 ProfileApi.updateAvailableIcons = function(iconUrls) { |
| 111 if (ProfileApi.getAvailableIconsCallback_) |
| 112 ProfileApi.getAvailableIconsCallback_(iconUrls); |
| 113 }; |
| 114 |
| 115 /** |
| 116 * Called from C++ in response to 'requestSignedInProfiles'. |
| 117 * @param {!Array<SignedInUser>} signedInUsers An array of email addresses of |
| 118 * signed in users and the corresponding profile path. |
| 119 * @private |
| 120 */ |
| 121 ProfileApi.updateSignedInUsers = function(signedInUsers) { |
| 122 if (ProfileApi.getSignedInUsersCallback_) |
| 123 ProfileApi.getSignedInUsersCallback_(signedInUsers); |
| 124 }; |
| 125 |
| 126 /** |
| 127 * Called from C++ to report supervised profile create errors. |
| 128 * @param {string} error The error raised while creating a profile. |
| 129 * @private |
| 130 */ |
| 131 ProfileApi.onCreateProfileError = function(error) { |
| 132 if (ProfileApi.profileCreateErrorCallback_) |
| 133 ProfileApi.profileCreateErrorCallback_(error); |
| 134 }; |
| 135 |
| 136 /** |
| 137 * Called from C++ to report supervised profile create warnings. |
| 138 * @param {string} warning The warning issued while creating a profile. |
| 139 * @private |
| 140 */ |
| 141 ProfileApi.onCreateProfileWarning = function(warning) { |
| 142 if (ProfileApi.profileCreateWarningCallback_) |
| 143 ProfileApi.profileCreateWarningCallback_(warning); |
| 144 }; |
| 145 |
| 146 /** |
| 147 * Called from C++ to report successful creation of a profile. |
| 148 * @param {!ProfileInfo} profileInfo |
| 149 * @private |
| 150 */ |
| 151 ProfileApi.onCreateProfileSuccess = function(profileInfo) { |
| 152 if (ProfileApi.profileCreateSuccessCallback_) |
| 153 ProfileApi.profileCreateSuccessCallback_(profileInfo); |
| 154 }; |
| 155 |
| 156 return { |
| 157 ProfileApi: ProfileApi, |
| 158 }; |
| 159 }); |
OLD | NEW |