mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-21 15:57:31 +09:00
WebUSB initial commit
This commit is contained in:
parent
c461f87cc7
commit
b898673be8
22 changed files with 2231 additions and 1 deletions
|
|
@ -2241,6 +2241,9 @@ const ContentPermissionIntegration = {
|
|||
case "geolocation": {
|
||||
return new PermissionUI.GeolocationPermissionPrompt(request);
|
||||
}
|
||||
case "usb": {
|
||||
return new PermissionUI.USBPermissionPrompt(request);
|
||||
}
|
||||
case "desktop-notification": {
|
||||
return new PermissionUI.DesktopNotificationPermissionPrompt(request);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@
|
|||
<preference id="javascript.options.wasm"
|
||||
name="javascript.options.wasm"
|
||||
type="bool"/>
|
||||
<preference id="dom.usb.enabled"
|
||||
name="dom.usb.enabled"
|
||||
type="bool"/>
|
||||
#ifdef MOZ_WEBRTC
|
||||
<preference id="media.peerconnection.enabled"
|
||||
name="media.peerconnection.enabled"
|
||||
|
|
@ -246,6 +249,14 @@
|
|||
accesskey="&javascriptWasm.accesskey;" />
|
||||
</vbox>
|
||||
</row>
|
||||
<row id="javascriptWebUSBRow">
|
||||
<vbox align="start">
|
||||
<checkbox id="javascriptWebUSBPolicy"
|
||||
preference="dom.usb.enabled"
|
||||
label="&javascriptWebusb.label;"
|
||||
accesskey="&javascriptWebusb.accesskey;" />
|
||||
</vbox>
|
||||
</row>
|
||||
#ifdef MOZ_WEBRTC
|
||||
<row id="javascriptRow2">
|
||||
<vbox align="start">
|
||||
|
|
|
|||
|
|
@ -367,6 +367,12 @@ geolocation.neverShareLocation.accesskey=N
|
|||
geolocation.shareWithSite2=Would you like to share your location with this site?
|
||||
geolocation.shareWithFile2=Would you like to share your location with this file?
|
||||
|
||||
webUSB.connectToSite=Would you like to let this site access USB devices?
|
||||
webUSB.allow=Allow USB Devices
|
||||
webUSB.allow.accesskey=A
|
||||
webUSB.block=Block USB Devices
|
||||
webUSB.block.accesskey=B
|
||||
|
||||
webNotifications.receiveForSession=Receive for this session
|
||||
webNotifications.receiveForSession.accesskey=s
|
||||
webNotifications.alwaysReceive=Always Receive Notifications
|
||||
|
|
|
|||
|
|
@ -48,6 +48,8 @@
|
|||
|
||||
<!ENTITY javascriptWasm.label "Enable WebAssembly (WASM)">
|
||||
<!ENTITY javascriptWasm.accesskey "y">
|
||||
<!ENTITY javascriptWebusb.label "Enable WebUSB">
|
||||
<!ENTITY javascriptWebusb.accesskey "U">
|
||||
#ifdef MOZ_WEBRTC
|
||||
<!ENTITY javascriptWebrtc.label "Enable WebRTC">
|
||||
<!ENTITY javascriptWebrtc.accesskey "R">
|
||||
|
|
|
|||
|
|
@ -472,6 +472,59 @@ GeolocationPermissionPrompt.prototype = {
|
|||
|
||||
PermissionUI.GeolocationPermissionPrompt = GeolocationPermissionPrompt;
|
||||
|
||||
/**
|
||||
* Creates a PermissionPrompt for the WebUSB API.
|
||||
* USB access is granted for the current browser session.
|
||||
*/
|
||||
function getUSBString(name, fallback) {
|
||||
try {
|
||||
return gBrowserBundle.GetStringFromName(name);
|
||||
} catch (ex) {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
function USBPermissionPrompt(request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
USBPermissionPrompt.prototype = {
|
||||
__proto__: PermissionPromptForRequestPrototype,
|
||||
|
||||
get permissionKey() {
|
||||
return "usb";
|
||||
},
|
||||
|
||||
get notificationID() {
|
||||
return "web-usb";
|
||||
},
|
||||
|
||||
get anchorID() {
|
||||
return "default-notification-icon";
|
||||
},
|
||||
|
||||
get message() {
|
||||
return getUSBString("webUSB.connectToSite",
|
||||
"Would you like to let this site access USB devices?");
|
||||
},
|
||||
|
||||
get promptActions() {
|
||||
return [{
|
||||
label: getUSBString("webUSB.allow", "Allow USB Devices"),
|
||||
accessKey: getUSBString("webUSB.allow.accesskey", "A"),
|
||||
action: Ci.nsIPermissionManager.ALLOW_ACTION,
|
||||
expireType: Ci.nsIPermissionManager.EXPIRE_SESSION,
|
||||
}, {
|
||||
label: getUSBString("webUSB.block", "Block USB Devices"),
|
||||
accessKey: getUSBString("webUSB.block.accesskey", "B"),
|
||||
action: Ci.nsIPermissionManager.DENY_ACTION,
|
||||
expireType: Ci.nsIPermissionManager.EXPIRE_SESSION,
|
||||
}];
|
||||
},
|
||||
};
|
||||
|
||||
PermissionUI.USBPermissionPrompt = USBPermissionPrompt;
|
||||
|
||||
/**
|
||||
* Creates a PermissionPrompt for a nsIContentPermissionRequest for
|
||||
* the Desktop Notification API.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue