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.
8 var binding = require('binding').Binding.create('fileManagerPrivate');
9 var eventBindings = require('event_bindings');
12 var fileManagerPrivateNatives = requireNative('file_manager_private');
13 var fileBrowserHandlerNatives = requireNative('file_browser_handler');
16 var fileManagerPrivateInternal =
17 require('binding').Binding.create('fileManagerPrivateInternal').generate();
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);
34 // So |callback| doesn't break if response is not defined.
39 callback(response.entries, response.nextFeed);
42 apiFunctions.setCustomCallback('searchDriveMetadata',
43 function(name, request, callback, response) {
44 if (response && !response.error) {
45 for (var i = 0; i < response.length; i++) {
47 GetExternalFileEntry(response[i].entry);
51 // So |callback| doesn't break if response is not defined.
59 apiFunctions.setHandleRequest('resolveIsolatedEntries',
60 function(entries, callback) {
61 var urls = entries.map(function(entry) {
62 return fileBrowserHandlerNatives.GetEntryURL(entry);
64 fileManagerPrivateInternal.resolveIsolatedEntries(urls, function(
66 callback(entryDescriptions.map(function(description) {
67 return GetExternalFileEntry(description);
72 apiFunctions.setHandleRequest('getEntryProperties',
73 function(entries, names, callback) {
74 var urls = entries.map(function(entry) {
75 return fileBrowserHandlerNatives.GetEntryURL(entry);
77 fileManagerPrivateInternal.getEntryProperties(urls, names, callback);
80 apiFunctions.setHandleRequest('addFileWatch', function(entry, callback) {
81 var url = fileBrowserHandlerNatives.GetEntryURL(entry);
82 fileManagerPrivateInternal.addFileWatch(url, callback);
85 apiFunctions.setHandleRequest('removeFileWatch', function(entry, callback) {
86 var url = fileBrowserHandlerNatives.GetEntryURL(entry);
87 fileManagerPrivateInternal.removeFileWatch(url, callback);
90 apiFunctions.setHandleRequest('getEntryActions', function(entry, callback) {
91 var url = fileBrowserHandlerNatives.GetEntryURL(entry);
92 fileManagerPrivateInternal.getEntryActions(url, callback);
95 apiFunctions.setHandleRequest('executeEntryAction', function(
96 entry, actionId, callback) {
97 var url = fileBrowserHandlerNatives.GetEntryURL(entry);
98 fileManagerPrivateInternal.executeEntryAction(url, actionId, callback);
101 apiFunctions.setHandleRequest('computeChecksum', function(entry, callback) {
102 var url = fileBrowserHandlerNatives.GetEntryURL(entry);
103 fileManagerPrivateInternal.computeChecksum(url, callback);
106 apiFunctions.setHandleRequest('getMimeType', function(entry, callback) {
107 var url = fileBrowserHandlerNatives.GetEntryURL(entry);
108 fileManagerPrivateInternal.getMimeType(url, callback);
111 apiFunctions.setHandleRequest('pinDriveFile', function(entry, pin, callback) {
112 var url = fileBrowserHandlerNatives.GetEntryURL(entry);
113 fileManagerPrivateInternal.pinDriveFile(url, pin, callback);
116 apiFunctions.setHandleRequest('executeTask',
117 function(taskId, entries, callback) {
118 var urls = entries.map(function(entry) {
119 return fileBrowserHandlerNatives.GetEntryURL(entry);
121 fileManagerPrivateInternal.executeTask(taskId, urls, callback);
124 apiFunctions.setHandleRequest('setDefaultTask',
125 function(taskId, entries, mimeTypes, callback) {
126 var urls = entries.map(function(entry) {
127 return fileBrowserHandlerNatives.GetEntryURL(entry);
129 fileManagerPrivateInternal.setDefaultTask(
130 taskId, urls, mimeTypes, callback);
133 apiFunctions.setHandleRequest('getFileTasks', function(entries, callback) {
134 var urls = entries.map(function(entry) {
135 return fileBrowserHandlerNatives.GetEntryURL(entry);
137 fileManagerPrivateInternal.getFileTasks(urls, callback);
140 apiFunctions.setHandleRequest('getShareUrl', function(entry, callback) {
141 var url = fileBrowserHandlerNatives.GetEntryURL(entry);
142 fileManagerPrivateInternal.getShareUrl(url, callback);
145 apiFunctions.setHandleRequest('getDownloadUrl', function(entry, callback) {
146 var url = fileBrowserHandlerNatives.GetEntryURL(entry);
147 fileManagerPrivateInternal.getDownloadUrl(url, callback);
150 apiFunctions.setHandleRequest('requestDriveShare', function(
151 entry, shareType, callback) {
152 var url = fileBrowserHandlerNatives.GetEntryURL(entry);
153 fileManagerPrivateInternal.requestDriveShare(url, shareType, callback);
156 apiFunctions.setHandleRequest('setEntryTag', function(
157 entry, visibility, key, value, callback) {
158 var url = fileBrowserHandlerNatives.GetEntryURL(entry);
159 fileManagerPrivateInternal.setEntryTag(
160 url, visibility, key, value, callback);
163 apiFunctions.setHandleRequest('cancelFileTransfers', function(
165 var urls = entries.map(function(entry) {
166 return fileBrowserHandlerNatives.cancelFileTransfers(entry);
168 fileManagerPrivateInternal.cancelFileTransfers(urls, callback);
171 apiFunctions.setHandleRequest('startCopy', function(
172 entry, parentEntry, newName, callback) {
173 var url = fileBrowserHandlerNatives.GetEntryURL(entry);
174 var parentUrl = fileBrowserHandlerNatives.GetEntryURL(parentEntry);
175 fileManagerPrivateInternal.startCopy(
176 url, parentUrl, newName, callback);
179 apiFunctions.setHandleRequest('zipSelection', function(
180 parentEntry, entries, destName, callback) {
181 var parentUrl = fileBrowserHandlerNatives.GetEntryURL(parentEntry);
182 var urls = entries.map(function(entry) {
183 return fileBrowserHandlerNatives.cancelFileTransfers(entry);
185 fileManagerPrivateInternal.zipSelection(
186 parentUrl, urls, destName, callback);
189 apiFunctions.setHandleRequest('validatePathNameLength', function(
190 entry, name, callback) {
191 var url = fileBrowserHandlerNatives.GetEntryURL(entry);
192 fileManagerPrivateInternal.validatePathNameLength(url, name, callback);
196 eventBindings.registerArgumentMassager(
197 'fileManagerPrivate.onDirectoryChanged', function(args, dispatch) {
198 // Convert the entry arguments into a real Entry object.
199 args[0].entry = GetExternalFileEntry(args[0].entry);
203 exports.binding = binding.generate();