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

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

Issue 9284013: Extension Storage API: expose storage quota information to extensions, via: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with use-after-free fixed Created 8 years, 10 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 (function() { 7 (function() {
8 8
9 native function GetChromeHidden(); 9 native function GetChromeHidden();
10 10
11 var chromeHidden = GetChromeHidden(); 11 var chromeHidden = GetChromeHidden();
12 12
13 chromeHidden.registerCustomType('StorageNamespace', 13 chromeHidden.registerCustomType('StorageArea', function(typesAPI) {
14 function(typesAPI) {
15 var sendRequest = typesAPI.sendRequest; 14 var sendRequest = typesAPI.sendRequest;
16 15
17 function extendSchema(schema) { 16 function extendSchema(schema) {
18 var extendedSchema = schema.slice(); 17 var extendedSchema = schema.slice();
19 extendedSchema.unshift({'type': 'string'}); 18 extendedSchema.unshift({'type': 'string'});
20 return extendedSchema; 19 return extendedSchema;
21 } 20 }
22 21
23 function StorageNamespace(namespace, schema) { 22 function StorageArea(namespace, schema) {
24 // Binds an API function for a namespace to its browser-side call, e.g. 23 // Binds an API function for a namespace to its browser-side call, e.g.
25 // storage.sync.get('foo') -> (binds to) -> 24 // storage.sync.get('foo') -> (binds to) ->
26 // storage.get('sync', 'foo'). 25 // storage.get('sync', 'foo').
27 // 26 //
28 // TODO(kalman): Put as a method on CustomBindingsObject and re-use (or 27 // TODO(kalman): Put as a method on CustomBindingsObject and re-use (or
29 // even generate) for other APIs that need to do this. Same for other 28 // even generate) for other APIs that need to do this. Same for other
30 // callers of registerCustomType(). 29 // callers of registerCustomType().
31 function bindApiFunction(functionName) { 30 function bindApiFunction(functionName) {
32 this[functionName] = function() { 31 this[functionName] = function() {
33 var schema = this.parameters[functionName]; 32 var schema = this.parameters[functionName];
34 chromeHidden.validate(arguments, schema); 33 chromeHidden.validate(arguments, schema);
35 return sendRequest( 34 return sendRequest(
36 'storage.' + functionName, 35 'storage.' + functionName,
37 [namespace].concat(Array.prototype.slice.call(arguments)), 36 [namespace].concat(Array.prototype.slice.call(arguments)),
38 extendSchema(schema)); 37 extendSchema(schema));
39 }; 38 };
40 } 39 }
41 ['get', 'set', 'remove', 'clear'].forEach(bindApiFunction.bind(this)); 40 var apiFunctions = ['get', 'set', 'remove', 'clear', 'getBytesInUse'];
41 apiFunctions.forEach(bindApiFunction.bind(this));
42 } 42 }
43 43
44 return StorageNamespace; 44 return StorageArea;
45 }); 45 });
46 46
47 })(); 47 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698