| 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 |
| 6 cr.define('cr.ui', function() { |
| 7 /** |
| 8 * API that encapsulates messaging between JS and C++ for user-manager page. |
| 9 */ |
| 10 function ProfileApi() {} |
| 11 |
| 12 ProfileApi.getAvailableIconsCallback_ = null; |
| 13 ProfileApi.getSignedInUsersCallback = null; |
| 14 ProfileApi.profileCreateErrorCallback_ = null; |
| 15 ProfileApi.profileCreateWarningCallback_ = null; |
| 16 ProfileApi.profileCreateSuccessCallback_ = null; |
| 17 |
| 18 ProfileApi.setProfileCreateSuccessCallback = function(callback) { |
| 19 ProfileApi.profileCreateSuccessCallback_ = callback; |
| 20 }; |
| 21 |
| 22 ProfileApi.setProfileCreateWarningCallback = function(callback) { |
| 23 ProfileApi.profileCreateWarningCallback_ = callback; |
| 24 }; |
| 25 |
| 26 ProfileApi.setProfileCreateErrorCallback = function(callback) { |
| 27 ProfileApi.profileCreateErrorCallback_ = callback; |
| 28 }; |
| 29 |
| 30 /** |
| 31 * Called from JavaScript. Gets the available profile icons to choose from. |
| 32 */ |
| 33 ProfileApi.getAvailableIcons = function(callback) { |
| 34 ProfileApi.getAvailableIconsCallback_ = callback; |
| 35 chrome.send('requestDefaultProfileIcons'); |
| 36 }; |
| 37 |
| 38 /** |
| 39 * Called from JavaScript. Gets the current signed-in users. |
| 40 */ |
| 41 ProfileApi.getSignedInUsers = function(callback) { |
| 42 ProfileApi.getSignedInUsersCallback = callback; |
| 43 chrome.send('requestCreateProfileUpdate'); |
| 44 }; |
| 45 |
| 46 /** |
| 47 * Called from C++ as a response to getAvailableIcons. |
| 48 */ |
| 49 ProfileApi.receiveAvailableIcons = function(iconUrls) { |
| 50 if (ProfileApi.getAvailableIconsCallback_) |
| 51 ProfileApi.getAvailableIconsCallback_(iconUrls); |
| 52 }; |
| 53 |
| 54 /** |
| 55 * Called from C++ in response to 'requestCreateProfileUpdate'. |
| 56 */ |
| 57 ProfileApi.updateSignedInUsers = function(signedIn_users) { |
| 58 if (ProfileApi.getSignedInUsersCallback) |
| 59 ProfileApi.getSignedInUsersCallback(signedIn_users); |
| 60 }; |
| 61 |
| 62 /** |
| 63 * Called from C++ to report supervised user import errors. |
| 64 */ |
| 65 ProfileApi.onSupervisedUserImportError_ = function(error) {}; |
| 66 |
| 67 /** |
| 68 * Called from C++ to report successful importing of a supervised user to |
| 69 */ |
| 70 ProfileApi.onSupervisedUserImportSuccess_ = function() {}; |
| 71 |
| 72 /** |
| 73 * Called from C++ to report supervised user create errors. |
| 74 */ |
| 75 ProfileApi.onCreateProfileError = function(error) { |
| 76 if (ProfileApi.profileCreateErrorCallback_) |
| 77 ProfileApi.profileCreateErrorCallback_(error); |
| 78 }; |
| 79 |
| 80 /** |
| 81 * Called from C++ to report supervised user create warnings. |
| 82 */ |
| 83 ProfileApi.onCreateProfileWarning = function(warning) { |
| 84 if (ProfileApi.profileCreateWarningCallback_) |
| 85 ProfileApi.profileCreateWarningCallback_(warning); |
| 86 }; |
| 87 |
| 88 /** |
| 89 * Called from C++ to report successful creation of a user. |
| 90 * @param {Object}: |
| 91 * profileInfo = { |
| 92 * name: 'Profile Name', |
| 93 * filePath: '/path/to/profile/data/on/disk' |
| 94 * isSupervised: (true|false), |
| 95 * }; |
| 96 * @private |
| 97 */ |
| 98 ProfileApi.onCreateProfileSuccess = function(profileInfo) { |
| 99 if (ProfileApi.profileCreateSuccessCallback_) |
| 100 ProfileApi.profileCreateSuccessCallback_(profileInfo); |
| 101 }; |
| 102 |
| 103 return { |
| 104 ProfileApi: ProfileApi, |
| 105 }; |
| 106 }); |
| OLD | NEW |