Bug 1336308: Part 4 - Rename `tab` variables that refer to native tabs to avoid confusion. r=aswan

MozReview-Commit-ID: 5An7K1crYRS

--HG--
extra : rebase_source : b052d46fe2883850c95b2116534ee098f0d4efa2
This commit is contained in:
Kris Maglione 2017-02-03 12:57:43 -08:00
Родитель d76e319fe5
Коммит 28b57587cb
5 изменённых файлов: 277 добавлений и 277 удалений

Просмотреть файл

@ -58,9 +58,9 @@ extensions.on("page-shutdown", (type, context) => {
}
let {gBrowser} = context.xulBrowser.ownerGlobal;
if (gBrowser) {
let tab = gBrowser.getTabForBrowser(context.xulBrowser);
if (tab) {
gBrowser.removeTab(tab);
let nativeTab = gBrowser.getTabForBrowser(context.xulBrowser);
if (nativeTab) {
gBrowser.removeTab(nativeTab);
}
}
}
@ -83,16 +83,16 @@ let tabListener = {
onLocationChange(browser, webProgress, request, locationURI, flags) {
if (webProgress.isTopLevel) {
let {gBrowser} = browser.ownerGlobal;
let tab = gBrowser.getTabForBrowser(browser);
let nativeTab = gBrowser.getTabForBrowser(browser);
// Now we are certain that the first page in the tab was loaded.
this.initializingTabs.delete(tab);
this.initializingTabs.delete(nativeTab);
// browser.innerWindowID is now set, resolve the promises if any.
let deferred = this.tabReadyPromises.get(tab);
let deferred = this.tabReadyPromises.get(nativeTab);
if (deferred) {
deferred.resolve(tab);
this.tabReadyPromises.delete(tab);
deferred.resolve(nativeTab);
this.tabReadyPromises.delete(nativeTab);
}
}
},
@ -103,19 +103,20 @@ let tabListener = {
* changes to the requested URL. Other tabs are assumed to be ready once their
* inner window ID is known.
*
* @param {XULElement} tab The <tab> element.
* @param {XULElement} nativeTab The <tab> element.
* @returns {Promise} Resolves with the given tab once ready.
*/
awaitTabReady(tab) {
let deferred = this.tabReadyPromises.get(tab);
awaitTabReady(nativeTab) {
let deferred = this.tabReadyPromises.get(nativeTab);
if (!deferred) {
deferred = PromiseUtils.defer();
if (!this.initializingTabs.has(tab) && (tab.linkedBrowser.innerWindowID ||
tab.linkedBrowser.currentURI.spec === "about:blank")) {
deferred.resolve(tab);
if (!this.initializingTabs.has(nativeTab) &&
(nativeTab.linkedBrowser.innerWindowID ||
nativeTab.linkedBrowser.currentURI.spec === "about:blank")) {
deferred.resolve(nativeTab);
} else {
this.initTabReady();
this.tabReadyPromises.set(tab, deferred);
this.tabReadyPromises.set(nativeTab, deferred);
}
}
return deferred.promise;
@ -142,7 +143,7 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
tab = tabManager.getWrapper(tabTracker.activeTab);
}
await tabListener.awaitTabReady(tab.tab);
await tabListener.awaitTabReady(tab.nativeTab);
return tab;
}
@ -150,15 +151,15 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
let self = {
tabs: {
onActivated: new WindowEventManager(context, "tabs.onActivated", "TabSelect", (fire, event) => {
let tab = event.originalTarget;
let tabId = tabTracker.getId(tab);
let windowId = windowTracker.getId(tab.ownerGlobal);
let nativeTab = event.originalTarget;
let tabId = tabTracker.getId(nativeTab);
let windowId = windowTracker.getId(nativeTab.ownerGlobal);
fire.async({tabId, windowId});
}).api(),
onCreated: new SingletonEventManager(context, "tabs.onCreated", fire => {
let listener = (eventName, event) => {
fire.async(tabManager.convert(event.tab));
fire.async(tabManager.convert(event.nativeTab));
};
tabTracker.on("tab-created", listener);
@ -174,9 +175,9 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
* @see https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/Tabs/onHighlighted
*/
onHighlighted: new WindowEventManager(context, "tabs.onHighlighted", "TabSelect", (fire, event) => {
let tab = event.originalTarget;
let tabIds = [tabTracker.getId(tab)];
let windowId = windowTracker.getId(tab.ownerGlobal);
let nativeTab = event.originalTarget;
let tabIds = [tabTracker.getId(nativeTab)];
let windowId = windowTracker.getId(nativeTab.ownerGlobal);
fire.async({tabIds, windowId});
}).api(),
@ -236,17 +237,17 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
};
let moveListener = event => {
let tab = event.originalTarget;
let nativeTab = event.originalTarget;
if (ignoreNextMove.has(tab)) {
ignoreNextMove.delete(tab);
if (ignoreNextMove.has(nativeTab)) {
ignoreNextMove.delete(nativeTab);
return;
}
fire.async(tabTracker.getId(tab), {
windowId: windowTracker.getId(tab.ownerGlobal),
fire.async(tabTracker.getId(nativeTab), {
windowId: windowTracker.getId(nativeTab.ownerGlobal),
fromIndex: event.detail,
toIndex: tab._tPos,
toIndex: nativeTab._tPos,
});
};
@ -400,22 +401,22 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
options.disallowInheritPrincipal = true;
tabListener.initTabReady();
let tab = window.gBrowser.addTab(url || window.BROWSER_NEW_TAB_URL, options);
let nativeTab = window.gBrowser.addTab(url || window.BROWSER_NEW_TAB_URL, options);
let active = true;
if (createProperties.active !== null) {
active = createProperties.active;
}
if (active) {
window.gBrowser.selectedTab = tab;
window.gBrowser.selectedTab = nativeTab;
}
if (createProperties.index !== null) {
window.gBrowser.moveTabTo(tab, createProperties.index);
window.gBrowser.moveTabTo(nativeTab, createProperties.index);
}
if (createProperties.pinned) {
window.gBrowser.pinTab(tab);
window.gBrowser.pinTab(nativeTab);
}
if (createProperties.url && createProperties.url !== window.BROWSER_NEW_TAB_URL) {
@ -427,10 +428,10 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
// `executeScript` wait until the requested URL is loaded in
// the tab before dispatching messages to the inner window
// that contains the URL we're attempting to load.
tabListener.initializingTabs.add(tab);
tabListener.initializingTabs.add(nativeTab);
}
return tabManager.convert(tab);
return tabManager.convert(nativeTab);
});
},
@ -440,15 +441,15 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
}
for (let tabId of tabs) {
let tab = tabTracker.getTab(tabId);
tab.ownerGlobal.gBrowser.removeTab(tab);
let nativeTab = tabTracker.getTab(tabId);
nativeTab.ownerGlobal.gBrowser.removeTab(nativeTab);
}
},
async update(tabId, updateProperties) {
let tab = getTabOrActive(tabId);
let nativeTab = getTabOrActive(tabId);
let tabbrowser = tab.ownerGlobal.gBrowser;
let tabbrowser = nativeTab.ownerGlobal.gBrowser;
if (updateProperties.url !== null) {
let url = context.uri.resolve(updateProperties.url);
@ -457,55 +458,53 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
return Promise.reject({message: `Illegal URL: ${url}`});
}
tab.linkedBrowser.loadURI(url);
nativeTab.linkedBrowser.loadURI(url);
}
if (updateProperties.active !== null) {
if (updateProperties.active) {
tabbrowser.selectedTab = tab;
tabbrowser.selectedTab = nativeTab;
} else {
// Not sure what to do here? Which tab should we select?
}
}
if (updateProperties.muted !== null) {
if (tab.muted != updateProperties.muted) {
tab.toggleMuteAudio(extension.uuid);
if (nativeTab.muted != updateProperties.muted) {
nativeTab.toggleMuteAudio(extension.uuid);
}
}
if (updateProperties.pinned !== null) {
if (updateProperties.pinned) {
tabbrowser.pinTab(tab);
tabbrowser.pinTab(nativeTab);
} else {
tabbrowser.unpinTab(tab);
tabbrowser.unpinTab(nativeTab);
}
}
// FIXME: highlighted/selected, openerTabId
return tabManager.convert(tab);
return tabManager.convert(nativeTab);
},
async reload(tabId, reloadProperties) {
let tab = getTabOrActive(tabId);
let nativeTab = getTabOrActive(tabId);
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
if (reloadProperties && reloadProperties.bypassCache) {
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
}
tab.linkedBrowser.reloadWithFlags(flags);
nativeTab.linkedBrowser.reloadWithFlags(flags);
},
async get(tabId) {
let tab = tabTracker.getTab(tabId);
return tabManager.convert(tab);
return tabManager.get(tabId).convert();
},
getCurrent() {
let tab;
let tabData;
if (context.tabId) {
tab = tabManager.get(context.tabId).convert();
tabData = tabManager.get(context.tabId).convert();
}
return Promise.resolve(tab);
return Promise.resolve(tabData);
},
async query(queryInfo) {
@ -528,7 +527,7 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
windowTracker.getWindow(windowId, context);
let tab = tabManager.wrapTab(window.gBrowser.selectedTab);
await tabListener.awaitTabReady(tab.tab);
await tabListener.awaitTabReady(tab.nativeTab);
return tab.capture(context, options);
},
@ -583,9 +582,9 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
let indexMap = new Map();
let tabs = tabIds.map(tabId => tabTracker.getTab(tabId));
for (let tab of tabs) {
for (let nativeTab of tabs) {
// If the window is not specified, use the window from the tab.
let window = destinationWindow || tab.ownerGlobal;
let window = destinationWindow || nativeTab.ownerGlobal;
let gBrowser = window.gBrowser;
let insertionPoint = indexMap.get(window) || index;
@ -599,32 +598,32 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
// be moved to a position after the current set of pinned tabs.
// Attempts to move a tab to an illegal position are ignored.
let numPinned = gBrowser._numPinnedTabs;
let ok = tab.pinned ? insertionPoint <= numPinned : insertionPoint >= numPinned;
let ok = nativeTab.pinned ? insertionPoint <= numPinned : insertionPoint >= numPinned;
if (!ok) {
continue;
}
indexMap.set(window, insertionPoint + 1);
if (tab.ownerGlobal != window) {
if (nativeTab.ownerGlobal != window) {
// If the window we are moving the tab in is different, then move the tab
// to the new window.
tab = gBrowser.adoptTab(tab, insertionPoint, false);
nativeTab = gBrowser.adoptTab(nativeTab, insertionPoint, false);
} else {
// If the window we are moving is the same, just move the tab.
gBrowser.moveTabTo(tab, insertionPoint);
gBrowser.moveTabTo(nativeTab, insertionPoint);
}
tabsMoved.push(tab);
tabsMoved.push(nativeTab);
}
return tabsMoved.map(tab => tabManager.convert(tab));
return tabsMoved.map(nativeTab => tabManager.convert(nativeTab));
},
duplicate(tabId) {
let tab = tabTracker.getTab(tabId);
let nativeTab = tabTracker.getTab(tabId);
let gBrowser = tab.ownerGlobal.gBrowser;
let newTab = gBrowser.duplicateTab(tab);
let gBrowser = nativeTab.ownerGlobal.gBrowser;
let newTab = gBrowser.duplicateTab(nativeTab);
return new Promise(resolve => {
// We need to use SSTabRestoring because any attributes set before
@ -635,10 +634,10 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
// Pinned tabs that are duplicated are inserted
// after the existing pinned tab and pinned.
if (tab.pinned) {
if (nativeTab.pinned) {
gBrowser.pinTab(newTab);
}
gBrowser.moveTabTo(newTab, tab._tPos + 1);
gBrowser.moveTabTo(newTab, nativeTab._tPos + 1);
}, {once: true});
newTab.addEventListener("SSTabRestored", function() {
@ -651,24 +650,24 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
},
getZoom(tabId) {
let tab = getTabOrActive(tabId);
let nativeTab = getTabOrActive(tabId);
let {ZoomManager} = tab.ownerGlobal;
let zoom = ZoomManager.getZoomForBrowser(tab.linkedBrowser);
let {ZoomManager} = nativeTab.ownerGlobal;
let zoom = ZoomManager.getZoomForBrowser(nativeTab.linkedBrowser);
return Promise.resolve(zoom);
},
setZoom(tabId, zoom) {
let tab = getTabOrActive(tabId);
let nativeTab = getTabOrActive(tabId);
let {FullZoom, ZoomManager} = tab.ownerGlobal;
let {FullZoom, ZoomManager} = nativeTab.ownerGlobal;
if (zoom === 0) {
// A value of zero means use the default zoom factor.
return FullZoom.reset(tab.linkedBrowser);
return FullZoom.reset(nativeTab.linkedBrowser);
} else if (zoom >= ZoomManager.MIN && zoom <= ZoomManager.MAX) {
FullZoom.setZoom(zoom, tab.linkedBrowser);
FullZoom.setZoom(zoom, nativeTab.linkedBrowser);
} else {
return Promise.reject({
message: `Zoom value ${zoom} out of range (must be between ${ZoomManager.MIN} and ${ZoomManager.MAX})`,
@ -679,9 +678,9 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
},
_getZoomSettings(tabId) {
let tab = getTabOrActive(tabId);
let nativeTab = getTabOrActive(tabId);
let {FullZoom} = tab.ownerGlobal;
let {FullZoom} = nativeTab.ownerGlobal;
return {
mode: "automatic",
@ -695,9 +694,9 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
},
setZoomSettings(tabId, settings) {
let tab = getTabOrActive(tabId);
let nativeTab = getTabOrActive(tabId);
let currentSettings = this._getZoomSettings(tab.id);
let currentSettings = this._getZoomSettings(tabTracker.getId(nativeTab));
if (!Object.keys(settings).every(key => settings[key] === currentSettings[key])) {
return Promise.reject(`Unsupported zoom settings: ${JSON.stringify(settings)}`);
@ -718,14 +717,14 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
// Store the zoom level for all existing tabs.
for (let window of windowTracker.browserWindows()) {
for (let tab of window.gBrowser.tabs) {
let browser = tab.linkedBrowser;
for (let nativeTab of window.gBrowser.tabs) {
let browser = nativeTab.linkedBrowser;
zoomLevels.set(browser, getZoomLevel(browser));
}
}
let tabCreated = (eventName, event) => {
let browser = event.tab.linkedBrowser;
let browser = event.nativeTab.linkedBrowser;
zoomLevels.set(browser, getZoomLevel(browser));
};
@ -742,8 +741,8 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
}
let {gBrowser} = browser.ownerGlobal;
let tab = gBrowser.getTabForBrowser(browser);
if (!tab) {
let nativeTab = gBrowser.getTabForBrowser(browser);
if (!nativeTab) {
// We only care about zoom events in the top-level browser of a tab.
return;
}
@ -754,7 +753,7 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
if (oldZoomFactor != newZoomFactor) {
zoomLevels.set(browser, newZoomFactor);
let tabId = tabTracker.getId(tab);
let tabId = tabTracker.getId(nativeTab);
fire.async({
tabId,
oldZoomFactor,

Просмотреть файл

@ -49,23 +49,23 @@ global.TabContext = function TabContext(getDefaults, extension) {
};
TabContext.prototype = {
get(tab) {
if (!this.tabData.has(tab)) {
this.tabData.set(tab, this.getDefaults(tab));
get(nativeTab) {
if (!this.tabData.has(nativeTab)) {
this.tabData.set(nativeTab, this.getDefaults(nativeTab));
}
return this.tabData.get(tab);
return this.tabData.get(nativeTab);
},
clear(tab) {
this.tabData.delete(tab);
clear(nativeTab) {
this.tabData.delete(nativeTab);
},
handleEvent(event) {
if (event.type == "TabSelect") {
let tab = event.target;
this.emit("tab-select", tab);
this.emit("location-change", tab);
let nativeTab = event.target;
this.emit("tab-select", nativeTab);
this.emit("location-change", nativeTab);
}
},
@ -83,8 +83,8 @@ TabContext.prototype = {
let lastLocation = this.lastLocation.get(browser);
if (browser === gBrowser.selectedBrowser &&
!(lastLocation && lastLocation.equalsExceptRef(browser.currentURI))) {
let tab = gBrowser.getTabForBrowser(browser);
this.emit("location-change", tab, true);
let nativeTab = gBrowser.getTabForBrowser(browser);
this.emit("location-change", nativeTab, true);
}
this.lastLocation.set(browser, browser.currentURI);
},
@ -152,28 +152,28 @@ class TabTracker extends TabTrackerBase {
/* eslint-enable mozilla/balanced-listeners */
}
getId(tab) {
if (this._tabs.has(tab)) {
return this._tabs.get(tab);
getId(nativeTab) {
if (this._tabs.has(nativeTab)) {
return this._tabs.get(nativeTab);
}
this.init();
let id = this._nextId++;
this.setId(tab, id);
this.setId(nativeTab, id);
return id;
}
setId(tab, id) {
this._tabs.set(tab, id);
this._tabIds.set(id, tab);
setId(nativeTab, id) {
this._tabs.set(nativeTab, id);
this._tabIds.set(id, nativeTab);
}
_handleTabDestroyed(event, {tab}) {
let id = this._tabs.get(tab);
_handleTabDestroyed(event, {nativeTab}) {
let id = this._tabs.get(nativeTab);
if (id) {
this._tabs.delete(tab);
if (this._tabIds.get(id) === tab) {
this._tabs.delete(nativeTab);
if (this._tabIds.get(id) === nativeTab) {
this._tabIds.delete(id);
}
}
@ -192,9 +192,9 @@ class TabTracker extends TabTrackerBase {
* A XUL <tab> element.
*/
getTab(tabId, default_ = undefined) {
let tab = this._tabIds.get(tabId);
if (tab) {
return tab;
let nativeTab = this._tabIds.get(tabId);
if (nativeTab) {
return nativeTab;
}
if (default_ !== undefined) {
return default_;
@ -208,7 +208,7 @@ class TabTracker extends TabTrackerBase {
* @private
*/
handleEvent(event) {
let tab = event.target;
let nativeTab = event.target;
switch (event.type) {
case "TabOpen":
@ -218,10 +218,10 @@ class TabTracker extends TabTrackerBase {
// This tab is being created to adopt a tab from a different window.
// Copy the ID from the old tab to the new.
this.setId(tab, this.getId(adoptedTab));
this.setId(nativeTab, this.getId(adoptedTab));
adoptedTab.linkedBrowser.messageManager.sendAsyncMessage("Extension:SetTabAndWindowId", {
windowId: windowTracker.getId(tab.ownerGlobal),
windowId: windowTracker.getId(nativeTab.ownerGlobal),
});
}
@ -243,11 +243,11 @@ class TabTracker extends TabTrackerBase {
// Copy its ID to the new tab, in case it was created as the first tab
// of a new window, and did not have an `adoptedTab` detail when it was
// opened.
this.setId(adoptedBy, this.getId(tab));
this.setId(adoptedBy, this.getId(nativeTab));
this.emitDetached(tab, adoptedBy);
this.emitDetached(nativeTab, adoptedBy);
} else {
this.emitRemoved(tab, false);
this.emitRemoved(nativeTab, false);
}
break;
}
@ -272,16 +272,16 @@ class TabTracker extends TabTrackerBase {
// by the first MozAfterPaint event. That code handles finally
// adopting the tab, and clears it from the arguments list in the
// process, so if we run later than it, we're too late.
let tab = window.arguments[0];
let nativeTab = window.arguments[0];
let adoptedBy = window.gBrowser.tabs[0];
this.adoptedTabs.set(tab, adoptedBy);
this.setId(adoptedBy, this.getId(tab));
this.adoptedTabs.set(nativeTab, adoptedBy);
this.setId(adoptedBy, this.getId(nativeTab));
// We need to be sure to fire this event after the onDetached event
// for the original tab.
let listener = (event, details) => {
if (details.tab === tab) {
if (details.nativeTab === nativeTab) {
this.off("tab-detached", listener);
Promise.resolve().then(() => {
@ -292,8 +292,8 @@ class TabTracker extends TabTrackerBase {
this.on("tab-detached", listener);
} else {
for (let tab of window.gBrowser.tabs) {
this.emitCreated(tab);
for (let nativeTab of window.gBrowser.tabs) {
this.emitCreated(nativeTab);
}
}
}
@ -307,11 +307,11 @@ class TabTracker extends TabTrackerBase {
* @private
*/
_handleWindowClose(window) {
for (let tab of window.gBrowser.tabs) {
if (this.adoptedTabs.has(tab)) {
this.emitDetached(tab, this.adoptedTabs.get(tab));
for (let nativeTab of window.gBrowser.tabs) {
if (this.adoptedTabs.has(nativeTab)) {
this.emitDetached(nativeTab, this.adoptedTabs.get(nativeTab));
} else {
this.emitRemoved(tab, true);
this.emitRemoved(nativeTab, true);
}
}
}
@ -319,58 +319,58 @@ class TabTracker extends TabTrackerBase {
/**
* Emits a "tab-attached" event for the given tab element.
*
* @param {NativeTab} tab
* @param {NativeTab} nativeTab
* The tab element in the window to which the tab is being attached.
* @private
*/
emitAttached(tab) {
let newWindowId = windowTracker.getId(tab.ownerGlobal);
let tabId = this.getId(tab);
emitAttached(nativeTab) {
let newWindowId = windowTracker.getId(nativeTab.ownerGlobal);
let tabId = this.getId(nativeTab);
this.emit("tab-attached", {tab, tabId, newWindowId, newPosition: tab._tPos});
this.emit("tab-attached", {nativeTab, tabId, newWindowId, newPosition: nativeTab._tPos});
}
/**
* Emits a "tab-detached" event for the given tab element.
*
* @param {NativeTab} tab
* @param {NativeTab} nativeTab
* The tab element in the window from which the tab is being detached.
* @param {NativeTab} adoptedBy
* The tab element in the window to which detached tab is being moved,
* and will adopt this tab's contents.
* @private
*/
emitDetached(tab, adoptedBy) {
let oldWindowId = windowTracker.getId(tab.ownerGlobal);
let tabId = this.getId(tab);
emitDetached(nativeTab, adoptedBy) {
let oldWindowId = windowTracker.getId(nativeTab.ownerGlobal);
let tabId = this.getId(nativeTab);
this.emit("tab-detached", {tab, adoptedBy, tabId, oldWindowId, oldPosition: tab._tPos});
this.emit("tab-detached", {nativeTab, adoptedBy, tabId, oldWindowId, oldPosition: nativeTab._tPos});
}
/**
* Emits a "tab-created" event for the given tab element.
*
* @param {NativeTab} tab
* @param {NativeTab} nativeTab
* The tab element which is being created.
* @private
*/
emitCreated(tab) {
this.emit("tab-created", {tab});
emitCreated(nativeTab) {
this.emit("tab-created", {nativeTab});
}
/**
* Emits a "tab-removed" event for the given tab element.
*
* @param {NativeTab} tab
* @param {NativeTab} nativeTab
* The tab element which is being removed.
* @param {boolean} isWindowClosing
* True if the tab is being removed because the browser window is
* closing.
* @private
*/
emitRemoved(tab, isWindowClosing) {
let windowId = windowTracker.getId(tab.ownerGlobal);
let tabId = this.getId(tab);
emitRemoved(nativeTab, isWindowClosing) {
let windowId = windowTracker.getId(nativeTab.ownerGlobal);
let tabId = this.getId(nativeTab);
// When addons run in-process, `window.close()` is synchronous. Most other
// addon-invoked calls are asynchronous since they go through a proxy
@ -382,7 +382,7 @@ class TabTracker extends TabTrackerBase {
// event listener is registered. To make sure that the event listener is
// notified, we dispatch `tabs.onRemoved` asynchronously.
Services.tm.mainThread.dispatch(() => {
this.emit("tab-removed", {tab, tabId, windowId, isWindowClosing});
this.emit("tab-removed", {nativeTab, tabId, windowId, isWindowClosing});
}, Ci.nsIThread.DISPATCH_NORMAL);
}
@ -406,9 +406,9 @@ class TabTracker extends TabTrackerBase {
if (gBrowser && gBrowser.getTabForBrowser) {
result.windowId = windowTracker.getId(browser.ownerGlobal);
let tab = gBrowser.getTabForBrowser(browser);
if (tab) {
result.tabId = this.getId(tab);
let nativeTab = gBrowser.getTabForBrowser(browser);
if (nativeTab) {
result.tabId = this.getId(nativeTab);
}
}
@ -431,19 +431,19 @@ Object.assign(global, {tabTracker, windowTracker});
class Tab extends TabBase {
get _favIconUrl() {
return this.window.gBrowser.getIcon(this.tab);
return this.window.gBrowser.getIcon(this.nativeTab);
}
get audible() {
return this.tab.soundPlaying;
return this.nativeTab.soundPlaying;
}
get browser() {
return this.tab.linkedBrowser;
return this.nativeTab.linkedBrowser;
}
get cookieStoreId() {
return getCookieStoreIdForTab(this, this.tab);
return getCookieStoreIdForTab(this, this.nativeTab);
}
get height() {
@ -451,37 +451,37 @@ class Tab extends TabBase {
}
get index() {
return this.tab._tPos;
return this.nativeTab._tPos;
}
get mutedInfo() {
let tab = this.tab;
let {nativeTab} = this;
let mutedInfo = {muted: tab.muted};
if (tab.muteReason === null) {
let mutedInfo = {muted: nativeTab.muted};
if (nativeTab.muteReason === null) {
mutedInfo.reason = "user";
} else if (tab.muteReason) {
} else if (nativeTab.muteReason) {
mutedInfo.reason = "extension";
mutedInfo.extensionId = tab.muteReason;
mutedInfo.extensionId = nativeTab.muteReason;
}
return mutedInfo;
}
get pinned() {
return this.tab.pinned;
return this.nativeTab.pinned;
}
get active() {
return this.tab.selected;
return this.nativeTab.selected;
}
get selected() {
return this.tab.selected;
return this.nativeTab.selected;
}
get status() {
if (this.tab.getAttribute("busy") === "true") {
if (this.nativeTab.getAttribute("busy") === "true") {
return "loading";
}
return "complete";
@ -492,7 +492,7 @@ class Tab extends TabBase {
}
get window() {
return this.tab.ownerGlobal;
return this.nativeTab.ownerGlobal;
}
get windowId() {
@ -665,8 +665,8 @@ class Window extends WindowBase {
* getTabs() {
let {tabManager} = this.extension;
for (let tab of this.window.gBrowser.tabs) {
yield tabManager.getWrapper(tab);
for (let nativeTab of this.window.gBrowser.tabs) {
yield tabManager.getWrapper(nativeTab);
}
}
@ -695,8 +695,8 @@ class Window extends WindowBase {
};
if (windowData.tabs.length) {
result.tabs = windowData.tabs.map(tab => {
return Tab.convertFromSessionStoreClosedData(extension, tab);
result.tabs = windowData.tabs.map(tabData => {
return Tab.convertFromSessionStoreClosedData(extension, tabData);
});
}
@ -708,24 +708,24 @@ Object.assign(global, {Tab, Window});
class TabManager extends TabManagerBase {
get(tabId, default_ = undefined) {
let tab = tabTracker.getTab(tabId, default_);
let nativeTab = tabTracker.getTab(tabId, default_);
if (tab) {
return this.getWrapper(tab);
if (nativeTab) {
return this.getWrapper(nativeTab);
}
return default_;
}
addActiveTabPermission(tab = tabTracker.activeTab) {
return super.addActiveTabPermission(tab);
addActiveTabPermission(nativeTab = tabTracker.activeTab) {
return super.addActiveTabPermission(nativeTab);
}
revokeActiveTabPermission(tab = tabTracker.activeTab) {
return super.revokeActiveTabPermission(tab);
revokeActiveTabPermission(nativeTab = tabTracker.activeTab) {
return super.revokeActiveTabPermission(nativeTab);
}
wrapTab(tab) {
return new Tab(this.extension, tab, tabTracker.getId(tab));
wrapTab(nativeTab) {
return new Tab(this.extension, nativeTab, tabTracker.getId(nativeTab));
}
}

Просмотреть файл

@ -58,9 +58,9 @@ extensions.on("page-shutdown", (type, context) => {
}
let {BrowserApp} = context.xulBrowser.ownerGlobal;
if (BrowserApp) {
let tab = BrowserApp.getTabForBrowser(context.xulBrowser);
if (tab) {
BrowserApp.closeTab(tab);
let nativeTab = BrowserApp.getTabForBrowser(context.xulBrowser);
if (nativeTab) {
BrowserApp.closeTab(nativeTab);
}
}
}
@ -89,16 +89,16 @@ let tabListener = {
onLocationChange(browser, webProgress, request, locationURI, flags) {
if (webProgress.isTopLevel) {
let {BrowserApp} = browser.ownerGlobal;
let tab = BrowserApp.getTabForBrowser(browser);
let nativeTab = BrowserApp.getTabForBrowser(browser);
// Now we are certain that the first page in the tab was loaded.
this.initializingTabs.delete(tab);
this.initializingTabs.delete(nativeTab);
// browser.innerWindowID is now set, resolve the promises if any.
let deferred = this.tabReadyPromises.get(tab);
let deferred = this.tabReadyPromises.get(nativeTab);
if (deferred) {
deferred.resolve(tab);
this.tabReadyPromises.delete(tab);
deferred.resolve(nativeTab);
this.tabReadyPromises.delete(nativeTab);
}
}
},
@ -109,19 +109,20 @@ let tabListener = {
* changes to the requested URL. Other tabs are assumed to be ready once their
* inner window ID is known.
*
* @param {XULElement} tab The <tab> element.
* @param {NativeTab} nativeTab The native tab object.
* @returns {Promise} Resolves with the given tab once ready.
*/
awaitTabReady(tab) {
let deferred = this.tabReadyPromises.get(tab);
awaitTabReady(nativeTab) {
let deferred = this.tabReadyPromises.get(nativeTab);
if (!deferred) {
deferred = PromiseUtils.defer();
if (!this.initializingTabs.has(tab) && (tab.browser.innerWindowID ||
tab.browser.currentURI.spec === "about:blank")) {
deferred.resolve(tab);
if (!this.initializingTabs.has(nativeTab) &&
(nativeTab.browser.innerWindowID ||
nativeTab.browser.currentURI.spec === "about:blank")) {
deferred.resolve(nativeTab);
} else {
this.initTabReady();
this.tabReadyPromises.set(tab, deferred);
this.tabReadyPromises.set(nativeTab, deferred);
}
}
return deferred.promise;
@ -148,7 +149,7 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
tab = tabManager.getWrapper(tabTracker.activeTab);
}
await tabListener.awaitTabReady(tab.tab);
await tabListener.awaitTabReady(tab.nativeTab);
return tab;
}
@ -163,7 +164,7 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
onCreated: new SingletonEventManager(context, "tabs.onCreated", fire => {
let listener = (eventName, event) => {
fire.async(tabManager.convert(event.tab));
fire.async(tabManager.convert(event.nativeTab));
};
tabTracker.on("tab-created", listener);
@ -233,12 +234,12 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
let listener = event => {
let needed = [];
let tab;
let nativeTab;
switch (event.type) {
case "DOMTitleChanged": {
let {BrowserApp} = getBrowserWindow(event.target.ownerGlobal);
tab = BrowserApp.getTabForWindow(event.target.ownerGlobal);
nativeTab = BrowserApp.getTabForWindow(event.target.ownerGlobal);
needed.push("title");
break;
}
@ -246,17 +247,17 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
case "DOMAudioPlaybackStarted":
case "DOMAudioPlaybackStopped": {
let {BrowserApp} = event.target.ownerGlobal;
tab = BrowserApp.getTabForBrowser(event.originalTarget);
nativeTab = BrowserApp.getTabForBrowser(event.originalTarget);
needed.push("audible");
break;
}
}
if (!tab) {
if (!nativeTab) {
return;
}
tab = tabManager.getWrapper(tab);
let tab = tabManager.getWrapper(nativeTab);
let changeInfo = {};
for (let prop of needed) {
changeInfo[prop] = tab[prop];
@ -267,14 +268,14 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
let statusListener = ({browser, status, url}) => {
let {BrowserApp} = browser.ownerGlobal;
let tab = BrowserApp.getTabForBrowser(browser);
if (tab) {
let nativeTab = BrowserApp.getTabForBrowser(browser);
if (nativeTab) {
let changed = {status};
if (url) {
changed.url = url;
}
fireForTab(tabManager.wrapTab(tab), changed);
fireForTab(tabManager.wrapTab(nativeTab), changed);
}
};
@ -319,13 +320,13 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
options.disallowInheritPrincipal = true;
tabListener.initTabReady();
let tab = BrowserApp.addTab(url, options);
let nativeTab = BrowserApp.addTab(url, options);
if (createProperties.url) {
tabListener.initializingTabs.add(tab);
tabListener.initializingTabs.add(nativeTab);
}
return tabManager.convert(tab);
return tabManager.convert(nativeTab);
},
async remove(tabs) {
@ -334,15 +335,15 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
}
for (let tabId of tabs) {
let tab = tabTracker.getTab(tabId);
tab.browser.ownerGlobal.BrowserApp.closeTab(tab);
let nativeTab = tabTracker.getTab(tabId);
nativeTab.browser.ownerGlobal.BrowserApp.closeTab(nativeTab);
}
},
async update(tabId, updateProperties) {
let tab = getTabOrActive(tabId);
let nativeTab = getTabOrActive(tabId);
let {BrowserApp} = tab.browser.ownerGlobal;
let {BrowserApp} = nativeTab.browser.ownerGlobal;
if (updateProperties.url !== null) {
let url = context.uri.resolve(updateProperties.url);
@ -351,29 +352,29 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
return Promise.reject({message: `Illegal URL: ${url}`});
}
tab.browser.loadURI(url);
nativeTab.browser.loadURI(url);
}
if (updateProperties.active !== null) {
if (updateProperties.active) {
BrowserApp.selectTab(tab);
BrowserApp.selectTab(nativeTab);
} else {
// Not sure what to do here? Which tab should we select?
}
}
// FIXME: highlighted/selected, muted, pinned, openerTabId
return tabManager.convert(tab);
return tabManager.convert(nativeTab);
},
async reload(tabId, reloadProperties) {
let tab = getTabOrActive(tabId);
let nativeTab = getTabOrActive(tabId);
let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
if (reloadProperties && reloadProperties.bypassCache) {
flags |= Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
}
tab.browser.reloadWithFlags(flags);
nativeTab.browser.reloadWithFlags(flags);
},
async get(tabId) {
@ -406,7 +407,7 @@ extensions.registerSchemaAPI("tabs", "addon_parent", context => {
windowTracker.getWindow(windowId, context);
let tab = tabManager.wrapTab(window.BrowserApp.selectedTab);
await tabListener.awaitTabReady(tab.tab);
await tabListener.awaitTabReady(tab.nativeTab);
return tab.capture(context, options);
},

Просмотреть файл

@ -66,8 +66,8 @@ class ProgressListenerWrapper {
this.flags = Ci.nsIWebProgress.NOTIFY_STATE_ALL |
Ci.nsIWebProgress.NOTIFY_LOCATION;
for (let tab of this.window.BrowserApp.tabs) {
this.addBrowserProgressListener(tab.browser);
for (let nativeTab of this.window.BrowserApp.tabs) {
this.addBrowserProgressListener(nativeTab.browser);
}
this.window.BrowserApp.deck.addEventListener("TabOpen", this);
@ -76,8 +76,8 @@ class ProgressListenerWrapper {
destroy() {
this.window.BrowserApp.deck.removeEventListener("TabOpen", this);
for (let tab of this.window.BrowserApp.tabs) {
this.removeProgressListener(tab.browser);
for (let nativeTab of this.window.BrowserApp.tabs) {
this.removeProgressListener(nativeTab.browser);
}
}
@ -173,16 +173,16 @@ class TabTracker extends TabTrackerBase {
windowTracker.addListener("TabOpen", this);
}
getId(tab) {
return tab.id;
getId(nativeTab) {
return nativeTab.id;
}
getTab(id, default_ = undefined) {
let win = windowTracker.topWindow;
if (win) {
let tab = win.BrowserApp.getTabForId(id);
if (tab) {
return tab;
let nativeTab = win.BrowserApp.getTabForId(id);
if (nativeTab) {
return nativeTab;
}
}
if (default_ !== undefined) {
@ -193,29 +193,29 @@ class TabTracker extends TabTrackerBase {
handleEvent(event) {
const {BrowserApp} = event.target.ownerGlobal;
let tab = BrowserApp.getTabForBrowser(event.target);
let nativeTab = BrowserApp.getTabForBrowser(event.target);
switch (event.type) {
case "TabOpen":
this.emitCreated(tab);
this.emitCreated(nativeTab);
break;
case "TabClose":
this.emitRemoved(tab, false);
this.emitRemoved(nativeTab, false);
break;
}
}
emitCreated(tab) {
this.emit("tab-created", {tab});
emitCreated(nativeTab) {
this.emit("tab-created", {nativeTab});
}
emitRemoved(tab, isWindowClosing) {
let windowId = windowTracker.getId(tab.browser.ownerGlobal);
let tabId = this.getId(tab);
emitRemoved(nativeTab, isWindowClosing) {
let windowId = windowTracker.getId(nativeTab.browser.ownerGlobal);
let tabId = this.getId(nativeTab);
Services.tm.mainThread.dispatch(() => {
this.emit("tab-removed", {tab, tabId, windowId, isWindowClosing});
this.emit("tab-removed", {nativeTab, tabId, windowId, isWindowClosing});
}, Ci.nsIThread.DISPATCH_NORMAL);
}
@ -229,9 +229,9 @@ class TabTracker extends TabTrackerBase {
if (BrowserApp) {
result.windowId = windowTracker.getId(browser.ownerGlobal);
let tab = BrowserApp.getTabForBrowser(browser);
if (tab) {
result.tabId = this.getId(tab);
let nativeTab = BrowserApp.getTabForBrowser(browser);
if (nativeTab) {
result.tabId = this.getId(nativeTab);
}
}
@ -258,15 +258,15 @@ class Tab extends TabBase {
}
get audible() {
return this.tab.playingAudio;
return this.nativeTab.playingAudio;
}
get browser() {
return this.tab.browser;
return this.nativeTab.browser;
}
get cookieStoreId() {
return getCookieStoreIdForTab(this, this.tab);
return getCookieStoreIdForTab(this, this.nativeTab);
}
get height() {
@ -278,7 +278,7 @@ class Tab extends TabBase {
}
get index() {
return this.window.BrowserApp.tabs.indexOf(this.tab);
return this.window.BrowserApp.tabs.indexOf(this.nativeTab);
}
get mutedInfo() {
@ -290,11 +290,11 @@ class Tab extends TabBase {
}
get active() {
return this.tab.getActive();
return this.nativeTab.getActive();
}
get selected() {
return this.tab.getActive();
return this.nativeTab.getActive();
}
get status() {
@ -357,8 +357,8 @@ class Window extends WindowBase {
* getTabs() {
let {tabManager} = this.extension;
for (let tab of this.window.BrowserApp.tabs) {
yield tabManager.getWrapper(tab);
for (let nativeTab of this.window.BrowserApp.tabs) {
yield tabManager.getWrapper(nativeTab);
}
}
}
@ -367,24 +367,24 @@ Object.assign(global, {Tab, Window});
class TabManager extends TabManagerBase {
get(tabId, default_ = undefined) {
let tab = tabTracker.getTab(tabId, default_);
let nativeTab = tabTracker.getTab(tabId, default_);
if (tab) {
return this.getWrapper(tab);
if (nativeTab) {
return this.getWrapper(nativeTab);
}
return default_;
}
addActiveTabPermission(tab = tabTracker.activeTab) {
return super.addActiveTabPermission(tab);
addActiveTabPermission(nativeTab = tabTracker.activeTab) {
return super.addActiveTabPermission(nativeTab);
}
revokeActiveTabPermission(tab = tabTracker.activeTab) {
return super.revokeActiveTabPermission(tab);
revokeActiveTabPermission(nativeTab = tabTracker.activeTab) {
return super.revokeActiveTabPermission(nativeTab);
}
wrapTab(tab) {
return new Tab(this.extension, tab, tab.id);
wrapTab(nativeTab) {
return new Tab(this.extension, nativeTab, nativeTab.id);
}
}

Просмотреть файл

@ -54,7 +54,7 @@ const {
* The extension object for which this wrapper is being created. Used to
* determine permissions for access to certain properties and
* functionality.
* @param {NativeTab} tab
* @param {NativeTab} nativeTab
* The native tab object which is being wrapped. The type of this object
* varies by platform.
* @param {integer} id
@ -62,11 +62,11 @@ const {
* every extension, and for the lifetime of the tab.
*/
class TabBase {
constructor(extension, tab, id) {
constructor(extension, nativeTab, id) {
this.extension = extension;
this.tabManager = extension.tabManager;
this.id = id;
this.tab = tab;
this.nativeTab = nativeTab;
this.activeTabWindowID = null;
}
@ -224,7 +224,7 @@ class TabBase {
* @readonly
*/
get _title() {
return this.browser.contentTitle || this.tab.label;
return this.browser.contentTitle || this.nativeTab.label;
}
@ -1020,14 +1020,14 @@ class TabTrackerBase extends EventEmitter {
/**
* Returns the numeric ID for the given native tab.
*
* @param {NativeTab} tab
* @param {NativeTab} nativeTab
* The native tab for which to return an ID.
*
* @returns {integer}
* The tab's numeric ID.
* @abstract
*/
getId(tab) {
getId(nativeTab) {
throw new Error("Not implemented");
}
@ -1556,16 +1556,16 @@ class TabManagerBase {
* If the extension has requested activeTab permission, grant it those
* permissions for the current inner window in the given native tab.
*
* @param {NativeTab} tab
* @param {NativeTab} nativeTab
* The native tab for which to grant permissions.
*/
addActiveTabPermission(tab) {
addActiveTabPermission(nativeTab) {
if (this.extension.hasPermission("activeTab")) {
// Note that, unlike Chrome, we don't currently clear this permission with
// the tab navigates. If the inner window is revived from BFCache before
// we've granted this permission to a new inner window, the extension
// maintains its permissions for it.
tab = this.getWrapper(tab);
let tab = this.getWrapper(nativeTab);
tab.activeTabWindowID = tab.innerWindowID;
}
}
@ -1574,24 +1574,24 @@ class TabManagerBase {
* Revoke the extension's activeTab permissions for the current inner window
* of the given native tab.
*
* @param {NativeTab} tab
* @param {NativeTab} nativeTab
* The native tab for which to revoke permissions.
*/
revokeActiveTabPermission(tab) {
this.getWrapper(tab).activeTabWindowID = null;
revokeActiveTabPermission(nativeTab) {
this.getWrapper(nativeTab).activeTabWindowID = null;
}
/**
* Returns true if the extension has requested activeTab permission, and has
* been granted permissions for the current inner window if this tab.
*
* @param {NativeTab} tab
* @param {NativeTab} nativeTab
* The native tab for which to check permissions.
* @returns {boolean}
* True if the extension has activeTab permissions for this tab.
*/
hasActiveTabPermission(tab) {
return this.getWrapper(tab).hasActiveTabPermission;
hasActiveTabPermission(nativeTab) {
return this.getWrapper(nativeTab).hasActiveTabPermission;
}
/**
@ -1600,27 +1600,27 @@ class TabManagerBase {
* either requested the "tabs" permission or has activeTab permissions for the
* given tab.
*
* @param {NativeTab} tab
* @param {NativeTab} nativeTab
* The native tab for which to check permissions.
* @returns {boolean}
* True if the extension has permissions for this tab.
*/
hasTabPermission(tab) {
return this.getWrapper(tab).hasTabPermission;
hasTabPermission(nativeTab) {
return this.getWrapper(nativeTab).hasTabPermission;
}
/**
* Returns this extension's TabBase wrapper for the given native tab. This
* method will always return the same wrapper object for any given native tab.
*
* @param {NativeTab} tab
* @param {NativeTab} nativeTab
* The tab for which to return a wrapper.
*
* @returns {TabBase}
* The wrapper for this tab.
*/
getWrapper(tab) {
return this._tabs.get(tab);
getWrapper(nativeTab) {
return this._tabs.get(nativeTab);
}
/**
@ -1628,13 +1628,13 @@ class TabManagerBase {
* requried to be returned by WebExtension APIs, which may be safely passed to
* extension code.
*
* @param {NativeTab} tab
* @param {NativeTab} nativeTab
* The native tab to convert.
*
* @returns {Object}
*/
convert(tab) {
return this.getWrapper(tab).convert();
convert(nativeTab) {
return this.getWrapper(nativeTab).convert();
}
// The JSDoc validator does not support @returns tags in abstract functions or
@ -1681,7 +1681,7 @@ class TabManagerBase {
/**
* Returns a new TabBase instance wrapping the given native tab.
*
* @param {NativeTab} tab
* @param {NativeTab} nativeTab
* The native tab for which to return a wrapper.
*
* @returns {TabBase}
@ -1689,7 +1689,7 @@ class TabManagerBase {
* @abstract
*/
/* eslint-enable valid-jsdoc */
wrapTab(tab) {
wrapTab(nativeTab) {
throw new Error("Not implemented");
}
}