From 033860d18b6ae0c2d39359477a3cbdecb4ace2d7 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Tue, 2 Feb 2021 18:13:30 +0100 Subject: [PATCH] MOBILE-3689 android: Enable ionic-webview plugin --- package-lock.json | 5 +++-- package.json | 2 +- src/core/services/file.ts | 8 +++++--- src/core/services/utils/iframe.ts | 2 +- src/core/services/utils/url.ts | 7 ++++--- src/core/services/ws.ts | 2 +- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 977dd2cfb..6a54802d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7208,8 +7208,9 @@ "integrity": "sha512-6ucQ6FdlLdBm8kJfFnzozmBTjru/0xekHP/dAhjoCZggkGRlgs8TsUJFkxa/bV+qi7Dlo50JjmpE4UMWAO+aOQ==" }, "cordova-plugin-ionic-webview": { - "version": "git+https://github.com/moodlemobile/cordova-plugin-ionic-webview.git#ac90a8ac88e2c0512d6b250249b1f673f2fbcb68", - "from": "git+https://github.com/moodlemobile/cordova-plugin-ionic-webview.git#500-moodle" + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/cordova-plugin-ionic-webview/-/cordova-plugin-ionic-webview-4.2.1.tgz", + "integrity": "sha512-7KrmqLaOGq1RP8N2z1ezN1kqkWFzTwwMvQ3/qAkd+exxFZuOe3DIN4eaU1gdNphsxdirI8Ajnr9q4So5vQbWqw==" }, "cordova-plugin-local-notification": { "version": "git+https://github.com/moodlemobile/cordova-plugin-local-notification.git#0bb96b757fb484553ceabf35a59802f7983a2836", diff --git a/package.json b/package.json index 07da98963..8b72e926d 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "cordova-plugin-globalization": "^1.11.0", "cordova-plugin-inappbrowser": "git+https://github.com/moodlemobile/cordova-plugin-inappbrowser.git#moodle", "cordova-plugin-ionic-keyboard": "2.1.3", - "cordova-plugin-ionic-webview": "git+https://github.com/moodlemobile/cordova-plugin-ionic-webview.git#500-moodle", + "cordova-plugin-ionic-webview": "^4.2.1", "cordova-plugin-local-notification": "git+https://github.com/moodlemobile/cordova-plugin-local-notification.git#moodle", "cordova-plugin-media": "^5.0.3", "cordova-plugin-media-capture": "^3.0.3", diff --git a/src/core/services/file.ts b/src/core/services/file.ts index 5f48fa2e8..539aea31e 100644 --- a/src/core/services/file.ts +++ b/src/core/services/file.ts @@ -1233,7 +1233,7 @@ export class CoreFileProvider { * @return Converted src. */ convertFileSrc(src: string): string { - return CoreApp.instance.isIOS() ? WebView.instance.convertFileSrc(src) : src; + return CoreApp.instance.isMobile() ? WebView.instance.convertFileSrc(src) : src; } /** @@ -1243,11 +1243,13 @@ export class CoreFileProvider { * @return Unconverted src. */ unconvertFileSrc(src: string): string { - if (!CoreApp.instance.isIOS()) { + if (!CoreApp.instance.isMobile()) { return src; } - return src.replace(CoreConstants.CONFIG.ioswebviewscheme + '://localhost/_app_file_', 'file://'); + const scheme = CoreApp.instance.isIOS() ? CoreConstants.CONFIG.ioswebviewscheme : 'http'; + + return src.replace(scheme + '://localhost/_app_file_', 'file://'); } /** diff --git a/src/core/services/utils/iframe.ts b/src/core/services/utils/iframe.ts index b2ee65307..85dc4cbb9 100644 --- a/src/core/services/utils/iframe.ts +++ b/src/core/services/utils/iframe.ts @@ -390,7 +390,7 @@ export class CoreIframeUtilsProvider { return; } - if (urlParts.protocol && !CoreUrlUtils.instance.isLocalFileUrlScheme(urlParts.protocol)) { + if (urlParts.protocol && !CoreUrlUtils.instance.isLocalFileUrlScheme(urlParts.protocol, urlParts.domain || '')) { // Scheme suggests it's an external resource. event && event.preventDefault(); diff --git a/src/core/services/utils/url.ts b/src/core/services/utils/url.ts index 428cbce48..c773dd3fb 100644 --- a/src/core/services/utils/url.ts +++ b/src/core/services/utils/url.ts @@ -424,7 +424,7 @@ export class CoreUrlUtilsProvider { isLocalFileUrl(url: string): boolean { const urlParts = CoreUrl.parse(url); - return this.isLocalFileUrlScheme(urlParts?.protocol || ''); + return this.isLocalFileUrlScheme(urlParts?.protocol || '', urlParts?.domain || ''); } /** @@ -433,7 +433,7 @@ export class CoreUrlUtilsProvider { * @param scheme Scheme to check. * @return Whether the scheme belongs to a local file. */ - isLocalFileUrlScheme(scheme: string): boolean { + isLocalFileUrlScheme(scheme: string, domain: string): boolean { if (!scheme) { return false; } @@ -442,7 +442,8 @@ export class CoreUrlUtilsProvider { return scheme == 'cdvfile' || scheme == 'file' || scheme == 'filesystem' || - scheme == CoreConstants.CONFIG.ioswebviewscheme; + scheme == CoreConstants.CONFIG.ioswebviewscheme || + (scheme === 'http' && domain === 'localhost'); } /** diff --git a/src/core/services/ws.ts b/src/core/services/ws.ts index 33b285cc8..66420bbf9 100644 --- a/src/core/services/ws.ts +++ b/src/core/services/ws.ts @@ -927,7 +927,7 @@ export class CoreWSProvider { options.responseType = options.responseType || 'json'; options.timeout = typeof options.timeout == 'undefined' ? this.getRequestTimeout() : options.timeout; - if (CoreApp.instance.isIOS()) { + if (CoreApp.instance.isMobile()) { // Use the cordova plugin. if (url.indexOf('file://') === 0) { // We cannot load local files using the http native plugin. Use file provider instead.