Skip to content

Commit

Permalink
Merge branch 'main' into fcappelli/PixelKit
Browse files Browse the repository at this point in the history
  • Loading branch information
federicocappelli committed Apr 15, 2024
2 parents 541f86d + d550bef commit f7f9795
Show file tree
Hide file tree
Showing 24 changed files with 284 additions and 351 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/stale_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
uses: actions/stale@v9
with:
stale-pr-message: 'This PR has been inactive for more than 7 days and will be automatically closed 7 days from now.'
days-before-stale: 7
days-before-pr-stale: 7
close-pr-message: 'This PR has been closed after 14 days of inactivity. Feel free to reopen it if you plan to continue working on it or have further discussions.'
days-before-close: 7
days-before-pr-close: 7
stale-pr-label: stale
exempt-draft-pr: true
2 changes: 1 addition & 1 deletion Configuration/BuildNumber.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 162
CURRENT_PROJECT_VERSION = 163
2 changes: 1 addition & 1 deletion Configuration/Version.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MARKETING_VERSION = 1.83.0
MARKETING_VERSION = 1.84.0
4 changes: 2 additions & 2 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14504,7 +14504,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 134.0.1;
version = 134.1.0;
};
};
9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand All @@ -14520,7 +14520,7 @@
repositoryURL = "https://github.com/sparkle-project/Sparkle.git";
requirement = {
kind = exactVersion;
version = 2.5.2;
version = 2.6.0;
};
};
B65CD8C92B316DF100A595BB /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "b0749d25996c0fa18be07b7851f02ebb3b9fab50",
"version" : "134.0.1"
"revision" : "90e789b95403481e7c2f0e4aa661890d4252f0e6",
"version" : "134.1.0"
}
},
{
Expand Down Expand Up @@ -113,8 +113,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/sparkle-project/Sparkle.git",
"state" : {
"revision" : "47d3d90aee3c52b6f61d04ceae426e607df62347",
"version" : "2.5.2"
"revision" : "0a4caaf7a81eea2cece651ef4b17331fa0634dff",
"version" : "2.6.0"
}
},
{
Expand Down
8 changes: 8 additions & 0 deletions DuckDuckGo/Common/Extensions/URLExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ extension URL {
return string
}

func hostAndPort() -> String? {
guard let host else { return nil }

guard let port = port else { return host }

return "\(host):\(port)"
}

#if !SANDBOX_TEST_TOOL
func toString(forUserInput input: String, decodePunycode: Bool = true) -> String {
let hasInputScheme = input.hasOrIsPrefix(of: self.separatedScheme ?? "")
Expand Down
2 changes: 0 additions & 2 deletions DuckDuckGo/Common/Extensions/WKWebView+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ typedef NS_OPTIONS(NSUInteger, _WKFindOptions) {

- (void)_stopMediaCapture API_AVAILABLE(macos(10.15.4), ios(13.4));
- (void)_stopAllMediaPlayback;
- (_WKMediaMutedState)_mediaMutedState API_AVAILABLE(macos(11.0), ios(14.0));;
- (void)_setPageMuted:(_WKMediaMutedState)mutedState API_AVAILABLE(macos(10.13), ios(11.0));

@end

Expand Down
126 changes: 66 additions & 60 deletions DuckDuckGo/Common/Extensions/WKWebViewExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@ extension WKWebView {
enum AudioState {
case muted
case unmuted
case notSupported

init(wkMediaMutedState: _WKMediaMutedState) {
self = wkMediaMutedState.contains(.audioMuted) ? .muted : .unmuted
}

mutating func toggle() {
self = switch self {
case .muted: .unmuted
case .unmuted: .muted
}
}
}

enum CaptureState {
Expand Down Expand Up @@ -114,96 +124,84 @@ extension WKWebView {
return .active
}

#if !APPSTORE
private func setMediaCaptureMuted(_ muted: Bool) {
guard self.responds(to: #selector(WKWebView._setPageMuted(_:))) else {
assertionFailure("WKWebView does not respond to selector _stopMediaCapture")
return
@objc dynamic var mediaMutedState: _WKMediaMutedState {
get {
// swizzle the method to call `_mediaMutedState` without performSelector: usage
guard Self.swizzleMediaMutedStateOnce else { return [] }
return self.mediaMutedState // call the original
}
let mutedState: _WKMediaMutedState = {
guard self.responds(to: #selector(WKWebView._mediaMutedState)) else { return [] }
return self._mediaMutedState()
}()
var newState = mutedState
if muted {
newState.insert(.captureDevicesMuted)
} else {
newState.remove(.captureDevicesMuted)
set {
// swizzle the method to call `_setPageMuted:` without performSelector: usage (as there‘s a non-object argument to pass)
guard Self.swizzleSetPageMutedOnce else { return }
self.mediaMutedState = newValue // call the original
}
guard newState != mutedState else { return }
self._setPageMuted(newState)
}
#endif

func muteOrUnmute() {
#if !APPSTORE
guard self.responds(to: #selector(WKWebView._setPageMuted(_:))) else {
assertionFailure("WKWebView does not respond to selector _stopMediaCapture")
return
static private let swizzleMediaMutedStateOnce: Bool = {
guard let originalMethod = class_getInstanceMethod(WKWebView.self, Selector.mediaMutedState),
let swizzledMethod = class_getInstanceMethod(WKWebView.self, #selector(getter: mediaMutedState)) else {
assertionFailure("WKWebView does not respond to selector _mediaMutedState")
return false
}
let mutedState: _WKMediaMutedState = {
guard self.responds(to: #selector(WKWebView._mediaMutedState)) else { return [] }
return self._mediaMutedState()
}()
var newState = mutedState

if newState == .audioMuted {
newState.remove(.audioMuted)
} else {
newState.insert(.audioMuted)
method_exchangeImplementations(originalMethod, swizzledMethod)
return true
}()

static private let swizzleSetPageMutedOnce: Bool = {
guard let originalMethod = class_getInstanceMethod(WKWebView.self, Selector.setPageMuted),
let swizzledMethod = class_getInstanceMethod(WKWebView.self, #selector(setter: mediaMutedState)) else {
assertionFailure("WKWebView does not respond to selector _setPageMuted:")
return false
}
guard newState != mutedState else { return }
self._setPageMuted(newState)
#endif
}
method_exchangeImplementations(originalMethod, swizzledMethod)
return true
}()

/// Returns the audio state of the WKWebView.
///
/// - Returns: `muted` if the web view is muted
/// `unmuted` if the web view is unmuted
/// `notSupported` if the web view does not support fetching the current audio state
func audioState() -> AudioState {
#if APPSTORE
return .notSupported
#else
guard self.responds(to: #selector(WKWebView._mediaMutedState)) else {
assertionFailure("WKWebView does not respond to selector _mediaMutedState")
return .notSupported
var audioState: AudioState {
get {
AudioState(wkMediaMutedState: mediaMutedState)
}
set {
switch newValue {
case .muted:
self.mediaMutedState.insert(.audioMuted)
case .unmuted:
self.mediaMutedState.remove(.audioMuted)
}
}

let mutedState = self._mediaMutedState()

return mutedState.contains(.audioMuted) ? .muted : .unmuted
#endif
}

func stopMediaCapture() {
guard #available(macOS 12.0, *) else {
#if !APPSTORE
guard #available(macOS 12.0, *) else {
guard self.responds(to: #selector(_stopMediaCapture)) else {
assertionFailure("WKWebView does not respond to _stopMediaCapture")
return
}
self._stopMediaCapture()
#endif
return
}
#endif

setCameraCaptureState(.none)
setMicrophoneCaptureState(.none)
}

func stopAllMediaPlayback() {
guard #available(macOS 12.0, *) else {
#if !APPSTORE
guard #available(macOS 12.0, *) else {
guard self.responds(to: #selector(_stopAllMediaPlayback)) else {
assertionFailure("WKWebView does not respond to _stopAllMediaPlayback")
return
}
self._stopAllMediaPlayback()
return
#endif
}
#endif
pauseAllMediaPlayback()
}

Expand All @@ -212,20 +210,26 @@ extension WKWebView {
switch permission {
case .camera:
guard #available(macOS 12.0, *) else {
#if !APPSTORE
self.setMediaCaptureMuted(muted)
#endif
if muted {
self.mediaMutedState.insert(.captureDevicesMuted)
} else {
self.mediaMutedState.remove(.captureDevicesMuted)
}
return
}

self.setCameraCaptureState(muted ? .muted : .active, completionHandler: {})

case .microphone:
guard #available(macOS 12.0, *) else {
#if !APPSTORE
self.setMediaCaptureMuted(muted)
#endif
if muted {
self.mediaMutedState.insert(.captureDevicesMuted)
} else {
self.mediaMutedState.remove(.captureDevicesMuted)
}
return
}

self.setMicrophoneCaptureState(muted ? .muted : .active, completionHandler: {})
case .geolocation:
self.configuration.processPool.geolocationProvider?.isPaused = muted
Expand Down Expand Up @@ -360,6 +364,8 @@ extension WKWebView {
static let fullScreenPlaceholderView = NSSelectorFromString("_fullScreenPlaceholderView")
static let printOperationWithPrintInfoForFrame = NSSelectorFromString("_printOperationWithPrintInfo:forFrame:")
static let loadAlternateHTMLString = NSSelectorFromString("_loadAlternateHTMLString:baseURL:forUnreachableURL:")
static let mediaMutedState = NSSelectorFromString("_mediaMutedState")
static let setPageMuted = NSSelectorFromString("_setPageMuted:")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import BrowserServicesKit
final class AppPrivacyConfigurationDataProvider: EmbeddedDataProvider {

public struct Constants {
public static let embeddedDataETag = "\"fd95ad4da437370f57ea8c2e2d03f48f\""
public static let embeddedDataSHA = "f11d34eb516a2ba722c22e15ff8cdee5e5b2570adbf9d1b22d50438b30f57188"
public static let embeddedDataETag = "\"a482727f0d20b29eabd1e22fde2d54cf\""
public static let embeddedDataSHA = "993aa84559944a8866e40cebbce02beee2b1597f86b63f998d000d2a0e5d617a"
}

var embeddedDataEtag: String {
Expand Down
Loading

0 comments on commit f7f9795

Please sign in to comment.