| Index: chrome/renderer/resources/extensions/declarative_content_custom_bindings.js
|
| diff --git a/chrome/renderer/resources/extensions/declarative_content_custom_bindings.js b/chrome/renderer/resources/extensions/declarative_content_custom_bindings.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3655c4642025569299a53eae8a50f33027bb8ba2
|
| --- /dev/null
|
| +++ b/chrome/renderer/resources/extensions/declarative_content_custom_bindings.js
|
| @@ -0,0 +1,43 @@
|
| +// 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 declarativeContent API.
|
| +
|
| +var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
|
| +var utils = require('utils');
|
| +var validate = require('schemaUtils').validate;
|
| +
|
| +chromeHidden.registerCustomHook('declarativeContent', function(api) {
|
| + // Returns the schema definition of type |typeId| defined in |namespace|.
|
| + function getSchema(namespace, typeId) {
|
| + var apiSchema = utils.lookup(api.apiDefinitions, 'namespace', namespace);
|
| + var resultSchema = utils.lookup(
|
| + apiSchema.types, 'id', namespace + '.' + typeId);
|
| + return resultSchema;
|
| + }
|
| +
|
| + // Helper function for the constructor of concrete datatypes of the
|
| + // declarative content API.
|
| + // Makes sure that |this| contains the union of parameters and
|
| + // {'instanceType': 'declarativeContent.' + typeId} and validates the
|
| + // generated union dictionary against the schema for |typeId|.
|
| + function setupInstance(instance, parameters, typeId) {
|
| + for (var key in parameters) {
|
| + if (parameters.hasOwnProperty(key)) {
|
| + instance[key] = parameters[key];
|
| + }
|
| + }
|
| + instance.instanceType = 'declarativeContent.' + typeId;
|
| + var schema = getSchema('declarativeContent', typeId);
|
| + validate([instance], [schema]);
|
| + }
|
| +
|
| + // Setup all data types for the declarative content API.
|
| + chrome.declarativeContent.PageStateMatcher = function(parameters) {
|
| + setupInstance(this, parameters, 'PageStateMatcher');
|
| + };
|
| + chrome.declarativeContent.ShowPageAction = function(parameters) {
|
| + setupInstance(this, parameters, 'ShowPageAction');
|
| + };
|
| +});
|
|
|