Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/renderer/resources/extensions/sync_file_system_custom_bindings.js

Issue 2297043002: Web expose FileSystemFileEntry, FileSystemDirectoryEntry and friends (Closed)
Patch Set: Rebased Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Custom binding for the syncFileSystem API. 5 // Custom binding for the syncFileSystem API.
6 6
7 var binding = require('binding').Binding.create('syncFileSystem'); 7 var binding = require('binding').Binding.create('syncFileSystem');
8 8
9 var eventBindings = require('event_bindings'); 9 var eventBindings = require('event_bindings');
10 var fileSystemNatives = requireNative('file_system_natives'); 10 var fileSystemNatives = requireNative('file_system_natives');
11 var syncFileSystemNatives = requireNative('sync_file_system'); 11 var syncFileSystemNatives = requireNative('sync_file_system');
12 12
13 binding.registerCustomHook(function(bindingsAPI) { 13 binding.registerCustomHook(function(bindingsAPI) {
14 var apiFunctions = bindingsAPI.apiFunctions; 14 var apiFunctions = bindingsAPI.apiFunctions;
15 15
16 // Functions which take in an [instanceOf=FileEntry]. 16 // Functions which take in an [instanceOf=FileSystemFileEntry].
17 function bindFileEntryFunction(functionName) { 17 function bindFileEntryFunction(functionName) {
18 apiFunctions.setUpdateArgumentsPostValidate( 18 apiFunctions.setUpdateArgumentsPostValidate(
19 functionName, function(entry, callback) { 19 functionName, function(entry, callback) {
20 var fileSystemUrl = entry.toURL(); 20 var fileSystemUrl = entry.toURL();
21 return [fileSystemUrl, callback]; 21 return [fileSystemUrl, callback];
22 }); 22 });
23 } 23 }
24 $Array.forEach(['getFileStatus'], bindFileEntryFunction); 24 $Array.forEach(['getFileStatus'], bindFileEntryFunction);
25 25
26 // Functions which take in a FileEntry array. 26 // Functions which take in a FileSystemFileEntry array.
27 function bindFileEntryArrayFunction(functionName) { 27 function bindFileEntryArrayFunction(functionName) {
28 apiFunctions.setUpdateArgumentsPostValidate( 28 apiFunctions.setUpdateArgumentsPostValidate(
29 functionName, function(entries, callback) { 29 functionName, function(entries, callback) {
30 var fileSystemUrlArray = []; 30 var fileSystemUrlArray = [];
31 for (var i=0; i < entries.length; i++) { 31 for (var i=0; i < entries.length; i++) {
32 $Array.push(fileSystemUrlArray, entries[i].toURL()); 32 $Array.push(fileSystemUrlArray, entries[i].toURL());
33 } 33 }
34 return [fileSystemUrlArray, callback]; 34 return [fileSystemUrlArray, callback];
35 }); 35 });
36 } 36 }
37 $Array.forEach(['getFileStatuses'], bindFileEntryArrayFunction); 37 $Array.forEach(['getFileStatuses'], bindFileEntryArrayFunction);
38 38
39 // Functions which take in an [instanceOf=DOMFileSystem]. 39 // Functions which take in an [instanceOf=FileSystem].
40 function bindFileSystemFunction(functionName) { 40 function bindFileSystemFunction(functionName) {
41 apiFunctions.setUpdateArgumentsPostValidate( 41 apiFunctions.setUpdateArgumentsPostValidate(
42 functionName, function(filesystem, callback) { 42 functionName, function(filesystem, callback) {
43 var fileSystemUrl = filesystem.root.toURL(); 43 var fileSystemUrl = filesystem.root.toURL();
44 return [fileSystemUrl, callback]; 44 return [fileSystemUrl, callback];
45 }); 45 });
46 } 46 }
47 $Array.forEach(['getUsageAndQuota'], bindFileSystemFunction); 47 $Array.forEach(['getUsageAndQuota'], bindFileSystemFunction);
48 48
49 // Functions which return an [instanceOf=DOMFileSystem]. 49 // Functions which return an [instanceOf=FileSystem].
50 apiFunctions.setCustomCallback('requestFileSystem', 50 apiFunctions.setCustomCallback('requestFileSystem',
51 function(name, request, callback, response) { 51 function(name, request, callback, response) {
52 var result = null; 52 var result = null;
53 if (response) { 53 if (response) {
54 result = syncFileSystemNatives.GetSyncFileSystemObject( 54 result = syncFileSystemNatives.GetSyncFileSystemObject(
55 response.name, response.root); 55 response.name, response.root);
56 } 56 }
57 if (callback) 57 if (callback)
58 callback(result); 58 callback(result);
59 }); 59 });
60 60
61 // Functions which return an array of FileStatusInfo object 61 // Functions which return an array of FileStatusInfo object
62 // which has [instanceOf=FileEntry]. 62 // which has [instanceOf=FileSystemFileEntry].
63 apiFunctions.setCustomCallback('getFileStatuses', 63 apiFunctions.setCustomCallback('getFileStatuses',
64 function(name, request, callback, response) { 64 function(name, request, callback, response) {
65 var results = []; 65 var results = [];
66 if (response) { 66 if (response) {
67 for (var i = 0; i < response.length; i++) { 67 for (var i = 0; i < response.length; i++) {
68 var result = {}; 68 var result = {};
69 var entry = response[i].entry; 69 var entry = response[i].entry;
70 result.fileEntry = fileSystemNatives.GetFileEntry( 70 result.fileEntry = fileSystemNatives.GetFileEntry(
71 entry.fileSystemType, 71 entry.fileSystemType,
72 entry.fileSystemName, 72 entry.fileSystemName,
73 entry.rootUrl, 73 entry.rootUrl,
74 entry.filePath, 74 entry.filePath,
75 entry.isDirectory); 75 entry.isDirectory);
76 result.status = response[i].status; 76 result.status = response[i].status;
77 result.error = response[i].error; 77 result.error = response[i].error;
78 $Array.push(results, result); 78 $Array.push(results, result);
79 } 79 }
80 } 80 }
81 if (callback) 81 if (callback)
82 callback(results); 82 callback(results);
83 }); 83 });
84 }); 84 });
85 85
86 eventBindings.registerArgumentMassager( 86 eventBindings.registerArgumentMassager(
87 'syncFileSystem.onFileStatusChanged', function(args, dispatch) { 87 'syncFileSystem.onFileStatusChanged', function(args, dispatch) {
88 // Make FileEntry object using all the base string fields. 88 // Make FileSystemFileEntry object using all the base string fields.
89 var fileEntry = fileSystemNatives.GetFileEntry( 89 var fileEntry = fileSystemNatives.GetFileEntry(
90 args[0].fileSystemType, 90 args[0].fileSystemType,
91 args[0].fileSystemName, 91 args[0].fileSystemName,
92 args[0].rootUrl, 92 args[0].rootUrl,
93 args[0].filePath, 93 args[0].filePath,
94 args[0].isDirectory); 94 args[0].isDirectory);
95 95
96 // Combine into a single dictionary. 96 // Combine into a single dictionary.
97 var fileInfo = new Object(); 97 var fileInfo = new Object();
98 fileInfo.fileEntry = fileEntry; 98 fileInfo.fileEntry = fileEntry;
99 fileInfo.status = args[1]; 99 fileInfo.status = args[1];
100 if (fileInfo.status == "synced") { 100 if (fileInfo.status == "synced") {
101 fileInfo.action = args[2]; 101 fileInfo.action = args[2];
102 fileInfo.direction = args[3]; 102 fileInfo.direction = args[3];
103 } 103 }
104 dispatch([fileInfo]); 104 dispatch([fileInfo]);
105 }); 105 });
106 106
107 exports.$set('binding', binding.generate()); 107 exports.$set('binding', binding.generate());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698