12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- "use strict";
- module.metadata = {
- "stability": "experimental"
- };
- const { Ci } = require("chrome");
- const { windows, isInteractive } = require("../window/utils");
- const { events } = require("../browser/events");
- const { open } = require("../event/dom");
- const { filter, map, merge, expand } = require("../event/utils");
- const isFennec = require("sdk/system/xul-app").is("Fennec");
- const TYPES = ["TabOpen","TabClose","TabSelect","TabMove","TabPinned",
- "TabUnpinned"];
- function tabEventsFor(window) {
-
-
-
- let channels = TYPES.map(function(type) open(window, type));
- return merge(channels);
- }
- // Filter DOMContentLoaded events from all the browser events.
- let readyEvents = filter(events, function(e) e.type === "DOMContentLoaded");
- // Map DOMContentLoaded events to it's target browser windows.
- let futureWindows = map(readyEvents, function(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.
- let 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.
- let interactiveWindows = windows("navigator:browser", { includePrivate: true }).
- filter(isInteractive);
- let 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.
- let allEvents = merge([eventsFromInteractive, eventsFromFuture]);
- // Map events to Fennec format if necessary
- exports.events = map(allEvents, function (event) {
- return !isFennec ? event : {
- type: event.type,
- target: event.target.ownerDocument.defaultView.BrowserApp
- .getTabForBrowser(event.target)
- };
- });
|