• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5// Custom binding for the fileBrowserPrivate API.
6
7var binding = require('binding').Binding.create('fileBrowserPrivate');
8
9var eventBindings = require('event_bindings');
10var fileBrowserPrivateNatives = requireNative('file_browser_private');
11var GetFileSystem = fileBrowserPrivateNatives.GetFileSystem;
12
13var fileBrowserNatives = requireNative('file_browser_handler');
14var GetExternalFileEntry = fileBrowserNatives.GetExternalFileEntry;
15
16binding.registerCustomHook(function(bindingsAPI) {
17  var apiFunctions = bindingsAPI.apiFunctions;
18
19  apiFunctions.setCustomCallback('requestFileSystem',
20                                 function(name, request, response) {
21    var fs = null;
22    if (response && !response.error)
23      fs = GetFileSystem(response.name, response.root_url);
24    if (request.callback)
25      request.callback(fs);
26    request.callback = null;
27  });
28
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);
34      });
35    }
36
37    // So |request.callback| doesn't break if response is not defined.
38    if (!response)
39      response = {};
40
41    if (request.callback)
42      request.callback(response.entries, response.nextFeed);
43    request.callback = null;
44  });
45
46  apiFunctions.setCustomCallback('searchDriveMetadata',
47                                 function(name, request, response) {
48    if (response && !response.error) {
49      for (var i = 0; i < response.length; i++) {
50        response[i].entry =
51            GetExternalFileEntry(response[i].entry);
52      }
53    }
54
55    // So |request.callback| doesn't break if response is not defined.
56    if (!response)
57      response = {};
58
59    if (request.callback)
60      request.callback(response);
61    request.callback = null;
62  });
63});
64
65eventBindings.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);
69  dispatch(args);
70});
71
72exports.binding = binding.generate();
73