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

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: Comment 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('schemaUtils').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;
not at google - send to devlin 2012/06/07 03:15:04 just curious, could you have used something like t
benwells 2012/06/07 04:11:48 No I don't think this would help, not that I can s
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().
27 var self = this;
25 function bindApiFunction(functionName) { 28 function bindApiFunction(functionName) {
26 this[functionName] = function() { 29 self[functionName] = function() {
27 var schema = this.parameters[functionName]; 30 var funSchema = this.functionSchemas[functionName];
not at google - send to devlin 2012/06/07 03:15:04 Woohoo! Par-tay! Ok I'll stop now.
28 chromeHidden.validate(arguments, schema); 31 var args = Array.prototype.slice.call(arguments);
32 args = normalizeArgumentsAndValidate(args, funSchema);
29 return sendRequest( 33 return sendRequest(
30 'storage.' + functionName, 34 'storage.' + functionName,
31 [namespace].concat(Array.prototype.slice.call(arguments)), 35 [namespace].concat(args),
32 extendSchema(schema)); 36 extendSchema(funSchema.definition.parameters));
33 }; 37 };
34 } 38 }
35 var apiFunctions = ['get', 'set', 'remove', 'clear', 'getBytesInUse']; 39 var apiFunctions = ['get', 'set', 'remove', 'clear', 'getBytesInUse'];
36 apiFunctions.forEach(bindApiFunction.bind(this)); 40 apiFunctions.forEach(bindApiFunction);
not at google - send to devlin 2012/06/07 03:15:04 thanks!
37 } 41 }
38 42
39 return StorageArea; 43 return StorageArea;
40 }); 44 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698