Bug 1222516 part 1. Add a window API for opening a window with navigation and a given docshell loadinfo to use for the navigation. r=mconley

This will be used to pass through information like the triggering principal and
whatnot, as well as the boolean for not sending a referrer, for rel=noreferrer
links.
This commit is contained in:
Boris Zbarsky 2016-10-20 16:52:38 -04:00
parent 902033e592
commit c2d8d70720
8 changed files with 38 additions and 10 deletions

View File

@ -138,6 +138,7 @@ ImageAccessible::DoAction(uint8_t aIndex)
nsCOMPtr<nsPIDOMWindowOuter> tmp;
return NS_SUCCEEDED(piWindow->Open(spec, EmptyString(), EmptyString(),
/* aLoadInfo = */ nullptr,
getter_AddRefs(tmp)));
}

View File

@ -8139,9 +8139,10 @@ nsGlobalWindow::Open(const nsAString& aUrl, const nsAString& aName,
nsresult
nsGlobalWindow::Open(const nsAString& aUrl, const nsAString& aName,
const nsAString& aOptions, nsPIDOMWindowOuter **_retval)
const nsAString& aOptions, nsIDocShellLoadInfo* aLoadInfo,
nsPIDOMWindowOuter **_retval)
{
FORWARD_TO_OUTER(Open, (aUrl, aName, aOptions, _retval),
FORWARD_TO_OUTER(Open, (aUrl, aName, aOptions, aLoadInfo, _retval),
NS_ERROR_NOT_INITIALIZED);
return OpenInternal(aUrl, aName, aOptions,
false, // aDialog
@ -8150,6 +8151,7 @@ nsGlobalWindow::Open(const nsAString& aUrl, const nsAString& aName,
false, // aDoJSFixups
true, // aNavigate
nullptr, nullptr, // No args
aLoadInfo,
_retval);
}
@ -8165,6 +8167,7 @@ nsGlobalWindow::OpenJS(const nsAString& aUrl, const nsAString& aName,
true, // aDoJSFixups
true, // aNavigate
nullptr, nullptr, // No args
nullptr, // aLoadInfo
_retval);
}
@ -8183,7 +8186,8 @@ nsGlobalWindow::OpenDialog(const nsAString& aUrl, const nsAString& aName,
true, // aCalledNoScript
false, // aDoJSFixups
true, // aNavigate
nullptr, aExtraArgument, // Arguments
nullptr, aExtraArgument, // Arguments
nullptr, // aLoadInfo
_retval);
}
@ -8202,6 +8206,7 @@ nsGlobalWindow::OpenNoNavigate(const nsAString& aUrl,
false, // aDoJSFixups
false, // aNavigate
nullptr, nullptr, // No args
nullptr, // aLoadInfo
_retval);
}
@ -8230,6 +8235,7 @@ nsGlobalWindow::OpenDialogOuter(JSContext* aCx, const nsAString& aUrl,
false, // aDoJSFixups
true, // aNavigate
argvArray, nullptr, // Arguments
nullptr, // aLoadInfo
getter_AddRefs(dialog));
return dialog.forget();
}
@ -9314,6 +9320,7 @@ nsGlobalWindow::ShowModalDialogOuter(const nsAString& aUrl,
true, // aDoJSFixups
true, // aNavigate
nullptr, argHolder, // args
nullptr, // aLoadInfo
getter_AddRefs(dlgWin));
nsContentUtils::SetMicroTaskLevel(oldMicroTaskLevel);
LeaveModalState();
@ -11793,6 +11800,7 @@ nsGlobalWindow::OpenInternal(const nsAString& aUrl, const nsAString& aName,
bool aDoJSFixups, bool aNavigate,
nsIArray *argv,
nsISupports *aExtraArgument,
nsIDocShellLoadInfo* aLoadInfo,
nsPIDOMWindowOuter **aReturn)
{
MOZ_ASSERT(IsOuterWindow());
@ -11936,6 +11944,7 @@ nsGlobalWindow::OpenInternal(const nsAString& aUrl, const nsAString& aName,
aDialog, aNavigate, argv,
isPopupSpamWindow,
forceNoOpener,
aLoadInfo,
getter_AddRefs(domReturn));
} else {
// Force a system caller here so that the window watcher won't screw us
@ -11957,6 +11966,7 @@ nsGlobalWindow::OpenInternal(const nsAString& aUrl, const nsAString& aName,
aDialog, aNavigate, aExtraArgument,
isPopupSpamWindow,
forceNoOpener,
aLoadInfo,
getter_AddRefs(domReturn));
}

View File

@ -953,6 +953,7 @@ public:
mozilla::ErrorResult& aError);
nsresult Open(const nsAString& aUrl, const nsAString& aName,
const nsAString& aOptions,
nsIDocShellLoadInfo* aLoadInfo,
nsPIDOMWindowOuter **_retval) override;
mozilla::dom::Navigator* GetNavigator(mozilla::ErrorResult& aError);
nsIDOMNavigator* GetNavigator() override;
@ -1466,10 +1467,10 @@ private:
* three args, if present, will be aUrl, aName, and aOptions. So this
* param only matters if there are more than 3 arguments.
*
* @param argc The number of arguments in argv.
*
* @param aExtraArgument Another way to pass arguments in. This is mutually
* exclusive with the argv/argc approach.
* exclusive with the argv approach.
*
* @param aLoadInfo to be passed on along to the windowwatcher.
*
* @param aReturn [out] The window that was opened, if any.
*
@ -1485,6 +1486,7 @@ private:
bool aNavigate,
nsIArray *argv,
nsISupports *aExtraArgument,
nsIDocShellLoadInfo* aLoadInfo,
nsPIDOMWindowOuter **aReturn);
public:

View File

@ -26,6 +26,7 @@ class nsIArray;
class nsIContent;
class nsICSSDeclaration;
class nsIDocShell;
class nsIDocShellLoadInfo;
class nsIDocument;
class nsIIdleObserver;
class nsIPrincipal;
@ -549,8 +550,10 @@ public:
virtual already_AddRefed<nsISelection> GetSelection() = 0;
virtual already_AddRefed<nsPIDOMWindowOuter> GetOpener() = 0;
virtual already_AddRefed<nsIDOMWindowCollection> GetFrames() = 0;
// aLoadInfo will be passed on through to the windowwatcher.
virtual nsresult Open(const nsAString& aUrl, const nsAString& aName,
const nsAString& aOptions,
nsIDocShellLoadInfo* aLoadInfo,
nsPIDOMWindowOuter **_retval) = 0;
virtual nsresult OpenDialog(const nsAString& aUrl, const nsAString& aName,
const nsAString& aOptions,

View File

@ -613,6 +613,7 @@ private:
// opener anyway, and we _do_ want the returned
// window.
/* aForceNoOpener = */ false,
/* aLoadInfp = */ nullptr,
getter_AddRefs(newWindow));
nsCOMPtr<nsPIDOMWindowOuter> pwindow = nsPIDOMWindowOuter::From(newWindow);
pwindow.forget(aWindow);

View File

@ -17,6 +17,7 @@ interface nsIWebBrowserChrome;
interface nsIDocShellTreeItem;
interface nsIArray;
interface nsITabParent;
interface nsIDocShellLoadInfo;
[uuid(d162f9c4-19d5-4723-931f-f1e51bfa9f68)]
@ -61,6 +62,11 @@ interface nsPIWindowWatcher : nsISupports
looking for existing windows with the given name,
not setting an opener on the newly opened window,
and returning null from this method.
@param aLoadInfo if aNavigate is true, this allows the caller to pass in
an nsIDocShellLoadInfo to use for the navigation.
Callers can pass in null if they want the windowwatcher
to just construct a loadinfo itself. If aNavigate is
false, this argument is ignored.
@return the new window
@ -79,7 +85,8 @@ interface nsPIWindowWatcher : nsISupports
in boolean aNavigate,
in nsISupports aArgs,
in boolean aIsPopupSpam,
in boolean aForceNoOpener);
in boolean aForceNoOpener,
in nsIDocShellLoadInfo aLoadInfo);
/**
* Opens a new window using the most recent non-private browser

View File

@ -375,6 +375,7 @@ nsWindowWatcher::OpenWindow(mozIDOMWindowProxy* aParent,
/* navigate = */ true, argv,
/* aIsPopupSpam = */ false,
/* aForceNoOpener = */ false,
/* aLoadInfo = */ nullptr,
aResult);
}
@ -440,6 +441,7 @@ nsWindowWatcher::OpenWindow2(mozIDOMWindowProxy* aParent,
nsISupports* aArguments,
bool aIsPopupSpam,
bool aForceNoOpener,
nsIDocShellLoadInfo* aLoadInfo,
mozIDOMWindowProxy** aResult)
{
nsCOMPtr<nsIArray> argv = ConvertArgsToArray(aArguments);
@ -460,7 +462,7 @@ nsWindowWatcher::OpenWindow2(mozIDOMWindowProxy* aParent,
return OpenWindowInternal(aParent, aUrl, aName, aFeatures,
aCalledFromScript, dialog,
aNavigate, argv, aIsPopupSpam,
aForceNoOpener, aResult);
aForceNoOpener, aLoadInfo, aResult);
}
// This static function checks if the aDocShell uses an UserContextId equal to
@ -698,6 +700,7 @@ nsWindowWatcher::OpenWindowInternal(mozIDOMWindowProxy* aParent,
nsIArray* aArgv,
bool aIsPopupSpam,
bool aForceNoOpener,
nsIDocShellLoadInfo* aLoadInfo,
mozIDOMWindowProxy** aResult)
{
nsresult rv = NS_OK;
@ -1197,8 +1200,8 @@ nsWindowWatcher::OpenWindowInternal(mozIDOMWindowProxy* aParent,
}
}
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
if (uriToLoad && aNavigate) {
nsCOMPtr<nsIDocShellLoadInfo> loadInfo = aLoadInfo;
if (uriToLoad && aNavigate && !loadInfo) {
newDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);

View File

@ -88,6 +88,7 @@ protected:
nsIArray* aArgv,
bool aIsPopupSpam,
bool aForceNoOpener,
nsIDocShellLoadInfo* aLoadInfo,
mozIDOMWindowProxy** aResult);
static nsresult URIfromURL(const char* aURL,