diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-24 04:17:24 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-24 04:17:24 +0000 |
commit | 15d5b476275921317b88494f81ce08d16e936c71 (patch) | |
tree | 046c185a3e42df4883ed256bd6695ada54d94203 /chrome/renderer | |
parent | b77576f54910cfb2e64ef91f3b3bb197136553b0 (diff) | |
download | chromium_src-15d5b476275921317b88494f81ce08d16e936c71.zip chromium_src-15d5b476275921317b88494f81ce08d16e936c71.tar.gz chromium_src-15d5b476275921317b88494f81ce08d16e936c71.tar.bz2 |
Extension Settings API: move the API functions into an object SettingsNamepace,
and separate the API into a "sync" and a "local" namespace. Make calls into
the "local" namespace not synced.
BUG=103863
TEST=*ExtensionSetting* (browser_tests, unit_tests)
Review URL: http://codereview.chromium.org/8670012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111494 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/resources/extensions/schema_generated_bindings.js | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/chrome/renderer/resources/extensions/schema_generated_bindings.js b/chrome/renderer/resources/extensions/schema_generated_bindings.js index 3fe5c3e..3075d0d 100644 --- a/chrome/renderer/resources/extensions/schema_generated_bindings.js +++ b/chrome/renderer/resources/extensions/schema_generated_bindings.js @@ -384,6 +384,29 @@ var chrome = chrome || {}; customBindings['ContentSetting'] = ContentSetting; } + function setupStorageNamespace() { + function StorageNamespace(namespace, schema) { + // Binds an API function for a namespace to its browser-side call, e.g. + // experimental.settings.sync.get('foo') -> (binds to) -> + // experimental.settings.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. + function bindApiFunction(functionName) { + this[functionName] = function() { + var schema = this.parameters[functionName]; + chromeHidden.validate(arguments, schema); + return sendRequest( + 'experimental.settings.' + functionName, + [namespace].concat(Array.prototype.slice.call(arguments)), + extendSchema(schema)); + }; + } + ['get', 'set', 'remove', 'clear'].forEach(bindApiFunction.bind(this)); + } + StorageNamespace.prototype = new CustomBindingsObject(); + customBindings['StorageNamespace'] = StorageNamespace; + } function setupInputEvents() { chrome.experimental.input.ime.onKeyEvent.dispatch = function(engineID, keyData) { @@ -580,10 +603,12 @@ var chrome = chrome || {}; // ChromeSetting objects from the API definition. setupChromeSetting(); - // Setup the ContentSetting class so we can use it to construct - // ContentSetting objects from the API definition. + // Ditto ContentSetting. setupContentSetting(); + // Ditto StorageNamespace. + setupStorageNamespace(); + // |apiFunctions| is a hash of name -> object that stores the // name & definition of the apiFunction. Custom handling of api functions // is implemented by adding a "handleRequest" function to the object. @@ -593,7 +618,7 @@ var chrome = chrome || {}; // TODO(rafaelw): Consider defining a json schema for an api definition // and validating either here, in a unit_test or both. // TODO(rafaelw): Handle synchronous functions. - // TOOD(rafaelw): Consider providing some convenient override points + // TODO(rafaelw): Consider providing some convenient override points // for api functions that wish to insert themselves into the call. var apiDefinitions = GetExtensionAPIDefinition(); var platform = getPlatform(); |