| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 eventBindings.registerArgumentMassager( | 165 eventBindings.registerArgumentMassager( |
| 166 'fileSystemProvider.onUnmountRequested', | 166 'fileSystemProvider.onUnmountRequested', |
| 167 massageArgumentsDefault); | 167 massageArgumentsDefault); |
| 168 | 168 |
| 169 eventBindings.registerArgumentMassager( | 169 eventBindings.registerArgumentMassager( |
| 170 'fileSystemProvider.onGetMetadataRequested', | 170 'fileSystemProvider.onGetMetadataRequested', |
| 171 function(args, dispatch) { | 171 function(args, dispatch) { |
| 172 var executionStart = Date.now(); | 172 var executionStart = Date.now(); |
| 173 var options = args[0]; | 173 var options = args[0]; |
| 174 var onSuccessCallback = function(metadata) { | 174 var onSuccessCallback = function(metadata) { |
| 175 var error; |
| 175 // It is invalid to return a thumbnail when it's not requested. The | 176 // It is invalid to return a thumbnail when it's not requested. The |
| 176 // restriction is added in order to avoid fetching the thumbnail while | 177 // restriction is added in order to avoid fetching the thumbnail while |
| 177 // it's not needed. | 178 // it's not needed. |
| 178 if (!options.thumbnail && metadata.thumbnail) { | 179 if (!options.thumbnail && metadata.thumbnail) |
| 179 fileSystemProviderInternal.operationRequestedError( | 180 error = 'Thumbnail data provided, but not requested.'; |
| 180 options.fileSystemId, options.requestId, 'FAILED', | |
| 181 Date.now() - executionStart); | |
| 182 throw new Error('Thumbnail data provided, but not requested.'); | |
| 183 } | |
| 184 | 181 |
| 185 // Check the format and size. Note, that in the C++ layer, there is | 182 // Check the format and size. Note, that in the C++ layer, there is |
| 186 // another sanity check to avoid passing any evil URL. | 183 // another sanity check to avoid passing any evil URL. |
| 187 if ('thumbnail' in metadata && !verifyImageURI(metadata.thumbnail)) | 184 if ('thumbnail' in metadata && !verifyImageURI(metadata.thumbnail)) |
| 188 throw new Error('Thumbnail format invalid.'); | 185 error = 'Thumbnail format invalid.'; |
| 186 |
| 189 if ('thumbnail' in metadata && | 187 if ('thumbnail' in metadata && |
| 190 metadata.thumbnail.length > METADATA_THUMBNAIL_SIZE_LIMIT) { | 188 metadata.thumbnail.length > METADATA_THUMBNAIL_SIZE_LIMIT) { |
| 191 throw new Error('Thumbnail data too large.'); | 189 error = 'Thumbnail data too large.'; |
| 190 } |
| 191 |
| 192 if (error) { |
| 193 console.error(error); |
| 194 fileSystemProviderInternal.operationRequestedError( |
| 195 options.fileSystemId, options.requestId, 'FAILED', |
| 196 Date.now() - executionStart); |
| 197 return; |
| 192 } | 198 } |
| 193 | 199 |
| 194 fileSystemProviderInternal.getMetadataRequestedSuccess( | 200 fileSystemProviderInternal.getMetadataRequestedSuccess( |
| 195 options.fileSystemId, | 201 options.fileSystemId, |
| 196 options.requestId, | 202 options.requestId, |
| 197 annotateMetadata(metadata), | 203 annotateMetadata(metadata), |
| 198 Date.now() - executionStart); | 204 Date.now() - executionStart); |
| 199 }; | 205 }; |
| 206 |
| 200 var onErrorCallback = function(error) { | 207 var onErrorCallback = function(error) { |
| 201 fileSystemProviderInternal.operationRequestedError( | 208 fileSystemProviderInternal.operationRequestedError( |
| 202 options.fileSystemId, options.requestId, error, | 209 options.fileSystemId, options.requestId, error, |
| 203 Date.now() - executionStart); | 210 Date.now() - executionStart); |
| 204 } | 211 } |
| 212 |
| 205 dispatch([options, onSuccessCallback, onErrorCallback]); | 213 dispatch([options, onSuccessCallback, onErrorCallback]); |
| 206 }); | 214 }); |
| 207 | 215 |
| 208 eventBindings.registerArgumentMassager( | 216 eventBindings.registerArgumentMassager( |
| 209 'fileSystemProvider.onReadDirectoryRequested', | 217 'fileSystemProvider.onReadDirectoryRequested', |
| 210 function(args, dispatch) { | 218 function(args, dispatch) { |
| 211 var executionStart = Date.now(); | 219 var executionStart = Date.now(); |
| 212 var options = args[0]; | 220 var options = args[0]; |
| 213 var onSuccessCallback = function(entries, hasNext) { | 221 var onSuccessCallback = function(entries, hasNext) { |
| 214 var annotatedEntries = entries.map(annotateMetadata); | 222 var annotatedEntries = entries.map(annotateMetadata); |
| 215 // It is invalid to return a thumbnail when it's not requested. | 223 // It is invalid to return a thumbnail when it's not requested. |
| 224 var error; |
| 216 annotatedEntries.forEach(function(metadata) { | 225 annotatedEntries.forEach(function(metadata) { |
| 217 if (metadata.thumbnail) { | 226 if (metadata.thumbnail) { |
| 218 fileSystemProviderInternal.operationRequestedError( | 227 var error = |
| 219 options.fileSystemId, options.requestId, 'FAILED', | 228 'Thumbnails must not be provided when reading a directory.'; |
| 220 Date.now() - executionStart); | 229 return; |
| 221 throw new Error( | |
| 222 'Thumbnails must not be provided when reading a directory.'); | |
| 223 } | 230 } |
| 224 }); | 231 }); |
| 232 |
| 233 if (error) { |
| 234 console.error(error); |
| 235 fileSystemProviderInternal.operationRequestedError( |
| 236 options.fileSystemId, options.requestId, 'FAILED', |
| 237 Date.now() - executionStart); |
| 238 return; |
| 239 } |
| 240 |
| 225 fileSystemProviderInternal.readDirectoryRequestedSuccess( | 241 fileSystemProviderInternal.readDirectoryRequestedSuccess( |
| 226 options.fileSystemId, options.requestId, annotatedEntries, hasNext, | 242 options.fileSystemId, options.requestId, annotatedEntries, hasNext, |
| 227 Date.now() - executionStart); | 243 Date.now() - executionStart); |
| 228 }; | 244 }; |
| 245 |
| 229 var onErrorCallback = function(error) { | 246 var onErrorCallback = function(error) { |
| 230 fileSystemProviderInternal.operationRequestedError( | 247 fileSystemProviderInternal.operationRequestedError( |
| 231 options.fileSystemId, options.requestId, error, | 248 options.fileSystemId, options.requestId, error, |
| 232 Date.now() - executionStart); | 249 Date.now() - executionStart); |
| 233 } | 250 } |
| 234 dispatch([options, onSuccessCallback, onErrorCallback]); | 251 dispatch([options, onSuccessCallback, onErrorCallback]); |
| 235 }); | 252 }); |
| 236 | 253 |
| 237 eventBindings.registerArgumentMassager( | 254 eventBindings.registerArgumentMassager( |
| 238 'fileSystemProvider.onOpenFileRequested', | 255 'fileSystemProvider.onOpenFileRequested', |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 | 303 |
| 287 eventBindings.registerArgumentMassager( | 304 eventBindings.registerArgumentMassager( |
| 288 'fileSystemProvider.onWriteFileRequested', | 305 'fileSystemProvider.onWriteFileRequested', |
| 289 massageArgumentsDefault); | 306 massageArgumentsDefault); |
| 290 | 307 |
| 291 eventBindings.registerArgumentMassager( | 308 eventBindings.registerArgumentMassager( |
| 292 'fileSystemProvider.onAbortRequested', | 309 'fileSystemProvider.onAbortRequested', |
| 293 massageArgumentsDefault); | 310 massageArgumentsDefault); |
| 294 | 311 |
| 295 exports.binding = binding.generate(); | 312 exports.binding = binding.generate(); |
| OLD | NEW |