diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index fdf4fbd4dbcae..32e6c0e3de6e6 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -2424,38 +2424,40 @@ Navigator::HasPresentationSupport(JSContext* aCx, JSObject* aGlobal) // Grant access to browser receiving pages and their same-origin iframes. (App // pages should be controlled by "presentation" permission in app manifests.) - nsCOMPtr docshell = inner->GetDocShell(); - if (!docshell) { + mozilla::dom::ContentChild* cc = + mozilla::dom::ContentChild::GetSingleton(); + if (!cc || !cc->IsForBrowser()) { return false; } - if (!docshell->GetIsInMozBrowserOrApp()) { + nsCOMPtr win = inner->GetOuterWindow(); + nsCOMPtr top = win->GetTop(); + nsCOMPtr sop = do_QueryInterface(win); + nsCOMPtr topSop = do_QueryInterface(top); + if (!sop || !topSop) { return false; } - nsAutoString presentationURL; - nsContentUtils::GetPresentationURL(docshell, presentationURL); - - if (presentationURL.IsEmpty()) { + nsIPrincipal* principal = sop->GetPrincipal(); + nsIPrincipal* topPrincipal = topSop->GetPrincipal(); + if (!principal || !topPrincipal || !principal->Subsumes(topPrincipal)) { return false; } - nsCOMPtr securityManager = - do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID); - if (!securityManager) { + nsCOMPtr topInner; + if (!(topInner = top->GetCurrentInnerWindow())) { return false; } - nsCOMPtr presentationURI; - nsresult rv = NS_NewURI(getter_AddRefs(presentationURI), presentationURL); - if (NS_FAILED(rv)) { + nsCOMPtr presentationService = + do_GetService(PRESENTATION_SERVICE_CONTRACTID); + if (NS_WARN_IF(!presentationService)) { return false; } - nsCOMPtr docURI = inner->GetDocumentURI(); - return NS_SUCCEEDED(securityManager->CheckSameOriginURI(presentationURI, - docURI, - false)); + nsAutoString sessionId; + presentationService->GetExistentSessionIdAtLaunch(topInner->WindowID(), sessionId); + return !sessionId.IsEmpty(); } /* static */ diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index a35256103f643..38a33ab0535e5 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -114,7 +114,6 @@ #include "nsIDOMDocument.h" #include "nsIDOMDocumentType.h" #include "nsIDOMEvent.h" -#include "nsIDOMElement.h" #include "nsIDOMHTMLElement.h" #include "nsIDOMHTMLFormElement.h" #include "nsIDOMHTMLInputElement.h" @@ -204,7 +203,6 @@ #include "mozilla/EnumSet.h" #include "mozilla/BloomFilter.h" #include "SourceSurfaceRawData.h" -#include "TabChild.h" #include "nsIBidiKeyboard.h" @@ -8848,31 +8846,3 @@ nsContentUtils::SetScrollbarsVisibility(nsIDocShell* aDocShell, bool aVisible) nsIScrollable::ScrollOrientation_X, prefValue); } } - -/* static */ void -nsContentUtils::GetPresentationURL(nsIDocShell* aDocShell, nsAString& aPresentationUrl) -{ - MOZ_ASSERT(aDocShell); - - if (XRE_IsContentProcess()) { - nsCOMPtr sameTypeRoot; - aDocShell->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot)); - nsCOMPtr root; - aDocShell->GetRootTreeItem(getter_AddRefs(root)); - if (sameTypeRoot.get() == root.get()) { - // presentation URL is stored in TabChild for the top most - //