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

[iOS] Move web view delegate logic into a shared components #27746

Merged
merged 3 commits into from
Feb 27, 2025
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 @@ -44,17 +44,17 @@ class BraveSkusAccountLink {
}

@MainActor
static func injectLocalStorage(webView: WKWebView) async {
static func injectLocalStorage(tab: Tab) async {
if let vpnSubscriptionProductId = Preferences.VPN.subscriptionProductId.value,
let product = BraveStoreProduct(rawValue: vpnSubscriptionProductId)
{
await BraveSkusAccountLink.injectLocalStorage(webView: webView, product: product)
await BraveSkusAccountLink.injectLocalStorage(tab: tab, product: product)
}

if let aiChatSubscriptionProductId = Preferences.AIChat.subscriptionProductId.value,
let product = BraveStoreProduct(rawValue: aiChatSubscriptionProductId)
{
await BraveSkusAccountLink.injectLocalStorage(webView: webView, product: product)
await BraveSkusAccountLink.injectLocalStorage(tab: tab, product: product)
}
}

Expand All @@ -63,11 +63,11 @@ class BraveSkusAccountLink {
/// - Parameter product: The product whose receipt information to inject
@MainActor
@discardableResult private static func injectLocalStorage(
webView: WKWebView,
tab: Tab,
product: BraveStoreProduct
) async -> Bool {
// The WebView has no URL so do nothing
guard let url = webView.url else {
guard let webView = tab.webView, let url = webView.url else {
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

import BraveCore
import Foundation
import Shared
import WebKit
Expand Down Expand Up @@ -92,13 +93,13 @@ protocol JSAlertInfo {

struct MessageAlert: JSAlertInfo {
let message: String
let frame: WKFrameInfo
let origin: URLOrigin
let completionHandler: () -> Void
var suppressHandler: SuppressHandler?

func alertController() -> JSPromptAlertController {
let alertController = JSPromptAlertController(
title: titleForJavaScriptPanelInitiatedByFrame(frame),
title: origin.serialized,
message: message,
info: self,
showCancel: false
Expand All @@ -119,14 +120,14 @@ struct MessageAlert: JSAlertInfo {

struct ConfirmPanelAlert: JSAlertInfo {
let message: String
let frame: WKFrameInfo
let origin: URLOrigin
let completionHandler: (Bool) -> Void
var suppressHandler: SuppressHandler?

func alertController() -> JSPromptAlertController {
// Show JavaScript confirm dialogs.
let alertController = JSPromptAlertController(
title: titleForJavaScriptPanelInitiatedByFrame(frame),
title: origin.serialized,
message: message,
info: self
)
Expand All @@ -146,14 +147,14 @@ struct ConfirmPanelAlert: JSAlertInfo {

struct TextInputAlert: JSAlertInfo {
let message: String
let frame: WKFrameInfo
let origin: URLOrigin
let completionHandler: (String?) -> Void
let defaultText: String?
var suppressHandler: SuppressHandler?

func alertController() -> JSPromptAlertController {
let alertController = JSPromptAlertController(
title: titleForJavaScriptPanelInitiatedByFrame(frame),
title: origin.serialized,
message: message,
info: self
)
Expand All @@ -176,17 +177,6 @@ struct TextInputAlert: JSAlertInfo {
}
}

/// Show a title for a JavaScript Panel (alert) based on the WKFrameInfo. On iOS9 we will use the new securityOrigin
/// and on iOS 8 we will fall back to the request URL. If the request URL is nil, which happens for JavaScript pages,
/// we fall back to "JavaScript" as a title.
private func titleForJavaScriptPanelInitiatedByFrame(_ frame: WKFrameInfo) -> String {
var title = "\(frame.securityOrigin.`protocol`)://\(frame.securityOrigin.host)"
if frame.securityOrigin.port != 0 {
title += ":\(frame.securityOrigin.port)"
}
return title
}

/// A generic browser alert that will execute a closure if its dismissed and no actions were picked
/// to allow us to call any neccessary completion handlers required by WebKit
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ extension BrowserViewController {
activityType: .pageZoom,
callback: { [weak self] in
guard let self = self else { return }

self.displayPageZoom(visible: true)
self.displayPageZoomDialog()
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,15 @@ extension BrowserViewController: TabManagerDelegate {
}
}

displayPageZoom(visible: false)
clearPageZoomDialog()
updateTabsBarVisibility()
selected?.updatePullToRefreshVisibility()

topToolbar.locationView.loading = selected?.loading ?? false
updateBackForwardActionStatus(for: selected?.webView)
navigationToolbar.updateForwardStatus(selected?.canGoForward ?? false)
if let tab = selected {
topToolbar.locationView.loading = tab.loading
updateBackForwardActionStatus(for: tab)
navigationToolbar.updateForwardStatus(tab.canGoForward)
}

let shouldShowPlaylistURLBarButton = selected?.url?.isPlaylistSupportedSiteURL == true

Expand Down
Loading
Loading