Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / renderer / resources / extensions / file_browser_private_custom_bindings.js
blob2951e01ff31cb1a5dc1d2a439c5693c342832a58
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) {
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   });
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     }
37     // So |request.callback| doesn't break if response is not defined.
38     if (!response)
39       response = {};
41     if (request.callback)
42       request.callback(response.entries, response.nextFeed);
43     request.callback = null;
44   });
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     }
55     // So |request.callback| doesn't break if response is not defined.
56     if (!response)
57       response = {};
59     if (request.callback)
60       request.callback(response);
61     request.callback = null;
62   });
63 });
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);
69   dispatch(args);
70 });
72 exports.binding = binding.generate();