Chromium Code Reviews| 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 20 matching lines...) Expand all Loading... | |
| 31 */ | 31 */ |
| 32 function annotateMetadata(metadata) { | 32 function annotateMetadata(metadata) { |
| 33 var result = { | 33 var result = { |
| 34 isDirectory: metadata.isDirectory, | 34 isDirectory: metadata.isDirectory, |
| 35 name: metadata.name, | 35 name: metadata.name, |
| 36 size: metadata.size, | 36 size: metadata.size, |
| 37 modificationTime: annotateDate(metadata.modificationTime) | 37 modificationTime: annotateDate(metadata.modificationTime) |
| 38 }; | 38 }; |
| 39 if ('mimeType' in metadata) | 39 if ('mimeType' in metadata) |
| 40 result.mimeType = metadata.mimeType; | 40 result.mimeType = metadata.mimeType; |
| 41 if ('thumbnail' in metadata) | |
| 42 result.thumbnail = metadata.thumbnail; | |
| 41 return result; | 43 return result; |
| 42 } | 44 } |
| 43 | 45 |
| 44 /** | 46 /** |
| 45 * Massages arguments of an event raised by the File System Provider API. | 47 * Massages arguments of an event raised by the File System Provider API. |
| 46 * @param {Array.<*>} args Input arguments. | 48 * @param {Array.<*>} args Input arguments. |
| 47 * @param {function(Array.<*>)} dispatch Closure to be called with massaged | 49 * @param {function(Array.<*>)} dispatch Closure to be called with massaged |
| 48 * arguments. | 50 * arguments. |
| 49 */ | 51 */ |
| 50 function massageArgumentsDefault(args, dispatch) { | 52 function massageArgumentsDefault(args, dispatch) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 eventBindings.registerArgumentMassager( | 136 eventBindings.registerArgumentMassager( |
| 135 'fileSystemProvider.onUnmountRequested', | 137 'fileSystemProvider.onUnmountRequested', |
| 136 massageArgumentsDefault); | 138 massageArgumentsDefault); |
| 137 | 139 |
| 138 eventBindings.registerArgumentMassager( | 140 eventBindings.registerArgumentMassager( |
| 139 'fileSystemProvider.onGetMetadataRequested', | 141 'fileSystemProvider.onGetMetadataRequested', |
| 140 function(args, dispatch) { | 142 function(args, dispatch) { |
| 141 var executionStart = Date.now(); | 143 var executionStart = Date.now(); |
| 142 var options = args[0]; | 144 var options = args[0]; |
| 143 var onSuccessCallback = function(metadata) { | 145 var onSuccessCallback = function(metadata) { |
| 146 // It is invalid to return a thumbnail when it's not requested. The | |
| 147 // restriction is added in order to avoid fetching the thumbnail while | |
| 148 // it's not needed. | |
| 149 if (!options.thumbnail && metadata.thumbnail) { | |
|
hirono
2014/08/27 09:20:08
How about checking format of thumbnail?
The string
mtomasz
2014/08/28 04:57:55
Good idea. If users passed something invalid (like
| |
| 150 fileSystemProviderInternal.operationRequestedError( | |
| 151 options.fileSystemId, options.requestId, 'FAILED', | |
| 152 Date.now() - executionStart); | |
| 153 throw new Error('Thumbnail data is provided, but not requested.'); | |
| 154 } | |
| 155 | |
| 144 fileSystemProviderInternal.getMetadataRequestedSuccess( | 156 fileSystemProviderInternal.getMetadataRequestedSuccess( |
| 145 options.fileSystemId, | 157 options.fileSystemId, |
| 146 options.requestId, | 158 options.requestId, |
| 147 annotateMetadata(metadata), | 159 annotateMetadata(metadata), |
| 148 Date.now() - executionStart); | 160 Date.now() - executionStart); |
| 149 }; | 161 }; |
| 150 var onErrorCallback = function(error) { | 162 var onErrorCallback = function(error) { |
| 151 fileSystemProviderInternal.operationRequestedError( | 163 fileSystemProviderInternal.operationRequestedError( |
| 152 options.fileSystemId, options.requestId, error, | 164 options.fileSystemId, options.requestId, error, |
| 153 Date.now() - executionStart); | 165 Date.now() - executionStart); |
| 154 } | 166 } |
| 155 dispatch([options, onSuccessCallback, onErrorCallback]); | 167 dispatch([options, onSuccessCallback, onErrorCallback]); |
| 156 }); | 168 }); |
| 157 | 169 |
| 158 eventBindings.registerArgumentMassager( | 170 eventBindings.registerArgumentMassager( |
| 159 'fileSystemProvider.onReadDirectoryRequested', | 171 'fileSystemProvider.onReadDirectoryRequested', |
| 160 function(args, dispatch) { | 172 function(args, dispatch) { |
| 161 var executionStart = Date.now(); | 173 var executionStart = Date.now(); |
| 162 var options = args[0]; | 174 var options = args[0]; |
| 163 var onSuccessCallback = function(entries, hasNext) { | 175 var onSuccessCallback = function(entries, hasNext) { |
| 164 var annotatedEntries = entries.map(annotateMetadata); | 176 var annotatedEntries = entries.map(annotateMetadata); |
| 177 // It is invalid to return a thumbnail when it's not requested. | |
| 178 annotatedEntries.forEach(function(metadata) { | |
| 179 if (metadata.thumbnail) { | |
| 180 fileSystemProviderInternal.operationRequestedError( | |
| 181 options.fileSystemId, options.requestId, 'FAILED', | |
| 182 Date.now() - executionStart); | |
| 183 throw new Error( | |
| 184 'Thumbnails must not be provided when reading a directory.'); | |
| 185 } | |
| 186 }); | |
| 165 fileSystemProviderInternal.readDirectoryRequestedSuccess( | 187 fileSystemProviderInternal.readDirectoryRequestedSuccess( |
| 166 options.fileSystemId, options.requestId, annotatedEntries, hasNext, | 188 options.fileSystemId, options.requestId, annotatedEntries, hasNext, |
| 167 Date.now() - executionStart); | 189 Date.now() - executionStart); |
| 168 }; | 190 }; |
| 169 var onErrorCallback = function(error) { | 191 var onErrorCallback = function(error) { |
| 170 fileSystemProviderInternal.operationRequestedError( | 192 fileSystemProviderInternal.operationRequestedError( |
| 171 options.fileSystemId, options.requestId, error, | 193 options.fileSystemId, options.requestId, error, |
| 172 Date.now() - executionStart); | 194 Date.now() - executionStart); |
| 173 } | 195 } |
| 174 dispatch([options, onSuccessCallback, onErrorCallback]); | 196 dispatch([options, onSuccessCallback, onErrorCallback]); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 | 248 |
| 227 eventBindings.registerArgumentMassager( | 249 eventBindings.registerArgumentMassager( |
| 228 'fileSystemProvider.onWriteFileRequested', | 250 'fileSystemProvider.onWriteFileRequested', |
| 229 massageArgumentsDefault); | 251 massageArgumentsDefault); |
| 230 | 252 |
| 231 eventBindings.registerArgumentMassager( | 253 eventBindings.registerArgumentMassager( |
| 232 'fileSystemProvider.onAbortRequested', | 254 'fileSystemProvider.onAbortRequested', |
| 233 massageArgumentsDefault); | 255 massageArgumentsDefault); |
| 234 | 256 |
| 235 exports.binding = binding.generate(); | 257 exports.binding = binding.generate(); |
| OLD | NEW |