Bug 856322 Private Browsing changes for browser feed preview r=Neil.

Also: Remove useless prmem.h include.
This commit is contained in:
Philip Chee 2013-04-11 12:10:12 +08:00
Родитель b402315e6e
Коммит a5650f138b
7 изменённых файлов: 119 добавлений и 7 удалений

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

@ -75,6 +75,8 @@ _BROWSER_FILES = \
browser_selectTabAtIndex.js \
title_test.svg \
redirect_bug623155.sjs \
browser_privatebrowsing_protocolhandler.js \
browser_privatebrowsing_protocolhandler_page.html \
$(NULL)
ifneq (cocoa,$(MOZ_WIDGET_TOOLKIT))

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

@ -0,0 +1,65 @@
/* 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/. */
// This test makes sure that the web pages can't register protocol handlers
// inside the private browsing mode.
function test() {
// initialization
waitForExplicitFinish();
let windowsToClose = [];
let notificationValue = "Protocol Registration: testprotocol";
let testURI = "http://example.com/browser/" +
"suite/browser/test/browser_privatebrowsing_protocolhandler_page.html";
function doTest(aIsPrivateMode, aWindow, aCallback) {
aWindow.getBrowser().selectedBrowser.addEventListener("load", function onLoad() {
aWindow.getBrowser().selectedBrowser.removeEventListener("load", onLoad, true);
setTimeout(function() {
let notificationBox = aWindow.getBrowser().getNotificationBox();
let notification = notificationBox.getNotificationWithValue(notificationValue);
if (aIsPrivateMode) {
// Make sure the notification is correctly displayed without a remember control
ok(!notification, "Notification box should not be displayed inside of private browsing mode");
} else {
// Make sure the notification is correctly displayed with a remember control
ok(notification, "Notification box should be displaying outside of private browsing mode");
}
aCallback();
}, 100); // remember control is added in a setTimeout(0) call
}, true);
aWindow.getBrowser().selectedBrowser.loadURI(testURI);
}
function testOnWindow(aOptions, aCallback) {
whenNewWindowLoaded(aOptions, function(aWin) {
windowsToClose.push(aWin);
// execute should only be called when need, like when you are opening
// web pages on the test. If calling executeSoon() is not necesary, then
// call whenNewWindowLoaded() instead of testOnWindow() on your test.
executeSoon(function() aCallback(aWin));
});
};
// this function is called after calling finish() on the test.
registerCleanupFunction(function() {
windowsToClose.forEach(function(aWin) {
aWin.close();
});
});
// test first when not on private mode
testOnWindow({}, function(aWin) {
doTest(false, aWin, function() {
// then test when on private mode
testOnWindow({private: true}, function(aWin) {
doTest(true, aWin, finish);
});
});
});
}

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

@ -0,0 +1,13 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Protocol registrar page</title>
</head>
<body>
<script type="text/javascript">
navigator.registerProtocolHandler("testprotocol",
"https://example.com/foobar?uri=%s",
"Test Protocol");
</script>
</body>
</html>

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

@ -31,3 +31,15 @@ function waitForCondition(condition, nextTest, errorMsg) {
}, 100);
var moveOn = function() { clearInterval(interval); nextTest(); };
}
function whenNewWindowLoaded(aOptions, aCallback) {
var { private } = aOptions;
var features = private ? "private,chrome,all,dialog=no" :
"non-private,chrome,all,dialog=no";
var win = window.openDialog(getBrowserURL(), "_blank", features,
"about:blank");
win.addEventListener("load", function onLoad() {
win.removeEventListener("load", onLoad, false);
aCallback(win);
}, false);
}

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

@ -1319,8 +1319,14 @@ FeedWriter.prototype = {
}
let faviconURI = makeURI(readerURI.resolve("/favicon.ico"));
let self = this;
this._faviconService.setAndFetchFaviconForPage(readerURI, faviconURI, false,
this._faviconService.FAVICON_LOAD_NON_PRIVATE,
var isPB = this._window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell)
.QueryInterface(Components.interfaces.nsILoadContext)
.usePrivateBrowsing;
var flags = isPB ? this._faviconService.FAVICON_LOAD_PRIVATE :
this._faviconService.FAVICON_LOAD_NON_PRIVATE;
this._faviconService.setAndFetchFaviconForPage(readerURI, faviconURI, false, flags,
function(aURI, aDataLen, aData, aMimeType) {
if (aDataLen > 0) {
let dataURL = "data:" + aMimeType + ";base64," +

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

@ -367,9 +367,25 @@ WebContentConverterRegistrar.prototype = {
* See nsIWebContentHandlerRegistrar
*/
registerProtocolHandler: function registerProtocolHandler(aProtocol, aURIString,
aTitle, aContentWindow) {
aTitle, aContentWindow) {
LOG("registerProtocolHandler(" + aProtocol + "," + aURIString + "," + aTitle + ")");
var win = aContentWindow;
var isPB = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell)
.QueryInterface(Components.interfaces.nsILoadContext)
.usePrivateBrowsing;
if (isPB) {
// Inside the private browsing mode, we don't want to alert the user to save
// a protocol handler. We log it to the error console so that web developers
// would have some way to tell what's going wrong.
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.logStringMessage("Web page denied access to register a protocol handler inside private browsing mode");
return;
}
// First, check to make sure this isn't already handled internally (we don't
// want to let them take over, say "chrome").
var ios = Components.classes["@mozilla.org/network/io-service;1"]
@ -810,8 +826,8 @@ WebContentConverterRegistrar.prototype = {
classID: WCCR_CLASSID,
classInfo: XPCOMUtils.generateCI({
classID: WCCR_CLASSID,
contractID: WCCR_CONTRACTID,
classID: WCCR_CLASSID,
contractID: WCCR_CONTRACTID,
interfaces: [Components.interfaces.nsIWebContentConverterService,
Components.interfaces.nsIWebContentHandlerRegistrar,
Components.interfaces.nsIObserver,

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

@ -5,8 +5,6 @@
#include "nsFeedSniffer.h"
#include "prmem.h"
#include "nsNetCID.h"
#include "nsXPCOM.h"
#include "nsCOMPtr.h"