| OLD | NEW |
| 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 = | 8 var normalizeArgumentsAndValidate = |
| 9 require('schemaUtils').normalizeArgumentsAndValidate | 9 require('schemaUtils').normalizeArgumentsAndValidate |
| 10 var sendRequest = require('sendRequest').sendRequest; | 10 var sendRequest = require('sendRequest').sendRequest; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // callers of registerCustomType(). | 26 // callers of registerCustomType(). |
| 27 var self = this; | 27 var self = this; |
| 28 function bindApiFunction(functionName) { | 28 function bindApiFunction(functionName) { |
| 29 self[functionName] = function() { | 29 self[functionName] = function() { |
| 30 var funSchema = this.functionSchemas[functionName]; | 30 var funSchema = this.functionSchemas[functionName]; |
| 31 var args = Array.prototype.slice.call(arguments); | 31 var args = Array.prototype.slice.call(arguments); |
| 32 args = normalizeArgumentsAndValidate(args, funSchema); | 32 args = normalizeArgumentsAndValidate(args, funSchema); |
| 33 return sendRequest( | 33 return sendRequest( |
| 34 'storage.' + functionName, | 34 'storage.' + functionName, |
| 35 [namespace].concat(args), | 35 [namespace].concat(args), |
| 36 extendSchema(funSchema.definition.parameters)); | 36 extendSchema(funSchema.definition.parameters), |
| 37 {preserveNullInObjects: true}); |
| 37 }; | 38 }; |
| 38 } | 39 } |
| 39 var apiFunctions = ['get', 'set', 'remove', 'clear', 'getBytesInUse']; | 40 var apiFunctions = ['get', 'set', 'remove', 'clear', 'getBytesInUse']; |
| 40 apiFunctions.forEach(bindApiFunction); | 41 apiFunctions.forEach(bindApiFunction); |
| 41 } | 42 } |
| 42 | 43 |
| 43 return StorageArea; | 44 return StorageArea; |
| 44 }); | 45 }); |
| OLD | NEW |