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

Commit 9c9e494

Browse files
committed
adds mimetype for html
1 parent d90bd16 commit 9c9e494

File tree

6 files changed

+34
-22
lines changed

6 files changed

+34
-22
lines changed

native-src/ios/NotaWebViewExt/NotaWebViewExt/Constants.swift

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import Foundation
1111
struct Constants {
1212
static let customURLScheme = "x-local"
1313
static let mimeType: [String: String] = [
14+
"html": "text/html",
15+
"htm": "text/html",
16+
"xhtml": "text/html",
17+
"xhtm": "text/html",
1418
"css": "text/css",
1519
"gif": "image/gif",
1620
"jpeg": "image/jpeg",

src/webview-ext-common.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export class WebViewExtBase extends View {
298298
this.writeTrace(`WebViewExt.src = "${originSrc}" x-local resolved to "${src}"`);
299299
} else {
300300
this.writeTrace(`WebViewExt.src = "${originSrc}" x-local couldn't resolve to file`, traceMessageType.error);
301-
this._onLoadFinished(src, 'unknown x-local-resource');
301+
this._onLoadFinished(src, 'unknown x-local-resource').catch(() => void 0);
302302
return;
303303
}
304304
}

src/webview-ext.android.ts

+24-16
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,17 @@ export declare namespace dk {
1515
class WebViewBridgeInterface extends java.lang.Object {
1616
public owner?: WebViewExt;
1717

18-
emitEventToNativeScript(eventName: string, data: string): void;
18+
public emitEventToNativeScript(eventName: string, data: string): void;
1919
}
2020
}
2121
}
2222
}
23-
export interface AndroidWebViewClient extends android.webkit.WebViewClient {
24-
owner?: WebViewExt;
25-
}
26-
27-
export interface AndroidWebView extends android.webkit.WebView {
28-
client?: AndroidWebViewClient;
29-
bridgeInterface?: dk.nota.webviewinterface.WebViewBridgeInterface;
30-
}
3123

3224
const extToMimeType = new Map<string, string>([
25+
['html', 'text/html'],
26+
['htm', 'text/html'],
27+
['xhtml', 'text/html'],
28+
['xhtm', 'text/html'],
3329
['css', 'text/css'],
3430
['gif', 'image/gif'],
3531
['jpeg', 'image/jpeg'],
@@ -51,6 +47,15 @@ const extToBinaryEncoding = new Set<string>([
5147
]);
5248

5349
//#region android_native_classes
50+
export interface AndroidWebViewClient extends android.webkit.WebViewClient {
51+
owner?: WebViewExt;
52+
}
53+
54+
export interface AndroidWebView extends android.webkit.WebView {
55+
client?: AndroidWebViewClient;
56+
bridgeInterface?: dk.nota.webviewinterface.WebViewBridgeInterface;
57+
}
58+
5459
let WebViewExtClient: new () => AndroidWebViewClient;
5560
let WebViewBridgeInterface: new () => dk.nota.webviewinterface.WebViewBridgeInterface;
5661
function initializeWebViewClient(): void {
@@ -181,7 +186,7 @@ function initializeWebViewClient(): void {
181186
}
182187

183188
owner.writeTrace(`WebViewClientClass.onPageFinished("${url}")`);
184-
owner._onLoadFinished(url);
189+
owner._onLoadFinished(url).catch(() => void 0);
185190
}
186191

187192
public onReceivedError() {
@@ -201,21 +206,24 @@ function initializeWebViewClient(): void {
201206
return;
202207
}
203208

204-
owner.writeTrace(`WebViewClientClass.onReceivedError(${error.getErrorCode()}, ${error.getDescription()}, ${error.getUrl && error.getUrl()})`);
209+
let url = error.getUrl && error.getUrl();
210+
if (!url && typeof request === 'object') {
211+
url = request.getUrl().toString();
212+
}
205213

206-
owner._onLoadFinished(error.getUrl && error.getUrl(), `${error.getDescription()}(${error.getErrorCode()})`);
214+
owner.writeTrace(`WebViewClientClass.onReceivedErrorAPI23(${error.getErrorCode()}, ${error.getDescription()}, ${url})`);
207215

216+
owner._onLoadFinished(url, `${error.getDescription()}(${error.getErrorCode()})`).catch(() => void 0);
208217
}
209218

210219
private onReceivedErrorBeforeAPI23(view: android.webkit.WebView, errorCode: number, description: string, failingUrl: string) {
211220
super.onReceivedError(view, errorCode, description, failingUrl);
212221

213222
const owner = this.owner;
214223
if (owner) {
215-
owner.writeTrace(`WebViewClientClass.onReceivedError(${errorCode}, "${description}", "${failingUrl}")`);
216-
owner._onLoadFinished(failingUrl, `${description}(${errorCode})`);
224+
owner.writeTrace(`WebViewClientClass.onReceivedErrorBeforeAPI23(${errorCode}, "${description}", "${failingUrl}")`);
225+
owner._onLoadFinished(failingUrl, `${description}(${errorCode})`).catch(() => void 0);
217226
}
218-
219227
}
220228
}
221229

@@ -229,7 +237,7 @@ function initializeWebViewClient(): void {
229237
return global.__native(this);
230238
}
231239

232-
emitEventToNativeScript(eventName: string, data: string) {
240+
public emitEventToNativeScript(eventName: string, data: string) {
233241
const owner = this.owner;
234242
if (!owner) {
235243
return;

src/webview-ext.ios.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ export class WebViewExt extends WebViewExtBase {
311311
try {
312312
const message = decodeURIComponent(url.replace(/^js2ios:/, ''));
313313
const { eventName, resId } = JSON.parse(message);
314-
this.executeJavaScript(`window.nsWebViewBridge.getUIWebViewResponse(${JSON.stringify(resId)})`)
314+
this.executeJavaScript<any>(`window.nsWebViewBridge.getUIWebViewResponse(${JSON.stringify(resId)})`)
315315
.then((data) => {
316316
this.onWebViewEvent(eventName, data);
317317
})

src/webview-ext.uiwebview.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class UIWebViewDelegateImpl extends NSObject implements UIWebViewDelegate
9595
if (webView.request && webView.request.URL) {
9696
src = webView.request.URL.absoluteString;
9797
}
98-
owner._onLoadFinished(src);
98+
owner._onLoadFinished(src).catch(() => void 0);
9999
}
100100

101101
public webViewDidFailLoadWithError(webView: UIWebView, error: NSError) {
@@ -110,6 +110,6 @@ export class UIWebViewDelegateImpl extends NSObject implements UIWebViewDelegate
110110
}
111111

112112
owner.writeTrace(`UIWebViewDelegateClass.webViewDidFailLoadWithError("${error.localizedDescription}") url: "${src}"`);
113-
owner._onLoadFinished(src, error.localizedDescription);
113+
owner._onLoadFinished(src, error.localizedDescription).catch(() => void 0);
114114
}
115115
}

src/webview-ext.wkwebview.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class WKNavigationDelegateImpl extends NSObject implements WKNavigationDe
8989
if (webView.URL) {
9090
src = webView.URL.absoluteString;
9191
}
92-
owner._onLoadFinished(src);
92+
owner._onLoadFinished(src).catch(() => void 0);
9393
}
9494

9595
public webViewDidFailNavigationWithError(webView: WKWebView, navigation: WKNavigation, error: NSError): void {
@@ -103,7 +103,7 @@ export class WKNavigationDelegateImpl extends NSObject implements WKNavigationDe
103103
src = webView.URL.absoluteString;
104104
}
105105
owner.writeTrace(`WKNavigationDelegateClass.webViewDidFailNavigationWithError("${error.localizedDescription}")`);
106-
owner._onLoadFinished(src, error.localizedDescription);
106+
owner._onLoadFinished(src, error.localizedDescription).catch(() => void 0);
107107
}
108108
}
109109

0 commit comments

Comments
 (0)