mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-09 17:31:47 +09:00
Dactyloidae iOS initial commit
This commit is contained in:
parent
daa6179d22
commit
7154a0497e
2123 changed files with 197052 additions and 0 deletions
41
mobile/ios/Client/Frontend/Browser/PrivilegedRequest.swift
Normal file
41
mobile/ios/Client/Frontend/Browser/PrivilegedRequest.swift
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* 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
|
||||
|
||||
private let REQUEST_KEY_PRIVILEGED = "privileged"
|
||||
|
||||
/**
|
||||
Request that is allowed to load local resources.
|
||||
|
||||
Pages running on the local server have same origin access all resources
|
||||
on the server, so we need to prevent arbitrary web pages from accessing
|
||||
these resources. We do so by explicitly requiring "privileged" requests
|
||||
in our navigation policy when loading local resources.
|
||||
|
||||
Be careful: creating a privileged request for an arbitrary URL provided
|
||||
by the page will break this model. Only use a privileged request when
|
||||
needed, and when you are sure the URL is from a trustworthy source!
|
||||
**/
|
||||
class PrivilegedRequest: NSMutableURLRequest {
|
||||
override init(url URL: URL, cachePolicy: NSURLRequest.CachePolicy, timeoutInterval: TimeInterval) {
|
||||
super.init(url: URL, cachePolicy: cachePolicy, timeoutInterval: timeoutInterval)
|
||||
setPrivileged()
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
setPrivileged()
|
||||
}
|
||||
|
||||
fileprivate func setPrivileged() {
|
||||
URLProtocol.setProperty(true, forKey: REQUEST_KEY_PRIVILEGED, in: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension URLRequest {
|
||||
var isPrivileged: Bool {
|
||||
return URLProtocol.property(forKey: REQUEST_KEY_PRIVILEGED, in: self) != nil
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue