Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / chrome / browser / resources / settings / users_page / users_page.js
blob44681b25d8e4f8743524ffc0309e76ba8aa2dbf3
1 // Copyright 2015 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.
5 /**
6 * @fileoverview
7 * 'cr-settings-users-page' is the settings page for managing user accounts on
8 * the device.
10 * Example:
12 * <neon-animated-pages>
13 * <cr-settings-users-page prefs="{{prefs}}">
14 * </cr-settings-users-page>
15 * ... other pages ...
16 * </neon-animated-pages>
18 * @group Chrome Settings Elements
19 * @element cr-settings-users-page
21 Polymer({
22 is: 'cr-settings-users-page',
24 behaviors: [
25 Polymer.IronA11yKeysBehavior
28 properties: {
29 /**
30 * Preferences state.
32 prefs: {
33 type: Object,
34 notify: true,
37 /** @override */
38 keyEventTarget: {
39 type: Object,
40 value: function() {
41 return this.$.addUserInput;
45 isOwner: {
46 type: Boolean,
47 value: false
50 isWhitelistManaged: {
51 type: Boolean,
52 value: false
55 editingDisabled: {
56 type: Boolean,
57 computed: 'computeEditingDisabled_(isOwner, isWhitelistManaged)'
60 editingUsersDisabled: {
61 type: Boolean,
62 computed: 'computeEditingUsersDisabled_(isOwner, isWhitelistManaged, ' +
63 'prefs.cros.accounts.allowGuest.value)'
67 keyBindings: {
68 'enter': 'addUser_'
71 /** @override */
72 created: function() {
73 chrome.usersPrivate.isCurrentUserOwner(function(isOwner) {
74 this.isOwner = isOwner;
75 }.bind(this));
77 chrome.usersPrivate.isWhitelistManaged(function(isWhitelistManaged) {
78 this.isWhitelistManaged = isWhitelistManaged;
79 }.bind(this));
82 /**
83 * Regular expression for adding a user where the string provided is just the
84 * part before the "@".
85 * Email alias only, assuming it's a gmail address.
86 * e.g. 'john'
87 * @const
88 * @private {string}
90 nameOnlyString_: '^\\s*([\\w\\.!#\\$%&\'\\*\\+-\\/=\\?\\^`\\{\\|\\}~]+)\\s*$',
92 /**
93 * Regular expression for adding a user where the string provided is a full
94 * email address.
95 * e.g. 'john@chromium.org'
96 * @const
97 * @private {string}
99 emailString_:
100 '^\\s*([\\w\\.!#\\$%&\'\\*\\+-\\/=\\?\\^`\\{\\|\\}~]+)@' +
101 '([A-Za-z0-9\-]{2,63}\\..+)\\s*$',
103 /** @private */
104 addUser_: function() {
105 /** @const */ var nameOnlyRegex = new RegExp(this.nameOnlyString_);
106 /** @const */ var emailRegex = new RegExp(this.emailString_);
108 var userStr = this.$.addUserInput.value;
110 var matches = nameOnlyRegex.exec(userStr);
111 var userEmail;
112 if (matches) {
113 userEmail = matches[1] + '@gmail.com';
116 matches = emailRegex.exec(userStr);
117 if (matches) {
118 userEmail = matches[1] + '@' + matches[2];
121 if (userEmail) {
122 chrome.usersPrivate.addWhitelistedUser(
123 userEmail,
124 /* callback */ function(success) {});
125 this.$.addUserInput.value = '';
130 * @param {boolean} isOwner
131 * @param {boolean} isWhitelistManaged
132 * @private
134 computeHideOwnerLabel_: function(isOwner, isWhitelistManaged) {
135 return isOwner || isWhitelistManaged;
139 * @param {boolean} isOwner
140 * @param {boolean} isWhitelistManaged
141 * @private
143 computeHideManagedLabel_: function(isOwner, isWhitelistManaged) {
144 return !isWhitelistManaged;
148 * @param {boolean} isOwner
149 * @param {boolean} isWhitelistManaged
150 * @private
152 computeEditingDisabled_: function(isOwner, isWhitelistManaged) {
153 return !isOwner || isWhitelistManaged;
157 * @param {boolean} isOwner
158 * @param {boolean} isWhitelistManaged
159 * @param {boolean} allowGuest
160 * @private
162 computeEditingUsersDisabled_: function(
163 isOwner, isWhitelistManaged, allowGuest) {
164 return !isOwner || isWhitelistManaged || allowGuest;