Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
home/ios: a link that leaves a document opens in Safari, not in its place (#598)
nyblnet01ff3fc34b87
diff --git a/docs/DECISIONS.md b/docs/DECISIONS.mdindex 968019bd..15cbe7b0 100644--- a/docs/DECISIONS.md+++ b/docs/DECISIONS.md@@ -14,6 +14,30 @@ Decision. Why. Pointers.---+## 2026-10-04 — A link that leaves a document opens outside it, on every host++**Decision.** In a native host, a document never navigates away from itself.+A link to the web (http, https) or to mail opens in the system — Safari, the+browser, the mail app — and the document stays on screen. Anything else that+would replace the document is dropped. Frames inside a document are untouched:+an embed loading its own content is the document's business. Android has worked+this way since it became a document host; iOS now matches it rule for rule+(`home/ios/LinkPolicy.swift`).++**Why.** iOS allowed every navigation, so a link in a deck replaced the deck+with a website inside the editor, with back navigation disabled — the only way+out was to close the document. And an app that shows arbitrary websites is,+for the App Store's age-rating questionnaire, offering unrestricted web access,+which rates it 18+. A document editor has no reason to be a web browser; with+links opening outside it, that answer is "no" and the rating 4+.++**Why the scheme list is short.** A document is content the user opened, and+the host should not launch another app on its say-so. http, https and mailto are+what a link in a document means. A custom URL scheme is dropped rather than+opened, the same choice Android makes.++---+## 2026-08-19 — Cross-app embedding: static render + source, never a second renderer**Decision.** One block/element shape, `bento/embed`, shared by every app in bothdiff --git a/home/README.md b/home/README.mdindex 8d985ac6..3f1c60b9 100644--- a/home/README.md+++ b/home/README.md@@ -467,6 +467,7 @@ here rather than discovered later.| in-place write | `UIDocument.save(.forOverwriting)` | `openOutputStream(uri, "wt")` | same || export destination chosen by the author | `UIDocumentPickerViewController` | `ACTION_CREATE_DOCUMENT` | same || `alert` / `confirm` / `prompt` | `WKUIDelegate` | `WebChromeClient` | same |+| a link that leaves the document | opens in Safari; the document stays (`LinkPolicy`) | opens in the browser (`shouldOverrideUrlLoading`) | same || `<input type="file">` | native | `onShowFileChooser` | same || element fullscreen | declined | declined | same || safe-area insets, natively + `--tray-safe-*` | ✓ | ✓ | same |diff --git a/home/ios/EditorViewController.swift b/home/ios/EditorViewController.swiftindex b43cf0be..86507319 100644--- a/home/ios/EditorViewController.swift+++ b/home/ios/EditorViewController.swift@@ -326,9 +326,34 @@ final class EditorViewController: UIViewController, WKScriptMessageHandler, WKUR// saves often, and a download cannot overwrite the user's original anyway —// that is what the FSA path is for.+ /// A document never navigates away from itself. A link to the web opens in+ /// Safari, where it belongs, and the document stays on screen.+ ///+ /// Allowing every navigation, as this used to, meant a link in a deck+ /// replaced the deck with a website inside the editor — with back navigation+ /// disabled, so the only way out was to close the document. It also made the+ /// app a web browser as far as the App Store age rating is concerned+ /// ("unrestricted web access"), which a document editor has no reason to be.+ ///+ /// The rule itself lives in LinkPolicy, where it can be checked without a+ /// simulator; this only applies the answer.func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction,decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {- decisionHandler(navigationAction.shouldPerformDownload ? .download : .allow)+ if navigationAction.shouldPerformDownload { decisionHandler(.download); return }++ // A nil targetFrame is a new window (target=_blank, window.open): it+ // would leave the document just as surely as replacing it would.+ switch LinkPolicy.decide(navigationAction.request.url,+ replacesDocument: navigationAction.targetFrame?.isMainFrame ?? true,+ documentHost: originHost) {+ case .allow:+ decisionHandler(.allow)+ case .openExternally(let url):+ decisionHandler(.cancel)+ UIApplication.shared.open(url)+ case .drop:+ decisionHandler(.cancel)+ }}func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse,diff --git a/home/ios/LinkPolicy.swift b/home/ios/LinkPolicy.swiftnew file mode 100644index 00000000..44607f0c--- /dev/null+++ b/home/ios/LinkPolicy.swift@@ -0,0 +1,41 @@+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors++import Foundation++/// What the editor does with a navigation: load it in place, or keep the+/// document on screen and (for a web or mail link) hand it to the system.+///+/// Foundation-only, so the whole decision table can be checked standalone with+/// `swiftc` rather than only by tapping links in a simulator. The delegate in+/// EditorViewController applies the answer; it decides nothing itself.+///+/// Mirrors home/android's `shouldOverrideUrlLoading` rule for rule.+enum LinkPolicy {+ enum Decision: Equatable {+ /// Load it in the editor.+ case allow+ /// Keep the document; open this URL in the system instead.+ case openExternally(URL)+ /// Keep the document; do nothing else.+ case drop+ }++ /// Schemes worth handing to the system. Anything else that would leave the+ /// document is dropped rather than launching some other app on its say-so.+ static let external: Set<String> = ["http", "https", "mailto"]++ /// - Parameters:+ /// - url: where the navigation goes.+ /// - replacesDocument: true for the main frame and for a new window+ /// (a nil target frame); false for a frame inside the document.+ /// - documentHost: the host the document itself is served from.+ static func decide(_ url: URL?, replacesDocument: Bool, documentHost: String) -> Decision {+ // A frame inside the document loading its own content is the+ // document's business, not a navigation of it.+ guard replacesDocument else { return .allow }+ if url?.scheme == "bento-tray", url?.host == documentHost { return .allow }+ if let url, external.contains(url.scheme?.lowercased() ?? "") { return .openExternally(url) }+ return .drop+ }+}