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

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

Issue 10535030: Allow updateArgumentsPostValidate to support callbacks and added / removed arguments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Proper syntax Created 8 years, 6 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 var eventBindingsNatives = requireNative('event_bindings'); 5 var eventBindingsNatives = requireNative('event_bindings');
6 var AttachEvent = eventBindingsNatives.AttachEvent; 6 var AttachEvent = eventBindingsNatives.AttachEvent;
7 var DetachEvent = eventBindingsNatives.DetachEvent; 7 var DetachEvent = eventBindingsNatives.DetachEvent;
8 var sendRequest = require('sendRequest').sendRequest; 8 var sendRequest = require('sendRequest').sendRequest;
9 var utils = require('utils'); 9 var utils = require('utils');
10 var validate = require('schemaUtils').validate;
10 11
11 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 12 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden();
12 var GetExtensionAPIDefinition = 13 var GetExtensionAPIDefinition =
13 requireNative('apiDefinitions').GetExtensionAPIDefinition; 14 requireNative('apiDefinitions').GetExtensionAPIDefinition;
14 15
15 // Schemas for the rule-style functions on the events API that 16 // Schemas for the rule-style functions on the events API that
16 // only need to be generated occasionally, so populate them lazily. 17 // only need to be generated occasionally, so populate them lazily.
17 var ruleFunctionSchemas = { 18 var ruleFunctionSchemas = {
18 // These values are set lazily: 19 // These values are set lazily:
19 // addRules: {}, 20 // addRules: {},
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 this.listeners_ = []; 93 this.listeners_ = [];
93 this.eventOptions_ = opt_eventOptions || 94 this.eventOptions_ = opt_eventOptions ||
94 {"supportsListeners": true, "supportsRules": false}; 95 {"supportsListeners": true, "supportsRules": false};
95 96
96 if (this.eventOptions_.supportsRules && !opt_eventName) 97 if (this.eventOptions_.supportsRules && !opt_eventName)
97 throw new Error("Events that support rules require an event name."); 98 throw new Error("Events that support rules require an event name.");
98 99
99 // Validate event arguments (the data that is passed to the callbacks) 100 // Validate event arguments (the data that is passed to the callbacks)
100 // if we are in debug. 101 // if we are in debug.
101 if (opt_argSchemas && 102 if (opt_argSchemas &&
102 chromeHidden.validateCallbacks && 103 chromeHidden.validateCallbacks) {
103 chromeHidden.validate) {
104 104
105 this.validateEventArgs_ = function(args) { 105 this.validateEventArgs_ = function(args) {
106 try { 106 try {
107 chromeHidden.validate(args, opt_argSchemas); 107 validate(args, opt_argSchemas);
108 } catch (exception) { 108 } catch (exception) {
109 return "Event validation error during " + opt_eventName + " -- " + 109 return "Event validation error during " + opt_eventName + " -- " +
110 exception; 110 exception;
111 } 111 }
112 }; 112 };
113 } else { 113 } else {
114 this.validateEventArgs_ = function() {} 114 this.validateEventArgs_ = function() {}
115 } 115 }
116 }; 116 };
117 117
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // event object type. 299 // event object type.
300 // |rules| is an array of JSON objects that follow the Rule type of the 300 // |rules| is an array of JSON objects that follow the Rule type of the
301 // declarative extension APIs. |conditions| is an array of JSON type 301 // declarative extension APIs. |conditions| is an array of JSON type
302 // identifiers that are allowed to occur in the conditions attribute of each 302 // identifiers that are allowed to occur in the conditions attribute of each
303 // rule. Likewise, |actions| is an array of JSON type identifiers that are 303 // rule. Likewise, |actions| is an array of JSON type identifiers that are
304 // allowed to occur in the actions attribute of each rule. 304 // allowed to occur in the actions attribute of each rule.
305 function validateRules(rules, conditions, actions) { 305 function validateRules(rules, conditions, actions) {
306 var conditionsSchema = buildArrayOfChoicesSchema(conditions); 306 var conditionsSchema = buildArrayOfChoicesSchema(conditions);
307 var actionsSchema = buildArrayOfChoicesSchema(actions); 307 var actionsSchema = buildArrayOfChoicesSchema(actions);
308 rules.forEach(function(rule) { 308 rules.forEach(function(rule) {
309 chromeHidden.validate([rule.conditions], [conditionsSchema]); 309 validate([rule.conditions], [conditionsSchema]);
310 chromeHidden.validate([rule.actions], [actionsSchema]); 310 validate([rule.actions], [actionsSchema]);
311 }) 311 })
312 }; 312 };
313 313
314 if (!this.eventOptions_.conditions || !this.eventOptions_.actions) { 314 if (!this.eventOptions_.conditions || !this.eventOptions_.actions) {
315 throw new Error('Event ' + this.eventName_ + ' misses conditions or ' + 315 throw new Error('Event ' + this.eventName_ + ' misses conditions or ' +
316 'actions in the API specification.'); 316 'actions in the API specification.');
317 } 317 }
318 318
319 validateRules(rules, 319 validateRules(rules,
320 this.eventOptions_.conditions, 320 this.eventOptions_.conditions,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 if (event) 359 if (event)
360 event.detach_(false); 360 event.detach_(false);
361 } 361 }
362 }; 362 };
363 363
364 chromeHidden.dispatchError = function(msg) { 364 chromeHidden.dispatchError = function(msg) {
365 console.error(msg); 365 console.error(msg);
366 }; 366 };
367 367
368 exports.Event = chrome.Event; 368 exports.Event = chrome.Event;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698