Bug 1350642 - part 1 - Remove the PBrowser::Msg_GetTabCount sync IPC; r=krizsa
Remove the sync GetTabCount message (sent from child to parent)
and instead rely on asynchronous messaging from parent to child
when tabs are opened or closed. Instead of using the tab count,
CanMoveResizeWindows will use the new member mTabCountResizable
for the security check for non-system callers.
MozReview-Commit-ID: 4DuxqK0YNE9
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -7557,34 +7557,35 @@ nsGlobalWindow::CanMoveResizeWindows(Cal
return false;
}
if (!CanSetProperty("dom.disable_window_move_resize")) {
return false;
}
// Ignore the request if we have more than one tab in the window.
- uint32_t itemCount = 0;
if (XRE_IsContentProcess()) {
nsCOMPtr<nsIDocShell> docShell = GetDocShell();
if (docShell) {
nsCOMPtr<nsITabChild> child = docShell->GetTabChild();
- if (child) {
- child->SendGetTabCount(&itemCount);
+ bool hasSiblings = true;
+ if (child &&
+ NS_SUCCEEDED(child->GetHasSiblings(&hasSiblings)) &&
+ hasSiblings) {
+ return false;
}
}
} else {
nsCOMPtr<nsIDocShellTreeOwner> treeOwner = GetTreeOwner();
- if (!treeOwner || NS_FAILED(treeOwner->GetTabCount(&itemCount))) {
- itemCount = 0;
+ uint32_t itemCount = 0;
+ if (treeOwner && NS_SUCCEEDED(treeOwner->GetTabCount(&itemCount)) &&
+ itemCount > 1) {
+ return false;
}
}
- if (itemCount > 1) {
- return false;
- }
}
if (mDocShell) {
bool allow;
nsresult rv = mDocShell->GetAllowWindowControl(&allow);
if (NS_SUCCEEDED(rv) && !allow)
return false;
}
--- a/dom/interfaces/base/nsITabChild.idl
+++ b/dom/interfaces/base/nsITabChild.idl
@@ -16,26 +16,29 @@ native CommandsArray(nsTArray<nsCString>
interface nsITabChild : nsISupports
{
readonly attribute nsIContentFrameMessageManager messageManager;
attribute nsIWebBrowserChrome3 webBrowserChrome;
[notxpcom] void sendRequestFocus(in boolean canFocus);
- [notxpcom] void sendGetTabCount(out uint32_t tabCount);
-
[noscript, notxpcom] void enableDisableCommands(in AString action,
in CommandsArrayRef enabledCommands,
in CommandsArrayRef disabledCommands);
[noscript] void remoteSizeShellTo(in int32_t width, in int32_t height,
in int32_t shellItemWidth, in int32_t shellItemHeight);
[noscript] void remoteDropLinks(in unsigned long linksCount,
[array, size_is(linksCount)] in nsIDroppedLinkItem links);
readonly attribute uint64_t tabId;
+ /*
+ * Indicates whether or not there are other tabs in this tab's window.
+ */
+ attribute boolean hasSiblings;
+
[noscript, notxpcom] void beforeUnloadAdded();
[noscript, notxpcom] void beforeUnloadRemoved();
};
--- a/dom/ipc/PBrowser.ipdl
+++ b/dom/ipc/PBrowser.ipdl
@@ -511,24 +511,16 @@ parent:
double aPointerPressure,
uint32_t aPointerOrientation,
uint64_t aObserverId);
async SynthesizeNativeTouchTap(LayoutDeviceIntPoint aPoint,
bool aLongTap,
uint64_t aObserverId);
async ClearNativeTouchSequence(uint64_t aObserverId);
- /**
- * Returns the number of tabs in the window via the out parameter.
- * If the number of tabs can't be determined, returns 0.
- *
- * @param aValue where to store the tab count
- */
- sync GetTabCount() returns (uint32_t value);
-
async AccessKeyNotHandled(WidgetKeyboardEvent event);
async SetHasBeforeUnload(bool aHasBeforeUnload);
child:
async NativeSynthesisResponse(uint64_t aObserverId, nsCString aResponse);
parent:
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -420,16 +420,17 @@ TabChild::TabChild(nsIContentChild* aMan
, mDidFakeShow(false)
, mNotified(false)
, mTriedBrowserInit(false)
, mOrientation(eScreenOrientation_PortraitPrimary)
, mIgnoreKeyPressEvent(false)
, mHasValidInnerSize(false)
, mDestroyed(false)
, mUniqueId(aTabId)
+ , mHasSiblings(true)
, mIsTransparent(false)
, mIPCOpen(false)
, mParentIsActive(false)
, mDidSetRealShowInfo(false)
, mDidLoadURLInit(false)
, mAwaitingLA(false)
, mSkipKeyPress(false)
, mLayerObserverEpoch(0)
@@ -2947,22 +2948,16 @@ TabChild::SetWebBrowserChrome(nsIWebBrow
void
TabChild::SendRequestFocus(bool aCanFocus)
{
PBrowserChild::SendRequestFocus(aCanFocus);
}
void
-TabChild::SendGetTabCount(uint32_t* tabCount)
-{
- PBrowserChild::SendGetTabCount(tabCount);
-}
-
-void
TabChild::EnableDisableCommands(const nsAString& aAction,
nsTArray<nsCString>& aEnabledCommands,
nsTArray<nsCString>& aDisabledCommands)
{
PBrowserChild::SendEnableDisableCommands(PromiseFlatString(aAction),
aEnabledCommands, aDisabledCommands);
}
@@ -3501,16 +3496,30 @@ TabChildSHistoryListener::SHistoryDidUpd
}
mozilla::dom::TabGroup*
TabChild::TabGroup()
{
return mTabGroup;
}
+nsresult
+TabChild::GetHasSiblings(bool* aHasSiblings)
+{
+ *aHasSiblings = mHasSiblings;
+ return NS_OK;
+}
+
+nsresult
+TabChild::SetHasSiblings(bool aHasSiblings)
+{
+ mHasSiblings = aHasSiblings;
+ return NS_OK;
+}
+
/*******************************************************************************
* nsISHistoryListener
******************************************************************************/
NS_IMETHODIMP
TabChildSHistoryListener::OnHistoryNewEntry(nsIURI *aNewURI, int32_t aOldIndex)
{
return NS_ERROR_NOT_IMPLEMENTED;
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -913,16 +913,21 @@ private:
bool mHasValidInnerSize;
bool mDestroyed;
// Position of client area relative to the outer window
LayoutDeviceIntPoint mClientOffset;
// Position of tab, relative to parent widget (typically the window)
LayoutDeviceIntPoint mChromeDisp;
TabId mUniqueId;
+ // Whether or not this tab has siblings (other tabs in the same window).
+ // This is one factor used when choosing to allow or deny a non-system
+ // script's attempt to resize the window.
+ bool mHasSiblings;
+
// Holds the compositor options for the compositor rendering this tab,
// once we find out which compositor that is.
Maybe<mozilla::layers::CompositorOptions> mCompositorOptions;
friend class ContentChild;
bool mIsTransparent;
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -3527,32 +3527,16 @@ TabParent::GetShowInfo()
isTransparent, mDPI, mRounding, mDefaultScale.scale);
}
return ShowInfo(EmptyString(), false, false, false,
false, mDPI, mRounding, mDefaultScale.scale);
}
mozilla::ipc::IPCResult
-TabParent::RecvGetTabCount(uint32_t* aValue)
-{
- *aValue = 0;
-
- nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow = GetXULBrowserWindow();
- NS_ENSURE_TRUE(xulBrowserWindow, IPC_OK());
-
- uint32_t tabCount;
- nsresult rv = xulBrowserWindow->GetTabCount(&tabCount);
- NS_ENSURE_SUCCESS(rv, IPC_OK());
-
- *aValue = tabCount;
- return IPC_OK();
-}
-
-mozilla::ipc::IPCResult
TabParent::RecvLookUpDictionary(const nsString& aText,
nsTArray<FontRange>&& aFontRangeArray,
const bool& aIsVertical,
const LayoutDeviceIntPoint& aPoint)
{
nsCOMPtr<nsIWidget> widget = GetWidget();
if (!widget) {
return IPC_OK();
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -634,18 +634,16 @@ protected:
virtual mozilla::ipc::IPCResult RecvRemoteIsReadyToHandleInputEvents() override;
virtual mozilla::ipc::IPCResult RecvForcePaintNoOp(const uint64_t& aLayerObserverEpoch) override;
virtual mozilla::ipc::IPCResult RecvSetDimensions(const uint32_t& aFlags,
const int32_t& aX, const int32_t& aY,
const int32_t& aCx, const int32_t& aCy) override;
- virtual mozilla::ipc::IPCResult RecvGetTabCount(uint32_t* aValue) override;
-
virtual mozilla::ipc::IPCResult RecvSHistoryUpdate(const uint32_t& aCount,
const uint32_t& aLocalIndex,
const bool& aTruncate) override;
virtual mozilla::ipc::IPCResult RecvRequestCrossBrowserNavigation(const uint32_t& aGlobalIndex) override;
ContentCacheInParent mContentCache;
--- a/ipc/ipdl/sync-messages.ini
+++ b/ipc/ipdl/sync-messages.ini
@@ -831,18 +831,16 @@ description =
description =
[PBrowser::GetInputContext]
description =
[PBrowser::IsParentWindowMainWidgetVisible]
description =
description =
[PBrowser::RequestNativeKeyBindings]
description =
-[PBrowser::GetTabCount]
-description =
[PBrowser::DispatchWheelEvent]
description =
[PBrowser::DispatchMouseEvent]
description =
[PBrowser::DispatchKeyboardEvent]
description =
[PBrowser::EnsureLayersConnected]
description =