@crossbind/extension-page-navigation 0.0.0-bootstrap.0 → 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,6 +1,26 @@
1
1
  # @crossbind/extension-page-navigation
2
2
 
3
- This version, 0.0.0-bootstrap.0, holds no code. npm lets a trusted publisher be configured only for a
4
- package that exists, so it reserves the name for the crossbind release workflow.
3
+ Loads the app's pages and the origins it lists, and opens other links the user follows in the browser.
5
4
 
6
- Install the real package: `npm install @crossbind/extension-page-navigation@beta`. Source: https://github.com/crossbind/crossbind
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 app's own pages load, and so do those of the origins `app.navigation.load` lists. A link to another origin that the
10
+ user follows opens in the default browser; any other navigation loads nothing. It holds `page-authentication` as well,
11
+ for which it answers nothing, so the host cancels an HTTP sign-in and a certificate error: an extension that takes
12
+ `page-authentication` answers them.
13
+
14
+ ## Options
15
+
16
+ `app.navigation.load` lists the origins that load in the app, as `['https://login.example.com']`.
17
+
18
+ ## Platforms
19
+
20
+ macOS, iOS, Linux, Windows and Android.
21
+
22
+ ## Replace or leave out
23
+
24
+ It holds the roles `page-authentication` and `page-navigation`. An extension that gives `replaces: 'page-authentication'` takes that role alone, and this one goes on with the rest; `app: { without: ['page-navigation'] }` in `crossbind.config.js` leaves it out. Leaving it out while `app.navigation` 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.
25
+
26
+ [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,36 @@
1
+ // The origins whose pages load in the app beside its own, as app.navigation.load lists them: http and https ones alone,
2
+ // each as a URL's origin is, as 'https://login.example.com'.
3
+ function checkedNavigation(navigation) {
4
+ if (navigation === null || typeof navigation !== 'object' || Array.isArray(navigation)) {
5
+ throw new Error(`crossbind: app.navigation ${JSON.stringify(navigation)} is no object, as { load: ['https://login.example.com'] } is.`);
6
+ }
7
+ const unknown = Object.keys(navigation).filter((key) => key !== 'load');
8
+ if (unknown.length > 0) throw new Error(`crossbind: app.navigation takes load alone; ${unknown.join(', ')} is none of it.`);
9
+ const load = navigation.load ?? [];
10
+ if (!Array.isArray(load)) throw new Error(`crossbind: app.navigation.load ${JSON.stringify(load)} is no list of origins, as ['https://login.example.com'] is.`);
11
+ for (const origin of load) {
12
+ const url = typeof origin === 'string' && URL.canParse(origin) ? new URL(origin) : null;
13
+ if (!url || !['http:', 'https:'].includes(url.protocol) || url.origin !== origin) {
14
+ throw new Error(`crossbind: app.navigation.load's ${JSON.stringify(origin)} is no http or https origin, as 'https://login.example.com' is, with no path, no default port and its host in lower case.`);
15
+ }
16
+ }
17
+ return { load: [...load] };
18
+ }
19
+
20
+ export default function pageNavigation() {
21
+ return {
22
+ name: 'page-navigation',
23
+ contract: 1,
24
+ root: import.meta.dirname,
25
+ holds: ['page-authentication', 'page-navigation'],
26
+ reads: ['navigation'],
27
+ fromApp: (api) => checkedNavigation(api.config.app.navigation ?? {}),
28
+ app: {
29
+ macos: { sources: ['native/navigation.cpp'] },
30
+ ios: { sources: ['native/navigation.cpp'] },
31
+ linux: { sources: ['native/navigation.cpp'] },
32
+ windows: { sources: ['native/navigation.cpp'] },
33
+ android: { sources: ['native/navigation.cpp'] },
34
+ },
35
+ };
36
+ }
@@ -0,0 +1,32 @@
1
+ #include "crossbind/extension.h"
2
+
3
+ #include <algorithm>
4
+ #include <string>
5
+ #include <vector>
6
+
7
+ namespace {
8
+
9
+ // A URL's origin as the page's scripts name it: its scheme, its host and the port it names.
10
+ std::string originOf(const std::string &url) {
11
+ const auto scheme = url.find("://");
12
+ if (scheme == std::string::npos) return "";
13
+ return url.substr(0, url.find_first_of("/?#", scheme + 3));
14
+ }
15
+
16
+ } // namespace
17
+
18
+ // The host's page-navigation: the origins app.navigation.load lists load in the app, a link to another its user follows
19
+ // opens outside, and the rest loads nothing. An authentication and a certificate error get no owner, so the host
20
+ // cancels each.
21
+ void crossbind_extension_page_navigation(crossbind::Registry &registry) {
22
+ std::vector<std::string> loads;
23
+ const crossbind::Value options = registry.options();
24
+ const crossbind::Value &listed = options["load"];
25
+ if (listed.isArray()) {
26
+ for (const crossbind::Value &origin : listed.asArray()) loads.push_back(origin.asString());
27
+ }
28
+ registry.onNavigation([loads](const crossbind::Navigation &navigation) {
29
+ if (std::find(loads.begin(), loads.end(), originOf(navigation.url())) != loads.end()) return crossbind::NavigationAnswer::load;
30
+ return navigation.isUserInitiated() ? crossbind::NavigationAnswer::openOutside : crossbind::NavigationAnswer::refuse;
31
+ });
32
+ }
package/package.json CHANGED
@@ -1,7 +1,29 @@
1
1
  {
2
- "name": "@crossbind/extension-page-navigation",
3
- "version": "0.0.0-bootstrap.0",
4
- "description": "Placeholder that let npm trust the crossbind release workflow; install @crossbind/extension-page-navigation@beta.",
5
- "license": "MIT",
6
- "repository": "https://github.com/crossbind/crossbind.git"
7
- }
2
+ "name": "@crossbind/extension-page-navigation",
3
+ "version": "2.0.0-beta.69",
4
+ "description": "crossbind app extension: loads the app's pages and the origins it lists, and opens other links the user follows in the browser.",
5
+ "homepage": "https://github.com/crossbind/crossbind/tree/main/extensions/page-navigation#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
+ "navigation",
27
+ "app"
28
+ ]
29
+ }