OLD | NEW |
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 DCHECK = requireNative('logging').DCHECK; | 5 var DCHECK = requireNative('logging').DCHECK; |
6 // TODO(cduvall/kalman): json_schema shouldn't put things on chromeHidden. | 6 // TODO(cduvall/kalman): json_schema shouldn't put things on chromeHidden. |
7 require('json_schema'); | 7 require('json_schema'); |
8 var eventBindingsNatives = requireNative('event_bindings'); | 8 var eventBindingsNatives = requireNative('event_bindings'); |
9 var AttachEvent = eventBindingsNatives.AttachEvent; | 9 var AttachEvent = eventBindingsNatives.AttachEvent; |
10 var DetachEvent = eventBindingsNatives.DetachEvent; | 10 var DetachEvent = eventBindingsNatives.DetachEvent; |
11 var AttachFilteredEvent = eventBindingsNatives.AttachFilteredEvent; | 11 var AttachFilteredEvent = eventBindingsNatives.AttachFilteredEvent; |
12 var DetachFilteredEvent = eventBindingsNatives.DetachFilteredEvent; | 12 var DetachFilteredEvent = eventBindingsNatives.DetachFilteredEvent; |
13 var MatchAgainstEventFilter = eventBindingsNatives.MatchAgainstEventFilter; | 13 var MatchAgainstEventFilter = eventBindingsNatives.MatchAgainstEventFilter; |
| 14 var forEach = require('utils').forEach; |
14 var sendRequest = require('sendRequest').sendRequest; | 15 var sendRequest = require('sendRequest').sendRequest; |
15 var utils = require('utils'); | 16 var utils = require('utils'); |
16 var validate = require('schemaUtils').validate; | 17 var validate = require('schemaUtils').validate; |
17 | 18 |
18 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); | 19 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
19 var chrome = requireNative('chrome').GetChrome(); | 20 var chrome = requireNative('chrome').GetChrome(); |
20 var schemaRegistry = requireNative('schema_registry'); | 21 var schemaRegistry = requireNative('schema_registry'); |
21 | 22 |
22 // Schemas for the rule-style functions on the events API that | 23 // Schemas for the rule-style functions on the events API that |
23 // only need to be generated occasionally, so populate them lazily. | 24 // only need to be generated occasionally, so populate them lazily. |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 // Validate conditions and actions against specific schemas of this | 392 // Validate conditions and actions against specific schemas of this |
392 // event object type. | 393 // event object type. |
393 // |rules| is an array of JSON objects that follow the Rule type of the | 394 // |rules| is an array of JSON objects that follow the Rule type of the |
394 // declarative extension APIs. |conditions| is an array of JSON type | 395 // declarative extension APIs. |conditions| is an array of JSON type |
395 // identifiers that are allowed to occur in the conditions attribute of each | 396 // identifiers that are allowed to occur in the conditions attribute of each |
396 // rule. Likewise, |actions| is an array of JSON type identifiers that are | 397 // rule. Likewise, |actions| is an array of JSON type identifiers that are |
397 // allowed to occur in the actions attribute of each rule. | 398 // allowed to occur in the actions attribute of each rule. |
398 function validateRules(rules, conditions, actions) { | 399 function validateRules(rules, conditions, actions) { |
399 var conditionsSchema = buildArrayOfChoicesSchema(conditions); | 400 var conditionsSchema = buildArrayOfChoicesSchema(conditions); |
400 var actionsSchema = buildArrayOfChoicesSchema(actions); | 401 var actionsSchema = buildArrayOfChoicesSchema(actions); |
401 rules.forEach(function(rule) { | 402 forEach(rules, function(i, rule) { |
402 validate([rule.conditions], [conditionsSchema]); | 403 validate([rule.conditions], [conditionsSchema]); |
403 validate([rule.actions], [actionsSchema]); | 404 validate([rule.actions], [actionsSchema]); |
404 }) | 405 }) |
405 }; | 406 }; |
406 | 407 |
407 if (!this.eventOptions_.conditions || !this.eventOptions_.actions) { | 408 if (!this.eventOptions_.conditions || !this.eventOptions_.actions) { |
408 throw new Error('Event ' + this.eventName_ + ' misses conditions or ' + | 409 throw new Error('Event ' + this.eventName_ + ' misses conditions or ' + |
409 'actions in the API specification.'); | 410 'actions in the API specification.'); |
410 } | 411 } |
411 | 412 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 if (event) | 468 if (event) |
468 event.detach_(); | 469 event.detach_(); |
469 } | 470 } |
470 }; | 471 }; |
471 | 472 |
472 chromeHidden.dispatchError = function(msg) { | 473 chromeHidden.dispatchError = function(msg) { |
473 console.error(msg); | 474 console.error(msg); |
474 }; | 475 }; |
475 | 476 |
476 chrome.Event = Event; | 477 chrome.Event = Event; |
OLD | NEW |