Bug 1058116 - Pass referrer and isPrivate to openURIInFrame instead of nullptr as aOpener. r=mconley, r=smaug, r=Margaret, r=ally

This commit is contained in:
Tomasz Kołodziejski 2014-11-06 09:41:00 -05:00
parent c05416ed8b
commit 6d25ef2447
9 changed files with 101 additions and 17 deletions

View File

@ -4551,15 +4551,14 @@ function nsBrowserAccess() { }
nsBrowserAccess.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIBrowserDOMWindow, Ci.nsISupports]),
_openURIInNewTab: function(aURI, aOpener, aIsExternal) {
_openURIInNewTab: function(aURI, aReferrer, aIsPrivate, aIsExternal) {
let win, needToFocusWin;
// try the current window. if we're in a popup, fall back on the most recent browser window
if (window.toolbar.visible)
win = window;
else {
let isPrivate = PrivateBrowsingUtils.isWindowPrivate(aOpener || window);
win = RecentWindow.getMostRecentBrowserWindow({private: isPrivate});
win = RecentWindow.getMostRecentBrowserWindow({private: aIsPrivate});
needToFocusWin = true;
}
@ -4575,10 +4574,9 @@ nsBrowserAccess.prototype = {
}
let loadInBackground = gPrefService.getBoolPref("browser.tabs.loadDivertedInBackground");
let referrer = aOpener ? makeURI(aOpener.location.href) : null;
let tab = win.gBrowser.loadOneTab(aURI ? aURI.spec : "about:blank", {
referrerURI: referrer,
referrerURI: aReferrer,
fromExternal: aIsExternal,
inBackground: loadInBackground});
let browser = win.gBrowser.getBrowserForTab(tab);
@ -4615,7 +4613,9 @@ nsBrowserAccess.prototype = {
newWindow = openDialog(getBrowserURL(), "_blank", "all,dialog=no", url, null, null, null);
break;
case Ci.nsIBrowserDOMWindow.OPEN_NEWTAB :
let browser = this._openURIInNewTab(aURI, aOpener, isExternal);
let referrer = aOpener ? makeURI(aOpener.location.href) : null;
let isPrivate = PrivateBrowsingUtils.isWindowPrivate(aOpener || window);
let browser = this._openURIInNewTab(aURI, referrer, isPrivate, isExternal);
if (browser)
newWindow = browser.contentWindow;
break;
@ -4634,14 +4634,14 @@ nsBrowserAccess.prototype = {
return newWindow;
},
openURIInFrame: function browser_openURIInFrame(aURI, aOpener, aWhere, aContext) {
openURIInFrame: function browser_openURIInFrame(aURI, aParams, aWhere, aContext) {
if (aWhere != Ci.nsIBrowserDOMWindow.OPEN_NEWTAB) {
dump("Error: openURIInFrame can only open in new tabs");
return null;
}
var isExternal = (aContext == Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL);
let browser = this._openURIInNewTab(aURI, aOpener, isExternal);
let browser = this._openURIInNewTab(aURI, aParams.referrer, aParams.isPrivate, isExternal);
if (browser)
return browser.QueryInterface(Ci.nsIFrameLoaderOwner);

View File

@ -123,7 +123,7 @@ chatBrowserAccess.prototype = {
return browser ? browser.contentWindow : null;
},
openURIInFrame: function browser_openURIInFrame(aURI, aOpener, aWhere, aContext) {
openURIInFrame: function browser_openURIInFrame(aURI, aParams, aWhere, aContext) {
let browser = this._openURIInNewTab(aURI, aWhere);
return browser ? browser.QueryInterface(Ci.nsIFrameLoaderOwner) : null;
},

View File

@ -1079,8 +1079,8 @@ nsBrowserAccess.prototype = {
return browser ? browser.contentWindow : null;
},
openURIInFrame: function browser_openURIInFrame(aURI, aOpener, aWhere, aContext) {
let browser = this._getBrowser(aURI, aOpener, aWhere, aContext);
openURIInFrame: function browser_openURIInFrame(aURI, aParams, aWhere, aContext) {
let browser = this._getBrowser(aURI, null, aWhere, aContext);
return browser ? browser.QueryInterface(Ci.nsIFrameLoaderOwner) : null;
},

View File

@ -293,6 +293,7 @@ UNIFIED_SOURCES += [
'nsNoDataProtocolContentPolicy.cpp',
'nsNodeInfoManager.cpp',
'nsNodeUtils.cpp',
'nsOpenURIInFrameParams.cpp',
'nsPerformance.cpp',
'nsPlainTextSerializer.cpp',
'nsPropertyTable.cpp',

View File

@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsOpenURIInFrameParams.h"
NS_IMPL_ISUPPORTS(nsOpenURIInFrameParams, nsIOpenURIInFrameParams)
nsOpenURIInFrameParams::nsOpenURIInFrameParams() :
mIsPrivate(false)
{
}
nsOpenURIInFrameParams::~nsOpenURIInFrameParams() {
}
/* attribute DOMString referrer; */
NS_IMETHODIMP
nsOpenURIInFrameParams::GetReferrer(nsAString& aReferrer)
{
aReferrer = mReferrer;
return NS_OK;
}
NS_IMETHODIMP
nsOpenURIInFrameParams::SetReferrer(const nsAString& aReferrer)
{
mReferrer = aReferrer;
return NS_OK;
}
/* attribute boolean isPrivate; */
NS_IMETHODIMP
nsOpenURIInFrameParams::GetIsPrivate(bool* aIsPrivate)
{
NS_ENSURE_ARG_POINTER(aIsPrivate);
*aIsPrivate = mIsPrivate;
return NS_OK;
}
NS_IMETHODIMP
nsOpenURIInFrameParams::SetIsPrivate(bool aIsPrivate)
{
mIsPrivate = aIsPrivate;
return NS_OK;
}

View File

@ -0,0 +1,21 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "nsIBrowserDOMWindow.h"
#include "nsString.h"
class nsOpenURIInFrameParams MOZ_FINAL : public nsIOpenURIInFrameParams
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOPENURIINFRAMEPARAMS
nsOpenURIInFrameParams();
private:
~nsOpenURIInFrameParams();
nsString mReferrer;
bool mIsPrivate;
};

View File

@ -9,7 +9,15 @@ interface nsIDOMWindow;
interface nsIURI;
interface nsIFrameLoaderOwner;
[scriptable, uuid(699b8f60-2898-11e4-8c21-0800200c9a66)]
[scriptable, uuid(e774db14-79ac-4156-a7a3-aa3fd0a22c10)]
interface nsIOpenURIInFrameParams : nsISupports
{
attribute DOMString referrer;
attribute boolean isPrivate;
};
[scriptable, uuid(99f5a347-722c-4337-bd38-f14ec94801b3)]
/**
* The C++ source has access to the browser script source through
@ -80,10 +88,10 @@ interface nsIBrowserDOMWindow : nsISupports
/**
* As above, but return the nsIFrameLoaderOwner for the new window.
// XXXbz is this the right API? Do we really need the opener here?
// XXXbz is this the right API?
// See bug 537428
*/
nsIFrameLoaderOwner openURIInFrame(in nsIURI aURI, in nsIDOMWindow aOpener,
nsIFrameLoaderOwner openURIInFrame(in nsIURI aURI, in nsIOpenURIInFrameParams params,
in short aWhere, in short aContext);
/**

View File

@ -50,6 +50,7 @@
#include "nsViewManager.h"
#include "nsIWidget.h"
#include "nsIWindowWatcher.h"
#include "nsOpenURIInFrameParams.h"
#include "nsPIDOMWindow.h"
#include "nsPIWindowWatcher.h"
#include "nsPresShell.h"
@ -441,8 +442,16 @@ TabParent::AnswerCreateWindow(const uint32_t& aChromeFlags,
if (openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB) {
NS_ENSURE_TRUE(mBrowserDOMWindow, false);
bool isPrivate;
nsCOMPtr<nsILoadContext> loadContext = GetLoadContext();
loadContext->GetUsePrivateBrowsing(&isPrivate);
nsCOMPtr<nsIOpenURIInFrameParams> params = new nsOpenURIInFrameParams();
params->SetReferrer(aBaseURI);
params->SetIsPrivate(isPrivate);
nsCOMPtr<nsIFrameLoaderOwner> frameLoaderOwner;
mBrowserDOMWindow->OpenURIInFrame(nullptr, nullptr,
mBrowserDOMWindow->OpenURIInFrame(nullptr, params,
nsIBrowserDOMWindow::OPEN_NEWTAB,
nsIBrowserDOMWindow::OPEN_NEW,
getter_AddRefs(frameLoaderOwner));

View File

@ -3115,8 +3115,8 @@ nsBrowserAccess.prototype = {
return browser ? browser.contentWindow : null;
},
openURIInFrame: function browser_openURIInFrame(aURI, aOpener, aWhere, aContext) {
let browser = this._getBrowser(aURI, aOpener, aWhere, aContext);
openURIInFrame: function browser_openURIInFrame(aURI, aParams, aWhere, aContext) {
let browser = this._getBrowser(aURI, null, aWhere, aContext);
return browser ? browser.QueryInterface(Ci.nsIFrameLoaderOwner) : null;
},