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 cr.define('md_history', function() { | 5 cr.define('md_history', function() { |
6 var lazyLoadPromise = null; | 6 var lazyLoadPromise = null; |
7 function ensureLazyLoaded() { | 7 function ensureLazyLoaded() { |
8 if (!lazyLoadPromise) { | 8 if (!lazyLoadPromise) { |
9 lazyLoadPromise = new Promise(function(resolve, reject) { | 9 lazyLoadPromise = new Promise(function(resolve, reject) { |
10 Polymer.Base.importHref( | 10 Polymer.Base.importHref( |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 behaviors: [Polymer.IronScrollTargetBehavior], | 25 behaviors: [Polymer.IronScrollTargetBehavior], |
26 | 26 |
27 properties: { | 27 properties: { |
28 // Used to display notices for profile sign-in status. | 28 // Used to display notices for profile sign-in status. |
29 showSidebarFooter: Boolean, | 29 showSidebarFooter: Boolean, |
30 | 30 |
31 hasSyncedResults: Boolean, | 31 hasSyncedResults: Boolean, |
32 | 32 |
33 // The id of the currently selected page. | 33 // The id of the currently selected page. |
34 selectedPage_: {type: String, observer: 'unselectAll'}, | 34 selectedPage_: {type: String, observer: 'selectedPageChanged_'}, |
35 | 35 |
36 // Whether domain-grouped history is enabled. | 36 // Whether domain-grouped history is enabled. |
37 grouped_: {type: Boolean, reflectToAttribute: true}, | 37 grouped_: {type: Boolean, reflectToAttribute: true}, |
38 | 38 |
39 /** @type {!QueryState} */ | 39 /** @type {!QueryState} */ |
40 queryState_: { | 40 queryState_: { |
41 type: Object, | 41 type: Object, |
42 value: function() { | 42 value: function() { |
43 return { | 43 return { |
44 // Whether the most recent query was incremental. | 44 // Whether the most recent query was incremental. |
(...skipping 17 matching lines...) Expand all Loading... |
62 type: Object, | 62 type: Object, |
63 value: function() { | 63 value: function() { |
64 return { | 64 return { |
65 info: null, | 65 info: null, |
66 results: null, | 66 results: null, |
67 sessionList: null, | 67 sessionList: null, |
68 }; | 68 }; |
69 } | 69 } |
70 }, | 70 }, |
71 | 71 |
72 // Route data for the current page. | |
73 routeData_: Object, | |
74 | |
75 // The query params for the page. | |
76 queryParams_: Object, | |
77 | |
78 // True if the window is narrow enough for the page to have a drawer. | 72 // True if the window is narrow enough for the page to have a drawer. |
79 hasDrawer_: Boolean, | 73 hasDrawer_: Boolean, |
80 | 74 |
81 isUserSignedIn_: { | 75 isUserSignedIn_: { |
82 type: Boolean, | 76 type: Boolean, |
83 // Updated on synced-device-manager attach by chrome.sending | 77 // Updated on synced-device-manager attach by chrome.sending |
84 // 'otherDevicesInitialized'. | 78 // 'otherDevicesInitialized'. |
85 value: loadTimeData.getBoolean('isUserSignedIn'), | 79 value: loadTimeData.getBoolean('isUserSignedIn'), |
86 }, | 80 }, |
87 | 81 |
88 toolbarShadow_: { | 82 toolbarShadow_: { |
89 type: Boolean, | 83 type: Boolean, |
90 reflectToAttribute: true, | 84 reflectToAttribute: true, |
91 notify: true, | 85 notify: true, |
92 } | 86 } |
93 }, | 87 }, |
94 | 88 |
95 observers: [ | |
96 // routeData_.page <=> selectedPage | |
97 'routeDataChanged_(routeData_.page)', | |
98 'selectedPageChanged_(selectedPage_)', | |
99 | |
100 // queryParams_.q <=> queryState.searchTerm | |
101 'searchTermChanged_(queryState_.searchTerm)', | |
102 'searchQueryParamChanged_(queryParams_.q)', | |
103 | |
104 ], | |
105 | |
106 // TODO(calamity): Replace these event listeners with data bound properties. | 89 // TODO(calamity): Replace these event listeners with data bound properties. |
107 listeners: { | 90 listeners: { |
108 'cr-menu-tap': 'onMenuTap_', | 91 'cr-menu-tap': 'onMenuTap_', |
109 'history-checkbox-select': 'checkboxSelected', | 92 'history-checkbox-select': 'checkboxSelected', |
110 'unselect-all': 'unselectAll', | 93 'unselect-all': 'unselectAll', |
111 'delete-selected': 'deleteSelected', | 94 'delete-selected': 'deleteSelected', |
112 'search-domain': 'searchDomain_', | |
113 'history-close-drawer': 'closeDrawer_', | 95 'history-close-drawer': 'closeDrawer_', |
114 'history-view-changed': 'historyViewChanged_', | 96 'history-view-changed': 'historyViewChanged_', |
115 }, | 97 }, |
116 | 98 |
117 /** @override */ | 99 /** @override */ |
118 ready: function() { | 100 ready: function() { |
119 this.grouped_ = loadTimeData.getBoolean('groupByDomain'); | 101 this.grouped_ = loadTimeData.getBoolean('groupByDomain'); |
120 | 102 |
121 cr.ui.decorate('command', cr.ui.Command); | 103 cr.ui.decorate('command', cr.ui.Command); |
122 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); | 104 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); |
123 document.addEventListener('command', this.onCommand_.bind(this)); | 105 document.addEventListener('command', this.onCommand_.bind(this)); |
124 | |
125 // Redirect legacy search URLs to URLs compatible with material history. | |
126 if (window.location.hash) { | |
127 window.location.href = window.location.href.split('#')[0] + '?' + | |
128 window.location.hash.substr(1); | |
129 } | |
130 }, | 106 }, |
131 | 107 |
132 onFirstRender: function() { | 108 onFirstRender: function() { |
133 setTimeout(function() { | 109 setTimeout(function() { |
134 chrome.send( | 110 chrome.send( |
135 'metricsHandler:recordTime', | 111 'metricsHandler:recordTime', |
136 ['History.ResultsRenderedTime', window.performance.now()]); | 112 ['History.ResultsRenderedTime', window.performance.now()]); |
137 }); | 113 }); |
138 | 114 |
139 // Focus the search field on load. Done here to ensure the history page | 115 // Focus the search field on load. Done here to ensure the history page |
140 // is rendered before we try to take focus. | 116 // is rendered before we try to take focus. |
141 if (!this.hasDrawer_) { | 117 if (!this.hasDrawer_) { |
142 this.focusToolbarSearchField(); | 118 this.focusToolbarSearchField(); |
143 } | 119 } |
144 | 120 |
145 // Lazily load the remainder of the UI. | 121 // Lazily load the remainder of the UI. |
146 md_history.ensureLazyLoaded(); | 122 md_history.ensureLazyLoaded(); |
147 }, | 123 }, |
148 | 124 |
149 /** Overridden from IronScrollTargetBehavior */ | 125 /** Overridden from IronScrollTargetBehavior */ |
150 _scrollHandler: function() { | 126 _scrollHandler: function() { |
151 this.toolbarShadow_ = this.scrollTarget.scrollTop != 0; | 127 if (this.scrollTarget) |
| 128 this.toolbarShadow_ = this.scrollTarget.scrollTop != 0; |
152 }, | 129 }, |
153 | 130 |
154 /** @private */ | 131 /** @private */ |
155 onMenuTap_: function() { | 132 onMenuTap_: function() { |
156 var drawer = this.$$('#drawer'); | 133 var drawer = this.$$('#drawer'); |
157 if (drawer) | 134 if (drawer) |
158 drawer.toggle(); | 135 drawer.toggle(); |
159 }, | 136 }, |
160 | 137 |
161 /** | 138 /** |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 /** @type {HistoryListContainerElement} */ (this.$['history']); | 174 /** @type {HistoryListContainerElement} */ (this.$['history']); |
198 listContainer.historyResult(info, results); | 175 listContainer.historyResult(info, results); |
199 }, | 176 }, |
200 | 177 |
201 /** | 178 /** |
202 * Focuses the search bar in the toolbar. | 179 * Focuses the search bar in the toolbar. |
203 */ | 180 */ |
204 focusToolbarSearchField: function() { this.$.toolbar.showSearchField(); }, | 181 focusToolbarSearchField: function() { this.$.toolbar.showSearchField(); }, |
205 | 182 |
206 /** | 183 /** |
207 * Fired when the user presses 'More from this site'. | |
208 * @param {{detail: {domain: string}}} e | |
209 */ | |
210 searchDomain_: function(e) { this.$.toolbar.setSearchTerm(e.detail.domain); }, | |
211 | |
212 /** | |
213 * @param {Event} e | 184 * @param {Event} e |
214 * @private | 185 * @private |
215 */ | 186 */ |
216 onCanExecute_: function(e) { | 187 onCanExecute_: function(e) { |
217 e = /** @type {cr.ui.CanExecuteEvent} */(e); | 188 e = /** @type {cr.ui.CanExecuteEvent} */(e); |
218 switch (e.command.id) { | 189 switch (e.command.id) { |
219 case 'find-command': | 190 case 'find-command': |
220 e.canExecute = true; | 191 e.canExecute = true; |
221 break; | 192 break; |
222 case 'slash-command': | 193 case 'slash-command': |
223 e.canExecute = !this.$.toolbar.searchBar.isSearchFocused(); | 194 e.canExecute = !this.$.toolbar.searchField.isSearchFocused(); |
224 break; | 195 break; |
225 case 'delete-command': | 196 case 'delete-command': |
226 e.canExecute = this.$.toolbar.count > 0; | 197 e.canExecute = this.$.toolbar.count > 0; |
227 break; | 198 break; |
228 } | 199 } |
229 }, | 200 }, |
230 | 201 |
231 /** | 202 /** |
232 * @param {string} searchTerm | |
233 * @private | |
234 */ | |
235 searchTermChanged_: function(searchTerm) { | |
236 this.set('queryParams_.q', searchTerm || null); | |
237 this.$['history'].queryHistory(false); | |
238 // TODO(tsergeant): Ignore incremental searches in this metric. | |
239 if (this.queryState_.searchTerm) | |
240 md_history.BrowserService.getInstance().recordAction('Search'); | |
241 }, | |
242 | |
243 /** | |
244 * @param {string} searchQuery | |
245 * @private | |
246 */ | |
247 searchQueryParamChanged_: function(searchQuery) { | |
248 this.$.toolbar.setSearchTerm(searchQuery || ''); | |
249 }, | |
250 | |
251 /** | |
252 * @param {Event} e | 203 * @param {Event} e |
253 * @private | 204 * @private |
254 */ | 205 */ |
255 onCommand_: function(e) { | 206 onCommand_: function(e) { |
256 if (e.command.id == 'find-command' || e.command.id == 'slash-command') | 207 if (e.command.id == 'find-command' || e.command.id == 'slash-command') |
257 this.focusToolbarSearchField(); | 208 this.focusToolbarSearchField(); |
258 if (e.command.id == 'delete-command') | 209 if (e.command.id == 'delete-command') |
259 this.deleteSelected(); | 210 this.deleteSelected(); |
260 }, | 211 }, |
261 | 212 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 * @param {boolean} hasSyncedResults | 268 * @param {boolean} hasSyncedResults |
318 * @param {string} selectedPage | 269 * @param {string} selectedPage |
319 * @return {boolean} Whether the (i) synced results notice should be shown. | 270 * @return {boolean} Whether the (i) synced results notice should be shown. |
320 * @private | 271 * @private |
321 */ | 272 */ |
322 showSyncNotice_: function(hasSyncedResults, selectedPage) { | 273 showSyncNotice_: function(hasSyncedResults, selectedPage) { |
323 return hasSyncedResults && selectedPage != 'syncedTabs'; | 274 return hasSyncedResults && selectedPage != 'syncedTabs'; |
324 }, | 275 }, |
325 | 276 |
326 /** | 277 /** |
327 * @param {string} page | |
328 * @private | 278 * @private |
329 */ | 279 */ |
330 routeDataChanged_: function(page) { this.selectedPage_ = page; }, | 280 selectedPageChanged_: function() { |
331 | 281 this.unselectAll(); |
332 /** | |
333 * @param {string} selectedPage | |
334 * @private | |
335 */ | |
336 selectedPageChanged_: function(selectedPage) { | |
337 this.set('routeData_.page', selectedPage); | |
338 this.historyViewChanged_(); | 282 this.historyViewChanged_(); |
339 }, | 283 }, |
340 | 284 |
341 /** @private */ | 285 /** @private */ |
342 historyViewChanged_: function() { | 286 historyViewChanged_: function() { |
343 // This allows the synced-device-manager to render so that it can be set as | 287 // This allows the synced-device-manager to render so that it can be set as |
344 // the scroll target. | 288 // the scroll target. |
345 requestAnimationFrame(function() { | 289 requestAnimationFrame(function() { |
346 this.scrollTarget = this.$.content.selectedItem.getContentScrollTarget(); | 290 // <iron-pages> can occasionally end up with no item selected during |
| 291 // tests. |
| 292 if (!this.$.content.selectedItem) |
| 293 return; |
| 294 this.scrollTarget = |
| 295 this.$.content.selectedItem.getContentScrollTarget(); |
347 this._scrollHandler(); | 296 this._scrollHandler(); |
348 }.bind(this)); | 297 }.bind(this)); |
349 this.recordHistoryPageView_(); | 298 this.recordHistoryPageView_(); |
350 }, | 299 }, |
351 | 300 |
352 /** | 301 /** |
353 * This computed binding is needed to make the iron-pages selector update when | 302 * This computed binding is needed to make the iron-pages selector update when |
354 * the synced-device-manager is instantiated for the first time. Otherwise the | 303 * the synced-device-manager is instantiated for the first time. Otherwise the |
355 * fallback selection will continue to be used after the corresponding item is | 304 * fallback selection will continue to be used after the corresponding item is |
356 * added as a child of iron-pages. | 305 * added as a child of iron-pages. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 break; | 339 break; |
391 } | 340 } |
392 break; | 341 break; |
393 } | 342 } |
394 | 343 |
395 md_history.BrowserService.getInstance().recordHistogram( | 344 md_history.BrowserService.getInstance().recordHistogram( |
396 'History.HistoryPageView', histogramValue, HistoryPageViewHistogram.END | 345 'History.HistoryPageView', histogramValue, HistoryPageViewHistogram.END |
397 ); | 346 ); |
398 }, | 347 }, |
399 }); | 348 }); |
OLD | NEW |