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

[DuckPlayer] 1. Move Extension to BSK and add Init Updates #3055

Merged
merged 11 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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: 18 additions & 14 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@
3706FA97293F65D500E42796 /* WindowDraggingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B693954526F04BEA0015B914 /* WindowDraggingView.swift */; };
3706FA98293F65D500E42796 /* SecureVaultSorting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1E6EEB27AB5E5100F51793 /* SecureVaultSorting.swift */; };
3706FA99293F65D500E42796 /* PreferencesSidebarModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37CD54C627F2FDD100F1F7B9 /* PreferencesSidebarModel.swift */; };
3706FA9A293F65D500E42796 /* DuckPlayerURLExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3767190128E724B2003A2A15 /* DuckPlayerURLExtension.swift */; };
3706FA9D293F65D500E42796 /* PermissionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6106BAC26A7BF390013B453 /* PermissionState.swift */; };
3706FA9F293F65D500E42796 /* FeedbackPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 371C0A2827E33EDC0070591F /* FeedbackPresenter.swift */; };
3706FAA0293F65D500E42796 /* UserAgent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14505A07256084EF00272CC6 /* UserAgent.swift */; };
Expand Down Expand Up @@ -872,7 +871,6 @@
3706FE64293F661700E42796 /* DownloadListStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B693955C26F19CD70015B914 /* DownloadListStoreTests.swift */; };
3706FE65293F661700E42796 /* ContentBlockingUpdatingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B610F2E527AA388100FCEBE9 /* ContentBlockingUpdatingTests.swift */; };
3706FE67293F661700E42796 /* EncryptionMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BA1A6F5258C4F9600F6F690 /* EncryptionMocks.swift */; };
3706FE68293F661700E42796 /* DuckPlayerURLExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 376718FF28E58513003A2A15 /* DuckPlayerURLExtensionTests.swift */; };
3706FE6A293F661700E42796 /* FirefoxKeyReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B2975982828285900187C4E /* FirefoxKeyReaderTests.swift */; };
3706FE6B293F661700E42796 /* AppKitPrivateMethodsAvailabilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B698E5032908011E00A746A8 /* AppKitPrivateMethodsAvailabilityTests.swift */; };
3706FE6D293F661700E42796 /* ChromiumBookmarksReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB99D0C26FE1A83001E4761 /* ChromiumBookmarksReaderTests.swift */; };
Expand Down Expand Up @@ -1011,8 +1009,6 @@
37534CA8281198CD002621E7 /* AdjacentItemEnumerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37534CA62811988E002621E7 /* AdjacentItemEnumerator.swift */; };
376113CC2B29CD5B00E794BB /* CriticalPathsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 565E46DF2B2725DD0013AC2A /* CriticalPathsTests.swift */; };
376705AF27EB488600DD8D76 /* RoundedSelectionRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B0511B3262CAA5A00F6079C /* RoundedSelectionRowView.swift */; };
3767190028E58513003A2A15 /* DuckPlayerURLExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 376718FF28E58513003A2A15 /* DuckPlayerURLExtensionTests.swift */; };
3767190328E724D8003A2A15 /* DuckPlayerURLExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3767190128E724B2003A2A15 /* DuckPlayerURLExtension.swift */; };
3768D8382C24BFF5004120AE /* RemoteMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3768D8372C24BFF5004120AE /* RemoteMessageView.swift */; };
3768D8392C24BFF5004120AE /* RemoteMessageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3768D8372C24BFF5004120AE /* RemoteMessageView.swift */; };
3768D83B2C24C0A8004120AE /* RemoteMessageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3768D83A2C24C0A8004120AE /* RemoteMessageViewModel.swift */; };
Expand Down Expand Up @@ -2602,6 +2598,8 @@
CBDD5DE429A6800300832877 /* MockConfigurationStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBDD5DE229A67F2700832877 /* MockConfigurationStore.swift */; };
D64A5FF82AEA5C2B00B6D6E7 /* HomeButtonMenuFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = D64A5FF72AEA5C2B00B6D6E7 /* HomeButtonMenuFactory.swift */; };
D64A5FF92AEA5C2B00B6D6E7 /* HomeButtonMenuFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = D64A5FF72AEA5C2B00B6D6E7 /* HomeButtonMenuFactory.swift */; };
D6BC8AC62C5A95AA0025375B /* DuckPlayer in Frameworks */ = {isa = PBXBuildFile; productRef = D6BC8AC52C5A95AA0025375B /* DuckPlayer */; };
D6BC8AC82C5A95B10025375B /* DuckPlayer in Frameworks */ = {isa = PBXBuildFile; productRef = D6BC8AC72C5A95B10025375B /* DuckPlayer */; };
EA0BA3A9272217E6002A0B6C /* ClickToLoadUserScript.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0BA3A8272217E6002A0B6C /* ClickToLoadUserScript.swift */; };
EA18D1CA272F0DC8006DC101 /* social_images in Resources */ = {isa = PBXBuildFile; fileRef = EA18D1C9272F0DC8006DC101 /* social_images */; };
EA8AE76A279FBDB20078943E /* ClickToLoadTDSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA8AE769279FBDB20078943E /* ClickToLoadTDSTests.swift */; };
Expand Down Expand Up @@ -3119,8 +3117,6 @@
376113C52B29BCD600E794BB /* SyncE2EUITests.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = SyncE2EUITests.xcconfig; sourceTree = "<group>"; };
376113D42B29CD5B00E794BB /* SyncE2EUITests App Store.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SyncE2EUITests App Store.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
376113D72B29D0F800E794BB /* SyncE2EUITestsAppStore.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = SyncE2EUITestsAppStore.xcconfig; sourceTree = "<group>"; };
376718FF28E58513003A2A15 /* DuckPlayerURLExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DuckPlayerURLExtensionTests.swift; sourceTree = "<group>"; };
3767190128E724B2003A2A15 /* DuckPlayerURLExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DuckPlayerURLExtension.swift; sourceTree = "<group>"; };
3768D8372C24BFF5004120AE /* RemoteMessageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteMessageView.swift; sourceTree = "<group>"; };
3768D83A2C24C0A8004120AE /* RemoteMessageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteMessageViewModel.swift; sourceTree = "<group>"; };
3768D83F2C29C1F1004120AE /* ActiveRemoteMessageModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActiveRemoteMessageModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4349,6 +4345,7 @@
85E2BBD02B8F534A00DBEC7A /* History in Frameworks */,
4BF97AD52B43C43F00EB4240 /* NetworkProtection in Frameworks */,
3739326529AE4B39009346AE /* DDGSync in Frameworks */,
D6BC8AC82C5A95B10025375B /* DuckPlayer in Frameworks */,
37DF000729F9C061002B7D3E /* SyncDataProviders in Frameworks */,
37BA812F29B3CD6E0053F1A3 /* SyncUI in Frameworks */,
3706FCAF293F65D500E42796 /* PrivacyDashboard in Frameworks */,
Expand Down Expand Up @@ -4526,6 +4523,7 @@
B6F7128129F681EB00594A45 /* QuickLookUI.framework in Frameworks */,
EE7295E32A545B9A008C0991 /* NetworkProtection in Frameworks */,
9807F645278CA16F00E1547B /* BrowserServicesKit in Frameworks */,
D6BC8AC62C5A95AA0025375B /* DuckPlayer in Frameworks */,
987799ED299998B1005D8EB6 /* Bookmarks in Frameworks */,
1E950E3F2912A10D0051A99B /* ContentBlocking in Frameworks */,
31A3A4E32B0C115F0021063C /* DataBrokerProtection in Frameworks */,
Expand Down Expand Up @@ -4870,7 +4868,6 @@
isa = PBXGroup;
children = (
37F19A6928E2F2D000740DC6 /* DuckPlayer.swift */,
3767190128E724B2003A2A15 /* DuckPlayerURLExtension.swift */,
31F28C5228C8EECA00119F70 /* DuckURLSchemeHandler.swift */,
315AA06F28CA5CC800200030 /* YoutubePlayerNavigationHandler.swift */,
31F28C4C28C8EEC500119F70 /* YoutubePlayerUserScript.swift */,
Expand Down Expand Up @@ -4938,7 +4935,6 @@
isa = PBXGroup;
children = (
3714B1E828EDBAAB0056C57A /* DuckPlayerTests.swift */,
376718FF28E58513003A2A15 /* DuckPlayerURLExtensionTests.swift */,
567DA94429E95C3F008AC5EE /* YoutubeOverlayUserScriptTests.swift */,
);
path = YoutubePlayer;
Expand Down Expand Up @@ -8653,6 +8649,7 @@
F198C71F2BD18D92000BF24D /* SwiftLintTool */,
7B2366852C09FACD002D393F /* VPNAppLauncher */,
371209242C232E6C003ADF3D /* RemoteMessaging */,
D6BC8AC72C5A95B10025375B /* DuckPlayer */,
);
productName = DuckDuckGo;
productReference = 3706FD05293F65D500E42796 /* DuckDuckGo App Store.app */;
Expand Down Expand Up @@ -9057,6 +9054,7 @@
F198C71D2BD18D88000BF24D /* SwiftLintTool */,
7B2366832C09FAC2002D393F /* VPNAppLauncher */,
371209222C232E66003ADF3D /* RemoteMessaging */,
D6BC8AC52C5A95AA0025375B /* DuckPlayer */,
);
productName = DuckDuckGo;
productReference = AA585D7E248FD31100E9A3E2 /* DuckDuckGo.app */;
Expand Down Expand Up @@ -9894,7 +9892,6 @@
3706FA98293F65D500E42796 /* SecureVaultSorting.swift in Sources */,
1DEDB3652C19934C006B6D1B /* MoreOptionsMenuButton.swift in Sources */,
3706FA99293F65D500E42796 /* PreferencesSidebarModel.swift in Sources */,
3706FA9A293F65D500E42796 /* DuckPlayerURLExtension.swift in Sources */,
3706FA9D293F65D500E42796 /* PermissionState.swift in Sources */,
3707C724294B5D2900682A9F /* StringExtension.swift in Sources */,
3706FA9F293F65D500E42796 /* FeedbackPresenter.swift in Sources */,
Expand Down Expand Up @@ -10923,7 +10920,6 @@
3706FE65293F661700E42796 /* ContentBlockingUpdatingTests.swift in Sources */,
3706FE67293F661700E42796 /* EncryptionMocks.swift in Sources */,
9F872D9E2B9058D000138637 /* Bookmarks+TabTests.swift in Sources */,
3706FE68293F661700E42796 /* DuckPlayerURLExtensionTests.swift in Sources */,
3706FE6A293F661700E42796 /* FirefoxKeyReaderTests.swift in Sources */,
1DA860732BE3AE950027B813 /* DockPositionProviderTests.swift in Sources */,
3706FE6B293F661700E42796 /* AppKitPrivateMethodsAvailabilityTests.swift in Sources */,
Expand Down Expand Up @@ -11343,7 +11339,6 @@
B693955326F04BEC0015B914 /* WindowDraggingView.swift in Sources */,
4B1E6EED27AB5E5100F51793 /* SecureVaultSorting.swift in Sources */,
37CD54CE27F2FDD100F1F7B9 /* PreferencesSidebarModel.swift in Sources */,
3767190328E724D8003A2A15 /* DuckPlayerURLExtension.swift in Sources */,
1D43EB32292788C70065E5D6 /* BWEncryptionOutput.m in Sources */,
3707EC4A2C47E36A00B67CBE /* CloseButton.swift in Sources */,
B6106BAD26A7BF390013B453 /* PermissionState.swift in Sources */,
Expand Down Expand Up @@ -12387,7 +12382,6 @@
B610F2EB27AA8E4500FCEBE9 /* ContentBlockingUpdatingTests.swift in Sources */,
4BA1A6F6258C4F9600F6F690 /* EncryptionMocks.swift in Sources */,
56A054162C1C37B0007D8FAB /* CapturingOnboardingNavigation.swift in Sources */,
3767190028E58513003A2A15 /* DuckPlayerURLExtensionTests.swift in Sources */,
9FBD847A2BB3EC3300220859 /* MockAttributionOriginProvider.swift in Sources */,
4B2975992828285900187C4E /* FirefoxKeyReaderTests.swift in Sources */,
B698E5042908011E00A746A8 /* AppKitPrivateMethodsAvailabilityTests.swift in Sources */,
Expand Down Expand Up @@ -13425,8 +13419,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 177.0.1;
branch = daniel/duckplayer.extension;
kind = branch;
};
};
9FF521422BAA8FF300B9819B /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down Expand Up @@ -14008,6 +14002,16 @@
package = 9807F643278CA16F00E1547B /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
productName = Configuration;
};
D6BC8AC52C5A95AA0025375B /* DuckPlayer */ = {
isa = XCSwiftPackageProductDependency;
package = 9807F643278CA16F00E1547B /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
productName = DuckPlayer;
};
D6BC8AC72C5A95B10025375B /* DuckPlayer */ = {
isa = XCSwiftPackageProductDependency;
package = 9807F643278CA16F00E1547B /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
productName = DuckPlayer;
};
DC3F73D49B2D44464AFEFCD8 /* Subscription */ = {
isa = XCSwiftPackageProductDependency;
package = 3FFD51CF7C19ACBDB9687474 /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
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" : "8623ea8296f93efb59320aed8b0f6705f366f89b",
"version" : "177.0.1"
"branch" : "daniel/duckplayer.extension",
"revision" : "9965e9f47284b502d03999f73193813978c8e652"
}
},
{
Expand Down
1 change: 0 additions & 1 deletion DuckDuckGo/Common/Extensions/URLExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import Foundation

extension URL.NavigationalScheme {

static let duck = URL.NavigationalScheme(rawValue: "duck")
static let javascript = URL.NavigationalScheme(rawValue: "javascript")

static var validSchemes: [URL.NavigationalScheme] {
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/Tab/TabExtensions/DuckPlayerTabExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ContentBlocking
import Foundation
import Navigation
import PixelKit
import DuckPlayer

protocol YoutubeScriptsProvider {
var youtubeOverlayScript: YoutubeOverlayUserScript? { get }
Expand Down
56 changes: 48 additions & 8 deletions DuckDuckGo/YoutubePlayer/DuckPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ enum DuckPlayerMode: Equatable, Codable {
}

/// Values that the Frontend can use to determine the current state.
struct InitialSetupSettings: Codable {
struct InitialPlayerSettings: Codable {
struct PlayerSettings: Codable {
let pip: PIP
let autoplay: Autoplay
Expand All @@ -63,6 +63,14 @@ struct InitialSetupSettings: Codable {
let state: State
}

struct Platform: Codable {
let name: String
}

enum Locale: String, Codable {
case en
}

struct Autoplay: Codable {
let state: State
}
Expand All @@ -72,8 +80,20 @@ struct InitialSetupSettings: Codable {
case disabled
}

enum Environment: String, Codable {
case development
case production
}

let userValues: UserValues
let settings: PlayerSettings
let platform: Platform
let environment: Environment
let locale: Locale
}

struct InitialOverlaySettings: Codable {
let userValues: UserValues
}

// Values that the YouTube Overlays can use to determine the current state
Expand Down Expand Up @@ -199,9 +219,15 @@ final class DuckPlayer {
encodeUserValues()
}

public func initialSetup(with webView: WKWebView?) -> (_ params: Any, _ message: UserScriptMessage) async -> Encodable? {
public func initialPlayerSetup(with webView: WKWebView?) -> (_ params: Any, _ message: UserScriptMessage) async -> Encodable? {
return { _, _ in
return await self.encodedSettings(with: webView)
return await self.encodedPlayerSettings(with: webView)
}
}

public func initialOverlaySetup(with webView: WKWebView?) -> (_ params: Any, _ message: UserScriptMessage) async -> Encodable? {
return { _, _ in
return await self.encodedOverlaySettings(with: webView)
}
}

Expand All @@ -213,7 +239,7 @@ final class DuckPlayer {
}

@MainActor
private func encodedSettings(with webView: WKWebView?) async -> InitialSetupSettings {
private func encodedPlayerSettings(with webView: WKWebView?) async -> InitialPlayerSettings {
var isPiPEnabled = webView?.configuration.preferences[.allowsPictureInPictureMediaPlayback] == true

var isAutoplayEnabled = DuckPlayerPreferences.shared.duckPlayerAutoplay
Expand All @@ -230,13 +256,27 @@ final class DuckPlayer {
isPiPEnabled = false
}

let pip = InitialSetupSettings.PIP(state: isPiPEnabled ? .enabled : .disabled)
let autoplay = InitialSetupSettings.Autoplay(state: isAutoplayEnabled ? .enabled : .disabled)
let pip = InitialPlayerSettings.PIP(state: isPiPEnabled ? .enabled : .disabled)
let autoplay = InitialPlayerSettings.Autoplay(state: isAutoplayEnabled ? .enabled : .disabled)
let platform = InitialPlayerSettings.Platform(name: "ios")
let environment = InitialPlayerSettings.Environment.development
let locale = InitialPlayerSettings.Locale.en
let playerSettings = InitialPlayerSettings.PlayerSettings(pip: pip, autoplay: autoplay)
let userValues = encodeUserValues()

let playerSettings = InitialSetupSettings.PlayerSettings(pip: pip, autoplay: autoplay)
return InitialPlayerSettings(userValues: userValues,
settings: playerSettings,
platform: platform,
environment: environment,
locale: locale)
}

@MainActor
private func encodedOverlaySettings(with webView: WKWebView?) async -> InitialOverlaySettings {
var isPiPEnabled = webView?.configuration.preferences[.allowsPictureInPictureMediaPlayback] == true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can be removed

let userValues = encodeUserValues()

return InitialSetupSettings(userValues: userValues, settings: playerSettings)
return InitialOverlaySettings(userValues: userValues)
}

// MARK: - Private
Expand Down
Loading
Loading