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

Side by Side Diff: chrome/renderer/resources/extensions/storage_area.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 var forEach = require('utils').forEach;
6 var normalizeArgumentsAndValidate =
7 require('schemaUtils').normalizeArgumentsAndValidate
8 var sendRequest = require('sendRequest').sendRequest;
9
10 function extendSchema(schema) {
11 var extendedSchema = schema.slice();
12 extendedSchema.unshift({'type': 'string'});
13 return extendedSchema;
14 }
15
16 function StorageArea(namespace, schema) {
17 // Binds an API function for a namespace to its browser-side call, e.g.
18 // storage.sync.get('foo') -> (binds to) ->
19 // storage.get('sync', 'foo').
20 //
21 // TODO(kalman): Put as a method on CustombindingObject and re-use (or
22 // even generate) for other APIs that need to do this. Same for other
23 // callers of registerCustomType().
24 var self = this;
25 function bindApiFunction(i, functionName) {
26 self[functionName] = function() {
27 var funSchema = this.functionSchemas[functionName];
28 var args = Array.prototype.slice.call(arguments);
29 args = normalizeArgumentsAndValidate(args, funSchema);
30 return sendRequest(
31 'storage.' + functionName,
32 [namespace].concat(args),
33 extendSchema(funSchema.definition.parameters),
34 {preserveNullInObjects: true});
35 };
36 }
37 var apiFunctions = ['get', 'set', 'remove', 'clear', 'getBytesInUse'];
38 forEach(apiFunctions, bindApiFunction);
39 }
40
41 exports.StorageArea = StorageArea;
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extensions/json_schema.js ('k') | chrome/renderer/resources/extensions/storage_custom_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698