diff --git a/Shared/Localizable.xcstrings b/Shared/Localizable.xcstrings index 7ec517e42..5d2dbeeb5 100644 --- a/Shared/Localizable.xcstrings +++ b/Shared/Localizable.xcstrings @@ -78,6 +78,9 @@ }, "Activity may contain feed URLs and other information you may not want to share publicly." : { "comment" : "Activity log privacy warning" + }, + "Add ${url} to ${accountName}" : { + }, "Add Account" : { "comment" : "Add Account" @@ -94,6 +97,14 @@ "Add Item" : { "comment" : "Add Item" }, + "Adding %@ to NetNewsWire." : { + "comment" : "A description of an action that adds a feed to a folder.", + "isCommentAutoGenerated" : true + }, + "Adds a feed to NetNewsWire." : { + "comment" : "Intent description for the \"Add Feed\" app intent.", + "isCommentAutoGenerated" : true + }, "Advanced" : { "comment" : "Preferences" }, @@ -253,6 +264,10 @@ "Couldn’t complete the iCloud scan because of an error:" : { "comment" : "Scan error alert title" }, + "Couldn’t find a place to add the feed." : { + "comment" : "Error message when the app can’t find a suitable folder to add the feed to.", + "isCommentAutoGenerated" : true + }, "Create" : { "comment" : "Create" }, @@ -442,6 +457,10 @@ "First Unread" : { "comment" : "First Unread" }, + "Folder" : { + "comment" : "Label for a parameter that lets the user choose a folder.", + "isCommentAutoGenerated" : true + }, "Folder Inspector" : { "comment" : "Folder Inspector window title" }, @@ -1002,6 +1021,10 @@ "Theme installed" : { "comment" : "Theme installed" }, + "There are no accounts to add the feed to." : { + "comment" : "Error message when the user has no accounts to add a feed to.", + "isCommentAutoGenerated" : true + }, "There is already a Feedbin account with that username created." : { "comment" : "Duplicate Error" }, @@ -1137,6 +1160,10 @@ "Updating…" : { "comment" : "Updating…" }, + "URL" : { + "comment" : "Label for the URL parameter in the Add Feed intent.", + "isCommentAutoGenerated" : true + }, "Username & password required." : { "comment" : "Credentials Error" }, diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index 8dc556e28..a9457e6cf 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -26,6 +26,7 @@ final class WebViewController: UIViewController { static let imageWasClicked = "imageWasClicked" static let imageWasShown = "imageWasShown" static let showFeedInspector = "showFeedInspector" + static let mediaSourceURLs = "mediaSourceURLs" } private var topShowBarsView: UIView! @@ -46,6 +47,7 @@ final class WebViewController: UIViewController { private lazy var articleIconSchemeHandler = ArticleIconSchemeHandler(coordinator: coordinator) private lazy var transition = ImageTransition(controller: self) private var imageDownloadTask: Task? + private var mediaSourceURLs = Set() private var clickedImageCompletion: (() -> Void)? private var articleExtractor: ArticleExtractor? @@ -415,6 +417,14 @@ extension WebViewController: WKNavigationDelegate { return } + // WebKit reports a tap on a not-yet-loaded video’s controls as a link activation + // targeting the media source. The tap already operates the control — don’t open a browser. + // + if mediaSourceURLs.contains(url.absoluteString) { + decisionHandler(.cancel) + return + } + let components = URLComponents(url: url, resolvingAgainstBaseURL: false) if components?.scheme == "http" || components?.scheme == "https" { decisionHandler(.cancel) @@ -501,6 +511,8 @@ extension WebViewController: WKScriptMessageHandler { if let feed = article?.feed { coordinator.showFeedInspector(for: feed) } + case MessageName.mediaSourceURLs: + mediaSourceURLs = Set((message.body as? [String]) ?? []) default: return } @@ -588,11 +600,13 @@ private extension WebViewController { webView.configuration.userContentController.removeScriptMessageHandler(forName: MessageName.imageWasClicked) webView.configuration.userContentController.removeScriptMessageHandler(forName: MessageName.imageWasShown) webView.configuration.userContentController.removeScriptMessageHandler(forName: MessageName.showFeedInspector) + webView.configuration.userContentController.removeScriptMessageHandler(forName: MessageName.mediaSourceURLs) // Add handlers webView.configuration.userContentController.add(WrapperScriptMessageHandler(self), name: MessageName.imageWasClicked) webView.configuration.userContentController.add(WrapperScriptMessageHandler(self), name: MessageName.imageWasShown) webView.configuration.userContentController.add(WrapperScriptMessageHandler(self), name: MessageName.showFeedInspector) + webView.configuration.userContentController.add(WrapperScriptMessageHandler(self), name: MessageName.mediaSourceURLs) self.renderPage(webView) } diff --git a/iOS/Resources/main_ios.js b/iOS/Resources/main_ios.js index e54685859..f6beaf736 100644 --- a/iOS/Resources/main_ios.js +++ b/iOS/Resources/main_ios.js @@ -155,6 +155,22 @@ function showFeedInspectorSetup() { function postRenderProcessing() { ImageViewer.init(); showFeedInspectorSetup(); + postMediaSourceURLs(); +} + +// Tell the app which URLs are embedded media, so it can tell a real link tap +// from WebKit’s synthesized link activation for a video’s source. +function postMediaSourceURLs() { + var urls = new Set(); + document.querySelectorAll("video, audio, video source, audio source").forEach(element => { + if (element.src) { + urls.add(element.src); + } + if (element.currentSrc) { + urls.add(element.currentSrc); + } + }); + window.webkit.messageHandlers.mediaSourceURLs.postMessage(Array.from(urls)); } function onResize() {