Reland the ULONG -> SIZE_T change from 317177
[chromium-blink-merge.git] / extensions / renderer / resources / guest_view / extension_view_events.js
bloba30c5fd7fdfc05bb5a3635a81a52e64d47c8e9ac
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 = {
15   'loadcommit': {
16     handler: function(event) {
17       ExtensionViewEvents.prototype.handleLoadCommitEvent.call(this, event);
18     },
19     evt: CreateEvent('extensionViewInternal.onLoadCommit'),
20   }
23 // Constructor.
24 function ExtensionViewEvents(extensionViewImpl, viewInstanceId) {
25   this.extensionViewImpl = extensionViewImpl;
26   this.viewInstanceId = viewInstanceId;
28   // Set up the events.
29   var events = this.getEvents();
30   for (var eventName in events) {
31     this.setupEvent(eventName, events[eventName]);
32   }
35 ExtensionViewEvents.prototype.getEvents = function() {
36   return EXTENSION_VIEW_EVENTS;
39 ExtensionViewEvents.prototype.setupEvent = function(name, info) {
40   info.evt.addListener(function(e) {
41     if (info.handler)
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;