| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 Polymer({ | 5 Polymer({ |
| 6 is: 'history-app', | 6 is: 'history-app', |
| 7 | 7 |
| 8 properties: { | 8 properties: { |
| 9 showSidebarFooter: Boolean, | 9 showSidebarFooter: Boolean, |
| 10 | 10 |
| 11 // The id of the currently selected page. | 11 // The id of the currently selected page. |
| 12 selectedPage_: {type: String, value: 'history', observer: 'unselectAll'}, | 12 selectedPage_: {type: String, observer: 'unselectAll'}, |
| 13 | 13 |
| 14 // Whether domain-grouped history is enabled. | 14 // Whether domain-grouped history is enabled. |
| 15 grouped_: {type: Boolean, reflectToAttribute: true}, | 15 grouped_: {type: Boolean, reflectToAttribute: true}, |
| 16 | 16 |
| 17 /** @type {!QueryState} */ | 17 /** @type {!QueryState} */ |
| 18 queryState_: { | 18 queryState_: { |
| 19 type: Object, | 19 type: Object, |
| 20 value: function() { | 20 value: function() { |
| 21 return { | 21 return { |
| 22 // Whether the most recent query was incremental. | 22 // Whether the most recent query was incremental. |
| 23 incremental: false, | 23 incremental: false, |
| 24 // A query is initiated by page load. | 24 // A query is initiated by page load. |
| 25 querying: true, | 25 querying: true, |
| 26 queryingDisabled: false, | 26 queryingDisabled: false, |
| 27 _range: HistoryRange.ALL_TIME, | 27 _range: HistoryRange.ALL_TIME, |
| 28 searchTerm: '', | 28 searchTerm: '', |
| 29 // TODO(calamity): Make history toolbar buttons change the offset | 29 // TODO(calamity): Make history toolbar buttons change the offset |
| 30 groupedOffset: 0, | 30 groupedOffset: 0, |
| 31 | 31 |
| 32 set range(val) { this._range = Number(val); }, | 32 set range(val) { this._range = Number(val); }, |
| 33 get range() { return this._range; }, | 33 get range() { return this._range; }, |
| 34 }; | 34 }; |
| 35 } | 35 } |
| 36 }, | 36 }, |
| 37 | 37 |
| 38 /** @type {!QueryResult} */ | 38 /** @type {!QueryResult} */ |
| 39 queryResult_: { | 39 queryResult_: { |
| 40 type: Object, | 40 type: Object, |
| 41 value: function() { | 41 value: function() { |
| 42 return { | 42 return { |
| 43 info: null, | 43 info: null, |
| 44 results: null, | 44 results: null, |
| 45 sessionList: null, | 45 sessionList: null, |
| 46 }; | 46 }; |
| 47 } | 47 } |
| 48 }, | 48 }, |
| 49 | 49 |
| 50 // Route data for the current page. | 50 // Route data for the current page. |
| 51 routeData_: Object, | 51 routeData_: Object, |
| 52 | 52 |
| 53 // The query params for the page. | 53 // The query params for the page. |
| 54 queryParams_: Object, | 54 queryParams_: Object, |
| 55 | 55 |
| 56 // True if the window is narrow enough for the page to have a drawer. | 56 // True if the window is narrow enough for the page to have a drawer. |
| 57 hasDrawer: Boolean, | 57 hasDrawer: Boolean, |
| 58 |
| 59 isUserSignedIn_: { |
| 60 type: Boolean, |
| 61 // Updated on synced-device-manager attach by chrome.sending |
| 62 // 'otherDevicesInitialized'. |
| 63 value: loadTimeData.getBoolean('isUserSignedIn'), |
| 64 }, |
| 58 }, | 65 }, |
| 59 | 66 |
| 60 observers: [ | 67 observers: [ |
| 61 // routeData_.page <=> selectedPage | 68 // routeData_.page <=> selectedPage |
| 62 'routeDataChanged_(routeData_.page)', | 69 'routeDataChanged_(routeData_.page)', |
| 63 'selectedPageChanged_(selectedPage_)', | 70 'selectedPageChanged_(selectedPage_)', |
| 64 | 71 |
| 65 // queryParams_.q <=> queryState.searchTerm | 72 // queryParams_.q <=> queryState.searchTerm |
| 66 'searchTermChanged_(queryState_.searchTerm)', | 73 'searchTermChanged_(queryState_.searchTerm)', |
| 67 'searchQueryParamChanged_(queryParams_.q)', | 74 'searchQueryParamChanged_(queryParams_.q)', |
| 68 | 75 |
| 69 ], | 76 ], |
| 70 | 77 |
| 71 // TODO(calamity): Replace these event listeners with data bound properties. | 78 // TODO(calamity): Replace these event listeners with data bound properties. |
| 72 listeners: { | 79 listeners: { |
| 73 'cr-menu-tap': 'onMenuTap_', | 80 'cr-menu-tap': 'onMenuTap_', |
| 74 'history-checkbox-select': 'checkboxSelected', | 81 'history-checkbox-select': 'checkboxSelected', |
| 75 'unselect-all': 'unselectAll', | 82 'unselect-all': 'unselectAll', |
| 76 'delete-selected': 'deleteSelected', | 83 'delete-selected': 'deleteSelected', |
| 77 'search-domain': 'searchDomain_', | 84 'search-domain': 'searchDomain_', |
| 78 'history-close-drawer': 'closeDrawer_', | 85 'history-close-drawer': 'closeDrawer_', |
| 86 'history-view-changed': 'recordHistoryView_', |
| 79 }, | 87 }, |
| 80 | 88 |
| 81 /** @override */ | 89 /** @override */ |
| 82 ready: function() { | 90 ready: function() { |
| 83 this.grouped_ = loadTimeData.getBoolean('groupByDomain'); | 91 this.grouped_ = loadTimeData.getBoolean('groupByDomain'); |
| 84 | 92 |
| 85 cr.ui.decorate('command', cr.ui.Command); | 93 cr.ui.decorate('command', cr.ui.Command); |
| 86 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); | 94 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); |
| 87 document.addEventListener('command', this.onCommand_.bind(this)); | 95 document.addEventListener('command', this.onCommand_.bind(this)); |
| 88 | 96 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 117 * @private | 125 * @private |
| 118 */ | 126 */ |
| 119 unselectAll: function() { | 127 unselectAll: function() { |
| 120 var listContainer = | 128 var listContainer = |
| 121 /** @type {HistoryListContainerElement} */ (this.$.history); | 129 /** @type {HistoryListContainerElement} */ (this.$.history); |
| 122 var toolbar = /** @type {HistoryToolbarElement} */ (this.$.toolbar); | 130 var toolbar = /** @type {HistoryToolbarElement} */ (this.$.toolbar); |
| 123 listContainer.unselectAllItems(toolbar.count); | 131 listContainer.unselectAllItems(toolbar.count); |
| 124 toolbar.count = 0; | 132 toolbar.count = 0; |
| 125 }, | 133 }, |
| 126 | 134 |
| 127 deleteSelected: function() { | 135 deleteSelected: function() { this.$.history.deleteSelectedWithPrompt(); }, |
| 128 this.$.history.deleteSelectedWithPrompt(); | |
| 129 }, | |
| 130 | 136 |
| 131 /** | 137 /** |
| 132 * @param {HistoryQuery} info An object containing information about the | 138 * @param {HistoryQuery} info An object containing information about the |
| 133 * query. | 139 * query. |
| 134 * @param {!Array<HistoryEntry>} results A list of results. | 140 * @param {!Array<HistoryEntry>} results A list of results. |
| 135 */ | 141 */ |
| 136 historyResult: function(info, results) { | 142 historyResult: function(info, results) { |
| 137 this.set('queryState_.querying', false); | 143 this.set('queryState_.querying', false); |
| 138 this.set('queryResult_.info', info); | 144 this.set('queryResult_.info', info); |
| 139 this.set('queryResult_.results', results); | 145 this.set('queryResult_.results', results); |
| 140 var listContainer = | 146 var listContainer = |
| 141 /** @type {HistoryListContainerElement} */ (this.$['history']); | 147 /** @type {HistoryListContainerElement} */ (this.$['history']); |
| 142 listContainer.historyResult(info, results); | 148 listContainer.historyResult(info, results); |
| 143 }, | 149 }, |
| 144 | 150 |
| 145 /** | 151 /** |
| 146 * Focuses the search bar in the toolbar. | 152 * Focuses the search bar in the toolbar. |
| 147 */ | 153 */ |
| 148 focusToolbarSearchField: function() { | 154 focusToolbarSearchField: function() { this.$.toolbar.showSearchField(); }, |
| 149 this.$.toolbar.showSearchField(); | |
| 150 }, | |
| 151 | 155 |
| 152 /** | 156 /** |
| 153 * Fired when the user presses 'More from this site'. | 157 * Fired when the user presses 'More from this site'. |
| 154 * @param {{detail: {domain: string}}} e | 158 * @param {{detail: {domain: string}}} e |
| 155 */ | 159 */ |
| 156 searchDomain_: function(e) { this.$.toolbar.setSearchTerm(e.detail.domain); }, | 160 searchDomain_: function(e) { this.$.toolbar.setSearchTerm(e.detail.domain); }, |
| 157 | 161 |
| 158 /** | 162 /** |
| 159 * @param {Event} e | 163 * @param {Event} e |
| 160 * @private | 164 * @private |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 222 } |
| 219 | 223 |
| 220 this.set('queryResult_.sessionList', sessionList); | 224 this.set('queryResult_.sessionList', sessionList); |
| 221 }, | 225 }, |
| 222 | 226 |
| 223 /** | 227 /** |
| 224 * Update sign in state of synced device manager after user logs in or out. | 228 * Update sign in state of synced device manager after user logs in or out. |
| 225 * @param {boolean} isUserSignedIn | 229 * @param {boolean} isUserSignedIn |
| 226 */ | 230 */ |
| 227 updateSignInState: function(isUserSignedIn) { | 231 updateSignInState: function(isUserSignedIn) { |
| 228 var syncedDeviceManagerElem = | 232 this.isUserSignedIn_ = isUserSignedIn; |
| 229 /** @type {HistorySyncedDeviceManagerElement} */this | |
| 230 .$$('history-synced-device-manager'); | |
| 231 if (syncedDeviceManagerElem) | |
| 232 syncedDeviceManagerElem.updateSignInState(isUserSignedIn); | |
| 233 }, | 233 }, |
| 234 | 234 |
| 235 /** | 235 /** |
| 236 * @param {string} selectedPage | 236 * @param {string} selectedPage |
| 237 * @return {boolean} | 237 * @return {boolean} |
| 238 * @private | 238 * @private |
| 239 */ | 239 */ |
| 240 syncedTabsSelected_: function(selectedPage) { | 240 syncedTabsSelected_: function(selectedPage) { |
| 241 return selectedPage == 'syncedTabs'; | 241 return selectedPage == 'syncedTabs'; |
| 242 }, | 242 }, |
| 243 | 243 |
| 244 /** | 244 /** |
| 245 * @param {boolean} querying | 245 * @param {boolean} querying |
| 246 * @param {boolean} incremental | 246 * @param {boolean} incremental |
| 247 * @param {string} searchTerm | 247 * @param {string} searchTerm |
| 248 * @return {boolean} Whether a loading spinner should be shown (implies the | 248 * @return {boolean} Whether a loading spinner should be shown (implies the |
| 249 * backend is querying a new search term). | 249 * backend is querying a new search term). |
| 250 * @private | 250 * @private |
| 251 */ | 251 */ |
| 252 shouldShowSpinner_: function(querying, incremental, searchTerm) { | 252 shouldShowSpinner_: function(querying, incremental, searchTerm) { |
| 253 return querying && !incremental && searchTerm != ''; | 253 return querying && !incremental && searchTerm != ''; |
| 254 }, | 254 }, |
| 255 | 255 |
| 256 /** | 256 /** |
| 257 * @param {string} page | 257 * @param {string} page |
| 258 * @private | 258 * @private |
| 259 */ | 259 */ |
| 260 routeDataChanged_: function(page) { | 260 routeDataChanged_: function(page) { this.selectedPage_ = page; }, |
| 261 this.selectedPage_ = page; | |
| 262 }, | |
| 263 | 261 |
| 264 /** | 262 /** |
| 265 * @param {string} selectedPage | 263 * @param {string} selectedPage |
| 266 * @private | 264 * @private |
| 267 */ | 265 */ |
| 268 selectedPageChanged_: function(selectedPage) { | 266 selectedPageChanged_: function(selectedPage) { |
| 269 this.set('routeData_.page', selectedPage); | 267 this.set('routeData_.page', selectedPage); |
| 268 this.recordHistoryView_(); |
| 270 }, | 269 }, |
| 271 | 270 |
| 272 /** | 271 /** |
| 273 * This computed binding is needed to make the iron-pages selector update when | 272 * This computed binding is needed to make the iron-pages selector update when |
| 274 * the synced-device-manager is instantiated for the first time. Otherwise the | 273 * the synced-device-manager is instantiated for the first time. Otherwise the |
| 275 * fallback selection will continue to be used after the corresponding item is | 274 * fallback selection will continue to be used after the corresponding item is |
| 276 * added as a child of iron-pages. | 275 * added as a child of iron-pages. |
| 277 * @param {string} selectedPage | 276 * @param {string} selectedPage |
| 278 * @param {Array} items | 277 * @param {Array} items |
| 279 * @return {string} | 278 * @return {string} |
| 280 * @private | 279 * @private |
| 281 */ | 280 */ |
| 282 getSelectedPage_: function(selectedPage, items) { | 281 getSelectedPage_: function(selectedPage, items) { return selectedPage; }, |
| 283 return selectedPage; | |
| 284 }, | |
| 285 | 282 |
| 286 /** @private */ | 283 /** @private */ |
| 287 closeDrawer_: function() { | 284 closeDrawer_: function() { |
| 288 var drawer = this.$$('#drawer'); | 285 var drawer = this.$$('#drawer'); |
| 289 if (drawer) | 286 if (drawer) |
| 290 drawer.close(); | 287 drawer.close(); |
| 291 }, | 288 }, |
| 289 |
| 290 /** @private */ |
| 291 recordHistoryView_: function() { |
| 292 var histogramValue = HistoryViewHistogram.END; |
| 293 switch (this.selectedPage_) { |
| 294 case 'syncedTabs': |
| 295 histogramValue = this.isUserSignedIn_ ? |
| 296 HistoryViewHistogram.SYNCED_TABS : |
| 297 HistoryViewHistogram.SIGNIN_PROMO; |
| 298 break; |
| 299 default: |
| 300 switch (this.queryState_.range) { |
| 301 case HistoryRange.ALL_TIME: |
| 302 histogramValue = HistoryViewHistogram.HISTORY; |
| 303 break; |
| 304 case HistoryRange.WEEK: |
| 305 histogramValue = HistoryViewHistogram.GROUPED_WEEK; |
| 306 break; |
| 307 case HistoryRange.MONTH: |
| 308 histogramValue = HistoryViewHistogram.GROUPED_MONTH; |
| 309 break; |
| 310 } |
| 311 break; |
| 312 } |
| 313 |
| 314 md_history.BrowserService.getInstance().recordHistogram( |
| 315 'History.HistoryView', histogramValue, HistoryViewHistogram.END |
| 316 ); |
| 317 }, |
| 292 }); | 318 }); |
| OLD | NEW |