@crossbind/extension-page-permissions 0.0.0-stage → 2.0.0-beta.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Buğra Sarı and crossbind contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,25 @@
1
- # Temporary Holding Version
1
+ # @crossbind/extension-page-permissions
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ What a page may use, such as the camera and the microphone.
4
+
5
+ An app has it by having `@crossbind/core-app-host`, which lists it as a dependency: there is nothing to install or list.
6
+
7
+ ## What it does
8
+
9
+ The page gets the devices `app.permissions` lists, as the camera and the microphone, and the clipboard's text, which a
10
+ webview asks for on its user's gesture alone, and nothing else, so that no webview asks the app's user anything of its
11
+ own. The system still asks for each device.
12
+
13
+ ## Options
14
+
15
+ `app.permissions` lists each device with the reason the system shows, as `{ camera: 'To scan barcodes' }`.
16
+
17
+ ## Platforms
18
+
19
+ macOS, iOS, Linux, Windows and Android.
20
+
21
+ ## Replace or leave out
22
+
23
+ It holds the role `page-permissions`. An extension that gives `replaces: 'page-permissions'` takes it; `app: { without: ['page-permissions'] }` in `crossbind.config.js` leaves it out. Leaving it out while `app.permissions` is set stops the build. [The guide](https://crossbind.dev/guide/extensions/#replace) shows how, and [extensions.md](https://github.com/crossbind/crossbind/blob/main/docs/api/extensions.md#the-hosts-own-extensions) what a replacement answers.
24
+
25
+ [extensions.md](https://github.com/crossbind/crossbind/blob/main/docs/api/extensions.md#the-pages-requests) has the hooks a replacement answers.
@@ -0,0 +1,15 @@
1
+ export default function pagePermissions() {
2
+ return {
3
+ name: 'page-permissions',
4
+ contract: 1,
5
+ root: import.meta.dirname,
6
+ reads: ['permissions'],
7
+ app: {
8
+ macos: { sources: ['native/permissions.cpp'] },
9
+ ios: { sources: ['native/permissions.cpp'] },
10
+ linux: { sources: ['native/permissions.cpp'] },
11
+ windows: { sources: ['native/permissions.cpp'] },
12
+ android: { java: 'native/android', class: 'dev.crossbind.extension.pagepermissions.PagePermissionsExtension' },
13
+ },
14
+ };
15
+ }
@@ -0,0 +1,53 @@
1
+ package dev.crossbind.extension.pagepermissions;
2
+
3
+ import android.Manifest;
4
+ import android.app.Activity;
5
+ import android.content.pm.PackageManager;
6
+
7
+ import java.util.Arrays;
8
+ import java.util.List;
9
+ import java.util.Map;
10
+
11
+ import org.json.JSONObject;
12
+
13
+ import dev.crossbind.app.Extension;
14
+ import dev.crossbind.app.ExtensionHost;
15
+
16
+ // The host's page-permissions on Android: the page gets the devices the manifest asks for, which crossbind writes from
17
+ // app.permissions, once the app's user gives them, and nothing else, so that the WebView asks nothing of its own. The
18
+ // location is the approximate one at least, which its user may give alone.
19
+ public final class PagePermissionsExtension implements Extension {
20
+ private static final String COARSE = Manifest.permission.ACCESS_COARSE_LOCATION;
21
+ private static final Map<String, String> DEVICES = Map.of(
22
+ "camera", Manifest.permission.CAMERA,
23
+ "microphone", Manifest.permission.RECORD_AUDIO);
24
+
25
+ @Override
26
+ public void call(ExtensionHost host, String function, JSONObject options, Call call) {
27
+ call.reject("crossbind: page-permissions has no function " + function);
28
+ }
29
+
30
+ @Override
31
+ public void onPagePermission(ExtensionHost host, PagePermission request) {
32
+ Activity activity = host.activity();
33
+ if (!request.isListed()) {
34
+ request.deny();
35
+ } else if (request.kinds().equals(List.of("location"))) {
36
+ // Asked for the precise location again, a user who gave the approximate one is asked to change it.
37
+ if (isGranted(activity, COARSE)) request.allow();
38
+ else host.afterAsking(new String[] {COARSE, Manifest.permission.ACCESS_FINE_LOCATION}, () -> answer(activity, request, COARSE));
39
+ } else {
40
+ String[] permissions = request.kinds().stream().map(DEVICES::get).toArray(String[]::new);
41
+ host.afterAsking(permissions, () -> answer(activity, request, permissions));
42
+ }
43
+ }
44
+
45
+ private static void answer(Activity activity, PagePermission request, String... permissions) {
46
+ if (Arrays.stream(permissions).allMatch((permission) -> isGranted(activity, permission))) request.allow();
47
+ else request.deny();
48
+ }
49
+
50
+ private static boolean isGranted(Activity activity, String permission) {
51
+ return activity.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
52
+ }
53
+ }
@@ -0,0 +1,12 @@
1
+ #include "crossbind/extension.h"
2
+
3
+ // The host's page-permissions: the page gets the devices app.permissions lists, and the clipboard's text, which a
4
+ // webview asks for on its user's gesture alone, and nothing else, so that no webview asks the app's user anything of
5
+ // its own. The system still asks for each device.
6
+ void crossbind_extension_page_permissions(crossbind::Registry &registry) {
7
+ registry.onPagePermission([](crossbind::PagePermission request) {
8
+ const auto &kinds = request.kinds();
9
+ if (request.isListed() || (kinds.size() == 1 && kinds.front() == "clipboard")) request.allow();
10
+ else request.deny();
11
+ });
12
+ }
package/package.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "@crossbind/extension-page-permissions",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "2.0.0-beta.69",
4
+ "description": "crossbind app extension: what a page may use, such as the camera and the microphone.",
5
+ "homepage": "https://github.com/crossbind/crossbind/tree/main/extensions/page-permissions#readme",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/crossbind/crossbind.git"
9
+ },
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "exports": {
13
+ "./crossbind.extension.js": "./crossbind.extension.js"
14
+ },
15
+ "files": [
16
+ "crossbind.extension.js",
17
+ "native"
18
+ ],
19
+ "crossbind": {
20
+ "extension": "./crossbind.extension.js"
21
+ },
22
+ "keywords": [
23
+ "crossbind-extension",
24
+ "crossbind",
25
+ "page",
26
+ "permissions",
27
+ "app"
28
+ ]
6
29
  }