Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Web Extensions from the App Store build #3853

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 2 additions & 30 deletions DuckDuckGo-macOS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ extension WKWebViewConfiguration {
}
}

#if !APPSTORE
if #available(macOS 14.4, *), WebExtensionManager.shared.areExtenstionsEnabled {
self._webExtensionController = WebExtensionManager.shared.controller
}
#endif

let userContentController = UserContentController(assetsPublisher: contentBlocking.contentBlockingAssetsPublisher,
privacyConfigurationManager: contentBlocking.privacyConfigurationManager,
Expand Down
6 changes: 6 additions & 0 deletions DuckDuckGo/MainWindow/MainWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ final class MainWindowController: NSWindowController {
subscribeToResolutionChange()
subscribeToFullScreenToolbarChanges()

#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didOpenWindow(self)
}
#endif
}

required init?(coder: NSCoder) {
Expand Down Expand Up @@ -241,9 +243,11 @@ extension MainWindowController: NSWindowDelegate {
WindowControllersManager.shared.lastKeyMainWindowController = self
}

#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didFocusWindow(self)
}
#endif
}

func windowDidResignKey(_ notification: Notification) {
Expand Down Expand Up @@ -349,9 +353,11 @@ extension MainWindowController: NSWindowDelegate {
_=Unmanaged.passRetained(self).autorelease()
WindowControllersManager.shared.unregister(self)

#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didCloseWindow(self)
}
#endif
}

func windowShouldClose(_ window: NSWindow) -> Bool {
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/Menus/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -767,11 +767,13 @@ final class MainMenu: NSMenu {
NSMenuItem(title: "Logging").submenu(setupLoggingMenu())
NSMenuItem(title: "AI Chat").submenu(AIChatDebugMenu())

#if !APPSTORE
if #available(macOS 14.4, *) {
NSMenuItem.separator()
NSMenuItem(title: "Web Extensions").submenu(WebExtensionsDebugMenu())
NSMenuItem.separator()
}
#endif
}

debugMenu.addItem(internalUserItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,13 @@ final class NavigationBarViewController: NSViewController {

subscribeToAIChatOnboarding()

#if !APPSTORE
if #available(macOS 14.4, *), !burnerMode.isBurner {
WebExtensionManager.shared.toolbarButtons().enumerated().forEach { (index, button) in
menuButtons.insertArrangedSubview(button, at: index)
}
}
#endif
}

override func viewWillAppear() {
Expand Down
4 changes: 4 additions & 0 deletions DuckDuckGo/PinnedTabs/Model/PinnedTabsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ final class PinnedTabsManager {
tabCollection.append(tab: tab)
}

#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didChangeTabProperties([.pinned], for: tab)
}
#endif
}

func unpinTab(at index: Int, published: Bool = false) -> Tab? {
Expand All @@ -52,9 +54,11 @@ final class PinnedTabsManager {
}
didUnpinTabSubject.send(index)

#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didChangeTabProperties([.pinned], for: tab)
}
#endif
return tab
}

Expand Down
8 changes: 8 additions & 0 deletions DuckDuckGo/Tab/Model/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,11 @@ protocol NewWindowPolicyDecisionMaker {
if navigationDelegate.currentNavigation == nil {
updateCanGoBackForward(withCurrentNavigation: nil)
}
#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didChangeTabProperties([.URL], for: self)
}
#endif
}
}

Expand Down Expand Up @@ -533,9 +535,11 @@ protocol NewWindowPolicyDecisionMaker {

@Published var title: String? {
didSet {
#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didChangeTabProperties([.title], for: self)
}
#endif
}
}

Expand Down Expand Up @@ -566,9 +570,11 @@ protocol NewWindowPolicyDecisionMaker {

@Published private(set) var isLoading: Bool = false {
didSet {
#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didChangeTabProperties([.loading], for: self)
}
#endif
}
}
@Published private(set) var loadingProgress: Double = 0.0
Expand Down Expand Up @@ -848,9 +854,11 @@ protocol NewWindowPolicyDecisionMaker {
webView.audioState.toggle()
objectWillChange.send()

#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didChangeTabProperties([.muted], for: self)
}
#endif
}

private enum ReloadIfNeededSource {
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/Tab/View/BrowserTabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ final class BrowserTabViewController: NSViewController {

case .webExtensionUrl:
removeAllTabContent()
#if !APPSTORE
if #available(macOS 14.4, *) {
if let tab = tabViewModel?.tab,
let url = tab.url,
Expand All @@ -871,6 +872,7 @@ final class BrowserTabViewController: NSViewController {
self.addWebViewToViewHierarchy(webExtensionWebView, tab: tab)
}
}
#endif
default:
removeAllTabContent()
}
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/Tab/ViewModel/TabViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ final class TabViewModel {
zoomLevelSubject.send(zoomLevel)
}

#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didChangeTabProperties([.zoomFactor], for: tab)
}
#endif
}
}

Expand Down
10 changes: 10 additions & 0 deletions DuckDuckGo/TabBar/Model/TabCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ final class TabCollection: NSObject {
func append(tab: Tab) {
tabs.append(tab)

#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didOpenTab(tab)
}
#endif
}

@discardableResult
Expand All @@ -46,9 +48,11 @@ final class TabCollection: NSObject {
}

tabs.insert(tab, at: index)
#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didOpenTab(tab)
}
#endif
return true
}

Expand Down Expand Up @@ -120,18 +124,22 @@ final class TabCollection: NSObject {
keepLocalHistory(of: tabs[index])
}

#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didCloseTab(tabs[index], windowIsClosing: false)
}
#endif
}

private func tabsWillClose(range: Range<Int>) {
for i in range {
keepLocalHistory(of: tabs[i])

#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didCloseTab(tabs[i], windowIsClosing: false)
}
#endif
}
}

Expand Down Expand Up @@ -162,9 +170,11 @@ final class TabCollection: NSObject {
let oldTab = tabs[index]
tabs[index] = tab

#if !APPSTORE
if #available(macOS 14.4, *) {
WebExtensionManager.shared.eventsListener.didReplaceTab(oldTab, with: tab)
}
#endif
}

// MARK: - Fire button
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/TabBar/ViewModel/TabCollectionViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ final class TabCollectionViewModel: NSObject {
previouslySelectedTabViewModel = oldValue
oldValue?.tab.renderTabSnapshot()

#if !APPSTORE
if #available(macOS 14.4, *) {
if let oldValue {
WebExtensionManager.shared.eventsListener.didDeselectTabs([oldValue.tab])
Expand All @@ -100,6 +101,7 @@ final class TabCollectionViewModel: NSObject {
previousActiveTab: oldValue?.tab)
}
}
#endif
}
}
private weak var previouslySelectedTabViewModel: TabViewModel?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,21 @@ import Foundation
import PackagePlugin
import XcodeProjectPlugin

let nonSandboxedExtraInputFiles: Set<InputFile> = [
let extensionsInputFiles: [InputFile] = [
.init("WebExtensionsDebugMenu.swift", .source),
.init("WebExtensionManager.swift", .source),
.init("WebExtensionPathsCache.swift", .source),
.init("WebExtensionLoader.swift", .source),
.init("WebExtensionEventsListener.swift", .source),
.init("WebExtensionInternalSiteNavigationDelegate.swift", .source),
.init("WebExtensionInternalSiteHandler.swift", .source),
.init("NativeMessagingHandler.swift", .source),
.init("NativeMessagingConnection.swift", .source),
.init("WKWebExtensionTab.swift", .source),
.init("WKWebExtensionWindow.swift", .source)
]

let nonSandboxedExtraInputFiles: Set<InputFile> = Set([
.init("BWEncryption.m", .source),
.init("BWEncryptionOutput.m", .source),
.init("BWManager.swift", .source),
Expand All @@ -30,7 +44,7 @@ let nonSandboxedExtraInputFiles: Set<InputFile> = [
.init("DuckDuckGo VPN.app", .unknown),
.init("DuckDuckGo Notifications.app", .unknown),
.init("DuckDuckGo Personal Information Removal.app", .unknown)
]
] + extensionsInputFiles)

/**
* This dictionary keeps track of input files that are not present in all targets.
Expand All @@ -51,7 +65,10 @@ let extraInputFiles: [TargetName: Set<InputFile>] = [

"Unit Tests": [
.init("BWEncryptionTests.swift", .source),
.init("WKWebViewPrivateMethodsAvailabilityTests.swift", .source)
.init("WKWebViewPrivateMethodsAvailabilityTests.swift", .source),
.init("WebExtensionManagerTests.swift", .source),
.init("WebExtensionPathsCacheMock.swift", .source),
.init("WebExtensionLoaderMock.swift", .source)
],

"Integration Tests": []
Expand Down
Loading