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] 26. Fix saved favs when DuckPlayer is disabled #3285

Merged
merged 24 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
174a172
Fix Close tab with back button
afterxleep Aug 21, 2024
c1f7586
Add tests
afterxleep Aug 21, 2024
1374ef0
Update tab Link to use duck:// scheme if needed
afterxleep Aug 21, 2024
52b5882
Updated Build settings
afterxleep Aug 22, 2024
3cdb17d
Merge branch 'main' into daniel/duckplayer/23.bug.fixes.1
afterxleep Aug 26, 2024
0035855
Attempt to open in the Youtube app if user has requested it
afterxleep Aug 27, 2024
ee2a57f
Fix whitespace
afterxleep Aug 27, 2024
b56d8d7
Only go back to non-youtube items when DP is enabled
afterxleep Aug 27, 2024
7d18dc9
Merge branch 'main' into daniel/duckplayer/23.bug.fixes.1
afterxleep Aug 27, 2024
b174419
Add translations for DuckPlayer FE
afterxleep Aug 27, 2024
2f22f94
Move to constants
afterxleep Aug 27, 2024
9de3ad9
Update tests to include appSettings
afterxleep Aug 27, 2024
dfcc532
Updated strings
afterxleep Aug 27, 2024
a5b20de
Fix JSON extension and make var private
afterxleep Aug 28, 2024
efdca2e
Remove C.S.S
afterxleep Aug 28, 2024
d04cd3d
Allow message origin for www.youtube.com
afterxleep Aug 28, 2024
1c8c489
Update string to use constant and remove dupe
afterxleep Aug 28, 2024
d6dca9a
Merge branch 'daniel/duckplayer/23.bug.fixes.1' into daniel/duckplaye…
afterxleep Aug 28, 2024
78c14f6
Saved favorites redirect properly when DP is disabled
afterxleep Aug 28, 2024
453b9ad
Merge branch 'main' into daniel/duckplayer/26.fix.favorites.save
afterxleep Aug 28, 2024
97e2cfb
Merge branch 'daniel/duckplayer/25.message.origin' into daniel/duckpl…
afterxleep Aug 28, 2024
751fd74
Merge branch 'daniel/duckplayer/24.locales' into daniel/duckplayer/26…
afterxleep Aug 28, 2024
bf28ef7
Merge branch 'main' into daniel/duckplayer/26.fix.favorites.save
afterxleep Aug 28, 2024
fcc3ae0
Updated comment
afterxleep Aug 28, 2024
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
33 changes: 23 additions & 10 deletions DuckDuckGo/DuckPlayer/DuckPlayerNavigationHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,13 @@ extension DuckPlayerNavigationHandler: DuckNavigationHandling {
return
}


// Daily Unique View Pixel
if url.isDuckPlayer,
duckPlayer.settings.mode != .disabled {
let setting = duckPlayer.settings.mode == .enabled ? Constants.duckPlayerAlwaysString : Constants.duckPlayerDefaultString
DailyPixel.fire(pixel: Pixel.Event.duckPlayerDailyUniqueView, withAdditionalParameters: [Constants.settingsKey: setting])

}

// Pixel for Views From Youtube
Expand All @@ -237,16 +239,27 @@ extension DuckPlayerNavigationHandler: DuckNavigationHandling {
Pixel.fire(pixel: Pixel.Event.duckPlayerViewFromYoutubeAutomatic)
}

// If DuckPlayer is Enabled or in ask mode, render the video
if url.isDuckURLScheme,
duckPlayer.settings.mode == .enabled || duckPlayer.settings.mode == .alwaysAsk,
!url.hasWatchInYoutubeQueryParameter {
let newRequest = Self.makeDuckPlayerRequest(from: URLRequest(url: url))

Logger.duckPlayer.debug("DP: Loading Simulated Request for \(navigationAction.request.url?.absoluteString ?? "")")

DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.performRequest(request: newRequest, webView: webView)

if url.isDuckURLScheme {

// If DuckPlayer is Enabled or in ask mode, render the video
if duckPlayer.settings.mode == .enabled || duckPlayer.settings.mode == .alwaysAsk,
!url.hasWatchInYoutubeQueryParameter {
let newRequest = Self.makeDuckPlayerRequest(from: URLRequest(url: url))

Logger.duckPlayer.debug("DP: Loading Simulated Request for \(navigationAction.request.url?.absoluteString ?? "")")

DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.performRequest(request: newRequest, webView: webView)
}

// Otherwise, just redirect to YouTube
} else {
if let (videoID, timestamp) = url.youtubeVideoParams {
let youtubeURL = URL.youtube(videoID, timestamp: timestamp)
let request = URLRequest(url: youtubeURL)
webView.load(request)
}
}
return
}
Expand Down
22 changes: 2 additions & 20 deletions DuckDuckGo/DuckPlayer/YoutubeOverlayUserScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,6 @@ final class YoutubeOverlayUserScript: NSObject, Subfeature {
.store(in: &cancellables)
}

enum MessageOrigin {
case duckPlayer, serpOverlay, youtubeOverlay

init?(url: URL) {
switch url.host {
case DuckPlayerSettings.OriginDomains.duckduckgo:
self = .serpOverlay
case DuckPlayerSettings.OriginDomains.youtubeMobile:
self = .youtubeOverlay
case DuckPlayerSettings.OriginDomains.youtube:
self = .youtubeOverlay
case DuckPlayerSettings.OriginDomains.youtubeWWW:
self = .youtubeOverlay
default:
return nil
}
}
}

struct Handlers {
static let setUserValues = "setUserValues"
static let getUserValues = "getUserValues"
Expand All @@ -91,7 +72,8 @@ final class YoutubeOverlayUserScript: NSObject, Subfeature {
.exact(hostname: "use-devtesting18.duckduckgo.com"),
.exact(hostname: DuckPlayerSettings.OriginDomains.duckduckgo),
.exact(hostname: DuckPlayerSettings.OriginDomains.youtube),
.exact(hostname: DuckPlayerSettings.OriginDomains.youtubeMobile)
.exact(hostname: DuckPlayerSettings.OriginDomains.youtubeMobile),
.exact(hostname: DuckPlayerSettings.OriginDomains.youtubeWWW)
])
public var featureName: String = Constants.featureName

Expand Down
24 changes: 24 additions & 0 deletions DuckDuckGoTests/YoutublePlayerNavigationHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,30 @@ class DuckPlayerNavigationHandlerTests: XCTestCase {

}

@MainActor
func testHandleNavigationWithDuckPlayerDisabledRedirectsToYoutube() {

let link = URL(string: "duck://player/12345")!
let navigationAction = MockNavigationAction(request: URLRequest(url: link))
let playerSettings = MockDuckPlayerSettings(appSettings: mockAppSettings, privacyConfigManager: mockPrivacyConfig)
playerSettings.mode = .disabled
let player = MockDuckPlayer(settings: playerSettings)
let handler = DuckPlayerNavigationHandler(duckPlayer: player, featureFlagger: featureFlagger, appSettings: mockAppSettings)

handler.handleNavigation(navigationAction, webView: webView)

let expectation = self.expectation(description: "Youtube URL request")
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {


XCTAssertEqual(self.webView.url?.absoluteString, "https://m.youtube.com/watch?v=12345")
expectation.fulfill()
}

waitForExpectations(timeout: 1.0, handler: nil)

}

@MainActor
func testHandleReloadForDuckPlayerVideo() {
let duckPlayerURL = URL(string: "https://www.youtube-nocookie.com/embed/abc123?t=10s")!
Expand Down
Loading