mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-22 08:27:31 +09:00
USBPermissionRequest pt.2
This commit is contained in:
parent
523744bc74
commit
e1e5fbf698
2 changed files with 52 additions and 12 deletions
|
|
@ -490,6 +490,7 @@ function USBPermissionPrompt(request) {
|
||||||
|
|
||||||
function getUSBDeviceChoices(request) {
|
function getUSBDeviceChoices(request) {
|
||||||
let choices = [];
|
let choices = [];
|
||||||
|
try {
|
||||||
let types = request.types.QueryInterface(Ci.nsIArray);
|
let types = request.types.QueryInterface(Ci.nsIArray);
|
||||||
if (!types.length) {
|
if (!types.length) {
|
||||||
return choices;
|
return choices;
|
||||||
|
|
@ -502,7 +503,11 @@ function getUSBDeviceChoices(request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < options.length; ++i) {
|
for (let i = 0; i < options.length; ++i) {
|
||||||
choices.push(options.queryElementAt(i, Ci.nsISupportsString).data);
|
let option = options.queryElementAt(i, Ci.nsISupportsString);
|
||||||
|
choices.push(option.data || "USB device");
|
||||||
|
}
|
||||||
|
} catch (ex) {
|
||||||
|
Cu.reportError("Unable to read WebUSB device choices: " + ex);
|
||||||
}
|
}
|
||||||
return choices;
|
return choices;
|
||||||
}
|
}
|
||||||
|
|
@ -510,6 +515,37 @@ function getUSBDeviceChoices(request) {
|
||||||
USBPermissionPrompt.prototype = {
|
USBPermissionPrompt.prototype = {
|
||||||
__proto__: PermissionPromptForRequestPrototype,
|
__proto__: PermissionPromptForRequestPrototype,
|
||||||
|
|
||||||
|
// UXP builds do not always expose the requesting <browser> through
|
||||||
|
// nsIContentPermissionRequest.element. Resolve the active browser window
|
||||||
|
// here so the USB doorhanger is still shown for those requests.
|
||||||
|
get browser() {
|
||||||
|
let element = this.request.element;
|
||||||
|
if (element && element.ownerGlobal && element.ownerGlobal.PopupNotifications) {
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
let window = this.request.window;
|
||||||
|
if (window) {
|
||||||
|
let browser = window.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIWebNavigation)
|
||||||
|
.QueryInterface(Ci.nsIDocShell)
|
||||||
|
.chromeEventHandler;
|
||||||
|
if (browser && browser.ownerGlobal &&
|
||||||
|
browser.ownerGlobal.PopupNotifications) {
|
||||||
|
return browser;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (ex) {
|
||||||
|
// Fall through to the most recent browser window below.
|
||||||
|
}
|
||||||
|
|
||||||
|
let chromeWindow = Services.wm.getMostRecentWindow("navigator:browser");
|
||||||
|
return chromeWindow && chromeWindow.gBrowser
|
||||||
|
? chromeWindow.gBrowser.selectedBrowser
|
||||||
|
: element;
|
||||||
|
},
|
||||||
|
|
||||||
get notificationID() {
|
get notificationID() {
|
||||||
return "web-usb";
|
return "web-usb";
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,11 @@ bool
|
||||||
MatchesRequest(const USBDeviceInfo& aDevice,
|
MatchesRequest(const USBDeviceInfo& aDevice,
|
||||||
const USBDeviceRequestOptions& aOptions)
|
const USBDeviceRequestOptions& aOptions)
|
||||||
{
|
{
|
||||||
bool included = false;
|
// Chromium accepts a chooser request that has no restrictive filters and
|
||||||
|
// lets the user select from the enumerated USB devices. Keep that useful
|
||||||
|
// behaviour in UXP as well; an empty filter list must not suppress the
|
||||||
|
// permission prompt entirely.
|
||||||
|
bool included = aOptions.mFilters.IsEmpty();
|
||||||
for (const auto& filter : aOptions.mFilters) {
|
for (const auto& filter : aOptions.mFilters) {
|
||||||
if (MatchesFilter(aDevice, filter)) {
|
if (MatchesFilter(aDevice, filter)) {
|
||||||
included = true;
|
included = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue