From 3f5ea7b8762cd842c5b8c29c9191242bc4a32c18 Mon Sep 17 00:00:00 2001 From: Elon Park Date: Fri, 8 Sep 2023 12:34:33 +0900 Subject: [PATCH] refactor isStoreURL check logic --- ...BrowserViewController+WKNavigationDelegate.swift | 13 ++++++------- .../Managers & Cache/PlaylistCacheLoader.swift | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift index adcb2b061bd..e505c81a2df 100644 --- a/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift +++ b/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController+WKNavigationDelegate.swift @@ -110,15 +110,14 @@ extension BrowserViewController: WKNavigationDelegate { // them then iOS will actually first open Safari, which then redirects to the app store. This works but it will // leave a 'Back to Safari' button in the status bar, which we do not want. fileprivate func isStoreURL(_ url: URL) -> Bool { - if url.scheme == "http" || url.scheme == "https" { - if url.host == "itunes.apple.com" || url.host == "apps.apple.com" || url.host == "appsto.re" { - return true - } - } - if url.scheme == "itms-appss" || url.scheme == "itms-apps" || url.scheme == "itmss" { + let isStoreScheme = ["itms-apps", "itms-appss", "itmss"].contains(url.scheme) + if isStoreScheme { return true } - return false + + let isHttpScheme = ["http", "https"].contains(url.scheme) + let isAppStoreHost = ["itunes.apple.com", "apps.apple.com", "appsto.re"].contains(url.host) + return isHttpScheme && isAppStoreHost } // This is the place where we decide what to do with a new navigation action. There are a number of special schemes diff --git a/Sources/Brave/Frontend/Browser/Playlist/Managers & Cache/PlaylistCacheLoader.swift b/Sources/Brave/Frontend/Browser/Playlist/Managers & Cache/PlaylistCacheLoader.swift index b3d108fe8e0..ec27d1d3054 100644 --- a/Sources/Brave/Frontend/Browser/Playlist/Managers & Cache/PlaylistCacheLoader.swift +++ b/Sources/Brave/Frontend/Browser/Playlist/Managers & Cache/PlaylistCacheLoader.swift @@ -511,15 +511,14 @@ extension PlaylistWebLoader: WKNavigationDelegate { // them then iOS will actually first open Safari, which then redirects to the app store. This works but it will // leave a 'Back to Safari' button in the status bar, which we do not want. fileprivate func isStoreURL(_ url: URL) -> Bool { - if url.scheme == "http" || url.scheme == "https" { - if url.host == "itunes.apple.com" || url.host == "apps.apple.com" || url.host == "appsto.re" { - return true - } - } - if url.scheme == "itms-appss" || url.scheme == "itms-apps" || url.scheme == "itmss" { + let isStoreScheme = ["itms-apps", "itms-appss", "itmss"].contains(url.scheme) + if isStoreScheme { return true } - return false + + let isHttpScheme = ["http", "https"].contains(url.scheme) + let isAppStoreHost = ["itunes.apple.com", "apps.apple.com", "appsto.re"].contains(url.host) + return isHttpScheme && isAppStoreHost } func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {