Chromium Code Reviews| Index: chrome/renderer/resources/extension_process_bindings.js |
| diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js |
| index af682c07e189a3c97fa5363260f7862ab0a1cc22..c0b255bd829571b86ac25ee489665ee00226f7f0 100644 |
| --- a/chrome/renderer/resources/extension_process_bindings.js |
| +++ b/chrome/renderer/resources/extension_process_bindings.js |
| @@ -125,7 +125,7 @@ var chrome = chrome || {}; |
| request.callbackSchema.parameters); |
| } catch (exception) { |
| return "Callback validation error during " + name + " -- " + |
| - exception; |
| + exception.stack; |
| } |
| } |
| @@ -347,7 +347,7 @@ var chrome = chrome || {}; |
| var customBindings = {}; |
| function setupChromeSetting() { |
| - customBindings['ChromeSetting'] = function(prefKey, valueSchema) { |
| + function ChromeSetting(prefKey, valueSchema) { |
|
battre
2011/06/06 23:45:13
nit: start with lowercase?
Bernhard Bauer
2011/06/07 13:48:13
It's supposed to be the constructor.
|
| this.get = function(details, callback) { |
| var getSchema = this.parameters.get; |
| chromeHidden.validate([details, callback], getSchema); |
| @@ -373,7 +373,37 @@ var chrome = chrome || {}; |
| this.onChange = new chrome.Event('types.ChromeSetting.' + prefKey + |
| '.onChange'); |
| }; |
| - customBindings['ChromeSetting'].prototype = new CustomBindingsObject(); |
| + ChromeSetting.prototype = new CustomBindingsObject(); |
| + customBindings['ChromeSetting'] = ChromeSetting; |
| + } |
| + |
| + function setupContentSetting() { |
| + function ContentSetting(content_type, settingSchema) { |
|
battre
2011/06/06 23:45:13
same here?
|
| + this.get = function(details, callback) { |
| + var getSchema = this.parameters.get; |
| + chromeHidden.validate([details, callback], getSchema); |
| + return sendRequest('experimental.contentSettings.get', |
| + [content_type, details, callback], |
| + extendSchema(getSchema)); |
| + }; |
| + this.set = function(details, callback) { |
| + var setSchema = this.parameters.set.slice(); |
| + setSchema[0].properties.setting = settingSchema; |
| + chromeHidden.validate([details, callback], setSchema); |
| + return sendRequest('experimental.contentSettings.set', |
| + [content_type, details, callback], |
| + extendSchema(setSchema)); |
| + }; |
| + this.clear = function(details, callback) { |
| + var clearSchema = this.parameters.clear; |
| + chromeHidden.validate([details, callback], clearSchema); |
| + return sendRequest('experimental.contentSettings.clear', |
| + [content_type, details, callback], |
| + extendSchema(clearSchema)); |
| + }; |
| + } |
| + ContentSetting.prototype = new CustomBindingsObject(); |
| + customBindings['ContentSetting'] = ContentSetting; |
| } |
| // Page action events send (pageActionId, {tabId, tabUrl}). |
| @@ -509,6 +539,10 @@ 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. |
| + setupContentSetting(); |
| + |
| // |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. |
| @@ -601,34 +635,42 @@ var chrome = chrome || {}; |
| }); |
| } |
| - |
| - // Parse any values defined for properties. |
| - if (apiDef.properties) { |
| - forEach(apiDef.properties, function(prop, property) { |
| - if (property.value) { |
| + function addProperties(m, def) { |
| + // Parse any values defined for properties. |
| + if (def.properties) { |
| + forEach(def.properties, function(prop, property) { |
| var value = property.value; |
| - if (property.type === 'integer') { |
| - value = parseInt(value); |
| - } else if (property.type === 'boolean') { |
| - value = value === "true"; |
| - } else if (property["$ref"]) { |
| - var constructor = customBindings[property["$ref"]]; |
| - var args = value; |
| - // For an object property, |value| is an array of constructor |
| - // arguments, but we want to pass the arguments directly |
| - // (i.e. not as an array), so we have to fake calling |new| on the |
| - // constructor. |
| - value = { __proto__: constructor.prototype }; |
| - constructor.apply(value, args); |
| - } else if (property.type !== 'string') { |
| - throw "NOT IMPLEMENTED (extension_api.json error): Cannot " + |
| - "parse values for type \"" + property.type + "\""; |
| + if (value) { |
| + if (property.type === 'integer') { |
| + value = parseInt(value); |
| + } else if (property.type === 'boolean') { |
| + value = value === "true"; |
| + } else if (property["$ref"]) { |
| + var constructor = customBindings[property["$ref"]]; |
| + var args = value; |
| + // For an object property, |value| is an array of constructor |
| + // arguments, but we want to pass the arguments directly |
| + // (i.e. not as an array), so we have to fake calling |new| on |
| + // the constructor. |
| + value = { __proto__: constructor.prototype }; |
| + constructor.apply(value, args); |
| + } else if (property.type === 'object') { |
| + // Recursively add properties. |
| + addProperties(value, property); |
| + } else if (property.type !== 'string') { |
| + throw "NOT IMPLEMENTED (extension_api.json error): Cannot " + |
| + "parse values for type \"" + property.type + "\""; |
| + } |
| } |
| - module[prop] = value; |
| - } |
| - }); |
| + if (value) { |
| + m[prop] = value; |
| + } |
| + }); |
| + } |
| } |
| + addProperties(module, apiDef); |
| + |
| // getTabContentses is retained for backwards compatibility |
| // See http://crbug.com/21433 |
| chrome.extension.getTabContentses = chrome.extension.getExtensionTabs; |