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

Side by Side Diff: extensions/renderer/resources/guest_view/guest_view_events.js

Issue 988293004: Added the 'internal' flag for guestview event info. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 // Event management for GuestViewContainers. 5 // Event management for GuestViewContainers.
6 6
7 var EventBindings = require('event_bindings'); 7 var EventBindings = require('event_bindings');
8 8
9 var CreateEvent = function(name) { 9 var CreateEvent = function(name) {
10 var eventOpts = {supportsListeners: true, supportsFilters: true}; 10 var eventOpts = {supportsListeners: true, supportsFilters: true};
(...skipping 23 matching lines...) Expand all
34 // meaningful. 34 // meaningful.
35 // |evt| specifies a descriptor object for the extension event. An event 35 // |evt| specifies a descriptor object for the extension event. An event
36 // listener will be attached to this descriptor. 36 // listener will be attached to this descriptor.
37 // |fields| (default: none) specifies the public-facing fields in the DOM event 37 // |fields| (default: none) specifies the public-facing fields in the DOM event
38 // that are accessible to developers. 38 // that are accessible to developers.
39 // |handler| specifies the name of a handler function to be called each time 39 // |handler| specifies the name of a handler function to be called each time
40 // that extension event is caught by its event listener. The DOM event 40 // that extension event is caught by its event listener. The DOM event
41 // should be dispatched within this handler function (if desired). With no 41 // should be dispatched within this handler function (if desired). With no
42 // handler function, the DOM event will be dispatched by default each time 42 // handler function, the DOM event will be dispatched by default each time
43 // the extension event is caught. 43 // the extension event is caught.
44 // |internal| (default: false) specifies that the event will not be dispatched
45 // as a DOM event, and will also not appear as an on* property on the view’s
46 // element. A |handler| should be specified for all internal events, and
47 // |fields| and |cancelable| should be left unspecified (as they are only
48 // meaningful for DOM events).
44 GuestViewEvents.EVENTS = {}; 49 GuestViewEvents.EVENTS = {};
45 50
46 // Sets up the handling of events. 51 // Sets up the handling of events.
47 GuestViewEvents.prototype.setupEvents = function() { 52 GuestViewEvents.prototype.setupEvents = function() {
48 for (var eventName in GuestViewEvents.EVENTS) { 53 for (var eventName in GuestViewEvents.EVENTS) {
49 this.setupEvent(eventName, GuestViewEvents.EVENTS[eventName]); 54 this.setupEvent(eventName, GuestViewEvents.EVENTS[eventName]);
50 } 55 }
51 56
52 var events = this.getEvents(); 57 var events = this.getEvents();
53 for (var eventName in events) { 58 for (var eventName in events) {
54 this.setupEvent(eventName, events[eventName]); 59 this.setupEvent(eventName, events[eventName]);
55 } 60 }
56 }; 61 };
57 62
58 // Sets up the handling of the |eventName| event. 63 // Sets up the handling of the |eventName| event.
59 GuestViewEvents.prototype.setupEvent = function(eventName, eventInfo) { 64 GuestViewEvents.prototype.setupEvent = function(eventName, eventInfo) {
60 this.setupEventProperty(eventName); 65 if (!eventInfo.internal) {
66 this.setupEventProperty(eventName);
67 }
61 68
62 var listenerOpts = { instanceId: this.view.viewInstanceId }; 69 var listenerOpts = { instanceId: this.view.viewInstanceId };
63 if (eventInfo.handler) { 70 if (eventInfo.handler) {
64 eventInfo.evt.addListener(function(e) { 71 eventInfo.evt.addListener(function(e) {
65 this[eventInfo.handler](e, eventName); 72 this[eventInfo.handler](e, eventName);
66 }.bind(this), listenerOpts); 73 }.bind(this), listenerOpts);
67 return; 74 return;
68 } 75 }
69 76
77 // Internal events are not dispatched as DOM events.
78 if (eventInfo.internal) {
79 return;
80 }
81
70 eventInfo.evt.addListener(function(e) { 82 eventInfo.evt.addListener(function(e) {
71 var domEvent = this.makeDomEvent(e, eventName); 83 var domEvent = this.makeDomEvent(e, eventName);
72 this.view.dispatchEvent(domEvent); 84 this.view.dispatchEvent(domEvent);
73 }.bind(this), listenerOpts); 85 }.bind(this), listenerOpts);
74 }; 86 };
75 87
76 // Constructs a DOM event based on the info for the |eventName| event provided 88 // Constructs a DOM event based on the info for the |eventName| event provided
77 // in either |GuestViewEvents.EVENTS| or getEvents(). 89 // in either |GuestViewEvents.EVENTS| or getEvents().
78 GuestViewEvents.prototype.makeDomEvent = function(event, eventName) { 90 GuestViewEvents.prototype.makeDomEvent = function(event, eventName) {
79 var eventInfo = 91 var eventInfo =
80 GuestViewEvents.EVENTS[eventName] || this.getEvents()[eventName]; 92 GuestViewEvents.EVENTS[eventName] || this.getEvents()[eventName];
81 93
94 // Internal events are not dispatched as DOM events.
95 if (eventInfo.internal) {
96 return null;
97 }
98
82 var details = { bubbles: true }; 99 var details = { bubbles: true };
83 if (eventInfo.cancelable) { 100 if (eventInfo.cancelable) {
84 details.cancelable = true; 101 details.cancelable = true;
85 } 102 }
86 var domEvent = new Event(eventName, details); 103 var domEvent = new Event(eventName, details);
87 if (eventInfo.fields) { 104 if (eventInfo.fields) {
88 $Array.forEach(eventInfo.fields, function(field) { 105 $Array.forEach(eventInfo.fields, function(field) {
89 if (event[field] !== undefined) { 106 if (event[field] !== undefined) {
90 domEvent[field] = event[field]; 107 domEvent[field] = event[field];
91 } 108 }
(...skipping 23 matching lines...) Expand all
115 enumerable: true 132 enumerable: true
116 }); 133 });
117 }; 134 };
118 135
119 // Implemented by the derived event manager, if one exists. 136 // Implemented by the derived event manager, if one exists.
120 GuestViewEvents.prototype.getEvents = function() { return {}; }; 137 GuestViewEvents.prototype.getEvents = function() { return {}; };
121 138
122 // Exports. 139 // Exports.
123 exports.GuestViewEvents = GuestViewEvents; 140 exports.GuestViewEvents = GuestViewEvents;
124 exports.CreateEvent = CreateEvent; 141 exports.CreateEvent = CreateEvent;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698