From 0c883395df04c2f6ae38dfc63cab9d1f2a100932 Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Tue, 25 Aug 2015 15:21:56 +0300 Subject: [PATCH 1/2] base url used when loading local files in web-view Fix for #613 --- CrossPlatformModules.csproj | 7 ++++++- apps/ui-tests-app/web-view/test.css | 3 +++ apps/ui-tests-app/web-view/test.html | 11 +++++++++++ apps/ui-tests-app/web-view/webview.xml | 2 +- apps/ui-tests-app/web-view/webviewlocalfile.xml | 6 ++++++ ui/web-view/web-view.android.ts | 5 +++-- ui/web-view/web-view.ios.ts | 3 ++- 7 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 apps/ui-tests-app/web-view/test.css create mode 100644 apps/ui-tests-app/web-view/test.html create mode 100644 apps/ui-tests-app/web-view/webviewlocalfile.xml diff --git a/CrossPlatformModules.csproj b/CrossPlatformModules.csproj index 02cbc7f68..dbe6a6c2f 100644 --- a/CrossPlatformModules.csproj +++ b/CrossPlatformModules.csproj @@ -150,6 +150,8 @@ + + @@ -965,7 +967,10 @@ + + + @@ -1944,7 +1949,7 @@ False - + \ No newline at end of file diff --git a/apps/ui-tests-app/web-view/test.css b/apps/ui-tests-app/web-view/test.css new file mode 100644 index 000000000..dde830c8f --- /dev/null +++ b/apps/ui-tests-app/web-view/test.css @@ -0,0 +1,3 @@ +body { + background-color: green; +} diff --git a/apps/ui-tests-app/web-view/test.html b/apps/ui-tests-app/web-view/test.html new file mode 100644 index 000000000..f3daf0bd7 --- /dev/null +++ b/apps/ui-tests-app/web-view/test.html @@ -0,0 +1,11 @@ + + + + MyTitle + + + + + Test + + diff --git a/apps/ui-tests-app/web-view/webview.xml b/apps/ui-tests-app/web-view/webview.xml index 7e1f5ce11..2f756ac0a 100644 --- a/apps/ui-tests-app/web-view/webview.xml +++ b/apps/ui-tests-app/web-view/webview.xml @@ -2,7 +2,7 @@ + src="http://www.bbc.com/" minHeight="250" /> \ No newline at end of file diff --git a/apps/ui-tests-app/web-view/webviewlocalfile.xml b/apps/ui-tests-app/web-view/webviewlocalfile.xml new file mode 100644 index 000000000..59819ee4e --- /dev/null +++ b/apps/ui-tests-app/web-view/webviewlocalfile.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/ui/web-view/web-view.android.ts b/ui/web-view/web-view.android.ts index 13dc09095..a1830da28 100644 --- a/ui/web-view/web-view.android.ts +++ b/ui/web-view/web-view.android.ts @@ -89,8 +89,9 @@ export class WebView extends common.WebView { var file = fs.File.fromPath(src); if (file) { - file.readText().then((r) => { - this._android.loadData(r, "text/html", null); + var baseUrl = `file:///${src.substring(0, src.lastIndexOf('/') + 1)}`; + file.readText().then(r => { + this._android.loadDataWithBaseURL(baseUrl, r, "text/html", null, null); }); } } else if (src.indexOf("http://") === 0 || src.indexOf("https://") === 0) { diff --git a/ui/web-view/web-view.ios.ts b/ui/web-view/web-view.ios.ts index 053857442..e33e80414 100644 --- a/ui/web-view/web-view.ios.ts +++ b/ui/web-view/web-view.ios.ts @@ -97,8 +97,9 @@ export class WebView extends common.WebView { var file = fs.File.fromPath(src); if (file) { + var baseURL = NSURL.fileURLWithPath(NSString.stringWithString(src).stringByDeletingLastPathComponent); file.readText().then((r) => { - this._ios.loadHTMLStringBaseURL(r, null); + this._ios.loadHTMLStringBaseURL(r, baseURL); }); } } else if (src.indexOf("http://") === 0 || src.indexOf("https://") === 0) { From 675fa3cceebfec4284aa97cab542e78e789f8636 Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Tue, 25 Aug 2015 15:39:33 +0300 Subject: [PATCH 2/2] path fixed --- apps/ui-tests-app/web-view/webviewlocalfile.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/ui-tests-app/web-view/webviewlocalfile.xml b/apps/ui-tests-app/web-view/webviewlocalfile.xml index 59819ee4e..669a78965 100644 --- a/apps/ui-tests-app/web-view/webviewlocalfile.xml +++ b/apps/ui-tests-app/web-view/webviewlocalfile.xml @@ -1,6 +1,6 @@  - +