-
Notifications
You must be signed in to change notification settings - Fork 905
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
[iOS] - Add ability to download and install PKPasses (Bundled) #27258
base: master
Are you sure you want to change the base?
Conversation
CI failing |
import Foundation | ||
import os.log | ||
|
||
class ZipImporter { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this in Sync/BraveCore/ZipImporter
? If its generic lets move it to BraveShared
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@MainActor | ||
static func unzip(path: URL) async throws -> URL { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has no reason to be MainActor
isolated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does. It calls Brave-Core's await Unzip.unzip(nativeImportPath, toDirectory: nativeDestinationPath)
and it crashes iirc, if not on the main-actor with some sequence checker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then that requirement should be in the core side, not here, otherwise you'd need to remember to always add MainActor isolation when unzipping using this method. If there's a sequence checker requirement then you should be using a stable task runner in the Obj-C++ side since we can't control that aspect from Swift other than forcing the code to run on main
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
static func uniqueFileName(_ filename: String, folder: URL) async throws -> URL { | ||
let basePath = folder.appending(path: filename) | ||
let fileExtension = basePath.pathExtension | ||
let filenameWithoutExtension = | ||
!fileExtension.isEmpty ? String(filename.dropLast(fileExtension.count + 1)) : filename | ||
|
||
var proposedPath = basePath | ||
var count = 0 | ||
|
||
while await AsyncFileManager.default.fileExists(atPath: proposedPath.path) { | ||
count += 1 | ||
|
||
let proposedFilenameWithoutExtension = "\(filenameWithoutExtension) (\(count))" | ||
proposedPath = folder.appending(path: proposedFilenameWithoutExtension) | ||
.appending(path: fileExtension) | ||
} | ||
|
||
return proposedPath | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be duplicated, we should move it to a shared place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
/// URL where temporary files are stored. | ||
public var temporaryDirectory: URL { | ||
fileManager.temporaryDirectory | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be deleted, just access FileManger.default.temporaryDirectory
like normal
public var fileSystemRepresentation: String? { | ||
return self.withUnsafeFileSystemRepresentation { bytes -> String? in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the reasoning for using the withUnsafeFileSystemRepresentation
instead of just using absoluteString
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AbsoluteString doesn't strip query parameters or scheme or anything. It's just the full URL as a string representation.
fileSystemRepresentation
returns a path
always, with no scheme and works better with native code that requires a native file-system path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wouldn't you already be dealing with a proper file path here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the file path we get is from whatever the user selected in the document picker. The url is a file path but it contains the file:///
scheme and I don't want the scheme or the escaping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -18,7 +18,8 @@ extension BrowserViewController: WKDownloadDelegate { | |||
) async -> URL? { | |||
|
|||
if let httpResponse = response as? HTTPURLResponse { | |||
if httpResponse.mimeType != MIMEType.passbook { | |||
if ![MIMEType.passbook, MIMEType.passbookBundle].contains(httpResponse.mimeType?.lowercased()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it actually possible for the mime-type stored in URLResponse
to be not lowercase for these mimtypes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The HTML spec says it's case-insensitive but handling of it depends on the developer. So if I send back TEXT/HTML
I'm not sure if it'll be normalized to text/html
when received. I'm not sure if iOS will do it.
So I lower-case it anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chromium major version is behind target branch (132.0.6834.83 vs 133.0.6943.27). Please rebase. |
87a5449
to
90a20b5
Compare
Summary
Resolves brave/brave-browser#43338
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
wikinpm run presubmit
wiki,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan: