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

Don't force reload tab when restoring state #2016

Merged
merged 3 commits into from
Jan 4, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,19 @@ extension Tab.TabContent {
func loadedFromCache() -> Self {
switch self {
case .url(let url, credential: let credential, source: _):
.url(url, credential: credential, source: .stateRestoration)
.url(url, credential: credential, source: .pendingStateRestoration)
case .homePage, .preferences, .bookmarks, .onboarding, .none, .dataBrokerProtection:
self
}
}

func forceReload() -> Self {
switch self {
case .url(let url, credential: let credential, source: _):
.url(url, credential: credential, source: .reload)
case .url(let url, credential: let credential, source: let source):
let newSource: URLSource = source == .pendingStateRestoration ? .loadedByStateRestoration : .reload
return .url(url, credential: credential, source: newSource)
case .homePage, .preferences, .bookmarks, .onboarding, .none, .dataBrokerProtection:
self
return self
}
}

Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/StateRestoration/Tab+NSSecureCoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private extension Tab.TabContent {
self = .homePage
case .url:
guard let url = url else { return nil }
self = .url(url, source: .stateRestoration)
self = .url(url, source: .pendingStateRestoration)
case .bookmarks:
self = .bookmarks
case .preferences:
Expand All @@ -109,7 +109,7 @@ private extension Tab.TabContent {
self = .onboarding
case .duckPlayer:
guard let videoID = videoID else { return nil }
self = .url(.duckPlayer(videoID, timestamp: timestamp), source: .stateRestoration)
self = .url(.duckPlayer(videoID, timestamp: timestamp), source: .pendingStateRestoration)
case .dataBrokerProtection:
self = .dataBrokerProtection
}
Expand Down
11 changes: 6 additions & 5 deletions DuckDuckGo/Tab/Model/Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ protocol NewWindowPolicyDecisionMaker {
case dataBrokerProtection

enum URLSource: Equatable {
case stateRestoration
case pendingStateRestoration
case loadedByStateRestoration
case userEntered(String)
case historyEntry
case bookmark
Expand All @@ -86,9 +87,9 @@ protocol NewWindowPolicyDecisionMaker {
switch self {
case .userEntered:
.custom(.userEnteredUrl)
case .stateRestoration:
case .pendingStateRestoration:
.sessionRestoration
case .appOpenUrl, .historyEntry, .bookmark, .ui, .link, .webViewUpdated:
case .loadedByStateRestoration, .appOpenUrl, .historyEntry, .bookmark, .ui, .link, .webViewUpdated:
.custom(.tabContentUpdate)
case .reload:
.reload
Expand All @@ -97,9 +98,9 @@ protocol NewWindowPolicyDecisionMaker {

var cachePolicy: URLRequest.CachePolicy {
switch self {
case .stateRestoration, .historyEntry:
case .pendingStateRestoration, .historyEntry:
.returnCacheDataElseLoad
case .reload:
case .reload, .loadedByStateRestoration:
.reloadIgnoringCacheData
case .userEntered, .bookmark, .ui, .link, .appOpenUrl, .webViewUpdated:
.useProtocolCachePolicy
Expand Down
2 changes: 1 addition & 1 deletion UnitTests/Permissions/TabPermissionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ final class TabPermissionsTests: XCTestCase {
eDidCancel = expectation(description: "didCancel external app should be called")

// shouldn‘t open external app when restoring session from interaction state
let tab = Tab(content: .url(externalUrl, source: .stateRestoration), webViewConfiguration: webViewConfiguration, workspace: workspace, privacyFeatures: privacyFeaturesMock, extensionsBuilder: extensionsBuilder, shouldLoadInBackground: true)
let tab = Tab(content: .url(externalUrl, source: .pendingStateRestoration), webViewConfiguration: webViewConfiguration, workspace: workspace, privacyFeatures: privacyFeaturesMock, extensionsBuilder: extensionsBuilder, shouldLoadInBackground: true)

var c = tab.permissions.$authorizationQuery.sink { query in
guard let query else { return }
Expand Down
Loading