mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 1288440 P1 Avoid leaking existing windows in sdk/tab/events. r=gabor
This commit is contained in:
parent
45cd7b63bf
commit
b0f1ee1387
@ -39,29 +39,33 @@ function tabEventsFor(window) {
|
||||
return merge(channels);
|
||||
}
|
||||
|
||||
// Filter DOMContentLoaded events from all the browser events.
|
||||
var readyEvents = filter(events, e => e.type === "DOMContentLoaded");
|
||||
// Map DOMContentLoaded events to it's target browser windows.
|
||||
var futureWindows = map(readyEvents, e => e.target);
|
||||
// Expand all browsers that will become interactive to supported tab events
|
||||
// on these windows. Result will be a tab events from all tabs of all windows
|
||||
// that will become interactive.
|
||||
var eventsFromFuture = expand(futureWindows, tabEventsFor);
|
||||
// Create our event channels. We do this in a separate function to
|
||||
// minimize the chance of leaking intermediate objects on the global.
|
||||
function makeEvents() {
|
||||
// Filter DOMContentLoaded events from all the browser events.
|
||||
var readyEvents = filter(events, e => e.type === "DOMContentLoaded");
|
||||
// Map DOMContentLoaded events to it's target browser windows.
|
||||
var futureWindows = map(readyEvents, e => e.target);
|
||||
// Expand all browsers that will become interactive to supported tab events
|
||||
// on these windows. Result will be a tab events from all tabs of all windows
|
||||
// that will become interactive.
|
||||
var eventsFromFuture = expand(futureWindows, tabEventsFor);
|
||||
|
||||
// Above covers only windows that will become interactive in a future, but some
|
||||
// windows may already be interactive so we pick those and expand to supported
|
||||
// tab events for them too.
|
||||
var interactiveWindows = windows("navigator:browser", { includePrivate: true }).
|
||||
filter(isInteractive);
|
||||
var eventsFromInteractive = merge(interactiveWindows.map(tabEventsFor));
|
||||
// Above covers only windows that will become interactive in a future, but some
|
||||
// windows may already be interactive so we pick those and expand to supported
|
||||
// tab events for them too.
|
||||
var interactiveWindows = windows("navigator:browser", { includePrivate: true }).
|
||||
filter(isInteractive);
|
||||
var eventsFromInteractive = merge(interactiveWindows.map(tabEventsFor));
|
||||
|
||||
|
||||
// Finally merge stream of tab events from future windows and current windows
|
||||
// to cover all tab events on all windows that will open.
|
||||
var allEvents = merge([eventsFromInteractive, eventsFromFuture]);
|
||||
// Finally merge stream of tab events from future windows and current windows
|
||||
// to cover all tab events on all windows that will open.
|
||||
return merge([eventsFromInteractive, eventsFromFuture]);
|
||||
}
|
||||
|
||||
// Map events to Fennec format if necessary
|
||||
exports.events = map(allEvents, function (event) {
|
||||
exports.events = map(makeEvents(), function (event) {
|
||||
return !isFennec ? event : {
|
||||
type: event.type,
|
||||
target: event.target.ownerDocument.defaultView.BrowserApp
|
||||
|
Loading…
Reference in New Issue
Block a user