Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Refactor URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon-T committed Jun 22, 2020
1 parent af5a294 commit e30952f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,13 @@ extension BrowserViewController: WKNavigationDelegate {
// Three types of results.. "safe", "dangerous", "unknown"
// We currently only block `dangerous` pages as per the spec.
// Unknown results must be considered safe.
if case .dangerous(let threatType) = safeBrowsingResult {
switch safeBrowsingResult {
case .dangerous(let threatType):
self.tabManager.tabForWebView(webView)?.interstitialPageHandler?.showSafeBrowsingPage(url: url, for: webView, threatType: threatType, completion: { policy in
decisionHandler(policy)
})
} else {

default:
//The url/page/ip is not a threat, so handle navigation like normal.
self.handleNavigation(webView, decidePolicyFor: navigationAction, decisionHandler: decisionHandler)
}
Expand Down
12 changes: 8 additions & 4 deletions Client/SafeBrowsingPages/InterstitialPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ class InterstitialPageHandler: TabContentScript {
.potentiallyHarmfulApplication: "HarmfulApplication"
]

var components = URLComponents(string: WebServer.sharedInstance.base + "/interstitial/\(pages[threatType]!).html")!
let page = pages[threatType] ?? "MITM"
var components = URLComponents(string: WebServer.sharedInstance.base + "/interstitial/\(page).html")!
components.queryItems = [URLQueryItem(name: "url", value: url.absoluteString)]
webView.load(PrivilegedRequest(url: components.url!) as URLRequest)

if let url = components.url {
webView.load(PrivilegedRequest(url: url) as URLRequest)
} else {
fatalError("Invalid URL")
}
}

func userContentController(_ userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
Expand All @@ -45,8 +51,6 @@ class InterstitialPageHandler: TabContentScript {
tab?.goBack()
} else if message == "proceed_unsafe" {
tab?.webView?.load(InterstitialRequest(url: url!) as URLRequest)
} else {

}
}

Expand Down

0 comments on commit e30952f

Please sign in to comment.