OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Custom bindings for the downloads API. |
| 6 |
| 7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
| 8 |
| 9 chromeHidden.Event.registerArgumentMassager( |
| 10 'downloads.onDeterminingFilename', |
| 11 function massage_determining_filename(args, dispatch) { |
| 12 var downloadItem = args[0]; |
| 13 // Copy the id so that extensions can't change it. |
| 14 var downloadId = downloadItem.id; |
| 15 var suggestable = true; |
| 16 function suggestCallback(result) { |
| 17 if (!suggestable) { |
| 18 console.error('suggestCallback may not be called more than once.'); |
| 19 return; |
| 20 } |
| 21 suggestable = false; |
| 22 if ((typeof(result) == 'object') && |
| 23 result.filename && |
| 24 (typeof(result.filename) == 'string') && |
| 25 ((result.overwrite === undefined) || |
| 26 (typeof(result.overwrite) == 'boolean'))) { |
| 27 chromeHidden.internalAPIs.downloadsInternal.determineFilename( |
| 28 downloadId, |
| 29 result.filename, |
| 30 result.overwrite || false); |
| 31 } else { |
| 32 chromeHidden.internalAPIs.downloadsInternal.determineFilename( |
| 33 downloadId); |
| 34 } |
| 35 } |
| 36 try { |
| 37 var results = dispatch([downloadItem, suggestCallback]); |
| 38 var async = (results && |
| 39 results.results && |
| 40 (results.results.length != 0) && |
| 41 (results.results[0] === true)); |
| 42 if (suggestable && !async) |
| 43 suggestCallback(); |
| 44 } catch (e) { |
| 45 suggestCallback(); |
| 46 throw e; |
| 47 } |
| 48 }); |
OLD | NEW |