• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2013 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 fileSystemProvider API.
6
7var binding = require('binding').Binding.create('fileSystemProvider');
8var fileSystemNatives = requireNative('file_system_natives');
9var GetDOMError = fileSystemNatives.GetDOMError;
10
11binding.registerCustomHook(function(bindingsAPI) {
12  var apiFunctions = bindingsAPI.apiFunctions;
13
14  apiFunctions.setUpdateArgumentsPostValidate(
15    'mount',
16    function(displayName, successCallback, errorCallback) {
17      // Piggyback the error callback onto the success callback,
18      // so we can use the error callback later.
19      successCallback.errorCallback_ = errorCallback;
20      return [displayName, successCallback];
21    });
22
23  apiFunctions.setCustomCallback(
24    'mount',
25    function(name, request, response) {
26      var fileSystemId = null;
27      var domError = null;
28      if (request.callback && response) {
29        fileSystemId = response[0];
30        // DOMError is present only if mount() failed.
31        if (response[1]) {
32          // Convert a Dictionary to a DOMError.
33          domError = GetDOMError(response[1].name, response[1].message);
34          response.length = 1;
35        }
36
37        var successCallback = request.callback;
38        var errorCallback = request.callback.errorCallback_;
39        delete request.callback;
40
41        if (domError)
42          errorCallback(domError);
43        else
44          successCallback(fileSystemId);
45      }
46    });
47});
48
49exports.binding = binding.generate();
50