Give names to all utility processes.
[chromium-blink-merge.git] / chrome / renderer / resources / extensions / file_manager_private_custom_bindings.js
blobed0856ec9e0ee9866ccf3e4a388d1ba9b69ace1d
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 fileManagerPrivate API.
7 // Bindings
8 var binding = require('binding').Binding.create('fileManagerPrivate');
9 var eventBindings = require('event_bindings');
11 // Natives
12 var fileManagerPrivateNatives = requireNative('file_manager_private');
13 var fileBrowserHandlerNatives = requireNative('file_browser_handler');
15 // Internals
16 var fileManagerPrivateInternal =
17 require('binding').Binding.create('fileManagerPrivateInternal').generate();
19 // Shorthands
20 var GetFileSystem = fileManagerPrivateNatives.GetFileSystem;
21 var GetExternalFileEntry = fileBrowserHandlerNatives.GetExternalFileEntry;
23 binding.registerCustomHook(function(bindingsAPI) {
24 var apiFunctions = bindingsAPI.apiFunctions;
26 apiFunctions.setCustomCallback('searchDrive',
27 function(name, request, callback, response) {
28 if (response && !response.error && response.entries) {
29 response.entries = response.entries.map(function(entry) {
30 return GetExternalFileEntry(entry);
31 });
34 // So |callback| doesn't break if response is not defined.
35 if (!response)
36 response = {};
38 if (callback)
39 callback(response.entries, response.nextFeed);
40 });
42 apiFunctions.setCustomCallback('searchDriveMetadata',
43 function(name, request, callback, response) {
44 if (response && !response.error) {
45 for (var i = 0; i < response.length; i++) {
46 response[i].entry =
47 GetExternalFileEntry(response[i].entry);
51 // So |callback| doesn't break if response is not defined.
52 if (!response)
53 response = {};
55 if (callback)
56 callback(response);
57 });
59 apiFunctions.setHandleRequest('resolveIsolatedEntries',
60 function(entries, callback) {
61 var urls = entries.map(function(entry) {
62 return fileBrowserHandlerNatives.GetEntryURL(entry);
63 });
64 fileManagerPrivateInternal.resolveIsolatedEntries(urls, function(
65 entryDescriptions) {
66 callback(entryDescriptions.map(function(description) {
67 return GetExternalFileEntry(description);
68 }));
69 });
70 });
71 });
73 eventBindings.registerArgumentMassager(
74 'fileManagerPrivate.onDirectoryChanged', function(args, dispatch) {
75 // Convert the entry arguments into a real Entry object.
76 args[0].entry = GetExternalFileEntry(args[0].entry);
77 dispatch(args);
78 });
80 exports.binding = binding.generate();