Bug 1539497, navigator.maxTouchPoints returns 0 in child process, r=ehsan

Differential Revision: https://phabricator.services.mozilla.com/D38583

--HG--
extra : amend_source : 52f1fdbf79f18a6c3ff52eab0a45b397cee76baf
This commit is contained in:
Olli Pettay 2019-07-19 01:45:16 +03:00
Родитель f52133cc3d
Коммит 7c88ba1685
15 изменённых файлов: 121 добавлений и 26 удалений

Просмотреть файл

@ -3398,9 +3398,11 @@ nsresult nsFrameLoader::GetNewTabContext(MutableTabContext* aTabContext,
}
}
bool tabContextUpdated =
aTabContext->SetTabContext(OwnerIsMozBrowserFrame(), chromeOuterWindowID,
showFocusRings, attrs, presentationURLStr);
uint32_t maxTouchPoints = BrowserParent::GetMaxTouchPoints(mOwnerContent);
bool tabContextUpdated = aTabContext->SetTabContext(
OwnerIsMozBrowserFrame(), chromeOuterWindowID, showFocusRings, attrs,
presentationURLStr, maxTouchPoints);
NS_ENSURE_STATE(tabContextUpdated);
return NS_OK;

Просмотреть файл

@ -1,4 +1,5 @@
[DEFAULT]
[browser_bug1539497.js]
[browser_shortcutkey_modifier_conflicts_with_content_accesskey_modifier.js]
skip-if = os != 'linux' && os != 'win' // Alt + D is defined only on Linux and Windows

Просмотреть файл

@ -0,0 +1,28 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
add_task(async function maxTouchPoints() {
await new Promise(resolve => {
SpecialPowers.pushPrefEnv(
{
set: [
["dom.w3c_pointer_events.enabled", true],
["dom.maxtouchpoints.testing.value", 5],
],
},
resolve
);
});
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
"data:text/html,Test page for navigator.maxTouchPoints"
);
await ContentTask.spawn(tab.linkedBrowser, null, function() {
is(content.navigator.maxTouchPoints, 5, "Should have touch points.");
});
BrowserTestUtils.removeTab(tab);
});

Просмотреть файл

@ -24,6 +24,7 @@ support-files =
[test_accel_virtual_modifier.html]
[test_addEventListenerExtraArg.html]
[test_all_synthetic_events.html]
[test_bug1539497.html]
[test_bug226361.xhtml]
[test_bug238987.html]
[test_bug288392.html]

Просмотреть файл

@ -0,0 +1,30 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>bug 1539497</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
SimpleTest.waitForExplicitFinish();
function runTest() {
var win = window.open("about:blank");
win.onload = function() {
is(win.navigator.maxTouchPoints, 5, "Should have max touch points");
win.close();
SimpleTest.finish();
}
}
function init() {
SpecialPowers.pushPrefEnv(
{"set": [["dom.w3c_pointer_events.enabled", true],
["dom.maxtouchpoints.testing.value", 5]]}, runTest);
}
</script>
</head>
<body onload="init()">
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>

Просмотреть файл

@ -43,9 +43,10 @@ nsresult BrowserBridgeParent::Init(const nsString& aPresentationURL,
OriginAttributes attrs;
attrs.mInIsolatedMozBrowser = false;
attrs.SyncAttributesWithPrivateBrowsing(false);
uint32_t maxTouchPoints = Manager()->GetMaxTouchPoints();
MutableTabContext tabContext;
tabContext.SetTabContext(false, 0, UIStateChangeType_Set, attrs,
aPresentationURL);
aPresentationURL, maxTouchPoints);
ProcessPriority initialPriority = PROCESS_PRIORITY_FOREGROUND;

Просмотреть файл

@ -424,14 +424,6 @@ class BrowserChild final : public nsMessageManagerScriptExecutor,
const EffectsInfo& GetEffectsInfo() const { return mEffectsInfo; }
void GetMaxTouchPoints(uint32_t* aTouchPoints) {
*aTouchPoints = mMaxTouchPoints;
}
void SetMaxTouchPoints(uint32_t aMaxTouchPoints) {
mMaxTouchPoints = aMaxTouchPoints;
}
hal::ScreenOrientation GetOrientation() const { return mOrientation; }
void SetBackgroundColor(const nscolor& aColor);

Просмотреть файл

@ -403,6 +403,19 @@ nsIXULBrowserWindow* BrowserParent::GetXULBrowserWindow() {
return xulBrowserWindow;
}
uint32_t BrowserParent::GetMaxTouchPoints(Element* aElement) {
if (!aElement) {
return 0;
}
if (StaticPrefs::dom_maxtouchpoints_testing_value() >= 0) {
return StaticPrefs::dom_maxtouchpoints_testing_value();
}
nsIWidget* widget = nsContentUtils::WidgetForDocument(aElement->OwnerDoc());
return widget ? widget->GetMaxTouchPoints() : 0;
}
a11y::DocAccessibleParent* BrowserParent::GetTopLevelDocAccessible() const {
#ifdef ACCESSIBILITY
// XXX Consider managing non top level PDocAccessibles with their parent
@ -3073,9 +3086,10 @@ mozilla::ipc::IPCResult BrowserParent::RecvBrowserFrameOpenWindow(
aURL, aName, aForceNoReferrer,
aFeatures);
cwi.windowOpened() = (opened == BrowserElementParent::OPEN_WINDOW_ADDED);
cwi.maxTouchPoints() = GetMaxTouchPoints();
nsCOMPtr<nsIWidget> widget = GetWidget();
if (widget) {
cwi.maxTouchPoints() = widget->GetMaxTouchPoints();
cwi.dimensions() = GetDimensionInfo();
}

Просмотреть файл

@ -161,6 +161,9 @@ class BrowserParent final : public PBrowserParent,
nsIXULBrowserWindow* GetXULBrowserWindow();
static uint32_t GetMaxTouchPoints(Element* aElement);
uint32_t GetMaxTouchPoints() { return GetMaxTouchPoints(mFrameElement); }
/**
* Return the top level DocAccessibleParent for this BrowserParent.
* Note that in the case of an out-of-process iframe, the returned actor

Просмотреть файл

@ -4967,10 +4967,10 @@ mozilla::ipc::IPCResult ContentParent::RecvCreateWindow(
nsCOMPtr<nsIWidget> widget = newTab->GetWidget();
if (widget) {
cwi.maxTouchPoints() = widget->GetMaxTouchPoints();
cwi.dimensions() = newTab->GetDimensionInfo();
}
cwi.maxTouchPoints() = newTab->GetMaxTouchPoints();
cwi.hasSiblings() = (openLocation == nsIBrowserDOMWindow::OPEN_NEWTAB);
return IPC_OK();

Просмотреть файл

@ -51,6 +51,9 @@ struct FrameIPCTabContext
// Keyboard indicator state inherited from the parent.
UIStateChangeType showFocusRings;
// Maximum number of touch points on the screen.
uint32_t maxTouchPoints;
};
struct JSPluginFrameIPCTabContext

Просмотреть файл

@ -23,7 +23,8 @@ TabContext::TabContext()
mIsMozBrowserElement(false),
mChromeOuterWindowID(0),
mJSPluginID(-1),
mShowFocusRings(UIStateChangeType_NoChange) {}
mShowFocusRings(UIStateChangeType_NoChange),
mMaxTouchPoints(0) {}
bool TabContext::IsMozBrowserElement() const { return mIsMozBrowserElement; }
@ -84,7 +85,8 @@ bool TabContext::SetTabContext(bool aIsMozBrowserElement,
uint64_t aChromeOuterWindowID,
UIStateChangeType aShowFocusRings,
const OriginAttributes& aOriginAttributes,
const nsAString& aPresentationURL) {
const nsAString& aPresentationURL,
uint32_t aMaxTouchPoints) {
NS_ENSURE_FALSE(mInitialized, false);
mInitialized = true;
@ -93,6 +95,7 @@ bool TabContext::SetTabContext(bool aIsMozBrowserElement,
mOriginAttributes = aOriginAttributes;
mPresentationURL = aPresentationURL;
mShowFocusRings = aShowFocusRings;
mMaxTouchPoints = aMaxTouchPoints;
return true;
}
@ -111,7 +114,7 @@ IPCTabContext TabContext::AsIPCTabContext() const {
return IPCTabContext(FrameIPCTabContext(
mOriginAttributes, mIsMozBrowserElement, mChromeOuterWindowID,
mPresentationURL, mShowFocusRings));
mPresentationURL, mShowFocusRings, mMaxTouchPoints));
}
MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
@ -122,6 +125,7 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
OriginAttributes originAttributes;
nsAutoString presentationURL;
UIStateChangeType showFocusRings = UIStateChangeType_NoChange;
uint32_t maxTouchPoints = 0;
switch (aParams.type()) {
case IPCTabContext::TPopupIPCTabContext: {
@ -192,6 +196,7 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
presentationURL = ipcContext.presentationURL();
showFocusRings = ipcContext.showFocusRings();
originAttributes = ipcContext.originAttributes();
maxTouchPoints = ipcContext.maxTouchPoints();
break;
}
case IPCTabContext::TUnsafeIPCTabContext: {
@ -217,7 +222,7 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
} else {
rv = mTabContext.SetTabContext(isMozBrowserElement, chromeOuterWindowID,
showFocusRings, originAttributes,
presentationURL);
presentationURL, maxTouchPoints);
}
if (!rv) {
mInvalidReason = "Couldn't initialize TabContext.";

Просмотреть файл

@ -82,6 +82,8 @@ class TabContext {
UIStateChangeType ShowFocusRings() const;
uint32_t MaxTouchPoints() const { return mMaxTouchPoints; }
protected:
friend class MaybeInvalidTabContext;
@ -107,7 +109,8 @@ class TabContext {
bool SetTabContext(bool aIsMozBrowserElement, uint64_t aChromeOuterWindowID,
UIStateChangeType aShowFocusRings,
const OriginAttributes& aOriginAttributes,
const nsAString& aPresentationURL);
const nsAString& aPresentationURL,
uint32_t aMaxTouchPoints);
/**
* Modify this TabContext to match the given TabContext. This is a special
@ -130,6 +133,10 @@ class TabContext {
*/
bool SetTabContextForJSPluginFrame(int32_t aJSPluginID);
void SetMaxTouchPoints(uint32_t aMaxTouchPoints) {
mMaxTouchPoints = aMaxTouchPoints;
}
private:
/**
* Has this TabContext been initialized? If so, mutator methods will fail.
@ -165,6 +172,11 @@ class TabContext {
* Keyboard indicator state (focus rings).
*/
UIStateChangeType mShowFocusRings;
/**
* Maximum number of touch points.
*/
uint32_t mMaxTouchPoints;
};
/**
@ -181,10 +193,11 @@ class MutableTabContext : public TabContext {
bool SetTabContext(bool aIsMozBrowserElement, uint64_t aChromeOuterWindowID,
UIStateChangeType aShowFocusRings,
const OriginAttributes& aOriginAttributes,
const nsAString& aPresentationURL = EmptyString()) {
const nsAString& aPresentationURL,
uint32_t aMaxTouchPoints) {
return TabContext::SetTabContext(aIsMozBrowserElement, aChromeOuterWindowID,
aShowFocusRings, aOriginAttributes,
aPresentationURL);
aPresentationURL, aMaxTouchPoints);
}
bool SetTabContextForJSPluginFrame(uint32_t aJSPluginID) {

Просмотреть файл

@ -2012,6 +2012,12 @@
mirror: always
#undef PREF_VALUE
# If the value is >= 0, it will be used for max touch points in child processes.
- name: dom.maxtouchpoints.testing.value
type: int32_t
value: -1
mirror: always
# Is support for Navigator.webdriver enabled?
- name: dom.webdriver.enabled
type: bool

Просмотреть файл

@ -1168,11 +1168,7 @@ LayoutDeviceIntSize PuppetWidget::GetCompositionSize() {
}
uint32_t PuppetWidget::GetMaxTouchPoints() const {
uint32_t maxTouchPoints = 0;
if (mBrowserChild) {
mBrowserChild->GetMaxTouchPoints(&maxTouchPoints);
}
return maxTouchPoints;
return mBrowserChild ? mBrowserChild->MaxTouchPoints() : 0;
}
void PuppetWidget::StartAsyncScrollbarDrag(