Skip to content

Commit

Permalink
[iOS] Show correct options when sharing a temporary doc like a PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehickinson committed Sep 9, 2024
1 parent 3516cf1 commit 315c4bd
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 315c4bd

Please sign in to comment.