diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-31 05:12:01 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-31 05:12:01 +0000 |
commit | 6c377605a796251d51efe70e903218a6f2ea78b4 (patch) | |
tree | 17856a10bed983bd548040a4b19924be9d9b332b /chrome/renderer/resources/extensions/experimental.storage_custom_bindings.js | |
parent | a9b16dd01eea5070cab620a1177a05a6b43677ee (diff) | |
download | chromium_src-6c377605a796251d51efe70e903218a6f2ea78b4.zip chromium_src-6c377605a796251d51efe70e903218a6f2ea78b4.tar.gz chromium_src-6c377605a796251d51efe70e903218a6f2ea78b4.tar.bz2 |
Put the Extension Storage API back under experimental until the next release.
There are a couple of missing pieces, notably turning on the sync feature by
default (blocked on writing integration tests).
This patch will be reverted ASAP after the next release build is stable.
BUG=
TEST=browser_tests --gtest_filter=ExtensionSettings*; unit_tests --gtest_filter=ExtensionSettings*
Review URL: http://codereview.chromium.org/9233043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/resources/extensions/experimental.storage_custom_bindings.js')
-rw-r--r-- | chrome/renderer/resources/extensions/experimental.storage_custom_bindings.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/chrome/renderer/resources/extensions/experimental.storage_custom_bindings.js b/chrome/renderer/resources/extensions/experimental.storage_custom_bindings.js new file mode 100644 index 0000000..53a9097 --- /dev/null +++ b/chrome/renderer/resources/extensions/experimental.storage_custom_bindings.js @@ -0,0 +1,47 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Custom bindings for the storage API. + +(function() { + +native function GetChromeHidden(); + +var chromeHidden = GetChromeHidden(); + +chromeHidden.registerCustomType('StorageArea', function(typesAPI) { + var sendRequest = typesAPI.sendRequest; + + function extendSchema(schema) { + var extendedSchema = schema.slice(); + extendedSchema.unshift({'type': 'string'}); + return extendedSchema; + } + + function StorageArea(namespace, schema) { + // Binds an API function for a namespace to its browser-side call, e.g. + // storage.sync.get('foo') -> (binds to) -> + // storage.get('sync', 'foo'). + // + // TODO(kalman): Put as a method on CustomBindingsObject and re-use (or + // even generate) for other APIs that need to do this. Same for other + // callers of registerCustomType(). + function bindApiFunction(functionName) { + this[functionName] = function() { + var schema = this.parameters[functionName]; + chromeHidden.validate(arguments, schema); + return sendRequest( + 'experimental.storage.' + functionName, + [namespace].concat(Array.prototype.slice.call(arguments)), + extendSchema(schema)); + }; + } + var apiFunctions = ['get', 'set', 'remove', 'clear', 'getBytesInUse']; + apiFunctions.forEach(bindApiFunction.bind(this)); + } + + return StorageArea; +}); + +})(); |