From 331185afe9bfcca8940b9c69a01048922851b838 Mon Sep 17 00:00:00 2001 From: Brandon-T Date: Thu, 6 Apr 2023 14:37:30 -0400 Subject: [PATCH] Fix brave/brave-ios#7213: Block Playlist from showing up on Brave-Talk (brave/brave-ios#7214) --- .../ScriptHandlers/Paged/PlaylistScriptHandler.swift | 11 +++++++++++ Sources/Shared/Extensions/URLExtensions.swift | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Paged/PlaylistScriptHandler.swift b/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Paged/PlaylistScriptHandler.swift index 5d41118b682f..d5706965730a 100644 --- a/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Paged/PlaylistScriptHandler.swift +++ b/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Paged/PlaylistScriptHandler.swift @@ -100,6 +100,11 @@ class PlaylistScriptHandler: NSObject, TabContentScript { return } + // If this URL is blocked from Playlist support, do nothing + if url?.isPlaylistBlockedSiteURL == true { + return + } + if ReadyState.from(message: message) != nil { return } @@ -216,6 +221,12 @@ extension PlaylistScriptHandler: UIGestureRecognizerDelegate { if gestureRecognizer.state == .began, let webView = tab?.webView, Preferences.Playlist.enableLongPressAddToPlaylist.value { + + // If this URL is blocked from Playlist support, do nothing + if url?.isPlaylistBlockedSiteURL == true { + return + } + let touchPoint = gestureRecognizer.location(in: webView) webView.evaluateSafeJavaScript(functionName: "window.__firefox__.\(PlaylistScriptHandler.playlistLongPressed)", diff --git a/Sources/Shared/Extensions/URLExtensions.swift b/Sources/Shared/Extensions/URLExtensions.swift index bc329a9ce259..20e13a638081 100644 --- a/Sources/Shared/Extensions/URLExtensions.swift +++ b/Sources/Shared/Extensions/URLExtensions.swift @@ -434,6 +434,11 @@ extension URL { return siteList.contains(where: urlHost.contains) } + + public var isPlaylistBlockedSiteURL: Bool { + let urlHost = self.host ?? self.hostSLD + return urlHost == "talk.brave.com" + } public func uniquePathForFilename(_ filename: String) throws -> URL { let basePath = self.appendingPathComponent(filename)