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 behaviors: [Polymer.IronScrollTargetBehavior], | 8 behaviors: [Polymer.IronScrollTargetBehavior], |
9 | 9 |
10 properties: { | 10 properties: { |
11 // Used to display notices for profile sign-in status. | 11 // Used to display notices for profile sign-in status. |
12 showSidebarFooter: Boolean, | 12 showSidebarFooter: Boolean, |
13 | 13 |
14 hasSyncedResults: Boolean, | 14 hasSyncedResults: Boolean, |
15 | 15 |
16 // The id of the currently selected page. | 16 // The id of the currently selected page. |
17 selectedPage_: {type: String, observer: 'unselectAll'}, | 17 selectedPage_: {type: String, observer: 'selectedPageChanged_'}, |
18 | 18 |
19 // Whether domain-grouped history is enabled. | 19 // Whether domain-grouped history is enabled. |
20 grouped_: {type: Boolean, reflectToAttribute: true}, | 20 grouped_: {type: Boolean, reflectToAttribute: true}, |
21 | 21 |
22 /** @type {!QueryState} */ | 22 /** @type {!QueryState} */ |
23 queryState_: { | 23 queryState_: { |
24 type: Object, | 24 type: Object, |
25 value: function() { | 25 value: function() { |
26 return { | 26 return { |
27 // Whether the most recent query was incremental. | 27 // Whether the most recent query was incremental. |
(...skipping 17 matching lines...) Expand all Loading... | |
45 type: Object, | 45 type: Object, |
46 value: function() { | 46 value: function() { |
47 return { | 47 return { |
48 info: null, | 48 info: null, |
49 results: null, | 49 results: null, |
50 sessionList: null, | 50 sessionList: null, |
51 }; | 51 }; |
52 } | 52 } |
53 }, | 53 }, |
54 | 54 |
55 // Route data for the current page. | |
56 routeData_: Object, | |
57 | |
58 // The query params for the page. | |
59 queryParams_: Object, | |
60 | |
61 // True if the window is narrow enough for the page to have a drawer. | 55 // True if the window is narrow enough for the page to have a drawer. |
62 hasDrawer_: Boolean, | 56 hasDrawer_: Boolean, |
63 | 57 |
64 isUserSignedIn_: { | 58 isUserSignedIn_: { |
65 type: Boolean, | 59 type: Boolean, |
66 // Updated on synced-device-manager attach by chrome.sending | 60 // Updated on synced-device-manager attach by chrome.sending |
67 // 'otherDevicesInitialized'. | 61 // 'otherDevicesInitialized'. |
68 value: loadTimeData.getBoolean('isUserSignedIn'), | 62 value: loadTimeData.getBoolean('isUserSignedIn'), |
69 }, | 63 }, |
70 | 64 |
71 toolbarShadow_: { | 65 toolbarShadow_: { |
72 type: Boolean, | 66 type: Boolean, |
73 reflectToAttribute: true, | 67 reflectToAttribute: true, |
74 notify: true, | 68 notify: true, |
75 } | 69 } |
76 }, | 70 }, |
77 | 71 |
78 observers: [ | |
79 // routeData_.page <=> selectedPage | |
80 'routeDataChanged_(routeData_.page)', | |
81 'selectedPageChanged_(selectedPage_)', | |
82 | |
83 // queryParams_.q <=> queryState.searchTerm | |
84 'searchTermChanged_(queryState_.searchTerm)', | |
85 'searchQueryParamChanged_(queryParams_.q)', | |
86 | |
87 ], | |
88 | |
89 // TODO(calamity): Replace these event listeners with data bound properties. | 72 // TODO(calamity): Replace these event listeners with data bound properties. |
90 listeners: { | 73 listeners: { |
91 'cr-menu-tap': 'onMenuTap_', | 74 'cr-menu-tap': 'onMenuTap_', |
92 'history-checkbox-select': 'checkboxSelected', | 75 'history-checkbox-select': 'checkboxSelected', |
93 'unselect-all': 'unselectAll', | 76 'unselect-all': 'unselectAll', |
94 'delete-selected': 'deleteSelected', | 77 'delete-selected': 'deleteSelected', |
95 'search-domain': 'searchDomain_', | 78 'search-domain': 'searchDomain_', |
calamity
2016/09/22 05:12:26
Remove.
tsergeant
2016/09/22 23:57:42
Good pickup, done.
| |
96 'history-close-drawer': 'closeDrawer_', | 79 'history-close-drawer': 'closeDrawer_', |
97 'history-view-changed': 'historyViewChanged_', | 80 'history-view-changed': 'historyViewChanged_', |
98 }, | 81 }, |
99 | 82 |
100 /** @override */ | 83 /** @override */ |
101 ready: function() { | 84 ready: function() { |
102 this.grouped_ = loadTimeData.getBoolean('groupByDomain'); | 85 this.grouped_ = loadTimeData.getBoolean('groupByDomain'); |
103 | 86 |
104 cr.ui.decorate('command', cr.ui.Command); | 87 cr.ui.decorate('command', cr.ui.Command); |
105 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); | 88 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); |
106 document.addEventListener('command', this.onCommand_.bind(this)); | 89 document.addEventListener('command', this.onCommand_.bind(this)); |
107 | |
108 // Redirect legacy search URLs to URLs compatible with material history. | |
109 if (window.location.hash) { | |
110 window.location.href = window.location.href.split('#')[0] + '?' + | |
111 window.location.hash.substr(1); | |
112 } | |
113 }, | 90 }, |
114 | 91 |
115 onFirstRender: function() { | 92 onFirstRender: function() { |
116 // requestAnimationFrame allows measurement immediately before the next | 93 // requestAnimationFrame allows measurement immediately before the next |
117 // repaint, but after the first page of <iron-list> items has stamped. | 94 // repaint, but after the first page of <iron-list> items has stamped. |
118 requestAnimationFrame(function() { | 95 requestAnimationFrame(function() { |
119 chrome.send( | 96 chrome.send( |
120 'metricsHandler:recordTime', | 97 'metricsHandler:recordTime', |
121 ['History.ResultsRenderedTime', window.performance.now()]); | 98 ['History.ResultsRenderedTime', window.performance.now()]); |
122 }); | 99 }); |
123 | 100 |
124 // Focus the search field on load. Done here to ensure the history page | 101 // Focus the search field on load. Done here to ensure the history page |
125 // is rendered before we try to take focus. | 102 // is rendered before we try to take focus. |
126 if (!this.hasDrawer_) { | 103 if (!this.hasDrawer_) { |
127 this.focusToolbarSearchField(); | 104 this.focusToolbarSearchField(); |
128 } | 105 } |
129 }, | 106 }, |
130 | 107 |
131 /** Overridden from IronScrollTargetBehavior */ | 108 /** Overridden from IronScrollTargetBehavior */ |
132 _scrollHandler: function() { | 109 _scrollHandler: function() { |
133 this.toolbarShadow_ = this.scrollTarget.scrollTop != 0; | 110 if (this.scrollTarget) |
111 this.toolbarShadow_ = this.scrollTarget.scrollTop != 0; | |
134 }, | 112 }, |
135 | 113 |
136 /** @private */ | 114 /** @private */ |
137 onMenuTap_: function() { | 115 onMenuTap_: function() { |
138 var drawer = this.$$('#drawer'); | 116 var drawer = this.$$('#drawer'); |
139 if (drawer) | 117 if (drawer) |
140 drawer.toggle(); | 118 drawer.toggle(); |
141 }, | 119 }, |
142 | 120 |
143 /** | 121 /** |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 /** @type {HistoryListContainerElement} */ (this.$['history']); | 157 /** @type {HistoryListContainerElement} */ (this.$['history']); |
180 listContainer.historyResult(info, results); | 158 listContainer.historyResult(info, results); |
181 }, | 159 }, |
182 | 160 |
183 /** | 161 /** |
184 * Focuses the search bar in the toolbar. | 162 * Focuses the search bar in the toolbar. |
185 */ | 163 */ |
186 focusToolbarSearchField: function() { this.$.toolbar.showSearchField(); }, | 164 focusToolbarSearchField: function() { this.$.toolbar.showSearchField(); }, |
187 | 165 |
188 /** | 166 /** |
189 * Fired when the user presses 'More from this site'. | |
190 * @param {{detail: {domain: string}}} e | |
191 */ | |
192 searchDomain_: function(e) { this.$.toolbar.setSearchTerm(e.detail.domain); }, | |
193 | |
194 /** | |
195 * @param {Event} e | 167 * @param {Event} e |
196 * @private | 168 * @private |
197 */ | 169 */ |
198 onCanExecute_: function(e) { | 170 onCanExecute_: function(e) { |
199 e = /** @type {cr.ui.CanExecuteEvent} */(e); | 171 e = /** @type {cr.ui.CanExecuteEvent} */(e); |
200 switch (e.command.id) { | 172 switch (e.command.id) { |
201 case 'find-command': | 173 case 'find-command': |
202 e.canExecute = true; | 174 e.canExecute = true; |
203 break; | 175 break; |
204 case 'slash-command': | 176 case 'slash-command': |
205 e.canExecute = !this.$.toolbar.searchBar.isSearchFocused(); | 177 e.canExecute = !this.$.toolbar.searchBar.isSearchFocused(); |
206 break; | 178 break; |
207 case 'delete-command': | 179 case 'delete-command': |
208 e.canExecute = this.$.toolbar.count > 0; | 180 e.canExecute = this.$.toolbar.count > 0; |
209 break; | 181 break; |
210 } | 182 } |
211 }, | 183 }, |
212 | 184 |
213 /** | 185 /** |
214 * @param {string} searchTerm | |
215 * @private | |
216 */ | |
217 searchTermChanged_: function(searchTerm) { | |
218 this.set('queryParams_.q', searchTerm || null); | |
219 this.$['history'].queryHistory(false); | |
220 // TODO(tsergeant): Ignore incremental searches in this metric. | |
221 if (this.queryState_.searchTerm) | |
222 md_history.BrowserService.getInstance().recordAction('Search'); | |
223 }, | |
224 | |
225 /** | |
226 * @param {string} searchQuery | |
227 * @private | |
228 */ | |
229 searchQueryParamChanged_: function(searchQuery) { | |
230 this.$.toolbar.setSearchTerm(searchQuery || ''); | |
231 }, | |
232 | |
233 /** | |
234 * @param {Event} e | 186 * @param {Event} e |
235 * @private | 187 * @private |
236 */ | 188 */ |
237 onCommand_: function(e) { | 189 onCommand_: function(e) { |
238 if (e.command.id == 'find-command' || e.command.id == 'slash-command') | 190 if (e.command.id == 'find-command' || e.command.id == 'slash-command') |
239 this.focusToolbarSearchField(); | 191 this.focusToolbarSearchField(); |
240 if (e.command.id == 'delete-command') | 192 if (e.command.id == 'delete-command') |
241 this.deleteSelected(); | 193 this.deleteSelected(); |
242 }, | 194 }, |
243 | 195 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 * @param {boolean} hasSyncedResults | 251 * @param {boolean} hasSyncedResults |
300 * @param {string} selectedPage | 252 * @param {string} selectedPage |
301 * @return {boolean} Whether the (i) synced results notice should be shown. | 253 * @return {boolean} Whether the (i) synced results notice should be shown. |
302 * @private | 254 * @private |
303 */ | 255 */ |
304 showSyncNotice_: function(hasSyncedResults, selectedPage) { | 256 showSyncNotice_: function(hasSyncedResults, selectedPage) { |
305 return hasSyncedResults && selectedPage != 'syncedTabs'; | 257 return hasSyncedResults && selectedPage != 'syncedTabs'; |
306 }, | 258 }, |
307 | 259 |
308 /** | 260 /** |
309 * @param {string} page | |
310 * @private | 261 * @private |
311 */ | 262 */ |
312 routeDataChanged_: function(page) { this.selectedPage_ = page; }, | 263 selectedPageChanged_: function() { |
313 | 264 this.unselectAll(); |
314 /** | |
315 * @param {string} selectedPage | |
316 * @private | |
317 */ | |
318 selectedPageChanged_: function(selectedPage) { | |
319 this.set('routeData_.page', selectedPage); | |
320 this.historyViewChanged_(); | 265 this.historyViewChanged_(); |
321 }, | 266 }, |
322 | 267 |
323 /** @private */ | 268 /** @private */ |
324 historyViewChanged_: function() { | 269 historyViewChanged_: function() { |
325 // This allows the synced-device-manager to render so that it can be set as | 270 // This allows the synced-device-manager to render so that it can be set as |
326 // the scroll target. | 271 // the scroll target. |
327 requestAnimationFrame(function() { | 272 requestAnimationFrame(function() { |
328 this.scrollTarget = this.$.content.selectedItem.getContentScrollTarget(); | 273 if (this.$.content.selectedItem) { |
tsergeant
2016/09/21 07:57:47
These guards are necessary because of tests.
I do
calamity
2016/09/22 05:12:26
Looks fine. Invert and early return with comment.
tsergeant
2016/09/22 23:57:42
Done.
| |
329 this._scrollHandler(); | 274 this.scrollTarget = |
275 this.$.content.selectedItem.getContentScrollTarget(); | |
276 this._scrollHandler(); | |
277 } | |
330 }.bind(this)); | 278 }.bind(this)); |
331 this.recordHistoryPageView_(); | 279 this.recordHistoryPageView_(); |
332 }, | 280 }, |
333 | 281 |
334 /** | 282 /** |
335 * This computed binding is needed to make the iron-pages selector update when | 283 * This computed binding is needed to make the iron-pages selector update when |
336 * the synced-device-manager is instantiated for the first time. Otherwise the | 284 * the synced-device-manager is instantiated for the first time. Otherwise the |
337 * fallback selection will continue to be used after the corresponding item is | 285 * fallback selection will continue to be used after the corresponding item is |
338 * added as a child of iron-pages. | 286 * added as a child of iron-pages. |
339 * @param {string} selectedPage | 287 * @param {string} selectedPage |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 break; | 320 break; |
373 } | 321 } |
374 break; | 322 break; |
375 } | 323 } |
376 | 324 |
377 md_history.BrowserService.getInstance().recordHistogram( | 325 md_history.BrowserService.getInstance().recordHistogram( |
378 'History.HistoryPageView', histogramValue, HistoryPageViewHistogram.END | 326 'History.HistoryPageView', histogramValue, HistoryPageViewHistogram.END |
379 ); | 327 ); |
380 }, | 328 }, |
381 }); | 329 }); |
OLD | NEW |