Bug 1305352 - (Part 1) Make Presentation API support XUL browser element. r=smaug
authorKuoE0 <kuoe0.tw@gmail.com>
Thu, 27 Oct 2016 11:27:41 +0800
changeset 351922 a64e70dc94f7aa147c33c2a2c92efd9fddd006f4
parent 351921 0a2c98b982b9e3dd04521535e5b9a34ad9f49b9e
child 351923 47f86091deddd87636138843bad95f3168637217
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1305352
milestone52.0a1
Bug 1305352 - (Part 1) Make Presentation API support XUL browser element. r=smaug MozReview-Commit-ID: 9t5mhvcbpXB
docshell/base/nsDocShell.cpp
docshell/base/nsIDocShell.idl
dom/presentation/Presentation.cpp
dom/presentation/PresentationSessionInfo.cpp
--- 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);