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

Unified Diff: chrome/renderer/resources/extensions/schema_generated_bindings.js

Issue 8670012: Extension Settings API: move the API functions into an object SettingsNamepace, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bug / sync Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/schema_generated_bindings.js
diff --git a/chrome/renderer/resources/extensions/schema_generated_bindings.js b/chrome/renderer/resources/extensions/schema_generated_bindings.js
index 3fe5c3e58dfb0b227518da7ab672d4337fb2ab7c..3075d0d385d6cbaa6df1e317d7d0923f70f35b8b 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();

Powered by Google App Engine
This is Rietveld 408576698