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

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

Issue 11547033: Implement declarativeContent API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Dominic's comments Created 7 years, 11 months 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/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');
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698