SSL ext-tabs.js
Interaktion und PortierbarkeitJAVA
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ /* vim: set sts=2 sw=2 et tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Now we are certain that the first page in the tab was loaded. this.initializingTabs.delete(tab);
// browser.innerWindowID is now set, resolve the promises if any. const deferred = this.tabReadyPromises.get(tab); if (deferred) {
deferred.resolve(tab); this.tabReadyPromises.delete(tab);
}
}
},
/** * Returns a promise that resolves when the tab is ready. * Tabs created via the `tabs.create` method are "ready" once the location * changes to the requested URL. Other tabs are assumed to be ready once their * inner window ID is known. * * @param {NativeTab} nativeTab The native tab object. * @returns {Promise} Resolves with the given tab once ready.
*/
awaitTabReady(nativeTab) {
let deferred = this.tabReadyPromises.get(nativeTab); if (!deferred) {
deferred = Promise.withResolvers(); if (
!this.initializingTabs.has(nativeTab) &&
(nativeTab.browser.innerWindowID ||
nativeTab.browser.currentURI.spec === "about:blank")
) {
deferred.resolve(nativeTab);
} else { this.initTabReady(); this.tabReadyPromises.set(nativeTab, deferred);
}
} return deferred.promise;
},
};
function sanitize(tab, changeInfo) { const result = {};
let nonempty = false; for (const prop in changeInfo) { // In practice, changeInfo contains at most one property from // restricted. Therefore it is not necessary to cache the value // of tab.hasTabPermission outside the loop. if (!restricted.includes(prop) || tab.hasTabPermission) {
nonempty = true;
result[prop] = changeInfo[prop];
}
} return [nonempty, result];
}
function getTabOrActive(tabId) { if (tabId !== null) { return tabTracker.getTab(tabId);
} return tabTracker.activeTab;
}
async function promiseTabWhenReady(tabId) {
let tab; if (tabId !== null) {
tab = tabManager.get(tabId);
} else {
tab = tabManager.getWrapper(tabTracker.activeTab);
} if (!tab) { thrownew ExtensionError(
tabId == null ? "Cannot access activeTab" : `Invalid tab ID: ${tabId}`
);
}
await tabListener.awaitTabReady(tab.nativeTab);
return tab;
}
function loadURIInTab(nativeTab, url) { const { browser } = nativeTab;
let loadFlags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
let { principal } = context; const isAboutUrl = url.startsWith("about:"); if (
isAboutUrl ||
(url.startsWith("moz-extension://") &&
!context.checkLoadURL(url, { dontReportErrors: true }))
) { // Falling back to content here as about: requires it, however is safe.
principal =
Services.scriptSecurityManager.getLoadContextContentPrincipal(
Services.io.newURI(url),
browser.loadContext
);
} if (isAboutUrl) { // Make sure things like about:blank and other about: URIs never // inherit, and instead always get a NullPrincipal.
loadFlags |= Ci.nsIWebNavigation.LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL;
}
onCreated: new EventManager({
context,
module,
event: "onCreated",
extensionApi,
}).api(),
/** * Since multiple tabs currently can't be highlighted, onHighlighted * essentially acts an alias for tabs.onActivated but returns * the tabId in an array to match the API. * * @see https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/Tabs/onHighlighted
*/
onHighlighted: makeGlobalEvent(
context, "tabs.onHighlighted", "Tab:Selected",
(fire, data) => { const tab = tabManager.get(data.id);
// Some events below are not be persisted because they are not implemented. // They do not have an "extensionApi" property with an entry in // PERSISTENT_EVENTS, but instead an empty "register" method.
onAttached: new EventManager({
context,
name: "tabs.onAttached",
register: () => { return () => {};
},
}).api(),
// Make sure things like about:blank URIs never inherit, // and instead always get a NullPrincipal. if (url !== null) {
tabListener.initializingTabs.add(nativeTab);
} else {
url = "about:blank";
}
loadURIInTab(nativeTab, url);
if (active) { const newWindow = nativeTab.browser.ownerGlobal;
mobileWindowTracker.setTabActive(newWindow, true);
}
return tabManager.convert(nativeTab);
},
async remove(tabs) { if (!Array.isArray(tabs)) {
tabs = [tabs];
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.