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

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

Issue 2643013002: Don't crash browser process when OK passed as error code in FSP API. (Closed)
Patch Set: Created 3 years, 11 months 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
« no previous file with comments | « chrome/common/extensions/api/file_system_provider.idl ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 if (metadata.thumbnail !== undefined && 113 if (metadata.thumbnail !== undefined &&
114 metadata.thumbnail.length > METADATA_THUMBNAIL_SIZE_LIMIT) { 114 metadata.thumbnail.length > METADATA_THUMBNAIL_SIZE_LIMIT) {
115 console.error('Thumbnail data too large.'); 115 console.error('Thumbnail data too large.');
116 return false; 116 return false;
117 } 117 }
118 118
119 return true; 119 return true;
120 } 120 }
121 121
122 /** 122 /**
123 * Verifies if the passed error code is valid when used to indicate
124 * a failure.
125 * @param {!string} error
126 * @return {boolean} True if valid, false if invalid.
127 */
128 function verifyErrorForFailure(error) {
129 if (error === 'OK') {
130 console.error('Error code cannot be OK in case of failures.');
131 return false;
132 }
133 return true;
134 }
135
136 /**
123 * Annotates an entry metadata by serializing its modifiedTime value. 137 * Annotates an entry metadata by serializing its modifiedTime value.
124 * @param {EntryMetadata} metadata Input metadata. 138 * @param {EntryMetadata} metadata Input metadata.
125 * @return {EntryMetadata} metadata Annotated metadata, which can be passed 139 * @return {EntryMetadata} metadata Annotated metadata, which can be passed
126 * back to the C++ layer. 140 * back to the C++ layer.
127 */ 141 */
128 function annotateMetadata(metadata) { 142 function annotateMetadata(metadata) {
129 var result = {}; 143 var result = {};
130 if (metadata.isDirectory !== undefined) 144 if (metadata.isDirectory !== undefined)
131 result.isDirectory = metadata.isDirectory; 145 result.isDirectory = metadata.isDirectory;
132 if (metadata.name !== undefined) 146 if (metadata.name !== undefined)
(...skipping 16 matching lines...) Expand all
149 * arguments. 163 * arguments.
150 */ 164 */
151 function massageArgumentsDefault(args, dispatch) { 165 function massageArgumentsDefault(args, dispatch) {
152 var executionStart = Date.now(); 166 var executionStart = Date.now();
153 var options = args[0]; 167 var options = args[0];
154 var onSuccessCallback = function(hasNext) { 168 var onSuccessCallback = function(hasNext) {
155 fileSystemProviderInternal.operationRequestedSuccess( 169 fileSystemProviderInternal.operationRequestedSuccess(
156 options.fileSystemId, options.requestId, Date.now() - executionStart); 170 options.fileSystemId, options.requestId, Date.now() - executionStart);
157 }; 171 };
158 var onErrorCallback = function(error) { 172 var onErrorCallback = function(error) {
173 if (!verifyErrorForFailure(error))
174 return;
159 fileSystemProviderInternal.operationRequestedError( 175 fileSystemProviderInternal.operationRequestedError(
160 options.fileSystemId, options.requestId, error, 176 options.fileSystemId, options.requestId, error,
161 Date.now() - executionStart); 177 Date.now() - executionStart);
162 } 178 }
163 dispatch([options, onSuccessCallback, onErrorCallback]); 179 dispatch([options, onSuccessCallback, onErrorCallback]);
164 } 180 }
165 181
166 eventBindings.registerArgumentMassager( 182 eventBindings.registerArgumentMassager(
167 'fileSystemProvider.onUnmountRequested', 183 'fileSystemProvider.onUnmountRequested',
168 massageArgumentsDefault); 184 massageArgumentsDefault);
(...skipping 12 matching lines...) Expand all
181 } 197 }
182 198
183 fileSystemProviderInternal.getMetadataRequestedSuccess( 199 fileSystemProviderInternal.getMetadataRequestedSuccess(
184 options.fileSystemId, 200 options.fileSystemId,
185 options.requestId, 201 options.requestId,
186 annotateMetadata(metadata), 202 annotateMetadata(metadata),
187 Date.now() - executionStart); 203 Date.now() - executionStart);
188 }; 204 };
189 205
190 var onErrorCallback = function(error) { 206 var onErrorCallback = function(error) {
207 if (!verifyErrorForFailure(error))
208 return;
191 fileSystemProviderInternal.operationRequestedError( 209 fileSystemProviderInternal.operationRequestedError(
192 options.fileSystemId, options.requestId, error, 210 options.fileSystemId, options.requestId, error,
193 Date.now() - executionStart); 211 Date.now() - executionStart);
194 } 212 }
195 213
196 dispatch([options, onSuccessCallback, onErrorCallback]); 214 dispatch([options, onSuccessCallback, onErrorCallback]);
197 }); 215 });
198 216
199 eventBindings.registerArgumentMassager( 217 eventBindings.registerArgumentMassager(
200 'fileSystemProvider.onGetActionsRequested', 218 'fileSystemProvider.onGetActionsRequested',
201 function(args, dispatch) { 219 function(args, dispatch) {
202 var executionStart = Date.now(); 220 var executionStart = Date.now();
203 var options = args[0]; 221 var options = args[0];
204 var onSuccessCallback = function(actions) { 222 var onSuccessCallback = function(actions) {
205 fileSystemProviderInternal.getActionsRequestedSuccess( 223 fileSystemProviderInternal.getActionsRequestedSuccess(
206 options.fileSystemId, 224 options.fileSystemId,
207 options.requestId, 225 options.requestId,
208 actions, 226 actions,
209 Date.now() - executionStart); 227 Date.now() - executionStart);
210 }; 228 };
211 229
212 var onErrorCallback = function(error) { 230 var onErrorCallback = function(error) {
231 if (!verifyErrorForFailure(error))
232 return;
213 fileSystemProviderInternal.operationRequestedError( 233 fileSystemProviderInternal.operationRequestedError(
214 options.fileSystemId, options.requestId, error, 234 options.fileSystemId, options.requestId, error,
215 Date.now() - executionStart); 235 Date.now() - executionStart);
216 } 236 }
217 237
218 dispatch([options, onSuccessCallback, onErrorCallback]); 238 dispatch([options, onSuccessCallback, onErrorCallback]);
219 }); 239 });
220 240
221 eventBindings.registerArgumentMassager( 241 eventBindings.registerArgumentMassager(
222 'fileSystemProvider.onReadDirectoryRequested', 242 'fileSystemProvider.onReadDirectoryRequested',
(...skipping 16 matching lines...) Expand all
239 return; 259 return;
240 } 260 }
241 261
242 var annotatedEntries = entries.map(annotateMetadata); 262 var annotatedEntries = entries.map(annotateMetadata);
243 fileSystemProviderInternal.readDirectoryRequestedSuccess( 263 fileSystemProviderInternal.readDirectoryRequestedSuccess(
244 options.fileSystemId, options.requestId, annotatedEntries, hasNext, 264 options.fileSystemId, options.requestId, annotatedEntries, hasNext,
245 Date.now() - executionStart); 265 Date.now() - executionStart);
246 }; 266 };
247 267
248 var onErrorCallback = function(error) { 268 var onErrorCallback = function(error) {
269 if (!verifyErrorForFailure(error))
270 return;
249 fileSystemProviderInternal.operationRequestedError( 271 fileSystemProviderInternal.operationRequestedError(
250 options.fileSystemId, options.requestId, error, 272 options.fileSystemId, options.requestId, error,
251 Date.now() - executionStart); 273 Date.now() - executionStart);
252 } 274 }
253 dispatch([options, onSuccessCallback, onErrorCallback]); 275 dispatch([options, onSuccessCallback, onErrorCallback]);
254 }); 276 });
255 277
256 eventBindings.registerArgumentMassager( 278 eventBindings.registerArgumentMassager(
257 'fileSystemProvider.onOpenFileRequested', 279 'fileSystemProvider.onOpenFileRequested',
258 massageArgumentsDefault); 280 massageArgumentsDefault);
259 281
260 eventBindings.registerArgumentMassager( 282 eventBindings.registerArgumentMassager(
261 'fileSystemProvider.onCloseFileRequested', 283 'fileSystemProvider.onCloseFileRequested',
262 massageArgumentsDefault); 284 massageArgumentsDefault);
263 285
264 eventBindings.registerArgumentMassager( 286 eventBindings.registerArgumentMassager(
265 'fileSystemProvider.onReadFileRequested', 287 'fileSystemProvider.onReadFileRequested',
266 function(args, dispatch) { 288 function(args, dispatch) {
267 var executionStart = Date.now(); 289 var executionStart = Date.now();
268 var options = args[0]; 290 var options = args[0];
269 var onSuccessCallback = function(data, hasNext) { 291 var onSuccessCallback = function(data, hasNext) {
270 fileSystemProviderInternal.readFileRequestedSuccess( 292 fileSystemProviderInternal.readFileRequestedSuccess(
271 options.fileSystemId, options.requestId, data, hasNext, 293 options.fileSystemId, options.requestId, data, hasNext,
272 Date.now() - executionStart); 294 Date.now() - executionStart);
273 }; 295 };
274 var onErrorCallback = function(error) { 296 var onErrorCallback = function(error) {
297 if (!verifyErrorForFailure(error))
298 return;
275 fileSystemProviderInternal.operationRequestedError( 299 fileSystemProviderInternal.operationRequestedError(
276 options.fileSystemId, options.requestId, error, 300 options.fileSystemId, options.requestId, error,
277 Date.now() - executionStart); 301 Date.now() - executionStart);
278 } 302 }
279 dispatch([options, onSuccessCallback, onErrorCallback]); 303 dispatch([options, onSuccessCallback, onErrorCallback]);
280 }); 304 });
281 305
282 eventBindings.registerArgumentMassager( 306 eventBindings.registerArgumentMassager(
283 'fileSystemProvider.onCreateDirectoryRequested', 307 'fileSystemProvider.onCreateDirectoryRequested',
284 massageArgumentsDefault); 308 massageArgumentsDefault);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 'fileSystemProvider.onExecuteActionRequested', 359 'fileSystemProvider.onExecuteActionRequested',
336 massageArgumentsDefault); 360 massageArgumentsDefault);
337 361
338 eventBindings.registerArgumentMassager( 362 eventBindings.registerArgumentMassager(
339 'fileSystemProvider.onMountRequested', 363 'fileSystemProvider.onMountRequested',
340 function(args, dispatch) { 364 function(args, dispatch) {
341 var onSuccessCallback = function() { 365 var onSuccessCallback = function() {
342 // TODO(mtomasz): To be implemented. 366 // TODO(mtomasz): To be implemented.
343 }; 367 };
344 var onErrorCallback = function(error) { 368 var onErrorCallback = function(error) {
369 verifyErrorForFailure(error);
benwells 2017/01/30 01:50:50 Nit: should this bail on failure like the other on
mtomasz 2017/02/21 05:25:59 Do you mean return if returned false? It would be
benwells 2017/02/21 05:35:11 That is what I meant. It would be a no-op, but wou
mtomasz 2017/02/21 05:56:43 I took a look at the original CL adding this TODO,
345 // TODO(mtomasz): To be implemented. 370 // TODO(mtomasz): To be implemented.
346 } 371 }
347 dispatch([onSuccessCallback, onErrorCallback]); 372 dispatch([onSuccessCallback, onErrorCallback]);
348 }); 373 });
349 374
350 exports.$set('binding', binding.generate()); 375 exports.$set('binding', binding.generate());
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/file_system_provider.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698