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

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

Issue 12647017: Lazily require types when validating Extensions API calls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 7 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 // Custom binding for the storage API.
6
7 var binding = require('binding').Binding.create('storage');
8
9 var forEach = require('utils').forEach;
10 var normalizeArgumentsAndValidate =
11 require('schemaUtils').normalizeArgumentsAndValidate
12 var sendRequest = require('sendRequest').sendRequest;
13
14 binding.registerCustomType('storage.StorageArea', function() {
15 function extendSchema(schema) {
16 var extendedSchema = schema.slice();
17 extendedSchema.unshift({'type': 'string'});
18 return extendedSchema;
19 }
20
21 function StorageArea(namespace, schema) {
22 // Binds an API function for a namespace to its browser-side call, e.g.
23 // storage.sync.get('foo') -> (binds to) ->
24 // storage.get('sync', 'foo').
25 //
26 // TODO(kalman): Put as a method on CustombindingObject and re-use (or
27 // even generate) for other APIs that need to do this. Same for other
28 // callers of registerCustomType().
29 var self = this;
30 function bindApiFunction(i, functionName) {
31 self[functionName] = function() {
32 var funSchema = this.functionSchemas[functionName];
33 var args = Array.prototype.slice.call(arguments);
34 args = normalizeArgumentsAndValidate(args, funSchema);
35 return sendRequest(
36 'storage.' + functionName,
37 [namespace].concat(args),
38 extendSchema(funSchema.definition.parameters),
39 {preserveNullInObjects: true});
40 };
41 }
42 var apiFunctions = ['get', 'set', 'remove', 'clear', 'getBytesInUse'];
43 forEach(apiFunctions, bindApiFunction);
44 }
45
46 return StorageArea;
47 });
48
49 exports.binding = binding.generate();
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/storage_area.js ('k') | chrome/renderer/resources/extensions/types_custom_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698