OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 The section of the history page that shows tabs from sessions | 6 * @fileoverview The section of the history page that shows tabs from sessions |
7 on other devices. | 7 on other devices. |
8 */ | 8 */ |
9 | 9 |
10 /////////////////////////////////////////////////////////////////////////////// | 10 /////////////////////////////////////////////////////////////////////////////// |
11 // Globals: | 11 // Globals: |
12 /** @const */ var MAX_NUM_COLUMNS = 3; | 12 /** @const */ var MAX_NUM_COLUMNS = 3; |
13 /** @const */ var NB_ENTRIES_FIRST_ROW_COLUMN = 6; | 13 /** @const */ var NB_ENTRIES_FIRST_ROW_COLUMN = 6; |
14 /** @const */ var NB_ENTRIES_OTHER_ROWS_COLUMN = 0; | 14 /** @const */ var NB_ENTRIES_OTHER_ROWS_COLUMN = 0; |
15 | 15 |
16 // Histogram buckets for UMA tracking of menu usage. | 16 // Histogram buckets for UMA tracking of menu usage. |
17 /** @const */ var HISTOGRAM_EVENT = { | 17 /** @const */ var HISTOGRAM_EVENT = { |
18 INITIALIZED: 0, | 18 INITIALIZED: 0, |
19 SHOW_MENU: 1, | 19 SHOW_MENU: 1, |
20 LINK_CLICKED: 2, | 20 LINK_CLICKED: 2, |
21 LINK_RIGHT_CLICKED: 3, | 21 LINK_RIGHT_CLICKED: 3, |
22 SESSION_NAME_RIGHT_CLICKED: 4, | 22 SESSION_NAME_RIGHT_CLICKED: 4, |
23 SHOW_SESSION_MENU: 5, | 23 SHOW_SESSION_MENU: 5, |
24 COLLAPSE_SESSION: 6, | 24 COLLAPSE_SESSION: 6, |
25 EXPAND_SESSION: 7, | 25 EXPAND_SESSION: 7, |
26 OPEN_ALL: 8, | 26 OPEN_ALL: 8, |
27 HAS_FOREIGN_DATA: 9, | 27 HAS_FOREIGN_DATA: 9, |
28 LIMIT: 10 // Should always be the last one. | 28 HIDE_FOR_NOW: 10, |
| 29 LIMIT: 11 // Should always be the last one. |
29 }; | 30 }; |
30 | 31 |
31 /** | 32 /** |
32 * Record an event in the UMA histogram. | 33 * Record an event in the UMA histogram. |
33 * @param {number} eventId The id of the event to be recorded. | 34 * @param {number} eventId The id of the event to be recorded. |
34 * @private | 35 * @private |
35 */ | 36 */ |
36 function recordUmaEvent_(eventId) { | 37 function recordUmaEvent_(eventId) { |
37 chrome.send('metricsHandler:recordInHistogram', | 38 chrome.send('metricsHandler:recordInHistogram', |
38 ['HistoryPage.OtherDevicesMenu', eventId, HISTOGRAM_EVENT.LIMIT]); | 39 ['HistoryPage.OtherDevicesMenu', eventId, HISTOGRAM_EVENT.LIMIT]); |
(...skipping 23 matching lines...) Expand all Loading... |
62 this.menu = menu; | 63 this.menu = menu; |
63 this.collapseItem_ = this.appendMenuItem_('collapseSessionMenuItemText'); | 64 this.collapseItem_ = this.appendMenuItem_('collapseSessionMenuItemText'); |
64 this.collapseItem_.addEventListener('activate', | 65 this.collapseItem_.addEventListener('activate', |
65 this.onCollapseOrExpand_.bind(this)); | 66 this.onCollapseOrExpand_.bind(this)); |
66 this.expandItem_ = this.appendMenuItem_('expandSessionMenuItemText'); | 67 this.expandItem_ = this.appendMenuItem_('expandSessionMenuItemText'); |
67 this.expandItem_.addEventListener('activate', | 68 this.expandItem_.addEventListener('activate', |
68 this.onCollapseOrExpand_.bind(this)); | 69 this.onCollapseOrExpand_.bind(this)); |
69 this.openAllItem_ = this.appendMenuItem_('restoreSessionMenuItemText'); | 70 this.openAllItem_ = this.appendMenuItem_('restoreSessionMenuItemText'); |
70 this.openAllItem_.addEventListener('activate', | 71 this.openAllItem_.addEventListener('activate', |
71 this.onOpenAll_.bind(this)); | 72 this.onOpenAll_.bind(this)); |
| 73 this.deleteItem_ = this.appendMenuItem_('deleteSessionMenuItemText'); |
| 74 this.deleteItem_.addEventListener('activate', |
| 75 this.onDeleteSession_.bind(this)); |
72 }; | 76 }; |
73 | 77 |
74 /** | 78 /** |
75 * Set the session data for the session the context menu was invoked on. | 79 * Set the session data for the session the context menu was invoked on. |
76 * This should never be called when the menu is visible. | 80 * This should never be called when the menu is visible. |
77 * @param {Object} session The model object for the session. | 81 * @param {Object} session The model object for the session. |
78 */ | 82 */ |
79 DeviceContextMenuController.prototype.setSession = function(session) { | 83 DeviceContextMenuController.prototype.setSession = function(session) { |
80 this.session_ = session; | 84 this.session_ = session; |
81 this.updateMenuItems_(); | 85 this.updateMenuItems_(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 * Handler for the 'Open all' menu item. | 123 * Handler for the 'Open all' menu item. |
120 * @param {Event} e The activation event. | 124 * @param {Event} e The activation event. |
121 * @private | 125 * @private |
122 */ | 126 */ |
123 DeviceContextMenuController.prototype.onOpenAll_ = function(e) { | 127 DeviceContextMenuController.prototype.onOpenAll_ = function(e) { |
124 chrome.send('openForeignSession', [this.session_.tag]); | 128 chrome.send('openForeignSession', [this.session_.tag]); |
125 recordUmaEvent_(HISTOGRAM_EVENT.OPEN_ALL); | 129 recordUmaEvent_(HISTOGRAM_EVENT.OPEN_ALL); |
126 }; | 130 }; |
127 | 131 |
128 /** | 132 /** |
| 133 * Handler for the 'Hide for now' menu item. |
| 134 * @param {Event} e The activation event. |
| 135 * @private |
| 136 */ |
| 137 DeviceContextMenuController.prototype.onDeleteSession_ = function(e) { |
| 138 chrome.send('deleteForeignSession', [this.session_.tag]); |
| 139 recordUmaEvent_(HISTOGRAM_EVENT.HIDE_FOR_NOW); |
| 140 }; |
| 141 |
| 142 /** |
129 * Set the visibility of the Expand/Collapse menu items based on the state | 143 * Set the visibility of the Expand/Collapse menu items based on the state |
130 * of the session that this menu is currently associated with. | 144 * of the session that this menu is currently associated with. |
131 * @private | 145 * @private |
132 */ | 146 */ |
133 DeviceContextMenuController.prototype.updateMenuItems_ = function() { | 147 DeviceContextMenuController.prototype.updateMenuItems_ = function() { |
134 this.collapseItem_.hidden = this.session_.collapsed; | 148 this.collapseItem_.hidden = this.session_.collapsed; |
135 this.expandItem_.hidden = !this.session_.collapsed; | 149 this.expandItem_.hidden = !this.session_.collapsed; |
136 this.menu.selectedItem = this.menu.querySelector(':not([hidden])'); | 150 this.menu.selectedItem = this.menu.querySelector(':not([hidden])'); |
137 }; | 151 }; |
138 | 152 |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 devicesView.setSearchText($('search-field').value); | 580 devicesView.setSearchText($('search-field').value); |
567 }; | 581 }; |
568 $('search-field').addEventListener('search', doSearch); | 582 $('search-field').addEventListener('search', doSearch); |
569 $('search-button').addEventListener('click', doSearch); | 583 $('search-button').addEventListener('click', doSearch); |
570 | 584 |
571 chrome.send('otherDevicesInitialized'); | 585 chrome.send('otherDevicesInitialized'); |
572 } | 586 } |
573 | 587 |
574 // Add handlers to HTML elements. | 588 // Add handlers to HTML elements. |
575 document.addEventListener('DOMContentLoaded', load); | 589 document.addEventListener('DOMContentLoaded', load); |
OLD | NEW |