mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-08-20 19:33:08 +09:00
32 lines
1.1 KiB
Swift
32 lines
1.1 KiB
Swift
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
import Foundation
|
|
import WebKit
|
|
|
|
class LocalRequestHelper: TabContentScript {
|
|
func scriptMessageHandlerName() -> String? {
|
|
return "localRequestHelper"
|
|
}
|
|
|
|
func userContentController(_ userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
|
|
guard message.frameInfo.request.url?.isLocal ?? false else { return }
|
|
|
|
let params = message.body as! [String: String]
|
|
|
|
if params["type"] == "load",
|
|
let urlString = params["url"],
|
|
let url = URL(string: urlString) {
|
|
_ = message.webView?.load(PrivilegedRequest(url: url) as URLRequest)
|
|
} else if params["type"] == "reload" {
|
|
_ = message.webView?.reload()
|
|
} else {
|
|
assertionFailure("Invalid message: \(message.body)")
|
|
}
|
|
}
|
|
|
|
class func name() -> String {
|
|
return "LocalRequestHelper"
|
|
}
|
|
}
|