| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 // Custom bindings for the downloads API. | 5 // Custom bindings for the downloads API. |
| 6 | 6 |
| 7 var binding = require('binding').Binding.create('downloads'); | 7 var binding = require('binding').Binding.create('downloads'); |
| 8 var downloadsInternal = require('binding').Binding.create( | 8 var downloadsInternal = require('binding').Binding.create( |
| 9 'downloadsInternal').generate(); | 9 'downloadsInternal').generate(); |
| 10 var eventBindings = require('event_bindings'); | 10 var eventBindings = require('event_bindings'); |
| 11 | 11 |
| 12 eventBindings.registerArgumentMassager( | 12 eventBindings.registerArgumentMassager( |
| 13 'downloads.onDeterminingFilename', | 13 'downloads.onDeterminingFilename', |
| 14 function massage_determining_filename(args, dispatch) { | 14 function massage_determining_filename(args, dispatch) { |
| 15 var downloadItem = args[0]; | 15 var downloadItem = args[0]; |
| 16 // Copy the id so that extensions can't change it. | 16 // Copy the id so that extensions can't change it. |
| 17 var downloadId = downloadItem.id; | 17 var downloadId = downloadItem.id; |
| 18 var suggestable = true; | 18 var suggestable = true; |
| 19 function suggestCallback(result) { | 19 function suggestCallback(result) { |
| 20 if (!suggestable) { | 20 if (!suggestable) { |
| 21 console.error('suggestCallback may not be called more than once.'); | 21 console.error('suggestCallback may not be called more than once.'); |
| 22 return; | 22 return; |
| 23 } | 23 } |
| 24 suggestable = false; | 24 suggestable = false; |
| 25 if ((typeof(result) == 'object') && | 25 if ((typeof(result) == 'object') && |
| 26 result.filename && | 26 result.filename && |
| 27 (typeof(result.filename) == 'string') && | 27 (typeof(result.filename) == 'string') && |
| 28 ((result.conflict_action == undefined) || | 28 ((result.conflictAction == undefined) || |
| 29 (typeof(result.conflict_action) == 'string'))) { | 29 (typeof(result.conflictAction) == 'string'))) { |
| 30 downloadsInternal.determineFilename( | 30 downloadsInternal.determineFilename( |
| 31 downloadId, result.filename, result.conflict_action || ""); | 31 downloadId, result.filename, result.conflictAction || ""); |
| 32 } else { | 32 } else { |
| 33 downloadsInternal.determineFilename(downloadId, "", ""); | 33 downloadsInternal.determineFilename(downloadId, "", ""); |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 try { | 36 try { |
| 37 var results = dispatch([downloadItem, suggestCallback]); | 37 var results = dispatch([downloadItem, suggestCallback]); |
| 38 var async = (results && | 38 var async = (results && |
| 39 results.results && | 39 results.results && |
| 40 (results.results.length != 0) && | 40 (results.results.length != 0) && |
| 41 (results.results[0] === true)); | 41 (results.results[0] === true)); |
| 42 if (suggestable && !async) | 42 if (suggestable && !async) |
| 43 suggestCallback(); | 43 suggestCallback(); |
| 44 } catch (e) { | 44 } catch (e) { |
| 45 suggestCallback(); | 45 suggestCallback(); |
| 46 throw e; | 46 throw e; |
| 47 } | 47 } |
| 48 }); | 48 }); |
| 49 exports.binding = binding.generate(); | 49 exports.binding = binding.generate(); |
| OLD | NEW |