Skip to content

Commit

Permalink
Merge pull request #25496 from brave/ios-fix-tempdoc-share
Browse files Browse the repository at this point in the history
[iOS] Show correct options when sharing a temporary doc like a PDF
  • Loading branch information
kylehickinson authored Sep 10, 2024
2 parents e23684f + 315c4bd commit c790d67
Showing 1 changed file with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,6 @@ extension BrowserViewController: WKNavigationDelegate {
return .download
}

if canShowInWebView {
return .allow
}

// Check if this response should be handed off to Passbook.
if shouldDownloadNavigationResponse {
shouldDownloadNavigationResponse = false
Expand All @@ -769,6 +765,26 @@ extension BrowserViewController: WKNavigationDelegate {
}
}

// If the content type is not HTML, create a temporary document so it can be downloaded and
// shared to external applications later. Otherwise, clear the old temporary document.
if let tab = tab, navigationResponse.isForMainFrame {
if response.mimeType?.isKindOfHTML == false, let request = request {
tab.temporaryDocument = TemporaryDocument(
preflightResponse: response,
request: request,
tab: tab
)
} else {
tab.temporaryDocument = nil
}

tab.mimeType = response.mimeType
}

if canShowInWebView {
return .allow
}

// Check if this response should be downloaded.
let cookieStore = webView.configuration.websiteDataStore.httpCookieStore
if let downloadHelper = DownloadHelper(
Expand Down Expand Up @@ -796,22 +812,6 @@ extension BrowserViewController: WKNavigationDelegate {
return .cancel
}

// If the content type is not HTML, create a temporary document so it can be downloaded and
// shared to external applications later. Otherwise, clear the old temporary document.
if let tab = tab, navigationResponse.isForMainFrame {
if response.mimeType?.isKindOfHTML == false, let request = request {
tab.temporaryDocument = TemporaryDocument(
preflightResponse: response,
request: request,
tab: tab
)
} else {
tab.temporaryDocument = nil
}

tab.mimeType = response.mimeType
}

// If none of our helpers are responsible for handling this response,
// just let the webview handle it as normal.
return .download
Expand Down

0 comments on commit c790d67

Please sign in to comment.