Skip to content

Commit 7b32a7d

Browse files
committed
Bug 1616353 - Part 7.2: Create and use nsOpenWindowInfo types in nsWindowWatcher logic, r=kmag
This patch builds on top of part 7.1 by creating this object within nsWindowWatcher and ContentParent to carry the relevant information through provider interfaces when creating new content windows. The nsOpenWindowInfo object is not created for new chrome windows. This patch does not propagate these flags all of the way through to the nsFrameLoader. That change is performed in later parts to keep each part smaller. Differential Revision: https://phabricator.services.mozilla.com/D67051
1 parent 20da588 commit 7b32a7d

22 files changed

+354
-333
lines changed

dom/base/nsOpenURIInFrameParams.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
66

77
#include "nsOpenURIInFrameParams.h"
8+
#include "nsIOpenWindowInfo.h"
89
#include "mozilla/BasePrincipal.h"
910
#include "mozilla/dom/Element.h"
1011
#include "mozilla/dom/ToJSValue.h"
@@ -20,12 +21,17 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(nsOpenURIInFrameParams)
2021
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsOpenURIInFrameParams)
2122

2223
nsOpenURIInFrameParams::nsOpenURIInFrameParams(
23-
const mozilla::OriginAttributes& aOriginAttributes,
24-
mozilla::dom::Element* aOpener)
25-
: mOpenerOriginAttributes(aOriginAttributes), mOpenerBrowser(aOpener) {}
24+
nsIOpenWindowInfo* aOpenWindowInfo, mozilla::dom::Element* aOpener)
25+
: mOpenWindowInfo(aOpenWindowInfo), mOpenerBrowser(aOpener) {}
2626

2727
nsOpenURIInFrameParams::~nsOpenURIInFrameParams() = default;
2828

29+
NS_IMETHODIMP
30+
nsOpenURIInFrameParams::GetOpenWindowInfo(nsIOpenWindowInfo** aOpenWindowInfo) {
31+
NS_IF_ADDREF(*aOpenWindowInfo = mOpenWindowInfo);
32+
return NS_OK;
33+
}
34+
2935
NS_IMETHODIMP
3036
nsOpenURIInFrameParams::GetReferrerInfo(nsIReferrerInfo** aReferrerInfo) {
3137
NS_IF_ADDREF(*aReferrerInfo = mReferrerInfo);
@@ -41,7 +47,7 @@ nsOpenURIInFrameParams::SetReferrerInfo(nsIReferrerInfo* aReferrerInfo) {
4147
NS_IMETHODIMP
4248
nsOpenURIInFrameParams::GetIsPrivate(bool* aIsPrivate) {
4349
NS_ENSURE_ARG_POINTER(aIsPrivate);
44-
*aIsPrivate = mOpenerOriginAttributes.mPrivateBrowsingId > 0;
50+
*aIsPrivate = mOpenWindowInfo->GetOriginAttributes().mPrivateBrowsingId > 0;
4551
return NS_OK;
4652
}
4753

@@ -83,7 +89,5 @@ nsresult nsOpenURIInFrameParams::GetOpenerBrowser(
8389
NS_IMETHODIMP
8490
nsOpenURIInFrameParams::GetOpenerOriginAttributes(
8591
JSContext* aCx, JS::MutableHandle<JS::Value> aValue) {
86-
bool ok = ToJSValue(aCx, mOpenerOriginAttributes, aValue);
87-
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
88-
return NS_OK;
92+
return mOpenWindowInfo->GetScriptableOriginAttributes(aCx, aValue);
8993
}

dom/base/nsOpenURIInFrameParams.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ class nsOpenURIInFrameParams final : public nsIOpenURIInFrameParams {
2626
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
2727
NS_DECL_NSIOPENURIINFRAMEPARAMS
2828

29-
explicit nsOpenURIInFrameParams(
30-
const mozilla::OriginAttributes& aOriginAttributes,
31-
mozilla::dom::Element* aOpener);
29+
explicit nsOpenURIInFrameParams(nsIOpenWindowInfo* aOpenWindowInfo,
30+
mozilla::dom::Element* aOpener);
3231

3332
private:
3433
~nsOpenURIInFrameParams();
3534

36-
mozilla::OriginAttributes mOpenerOriginAttributes;
35+
nsCOMPtr<nsIOpenWindowInfo> mOpenWindowInfo;
3736
RefPtr<mozilla::dom::Element> mOpenerBrowser;
3837
nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
3938
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;

dom/interfaces/base/nsIBrowserDOMWindow.idl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ interface nsIURI;
1111
interface nsIPrincipal;
1212
interface nsIContentSecurityPolicy;
1313
interface nsIReferrerInfo;
14+
interface nsIOpenWindowInfo;
1415
webidl BrowsingContext;
1516
webidl Element;
1617

1718
[scriptable, uuid(e774db14-79ac-4156-a7a3-aa3fd0a22c10)]
1819
interface nsIOpenURIInFrameParams : nsISupports
1920
{
21+
readonly attribute nsIOpenWindowInfo openWindowInfo;
22+
2023
attribute nsIReferrerInfo referrerInfo;
2124
readonly attribute boolean isPrivate;
2225
attribute nsIPrincipal triggeringPrincipal;
@@ -107,7 +110,7 @@ interface nsIBrowserDOMWindow : nsISupports
107110

108111
* @param aURI the URI to be opened in the window (can be null).
109112
* @param aWhere see possible values described above.
110-
* @param aOpener window requesting the creation (can be null).
113+
* @param aOpenWindowInfo info about the creation (can be null).
111114
* @param aFlags flags which control the behavior of the load. The
112115
* OPEN_EXTERNAL/OPEN_NEW flag is only used when
113116
* aWhere == OPEN_DEFAULTWINDOW.
@@ -117,7 +120,7 @@ interface nsIBrowserDOMWindow : nsISupports
117120
* @return the window into which the URI would have been opened.
118121
*/
119122
BrowsingContext
120-
createContentWindow(in nsIURI aURI, in mozIDOMWindowProxy aOpener,
123+
createContentWindow(in nsIURI aURI, in nsIOpenWindowInfo aOpenWindowInfo,
121124
in short aWhere, in long aFlags,
122125
in nsIPrincipal aTriggeringPrincipal,
123126
[optional] in nsIContentSecurityPolicy aCsp);
@@ -127,14 +130,12 @@ interface nsIBrowserDOMWindow : nsISupports
127130
* returned as Element, QI'd back to nsFrameLoaderOwner as needed.
128131
*
129132
* Additional Parameters:
130-
* @param aNextRemoteTabId The RemoteTab to associate the window with.
131133
* @param aName The name to give the window opened in the new tab.
132134
* @return The frame element for the newly opened window.
133135
*/
134136
Element
135137
createContentWindowInFrame(in nsIURI aURI, in nsIOpenURIInFrameParams params,
136138
in short aWhere, in long aFlags,
137-
in unsigned long long aNextRemoteTabId,
138139
in AString aName);
139140

140141
/**
@@ -143,7 +144,7 @@ interface nsIBrowserDOMWindow : nsISupports
143144
* @param aURI the URI to open. null is not allowed. To create the window
144145
* without loading the URI, use createContentWindow instead.
145146
* @param aWhere see possible values described above.
146-
* @param aOpener window requesting the open (can be null).
147+
* @param aOpenWindowInfo info about the open (can be null).
147148
* @param aFlags flags which control the behavior of the load. The
148149
* OPEN_EXTERNAL/OPEN_NEW flag is only used when
149150
* aWhere == OPEN_DEFAULTWINDOW.
@@ -152,7 +153,7 @@ interface nsIBrowserDOMWindow : nsISupports
152153
* @return the window into which the URI was opened.
153154
*/
154155
BrowsingContext
155-
openURI(in nsIURI aURI, in mozIDOMWindowProxy aOpener,
156+
openURI(in nsIURI aURI, in nsIOpenWindowInfo aOpenWindowInfo,
156157
in short aWhere, in long aFlags, in nsIPrincipal aTriggeringPrincipal,
157158
[optional] in nsIContentSecurityPolicy aCsp);
158159

@@ -161,7 +162,6 @@ interface nsIBrowserDOMWindow : nsISupports
161162
* returned as Element, QI'd back to nsFrameLoaderOwner as needed.
162163
*
163164
* Additional Parameters:
164-
* @param aNextRemoteTabId The RemoteTab to associate the window with.
165165
* @param aName The name to give the window opened in the new tab.
166166
* @return The frame element for the newly opened window.
167167
// XXXbz is this the right API?
@@ -170,7 +170,6 @@ interface nsIBrowserDOMWindow : nsISupports
170170
Element
171171
openURIInFrame(in nsIURI aURI, in nsIOpenURIInFrameParams params,
172172
in short aWhere, in long aFlags,
173-
in unsigned long long aNextRemoteTabId,
174173
in AString aName);
175174

176175
/**

dom/ipc/BrowserChild.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
#include "nsIWebProgress.h"
117117
#include "nsLayoutUtils.h"
118118
#include "nsNetUtil.h"
119+
#include "nsIOpenWindowInfo.h"
119120
#include "nsPIDOMWindow.h"
120121
#include "nsPIWindowRoot.h"
121122
#include "nsPointerHashKeys.h"
@@ -868,19 +869,21 @@ BrowserChild::GetInterface(const nsIID& aIID, void** aSink) {
868869
}
869870

870871
NS_IMETHODIMP
871-
BrowserChild::ProvideWindow(mozIDOMWindowProxy* aParent, uint32_t aChromeFlags,
872-
bool aCalledFromJS, bool aWidthSpecified,
873-
nsIURI* aURI, const nsAString& aName,
874-
const nsACString& aFeatures, bool aForceNoOpener,
875-
bool aForceNoReferrer,
872+
BrowserChild::ProvideWindow(nsIOpenWindowInfo* aOpenWindowInfo,
873+
uint32_t aChromeFlags, bool aCalledFromJS,
874+
bool aWidthSpecified, nsIURI* aURI,
875+
const nsAString& aName, const nsACString& aFeatures,
876+
bool aForceNoOpener, bool aForceNoReferrer,
876877
nsDocShellLoadState* aLoadState, bool* aWindowIsNew,
877878
BrowsingContext** aReturn) {
878879
*aReturn = nullptr;
879880

880-
// If aParent is inside an <iframe mozbrowser> and this isn't a request to
881+
RefPtr<BrowsingContext> parent = aOpenWindowInfo->GetParent();
882+
883+
// If parent is inside an <iframe mozbrowser> and this isn't a request to
881884
// open a modal-type window, we're going to create a new <iframe mozbrowser>
882885
// and return its window here.
883-
nsCOMPtr<nsIDocShell> docshell = do_GetInterface(aParent);
886+
nsCOMPtr<nsIDocShell> docshell = parent->GetDocShell();
884887
bool iframeMoz =
885888
(docshell && docshell->GetIsInMozBrowser() &&
886889
!(aChromeFlags & (nsIWebBrowserChrome::CHROME_MODAL |
@@ -889,8 +892,7 @@ BrowserChild::ProvideWindow(mozIDOMWindowProxy* aParent, uint32_t aChromeFlags,
889892

890893
if (!iframeMoz) {
891894
int32_t openLocation = nsWindowWatcher::GetWindowOpenLocation(
892-
nsPIDOMWindowOuter::From(aParent), aChromeFlags, aCalledFromJS,
893-
aWidthSpecified);
895+
parent->GetDOMWindow(), aChromeFlags, aCalledFromJS, aWidthSpecified);
894896

895897
// If it turns out we're opening in the current browser, just hand over the
896898
// current browser's docshell.
@@ -912,7 +914,7 @@ BrowserChild::ProvideWindow(mozIDOMWindowProxy* aParent, uint32_t aChromeFlags,
912914
// open window call was canceled. It's important that we pass this error
913915
// code back to our caller.
914916
ContentChild* cc = ContentChild::GetSingleton();
915-
return cc->ProvideWindowCommon(this, aParent, iframeMoz, aChromeFlags,
917+
return cc->ProvideWindowCommon(this, aOpenWindowInfo, iframeMoz, aChromeFlags,
916918
aCalledFromJS, aWidthSpecified, aURI, aName,
917919
aFeatures, aForceNoOpener, aForceNoReferrer,
918920
aLoadState, aWindowIsNew, aReturn);

0 commit comments

Comments
 (0)