OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 fileSystemProvider API. | 5 // Custom binding for the fileSystemProvider API. |
6 | 6 |
7 var binding = require('binding').Binding.create('fileSystemProvider'); | 7 var binding = require('binding').Binding.create('fileSystemProvider'); |
8 var fileSystemProviderInternal = | 8 var fileSystemProviderInternal = |
9 require('binding').Binding.create('fileSystemProviderInternal').generate(); | 9 require('binding').Binding.create('fileSystemProviderInternal').generate(); |
10 var eventBindings = require('event_bindings'); | 10 var eventBindings = require('event_bindings'); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 /** | 53 /** |
54 * Annotates an entry metadata by serializing its modifiedTime value. | 54 * Annotates an entry metadata by serializing its modifiedTime value. |
55 * @param {EntryMetadata} metadata Input metadata. | 55 * @param {EntryMetadata} metadata Input metadata. |
56 * @return {EntryMetadata} metadata Annotated metadata, which can be passed | 56 * @return {EntryMetadata} metadata Annotated metadata, which can be passed |
57 * back to the C++ layer. | 57 * back to the C++ layer. |
58 */ | 58 */ |
59 function annotateMetadata(metadata) { | 59 function annotateMetadata(metadata) { |
60 var result = { | 60 var result = { |
61 isDirectory: metadata.isDirectory, | 61 isDirectory: metadata.isDirectory, |
62 name: metadata.name, | 62 name: metadata.name, |
63 size: metadata.size, | |
64 modificationTime: annotateDate(metadata.modificationTime) | |
65 }; | 63 }; |
66 if ('mimeType' in metadata) | 64 if (metadata.size !== undefined) |
| 65 result.size = metadata.size; |
| 66 if (metadata.modificationTime !== undefined) |
| 67 result.modificationTime = annotateDate(metadata.modificationTime); |
| 68 if (metadata.mimeType !== undefined) |
67 result.mimeType = metadata.mimeType; | 69 result.mimeType = metadata.mimeType; |
68 if ('thumbnail' in metadata) | 70 if (metadata.thumbnail !== undefined) |
69 result.thumbnail = metadata.thumbnail; | 71 result.thumbnail = metadata.thumbnail; |
70 return result; | 72 return result; |
71 } | 73 } |
72 | 74 |
73 /** | 75 /** |
74 * Massages arguments of an event raised by the File System Provider API. | 76 * Massages arguments of an event raised by the File System Provider API. |
75 * @param {Array<*>} args Input arguments. | 77 * @param {Array<*>} args Input arguments. |
76 * @param {function(Array<*>)} dispatch Closure to be called with massaged | 78 * @param {function(Array<*>)} dispatch Closure to be called with massaged |
77 * arguments. | 79 * arguments. |
78 */ | 80 */ |
(...skipping 16 matching lines...) Expand all Loading... |
95 'fileSystemProvider.onUnmountRequested', | 97 'fileSystemProvider.onUnmountRequested', |
96 massageArgumentsDefault); | 98 massageArgumentsDefault); |
97 | 99 |
98 eventBindings.registerArgumentMassager( | 100 eventBindings.registerArgumentMassager( |
99 'fileSystemProvider.onGetMetadataRequested', | 101 'fileSystemProvider.onGetMetadataRequested', |
100 function(args, dispatch) { | 102 function(args, dispatch) { |
101 var executionStart = Date.now(); | 103 var executionStart = Date.now(); |
102 var options = args[0]; | 104 var options = args[0]; |
103 var onSuccessCallback = function(metadata) { | 105 var onSuccessCallback = function(metadata) { |
104 var error; | 106 var error; |
| 107 // TODO(mtomasz): Remove the following two fields once crbug.com/413161 |
| 108 // is landed. |
| 109 if (options.size !== undefined) |
| 110 error = 'Size is required for this event.'; |
| 111 if (options.modificationTime !== undefined) |
| 112 error = 'Last modified time is required for this event.'; |
| 113 |
105 // It is invalid to return a thumbnail when it's not requested. The | 114 // It is invalid to return a thumbnail when it's not requested. The |
106 // restriction is added in order to avoid fetching the thumbnail while | 115 // restriction is added in order to avoid fetching the thumbnail while |
107 // it's not needed. | 116 // it's not needed. |
108 if (!options.thumbnail && metadata.thumbnail) | 117 if (!options.thumbnail && metadata.thumbnail) |
109 error = 'Thumbnail data provided, but not requested.'; | 118 error = 'Thumbnail data provided, but not requested.'; |
110 | 119 |
111 // Check the format and size. Note, that in the C++ layer, there is | 120 // Check the format and size. Note, that in the C++ layer, there is |
112 // another sanity check to avoid passing any evil URL. | 121 // another sanity check to avoid passing any evil URL. |
113 if ('thumbnail' in metadata && !verifyImageURI(metadata.thumbnail)) | 122 if ('thumbnail' in metadata && !verifyImageURI(metadata.thumbnail)) |
114 error = 'Thumbnail format invalid.'; | 123 error = 'Thumbnail format invalid.'; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 var onSuccessCallback = function() { | 299 var onSuccessCallback = function() { |
291 // TODO(mtomasz): To be implemented. | 300 // TODO(mtomasz): To be implemented. |
292 }; | 301 }; |
293 var onErrorCallback = function(error) { | 302 var onErrorCallback = function(error) { |
294 // TODO(mtomasz): To be implemented. | 303 // TODO(mtomasz): To be implemented. |
295 } | 304 } |
296 dispatch([onSuccessCallback, onErrorCallback]); | 305 dispatch([onSuccessCallback, onErrorCallback]); |
297 }); | 306 }); |
298 | 307 |
299 exports.binding = binding.generate(); | 308 exports.binding = binding.generate(); |
OLD | NEW |