Bug 1305352 - (Part 1) Make Presentation API support XUL browser element. r?smaug
MozReview-Commit-ID: 9t5mhvcbpXB
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -14243,16 +14243,30 @@ nsDocShell::GetIsInIsolatedMozBrowserEle
/* [infallible] */ NS_IMETHODIMP
nsDocShell::GetIsInMozBrowserOrApp(bool* aIsInMozBrowserOrApp)
{
*aIsInMozBrowserOrApp = (GetInheritedFrameType() != FRAME_TYPE_REGULAR);
return NS_OK;
}
/* [infallible] */ NS_IMETHODIMP
+nsDocShell::GetIsTopLevelContentDocShell(bool* aIsTopLevelContentDocShell)
+{
+ *aIsTopLevelContentDocShell = false;
+
+ if (mItemType == typeContent) {
+ nsCOMPtr<nsIDocShellTreeItem> root;
+ GetSameTypeRootTreeItem(getter_AddRefs(root));
+ *aIsTopLevelContentDocShell = root.get() == static_cast<nsIDocShellTreeItem*>(this);
+ }
+
+ return NS_OK;
+}
+
+/* [infallible] */ NS_IMETHODIMP
nsDocShell::GetAppId(uint32_t* aAppId)
{
if (mOriginAttributes.mAppId != nsIScriptSecurityManager::UNKNOWN_APP_ID) {
*aAppId = mOriginAttributes.mAppId;
return NS_OK;
}
nsCOMPtr<nsIDocShell> parent;
--- a/docshell/base/nsIDocShell.idl
+++ b/docshell/base/nsIDocShell.idl
@@ -847,16 +847,21 @@ interface nsIDocShell : nsIDocShellTreeI
*
* To compute this value, we walk up the docshell hierarchy. If we encounter
* a docshell with isMozBrowserOrApp before we hit the end of the hierarchy,
* we return true. Otherwise, we return false.
*/
[infallible] readonly attribute boolean isInMozBrowserOrApp;
/**
+ * Returns true if this docshell is the top level content docshell.
+ */
+ [infallible] readonly attribute boolean isTopLevelContentDocShell;
+
+ /**
* Returns the id of the app associated with this docshell. If this docshell
* is an <iframe mozbrowser> inside an <iframe mozapp>, we return the app's
* appId.
*
* We compute this value by walking up the docshell hierarchy until we find a
* docshell on which origin attributes was set. (ignoring those docshells
* where x == UNKNOWN_APP_ID). We return the app id x.
*
--- a/dom/presentation/Presentation.cpp
+++ b/dom/presentation/Presentation.cpp
@@ -127,17 +127,18 @@ Presentation::HasReceiverSupport() const
// Grant access to browser receiving pages and their same-origin iframes. (App
// pages should be controlled by "presentation" permission in app manifests.)
nsCOMPtr<nsIDocShell> docShell = mWindow->GetDocShell();
if (!docShell) {
return false;
}
if (!Preferences::GetBool("dom.presentation.testing.simulate-receiver") &&
- !docShell->GetIsInMozBrowserOrApp()) {
+ !docShell->GetIsInMozBrowserOrApp() &&
+ !docShell->GetIsTopLevelContentDocShell()) {
return false;
}
nsAutoString presentationURL;
nsContentUtils::GetPresentationURL(docShell, presentationURL);
if (presentationURL.IsEmpty()) {
return false;
--- a/dom/presentation/PresentationSessionInfo.cpp
+++ b/dom/presentation/PresentationSessionInfo.cpp
@@ -1597,18 +1597,19 @@ PresentationPresentingInfo::ResolvedCall
JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
if (NS_WARN_IF(!obj)) {
ReplyError(NS_ERROR_DOM_OPERATION_ERR);
return;
}
// Start to listen to document state change event |STATE_TRANSFERRING|.
- HTMLIFrameElement* frame = nullptr;
- nsresult rv = UNWRAP_OBJECT(HTMLIFrameElement, obj, frame);
+ // Use Element to support both HTMLIFrameElement and nsXULElement.
+ Element* frame = nullptr;
+ nsresult rv = UNWRAP_OBJECT(Element, obj, frame);
if (NS_WARN_IF(!frame)) {
ReplyError(NS_ERROR_DOM_OPERATION_ERR);
return;
}
nsCOMPtr<nsIFrameLoaderOwner> owner = do_QueryInterface((nsIFrameLoaderOwner*) frame);
if (NS_WARN_IF(!owner)) {
ReplyError(NS_ERROR_DOM_OPERATION_ERR);