| 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) { |
| 11 return function(id) { chrome.send(chromeSendName, [id]); }; | 11 return function(id) { chrome.send(chromeSendName, [id]); }; |
| 12 } | 12 } |
| 13 | 13 |
| 14 /** @constructor */ | 14 /** @constructor */ |
| 15 function ActionService() {} | 15 function ActionService() { |
| 16 /** @private {Array<string>} */ |
| 17 this.searchTerms_ = []; |
| 18 } |
| 16 | 19 |
| 17 /** | 20 /** |
| 18 * @param {string} s | 21 * @param {string} s |
| 19 * @return {string} |s| without whitespace at the beginning or end. | 22 * @return {string} |s| without whitespace at the beginning or end. |
| 20 */ | 23 */ |
| 21 function trim(s) { return s.trim(); } | 24 function trim(s) { return s.trim(); } |
| 22 | 25 |
| 23 /** | 26 /** |
| 24 * @param {string|undefined} value | 27 * @param {string|undefined} value |
| 25 * @return {boolean} Whether |value| is truthy. | 28 * @return {boolean} Whether |value| is truthy. |
| 26 */ | 29 */ |
| 27 function truthy(value) { return !!value; } | 30 function truthy(value) { return !!value; } |
| 28 | 31 |
| 29 /** | 32 /** |
| 30 * @param {string} searchText Input typed by the user into a search box. | 33 * @param {string} searchText Input typed by the user into a search box. |
| 31 * @return {Array<string>} A list of terms extracted from |searchText|. | 34 * @return {Array<string>} A list of terms extracted from |searchText|. |
| 32 */ | 35 */ |
| 33 ActionService.splitTerms = function(searchText) { | 36 ActionService.splitTerms = function(searchText) { |
| 34 // Split quoted terms (e.g., 'The "lazy" dog' => ['The', 'lazy', 'dog']). | 37 // Split quoted terms (e.g., 'The "lazy" dog' => ['The', 'lazy', 'dog']). |
| 35 return searchText.split(/"([^"]*)"/).map(trim).filter(truthy); | 38 return searchText.split(/"([^"]*)"/).map(trim).filter(truthy); |
| 36 }; | 39 }; |
| 37 | 40 |
| 38 ActionService.prototype = { | 41 ActionService.prototype = { |
| 39 /** @private {Array<string>} */ | |
| 40 searchTerms_: [], | |
| 41 | |
| 42 /** @param {string} id ID of the download to cancel. */ | 42 /** @param {string} id ID of the download to cancel. */ |
| 43 cancel: chromeSendWithId('cancel'), | 43 cancel: chromeSendWithId('cancel'), |
| 44 | 44 |
| 45 /** Instructs the browser to clear all finished downloads. */ | 45 /** Instructs the browser to clear all finished downloads. */ |
| 46 clearAll: function() { | 46 clearAll: function() { |
| 47 if (loadTimeData.getBoolean('allowDeletingHistory')) { | 47 if (loadTimeData.getBoolean('allowDeletingHistory')) { |
| 48 chrome.send('clearAll'); | 48 chrome.send('clearAll'); |
| 49 this.search(''); | 49 this.search(''); |
| 50 } | 50 } |
| 51 }, | 51 }, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 show: chromeSendWithId('show'), | 124 show: chromeSendWithId('show'), |
| 125 | 125 |
| 126 /** Undo download removal. */ | 126 /** Undo download removal. */ |
| 127 undo: chrome.send.bind(chrome, 'undo'), | 127 undo: chrome.send.bind(chrome, 'undo'), |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 cr.addSingletonGetter(ActionService); | 130 cr.addSingletonGetter(ActionService); |
| 131 | 131 |
| 132 return {ActionService: ActionService}; | 132 return {ActionService: ActionService}; |
| 133 }); | 133 }); |
| OLD | NEW |