1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- //
- // NCRichdocument.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 06/09/18.
- // Copyright © 2018 TWS. All rights reserved.
- //
- // Author Marino Faggiana <m.faggiana@twsweb.it>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- import Foundation
- class NCRichdocument: NSObject, WKNavigationDelegate, WKScriptMessageHandler {
-
- @objc static let sharedInstance: NCRichdocument = {
- let instance = NCRichdocument()
- return instance
- }()
-
- var webView: WKWebView?
- var request: URLRequest!
- var viewDetail: CCDetail?
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
- @objc func viewRichDocumentAt(_ link: String, viewDetail: CCDetail) {
-
- self.viewDetail = viewDetail
-
- let contentController = WKUserContentController()
- contentController.add(self, name: "RichDocumentsMobileInterface")
- let configuration = WKWebViewConfiguration()
- configuration.userContentController = contentController
-
- webView = WKWebView(frame: viewDetail.view.bounds, configuration: configuration)
- webView?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
- webView?.navigationDelegate = self
-
- self.request = URLRequest(url: URL(string: link)!)
- self.request.addValue("true", forHTTPHeaderField: "OCS-APIRequest")
- let language = NSLocale.preferredLanguages[0] as String
- self.request.addValue(language, forHTTPHeaderField: "Accept-Language")
-
- let userAgent : String = CCUtility.getUserAgent()
- webView!.customUserAgent = userAgent
- webView!.load(self.request!)
-
- viewDetail.view.addSubview(webView!)
- }
-
- public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
- print("WKScriptMessage");
- }
-
- public func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
- if let serverTrust = challenge.protectionSpace.serverTrust {
- completionHandler(Foundation.URLSession.AuthChallengeDisposition.useCredential, URLCredential(trust: serverTrust))
- } else {
- completionHandler(URLSession.AuthChallengeDisposition.useCredential, nil);
- }
- }
-
- public func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
- print("didStartProvisionalNavigation");
- }
-
- public func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
- print("didReceiveServerRedirectForProvisionalNavigation");
- }
-
- public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
- print("didFinish");
- }
- }
|