mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
bc8ce42355
- Bug 1226200: Don't assume a TCPSocket has only one managee (and rename LoneManagedOrNull) r=jdm (aa2d0fcc14) - Bug 1227300, Part 1 - Add an alert notification component. r=MattN,wchen (37758ce9ff) - Bug 1230700. Make Notification::ShowInternal explicitly suppress the exception from GetPermissionInternal. r=smaug (9e288cf5ae) - Bug 1225336 - Add telemetry about web notification display/messages. r=wchen,kitcambridge p=vladan# Please enter the commit message for your changes. Lines starting (b2e481691a) - Bug 1219030 - Collect notification management telemetry. r=wchen,MattN; p=ally (c0ba425b4e) - Bug 1212611 - Use system notification for website notifications in Android. r=mfinkle (84985bcf01) - Bug 1227300, Part 2 - Implement showAlert. r=MattN,wchen (33eedc7e91) - Bug 1214305 - Part 0: Ensure site security service is initialized before trying to use DataStorage via IPC. (8bd73f43b0) - Bug 1137681 - Make user agent docshell overrides affect network requests. r=jduell (e8dabb8338) - Bug 1233245 - Propagate the interception information in the non-e10s case for all HTTP redirects, not just the internal ones; r=jdm (6922fddcf8) - Bug 1226444 - Use helper function to identify preloads. r=sicking (d110669f73) - Bug 1214305 - Part 1: Refactor the logic for querying whether a connection should go through a secure upgrade into NS_ShouldSecureUpgrade; r=mcmanus (2d04c78290) - Bug 1137681 - Per-tab user agent emulation. r=bz (4ff70db690) - Bug 1227300, Part 3 - Implement showAlert for the OS X alerts backend. r=mstange (5eb05d0728) - Bug 1227300, Part 4 - Implement showAlert for the libnotify alerts backend. r=karlt (0942fa2764) - Bug 1227300, Part 5 - Implement showAlert for the B2G alerts backend. r=mhenretty (e39581aea5) - Bug 1227300, Part 6 - Use showAlert to display web notifications. r=wchen (ab79eaa0c8) - domBug 1227300, Part 7 - Update test interfaces. a=testonly (387cb62772) - Bug 1214305 - Part 3: Add a nsIInterceptedChannel.secureUpgradedChannelURI helper; r=jdm (811d25bd58) - Bug 1214305 - Part 4: Use the secure upgraded channel URI in ServiceWorkerManager::PrepareFetchEvent; r=jdm (0c44bf527c) - Bug 1214305 - Part 5: Use the secure upgraded channel URI in FetchEventRunnable::Init; r=jdm (a30f239261) - Bug 1214305 - Part 6: Use a non-IPC redirect for synthesized upgraded responses to ensure the response URL is correctly propagated; r=mcmanus (8ba8a5728c) - Bug 1214305 - Part 7: Decide in the child process whether an intercepted channel should go through a secure upgrade; r=mcmanus (93e27decae) - Bug 1198397 - Add a test for interception of requests upgraded through the CSP upgrade-insecure-requests directive; r=jdm (21eb14eb34) - Bug 1214305 - Part 8: Enable secure upgrade service worker tests on e10s; r=jdm (c14f5fb504) - Bug 1214305 - Part 10: Clean up global DataStorage references in the child process; r=keeler (ef0b52d049) - Bug 1224771 - Close all web notifications when the originating tab is closed. r=wchen (da295b4ba7) - Bug 1214305 - Part 2: Refactor the logic for obtaining the secure upgraded URI into HttpBaseChannel; r=mcmanus (3346078285) - Bug 1237151 (part 1) - Remove ignored qualifiers in dom/media/gmp/. r=cpearce. (18134820a6) - Bug 1237151 (part 2) - Remove ignored qualifiers in WebRTC-relate code. r=jesup. (effe5bd694) - Bug 1118820 part 1 (style system part) - [css-grid] Implement the 'auto-fill' and 'auto-fit' keywords in the repeat() function. r=dholbert (5db1a577db) - Bug 1118820 part 2a - [css-grid] Add a LineNameMap class that lets us lookup line names with a dynamic number of 'repeat(auto-fill/auto-fit)' tracks taken into account. r=dholbert (3ecf4b53f0) - Bug 1118820 part 2b - [css-grid] Move the static functions FindLine/RFindLine/FindNamedLine into the LineNameMap class (idempotent patch). r=dholbert (efb12c594b) - Bug 1118820 part 2c+2d - [css-grid] Modify the LineNameMap::FindLine/RFindLine/FindNamedLine methods to take line names associated with 'repeat(auto-fill/auto-fit)' tracks into account. Instantiate and pass around a LineNameMap object instead of an array of line name arrays. r=dholbert (a3db750297) - Bug 1118820 part 3a - [css-grid] Modify TrackSizingFunctions to take a dynamic number of 'repeat(auto-fill/auto-fit)' tracks taking into account. r=dholbert (9aa6033332) - Bug 1118820 part 3b - [css-grid] Implement the CalculateRepeatFillCount method that calculates the number of 'repeat(auto-fill/auto-fit)' tracks to use for the given sizes. r=dholbert (cf75fab8a8) - Bug 1118820 part 4 - [css-grid] Provide the sizes to use for CalculateRepeatFillCount. r=dholbert (8184c00dba) - Bug 1118820 part 5 - [css-grid] Remove any empty 'repeat(auto-fit)' tracks at the end of its range and adjust affected grid area line numbers accordingly. r=dholbert (c02ba6a6e3) - Bug 1229165 - [css-grid] Reftests for min/max-width/height properties on the grid container. (725097f878) - Bug 1229999 - [css-grid] Reftest. (51b5bc9535) - Bug 1237151 (part 3) - Remove ignored qualifiers in all remaining code. r=froydnj. (69917ebbad) - more bits of Bug 1178892 - Split the profiler into Core & Gecko files (41bb127b9c) - Bug 1199841 - Restructure private browsing to remember status after OnStopRequest r=jdm (16c2c1044d) - Bug 1233845 - Report an interception error and cancel the HTTP channel when encountering a known topcrash situation. r=ehsan (5d08075110) - Bug 664163 - Fix Get(Local|Remote)(Address|Port) in HttpChannelChild. r=jduell (cbf70af4e8) - Bug 1229177 - Show the tracking protection shield for fetch and XHR requests. r=jduell (5833b3e872) - Bug 1220678 Don't crash when DivertToParent() is called on an intercepted channel. r=jdm (5d7ff6ecc8) - Bug 1220681 P1 Make HttpChannelChild::DivertToParent() work with synthetic responses. r=jdm (67715703ef) - Bug 1169819 Add browser chrome test to validate SW force refresh. r=ehsan (c0b6b3e874) - Bug 1220681 P2 Test synthetic responses that trigger downloads. r=ehsan (c701f3ddb1) - Bug 1220681 P3 Delay diversion on parent side until response head has been synthesized. r=jdm (7c697aacee) - Bug 1220681 P4 Automatically suspend the parent channel after synthesizing the response for diverison. r=jdm (27f31bcb35) - Bug 1220681 P5 Don't double suspend parent channel during synthesized divert to parent. r=jdm (62081d4b56) - Bug 1220681 P6 Use clients.claim() in browser_download.js to avoid worker unregister race. r=jdm (c8de291727) - Bug 1240161 - Remove "only-if-cached" from RequestCache; r=bkelly (283486f584) - Bug 1184550 - Add a mochitest for the Request constructor that tests that the body is set to used after being fetched and then fails on the second fetch with the same Request. r=bkelly (db4a967203) - Bug 1205495 - Correctly use the requests's body and redirect mode in reroute.js; r=nsm (a36a96624a) - Bug 1189656 - Fix fetch-request-fallback test paths. r=bkelly (366c884179) - Bug 1219085 - Import the fetch-request-redirect.https.html test from Blink; r=jdm (bf6b484d82) - Bug 1209081 - Part 1: Implement the "navigate" value for RequestMode; r=bkelly (a22f19d94b) - Bug 1209081 - Part 2: Upgrade the saved Requests in the DOM Cache to reflect the "navigate" RequestMode if they represent navigation content policy types; r=bkelly (60d1da23bb) - Bug 1219469 - Part 1: Revert the error reporting added in bug 1233845; r=jdm (dcc022b9d3) - Bug 1219469 - Part 2: Make HttpChannelParentListener be the controller; r=jdm,jduell (9c5f0dfbe0) - Bug 1229369 - Intercept redirected network fetches that have their request mode set to manual; r=jdm (fb21d86ed2)
524 lines
15 KiB
C++
524 lines
15 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
// mostly derived from the Allegro source code at:
|
|
// http://alleg.svn.sourceforge.net/viewvc/alleg/allegro/branches/4.9/src/macosx/hidjoy.m?revision=13760&view=markup
|
|
|
|
#include "mozilla/dom/GamepadFunctions.h"
|
|
#include "mozilla/ArrayUtils.h"
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
#include <IOKit/hid/IOHIDBase.h>
|
|
#include <IOKit/hid/IOHIDKeys.h>
|
|
#include <IOKit/hid/IOHIDManager.h>
|
|
|
|
#include <stdio.h>
|
|
#include <vector>
|
|
|
|
namespace {
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::dom::GamepadFunctions;
|
|
using std::vector;
|
|
|
|
struct Button {
|
|
int id;
|
|
bool analog;
|
|
IOHIDElementRef element;
|
|
CFIndex min;
|
|
CFIndex max;
|
|
|
|
Button(int aId, IOHIDElementRef aElement, CFIndex aMin, CFIndex aMax) :
|
|
id(aId),
|
|
analog((aMax - aMin) > 1),
|
|
element(aElement),
|
|
min(aMin),
|
|
max(aMax) {}
|
|
};
|
|
|
|
struct Axis {
|
|
int id;
|
|
IOHIDElementRef element;
|
|
uint32_t usagePage;
|
|
uint32_t usage;
|
|
CFIndex min;
|
|
CFIndex max;
|
|
};
|
|
|
|
typedef bool dpad_buttons[4];
|
|
|
|
// These values can be found in the USB HID Usage Tables:
|
|
// http://www.usb.org/developers/hidpage
|
|
const unsigned kDesktopUsagePage = 0x01;
|
|
const unsigned kSimUsagePage = 0x02;
|
|
const unsigned kAcceleratorUsage = 0xC4;
|
|
const unsigned kBrakeUsage = 0xC5;
|
|
const unsigned kJoystickUsage = 0x04;
|
|
const unsigned kGamepadUsage = 0x05;
|
|
const unsigned kAxisUsageMin = 0x30;
|
|
const unsigned kAxisUsageMax = 0x35;
|
|
const unsigned kDpadUsage = 0x39;
|
|
const unsigned kButtonUsagePage = 0x09;
|
|
const unsigned kConsumerPage = 0x0C;
|
|
const unsigned kHomeUsage = 0x223;
|
|
const unsigned kBackUsage = 0x224;
|
|
|
|
|
|
class Gamepad {
|
|
private:
|
|
IOHIDDeviceRef mDevice;
|
|
nsTArray<Button> buttons;
|
|
nsTArray<Axis> axes;
|
|
IOHIDElementRef mDpad;
|
|
dpad_buttons mDpadState;
|
|
|
|
public:
|
|
Gamepad() : mDevice(nullptr), mDpad(nullptr), mSuperIndex(-1) {}
|
|
bool operator==(IOHIDDeviceRef device) const { return mDevice == device; }
|
|
bool empty() const { return mDevice == nullptr; }
|
|
void clear()
|
|
{
|
|
mDevice = nullptr;
|
|
buttons.Clear();
|
|
axes.Clear();
|
|
mDpad = nullptr;
|
|
mSuperIndex = -1;
|
|
}
|
|
void init(IOHIDDeviceRef device);
|
|
size_t numButtons() { return buttons.Length() + (mDpad ? 4 : 0); }
|
|
size_t numAxes() { return axes.Length(); }
|
|
|
|
// Index given by our superclass.
|
|
uint32_t mSuperIndex;
|
|
|
|
bool isDpad(IOHIDElementRef element) const
|
|
{
|
|
return element == mDpad;
|
|
}
|
|
|
|
const dpad_buttons& getDpadState() const
|
|
{
|
|
return mDpadState;
|
|
}
|
|
|
|
void setDpadState(const dpad_buttons& dpadState)
|
|
{
|
|
for (unsigned i = 0; i < ArrayLength(mDpadState); i++) {
|
|
mDpadState[i] = dpadState[i];
|
|
}
|
|
}
|
|
|
|
const Button* lookupButton(IOHIDElementRef element) const
|
|
{
|
|
for (unsigned i = 0; i < buttons.Length(); i++) {
|
|
if (buttons[i].element == element)
|
|
return &buttons[i];
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
const Axis* lookupAxis(IOHIDElementRef element) const
|
|
{
|
|
for (unsigned i = 0; i < axes.Length(); i++) {
|
|
if (axes[i].element == element)
|
|
return &axes[i];
|
|
}
|
|
return nullptr;
|
|
}
|
|
};
|
|
|
|
class AxisComparator {
|
|
public:
|
|
bool Equals(const Axis& a1, const Axis& a2) const
|
|
{
|
|
return a1.usagePage == a2.usagePage && a1.usage == a2.usage;
|
|
}
|
|
bool LessThan(const Axis& a1, const Axis& a2) const
|
|
{
|
|
if (a1.usagePage == a2.usagePage) {
|
|
return a1.usage < a2.usage;
|
|
}
|
|
return a1.usagePage < a2.usagePage;
|
|
}
|
|
};
|
|
|
|
void Gamepad::init(IOHIDDeviceRef device)
|
|
{
|
|
clear();
|
|
mDevice = device;
|
|
|
|
CFArrayRef elements = IOHIDDeviceCopyMatchingElements(device,
|
|
nullptr,
|
|
kIOHIDOptionsTypeNone);
|
|
CFIndex n = CFArrayGetCount(elements);
|
|
for (CFIndex i = 0; i < n; i++) {
|
|
IOHIDElementRef element = (IOHIDElementRef)CFArrayGetValueAtIndex(elements,
|
|
i);
|
|
uint32_t usagePage = IOHIDElementGetUsagePage(element);
|
|
uint32_t usage = IOHIDElementGetUsage(element);
|
|
|
|
if (usagePage == kDesktopUsagePage &&
|
|
usage >= kAxisUsageMin &&
|
|
usage <= kAxisUsageMax)
|
|
{
|
|
Axis axis = { int(axes.Length()),
|
|
element,
|
|
usagePage,
|
|
usage,
|
|
IOHIDElementGetLogicalMin(element),
|
|
IOHIDElementGetLogicalMax(element) };
|
|
axes.AppendElement(axis);
|
|
} else if (usagePage == kDesktopUsagePage && usage == kDpadUsage &&
|
|
// Don't know how to handle d-pads that return weird values.
|
|
IOHIDElementGetLogicalMax(element) - IOHIDElementGetLogicalMin(element) == 7) {
|
|
mDpad = element;
|
|
} else if ((usagePage == kSimUsagePage &&
|
|
(usage == kAcceleratorUsage ||
|
|
usage == kBrakeUsage)) ||
|
|
(usagePage == kButtonUsagePage) ||
|
|
(usagePage == kConsumerPage &&
|
|
(usage == kHomeUsage ||
|
|
usage == kBackUsage))) {
|
|
Button button(int(buttons.Length()), element, IOHIDElementGetLogicalMin(element), IOHIDElementGetLogicalMax(element));
|
|
buttons.AppendElement(button);
|
|
} else {
|
|
//TODO: handle other usage pages
|
|
}
|
|
}
|
|
|
|
AxisComparator comparator;
|
|
axes.Sort(comparator);
|
|
for (unsigned i = 0; i < axes.Length(); i++) {
|
|
axes[i].id = i;
|
|
}
|
|
}
|
|
|
|
class DarwinGamepadService {
|
|
private:
|
|
IOHIDManagerRef mManager;
|
|
vector<Gamepad> mGamepads;
|
|
|
|
static void DeviceAddedCallback(void* data, IOReturn result,
|
|
void* sender, IOHIDDeviceRef device);
|
|
static void DeviceRemovedCallback(void* data, IOReturn result,
|
|
void* sender, IOHIDDeviceRef device);
|
|
static void InputValueChangedCallback(void* data, IOReturn result,
|
|
void* sender, IOHIDValueRef newValue);
|
|
|
|
void DeviceAdded(IOHIDDeviceRef device);
|
|
void DeviceRemoved(IOHIDDeviceRef device);
|
|
void InputValueChanged(IOHIDValueRef value);
|
|
|
|
public:
|
|
DarwinGamepadService();
|
|
~DarwinGamepadService();
|
|
void Startup();
|
|
void Shutdown();
|
|
};
|
|
|
|
void
|
|
DarwinGamepadService::DeviceAdded(IOHIDDeviceRef device)
|
|
{
|
|
size_t slot = size_t(-1);
|
|
for (size_t i = 0; i < mGamepads.size(); i++) {
|
|
if (mGamepads[i] == device)
|
|
return;
|
|
if (slot == size_t(-1) && mGamepads[i].empty())
|
|
slot = i;
|
|
}
|
|
|
|
if (slot == size_t(-1)) {
|
|
slot = mGamepads.size();
|
|
mGamepads.push_back(Gamepad());
|
|
}
|
|
mGamepads[slot].init(device);
|
|
|
|
// Gather some identifying information
|
|
CFNumberRef vendorIdRef =
|
|
(CFNumberRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey));
|
|
CFNumberRef productIdRef =
|
|
(CFNumberRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductIDKey));
|
|
CFStringRef productRef =
|
|
(CFStringRef)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey));
|
|
int vendorId, productId;
|
|
CFNumberGetValue(vendorIdRef, kCFNumberIntType, &vendorId);
|
|
CFNumberGetValue(productIdRef, kCFNumberIntType, &productId);
|
|
char product_name[128];
|
|
CFStringGetCString(productRef, product_name,
|
|
sizeof(product_name), kCFStringEncodingASCII);
|
|
char buffer[256];
|
|
sprintf(buffer, "%x-%x-%s", vendorId, productId, product_name);
|
|
mGamepads[slot].mSuperIndex = AddGamepad(buffer,
|
|
mozilla::dom::GamepadMappingType::_empty,
|
|
(int)mGamepads[slot].numButtons(),
|
|
(int)mGamepads[slot].numAxes());
|
|
}
|
|
|
|
void
|
|
DarwinGamepadService::DeviceRemoved(IOHIDDeviceRef device)
|
|
{
|
|
for (size_t i = 0; i < mGamepads.size(); i++) {
|
|
if (mGamepads[i] == device) {
|
|
RemoveGamepad(mGamepads[i].mSuperIndex);
|
|
mGamepads[i].clear();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Given a value from a d-pad (POV hat in USB HID terminology),
|
|
* represent it as 4 buttons, one for each cardinal direction.
|
|
*/
|
|
static void
|
|
UnpackDpad(int dpad_value, int min, int max, dpad_buttons& buttons)
|
|
{
|
|
const unsigned kUp = 0;
|
|
const unsigned kDown = 1;
|
|
const unsigned kLeft = 2;
|
|
const unsigned kRight = 3;
|
|
|
|
// Different controllers have different ways of representing
|
|
// "nothing is pressed", but they're all outside the range of values.
|
|
if (dpad_value < min || dpad_value > max) {
|
|
// Nothing is pressed.
|
|
return;
|
|
}
|
|
|
|
// Normalize value to start at 0.
|
|
int value = dpad_value - min;
|
|
|
|
// Value will be in the range 0-7. The value represents the
|
|
// position of the d-pad around a circle, with 0 being straight up,
|
|
// 2 being right, 4 being straight down, and 6 being left.
|
|
if (value < 2 || value > 6) {
|
|
buttons[kUp] = true;
|
|
}
|
|
if (value > 2 && value < 6) {
|
|
buttons[kDown] = true;
|
|
}
|
|
if (value > 4) {
|
|
buttons[kLeft] = true;
|
|
}
|
|
if (value > 0 && value < 4) {
|
|
buttons[kRight] = true;
|
|
}
|
|
}
|
|
|
|
void
|
|
DarwinGamepadService::InputValueChanged(IOHIDValueRef value)
|
|
{
|
|
uint32_t value_length = IOHIDValueGetLength(value);
|
|
if (value_length > 4) {
|
|
// Workaround for bizarre issue with PS3 controllers that try to return
|
|
// massive (30+ byte) values and crash IOHIDValueGetIntegerValue
|
|
return;
|
|
}
|
|
IOHIDElementRef element = IOHIDValueGetElement(value);
|
|
IOHIDDeviceRef device = IOHIDElementGetDevice(element);
|
|
for (unsigned i = 0; i < mGamepads.size(); i++) {
|
|
Gamepad &gamepad = mGamepads[i];
|
|
if (gamepad == device) {
|
|
if (gamepad.isDpad(element)) {
|
|
const dpad_buttons& oldState = gamepad.getDpadState();
|
|
dpad_buttons newState = { false, false, false, false };
|
|
UnpackDpad(IOHIDValueGetIntegerValue(value),
|
|
IOHIDElementGetLogicalMin(element),
|
|
IOHIDElementGetLogicalMax(element),
|
|
newState);
|
|
const int numButtons = gamepad.numButtons();
|
|
for (unsigned b = 0; b < ArrayLength(newState); b++) {
|
|
if (newState[b] != oldState[b]) {
|
|
NewButtonEvent(i, numButtons - 4 + b, newState[b]);
|
|
}
|
|
}
|
|
gamepad.setDpadState(newState);
|
|
} else if (const Axis* axis = gamepad.lookupAxis(element)) {
|
|
double d = IOHIDValueGetIntegerValue(value);
|
|
double v = 2.0f * (d - axis->min) /
|
|
(double)(axis->max - axis->min) - 1.0f;
|
|
NewAxisMoveEvent(i, axis->id, v);
|
|
} else if (const Button* button = gamepad.lookupButton(element)) {
|
|
int iv = IOHIDValueGetIntegerValue(value);
|
|
bool pressed = iv != 0;
|
|
double v = 0;
|
|
if (button->analog) {
|
|
double dv = iv;
|
|
v = (dv - button->min) / (double)(button->max - button->min);
|
|
} else {
|
|
v = pressed ? 1.0 : 0.0;
|
|
}
|
|
NewButtonEvent(i, button->id, pressed, v);
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
DarwinGamepadService::DeviceAddedCallback(void* data, IOReturn result,
|
|
void* sender, IOHIDDeviceRef device)
|
|
{
|
|
DarwinGamepadService* service = (DarwinGamepadService*)data;
|
|
service->DeviceAdded(device);
|
|
}
|
|
|
|
void
|
|
DarwinGamepadService::DeviceRemovedCallback(void* data, IOReturn result,
|
|
void* sender, IOHIDDeviceRef device)
|
|
{
|
|
DarwinGamepadService* service = (DarwinGamepadService*)data;
|
|
service->DeviceRemoved(device);
|
|
}
|
|
|
|
void
|
|
DarwinGamepadService::InputValueChangedCallback(void* data,
|
|
IOReturn result,
|
|
void* sender,
|
|
IOHIDValueRef newValue)
|
|
{
|
|
DarwinGamepadService* service = (DarwinGamepadService*)data;
|
|
service->InputValueChanged(newValue);
|
|
}
|
|
|
|
static CFMutableDictionaryRef
|
|
MatchingDictionary(UInt32 inUsagePage, UInt32 inUsage)
|
|
{
|
|
CFMutableDictionaryRef dict =
|
|
CFDictionaryCreateMutable(kCFAllocatorDefault,
|
|
0,
|
|
&kCFTypeDictionaryKeyCallBacks,
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
if (!dict)
|
|
return nullptr;
|
|
CFNumberRef number = CFNumberCreate(kCFAllocatorDefault,
|
|
kCFNumberIntType,
|
|
&inUsagePage);
|
|
if (!number) {
|
|
CFRelease(dict);
|
|
return nullptr;
|
|
}
|
|
CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsagePageKey), number);
|
|
CFRelease(number);
|
|
|
|
number = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &inUsage);
|
|
if (!number) {
|
|
CFRelease(dict);
|
|
return nullptr;
|
|
}
|
|
CFDictionarySetValue(dict, CFSTR(kIOHIDDeviceUsageKey), number);
|
|
CFRelease(number);
|
|
|
|
return dict;
|
|
}
|
|
|
|
DarwinGamepadService::DarwinGamepadService() : mManager(nullptr) {}
|
|
|
|
DarwinGamepadService::~DarwinGamepadService()
|
|
{
|
|
if (mManager != nullptr)
|
|
CFRelease(mManager);
|
|
}
|
|
|
|
void DarwinGamepadService::Startup()
|
|
{
|
|
if (mManager != nullptr)
|
|
return;
|
|
|
|
IOHIDManagerRef manager = IOHIDManagerCreate(kCFAllocatorDefault,
|
|
kIOHIDOptionsTypeNone);
|
|
|
|
CFMutableDictionaryRef criteria_arr[2];
|
|
criteria_arr[0] = MatchingDictionary(kDesktopUsagePage,
|
|
kJoystickUsage);
|
|
if (!criteria_arr[0]) {
|
|
CFRelease(manager);
|
|
return;
|
|
}
|
|
|
|
criteria_arr[1] = MatchingDictionary(kDesktopUsagePage,
|
|
kGamepadUsage);
|
|
if (!criteria_arr[1]) {
|
|
CFRelease(criteria_arr[0]);
|
|
CFRelease(manager);
|
|
return;
|
|
}
|
|
|
|
CFArrayRef criteria =
|
|
CFArrayCreate(kCFAllocatorDefault, (const void**)criteria_arr, 2, nullptr);
|
|
if (!criteria) {
|
|
CFRelease(criteria_arr[1]);
|
|
CFRelease(criteria_arr[0]);
|
|
CFRelease(manager);
|
|
return;
|
|
}
|
|
|
|
IOHIDManagerSetDeviceMatchingMultiple(manager, criteria);
|
|
CFRelease(criteria);
|
|
CFRelease(criteria_arr[1]);
|
|
CFRelease(criteria_arr[0]);
|
|
|
|
IOHIDManagerRegisterDeviceMatchingCallback(manager,
|
|
DeviceAddedCallback,
|
|
this);
|
|
IOHIDManagerRegisterDeviceRemovalCallback(manager,
|
|
DeviceRemovedCallback,
|
|
this);
|
|
IOHIDManagerRegisterInputValueCallback(manager,
|
|
InputValueChangedCallback,
|
|
this);
|
|
IOHIDManagerScheduleWithRunLoop(manager,
|
|
CFRunLoopGetCurrent(),
|
|
kCFRunLoopDefaultMode);
|
|
IOReturn rv = IOHIDManagerOpen(manager, kIOHIDOptionsTypeNone);
|
|
if (rv != kIOReturnSuccess) {
|
|
CFRelease(manager);
|
|
return;
|
|
}
|
|
|
|
mManager = manager;
|
|
}
|
|
|
|
void DarwinGamepadService::Shutdown()
|
|
{
|
|
IOHIDManagerRef manager = (IOHIDManagerRef)mManager;
|
|
if (manager) {
|
|
IOHIDManagerClose(manager, 0);
|
|
CFRelease(manager);
|
|
mManager = nullptr;
|
|
}
|
|
}
|
|
|
|
} // namespace
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
DarwinGamepadService* gService = nullptr;
|
|
|
|
void StartGamepadMonitoring()
|
|
{
|
|
if (gService) {
|
|
return;
|
|
}
|
|
|
|
gService = new DarwinGamepadService();
|
|
gService->Startup();
|
|
}
|
|
|
|
void StopGamepadMonitoring()
|
|
{
|
|
if (!gService) {
|
|
return;
|
|
}
|
|
|
|
gService->Shutdown();
|
|
delete gService;
|
|
gService = nullptr;
|
|
}
|
|
|
|
} // namespace dom
|
|
} // namespace mozilla
|