Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
| 6 * @fileoverview User pod row implementation. | 6 * @fileoverview User pod row implementation. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 cr.define('login', function() { | 9 cr.define('login', function() { |
| 10 /** | 10 /** |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 * @const | 21 * @const |
| 22 */ | 22 */ |
| 23 var MARGIN_BY_COLUMNS = [undefined, 40, 40, 40, 40, 40, 12]; | 23 var MARGIN_BY_COLUMNS = [undefined, 40, 40, 40, 40, 40, 12]; |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * Mapping between number of columns in the desktop pod-row and margin | 26 * Mapping between number of columns in the desktop pod-row and margin |
| 27 * between user pods for such layout. | 27 * between user pods for such layout. |
| 28 * @type {Array<number>} | 28 * @type {Array<number>} |
| 29 * @const | 29 * @const |
| 30 */ | 30 */ |
| 31 var DESKTOP_MARGIN_BY_COLUMNS = [undefined, 15, 15, 15, 15, 15, 15]; | 31 var DESKTOP_MARGIN_BY_COLUMNS = [undefined, 32, 32, 32, 32, 32, 32]; |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * Maximal number of columns currently supported by pod-row. | 34 * Maximal number of columns currently supported by pod-row. |
| 35 * @type {number} | 35 * @type {number} |
| 36 * @const | 36 * @const |
| 37 */ | 37 */ |
| 38 var MAX_NUMBER_OF_COLUMNS = 6; | 38 var MAX_NUMBER_OF_COLUMNS = 6; |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * Maximal number of rows if sign-in banner is displayed alonside. | 41 * Maximal number of rows if sign-in banner is displayed alonside. |
| 42 * @type {number} | 42 * @type {number} |
| 43 * @const | 43 * @const |
| 44 */ | 44 */ |
| 45 var MAX_NUMBER_OF_ROWS_UNDER_SIGNIN_BANNER = 2; | 45 var MAX_NUMBER_OF_ROWS_UNDER_SIGNIN_BANNER = 2; |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * Variables used for pod placement processing. Width and height should be | 48 * Variables used for pod placement processing. Width and height should be |
| 49 * synced with computed CSS sizes of pods. | 49 * synced with computed CSS sizes of pods. |
| 50 */ | 50 */ |
| 51 var POD_WIDTH = 180; | 51 var CROS_POD_WIDTH = 180; |
| 52 var DESKTOP_POD_WIDTH = 160; | |
| 52 var PUBLIC_EXPANDED_BASIC_WIDTH = 500; | 53 var PUBLIC_EXPANDED_BASIC_WIDTH = 500; |
| 53 var PUBLIC_EXPANDED_ADVANCED_WIDTH = 610; | 54 var PUBLIC_EXPANDED_ADVANCED_WIDTH = 610; |
| 54 var CROS_POD_HEIGHT = 213; | 55 var CROS_POD_HEIGHT = 213; |
| 55 var DESKTOP_POD_HEIGHT = 226; | 56 var DESKTOP_POD_HEIGHT = 200; |
| 56 var POD_ROW_PADDING = 10; | 57 var POD_ROW_PADDING = 10; |
| 57 var DESKTOP_ROW_PADDING = 15; | 58 var DESKTOP_ROW_PADDING = 32; |
| 58 var CUSTOM_ICON_CONTAINER_SIZE = 40; | 59 var CUSTOM_ICON_CONTAINER_SIZE = 40; |
| 59 | 60 |
| 60 /** | 61 /** |
| 61 * Minimal padding between user pod and virtual keyboard. | 62 * Minimal padding between user pod and virtual keyboard. |
| 62 * @type {number} | 63 * @type {number} |
| 63 * @const | 64 * @const |
| 64 */ | 65 */ |
| 65 var USER_POD_KEYBOARD_MIN_PADDING = 20; | 66 var USER_POD_KEYBOARD_MIN_PADDING = 20; |
| 66 | 67 |
| 67 /** | 68 /** |
| (...skipping 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1542 * @param {string} message The message to be written. | 1543 * @param {string} message The message to be written. |
| 1543 * @param {number|string=} count The number or string to replace $1 in | 1544 * @param {number|string=} count The number or string to replace $1 in |
| 1544 * |message|. Can be omitted if $1 is not present in |message|. | 1545 * |message|. Can be omitted if $1 is not present in |message|. |
| 1545 */ | 1546 */ |
| 1546 updateRemoveWarningDialogSetMessage_: function(profilePath, message, | 1547 updateRemoveWarningDialogSetMessage_: function(profilePath, message, |
| 1547 count) { | 1548 count) { |
| 1548 if (profilePath !== this.user.profilePath) | 1549 if (profilePath !== this.user.profilePath) |
| 1549 return; | 1550 return; |
| 1550 // Add localized messages where $1 will be replaced with | 1551 // Add localized messages where $1 will be replaced with |
| 1551 // <span class="total-count"></span>. | 1552 // <span class="total-count"></span>. |
| 1553 // and $2 will be replaced with <span class="email"></span>. | |
| 1554 message = message.replace('$1', '<span class="total-count">' + count + | |
| 1555 '</span>'); | |
| 1556 message = message.replace('$2', '<span class="email">' + | |
| 1557 this.user.emailAddress + '</span>'); | |
| 1552 var element = this.querySelector('.action-box-remove-user-warning-text'); | 1558 var element = this.querySelector('.action-box-remove-user-warning-text'); |
| 1553 element.textContent = ''; | 1559 element.innerHTML = message; |
|
Dan Beam
2016/04/07 18:35:00
why are you moving from textContent to innerHTML?
Moe
2016/04/07 22:48:55
the existing logic was too complex. dzhioev@ sugge
Dan Beam
2016/04/08 00:16:28
innerHTML = '<script>alert(/xss/)</script>' // act
lwchkg
2016/04/12 18:28:38
Dan, WDYT about using innerHTML but escaping |coun
Dan Beam
2016/04/12 18:33:50
i think replacing $1 and $2 manually is silly when
lwchkg
2016/04/13 17:46:54
The sad part it the messages to process is already
Dan Beam
2016/04/13 23:00:31
read harder: https://code.google.com/p/chromium/co
lwchkg
2016/04/14 17:43:03
Thanks for pointing out. I'm still concerned about
| |
| 1554 | 1560 |
| 1555 messageParts = message.split('$1'); | |
| 1556 var numParts = messageParts.length; | |
| 1557 for (var j = 0; j < numParts; j++) { | |
| 1558 element.appendChild(document.createTextNode(messageParts[j])); | |
| 1559 if (j < numParts - 1) { | |
| 1560 var elementToAdd = document.createElement('span'); | |
| 1561 elementToAdd.classList.add('total-count'); | |
| 1562 elementToAdd.textContent = count; | |
| 1563 element.appendChild(elementToAdd); | |
| 1564 } | |
| 1565 } | |
| 1566 this.moveActionMenuUpIfNeeded_(); | 1561 this.moveActionMenuUpIfNeeded_(); |
| 1567 }, | 1562 }, |
| 1568 | 1563 |
| 1569 /** | 1564 /** |
| 1570 * Handles a click event on remove user confirmation button. | 1565 * Handles a click event on remove user confirmation button. |
| 1571 * @param {Event} e Click event. | 1566 * @param {Event} e Click event. |
| 1572 */ | 1567 */ |
| 1573 handleRemoveUserConfirmationClick_: function(e) { | 1568 handleRemoveUserConfirmationClick_: function(e) { |
| 1574 if (this.isActionBoxMenuActive) { | 1569 if (this.isActionBoxMenuActive) { |
| 1575 this.isActionBoxMenuActive = false; | 1570 this.isActionBoxMenuActive = false; |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2307 focus: [this.handleFocus_.bind(this), true /* useCapture */], | 2302 focus: [this.handleFocus_.bind(this), true /* useCapture */], |
| 2308 click: [this.handleClick_.bind(this), true], | 2303 click: [this.handleClick_.bind(this), true], |
| 2309 mousemove: [this.handleMouseMove_.bind(this), false], | 2304 mousemove: [this.handleMouseMove_.bind(this), false], |
| 2310 keydown: [this.handleKeyDown.bind(this), false] | 2305 keydown: [this.handleKeyDown.bind(this), false] |
| 2311 }; | 2306 }; |
| 2312 | 2307 |
| 2313 var isDesktopUserManager = Oobe.getInstance().displayType == | 2308 var isDesktopUserManager = Oobe.getInstance().displayType == |
| 2314 DISPLAY_TYPE.DESKTOP_USER_MANAGER; | 2309 DISPLAY_TYPE.DESKTOP_USER_MANAGER; |
| 2315 this.userPodHeight_ = isDesktopUserManager ? DESKTOP_POD_HEIGHT : | 2310 this.userPodHeight_ = isDesktopUserManager ? DESKTOP_POD_HEIGHT : |
| 2316 CROS_POD_HEIGHT; | 2311 CROS_POD_HEIGHT; |
| 2317 // Same for Chrome OS and desktop. | 2312 this.userPodWidth_ = isDesktopUserManager ? DESKTOP_POD_WIDTH : |
| 2318 this.userPodWidth_ = POD_WIDTH; | 2313 CROS_POD_WIDTH; |
| 2319 }, | 2314 }, |
| 2320 | 2315 |
| 2321 /** | 2316 /** |
| 2322 * Returns all the pods in this pod row. | 2317 * Returns all the pods in this pod row. |
| 2323 * @type {NodeList} | 2318 * @type {NodeList} |
| 2324 */ | 2319 */ |
| 2325 get pods() { | 2320 get pods() { |
| 2326 return Array.prototype.slice.call(this.children); | 2321 return Array.prototype.slice.call(this.children); |
| 2327 }, | 2322 }, |
| 2328 | 2323 |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2775 return 2 * rowPadding + rows * this.userPodHeight_; | 2770 return 2 * rowPadding + rows * this.userPodHeight_; |
| 2776 }, | 2771 }, |
| 2777 | 2772 |
| 2778 /** | 2773 /** |
| 2779 * Calculates number of columns and rows that podrow should have in order to | 2774 * Calculates number of columns and rows that podrow should have in order to |
| 2780 * hold as much its pods as possible for current screen size. Also it tries | 2775 * hold as much its pods as possible for current screen size. Also it tries |
| 2781 * to choose layout that looks good. | 2776 * to choose layout that looks good. |
| 2782 * @return {{columns: number, rows: number}} | 2777 * @return {{columns: number, rows: number}} |
| 2783 */ | 2778 */ |
| 2784 calculateLayout_: function() { | 2779 calculateLayout_: function() { |
| 2780 var isDesktopUserManager = Oobe.getInstance().displayType == | |
| 2781 DISPLAY_TYPE.DESKTOP_USER_MANAGER; | |
| 2785 var preferredColumns = this.pods.length < COLUMNS.length ? | 2782 var preferredColumns = this.pods.length < COLUMNS.length ? |
| 2786 COLUMNS[this.pods.length] : COLUMNS[COLUMNS.length - 1]; | 2783 COLUMNS[this.pods.length] : COLUMNS[COLUMNS.length - 1]; |
| 2787 var maxWidth = Oobe.getInstance().clientAreaSize.width; | 2784 var maxWidth = Oobe.getInstance().clientAreaSize.width; |
| 2788 var columns = preferredColumns; | 2785 var columns = preferredColumns; |
| 2789 while (maxWidth < this.columnsToWidth_(columns) && columns > 1) | 2786 while (maxWidth < this.columnsToWidth_(columns) && columns > 1) |
| 2790 --columns; | 2787 --columns; |
| 2791 var rows = Math.floor((this.pods.length - 1) / columns) + 1; | 2788 var rows = Math.floor((this.pods.length - 1) / columns) + 1; |
| 2792 if (getComputedStyle( | 2789 if (getComputedStyle( |
| 2793 $('signin-banner'), null).getPropertyValue('display') != 'none') { | 2790 $('signin-banner'), null).getPropertyValue('display') != 'none') { |
| 2794 rows = Math.min(rows, MAX_NUMBER_OF_ROWS_UNDER_SIGNIN_BANNER); | 2791 rows = Math.min(rows, MAX_NUMBER_OF_ROWS_UNDER_SIGNIN_BANNER); |
| 2795 } | 2792 } |
| 2796 var maxHeigth = Oobe.getInstance().clientAreaSize.height; | 2793 if (!isDesktopUserManager) { |
| 2797 while (maxHeigth < this.rowsToHeight_(rows) && rows > 1) | 2794 var maxHeigth = Oobe.getInstance().clientAreaSize.height; |
| 2798 --rows; | 2795 while (maxHeigth < this.rowsToHeight_(rows) && rows > 1) |
| 2796 --rows; | |
| 2797 } | |
| 2799 // One more iteration if it's not enough cells to place all pods. | 2798 // One more iteration if it's not enough cells to place all pods. |
| 2800 while (maxWidth >= this.columnsToWidth_(columns + 1) && | 2799 while (maxWidth >= this.columnsToWidth_(columns + 1) && |
| 2801 columns * rows < this.pods.length && | 2800 columns * rows < this.pods.length && |
| 2802 columns < MAX_NUMBER_OF_COLUMNS) { | 2801 columns < MAX_NUMBER_OF_COLUMNS) { |
| 2803 ++columns; | 2802 ++columns; |
| 2804 } | 2803 } |
| 2805 return {columns: columns, rows: rows}; | 2804 return {columns: columns, rows: rows}; |
| 2806 }, | 2805 }, |
| 2807 | 2806 |
| 2808 /** | 2807 /** |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3322 if (pod && pod.multiProfilesPolicyApplied) { | 3321 if (pod && pod.multiProfilesPolicyApplied) { |
| 3323 pod.userTypeBubbleElement.classList.remove('bubble-shown'); | 3322 pod.userTypeBubbleElement.classList.remove('bubble-shown'); |
| 3324 } | 3323 } |
| 3325 } | 3324 } |
| 3326 }; | 3325 }; |
| 3327 | 3326 |
| 3328 return { | 3327 return { |
| 3329 PodRow: PodRow | 3328 PodRow: PodRow |
| 3330 }; | 3329 }; |
| 3331 }); | 3330 }); |
| OLD | NEW |