Backed out 4 changesets (bug 1885936) for causing bpnu bustages related to Gamepad. CLOSED TREE

Backed out changeset 935c80ed4a38 (bug 1885936)
Backed out changeset 6cc4da44b050 (bug 1885936)
Backed out changeset 03205a0f59e6 (bug 1885936)
Backed out changeset 93619e887bb7 (bug 1885936)
This commit is contained in:
Tamas Szentpeteri
2024-05-15 16:58:13 +03:00
parent f20db7ea1d
commit 3be78841f1
17 changed files with 2 additions and 307 deletions

View File

@@ -1643,20 +1643,6 @@ GamepadServiceTest* Navigator::RequestGamepadServiceTest(ErrorResult& aRv) {
return mGamepadServiceTest;
}
already_AddRefed<Promise> Navigator::RequestAllGamepads(ErrorResult& aRv) {
if (!mWindow || !mWindow->IsFullyActive()) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsGlobalWindowInner* win = nsGlobalWindowInner::Cast(mWindow);
// We need to set the flag to trigger the parent process to start monitoring
// gamepads. Otherwise, we cannot get any gamepad information.
win->SetHasGamepadEventListener(true);
return win->RequestAllGamepads(aRv);
}
already_AddRefed<Promise> Navigator::GetVRDisplays(ErrorResult& aRv) {
if (!mWindow || !mWindow->GetDocShell() || !mWindow->GetExtantDoc()) {
aRv.Throw(NS_ERROR_UNEXPECTED);

View File

@@ -177,7 +177,6 @@ class Navigator final : public nsISupports, public nsWrapperCache {
void GetGamepads(nsTArray<RefPtr<Gamepad>>& aGamepads, ErrorResult& aRv);
GamepadServiceTest* RequestGamepadServiceTest(ErrorResult& aRv);
already_AddRefed<Promise> RequestAllGamepads(ErrorResult& aRv);
already_AddRefed<Promise> GetVRDisplays(ErrorResult& aRv);
void FinishGetVRDisplays(bool isWebVRSupportedInwindow, Promise* p);
void GetActiveVRDisplays(nsTArray<RefPtr<VRDisplay>>& aDisplays) const;

View File

@@ -6785,18 +6785,6 @@ void nsGlobalWindowInner::GetGamepads(nsTArray<RefPtr<Gamepad>>& aGamepads) {
}
}
already_AddRefed<mozilla::dom::Promise> nsGlobalWindowInner::RequestAllGamepads(
ErrorResult& aRv) {
RefPtr<GamepadManager> gamepadManager(GamepadManager::GetService());
if (!gamepadManager) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
return gamepadManager->RequestAllGamepads(this, aRv);
}
already_AddRefed<Gamepad> nsGlobalWindowInner::GetGamepad(
GamepadHandle aHandle) {
RefPtr<Gamepad> gamepad;

View File

@@ -495,8 +495,6 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget,
mozilla::dom::Gamepad* aGamepad);
void RemoveGamepad(mozilla::dom::GamepadHandle aHandle);
void GetGamepads(nsTArray<RefPtr<mozilla::dom::Gamepad>>& aGamepads);
already_AddRefed<mozilla::dom::Promise> RequestAllGamepads(
mozilla::ErrorResult& aRv);
already_AddRefed<mozilla::dom::Gamepad> GetGamepad(
mozilla::dom::GamepadHandle aHandle);
void SetHasSeenGamepadInput(bool aHasSeen);

View File

@@ -659,38 +659,4 @@ already_AddRefed<Promise> GamepadManager::SetLightIndicatorColor(
++mPromiseID;
return promise.forget();
}
already_AddRefed<Promise> GamepadManager::RequestAllGamepads(
nsIGlobalObject* aGlobal, ErrorResult& aRv) {
RefPtr<Promise> promise = Promise::Create(aGlobal, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
if (!mChannelChild) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
mChannelChild->SendRequestAllGamepads(
[promise](const nsTArray<GamepadAdded>& aAddedGamepads) {
nsTArray<RefPtr<Gamepad>> gamepads;
for (const auto& addedGamepad : aAddedGamepads) {
RefPtr<Gamepad> gamepad = new Gamepad(
nullptr, addedGamepad.id(), 0, GamepadHandle(),
addedGamepad.mapping(), addedGamepad.hand(),
addedGamepad.display_id(), addedGamepad.num_buttons(),
addedGamepad.num_axes(), addedGamepad.num_haptics(),
addedGamepad.num_lights(), addedGamepad.num_touches());
gamepads.AppendElement(gamepad);
}
promise->MaybeResolve(gamepads);
},
[promise](mozilla::ipc::ResponseRejectReason) {
promise->MaybeReject(NS_ERROR_UNEXPECTED);
});
return promise.forget();
}
} // namespace mozilla::dom

View File

@@ -83,10 +83,6 @@ class GamepadManager final : public nsIObserver {
nsIGlobalObject* aGlobal,
ErrorResult& aRv);
// Request information of all gamepads from the parent process.
already_AddRefed<Promise> RequestAllGamepads(nsIGlobalObject* aGlobal,
ErrorResult& aRv);
protected:
GamepadManager();
~GamepadManager() = default;

View File

@@ -122,15 +122,6 @@ class GamepadPlatformService final {
void MaybeShutdown();
nsTArray<GamepadAdded> GetAllGamePads() {
nsTArray<GamepadAdded> gamepads;
for (const auto& elem : mGamepadAdded) {
gamepads.AppendElement(elem.second);
}
return gamepads;
}
private:
GamepadPlatformService();
~GamepadPlatformService();

View File

@@ -100,16 +100,6 @@ mozilla::ipc::IPCResult GamepadEventChannelParent::RecvLightIndicatorColor(
return IPC_FAIL(this, "SendReplyGamepadPromise fail.");
}
mozilla::ipc::IPCResult GamepadEventChannelParent::RecvRequestAllGamepads(
RequestAllGamepadsResolver&& aResolver) {
RefPtr<GamepadPlatformService> service =
GamepadPlatformService::GetParentService();
MOZ_ASSERT(service);
aResolver(service->GetAllGamePads());
return IPC_OK();
}
void GamepadEventChannelParent::DispatchUpdateEvent(
const GamepadChangeEvent& aEvent) {
mBackgroundEventTarget->Dispatch(new SendGamepadUpdateRunnable(this, aEvent),

View File

@@ -29,9 +29,6 @@ class GamepadEventChannelParent final : public PGamepadEventChannelParent {
const uint8_t& aGreen, const uint8_t& aBlue, const uint32_t& aPromiseID);
void DispatchUpdateEvent(const GamepadChangeEvent& aEvent);
mozilla::ipc::IPCResult RecvRequestAllGamepads(
RequestAllGamepadsResolver&& aResolver);
GamepadEventChannelParent(const GamepadEventChannelParent&) = delete;
GamepadEventChannelParent(GamepadEventChannelParent&&) = delete;
GamepadEventChannelParent& operator=(const GamepadEventChannelParent&) =

View File

@@ -21,8 +21,6 @@ protocol PGamepadEventChannel {
[Tainted] async LightIndicatorColor(GamepadHandle aHandle, uint32_t aLightColorIndex,
[NoTaint=allvalid] uint8_t aRed, [NoTaint=allvalid] uint8_t aGreen,
[NoTaint=allvalid] uint8_t aBlue, [NoTaint=passback] uint32_t aPromiseID);
async RequestAllGamepads()
returns (GamepadAdded[] gamepads);
child:
async GamepadUpdate(GamepadChangeEvent aGamepadEvent);

View File

@@ -219,15 +219,6 @@ partial interface Navigator {
GamepadServiceTest requestGamepadServiceTest();
};
// Chrome-only interface for acquiring all gamepads. Normally, a gamepad can
// only become visible if it gets interacted by the user. This function bypasses
// this restriction; it allow requesting all gamepad info without user
// interacting with the gamepads.
partial interface Navigator {
[Throws, ChromeOnly]
Promise<sequence<Gamepad>> requestAllGamepads();
};
// https://immersive-web.github.io/webvr/spec/1.1/#interface-navigator
partial interface Navigator {
[NewObject, SecureContext, Pref="dom.vr.enabled"]

View File

@@ -5,10 +5,6 @@
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
setTimeout: "resource://gre/modules/Timer.sys.mjs",
});
ChromeUtils.defineLazyGetter(lazy, "console", () => {
return console.createInstance({
prefix: "UserCharacteristicsPage",
@@ -17,84 +13,14 @@ ChromeUtils.defineLazyGetter(lazy, "console", () => {
});
export class UserCharacteristicsChild extends JSWindowActorChild {
/**
* A placeholder for the collected data.
*
* @typedef {Object} userDataDetails
* @property {string} debug - The debug messages.
* @property {Object} output - The user characteristics data.
*/
userDataDetails;
collectingDelay = 1000; // Collecting delay for 1000 ms.
// Please add data collection here if the collection requires privilege
// access, such as accessing ChromeOnly functions. The function is called
// right after the content page finishes.
async collectUserCharacteristicsData() {
lazy.console.debug("Calling collectUserCharacteristicsData()");
}
// This function is similar to the above function, but we call this function
// with a delay after the content page finished. This function is for data
// that requires loading time.
async collectUserCharacteristicsDataWithDelay() {
lazy.console.debug("Calling collectUserCharacteristicsDataWithDelay()");
await this.populateGamepadsInfo();
}
async populateGamepadsInfo() {
lazy.console.debug("Calling populateGamepadsInfo()");
let gamepads = await this.contentWindow.navigator.requestAllGamepads();
lazy.console.debug(`Found ${gamepads.length} gamepads`);
let gamepadsInfo = [];
for (const gamepad of gamepads) {
// We use an array to represent a gamepad device because it uses less size
// then an object when convert to a JSON string. So, we can fit the string
// into a Glean string which has a 100 size limitation.
let data = [];
data.push(gamepad.id);
data.push(gamepad?.hand ?? "");
data.push(gamepad.buttons.length);
data.push(gamepad.axes?.length ?? 0);
data.push(gamepad.hapticActuators?.length ?? 0);
data.push(gamepad.lightIndicators?.length ?? 0);
data.push(gamepad.touchEvents?.length ?? 0);
gamepadsInfo.push(JSON.stringify(data));
}
lazy.console.debug(`Reporting gamepad: ${gamepadsInfo}`);
this.userDataDetails.output.gamepads = gamepadsInfo;
}
async handleEvent(event) {
handleEvent(event) {
lazy.console.debug("Got ", event.type);
switch (event.type) {
case "UserCharacteristicsDataDone":
// Clone the data so we can modify it. Otherwise, we cannot change it
// because it's behind Xray wrapper.
this.userDataDetails = structuredClone(event.detail);
await this.collectUserCharacteristicsData();
await new Promise(resolve => {
lazy.setTimeout(resolve, this.collectingDelay);
});
await this.collectUserCharacteristicsDataWithDelay();
lazy.console.debug("creating IdleDispatch");
ChromeUtils.idleDispatch(() => {
lazy.console.debug("sending PageReady");
this.sendAsyncMessage(
"UserCharacteristics::PageReady",
this.userDataDetails
);
this.sendAsyncMessage("UserCharacteristics::PageReady", event.detail);
});
break;
}

View File

@@ -181,10 +181,6 @@ export class UserCharacteristicsPageService {
lazy.console.debug("Populating Glean metrics...");
Glean.characteristics.timezone.set(data.output.foo);
for (let gamepad of data.output.gamepads) {
Glean.characteristics.gamepads.add(gamepad);
}
lazy.console.debug("Unregistering actor");
Services.obs.notifyObservers(
null,

View File

@@ -25,17 +25,6 @@ function debug(...args) {
debug("Debug Line");
debug("Another debug line, with", { an: "object" });
// A hacky way to ensure all GamePad related services are running by the time we
// want to know about GamePads. This will attach a listener for this window to
// the GamePadManager, creating it if it doesn't exist. When GamePadManager is
// created (either now or earlier) it will also create a GamePadEventChannel
// between the GamePadManager and the parent process. When that's created, the
// Parent will create a GamePadPlatformService if it's not already created, and
// when that Service gets created it kicks off a background thread to monitor
// for gamepads attached to the machine. We need to give that background thread
// time to run so all the data is there when we request it.
navigator.getGamepads();
// The first time we put a real value in here, please update browser_usercharacteristics.js
let output = {
foo: "Hello World",

View File

@@ -534,33 +534,6 @@ characteristics:
data_sensitivity:
- technical
gamepads:
type: string_list
description: >
The information of the gamepads inserted on the user device. Each string
represents one gamepad. We use a JSON array to describe a gamepad, every
value represents one property of the gamepad. Following are the details:
index 0: The ID of the game pad
index 1: Which hand for the gamepad.
index 2: Number of buttons
index 3: Number of axes
index 4: Number of haptics
index 5: Number of lights
index 6: Number of touches
lifetime: application
send_in_pings:
- user-characteristics
notification_emails:
- tom@mozilla.com
- tihuang@mozilla.com
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1885936
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1885936#c2
expires: never
data_sensitivity:
- technical
prefs_intl_accept_languages:
type: string
description: >

View File

@@ -32,6 +32,4 @@ support-files = ["file_pdf.pdf"]
["browser_serviceWorker_fingerprinting_webcompat.js"]
["browser_usercharacteristics_gamepads.js"]
["browser_usercharacteristics.js"]

View File

@@ -1,87 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const emptyPage =
getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"https://example.com"
) + "empty.html";
add_setup(async function setup() {
await SpecialPowers.pushPrefEnv({
set: [["dom.gamepad.test.enabled", true]],
});
});
async function promiseObserverNotification() {
await TestUtils.topicObserved("user-characteristics-populating-data-done");
GleanPings.userCharacteristics.testBeforeNextSubmit(_ => {
let gamepads = Glean.characteristics.gamepads.testGetValue();
is(gamepads.length, 2, "Two gamepads were reported");
is(
gamepads[0],
`["test gamepad 1","",4,4,0,0,0]`,
"The first gamepads metrics is expected."
);
is(
gamepads[1],
`["test gamepad 2","right",10,4,2,0,0]`,
"The second gamepads metrics is expected."
);
});
GleanPings.userCharacteristics.submit();
}
add_task(async function test() {
Services.fog.testResetFOG();
await BrowserTestUtils.withNewTab(
{ gBrowser, url: emptyPage },
async browser => {
await SpecialPowers.spawn(browser, [], async _ => {
const GamepadService = content.navigator.requestGamepadServiceTest();
// Call getGamepads() to start gamepad monitoring. Otherwise, the below
// addGamepad function will stuck.
content.navigator.getGamepads();
info("Add two gamepads");
await GamepadService.addGamepad(
"test gamepad 1",
GamepadService.standardMapping,
GamepadService.noHand,
4, // buttons
4, // axes
0, // haptics
0, // lights
0 // touches
);
await GamepadService.addGamepad(
"test gamepad 2",
GamepadService.standardMapping,
GamepadService.rightHand,
10, // buttons
4, // axes
2, // haptics
0, // lights
0 // touches
);
});
let promise = promiseObserverNotification();
Services.obs.notifyObservers(
null,
"user-characteristics-testing-please-populate-data"
);
await promise;
}
);
});