| 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': 'recordHistoryPageView_', |
| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 * @private | 141 * @private |
| 134 */ | 142 */ |
| 135 unselectAll: function() { | 143 unselectAll: function() { |
| 136 var listContainer = | 144 var listContainer = |
| 137 /** @type {HistoryListContainerElement} */ (this.$.history); | 145 /** @type {HistoryListContainerElement} */ (this.$.history); |
| 138 var toolbar = /** @type {HistoryToolbarElement} */ (this.$.toolbar); | 146 var toolbar = /** @type {HistoryToolbarElement} */ (this.$.toolbar); |
| 139 listContainer.unselectAllItems(toolbar.count); | 147 listContainer.unselectAllItems(toolbar.count); |
| 140 toolbar.count = 0; | 148 toolbar.count = 0; |
| 141 }, | 149 }, |
| 142 | 150 |
| 143 deleteSelected: function() { | 151 deleteSelected: function() { this.$.history.deleteSelectedWithPrompt(); }, |
| 144 this.$.history.deleteSelectedWithPrompt(); | |
| 145 }, | |
| 146 | 152 |
| 147 /** | 153 /** |
| 148 * @param {HistoryQuery} info An object containing information about the | 154 * @param {HistoryQuery} info An object containing information about the |
| 149 * query. | 155 * query. |
| 150 * @param {!Array<HistoryEntry>} results A list of results. | 156 * @param {!Array<HistoryEntry>} results A list of results. |
| 151 */ | 157 */ |
| 152 historyResult: function(info, results) { | 158 historyResult: function(info, results) { |
| 153 this.set('queryState_.querying', false); | 159 this.set('queryState_.querying', false); |
| 154 this.set('queryResult_.info', info); | 160 this.set('queryResult_.info', info); |
| 155 this.set('queryResult_.results', results); | 161 this.set('queryResult_.results', results); |
| 156 var listContainer = | 162 var listContainer = |
| 157 /** @type {HistoryListContainerElement} */ (this.$['history']); | 163 /** @type {HistoryListContainerElement} */ (this.$['history']); |
| 158 listContainer.historyResult(info, results); | 164 listContainer.historyResult(info, results); |
| 159 }, | 165 }, |
| 160 | 166 |
| 161 /** | 167 /** |
| 162 * Focuses the search bar in the toolbar. | 168 * Focuses the search bar in the toolbar. |
| 163 */ | 169 */ |
| 164 focusToolbarSearchField: function() { | 170 focusToolbarSearchField: function() { this.$.toolbar.showSearchField(); }, |
| 165 this.$.toolbar.showSearchField(); | |
| 166 }, | |
| 167 | 171 |
| 168 /** | 172 /** |
| 169 * Fired when the user presses 'More from this site'. | 173 * Fired when the user presses 'More from this site'. |
| 170 * @param {{detail: {domain: string}}} e | 174 * @param {{detail: {domain: string}}} e |
| 171 */ | 175 */ |
| 172 searchDomain_: function(e) { this.$.toolbar.setSearchTerm(e.detail.domain); }, | 176 searchDomain_: function(e) { this.$.toolbar.setSearchTerm(e.detail.domain); }, |
| 173 | 177 |
| 174 /** | 178 /** |
| 175 * @param {Event} e | 179 * @param {Event} e |
| 176 * @private | 180 * @private |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 */ | 245 */ |
| 242 historyDeleted: function() { | 246 historyDeleted: function() { |
| 243 this.$.history.historyDeleted(); | 247 this.$.history.historyDeleted(); |
| 244 }, | 248 }, |
| 245 | 249 |
| 246 /** | 250 /** |
| 247 * Update sign in state of synced device manager after user logs in or out. | 251 * Update sign in state of synced device manager after user logs in or out. |
| 248 * @param {boolean} isUserSignedIn | 252 * @param {boolean} isUserSignedIn |
| 249 */ | 253 */ |
| 250 updateSignInState: function(isUserSignedIn) { | 254 updateSignInState: function(isUserSignedIn) { |
| 251 var syncedDeviceManagerElem = | 255 this.isUserSignedIn_ = isUserSignedIn; |
| 252 /** @type {HistorySyncedDeviceManagerElement} */this | |
| 253 .$$('history-synced-device-manager'); | |
| 254 if (syncedDeviceManagerElem) | |
| 255 syncedDeviceManagerElem.updateSignInState(isUserSignedIn); | |
| 256 }, | 256 }, |
| 257 | 257 |
| 258 /** | 258 /** |
| 259 * @param {string} selectedPage | 259 * @param {string} selectedPage |
| 260 * @return {boolean} | 260 * @return {boolean} |
| 261 * @private | 261 * @private |
| 262 */ | 262 */ |
| 263 syncedTabsSelected_: function(selectedPage) { | 263 syncedTabsSelected_: function(selectedPage) { |
| 264 return selectedPage == 'syncedTabs'; | 264 return selectedPage == 'syncedTabs'; |
| 265 }, | 265 }, |
| 266 | 266 |
| 267 /** | 267 /** |
| 268 * @param {boolean} querying | 268 * @param {boolean} querying |
| 269 * @param {boolean} incremental | 269 * @param {boolean} incremental |
| 270 * @param {string} searchTerm | 270 * @param {string} searchTerm |
| 271 * @return {boolean} Whether a loading spinner should be shown (implies the | 271 * @return {boolean} Whether a loading spinner should be shown (implies the |
| 272 * backend is querying a new search term). | 272 * backend is querying a new search term). |
| 273 * @private | 273 * @private |
| 274 */ | 274 */ |
| 275 shouldShowSpinner_: function(querying, incremental, searchTerm) { | 275 shouldShowSpinner_: function(querying, incremental, searchTerm) { |
| 276 return querying && !incremental && searchTerm != ''; | 276 return querying && !incremental && searchTerm != ''; |
| 277 }, | 277 }, |
| 278 | 278 |
| 279 /** | 279 /** |
| 280 * @param {string} page | 280 * @param {string} page |
| 281 * @private | 281 * @private |
| 282 */ | 282 */ |
| 283 routeDataChanged_: function(page) { | 283 routeDataChanged_: function(page) { this.selectedPage_ = page; }, |
| 284 this.selectedPage_ = page; | |
| 285 }, | |
| 286 | 284 |
| 287 /** | 285 /** |
| 288 * @param {string} selectedPage | 286 * @param {string} selectedPage |
| 289 * @private | 287 * @private |
| 290 */ | 288 */ |
| 291 selectedPageChanged_: function(selectedPage) { | 289 selectedPageChanged_: function(selectedPage) { |
| 292 this.set('routeData_.page', selectedPage); | 290 this.set('routeData_.page', selectedPage); |
| 291 this.recordHistoryPageView_(); |
| 293 }, | 292 }, |
| 294 | 293 |
| 295 /** | 294 /** |
| 296 * This computed binding is needed to make the iron-pages selector update when | 295 * This computed binding is needed to make the iron-pages selector update when |
| 297 * the synced-device-manager is instantiated for the first time. Otherwise the | 296 * the synced-device-manager is instantiated for the first time. Otherwise the |
| 298 * fallback selection will continue to be used after the corresponding item is | 297 * fallback selection will continue to be used after the corresponding item is |
| 299 * added as a child of iron-pages. | 298 * added as a child of iron-pages. |
| 300 * @param {string} selectedPage | 299 * @param {string} selectedPage |
| 301 * @param {Array} items | 300 * @param {Array} items |
| 302 * @return {string} | 301 * @return {string} |
| 303 * @private | 302 * @private |
| 304 */ | 303 */ |
| 305 getSelectedPage_: function(selectedPage, items) { | 304 getSelectedPage_: function(selectedPage, items) { return selectedPage; }, |
| 306 return selectedPage; | |
| 307 }, | |
| 308 | 305 |
| 309 /** @private */ | 306 /** @private */ |
| 310 closeDrawer_: function() { | 307 closeDrawer_: function() { |
| 311 var drawer = this.$$('#drawer'); | 308 var drawer = this.$$('#drawer'); |
| 312 if (drawer) | 309 if (drawer) |
| 313 drawer.close(); | 310 drawer.close(); |
| 314 }, | 311 }, |
| 312 |
| 313 /** @private */ |
| 314 recordHistoryPageView_: function() { |
| 315 var histogramValue = HistoryPageViewHistogram.END; |
| 316 switch (this.selectedPage_) { |
| 317 case 'syncedTabs': |
| 318 histogramValue = this.isUserSignedIn_ ? |
| 319 HistoryPageViewHistogram.SYNCED_TABS : |
| 320 HistoryPageViewHistogram.SIGNIN_PROMO; |
| 321 break; |
| 322 default: |
| 323 switch (this.queryState_.range) { |
| 324 case HistoryRange.ALL_TIME: |
| 325 histogramValue = HistoryPageViewHistogram.HISTORY; |
| 326 break; |
| 327 case HistoryRange.WEEK: |
| 328 histogramValue = HistoryPageViewHistogram.GROUPED_WEEK; |
| 329 break; |
| 330 case HistoryRange.MONTH: |
| 331 histogramValue = HistoryPageViewHistogram.GROUPED_MONTH; |
| 332 break; |
| 333 } |
| 334 break; |
| 335 } |
| 336 |
| 337 md_history.BrowserService.getInstance().recordHistogram( |
| 338 'History.HistoryPageView', histogramValue, HistoryPageViewHistogram.END |
| 339 ); |
| 340 }, |
| 315 }); | 341 }); |
| OLD | NEW |