Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Sep 7, 2023
1 parent db4e533 commit 950c30b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
11 changes: 3 additions & 8 deletions ElementX/Sources/Application/Navigation/AppRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum AppRouteURLParser {
private enum KnownHosts: String, CaseIterable {
case elementIo = "element.io"
case appElementIo = "app.element.io"
case statingElementIo = "staging.element.io"
case stagingElementIo = "staging.element.io"
case developElementIo = "develop.element.io"
case mobileElementIo = "mobile.element.io"
case callElementIo = "call.element.io"
Expand All @@ -48,13 +48,8 @@ enum AppRouteURLParser {
if host == KnownHosts.callElementIo.rawValue {
return .genericCallLink(url: url)
}

#warning("Remove this")
if host == KnownHosts.appElementIo.rawValue {
return .genericCallLink(url: "https://call.element.io/stefanTestsThings")
}

// Deep linking not supported

// Deep linking not supported at the moment
return nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
// MARK: - Private

private func clearPresentedSheets(animated: Bool, completion: @escaping () -> Void) {
if navigationSplitCoordinator.sheetCoordinator == nil {
completion()
return
}

navigationSplitCoordinator.setSheetCoordinator(nil, animated: animated)

// Prevents system crashes when presenting a sheet if another one was already shown
Expand Down
32 changes: 28 additions & 4 deletions ElementX/Sources/Screens/Other/GenericCallLinkCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,20 @@ private struct WebView: UIViewRepresentable {
}

func makeCoordinator() -> Coordinator {
Coordinator()
Coordinator(initialURL: url)
}

func updateUIView(_ webView: WKWebView, context: Context) {
webView.load(URLRequest(url: url))
}

@MainActor
class Coordinator: NSObject, WKUIDelegate {
class Coordinator: NSObject, WKUIDelegate, WKNavigationDelegate {
private let initialURL: URL
private(set) var webView: WKWebView!

override init() {
init(initialURL: URL) {
self.initialURL = initialURL
super.init()

let configuration = WKWebViewConfiguration()
Expand All @@ -71,7 +73,29 @@ private struct WebView: UIViewRepresentable {
// MARK: - WKUIDelegate

func webView(_ webView: WKWebView, decideMediaCapturePermissionsFor origin: WKSecurityOrigin, initiatedBy frame: WKFrameInfo, type: WKMediaCaptureType) async -> WKPermissionDecision {
.grant
// Don't allow permissions for domains different than what the call was started on
guard origin.host == initialURL.host else {
return .deny
}

return .grant
}

// MARK: - WKNavigationDelegate

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction) async -> WKNavigationActionPolicy {
// Allow any content from the main URL.
if navigationAction.request.url?.host == initialURL.host {
return .allow
}

// Additionally allow any embedded content such as captchas.
if let targetFrame = navigationAction.targetFrame, !targetFrame.isMainFrame {
return .allow
}

// Otherwise the request is invalid.
return .cancel
}
}
}

0 comments on commit 950c30b

Please sign in to comment.