From 8270c26bcef3580e4e24dc14da8f393b063e1cbc Mon Sep 17 00:00:00 2001 From: "ladamski@duckduckgo.com" Date: Fri, 15 Mar 2024 17:35:53 -0700 Subject: [PATCH] remove dead code --- .../ClickToLoad/ClickToLoadUserScript.swift | 194 ------------------ .../ScriptSourceProviding.swift | 7 - 2 files changed, 201 deletions(-) diff --git a/DuckDuckGo/ContentBlocker/ClickToLoad/ClickToLoadUserScript.swift b/DuckDuckGo/ContentBlocker/ClickToLoad/ClickToLoadUserScript.swift index 1400fb280d..da2be89fd9 100644 --- a/DuckDuckGo/ContentBlocker/ClickToLoad/ClickToLoadUserScript.swift +++ b/DuckDuckGo/ContentBlocker/ClickToLoad/ClickToLoadUserScript.swift @@ -75,7 +75,6 @@ final class ClickToLoadUserScript: NSObject, WKNavigationDelegate, Subfeature { private func handleGetClickToLoadState(params: Any, message: UserScriptMessage) -> Encodable? { webView = message.messageWebView - print("handleGetClickToLoadState for url \(String(describing: message)) for webView \(webView?.url)") return [ "devMode": devMode, "youtubePreviewsEnabled": false @@ -105,200 +104,7 @@ final class ClickToLoadUserScript: NSObject, WKNavigationDelegate, Subfeature { public func displayClickToLoadPlaceholders() { print("displayClickToLoadPlaceholders for url \(String(describing: webView?.url)) for broker \(broker)") if let webView = webView { - let fbSurrogate = """ - (() => { - 'use strict'; - console.warn('fb-sdk document.currentScript.src', document.currentScript, document.currentScript?.src); - console.warn('in fbSurrogate, location is', window.location.href); - window.fbTest = "inline surrogate"; - const facebookEntity = 'Facebook, Inc.'; - const originalFBURL = 'https://connect.facebook.net/en_US/sdk.js?XFBML=false' //FIXME: document.currentScript.src; - let siteInit = function () {}; - let fbIsEnabled = false; - let initData = {}; - let runInit = false; - const parseCalls = []; - const popupName = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 12); - const fbLogin = { - callback: function () {}, - params: undefined, - shouldRun: false - }; - function messageAddon (detailObject) { - detailObject.entity = facebookEntity; - const event = new CustomEvent('ddg-ctp', { - detail: detailObject, - bubbles: false, - cancelable: false, - composed: false - }); - dispatchEvent(event); - } - /** - * When setting up the Facebook SDK, the site may define a function called window.fbAsyncInit. - * Once the SDK loads, it searches for and calls window.fbAsyncInit. However, some sites may - * not use this, and just call FB.init directly at some point (after ensuring that the script has loaded). - * - * Our surrogate (defined below in window.FB) captures calls made to init by page scripts. If at a - * later point we load the real sdk here, we then re-call init with whatever arguments the page passed in - * originally. The runInit param should be true when a page has called init directly. - * Because we put it in asyncInit, the flow will be something like: - * - * FB SDK loads -> SDK calls window.fbAsyncInit -> Our function calls window.FB.init (maybe) -> - * our function calls original fbAsyncInit (if it existed) - */ - function enableFacebookSDK () { - if (!fbIsEnabled) { - window.FB = undefined; - window.fbAsyncInit = function () { - if (runInit && initData) { - window.FB.init(initData); - } - siteInit(); - if (fbLogin.shouldRun) { - window.FB.login(fbLogin.callback, fbLogin.params); - } - }; - const fbScript = document.createElement('script'); - fbScript.setAttribute('crossorigin', 'anonymous'); - fbScript.setAttribute('async', ''); - fbScript.setAttribute('defer', ''); - fbScript.src = originalFBURL; - fbScript.onload = function () { - for (const node of parseCalls) { - window.FB.XFBML.parse.apply(window.FB.XFBML, node); - } - }; - document.head.appendChild(fbScript); - fbIsEnabled = true; - } else { - if (initData) { - window.FB.init(initData); - } - } - } - function runFacebookLogin () { - fbLogin.shouldRun = true; - replaceWindowOpen(); - loginPopup(); - enableFacebookSDK(); - } - function replaceWindowOpen () { - const oldOpen = window.open; - window.open = function (url, name, windowParams) { - const u = new URL(url); - if (u.origin === 'https://www.facebook.com') { - name = popupName; - } - return oldOpen.call(window, url, name, windowParams); - }; - } - function loginPopup () { - const width = Math.min(window.screen.width, 450); - const height = Math.min(window.screen.height, 450); - const popupParams = `width=${width},height=${height},scrollbars=1,location=1`; - window.open('about:blank', popupName, popupParams); - } - window.addEventListener('ddg-ctp-load-sdk', event => { - if (event.detail.entity === facebookEntity) { - enableFacebookSDK(); - } - }); - window.addEventListener('ddg-ctp-run-login', event => { - if (event.detail.entity === facebookEntity) { - runFacebookLogin(); - } - }); - window.addEventListener('ddg-ctp-cancel-modal', event => { - if (event.detail.entity === facebookEntity) { - fbLogin.callback({ }); - } - }); - // Instead of using fbAsyncInit, some websites create a list of FB API calls - // that should be made after init. - const bufferCalls = window.FB && window.FB.__buffer && window.FB.__buffer.calls; - function init () { - if (window.fbAsyncInit) { - siteInit = window.fbAsyncInit; - window.fbAsyncInit(); - } - if (bufferCalls) { - for (const [method, params] of bufferCalls) { - if (Object.prototype.hasOwnProperty.call(window.FB, method)) { - window.FB[method].apply(window.FB, params); - } - } - } - } - if (!window.FB || window.FB.__buffer) { - window.FB = { - api: function (url, cb) { cb(); }, - init: function (obj) { - if (obj) { - initData = obj; - runInit = true; - messageAddon({ - appID: obj.appId - }); - } - }, - ui: function (obj, cb) { - if (obj.method && obj.method === 'share') { - const shareLink = 'https://www.facebook.com/sharer/sharer.php?u=' + obj.href; - window.open(shareLink, 'share-facebook', 'width=550,height=235'); - } - // eslint-disable-next-line node/no-callback-literal - cb({}); - }, - getAccessToken: function () {}, - getAuthResponse: function () { - return { status: '' }; - }, - // eslint-disable-next-line node/no-callback-literal - getLoginStatus: function (callback) { callback({ status: 'unknown' }); }, - getUserID: function () {}, - login: function (cb, params) { - fbLogin.callback = cb; - fbLogin.params = params; - messageAddon({ - action: 'login' - }); - }, - logout: function () {}, - AppEvents: { - EventNames: {}, - logEvent: function (a, b, c) {}, - logPageView: function () {} - }, - Event: { - subscribe: function (event, callback) { - if (event === 'xfbml.render') { - callback(); - } - }, - unsubscribe: function () {} - }, - XFBML: { - parse: function (n) { - parseCalls.push(n); - } - } - }; - if (document.readyState === 'complete') { - init(); - } else { - // sdk script loaded before page content, so wait for load. - window.addEventListener('load', (event) => { - init(); - }); - } - } - window.dispatchEvent(new CustomEvent('ddg-ctp-surrogate-load')); - console.warn('dispatched event'); - })(); - """ broker?.push(method: "displayClickToLoadPlaceholders", params: ["ruleAction": ["block"]], for: self, into: webView) - webView.evaluateJavaScript(fbSurrogate, in: nil, in: WKContentWorld.page) } } } diff --git a/DuckDuckGo/ContentBlocker/ScriptSourceProviding.swift b/DuckDuckGo/ContentBlocker/ScriptSourceProviding.swift index 03ec40e579..97b24f39be 100644 --- a/DuckDuckGo/ContentBlocker/ScriptSourceProviding.swift +++ b/DuckDuckGo/ContentBlocker/ScriptSourceProviding.swift @@ -29,7 +29,6 @@ protocol ScriptSourceProviding { var privacyConfigurationManager: PrivacyConfigurationManaging { get } var autofillSourceProvider: AutofillUserScriptSourceProvider? { get } var sessionKey: String? { get } - var clickToLoadSource: String { get } func buildAutofillSource() -> AutofillUserScriptSourceProvider } @@ -46,7 +45,6 @@ struct ScriptSourceProvider: ScriptSourceProviding { private(set) var surrogatesConfig: SurrogatesUserScriptConfig? private(set) var autofillSourceProvider: AutofillUserScriptSourceProvider? private(set) var sessionKey: String? - private(set) var clickToLoadSource: String = "" let configStorage: ConfigurationStoring let privacyConfigurationManager: PrivacyConfigurationManaging @@ -72,7 +70,6 @@ struct ScriptSourceProvider: ScriptSourceProviding { self.contentBlockerRulesConfig = buildContentBlockerRulesConfig() self.surrogatesConfig = buildSurrogatesConfig() self.sessionKey = generateSessionKey() - self.clickToLoadSource = buildClickToLoadSource() self.autofillSourceProvider = buildAutofillSource() } @@ -154,8 +151,4 @@ struct ScriptSourceProvider: ScriptSourceProviding { return font } - private func buildClickToLoadSource() -> String { - return "" - } - }