Skip to content
Permalink
Browse files

first batch to transition nsIDOMWindow to nsPIDOMWindow at about TenF…

…ourFox level
  • Loading branch information...
rmottola committed Dec 18, 2018
1 parent c325946 commit dba07065a9a9543f772dd98ff3d3358e72ce3c32
@@ -307,16 +307,15 @@ nsDSURIContentListener::CheckOneFrameOptionsPolicy(nsIHttpChannel* aHttpChannel,
// window, if we're not the top. X-F-O: SAMEORIGIN requires that the
// document must be same-origin with top window. X-F-O: DENY requires that
// the document must never be framed.
nsCOMPtr<nsIDOMWindow> thisWindow = mDocShell->GetWindow();
nsCOMPtr<nsPIDOMWindow> thisWindow = mDocShell->GetWindow();
// If we don't have DOMWindow there is no risk of clickjacking
if (!thisWindow) {
return true;
}

// GetScriptableTop, not GetTop, because we want this to respect
// <iframe mozbrowser> boundaries.
nsCOMPtr<nsIDOMWindow> topWindow;
thisWindow->GetScriptableTop(getter_AddRefs(topWindow));
nsCOMPtr<nsPIDOMWindow> topWindow = thisWindow->GetScriptableTop();

// if the document is in the top window, it's not in a frame.
if (thisWindow == topWindow) {
@@ -3189,7 +3189,7 @@ nsDocShell::GetSessionStorageForPrincipal(nsIPrincipal* aPrincipal,
return NS_ERROR_UNEXPECTED;
}

nsCOMPtr<nsIDOMWindow> domWin = do_GetInterface(GetAsSupports(this));
nsCOMPtr<nsPIDOMWindow> domWin = do_GetInterface(GetAsSupports(this));

if (aCreate) {
return manager->CreateStorage(domWin, aPrincipal, aDocumentURI,
@@ -3697,7 +3697,7 @@ nsDocShell::CanAccessItem(nsIDocShellTreeItem* aTargetItem,
return false;
}

nsCOMPtr<nsIDOMWindow> targetWindow = aTargetItem->GetWindow();
nsCOMPtr<nsPIDOMWindow> targetWindow = aTargetItem->GetWindow();
if (!targetWindow) {
NS_ERROR("This should not happen, really");
return false;
@@ -3718,7 +3718,7 @@ nsDocShell::CanAccessItem(nsIDocShellTreeItem* aTargetItem,
static bool
ItemIsActive(nsIDocShellTreeItem* aItem)
{
nsCOMPtr<nsIDOMWindow> window = aItem->GetWindow();
nsCOMPtr<nsPIDOMWindow> window = aItem->GetWindow();

if (window) {
bool isClosed;
@@ -3978,7 +3978,7 @@ PrintDocTree(nsIDocShellTreeItem* aParentNode, int aLevel)
parentAsDocShell->GetPresContext(getter_AddRefs(presContext));
nsIDocument* doc = presShell->GetDocument();

nsCOMPtr<nsIDOMWindow> domwin(doc->GetWindow());
nsCOMPtr<nsPIDOMWindow> domwin(doc->GetWindow());

nsCOMPtr<nsIWidget> widget;
nsViewManager* vm = presShell->GetViewManager();
@@ -9940,7 +9940,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
// So, the best we can do, is to tear down the new window
// that was just created!
//
nsCOMPtr<nsIDOMWindow> domWin = targetDocShell->GetWindow();
nsCOMPtr<nsPIDOMWindow> domWin = targetDocShell->GetWindow();
if (domWin) {
domWin->Close();
}
@@ -13205,34 +13205,31 @@ nsDocShell::GetAssociatedWindow(nsIDOMWindow** aWindow)
NS_IMETHODIMP
nsDocShell::GetTopWindow(nsIDOMWindow** aWindow)
{
nsCOMPtr<nsIDOMWindow> win = GetWindow();
nsCOMPtr<nsPIDOMWindow> win = GetWindow();
if (win) {
win->GetTop(aWindow);
win = win->GetTop();
}
win.forget(aWindow);
return NS_OK;
}

NS_IMETHODIMP
nsDocShell::GetTopFrameElement(nsIDOMElement** aElement)
{
*aElement = nullptr;
nsCOMPtr<nsIDOMWindow> win = GetWindow();
nsCOMPtr<nsPIDOMWindow> win = GetWindow();
if (!win) {
return NS_OK;
}

nsCOMPtr<nsIDOMWindow> top;
win->GetScriptableTop(getter_AddRefs(top));
nsCOMPtr<nsPIDOMWindow> top = win->GetScriptableTop();
NS_ENSURE_TRUE(top, NS_ERROR_FAILURE);

nsCOMPtr<nsPIDOMWindow> piTop = do_QueryInterface(top);
NS_ENSURE_TRUE(piTop, NS_ERROR_FAILURE);

// GetFrameElementInternal, /not/ GetScriptableFrameElement -- if |top| is
// inside <iframe mozbrowser>, we want to return the iframe, not null.
// And we want to cross the content/chrome boundary.
nsCOMPtr<nsIDOMElement> elt =
do_QueryInterface(piTop->GetFrameElementInternal());
do_QueryInterface(top->GetFrameElementInternal());
elt.forget(aElement);
return NS_OK;
}
@@ -13347,7 +13344,7 @@ nsDocShell::EnsureCommandHandler()
return NS_ERROR_OUT_OF_MEMORY;
}

nsCOMPtr<nsIDOMWindow> domWindow = GetWindow();
nsCOMPtr<nsPIDOMWindow> domWindow = GetWindow();
nsresult rv = commandUpdater->Init(domWindow);
if (NS_SUCCEEDED(rv)) {
mCommandManager = do_QueryInterface(commandUpdater);
@@ -138,13 +138,12 @@ ThirdPartyUtil::IsThirdPartyWindow(nsIDOMWindow* aWindow,
}
}

nsCOMPtr<nsIDOMWindow> current = aWindow, parent;
nsCOMPtr<nsPIDOMWindow> current = do_QueryInterface(aWindow), parent;
nsCOMPtr<nsIURI> parentURI;
do {
// We use GetScriptableParent rather than GetParent because we consider
// <iframe mozbrowser/mozapp> to be a top-level frame.
rv = current->GetScriptableParent(getter_AddRefs(parent));
NS_ENSURE_SUCCESS(rv, rv);
parent = current->GetScriptableParent();

if (SameCOMIdentity(parent, current)) {
// We're at the topmost content window. We already know the answer.
@@ -267,13 +266,14 @@ ThirdPartyUtil::IsThirdPartyChannel(nsIChannel* aChannel,
// to the channel. This is limited to loads of certain types of resources. If
// those loads require cookies, the forceAllowThirdPartyCookie property should
// be set on the channel.
nsCOMPtr<nsIDOMWindow> ourWin, parentWin;
nsCOMPtr<nsIDOMWindow> ourWin;
ctx->GetAssociatedWindow(getter_AddRefs(ourWin));
if (!ourWin) return NS_ERROR_INVALID_ARG;

// We use GetScriptableParent rather than GetParent because we consider
// <iframe mozbrowser/mozapp> to be a top-level frame.
ourWin->GetScriptableParent(getter_AddRefs(parentWin));
nsCOMPtr<nsPIDOMWindow> ourPWin = do_QueryInterface(ourWin);
nsCOMPtr<nsPIDOMWindow> parentWin = ourPWin->GetScriptableParent();
NS_ENSURE_TRUE(parentWin, NS_ERROR_INVALID_ARG);

// Check whether this is the document channel for this window (representing a
@@ -311,7 +311,6 @@ ThirdPartyUtil::GetTopWindowForChannel(nsIChannel* aChannel, nsIDOMWindow** aWin
{
NS_ENSURE_ARG(aWin);

nsresult rv;
// Find the associated window and its parent window.
nsCOMPtr<nsILoadContext> ctx;
NS_QueryNotificationCallbacks(aChannel, ctx);
@@ -320,13 +319,15 @@ ThirdPartyUtil::GetTopWindowForChannel(nsIChannel* aChannel, nsIDOMWindow** aWin
}

nsCOMPtr<nsIDOMWindow> window;
rv = ctx->GetAssociatedWindow(getter_AddRefs(window));
ctx->GetAssociatedWindow(getter_AddRefs(window));
nsCOMPtr<nsPIDOMWindow> top = do_QueryInterface(window);
if (!window) {
return NS_ERROR_INVALID_ARG;
}

rv = window->GetTop(aWin);
return rv;
top = top->GetTop();
top.forget(aWin);
return NS_OK;
}

// Get the base domain for aHostURI; e.g. for "www.bbc.co.uk", this would be
@@ -6759,7 +6759,7 @@ nsContentUtils::GetFullscreenAncestor(nsIDocument* aDoc)

/* static */
bool
nsContentUtils::IsInPointerLockContext(nsIDOMWindow* aWin)
nsContentUtils::IsInPointerLockContext(nsPIDOMWindow* aWin)
{
if (!aWin) {
return false;
@@ -6771,11 +6771,8 @@ nsContentUtils::IsInPointerLockContext(nsIDOMWindow* aWin)
return false;
}

nsCOMPtr<nsIDOMWindow> lockTop;
pointerLockedDoc->GetWindow()->GetScriptableTop(getter_AddRefs(lockTop));

nsCOMPtr<nsIDOMWindow> top;
aWin->GetScriptableTop(getter_AddRefs(top));
nsCOMPtr<nsPIDOMWindow> lockTop = pointerLockedDoc->GetWindow()->GetScriptableTop();
nsCOMPtr<nsPIDOMWindow> top = aWin->GetScriptableTop();

return top == lockTop;
}
@@ -2035,7 +2035,7 @@ class nsContentUtils
* Returns true if aWin and the current pointer lock document
* have common scriptable top window.
*/
static bool IsInPointerLockContext(nsIDOMWindow* aWin);
static bool IsInPointerLockContext(nsPIDOMWindow* aWin);

/**
* Returns the time limit on handling user input before
@@ -12325,18 +12325,15 @@ nsDocument::ShouldLockPointer(Element* aElement, Element* aCurrentLock,
return false;
}

nsCOMPtr<nsIDOMWindow> top;
ownerWindow->GetScriptableTop(getter_AddRefs(top));
nsCOMPtr<nsPIDOMWindow> piTop = do_QueryInterface(top);
if (!piTop || !piTop->GetExtantDoc() ||
piTop->GetExtantDoc()->Hidden()) {
nsCOMPtr<nsPIDOMWindow> top = ownerWindow->GetScriptableTop();
if (!top || !top->GetExtantDoc() || top->GetExtantDoc()->Hidden()) {
NS_WARNING("ShouldLockPointer(): Top document isn't visible.");
return false;
}

if (!aNoFocusCheck) {
mozilla::ErrorResult rv;
if (!piTop->GetExtantDoc()->HasFocus(rv)) {
if (!top->GetExtantDoc()->HasFocus(rv)) {
NS_WARNING("ShouldLockPointer(): Top document isn't focused.");
return false;
}
@@ -12899,10 +12896,7 @@ nsAutoSyncOperation::nsAutoSyncOperation(nsIDocument* aDoc)
if (aDoc) {
nsPIDOMWindow* win = aDoc->GetWindow();
if (win) {
nsCOMPtr<nsIDOMWindow> topWindow;
win->GetTop(getter_AddRefs(topWindow));
nsCOMPtr<nsPIDOMWindow> top = do_QueryInterface(topWindow);
if (top) {
if (nsCOMPtr<nsPIDOMWindow> top = win->GetTop()) {
nsCOMPtr<nsIDocument> doc = top->GetExtantDoc();
MarkDocumentTreeToBeInSyncOperation(doc, &mDocuments);
}
Oops, something went wrong.

2 comments on commit dba0706

@roytam1

This comment has been minimized.

Copy link

roytam1 replied Jan 10, 2019

@rmottola accessible part is missing, proposed patch:

diff --git a/accessible/generic/ImageAccessible.cpp b/accessible/generic/ImageAccessible.cpp
index 5fb0d5953..50efc7720 100644
--- a/accessible/generic/ImageAccessible.cpp
+++ b/accessible/generic/ImageAccessible.cpp
@@ -133,12 +133,11 @@ ImageAccessible::DoAction(uint8_t aIndex)
 
   nsIDocument* document = mContent->OwnerDoc();
   nsCOMPtr<nsPIDOMWindow> piWindow = document->GetWindow();
-  nsCOMPtr<nsIDOMWindow> win = do_QueryInterface(piWindow);
-  if (!win)
+  if (!piWindow)
     return false;
 
-  nsCOMPtr<nsIDOMWindow> tmp;
-  return NS_SUCCEEDED(win->Open(spec, EmptyString(), EmptyString(),
+  nsCOMPtr<nsPIDOMWindow> tmp;
+  return NS_SUCCEEDED(piWindow->Open(spec, EmptyString(), EmptyString(),
                                 /* aLoadInfo = */ nullptr,
 				/* aForceNoOpener = */ false,
                                 getter_AddRefs(tmp)));

@rmottola

This comment has been minimized.

Copy link
Contributor Author

rmottola replied Jan 11, 2019

@roytam1 patch commited and pushed on my fork.

Please sign in to comment.
You can’t perform that action at this time.