Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Bug 843438 - ignore private tabs on fennec when there is no private-browsing permission #856

Merged
merged 1 commit into from

2 participants

@ochameau
Owner

Need more testing and also an addon test.
https://bugzilla.mozilla.org/show_bug.cgi?id=843438

@ochameau
Owner

Finally there is no need for an additional test addon as we are already ensure that tabs are visible when private browsing flag is set and the test still pass...

@erikvold erikvold merged commit d320573 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 20, 2013
  1. @ochameau
This page is out of date. Refresh to see the latest.
View
6 lib/sdk/tabs/tab-fennec.js
@@ -7,7 +7,7 @@ const { Cc, Ci } = require('chrome');
const { Class } = require('../core/heritage');
const { tabNS, rawTabNS } = require('./namespace');
const { EventTarget } = require('../event/target');
-const { activateTab, getTabTitle, setTabTitle, closeTab, getTabURL, getContentWindowForTab,
+const { activateTab, getTabTitle, setTabTitle, closeTab, getTabURL, getTabContentWindow,
getTabForBrowser,
setTabURL, getOwnerWindow, getTabContentType, getTabId } = require('./utils');
const { emit } = require('../event/core');
@@ -129,7 +129,7 @@ const Tab = Class({
// BUG 792946 https://bugzilla.mozilla.org/show_bug.cgi?id=792946
// TODO: fix this circular dependency
let { Worker } = require('./worker');
- return Worker(options, tabNS(this).tab.browser.contentWindow);
+ return Worker(options, getTabContentWindow(tabNS(this).tab));
},
/**
@@ -194,5 +194,5 @@ function onTabClose(event) {
};
getPBOwnerWindow.define(Tab, function(tab) {
- return getContentWindowForTab(tabNS(tab).tab);
+ return getTabContentWindow(tabNS(tab).tab);
});
View
6 lib/sdk/tabs/utils.js
@@ -166,12 +166,6 @@ function getBrowserForTab(tab) {
}
exports.getBrowserForTab = getBrowserForTab;
-
-function getContentWindowForTab(tab) {
- return getBrowserForTab(tab).contentWindow;
-}
-exports.getContentWindowForTab = getContentWindowForTab;
-
function getTabId(tab) {
if (tab.browser) // fennec
return tab.id
View
19 lib/sdk/windows/tabs-fennec.js
@@ -8,7 +8,8 @@ const { Tab } = require('../tabs/tab');
const { browserWindows } = require('./fennec');
const { windowNS } = require('../window/namespace');
const { tabsNS, tabNS } = require('../tabs/namespace');
-const { openTab, getTabs, getSelectedTab, getTabForBrowser: getRawTabForBrowser } = require('../tabs/utils');
+const { openTab, getTabs, getSelectedTab, getTabForBrowser: getRawTabForBrowser,
+ getTabContentWindow } = require('../tabs/utils');
const { Options } = require('../tabs/common');
const { getTabForBrowser, getTabForRawTab } = require('../tabs/helpers');
const { on, once, off, emit } = require('../event/core');
@@ -18,8 +19,8 @@ const { EventTarget } = require('../event/target');
const { when: unload } = require('../system/unload');
const { windowIterator } = require('../deprecated/window-utils');
const { List, addListItem, removeListItem } = require('../util/list');
-const { isPrivateBrowsingSupported } = require('sdk/self');
-const { isTabPBSupported } = require('sdk/private-browsing/utils');
+const { isPrivateBrowsingSupported } = require('../self');
+const { isTabPBSupported, ignoreWindow } = require('../private-browsing/utils');
const mainWindow = windowNS(browserWindows.activeWindow).window;
@@ -113,6 +114,10 @@ function removeTab(tab) {
function onTabOpen(event) {
let browser = event.target;
+ // Eventually ignore private tabs
+ if (ignoreWindow(browser.contentWindow))
+ return;
+
let tab = getTabForBrowser(browser);
if (tab === null) {
let rawTab = getRawTabForBrowser(browser);
@@ -132,8 +137,14 @@ function onTabOpen(event) {
// TabSelect
function onTabSelect(event) {
+ let browser = event.target;
+
+ // Eventually ignore private tabs
+ if (ignoreWindow(browser.contentWindow))
+ return;
+
// Set value whenever new tab becomes active.
- let tab = getTabForBrowser(event.target);
+ let tab = getTabForBrowser(browser);
emit(tab, 'activate', tab);
emit(gTabs, 'activate', tab);
View
2  lib/sdk/windows/tabs-firefox.js
@@ -16,7 +16,7 @@ const { getOwnerWindow, getActiveTab, getTabs,
openTab } = require("../tabs/utils");
const { Options } = require("../tabs/common");
const { observer: tabsObserver } = require("../tabs/observer");
-const { ignoreWindow, isWindowPrivate } = require("../private-browsing/utils");
+const { ignoreWindow } = require("../private-browsing/utils");
const TAB_BROWSER = "tabbrowser";
View
42 test/private-browsing/helper.js
@@ -9,6 +9,11 @@ const { loader } = LoaderWithHookedConsole(module);
const pb = loader.require('sdk/private-browsing');
const pbUtils = loader.require('sdk/private-browsing/utils');
+const xulApp = require("sdk/system/xul-app");
+const { openDialog, getMostRecentBrowserWindow } = require('sdk/window/utils');
+const { openTab, getTabContentWindow, getActiveTab, setTabURL, closeTab } = require('sdk/tabs/utils');
+const promise = require("sdk/core/promise");
+const windowHelpers = require('sdk/window/helpers');
function LoaderWithHookedConsole(module) {
let globals = {};
@@ -45,3 +50,40 @@ exports.deactivate = deactivate;
exports.pb = pb;
exports.pbUtils = pbUtils;
exports.LoaderWithHookedConsole = LoaderWithHookedConsole;
+
+exports.openWebpage = function openWebpage(url, enablePrivate) {
+ if (xulApp.is("Fennec")) {
+ let chromeWindow = getMostRecentBrowserWindow();
+ let rawTab = openTab(chromeWindow, url, {
+ isPrivate: enablePrivate
+ });
+ return {
+ ready: promise.resolve(getTabContentWindow(rawTab)),
+ close: function () {
+ closeTab(rawTab);
+ // Returns a resolved promise as there is no need to wait
+ return promise.resolve();
+ }
+ };
+ }
+ else {
+ let win = openDialog({
+ private: enablePrivate
+ });
+ let deferred = promise.defer();
+ win.addEventListener("load", function onLoad() {
+ win.removeEventListener("load", onLoad, false);
+
+ let rawTab = getActiveTab(win);
+ setTabURL(rawTab, url);
+ deferred.resolve(getTabContentWindow(rawTab));
+ });
+ return {
+ ready: deferred.promise,
+ close: function () {
+ return windowHelpers.close(win);
+ }
+ };
+ }
+ return null;
+}
View
36 test/test-page-mod.js
@@ -9,15 +9,15 @@ const { Loader } = require('sdk/test/loader');
const tabs = require("sdk/tabs");
const timer = require("sdk/timers");
const { Cc, Ci } = require("chrome");
-const { open, openDialog, getFrames, getMostRecentBrowserWindow } = require('sdk/window/utils');
+const { open, getFrames, getMostRecentBrowserWindow } = require('sdk/window/utils');
const windowUtils = require('sdk/deprecated/window-utils');
-const windowHelpers = require('sdk/window/helpers');
const { getTabContentWindow, getActiveTab, setTabURL, openTab, closeTab } = require('sdk/tabs/utils');
const xulApp = require("sdk/system/xul-app");
const { data } = require('sdk/self');
const { isPrivate } = require('sdk/private-browsing');
const { isTabPBSupported, isWindowPBSupported } = require('sdk/private-browsing/utils');
-const promise = require("sdk/core/promise");
+const { openWebpage } = require('./private-browsing/helper');
+
/* XXX This can be used to delay closing the test Firefox instance for interactive
* testing or visual inspection. This test is registered first so that it runs
@@ -1055,36 +1055,6 @@ exports.testEvents = function(test) {
);
};
-function openWebpage(url, enablePrivate) {
- if (xulApp.is("Fennec")) {
- let chromeWindow = getMostRecentBrowserWindow();
- let rawTab = openTab(chromeWindow, url, {
- isPrivate: enablePrivate
- });
- return {
- close: function () {
- closeTab(rawTab)
- // Returns a resolved promise as there is no need to wait
- return promise.resolve();
- }
- };
- }
- else {
- let win = openDialog({
- private: enablePrivate
- });
- win.addEventListener("load", function onLoad() {
- win.removeEventListener("load", onLoad, false);
- setTabURL(getActiveTab(win), url);
- });
- return {
- close: function () {
- return windowHelpers.close(win);
- }
- };
- }
-}
-
exports["test page-mod on private tab"] = function (test) {
test.waitUntilDone();
let privateUri = "data:text/html;charset=utf-8," +
View
36 test/test-tabs-common.js
@@ -8,9 +8,10 @@ const { browserWindows } = require('sdk/windows');
const tabs = require('sdk/tabs');
const { isPrivate } = require('sdk/private-browsing');
const { openDialog } = require('sdk/window/utils');
-const pbUtils = require('sdk/private-browsing/utils');
const { isWindowPrivate } = require('sdk/window/utils');
const { setTimeout } = require('sdk/timers');
+const { openWebpage } = require('./private-browsing/helper');
+const { isTabPBSupported, isWindowPBSupported } = require('sdk/private-browsing/utils');
const URL = 'data:text/html;charset=utf-8,<html><head><title>#title#</title></head></html>';
@@ -323,34 +324,27 @@ exports.testTabOpenPrivate = function(test) {
// We need permission flag in order to see private window's tabs
exports.testPrivateAreNotListed = function (test) {
- test.waitUntilDone();
let originalTabCount = tabs.length;
- let win = openDialog({
- private: true
- });
-
- win.addEventListener("load", function onload() {
- win.removeEventListener("load", onload);
+ let page = openWebpage("about:blank", true);
+ if (!page) {
+ test.pass("Private browsing isn't supported in this release");
+ return;
+ }
- // PWPB case
- if (pbUtils.isWindowPBSupported) {
- test.assert(isWindowPrivate(win), "window is private");
+ test.waitUntilDone();
+ page.ready.then(function (win) {
+ if (isTabPBSupported || isWindowPBSupported) {
+ test.assert(isWindowPrivate(win), "the window is private");
test.assertEqual(tabs.length, originalTabCount,
- 'New private window\'s tab isn\'t visible in tabs list');
+ 'but the tab is *not* visible in tabs list');
}
else {
- // Global case, openDialog didn't opened a private window/tab
- test.assert(!isWindowPrivate(win), "window is private");
+ test.assert(!isWindowPrivate(win), "the window isn't private");
test.assertEqual(tabs.length, originalTabCount + 1,
- 'New non-private window\'s tab is visible in tabs list');
+ 'so that the tab is visible is tabs list');
}
-
- win.addEventListener("unload", function onunload() {
- win.removeEventListener('unload', onunload);
- test.done();
- });
- win.close();
+ page.close().then(test.done.bind(test));
});
}
Something went wrong with that request. Please try again.