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

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

Issue 28273006: <webview>: Implement declarativeWebRequest API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nits Created 7 years, 1 month 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
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 eventNatives = requireNative('event_natives'); 5 var eventNatives = requireNative('event_natives');
6 var logging = requireNative('logging'); 6 var logging = requireNative('logging');
7 var schemaRegistry = requireNative('schema_registry'); 7 var schemaRegistry = requireNative('schema_registry');
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 var validate = require('schemaUtils').validate;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // 180 //
181 // Example: 181 // Example:
182 // var Event = require('event_bindings').Event; 182 // var Event = require('event_bindings').Event;
183 // chrome.tabs.onChanged = new Event("tab-changed"); 183 // chrome.tabs.onChanged = new Event("tab-changed");
184 // chrome.tabs.onChanged.addListener(function(data) { alert(data); }); 184 // chrome.tabs.onChanged.addListener(function(data) { alert(data); });
185 // Event.dispatch("tab-changed", "hi"); 185 // Event.dispatch("tab-changed", "hi");
186 // will result in an alert dialog that says 'hi'. 186 // will result in an alert dialog that says 'hi'.
187 // 187 //
188 // If opt_eventOptions exists, it is a dictionary that contains the boolean 188 // If opt_eventOptions exists, it is a dictionary that contains the boolean
189 // entries "supportsListeners" and "supportsRules". 189 // entries "supportsListeners" and "supportsRules".
190 var Event = function(opt_eventName, opt_argSchemas, opt_eventOptions) { 190 // If opt_webViewInstanceId exists, it is an integer uniquely identifying a
191 // <webview> tag within the embedder. If it does not exist, then this is an
192 // extension event rather than a <webview> event.
193 var Event = function(opt_eventName, opt_argSchemas, opt_eventOptions,
194 opt_webViewInstanceId) {
191 this.eventName_ = opt_eventName; 195 this.eventName_ = opt_eventName;
192 this.argSchemas_ = opt_argSchemas; 196 this.argSchemas_ = opt_argSchemas;
193 this.listeners_ = []; 197 this.listeners_ = [];
194 this.eventOptions_ = parseEventOptions(opt_eventOptions); 198 this.eventOptions_ = parseEventOptions(opt_eventOptions);
199 this.webViewInstanceId_ = opt_webViewInstanceId || 0;
195 200
196 if (!this.eventName_) { 201 if (!this.eventName_) {
197 if (this.eventOptions_.supportsRules) 202 if (this.eventOptions_.supportsRules)
198 throw new Error("Events that support rules require an event name."); 203 throw new Error("Events that support rules require an event name.");
199 // Events without names cannot be managed by the browser by definition 204 // Events without names cannot be managed by the browser by definition
200 // (the browser has no way of identifying them). 205 // (the browser has no way of identifying them).
201 this.eventOptions_.unmanaged = true; 206 this.eventOptions_.unmanaged = true;
202 } 207 }
203 208
204 // Track whether the event has been destroyed to help track down the cause 209 // Track whether the event has been destroyed to help track down the cause
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 'actions in the API specification.'); 445 'actions in the API specification.');
441 } 446 }
442 447
443 validateRules(rules, 448 validateRules(rules,
444 this.eventOptions_.conditions, 449 this.eventOptions_.conditions,
445 this.eventOptions_.actions); 450 this.eventOptions_.actions);
446 451
447 ensureRuleSchemasLoaded(); 452 ensureRuleSchemasLoaded();
448 // We remove the first parameter from the validation to give the user more 453 // We remove the first parameter from the validation to give the user more
449 // meaningful error messages. 454 // meaningful error messages.
450 validate([rules, opt_cb], 455 validate([this.webViewInstanceId_, rules, opt_cb],
451 $Array.splice( 456 $Array.splice(
452 $Array.slice(ruleFunctionSchemas.addRules.parameters), 1)); 457 $Array.slice(ruleFunctionSchemas.addRules.parameters), 1));
453 sendRequest("events.addRules", [this.eventName_, rules, opt_cb], 458 sendRequest("events.addRules",
459 [this.eventName_, this.webViewInstanceId_, rules, opt_cb],
454 ruleFunctionSchemas.addRules.parameters); 460 ruleFunctionSchemas.addRules.parameters);
455 } 461 }
456 462
457 Event.prototype.removeRules = function(ruleIdentifiers, opt_cb) { 463 Event.prototype.removeRules = function(ruleIdentifiers, opt_cb) {
458 if (!this.eventOptions_.supportsRules) 464 if (!this.eventOptions_.supportsRules)
459 throw new Error("This event does not support rules."); 465 throw new Error("This event does not support rules.");
460 ensureRuleSchemasLoaded(); 466 ensureRuleSchemasLoaded();
461 // We remove the first parameter from the validation to give the user more 467 // We remove the first parameter from the validation to give the user more
462 // meaningful error messages. 468 // meaningful error messages.
463 validate([ruleIdentifiers, opt_cb], 469 validate([this.webViewInstanceId_, ruleIdentifiers, opt_cb],
464 $Array.splice( 470 $Array.splice(
465 $Array.slice(ruleFunctionSchemas.removeRules.parameters), 1)); 471 $Array.slice(ruleFunctionSchemas.removeRules.parameters), 1));
466 sendRequest("events.removeRules", 472 sendRequest("events.removeRules",
467 [this.eventName_, ruleIdentifiers, opt_cb], 473 [this.eventName_,
474 this.webViewInstanceId_,
475 ruleIdentifiers,
476 opt_cb],
468 ruleFunctionSchemas.removeRules.parameters); 477 ruleFunctionSchemas.removeRules.parameters);
469 } 478 }
470 479
471 Event.prototype.getRules = function(ruleIdentifiers, cb) { 480 Event.prototype.getRules = function(ruleIdentifiers, cb) {
472 if (!this.eventOptions_.supportsRules) 481 if (!this.eventOptions_.supportsRules)
473 throw new Error("This event does not support rules."); 482 throw new Error("This event does not support rules.");
474 ensureRuleSchemasLoaded(); 483 ensureRuleSchemasLoaded();
475 // We remove the first parameter from the validation to give the user more 484 // We remove the first parameter from the validation to give the user more
476 // meaningful error messages. 485 // meaningful error messages.
477 validate([ruleIdentifiers, cb], 486 validate([this.webViewInstanceId_, ruleIdentifiers, cb],
478 $Array.splice( 487 $Array.splice(
479 $Array.slice(ruleFunctionSchemas.getRules.parameters), 1)); 488 $Array.slice(ruleFunctionSchemas.getRules.parameters), 1));
480 489
481 sendRequest("events.getRules", 490 sendRequest("events.getRules",
482 [this.eventName_, ruleIdentifiers, cb], 491 [this.eventName_, this.webViewInstanceId_, ruleIdentifiers, cb],
483 ruleFunctionSchemas.getRules.parameters); 492 ruleFunctionSchemas.getRules.parameters);
484 } 493 }
485 494
486 unloadEvent.addListener(function() { 495 unloadEvent.addListener(function() {
487 for (var i = 0; i < allAttachedEvents.length; ++i) { 496 for (var i = 0; i < allAttachedEvents.length; ++i) {
488 var event = allAttachedEvents[i]; 497 var event = allAttachedEvents[i];
489 if (event) 498 if (event)
490 event.detach_(); 499 event.detach_();
491 } 500 }
492 }); 501 });
493 502
494 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc. 503 // NOTE: Event is (lazily) exposed as chrome.Event from dispatcher.cc.
495 exports.Event = Event; 504 exports.Event = Event;
496 505
497 exports.dispatchEvent = dispatchEvent; 506 exports.dispatchEvent = dispatchEvent;
498 exports.parseEventOptions = parseEventOptions; 507 exports.parseEventOptions = parseEventOptions;
499 exports.registerArgumentMassager = registerArgumentMassager; 508 exports.registerArgumentMassager = registerArgumentMassager;
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/dispatcher.cc ('k') | chrome/renderer/resources/extensions/web_request_internal_custom_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698