1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Event management for ExtensionView.
7 var EventBindings = require('event_bindings');
9 var CreateEvent = function(name) {
10 var eventOpts = {supportsListeners: true, supportsFilters: true};
11 return new EventBindings.Event(name, undefined, eventOpts);
14 var EXTENSION_VIEW_EVENTS = {
16 handler: function(event) {
17 ExtensionViewEvents.prototype.handleLoadCommitEvent.call(this, event);
19 evt: CreateEvent('extensionViewInternal.onLoadCommit'),
24 function ExtensionViewEvents(extensionViewImpl, viewInstanceId) {
25 this.extensionViewImpl = extensionViewImpl;
26 this.viewInstanceId = viewInstanceId;
29 var events = this.getEvents();
30 for (var eventName in events) {
31 this.setupEvent(eventName, events[eventName]);
35 ExtensionViewEvents.prototype.getEvents = function() {
36 return EXTENSION_VIEW_EVENTS;
39 ExtensionViewEvents.prototype.setupEvent = function(name, info) {
40 info.evt.addListener(function(e) {
42 info.handler.call(this, e);
43 }.bind(this), {instanceId: this.viewInstanceId});
46 ExtensionViewEvents.prototype.handleLoadCommitEvent = function(event) {
47 this.extensionViewImpl.onLoadCommit(event.url);
50 exports.ExtensionViewEvents = ExtensionViewEvents;