Bug 849009 - Uplift Add-on SDK changeset 645b0ca71ccd41bb1fc69d97d22c456b03452e89

This commit is contained in:
Wes Kocher
2013-03-07 15:09:34 -08:00
parent 0fe59ae286
commit cba4c2a7c8
75 changed files with 1154 additions and 687 deletions

View File

@@ -8,9 +8,17 @@ module.metadata = {
'stability': 'unstable'
};
// NOTE: This file should only deal with xul/native tabs
const { Ci } = require('chrome');
const { defer } = require("../lang/functional");
const { windows, isBrowser } = require('../window/utils');
const { Ci } = require('chrome');
const { isPrivateBrowsingSupported } = require('../self');
// Bug 834961: ignore private windows when they are not supported
function getWindows() windows(null, { includePrivate: isPrivateBrowsingSupported });
function activateTab(tab, window) {
let gBrowser = getTabBrowserForTab(tab);
@@ -48,7 +56,7 @@ exports.getTabContainer = getTabContainer;
*/
function getTabs(window) {
if (arguments.length === 0) {
return windows().filter(isBrowser).reduce(function(tabs, window) {
return getWindows().filter(isBrowser).reduce(function(tabs, window) {
return tabs.concat(getTabs(window))
}, []);
}
@@ -63,7 +71,7 @@ function getTabs(window) {
exports.getTabs = getTabs;
function getActiveTab(window) {
return window.gBrowser.selectedTab;
return getSelectedTab(window);
}
exports.getActiveTab = getActiveTab;
@@ -79,7 +87,7 @@ exports.getOwnerWindow = getOwnerWindow;
// fennec
function getWindowHoldingTab(rawTab) {
for each (let window in windows()) {
for each (let window in getWindows()) {
// this function may be called when not using fennec,
// but BrowserApp is only defined on Fennec
if (!window.BrowserApp)
@@ -105,10 +113,13 @@ function openTab(window, url, options) {
isPrivate: options.isPrivate || false
});
}
let tab = window.gBrowser.addTab(url);
if (!options.inBackground)
activateTab(tab);
return tab;
// firefox
let newTab = window.gBrowser.addTab(url);
if (!options.inBackground) {
activateTab(newTab);
}
return newTab;
};
exports.openTab = openTab;
@@ -195,6 +206,7 @@ function getAllTabContentWindows() {
}
exports.getAllTabContentWindows = getAllTabContentWindows;
// gets the tab containing the provided window
function getTabForContentWindow(window) {
// Retrieve the topmost frame container. It can be either <xul:browser>,
// <xul:iframe/> or <html:iframe/>. But in our case, it should be xul:browser.
@@ -202,9 +214,12 @@ function getTabForContentWindow(window) {
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.chromeEventHandler;
// Is null for toplevel documents
if (!browser)
if (!browser) {
return false;
}
// Retrieve the owner window, should be browser.xul one
let chromeWindow = browser.ownerDocument.defaultView;
@@ -221,15 +236,29 @@ function getTabForContentWindow(window) {
return chromeWindow.gBrowser.tabs[i];
return null;
}
// Fennec
else if ('BrowserApp' in chromeWindow) {
// Looks like we are on Firefox Mobile
return chromeWindow.BrowserApp.getTabForWindow(window)
return getTabForWindow(window);
}
return null;
}
exports.getTabForContentWindow = getTabForContentWindow;
// used on fennec
function getTabForWindow(window) {
for each (let { BrowserApp } in getWindows()) {
if (!BrowserApp)
continue;
for each (let tab in BrowserApp.tabs) {
if (tab.browser.contentWindow == window.top)
return tab;
}
}
return null;
}
function getTabURL(tab) {
if (tab.browser) // fennec
return String(tab.browser.currentURI.spec);
@@ -262,3 +291,20 @@ function getSelectedTab(window) {
return null;
}
exports.getSelectedTab = getSelectedTab;
function getTabForBrowser(browser) {
for each (let window in getWindows()) {
// this function may be called when not using fennec
if (!window.BrowserApp)
continue;
for each (let tab in window.BrowserApp.tabs) {
if (tab.browser === browser)
return tab;
}
}
return null;
}
exports.getTabForBrowser = getTabForBrowser;