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

Side by Side Diff: chrome/renderer/resources/extensions/declarative_content_custom_bindings.js

Issue 12313142: Revert 184837 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Custom binding for the declarativeContent API. 5 // Custom bindings for the declarativeContent API.
6 6
7 var binding = require('binding').Binding.create('declarativeContent'); 7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
8
9 var utils = require('utils'); 8 var utils = require('utils');
10 var validate = require('schemaUtils').validate; 9 var validate = require('schemaUtils').validate;
11 10
12 binding.registerCustomHook( function(api) { 11 chromeHidden.registerCustomHook('declarativeContent', function(api) {
13 var declarativeContent = api.compiledApi;
14
15 // Returns the schema definition of type |typeId| defined in |namespace|. 12 // Returns the schema definition of type |typeId| defined in |namespace|.
16 function getSchema(typeId) { 13 function getSchema(namespace, typeId) {
17 return utils.lookup(api.schema.types, 14 var apiSchema = utils.lookup(api.apiDefinitions, 'namespace', namespace);
18 'id', 15 var resultSchema = utils.lookup(
19 'declarativeContent.' + typeId); 16 apiSchema.types, 'id', namespace + '.' + typeId);
17 return resultSchema;
20 } 18 }
21 19
22 // Helper function for the constructor of concrete datatypes of the 20 // Helper function for the constructor of concrete datatypes of the
23 // declarative content API. 21 // declarative content API.
24 // Makes sure that |this| contains the union of parameters and 22 // Makes sure that |this| contains the union of parameters and
25 // {'instanceType': 'declarativeContent.' + typeId} and validates the 23 // {'instanceType': 'declarativeContent.' + typeId} and validates the
26 // generated union dictionary against the schema for |typeId|. 24 // generated union dictionary against the schema for |typeId|.
27 function setupInstance(instance, parameters, typeId) { 25 function setupInstance(instance, parameters, typeId) {
28 for (var key in parameters) { 26 for (var key in parameters) {
29 if (parameters.hasOwnProperty(key)) { 27 if (parameters.hasOwnProperty(key)) {
30 instance[key] = parameters[key]; 28 instance[key] = parameters[key];
31 } 29 }
32 } 30 }
33 instance.instanceType = 'declarativeContent.' + typeId; 31 instance.instanceType = 'declarativeContent.' + typeId;
34 var schema = getSchema(typeId); 32 var schema = getSchema('declarativeContent', typeId);
35 validate([instance], [schema]); 33 validate([instance], [schema]);
36 } 34 }
37 35
38 // Setup all data types for the declarative content API. 36 // Setup all data types for the declarative content API.
39 declarativeContent.PageStateMatcher = function(parameters) { 37 chrome.declarativeContent.PageStateMatcher = function(parameters) {
40 setupInstance(this, parameters, 'PageStateMatcher'); 38 setupInstance(this, parameters, 'PageStateMatcher');
41 }; 39 };
42 declarativeContent.ShowPageAction = function(parameters) { 40 chrome.declarativeContent.ShowPageAction = function(parameters) {
43 setupInstance(this, parameters, 'ShowPageAction'); 41 setupInstance(this, parameters, 'ShowPageAction');
44 }; 42 };
45 }); 43 });
46
47 exports.binding = binding.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698