Skip to content

Commit

Permalink
Fix focusing bug on Asana in a pinned tab (#2149)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/1177771139624306/1206496915322029/f

Description:
This change brings back the code that has previously been reverted to fix Sign in with Apple
on some websites, and adds additional condition (webViewDidStartNavigation) when showTabContent
is called. This allows to retain the Sign in with Apple fix, while also fixing issues with focus in Asana pinned tab.
  • Loading branch information
ayoy authored Feb 5, 2024
1 parent ecc69db commit b0f30b5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr_task_url.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Asana PR Task URL

on:
pull_request:
types: [opened, edited, closed, unlabeled]
types: [opened, edited, closed, unlabeled, synchronize]

jobs:

Expand Down
17 changes: 17 additions & 0 deletions DuckDuckGo/Tab/Model/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,10 @@ protocol NewWindowPolicyDecisionMaker {

// MARK: - Event Publishers

let webViewDidStartNavigationPublisher = PassthroughSubject<Void, Never>()
let webViewDidReceiveUserInteractiveChallengePublisher = PassthroughSubject<Void, Never>()
let webViewDidReceiveRedirectPublisher = PassthroughSubject<Void, Never>()
let webViewDidCommitNavigationPublisher = PassthroughSubject<Void, Never>()
let webViewDidFinishNavigationPublisher = PassthroughSubject<Void, Never>()
let webViewDidFailNavigationPublisher = PassthroughSubject<Void, Never>()

Expand Down Expand Up @@ -1087,6 +1091,9 @@ extension Tab/*: NavigationResponder*/ { // to be moved to Tab+Navigation.swift
func didReceive(_ challenge: URLAuthenticationChallenge, for navigation: Navigation?) async -> AuthChallengeDisposition? {
guard challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodHTTPBasic else { return nil }

// send this event only when we're interrupting loading and showing extra UI to the user
webViewDidReceiveUserInteractiveChallengePublisher.send()

// when navigating to a URL with basic auth username/password, cache it and redirect to a trimmed URL
if case .url(let url, credential: .some(let credential), source: let source) = content,
url.matches(challenge.protectionSpace),
Expand All @@ -1110,6 +1117,15 @@ extension Tab/*: NavigationResponder*/ { // to be moved to Tab+Navigation.swift
}
}

func didReceiveRedirect(_ navigationAction: NavigationAction, for navigation: Navigation) {
webViewDidReceiveRedirectPublisher.send()
}

@MainActor
func didCommit(_ navigation: Navigation) {
webViewDidCommitNavigationPublisher.send()
}

@MainActor
func decidePolicy(for navigationAction: NavigationAction, preferences: inout NavigationPreferences) async -> NavigationActionPolicy? {
// allow local file navigations
Expand Down Expand Up @@ -1154,6 +1170,7 @@ extension Tab/*: NavigationResponder*/ { // to be moved to Tab+Navigation.swift

@MainActor
func didStart(_ navigation: Navigation) {
webViewDidStartNavigationPublisher.send()
delegate?.tabDidStartNavigation(self)
userInteractionDialog = nil

Expand Down
21 changes: 20 additions & 1 deletion DuckDuckGo/Tab/View/BrowserTabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,26 @@ final class BrowserTabViewController: NSViewController {
}
return old == new
})
.asVoid()
.map { [weak tabViewModel] tabContent -> AnyPublisher<Void, Never> in
// For non-URL tabs, just emit an event
guard let tabViewModel, tabContent.isUrl else {
return Just(()).eraseToAnyPublisher()
}

// For URL tabs, we only want to show tab content (webView) when webView starts
// navigation or when another navigation-related event happens.
// We take the first such event and move forward.
return Publishers.Merge5(
tabViewModel.tab.webViewDidStartNavigationPublisher,
tabViewModel.tab.webViewDidReceiveRedirectPublisher,
tabViewModel.tab.webViewDidCommitNavigationPublisher,
tabViewModel.tab.webViewDidFailNavigationPublisher,
tabViewModel.tab.webViewDidReceiveUserInteractiveChallengePublisher
)
.prefix(1)
.eraseToAnyPublisher()
}
.switchToLatest()
.receive(on: DispatchQueue.main)
.sink { [weak self, weak tabViewModel] in
guard let tabViewModel else { return }
Expand Down

0 comments on commit b0f30b5

Please sign in to comment.