1 // Copyright (c) 2012 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.
5 // Custom binding for the fileBrowserHandler API.
7 var binding
= require('binding').Binding
.create('fileBrowserHandler');
9 var eventBindings
= require('event_bindings');
10 var fileBrowserNatives
= requireNative('file_browser_handler');
11 var GetExternalFileEntry
= fileBrowserNatives
.GetExternalFileEntry
;
12 var fileBrowserHandlerInternal
= require('binding').Binding
.create(
13 'fileBrowserHandlerInternal').generate();
15 eventBindings
.registerArgumentMassager('fileBrowserHandler.onExecute',
16 function(args
, dispatch
) {
17 if (args
.length
< 2) {
21 var fileList
= args
[1].entries
;
26 // The second parameter for this event's payload is file definition
27 // dictionary that we used to reconstruct File API's Entry instance
29 for (var i
= 0; i
< fileList
.length
; i
++)
30 fileList
[i
] = GetExternalFileEntry(fileList
[i
]);
34 binding
.registerCustomHook(function(bindingsAPI
) {
35 var apiFunctions
= bindingsAPI
.apiFunctions
;
37 apiFunctions
.setHandleRequest('selectFile',
38 function(selectionParams
, callback
) {
39 function internalCallback(externalCallback
, internalResult
) {
40 if (!externalCallback
)
42 var result
= undefined;
44 result
= { success
: internalResult
.success
, entry
: null };
45 if (internalResult
.success
)
46 result
.entry
= GetExternalFileEntry(internalResult
.entry
);
49 externalCallback(result
);
52 return fileBrowserHandlerInternal
.selectFile(
53 selectionParams
, $Function
.bind(internalCallback
, null, callback
));
57 exports
.binding
= binding
.generate();