Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 cr.define('downloads', function() { | 5 cr.define('downloads', function() { |
| 6 /** | 6 /** |
| 7 * @param {string} chromeSendName | 7 * @param {string} chromeSendName |
| 8 * @return {function(string):void} A chrome.send() callback with curried name. | 8 * @return {function(string):void} A chrome.send() callback with curried name. |
| 9 */ | 9 */ |
| 10 function chromeSendWithId(chromeSendName) { | 10 function chromeSendWithId(chromeSendName) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 }, | 38 }, |
| 39 | 39 |
| 40 /** @param {string} id ID of the download that the user started dragging. */ | 40 /** @param {string} id ID of the download that the user started dragging. */ |
| 41 drag: chromeSendWithId('drag'), | 41 drag: chromeSendWithId('drag'), |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * @return {boolean} Whether the user is currently searching for downloads | 44 * @return {boolean} Whether the user is currently searching for downloads |
| 45 * (i.e. has a non-empty search term). | 45 * (i.e. has a non-empty search term). |
| 46 */ | 46 */ |
| 47 isSearching: function() { | 47 isSearching: function() { |
| 48 return this.searchText_.length > 0; | 48 return (this.searchText_ || '').length > 0; |
|
asanka
2015/11/24 22:08:22
!!this.searchText_
or do you folks dislike that e
Dan Beam
2015/11/25 04:06:36
Done.
| |
| 49 }, | 49 }, |
| 50 | 50 |
| 51 /** Opens the current local destination for downloads. */ | 51 /** Opens the current local destination for downloads. */ |
| 52 openDownloadsFolder: chrome.send.bind(chrome, 'openDownloadsFolder'), | 52 openDownloadsFolder: chrome.send.bind(chrome, 'openDownloadsFolder'), |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * @param {string} id ID of the download to run locally on the user's box. | 55 * @param {string} id ID of the download to run locally on the user's box. |
| 56 */ | 56 */ |
| 57 openFile: chromeSendWithId('openFile'), | 57 openFile: chromeSendWithId('openFile'), |
| 58 | 58 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 71 */ | 71 */ |
| 72 saveDangerous: chromeSendWithId('saveDangerous'), | 72 saveDangerous: chromeSendWithId('saveDangerous'), |
| 73 | 73 |
| 74 /** @param {string} searchText What to search for. */ | 74 /** @param {string} searchText What to search for. */ |
| 75 search: function(searchText) { | 75 search: function(searchText) { |
| 76 if (this.searchText_ == searchText) | 76 if (this.searchText_ == searchText) |
| 77 return; | 77 return; |
| 78 | 78 |
| 79 this.searchText_ = searchText; | 79 this.searchText_ = searchText; |
| 80 | 80 |
| 81 /** | |
| 82 * @param {string} s | |
| 83 * @return {string} |s| without whitespace at the ends (trimmed). | |
| 84 */ | |
| 85 function trim(s) { return s.trim(); } | |
| 86 | |
| 81 // Split quoted terms (e.g., 'The "lazy" dog' => ['The', 'lazy', 'dog']). | 87 // Split quoted terms (e.g., 'The "lazy" dog' => ['The', 'lazy', 'dog']). |
| 82 function trim(s) { return s.trim(); } | 88 var terms = searchText ? searchText.split(/"([^"]*)"/).map(trim) : []; |
|
dpapad
2015/11/24 18:42:33
Is it worth adding tests for the regular expressio
Dan Beam
2015/11/25 04:06:36
Done.
| |
| 83 chrome.send('getDownloads', searchText.split(/"([^"]*)"/).map(trim)); | 89 |
| 90 chrome.send('getDownloads', terms); | |
| 84 }, | 91 }, |
| 85 | 92 |
| 86 /** | 93 /** |
| 87 * Shows the local folder a finished download resides in. | 94 * Shows the local folder a finished download resides in. |
| 88 * @param {string} id ID of the download to show. | 95 * @param {string} id ID of the download to show. |
| 89 */ | 96 */ |
| 90 show: chromeSendWithId('show'), | 97 show: chromeSendWithId('show'), |
| 91 | 98 |
| 92 /** Undo download removal. */ | 99 /** Undo download removal. */ |
| 93 undo: chrome.send.bind(chrome, 'undo'), | 100 undo: chrome.send.bind(chrome, 'undo'), |
| 94 }; | 101 }; |
| 95 | 102 |
| 96 cr.addSingletonGetter(ActionService); | 103 cr.addSingletonGetter(ActionService); |
| 97 | 104 |
| 98 return {ActionService: ActionService}; | 105 return {ActionService: ActionService}; |
| 99 }); | 106 }); |
| OLD | NEW |