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
--- 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.
*