| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
| 7 | 7 |
| 8 ///////////////////////////////////////////////////////////////////////////// | 8 ///////////////////////////////////////////////////////////////////////////// |
| 9 // AccountsOptions class: | 9 // AccountsOptions class: |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // Set up accounts page. | 35 // Set up accounts page. |
| 36 var userList = $('userList'); | 36 var userList = $('userList'); |
| 37 userList.addEventListener('remove', this.handleRemoveUser_); | 37 userList.addEventListener('remove', this.handleRemoveUser_); |
| 38 | 38 |
| 39 var userNameEdit = $('userNameEdit'); | 39 var userNameEdit = $('userNameEdit'); |
| 40 options.accounts.UserNameEdit.decorate(userNameEdit); | 40 options.accounts.UserNameEdit.decorate(userNameEdit); |
| 41 userNameEdit.addEventListener('add', this.handleAddUser_); | 41 userNameEdit.addEventListener('add', this.handleAddUser_); |
| 42 | 42 |
| 43 // If the current user is not the owner, show some warning, | 43 // If the current user is not the owner, show some warning, |
| 44 // and do not show the user list. | 44 // and do not show the user list. |
| 45 this.showWhitelist_ = AccountsOptions.currentUserIsOwner(); | 45 this.showWhitelist_ = UIAccountTweaks.currentUserIsOwner(); |
| 46 if (this.showWhitelist_) { | 46 if (this.showWhitelist_) { |
| 47 options.accounts.UserList.decorate(userList); | 47 options.accounts.UserList.decorate(userList); |
| 48 } else { | 48 } else { |
| 49 if (!AccountsOptions.whitelistIsManaged()) { | 49 if (!AccountsOptions.whitelistIsManaged()) { |
| 50 $('ownerOnlyWarning').hidden = false; | 50 $('ownerOnlyWarning').hidden = false; |
| 51 } else { | 51 } else { |
| 52 this.managed = true; | 52 this.managed = true; |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 /** | 123 /** |
| 124 * Handler for "remove" event fired from userList. | 124 * Handler for "remove" event fired from userList. |
| 125 * @private | 125 * @private |
| 126 * @param {Event} e Remove event fired from userList. | 126 * @param {Event} e Remove event fired from userList. |
| 127 */ | 127 */ |
| 128 handleRemoveUser_: function(e) { | 128 handleRemoveUser_: function(e) { |
| 129 chrome.send('unwhitelistUser', [e.user.username]); | 129 chrome.send('unwhitelistUser', [e.user.username]); |
| 130 } | 130 } |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 /** | |
| 134 * Returns whether the current user is owner or not. | |
| 135 */ | |
| 136 AccountsOptions.currentUserIsOwner = function() { | |
| 137 return localStrings.getString('current_user_is_owner') == 'true'; | |
| 138 }; | |
| 139 | |
| 140 /** | |
| 141 * Returns whether we're currently in guest mode. | |
| 142 */ | |
| 143 AccountsOptions.loggedInAsGuest = function() { | |
| 144 return localStrings.getString('loggedInAsGuest') == 'true'; | |
| 145 }; | |
| 146 | 133 |
| 147 /** | 134 /** |
| 148 * Returns whether the whitelist is managed by policy or not. | 135 * Returns whether the whitelist is managed by policy or not. |
| 149 */ | 136 */ |
| 150 AccountsOptions.whitelistIsManaged = function() { | 137 AccountsOptions.whitelistIsManaged = function() { |
| 151 return localStrings.getString('whitelist_is_managed') == 'true'; | 138 return localStrings.getString('whitelist_is_managed') == 'true'; |
| 152 }; | 139 }; |
| 153 | 140 |
| 154 /** | 141 /** |
| 155 * Update account picture. | 142 * Update account picture. |
| 156 * @param {string} username User for which to update the image. | 143 * @param {string} username User for which to update the image. |
| 157 */ | 144 */ |
| 158 AccountsOptions.updateAccountPicture = function(username) { | 145 AccountsOptions.updateAccountPicture = function(username) { |
| 159 if (this.showWhitelist_) | 146 if (this.showWhitelist_) |
| 160 $('userList').updateAccountPicture(username); | 147 $('userList').updateAccountPicture(username); |
| 161 }; | 148 }; |
| 162 | 149 |
| 163 /** | |
| 164 * Disable or hide some elements in Guest mode in ChromeOS. | |
| 165 * All elements within given document with guest-visibility | |
| 166 * attribute are either hidden (for guest-visibility="hidden") | |
| 167 * or disabled (for guest-visibility="disabled"). | |
| 168 * | |
| 169 * @param {Document} document Document that should processed. | |
| 170 */ | |
| 171 AccountsOptions.applyGuestModeVisibility = function(document) { | |
| 172 if (!cr.isChromeOS || !AccountsOptions.loggedInAsGuest()) | |
| 173 return; | |
| 174 var elements = document.querySelectorAll('[guest-visibility]'); | |
| 175 for (var i = 0; i < elements.length; i++) { | |
| 176 var element = elements[i]; | |
| 177 var visibility = element.getAttribute('guest-visibility'); | |
| 178 if (visibility == 'hidden') { | |
| 179 element.hidden = true; | |
| 180 } else if (visibility == 'disabled') { | |
| 181 AccountsOptions.disableElementsForGuest(element); | |
| 182 } | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 /** | |
| 187 * Disables and marks page elements for Guest mode. | |
| 188 * Adds guest-disabled css class to all elements within given subtree, | |
| 189 * disables interactive elements (input/select/button), and removes href | |
| 190 * attribute from <a> elements. | |
| 191 * | |
| 192 * @param {Element} element Root element of DOM subtree that should be | |
| 193 * disabled. | |
| 194 */ | |
| 195 AccountsOptions.disableElementsForGuest = function(element) { | |
| 196 AccountsOptions.disableElementForGuest_(element); | |
| 197 | |
| 198 // Walk the tree, searching each ELEMENT node. | |
| 199 var walker = document.createTreeWalker(element, | |
| 200 NodeFilter.SHOW_ELEMENT, | |
| 201 null, | |
| 202 false); | |
| 203 | |
| 204 var node = walker.nextNode(); | |
| 205 while (node) { | |
| 206 AccountsOptions.disableElementForGuest_(node); | |
| 207 node = walker.nextNode(); | |
| 208 } | |
| 209 }; | |
| 210 | |
| 211 /** | |
| 212 * Disables single element for Guest mode. | |
| 213 * Adds guest-disabled css class, adds disabled attribute for appropriate | |
| 214 * elements (input/select/button), and removes href attribute from | |
| 215 * <a> element. | |
| 216 * | |
| 217 * @private | |
| 218 * @param {Element} element Element that should be disabled. | |
| 219 */ | |
| 220 AccountsOptions.disableElementForGuest_ = function(element) { | |
| 221 element.classList.add('guest-disabled'); | |
| 222 if (element.nodeName == 'INPUT' || | |
| 223 element.nodeName == 'SELECT' || | |
| 224 element.nodeName == 'BUTTON') | |
| 225 element.disabled = true; | |
| 226 if (element.nodeName == 'A') | |
| 227 element.removeAttribute('href'); | |
| 228 }; | |
| 229 | |
| 230 // Export | 150 // Export |
| 231 return { | 151 return { |
| 232 AccountsOptions: AccountsOptions | 152 AccountsOptions: AccountsOptions |
| 233 }; | 153 }; |
| 234 | 154 |
| 235 }); | 155 }); |
| OLD | NEW |