Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(634)

Side by Side Diff: chrome/browser/resources/md_downloads/crisper.js

Issue 1492273002: MD Downloads: limit the amount of downloads we send (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new-dl-data
Patch Set: self-review Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 if (typeof Polymer == 'undefined') 5 if (typeof Polymer == 'undefined')
6 Polymer = {dom: 'shadow'}; 6 Polymer = {dom: 'shadow'};
7 else 7 else
8 console.error('Polymer is already defined.'); 8 console.error('Polymer is already defined.');
9 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 9 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
10 // Use of this source code is governed by a BSD-style license that can be 10 // Use of this source code is governed by a BSD-style license that can be
(...skipping 1560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 download: function(url) { 1571 download: function(url) {
1572 var a = document.createElement('a'); 1572 var a = document.createElement('a');
1573 a.href = url; 1573 a.href = url;
1574 a.setAttribute('download', ''); 1574 a.setAttribute('download', '');
1575 a.click(); 1575 a.click();
1576 }, 1576 },
1577 1577
1578 /** @param {string} id ID of the download that the user started dragging. */ 1578 /** @param {string} id ID of the download that the user started dragging. */
1579 drag: chromeSendWithId('drag'), 1579 drag: chromeSendWithId('drag'),
1580 1580
1581 /** @private {boolean} */ 1581 /** Loads more downloads with the current search terms. */
1582 isSearching_: false, 1582 loadMore: function() {
1583 chrome.send('getDownloads', this.searchTerms_);
1584 },
1583 1585
1584 /** 1586 /**
1585 * @return {boolean} Whether the user is currently searching for downloads 1587 * @return {boolean} Whether the user is currently searching for downloads
1586 * (i.e. has a non-empty search term). 1588 * (i.e. has a non-empty search term).
1587 */ 1589 */
1588 isSearching: function() { 1590 isSearching: function() {
1589 return this.isSearching_; 1591 return this.searchTerms_.length > 0;
1590 }, 1592 },
1591 1593
1592 /** Opens the current local destination for downloads. */ 1594 /** Opens the current local destination for downloads. */
1593 openDownloadsFolder: chrome.send.bind(chrome, 'openDownloadsFolder'), 1595 openDownloadsFolder: chrome.send.bind(chrome, 'openDownloadsFolder'),
1594 1596
1595 /** 1597 /**
1596 * @param {string} id ID of the download to run locally on the user's box. 1598 * @param {string} id ID of the download to run locally on the user's box.
1597 */ 1599 */
1598 openFile: chromeSendWithId('openFile'), 1600 openFile: chromeSendWithId('openFile'),
1599 1601
(...skipping 11 matching lines...) Expand all
1611 * warnings. 1613 * warnings.
1612 */ 1614 */
1613 saveDangerous: chromeSendWithId('saveDangerous'), 1615 saveDangerous: chromeSendWithId('saveDangerous'),
1614 1616
1615 /** @param {string} searchText What to search for. */ 1617 /** @param {string} searchText What to search for. */
1616 search: function(searchText) { 1618 search: function(searchText) {
1617 if (this.searchText_ == searchText) 1619 if (this.searchText_ == searchText)
1618 return; 1620 return;
1619 1621
1620 this.searchText_ = searchText; 1622 this.searchText_ = searchText;
1623 this.searchTerms_ = ActionService.splitTerms(this.searchText_);
1624 this.loadMore();
1625 },
1621 1626
1622 var terms = ActionService.splitTerms(searchText); 1627 /** @private {Array<string>} */
1623 this.isSearching_ = terms.length > 0; 1628 searchTerms_: [],
1624 1629
1625 chrome.send('getDownloads', terms); 1630 /** @private {string} */
1626 }, 1631 searchText_: '',
1627 1632
1628 /** 1633 /**
1629 * Shows the local folder a finished download resides in. 1634 * Shows the local folder a finished download resides in.
1630 * @param {string} id ID of the download to show. 1635 * @param {string} id ID of the download to show.
1631 */ 1636 */
1632 show: chromeSendWithId('show'), 1637 show: chromeSendWithId('show'),
1633 1638
1634 /** Undo download removal. */ 1639 /** Undo download removal. */
1635 undo: chrome.send.bind(chrome, 'undo'), 1640 undo: chrome.send.bind(chrome, 'undo'),
1636 }; 1641 };
(...skipping 15332 matching lines...) Expand 10 before | Expand all | Expand 10 after
16969 items_: { 16974 items_: {
16970 type: Array, 16975 type: Array,
16971 value: function() { return []; }, 16976 value: function() { return []; },
16972 }, 16977 },
16973 }, 16978 },
16974 16979
16975 hostAttributes: { 16980 hostAttributes: {
16976 loading: true, 16981 loading: true,
16977 }, 16982 },
16978 16983
16984 listeners: {
16985 'downloads-list.scroll': 'onListScroll_',
16986 },
16987
16979 observers: [ 16988 observers: [
16980 'itemsChanged_(items_.*)', 16989 'itemsChanged_(items_.*)',
16981 ], 16990 ],
16982 16991
16983 /** @private */ 16992 /** @private */
16984 clearAll_: function() { 16993 clearAll_: function() {
16985 this.set('items_', []); 16994 this.set('items_', []);
16986 }, 16995 },
16987 16996
16988 /** @private */ 16997 /** @private */
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
17036 * @param {Event} e 17045 * @param {Event} e
17037 * @private 17046 * @private
17038 */ 17047 */
17039 onCommand_: function(e) { 17048 onCommand_: function(e) {
17040 if (e.command.id == 'clear-all-command') 17049 if (e.command.id == 'clear-all-command')
17041 downloads.ActionService.getInstance().clearAll(); 17050 downloads.ActionService.getInstance().clearAll();
17042 else if (e.command.id == 'undo-command') 17051 else if (e.command.id == 'undo-command')
17043 downloads.ActionService.getInstance().undo(); 17052 downloads.ActionService.getInstance().undo();
17044 }, 17053 },
17045 17054
17055 /**
17056 * @param {Event} e
17057 * @private
17058 */
17059 onListScroll_: function(e) {
17060 var list = this.$['downloads-list'];
17061 if (list.scrollHeight > list.offsetHeight &&
17062 list.scrollTop + list.offsetHeight == list.scrollHeight) {
17063 // Reached the end of the scrollback. Attempt to load more items.
17064 downloads.ActionService.getInstance().loadMore();
17065 }
17066 },
17067
17046 /** @private */ 17068 /** @private */
17047 onLoad_: function() { 17069 onLoad_: function() {
17048 cr.ui.decorate('command', cr.ui.Command); 17070 cr.ui.decorate('command', cr.ui.Command);
17049 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); 17071 document.addEventListener('canExecute', this.onCanExecute_.bind(this));
17050 document.addEventListener('command', this.onCommand_.bind(this)); 17072 document.addEventListener('command', this.onCommand_.bind(this));
17051 17073
17052 // Shows all downloads. 17074 downloads.ActionService.getInstance().loadMore();
17053 downloads.ActionService.getInstance().search('');
17054 }, 17075 },
17055 17076
17056 /** 17077 /**
17057 * @param {number} index 17078 * @param {number} index
17058 * @private 17079 * @private
17059 */ 17080 */
17060 removeItem_: function(index) { 17081 removeItem_: function(index) {
17061 this.splice('items_', index, 1); 17082 this.splice('items_', index, 1);
17062 this.updateHideDates_(index, index); 17083 this.updateHideDates_(index, index);
17063 }, 17084 },
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
17115 Manager.get().updateItem_(index, data); 17136 Manager.get().updateItem_(index, data);
17116 }; 17137 };
17117 17138
17118 return {Manager: Manager}; 17139 return {Manager: Manager};
17119 }); 17140 });
17120 // Copyright 2015 The Chromium Authors. All rights reserved. 17141 // Copyright 2015 The Chromium Authors. All rights reserved.
17121 // Use of this source code is governed by a BSD-style license that can be 17142 // Use of this source code is governed by a BSD-style license that can be
17122 // found in the LICENSE file. 17143 // found in the LICENSE file.
17123 17144
17124 window.addEventListener('load', downloads.Manager.onLoad); 17145 window.addEventListener('load', downloads.Manager.onLoad);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698