Skip to content

Commit

Permalink
Bug 1616353 - Part 7.2: Create and use nsOpenWindowInfo types in nsWi…
Browse files Browse the repository at this point in the history
…ndowWatcher 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
  • Loading branch information
mystor committed Apr 7, 2020
1 parent 20da588 commit 7b32a7d
Show file tree
Hide file tree
Showing 22 changed files with 354 additions and 333 deletions.
18 changes: 11 additions & 7 deletions dom/base/nsOpenURIInFrameParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsOpenURIInFrameParams.h"
#include "nsIOpenWindowInfo.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ToJSValue.h"
Expand All @@ -20,12 +21,17 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(nsOpenURIInFrameParams)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsOpenURIInFrameParams)

nsOpenURIInFrameParams::nsOpenURIInFrameParams(
const mozilla::OriginAttributes& aOriginAttributes,
mozilla::dom::Element* aOpener)
: mOpenerOriginAttributes(aOriginAttributes), mOpenerBrowser(aOpener) {}
nsIOpenWindowInfo* aOpenWindowInfo, mozilla::dom::Element* aOpener)
: mOpenWindowInfo(aOpenWindowInfo), mOpenerBrowser(aOpener) {}

nsOpenURIInFrameParams::~nsOpenURIInFrameParams() = default;

NS_IMETHODIMP
nsOpenURIInFrameParams::GetOpenWindowInfo(nsIOpenWindowInfo** aOpenWindowInfo) {
NS_IF_ADDREF(*aOpenWindowInfo = mOpenWindowInfo);
return NS_OK;
}

NS_IMETHODIMP
nsOpenURIInFrameParams::GetReferrerInfo(nsIReferrerInfo** aReferrerInfo) {
NS_IF_ADDREF(*aReferrerInfo = mReferrerInfo);
Expand All @@ -41,7 +47,7 @@ nsOpenURIInFrameParams::SetReferrerInfo(nsIReferrerInfo* aReferrerInfo) {
NS_IMETHODIMP
nsOpenURIInFrameParams::GetIsPrivate(bool* aIsPrivate) {
NS_ENSURE_ARG_POINTER(aIsPrivate);
*aIsPrivate = mOpenerOriginAttributes.mPrivateBrowsingId > 0;
*aIsPrivate = mOpenWindowInfo->GetOriginAttributes().mPrivateBrowsingId > 0;
return NS_OK;
}

Expand Down Expand Up @@ -83,7 +89,5 @@ nsresult nsOpenURIInFrameParams::GetOpenerBrowser(
NS_IMETHODIMP
nsOpenURIInFrameParams::GetOpenerOriginAttributes(
JSContext* aCx, JS::MutableHandle<JS::Value> aValue) {
bool ok = ToJSValue(aCx, mOpenerOriginAttributes, aValue);
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
return NS_OK;
return mOpenWindowInfo->GetScriptableOriginAttributes(aCx, aValue);
}
7 changes: 3 additions & 4 deletions dom/base/nsOpenURIInFrameParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ class nsOpenURIInFrameParams final : public nsIOpenURIInFrameParams {
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIOPENURIINFRAMEPARAMS

explicit nsOpenURIInFrameParams(
const mozilla::OriginAttributes& aOriginAttributes,
mozilla::dom::Element* aOpener);
explicit nsOpenURIInFrameParams(nsIOpenWindowInfo* aOpenWindowInfo,
mozilla::dom::Element* aOpener);

private:
~nsOpenURIInFrameParams();

mozilla::OriginAttributes mOpenerOriginAttributes;
nsCOMPtr<nsIOpenWindowInfo> mOpenWindowInfo;
RefPtr<mozilla::dom::Element> mOpenerBrowser;
nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
Expand Down
15 changes: 7 additions & 8 deletions dom/interfaces/base/nsIBrowserDOMWindow.idl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ interface nsIURI;
interface nsIPrincipal;
interface nsIContentSecurityPolicy;
interface nsIReferrerInfo;
interface nsIOpenWindowInfo;
webidl BrowsingContext;
webidl Element;

[scriptable, uuid(e774db14-79ac-4156-a7a3-aa3fd0a22c10)]
interface nsIOpenURIInFrameParams : nsISupports
{
readonly attribute nsIOpenWindowInfo openWindowInfo;

attribute nsIReferrerInfo referrerInfo;
readonly attribute boolean isPrivate;
attribute nsIPrincipal triggeringPrincipal;
Expand Down Expand Up @@ -107,7 +110,7 @@ interface nsIBrowserDOMWindow : nsISupports

* @param aURI the URI to be opened in the window (can be null).
* @param aWhere see possible values described above.
* @param aOpener window requesting the creation (can be null).
* @param aOpenWindowInfo info about the creation (can be null).
* @param aFlags flags which control the behavior of the load. The
* OPEN_EXTERNAL/OPEN_NEW flag is only used when
* aWhere == OPEN_DEFAULTWINDOW.
Expand All @@ -117,7 +120,7 @@ interface nsIBrowserDOMWindow : nsISupports
* @return the window into which the URI would have been opened.
*/
BrowsingContext
createContentWindow(in nsIURI aURI, in mozIDOMWindowProxy aOpener,
createContentWindow(in nsIURI aURI, in nsIOpenWindowInfo aOpenWindowInfo,
in short aWhere, in long aFlags,
in nsIPrincipal aTriggeringPrincipal,
[optional] in nsIContentSecurityPolicy aCsp);
Expand All @@ -127,14 +130,12 @@ interface nsIBrowserDOMWindow : nsISupports
* returned as Element, QI'd back to nsFrameLoaderOwner as needed.
*
* Additional Parameters:
* @param aNextRemoteTabId The RemoteTab to associate the window with.
* @param aName The name to give the window opened in the new tab.
* @return The frame element for the newly opened window.
*/
Element
createContentWindowInFrame(in nsIURI aURI, in nsIOpenURIInFrameParams params,
in short aWhere, in long aFlags,
in unsigned long long aNextRemoteTabId,
in AString aName);

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

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

/**
Expand Down
22 changes: 12 additions & 10 deletions dom/ipc/BrowserChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
#include "nsIWebProgress.h"
#include "nsLayoutUtils.h"
#include "nsNetUtil.h"
#include "nsIOpenWindowInfo.h"
#include "nsPIDOMWindow.h"
#include "nsPIWindowRoot.h"
#include "nsPointerHashKeys.h"
Expand Down Expand Up @@ -868,19 +869,21 @@ BrowserChild::GetInterface(const nsIID& aIID, void** aSink) {
}

NS_IMETHODIMP
BrowserChild::ProvideWindow(mozIDOMWindowProxy* aParent, uint32_t aChromeFlags,
bool aCalledFromJS, bool aWidthSpecified,
nsIURI* aURI, const nsAString& aName,
const nsACString& aFeatures, bool aForceNoOpener,
bool aForceNoReferrer,
BrowserChild::ProvideWindow(nsIOpenWindowInfo* aOpenWindowInfo,
uint32_t aChromeFlags, bool aCalledFromJS,
bool aWidthSpecified, nsIURI* aURI,
const nsAString& aName, const nsACString& aFeatures,
bool aForceNoOpener, bool aForceNoReferrer,
nsDocShellLoadState* aLoadState, bool* aWindowIsNew,
BrowsingContext** aReturn) {
*aReturn = nullptr;

// If aParent is inside an <iframe mozbrowser> and this isn't a request to
RefPtr<BrowsingContext> parent = aOpenWindowInfo->GetParent();

// If parent is inside an <iframe mozbrowser> and this isn't a request to
// open a modal-type window, we're going to create a new <iframe mozbrowser>
// and return its window here.
nsCOMPtr<nsIDocShell> docshell = do_GetInterface(aParent);
nsCOMPtr<nsIDocShell> docshell = parent->GetDocShell();
bool iframeMoz =
(docshell && docshell->GetIsInMozBrowser() &&
!(aChromeFlags & (nsIWebBrowserChrome::CHROME_MODAL |
Expand All @@ -889,8 +892,7 @@ BrowserChild::ProvideWindow(mozIDOMWindowProxy* aParent, uint32_t aChromeFlags,

if (!iframeMoz) {
int32_t openLocation = nsWindowWatcher::GetWindowOpenLocation(
nsPIDOMWindowOuter::From(aParent), aChromeFlags, aCalledFromJS,
aWidthSpecified);
parent->GetDOMWindow(), aChromeFlags, aCalledFromJS, aWidthSpecified);

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

0 comments on commit 7b32a7d

Please sign in to comment.