Skip to content

Commit

Permalink
Properly handle responses that should trigger download action (#3407)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/414709148257752/1208359719493827/f

**Description**:
We should be more deliberate on handling download triggers e.g. with
links with `download` attribute, BLOB content, responses with
`Content-Disposition: attachment` header.

**Steps to test this PR**:
See parent task for set of download scenarios to test. _Please compare
behavior with version from before changes._


**Definition of Done (Internal Only)**:

* [ ] Does this PR satisfy our [Definition of
Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)?

---
###### Internal references:
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
  • Loading branch information
miasma13 authored Oct 16, 2024
1 parent d82a840 commit 70b3d55
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 132 deletions.
2 changes: 0 additions & 2 deletions Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ extension Pixel {
case cachedTabPreviewRemovalError

case missingDownloadedFile
case unhandledDownload

case compilationResult(result: CompileRulesResult, waitTime: BucketAggregation, appState: AppState)

Expand Down Expand Up @@ -1329,7 +1328,6 @@ extension Pixel.Event {
case .cachedTabPreviewRemovalError: return "m_d_tpre"

case .missingDownloadedFile: return "m_d_missing_downloaded_file"
case .unhandledDownload: return "m_d_unhandled_download"

case .compilationResult(result: let result, waitTime: let waitTime, appState: let appState):
return "m_compilation_result_\(result)_time_\(waitTime)_state_\(appState)"
Expand Down
12 changes: 8 additions & 4 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
1E4FAA6427D8DFB900ADC5B3 /* OngoingDownloadRowViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E4FAA6327D8DFB900ADC5B3 /* OngoingDownloadRowViewModel.swift */; };
1E4FAA6627D8DFC800ADC5B3 /* CompleteDownloadRowViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E4FAA6527D8DFC800ADC5B3 /* CompleteDownloadRowViewModel.swift */; };
1E53508F2C7C9A1F00818DAA /* DefaultSubscriptionManager+AccountManagerKeychainAccessDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E53508E2C7C9A1F00818DAA /* DefaultSubscriptionManager+AccountManagerKeychainAccessDelegate.swift */; };
1E5918472CA422A7008ED2B3 /* Navigation in Frameworks */ = {isa = PBXBuildFile; productRef = 1E5918462CA422A7008ED2B3 /* Navigation */; };
1E60989B290009C700A508F9 /* Common in Frameworks */ = {isa = PBXBuildFile; productRef = 1E7060BD28F88EE200E4CCDB /* Common */; };
1E60989D290011E600A508F9 /* ContentBlocking in Frameworks */ = {isa = PBXBuildFile; productRef = 1E60989C290011E600A508F9 /* ContentBlocking */; };
1E6098A1290011E600A508F9 /* UserScript in Frameworks */ = {isa = PBXBuildFile; productRef = 1E6098A0290011E600A508F9 /* UserScript */; };
Expand Down Expand Up @@ -820,7 +821,6 @@
B6BA95C328891E33004ABA20 /* BrowsingMenuAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6BA95C228891E33004ABA20 /* BrowsingMenuAnimator.swift */; };
B6BA95C528894A28004ABA20 /* BrowsingMenuViewController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B6BA95C428894A28004ABA20 /* BrowsingMenuViewController.storyboard */; };
B6BA95E828924730004ABA20 /* JSAlertController.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B6BA95E728924730004ABA20 /* JSAlertController.storyboard */; };
B6CB93E5286445AB0090FEB4 /* Base64DownloadSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6CB93E4286445AB0090FEB4 /* Base64DownloadSession.swift */; };
BBFF18B12C76448100C48D7D /* QuerySubmittedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBFF18B02C76448100C48D7D /* QuerySubmittedTests.swift */; };
BD10B8AA2C7629740033115D /* Logger+Subscription.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD10B8A92C7629740033115D /* Logger+Subscription.swift */; };
BD15DB852B959CFD00821457 /* BundleExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD15DB842B959CFD00821457 /* BundleExtension.swift */; };
Expand Down Expand Up @@ -2626,7 +2626,6 @@
B6BA95C228891E33004ABA20 /* BrowsingMenuAnimator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowsingMenuAnimator.swift; sourceTree = "<group>"; };
B6BA95C428894A28004ABA20 /* BrowsingMenuViewController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = BrowsingMenuViewController.storyboard; sourceTree = "<group>"; };
B6BA95E728924730004ABA20 /* JSAlertController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = JSAlertController.storyboard; sourceTree = "<group>"; };
B6CB93E4286445AB0090FEB4 /* Base64DownloadSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base64DownloadSession.swift; sourceTree = "<group>"; };
B6DFE6CF2BC7E47500A9CE59 /* SwiftLintTool.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftLintTool.bundle; sourceTree = BUILT_PRODUCTS_DIR; };
B6DFE6D92BC7E61B00A9CE59 /* SwiftLintToolBundleConfiguration.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = SwiftLintToolBundleConfiguration.xcconfig; sourceTree = "<group>"; };
BBFF18B02C76448100C48D7D /* QuerySubmittedTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuerySubmittedTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3052,6 +3051,7 @@
31E69A63280F4CB600478327 /* DuckUI in Frameworks */,
CB941A6E2B96AB08000F9E7A /* PrivacyDashboard in Frameworks */,
F42D541D29DCA40B004C4FF1 /* DesignResourcesKit in Frameworks */,
1E5918472CA422A7008ED2B3 /* Navigation in Frameworks */,
85875B6129912A9900115F05 /* SyncUI in Frameworks */,
F4D7F634298C00C3006C3AE9 /* FindInPageIOSJSSupport in Frameworks */,
9F96F73B2C9144D5009E45D5 /* Onboarding in Frameworks */,
Expand Down Expand Up @@ -3494,7 +3494,6 @@
B623C1C12862CA9E0043013E /* DownloadSession.swift */,
31C138A727A3E9C900FFD4B2 /* URLDownloadSession.swift */,
B623C1C32862CD670043013E /* WKDownloadSession.swift */,
B6CB93E4286445AB0090FEB4 /* Base64DownloadSession.swift */,
B609D5512862EAFF0088CAC2 /* InlineWKDownloadDelegate.swift */,
310D09202799FD1A00DC0060 /* MIMEType.swift */,
3161D13127AC161B00285CF6 /* DownloadMetadata.swift */,
Expand Down Expand Up @@ -6532,6 +6531,7 @@
F1D43AF92B99C1D300BAB743 /* BareBonesBrowserKit */,
9F8FE9482BAE50E50071E372 /* Lottie */,
9F96F73A2C9144D5009E45D5 /* Onboarding */,
1E5918462CA422A7008ED2B3 /* Navigation */,
);
productName = DuckDuckGo;
productReference = 84E341921E2F7EFB00BDBA6F /* DuckDuckGo.app */;
Expand Down Expand Up @@ -7736,7 +7736,6 @@
EE01EB432AFC1E0A0096AAC9 /* NetworkProtectionVPNLocationView.swift in Sources */,
7BC571202BDBB877003B0CCE /* VPNActivationDateStore.swift in Sources */,
9820EAF522613CD30089094D /* WebProgressWorker.swift in Sources */,
B6CB93E5286445AB0090FEB4 /* Base64DownloadSession.swift in Sources */,
1EEF387D285B1A1100383393 /* TrackerImageCache.swift in Sources */,
3151F0EC27357FEE00226F58 /* VoiceSearchFeedbackViewModel.swift in Sources */,
1E53508F2C7C9A1F00818DAA /* DefaultSubscriptionManager+AccountManagerKeychainAccessDelegate.swift in Sources */,
Expand Down Expand Up @@ -11040,6 +11039,11 @@
package = F486D2FD25069744002D07D7 /* XCRemoteSwiftPackageReference "OHHTTPStubs" */;
productName = OHHTTPStubsSwift;
};
1E5918462CA422A7008ED2B3 /* Navigation */ = {
isa = XCSwiftPackageProductDependency;
package = 98A16C2928A11BDE00A6C003 /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
productName = Navigation;
};
1E60989C290011E600A508F9 /* ContentBlocking */ = {
isa = XCSwiftPackageProductDependency;
package = 98A16C2928A11BDE00A6C003 /* XCRemoteSwiftPackageReference "BrowserServicesKit" */;
Expand Down
63 changes: 0 additions & 63 deletions DuckDuckGo/Base64DownloadSession.swift

This file was deleted.

2 changes: 1 addition & 1 deletion DuckDuckGo/DownloadMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct DownloadMetadata {
self.filename = filename
self.expectedContentLength = response.expectedContentLength
self.mimeTypeSource = response.mimeType ?? ""
self.mimeType = MIMEType(from: response.mimeType)
self.mimeType = MIMEType(from: response.mimeType, fileExtension: filename.pathExtension)
self.url = url
}
}
12 changes: 11 additions & 1 deletion DuckDuckGo/MIMEType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@ enum MIMEType: String {
init(from string: String?) {
self = MIMEType(rawValue: string ?? "") ?? .unknown
}


init(from string: String?, fileExtension: String?) {
let initialMIMEType = MIMEType(from: string)

switch (initialMIMEType, fileExtension) {
case (.octetStream, "pkpass"): self = .passbook
case (.octetStream, "pkpasses"): self = .multipass
default: self = initialMIMEType
}
}

var isHTML: Bool {
switch self {
case .html, .xhtml:
Expand Down
Loading

0 comments on commit 70b3d55

Please sign in to comment.