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

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

Issue 10535030: Allow updateArgumentsPostValidate to support callbacks and added / removed arguments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Unit tests Created 8 years, 6 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 | Annotate | Revision Log
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 bindings for the storage API. 5 // Custom bindings for the storage API.
6 6
7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
8 var normalizeArgumentsAndValidate =
9 require('validateUtils').normalizeArgumentsAndValidate
8 var sendRequest = require('sendRequest').sendRequest; 10 var sendRequest = require('sendRequest').sendRequest;
9 11
10 chromeHidden.registerCustomType('storage.StorageArea', function() { 12 chromeHidden.registerCustomType('storage.StorageArea', function() {
11 function extendSchema(schema) { 13 function extendSchema(schema) {
12 var extendedSchema = schema.slice(); 14 var extendedSchema = schema.slice();
13 extendedSchema.unshift({'type': 'string'}); 15 extendedSchema.unshift({'type': 'string'});
14 return extendedSchema; 16 return extendedSchema;
15 } 17 }
16 18
17 function StorageArea(namespace, schema) { 19 function StorageArea(namespace, schema) {
18 // Binds an API function for a namespace to its browser-side call, e.g. 20 // Binds an API function for a namespace to its browser-side call, e.g.
19 // storage.sync.get('foo') -> (binds to) -> 21 // storage.sync.get('foo') -> (binds to) ->
20 // storage.get('sync', 'foo'). 22 // storage.get('sync', 'foo').
21 // 23 //
22 // TODO(kalman): Put as a method on CustomBindingsObject and re-use (or 24 // TODO(kalman): Put as a method on CustomBindingsObject and re-use (or
23 // even generate) for other APIs that need to do this. Same for other 25 // even generate) for other APIs that need to do this. Same for other
24 // callers of registerCustomType(). 26 // callers of registerCustomType().
25 function bindApiFunction(functionName) { 27 function bindApiFunction(functionName) {
26 this[functionName] = function() { 28 this[functionName] = function() {
27 var schema = this.parameters[functionName]; 29 var schema = this.parameters[functionName];
28 chromeHidden.validate(arguments, schema); 30 var funDef = this.funDefs[functionName];
31 arguments = normalizeArgumentsAndValidate(arguments, funDef);
not at google - send to devlin 2012/06/07 00:17:11 I don't think that overwriting "arguments" is a po
benwells 2012/06/07 01:45:40 Done.
29 return sendRequest( 32 return sendRequest(
30 'storage.' + functionName, 33 'storage.' + functionName,
31 [namespace].concat(Array.prototype.slice.call(arguments)), 34 [namespace].concat(Array.prototype.slice.call(arguments)),
32 extendSchema(schema)); 35 extendSchema(schema));
33 }; 36 };
34 } 37 }
35 var apiFunctions = ['get', 'set', 'remove', 'clear', 'getBytesInUse']; 38 var apiFunctions = ['get', 'set', 'remove', 'clear', 'getBytesInUse'];
36 apiFunctions.forEach(bindApiFunction.bind(this)); 39 apiFunctions.forEach(bindApiFunction.bind(this));
37 } 40 }
38 41
39 return StorageArea; 42 return StorageArea;
40 }); 43 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698