Bug 1610040 - Cut PGamepadEventChannel over to use Tainted<> IPC Mechanics; r=tjr

Differential Revision: https://phabricator.services.mozilla.com/D60745
This commit is contained in:
june wilde 2020-12-01 19:56:00 +00:00
Родитель 6464b0b4fe
Коммит 0948c09d02
10 изменённых файлов: 106 добавлений и 72 удалений

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

@ -14,9 +14,11 @@ namespace dom {
// (linux/LinuxGamepad.cpp, cocoa/CocoaGamepad.cpp, etc)
void StartGamepadMonitoring();
void StopGamepadMonitoring();
void SetGamepadLightIndicatorColor(uint32_t aControllerIdx,
uint32_t aLightColorIndex, uint8_t aRed,
uint8_t aGreen, uint8_t aBlue);
void SetGamepadLightIndicatorColor(const Tainted<uint32_t>& aControllerIdx,
const Tainted<uint32_t>& aLightColorIndex,
const Tainted<uint8_t>& aRed,
const Tainted<uint8_t>& aGreen,
const Tainted<uint8_t>& aBlue);
} // namespace dom
} // namespace mozilla

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

@ -86,9 +86,11 @@ void StopGamepadMonitoring() {
java::GeckoAppShell::GetApplicationContext());
}
void SetGamepadLightIndicatorColor(uint32_t aControllerIdx,
uint32_t aLightColorIndex, uint8_t aRed,
uint8_t aGreen, uint8_t aBlue) {
void SetGamepadLightIndicatorColor(const Tainted<uint32_t>& aControllerIdx,
const Tainted<uint32_t>& aLightColorIndex,
const Tainted<uint8_t>& aRed,
const Tainted<uint8_t>& aGreen,
const Tainted<uint8_t>& aBlue) {
NS_WARNING("Android doesn't support gamepad light indicator.");
}

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

@ -207,8 +207,11 @@ class DarwinGamepadService {
void Startup();
void Shutdown();
void SetLightIndicatorColor(uint32_t aControllerIdx, uint32_t aLightIndex,
uint8_t aRed, uint8_t aGreen, uint8_t aBlue);
void SetLightIndicatorColor(const Tainted<uint32_t>& aControllerIdx,
const Tainted<uint32_t>& aLightColorIndex,
const Tainted<uint8_t>& aRed,
const Tainted<uint8_t>& aGreen,
const Tainted<uint8_t>& aBlue);
friend class DarwinGamepadServiceStartupRunnable;
friend class DarwinGamepadServiceShutdownRunnable;
};
@ -565,32 +568,35 @@ void DarwinGamepadService::Shutdown() {
mIsRunning = false;
}
void DarwinGamepadService::SetLightIndicatorColor(uint32_t aControllerIdx,
uint32_t aLightColorIndex,
uint8_t aRed, uint8_t aGreen,
uint8_t aBlue) {
void DarwinGamepadService::SetLightIndicatorColor(
const Tainted<uint32_t>& aControllerIdx,
const Tainted<uint32_t>& aLightColorIndex, const Tainted<uint8_t>& aRed,
const Tainted<uint8_t>& aGreen, const Tainted<uint8_t>& aBlue) {
// We get aControllerIdx from GamepadPlatformService::AddGamepad(),
// It begins from 1 and is stored at Gamepad.id.
const Gamepad* gamepad = nullptr;
for (const auto& pad : mGamepads) {
if (pad.mSuperIndex == aControllerIdx) {
gamepad = &pad;
break;
}
}
const Gamepad* gamepad = MOZ_FIND_AND_VALIDATE(
aControllerIdx, list_item.mSuperIndex == aControllerIdx, mGamepads);
if (!gamepad) {
MOZ_ASSERT(false);
return;
}
RefPtr<GamepadRemapper> remapper = gamepad->mRemapper;
if (!remapper || remapper->GetLightIndicatorCount() <= aLightColorIndex) {
if (!remapper ||
MOZ_IS_VALID(aLightColorIndex,
remapper->GetLightIndicatorCount() <= aLightColorIndex)) {
MOZ_ASSERT(false);
return;
}
std::vector<uint8_t> report;
remapper->GetLightColorReport(aRed, aGreen, aBlue, report);
remapper->GetLightColorReport(
MOZ_NO_VALIDATE(aRed, "uint8_t's range is the range of all valid values"),
MOZ_NO_VALIDATE(aGreen,
"uint8_t's range is the range of all valid values"),
MOZ_NO_VALIDATE(aBlue,
"uint8_t's range is the range of all valid values"),
report);
gamepad->WriteOutputReport(report);
}
@ -619,9 +625,11 @@ void StopGamepadMonitoring() {
gService->Shutdown();
}
void SetGamepadLightIndicatorColor(uint32_t aControllerIdx,
uint32_t aLightColorIndex, uint8_t aRed,
uint8_t aGreen, uint8_t aBlue) {
void SetGamepadLightIndicatorColor(const Tainted<uint32_t>& aControllerIdx,
const Tainted<uint32_t>& aLightColorIndex,
const Tainted<uint8_t>& aRed,
const Tainted<uint8_t>& aGreen,
const Tainted<uint8_t>& aBlue) {
MOZ_ASSERT(gService);
if (!gService) {
return;

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

@ -13,8 +13,11 @@ void StartGamepadMonitoring() {}
void StopGamepadMonitoring() {}
void SetGamepadLightIndicatorColor(uint32_t, uint32_t, uint8_t, uint8_t,
uint8_t) {}
void SetGamepadLightIndicatorColor(const Tainted<uint32_t>&,
const Tainted<uint32_t>&,
const Tainted<uint8_t>&,
const Tainted<uint8_t>&,
const Tainted<uint8_t>&) {}
} // namespace dom
} // namespace mozilla

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

@ -66,12 +66,15 @@ void GamepadEventChannelParent::ActorDestroy(ActorDestroyReason aWhy) {
}
mozilla::ipc::IPCResult GamepadEventChannelParent::RecvVibrateHaptic(
const uint32_t& aControllerIdx, const uint32_t& aHapticIndex,
const double& aIntensity, const double& aDuration,
const uint32_t& aPromiseID) {
const Tainted<uint32_t>& aControllerIdx,
const Tainted<uint32_t>& aHapticIndex, const Tainted<double>& aIntensity,
const Tainted<double>& aDuration, const Tainted<uint32_t>& aPromiseID) {
// TODO: Bug 680289, implement for standard gamepads
if (SendReplyGamepadPromise(aPromiseID)) {
// TODO: simplify tainted validation, see 1610570
if (SendReplyGamepadPromise(MOZ_NO_VALIDATE(
aPromiseID,
"This value is unused aside from being passed back to the child."))) {
return IPC_OK();
}
@ -79,19 +82,23 @@ mozilla::ipc::IPCResult GamepadEventChannelParent::RecvVibrateHaptic(
}
mozilla::ipc::IPCResult GamepadEventChannelParent::RecvStopVibrateHaptic(
const uint32_t& aControllerIdx) {
const Tainted<uint32_t>& aControllerIdx) {
// TODO: Bug 680289, implement for standard gamepads
return IPC_OK();
}
mozilla::ipc::IPCResult GamepadEventChannelParent::RecvLightIndicatorColor(
const uint32_t& aControllerIdx, const uint32_t& aLightColorIndex,
const uint8_t& aRed, const uint8_t& aGreen, const uint8_t& aBlue,
const uint32_t& aPromiseID) {
const Tainted<uint32_t>& aControllerIdx,
const Tainted<uint32_t>& aLightColorIndex, const Tainted<uint8_t>& aRed,
const Tainted<uint8_t>& aGreen, const Tainted<uint8_t>& aBlue,
const Tainted<uint32_t>& aPromiseID) {
SetGamepadLightIndicatorColor(aControllerIdx, aLightColorIndex, aRed, aGreen,
aBlue);
if (SendReplyGamepadPromise(aPromiseID)) {
// TODO: simplify tainted validation, see 1610570
if (SendReplyGamepadPromise(MOZ_NO_VALIDATE(
aPromiseID,
"This value is unused aside from being passed back to the child."))) {
return IPC_OK();
}

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

@ -18,16 +18,17 @@ class GamepadEventChannelParent final : public PGamepadEventChannelParent {
static already_AddRefed<GamepadEventChannelParent> Create();
void ActorDestroy(ActorDestroyReason aWhy) override;
mozilla::ipc::IPCResult RecvVibrateHaptic(const uint32_t& aControllerIdx,
const uint32_t& aHapticIndex,
const double& aIntensity,
const double& aDuration,
const uint32_t& aPromiseID);
mozilla::ipc::IPCResult RecvStopVibrateHaptic(const uint32_t& aControllerIdx);
mozilla::ipc::IPCResult RecvVibrateHaptic(
const Tainted<uint32_t>& aControllerIdx,
const Tainted<uint32_t>& aHapticIndex, const Tainted<double>& aIntensity,
const Tainted<double>& aDuration, const Tainted<uint32_t>& aPromiseID);
mozilla::ipc::IPCResult RecvStopVibrateHaptic(
const Tainted<uint32_t>& aControllerIdx);
mozilla::ipc::IPCResult RecvLightIndicatorColor(
const uint32_t& aControllerIdx, const uint32_t& aLightColorIndex,
const uint8_t& aRed, const uint8_t& aGreen, const uint8_t& aBlue,
const uint32_t& aPromiseID);
const Tainted<uint32_t>& aControllerIdx,
const Tainted<uint32_t>& aLightColorIndex, const Tainted<uint8_t>& aRed,
const Tainted<uint8_t>& aGreen, const Tainted<uint8_t>& aBlue,
const Tainted<uint32_t>& aPromiseID);
void DispatchUpdateEvent(const GamepadChangeEvent& aEvent);
GamepadEventChannelParent(const GamepadEventChannelParent&) = delete;

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

@ -13,10 +13,10 @@ refcounted protocol PGamepadEventChannel {
async __delete__();
async VibrateHaptic(uint32_t aControllerIdx, uint32_t aHapticIndex,
double aIntensity, double aDuration, uint32_t aPromiseID);
async StopVibrateHaptic(uint32_t aControllerIdx);
double aIntensity, double aDuration, uint32_t aPromiseID) tainted;
async StopVibrateHaptic(uint32_t aControllerIdx) tainted;
async LightIndicatorColor(uint32_t aControllerIdx, uint32_t aLightColorIndex,
uint8_t aRed, uint8_t aGreen, uint8_t aBlue, uint32_t aPromiseID);
uint8_t aRed, uint8_t aGreen, uint8_t aBlue, uint32_t aPromiseID) tainted;
child:
async GamepadUpdate(GamepadChangeEvent aGamepadEvent);

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

@ -20,6 +20,7 @@
#include <unistd.h>
#include "nscore.h"
#include "mozilla/dom/GamepadPlatformService.h"
#include "mozilla/Tainting.h"
#include "udev.h"
namespace {
@ -342,9 +343,11 @@ void StopGamepadMonitoring() {
gService = nullptr;
}
void SetGamepadLightIndicatorColor(uint32_t aControllerIdx,
uint32_t aLightColorIndex, uint8_t aRed,
uint8_t aGreen, uint8_t aBlue) {
void SetGamepadLightIndicatorColor(const Tainted<uint32_t>& aControllerIdx,
const Tainted<uint32_t>& aLightColorIndex,
const Tainted<uint8_t>& aRed,
const Tainted<uint8_t>& aGreen,
const Tainted<uint8_t>& aBlue) {
// TODO: Bug 1523355.
NS_WARNING("Linux doesn't support gamepad light indicator.");
}

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

@ -68,10 +68,10 @@ class udev_lib {
private:
bool LoadSymbols() {
#define DLSYM(s) \
do { \
s = (typeof(s))dlsym(lib, #s); \
if (!s) return false; \
#define DLSYM(s) \
do { \
s = (__typeof__(s))dlsym(lib, #s); \
if (!s) return false; \
} while (0)
DLSYM(udev_new);

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

@ -334,8 +334,11 @@ class WindowsGamepadService {
void Shutdown();
// Parse gamepad input from a WM_INPUT message.
bool HandleRawInput(HRAWINPUT handle);
void SetLightIndicatorColor(uint32_t aControllerIdx, uint32_t aLightIndex,
uint8_t aRed, uint8_t aGreen, uint8_t aBlue);
void SetLightIndicatorColor(const Tainted<uint32_t>& aControllerIdx,
const Tainted<uint32_t>& aLightColorIndex,
const Tainted<uint8_t>& aRed,
const Tainted<uint8_t>& aGreen,
const Tainted<uint8_t>& aBlue);
size_t WriteOutputReport(const std::vector<uint8_t>& aReport);
static void XInputMessageLoopOnceCallback(nsITimer* aTimer, void* aClosure);
static void DevicesChangeCallback(nsITimer* aTimer, void* aService);
@ -883,32 +886,35 @@ bool WindowsGamepadService::HandleRawInput(HRAWINPUT handle) {
return true;
}
void WindowsGamepadService::SetLightIndicatorColor(uint32_t aControllerIdx,
uint32_t aLightColorIndex,
uint8_t aRed, uint8_t aGreen,
uint8_t aBlue) {
void WindowsGamepadService::SetLightIndicatorColor(
const Tainted<uint32_t>& aControllerIdx,
const Tainted<uint32_t>& aLightColorIndex, const Tainted<uint8_t>& aRed,
const Tainted<uint8_t>& aGreen, const Tainted<uint8_t>& aBlue) {
// We get aControllerIdx from GamepadPlatformService::AddGamepad(),
// It begins from 1 and is stored at Gamepad.id.
const Gamepad* gamepad = nullptr;
for (const auto& pad : mGamepads) {
if (pad.id == aControllerIdx) {
gamepad = &pad;
break;
}
}
const Gamepad* gamepad = (MOZ_FIND_AND_VALIDATE(
aControllerIdx, list_item.id == aControllerIdx, mGamepads));
if (!gamepad) {
MOZ_ASSERT(false);
return;
}
RefPtr<GamepadRemapper> remapper = gamepad->remapper;
if (!remapper || remapper->GetLightIndicatorCount() <= aLightColorIndex) {
if (!remapper ||
MOZ_IS_VALID(aLightColorIndex,
remapper->GetLightIndicatorCount() <= aLightColorIndex)) {
MOZ_ASSERT(false);
return;
}
std::vector<uint8_t> report;
remapper->GetLightColorReport(aRed, aGreen, aBlue, report);
remapper->GetLightColorReport(
MOZ_NO_VALIDATE(aRed, "uint8_t's range is the range of all valid values"),
MOZ_NO_VALIDATE(aGreen,
"uint8_t's range is the range of all valid values"),
MOZ_NO_VALIDATE(aBlue,
"uint8_t's range is the range of all valid values"),
report);
WriteOutputReport(report);
}
@ -1118,9 +1124,11 @@ void StopGamepadMonitoring() {
gMonitorThread = nullptr;
}
void SetGamepadLightIndicatorColor(uint32_t aControllerIdx,
uint32_t aLightColorIndex, uint8_t aRed,
uint8_t aGreen, uint8_t aBlue) {
void SetGamepadLightIndicatorColor(const Tainted<uint32_t>& aControllerIdx,
const Tainted<uint32_t>& aLightColorIndex,
const Tainted<uint8_t>& aRed,
const Tainted<uint8_t>& aGreen,
const Tainted<uint8_t>& aBlue) {
MOZ_ASSERT(gService);
if (!gService) {
return;