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 fileBrowserPrivate API.
7 var binding
= require('binding').Binding
.create('fileBrowserPrivate');
9 var eventBindings
= require('event_bindings');
10 var fileBrowserPrivateNatives
= requireNative('file_browser_private');
11 var GetFileSystem
= fileBrowserPrivateNatives
.GetFileSystem
;
13 var fileBrowserNatives
= requireNative('file_browser_handler');
14 var GetExternalFileEntry
= fileBrowserNatives
.GetExternalFileEntry
;
16 binding
.registerCustomHook(function(bindingsAPI
) {
17 var apiFunctions
= bindingsAPI
.apiFunctions
;
19 apiFunctions
.setCustomCallback('requestFileSystem',
20 function(name
, request
, response
) {
22 if (response
&& !response
.error
)
23 fs
= GetFileSystem(response
.name
, response
.root_url
);
26 request
.callback
= null;
29 apiFunctions
.setCustomCallback('searchDrive',
30 function(name
, request
, response
) {
31 if (response
&& !response
.error
&& response
.entries
) {
32 response
.entries
= response
.entries
.map(function(entry
) {
33 return GetExternalFileEntry(entry
);
37 // So |request.callback| doesn't break if response is not defined.
42 request
.callback(response
.entries
, response
.nextFeed
);
43 request
.callback
= null;
46 apiFunctions
.setCustomCallback('searchDriveMetadata',
47 function(name
, request
, response
) {
48 if (response
&& !response
.error
) {
49 for (var i
= 0; i
< response
.length
; i
++) {
51 GetExternalFileEntry(response
[i
].entry
);
55 // So |request.callback| doesn't break if response is not defined.
60 request
.callback(response
);
61 request
.callback
= null;
65 eventBindings
.registerArgumentMassager(
66 'fileBrowserPrivate.onDirectoryChanged', function(args
, dispatch
) {
67 // Convert the entry arguments into a real Entry object.
68 args
[0].entry
= GetExternalFileEntry(args
[0].entry
);
72 exports
.binding
= binding
.generate();