Bug 1350642 - Part 2 - WIP - Perform resize tab-count-check in RecvSetDimensions draft
authorHaik Aftandilian <haftandilian@mozilla.com>
Mon, 08 May 2017 23:07:38 -0700
changeset 575710 c49cfac9c012d5eb1e5299cc3d24bf8b43816d18
parent 575709 9415853dc524fbef06021fb1e6906777519cdf2e
child 575959 fa41b9379f63c06bd02d2437e58f18651b3839cc
push id58143
push userhaftandilian@mozilla.com
push dateWed, 10 May 2017 19:49:37 +0000
bugs1350642
milestone55.0a1
Bug 1350642 - Part 2 - WIP - Perform resize tab-count-check in RecvSetDimensions Add nsIEmbeddingSiteWindow::DIM_FLAGS_CHECK_TAB_COUNT flag and pass it to parent for non-system resize callers. WIP. MozReview-Commit-ID: CCzjtBF3WSO
dom/ipc/TabChild.cpp
dom/ipc/TabParent.cpp
toolkit/components/browser/nsIEmbeddingSiteWindow.idl
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -810,16 +810,22 @@ TabChild::RemoteSizeShellTo(int32_t aWid
   if (width == aWidth) {
     flags |= nsIEmbeddingSiteWindow::DIM_FLAGS_IGNORE_CX;
   }
 
   if (height == aHeight) {
     flags |= nsIEmbeddingSiteWindow::DIM_FLAGS_IGNORE_CY;
   }
 
+  JSContext *jsCtx = nsContentUtils::GetCurrentJSContext();
+  MOZ_ASSERT(jsCtx);
+  if (jsCtx && !nsContentUtils::IsSystemCaller(jsCtx)) {
+    flags |= nsIEmbeddingSiteWindow::DIM_FLAGS_CHECK_TAB_COUNT;
+  }
+
   bool sent = SendSizeShellTo(flags, aWidth, aHeight, aShellItemWidth, aShellItemHeight);
 
   return sent ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 TabChild::RemoteDropLinks(uint32_t aLinksCount, nsIDroppedLinkItem** aLinks)
 {
@@ -921,16 +927,22 @@ TabChild::SetDimensions(uint32_t aFlags,
   if (cx == aCx) {
     aFlags |= nsIEmbeddingSiteWindow::DIM_FLAGS_IGNORE_CX;
   }
 
   if (cy == aCy) {
     aFlags |= nsIEmbeddingSiteWindow::DIM_FLAGS_IGNORE_CY;
   }
 
+  JSContext *jsCtx = nsContentUtils::GetCurrentJSContext();
+  MOZ_ASSERT(jsCtx);
+  if (jsCtx && !nsContentUtils::IsSystemCaller(jsCtx)) {
+    aFlags |= nsIEmbeddingSiteWindow::DIM_FLAGS_CHECK_TAB_COUNT;
+  }
+
   Unused << SendSetDimensions(aFlags, aX, aY, aCx, aCy);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 TabChild::GetDimensions(uint32_t aFlags, int32_t* aX,
                              int32_t* aY, int32_t* aCx, int32_t* aCy)
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -655,16 +655,32 @@ TabParent::Show(const ScreenIntSize& siz
 mozilla::ipc::IPCResult
 TabParent::RecvSetDimensions(const uint32_t& aFlags,
                              const int32_t& aX, const int32_t& aY,
                              const int32_t& aCx, const int32_t& aCy)
 {
   MOZ_ASSERT(!(aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER),
              "We should never see DIM_FLAGS_SIZE_INNER here!");
 
+  // When the check tab count flag is set, only allow the resize for
+  // windows with a single tab.
+  if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_CHECK_TAB_COUNT) {
+    nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow = GetXULBrowserWindow();
+    NS_ENSURE_TRUE(xulBrowserWindow, IPC_OK());
+
+    uint32_t tabCount;
+    nsresult rv = xulBrowserWindow->GetTabCount(&tabCount);
+    NS_ENSURE_SUCCESS(rv, IPC_OK());
+
+    if (tabCount > 1) {
+      // Drop this request
+      return IPC_OK();
+    }
+  }
+
   NS_ENSURE_TRUE(mFrameElement, IPC_OK());
   nsCOMPtr<nsIDocShell> docShell = mFrameElement->OwnerDoc()->GetDocShell();
   NS_ENSURE_TRUE(docShell, IPC_OK());
   nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
   docShell->GetTreeOwner(getter_AddRefs(treeOwner));
   nsCOMPtr<nsIBaseWindow> treeOwnerAsWin = do_QueryInterface(treeOwner);
   NS_ENSURE_TRUE(treeOwnerAsWin, IPC_OK());
 
--- a/toolkit/components/browser/nsIEmbeddingSiteWindow.idl
+++ b/toolkit/components/browser/nsIEmbeddingSiteWindow.idl
@@ -69,16 +69,24 @@ interface nsIEmbeddingSiteWindow : nsISu
 
     /**
      * Flag indicates that the cy parameter should be ignored.
      *
      * @see setDimensions
      */
     const unsigned long DIM_FLAGS_IGNORE_CY = 64;
 
+    /**
+     * Flag indicates that the resize should be subject to a
+     * tab count security check.
+     *
+     * @see setDimensions
+     */
+    const unsigned long DIM_FLAGS_CHECK_TAB_COUNT = 128;
+
 
     /**
      * Sets the dimensions for the window; the position & size. The
      * flags to indicate what the caller wants to set and whether the size
      * refers to the inner or outer area. The inner area refers to just
      * the embedded area, wheras the outer area can also include any 
      * surrounding chrome, window frame, title bar, and so on.
      *