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

Side by Side Diff: chrome/renderer/resources/extensions/downloads_custom_bindings.js

Issue 16924017: A few minor changes to the chrome.downloads extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r213855 Created 7 years, 5 months 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 | Annotate | Revision Log
OLDNEW
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'))) {
asanka 2013/07/26 15:47:22 Shouldn't it be an error if the conflict action is
benjhayden 2013/07/26 19:56:25 suggest doesn't take a callback to set runtime.las
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();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698