From 2fa786e81614984788ad4dd062baf87c625e97f3 Mon Sep 17 00:00:00 2001 From: Brandon Date: Wed, 11 Dec 2024 21:47:22 -0500 Subject: [PATCH] Get rid of Window Render Script --- ios/brave-ios/Package.swift | 3 -- .../BrowserViewController.swift | 11 ---- .../User Scripts/Debug/Preferences.swift | 6 --- .../Debug/UserScriptsDebugView.swift | 5 -- .../Frontend/Browser/UserScriptManager.swift | 8 --- .../Sandboxed/WindowRenderScriptHandler.swift | 53 ------------------- .../Scripts/Sandboxed/WindowRenderScript.js | 33 ------------ 7 files changed, 119 deletions(-) delete mode 100644 ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Sandboxed/WindowRenderScriptHandler.swift delete mode 100644 ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/WindowRenderScript.js diff --git a/ios/brave-ios/Package.swift b/ios/brave-ios/Package.swift index c6cf20306bef..9082719539ff 100644 --- a/ios/brave-ios/Package.swift +++ b/ios/brave-ios/Package.swift @@ -589,9 +589,6 @@ var braveTarget: PackageDescription.Target = .target( .copy( "Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/SiteStateListenerScript.js" ), - .copy( - "Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/WindowRenderScript.js" - ), .copy("WebFilters/ContentBlocker/Lists/block-ads.json"), .copy("WebFilters/ContentBlocker/Lists/block-cookies.json"), .copy("WebFilters/ContentBlocker/Lists/block-trackers.json"), diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift index 5055063626bb..69e6599c0419 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/BrowserViewController/BrowserViewController.swift @@ -438,11 +438,6 @@ public class BrowserViewController: UIViewController { #if canImport(BraveTalk) self.braveTalkJitsiCoordinator.resetPictureInPictureBounds(.init(size: size)) #endif - }, - completion: { _ in - if let tab = self.tabManager.selectedTab { - WindowRenderScriptHandler.executeScript(for: tab) - } } ) } @@ -736,11 +731,6 @@ public class BrowserViewController: UIViewController { self.bottomBarKeyboardBackground.backgroundColor = self.topToolbar.backgroundColor self.setNeedsStatusBarAppearanceUpdate() } - }, - completion: { _ in - if let tab = self.tabManager.selectedTab { - WindowRenderScriptHandler.executeScript(for: tab) - } } ) } @@ -2624,7 +2614,6 @@ extension BrowserViewController: TabDelegate { BraveSearchScriptHandler(tab: tab, profile: profile, rewards: rewards), ResourceDownloadScriptHandler(tab: tab), DownloadContentScriptHandler(browserController: self, tab: tab), - WindowRenderScriptHandler(tab: tab), PlaylistScriptHandler(tab: tab), PlaylistFolderSharingScriptHandler(tab: tab), RewardsReportingScriptHandler(rewards: rewards, tab: tab), diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/User Scripts/Debug/Preferences.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/User Scripts/Debug/Preferences.swift index 2108951b5117..10d7bd2ce241 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/User Scripts/Debug/Preferences.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/User Scripts/Debug/Preferences.swift @@ -62,12 +62,6 @@ extension Preferences { default: true ) - public static let windowRender = - Option( - key: "userscript.preferences.\(UserScriptManager.ScriptType.windowRenderHelper.rawValue)", - default: true - ) - public static let readyState = Option( key: "userscript.preferences.\(UserScriptManager.ScriptType.readyStateHelper.rawValue)", diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/User Scripts/Debug/UserScriptsDebugView.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/User Scripts/Debug/UserScriptsDebugView.swift index 15f6275d1f52..90ad044deda0 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/User Scripts/Debug/UserScriptsDebugView.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/User Scripts/Debug/UserScriptsDebugView.swift @@ -37,9 +37,6 @@ struct UserScriptsDebugView: View { @ObservedObject private var trackingProtectionStats = Preferences.UserScript.trackingProtectionStats - @ObservedObject - private var windowRender = Preferences.UserScript.windowRender - @ObservedObject private var readyState = Preferences.UserScript.readyState @@ -83,8 +80,6 @@ struct UserScriptsDebugView: View { Toggle("Tracking Protection Stats", isOn: $trackingProtectionStats.value) - Toggle("Window Render Helper", isOn: $windowRender.value) - Toggle("Ready State", isOn: $readyState.value) Toggle("Ethereum Provider", isOn: $ethereumProvider.value) diff --git a/ios/brave-ios/Sources/Brave/Frontend/Browser/UserScriptManager.swift b/ios/brave-ios/Sources/Brave/Frontend/Browser/UserScriptManager.swift index a64b84e0b2bd..0c6e9d2145ad 100644 --- a/ios/brave-ios/Sources/Brave/Frontend/Browser/UserScriptManager.swift +++ b/ios/brave-ios/Sources/Brave/Frontend/Browser/UserScriptManager.swift @@ -30,10 +30,6 @@ class UserScriptManager { scripts.append(.playlist) } - if Preferences.UserScript.windowRender.value { - scripts.append(.windowRenderHelper) - } - if Preferences.UserScript.readyState.value { scripts.append(.readyStateHelper) } @@ -126,7 +122,6 @@ class UserScriptManager { case requestBlocking case trackerProtectionStats case resourceDownloader - case windowRenderHelper case readyStateHelper case ethereumProvider case solanaProvider @@ -170,9 +165,6 @@ class UserScriptManager { case .playlist: return Preferences.UserScript.playlist.value ? PlaylistScriptHandler.userScript : nil case .resourceDownloader: return ResourceDownloadScriptHandler.userScript - case .windowRenderHelper: - return Preferences.UserScript.windowRender.value - ? WindowRenderScriptHandler.userScript : nil case .readyStateHelper: return Preferences.UserScript.readyState.value ? ReadyStateScriptHandler.userScript : nil case .youtubeQuality: diff --git a/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Sandboxed/WindowRenderScriptHandler.swift b/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Sandboxed/WindowRenderScriptHandler.swift deleted file mode 100644 index 34682992340f..000000000000 --- a/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/ScriptHandlers/Sandboxed/WindowRenderScriptHandler.swift +++ /dev/null @@ -1,53 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -import Foundation -import Shared -import WebKit - -class WindowRenderScriptHandler: TabContentScript { - private weak var tab: Tab? - - required init(tab: Tab) { - self.tab = tab - } - - static let scriptName = "WindowRenderScript" - static let scriptId = UUID().uuidString - static let messageHandlerName = "\(scriptName)_\(messageUUID)" - static let scriptSandbox: WKContentWorld = .defaultClient - private static let resizeWindowFunction = "\(scriptName)_\(uniqueID)" - - static let userScript: WKUserScript? = { - guard var script = loadUserScript(named: scriptName) else { - return nil - } - return WKUserScript( - source: secureScript( - handlerNamesMap: ["$": resizeWindowFunction], - securityToken: scriptId, - script: script - ), - injectionTime: .atDocumentStart, - forMainFrameOnly: false, - in: scriptSandbox - ) - }() - - func userContentController( - _ userContentController: WKUserContentController, - didReceiveScriptMessage message: WKScriptMessage, - replyHandler: (Any?, String?) -> Void - ) { - // Do nothing with the messages received. - // For now.. It's useful for debugging though. - } - - static func executeScript(for tab: Tab) { - tab.webView?.evaluateSafeJavaScript( - functionName: "window.__firefox__.\(resizeWindowFunction).resizeWindow", - contentWorld: scriptSandbox - ) - } -} diff --git a/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/WindowRenderScript.js b/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/WindowRenderScript.js deleted file mode 100644 index 6eda02951122..000000000000 --- a/ios/brave-ios/Sources/Brave/Frontend/UserContent/UserScripts/Scripts_Dynamic/Scripts/Sandboxed/WindowRenderScript.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2021 The Brave Authors. All rights reserved. -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this file, -// You can obtain one at https://mozilla.org/MPL/2.0/. - -window.__firefox__.includeOnce("WindowRenderScript", function($) { - Object.defineProperty(window.__firefox__, "$", { - enumerable: false, - configurable: false, - writable: false, - value: Object.freeze({ - "resizeWindow": $(function () { - var evt = document.createEvent('UIEvents'); - evt.initUIEvent('resize', true, false, window, 0); - window.dispatchEvent(evt); - }) - }) - }); - - document.addEventListener('readystatechange', $(function(){ - let eventHandler = $(function(e) { - if (e.target.readyState === "interactive") { - window.__firefox__.$.resizeWindow(); - } - - if (e.target.readyState === "complete") { - window.__firefox__.$.resizeWindow(); - } - }); - - return eventHandler; - })()); -});