cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [30/31] git commit: CB-4421 Fix for XHR to local files, can now be relative to current page, as expected
Date Fri, 13 Sep 2013 01:20:05 GMT
CB-4421 Fix for XHR to local files, can now be relative to current page, as expected


Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/84c1395b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/84c1395b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/84c1395b

Branch: refs/heads/master
Commit: 84c1395b490d1a9212b9ca96fe35dae91c0c1ae6
Parents: b76752e
Author: purplecabbage <purplecabbage@gmail.com>
Authored: Thu Aug 22 13:03:55 2013 -0700
Committer: purplecabbage <purplecabbage@gmail.com>
Committed: Thu Aug 22 13:07:13 2013 -0700

----------------------------------------------------------------------
 wp7/template/cordovalib/XHRHelper.cs | 61 +++++++++++++++++++++----------
 wp8/template/cordovalib/XHRHelper.cs | 61 +++++++++++++++++++++----------
 2 files changed, 84 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/84c1395b/wp7/template/cordovalib/XHRHelper.cs
----------------------------------------------------------------------
diff --git a/wp7/template/cordovalib/XHRHelper.cs b/wp7/template/cordovalib/XHRHelper.cs
index 7c2fe10..35b8bd3 100644
--- a/wp7/template/cordovalib/XHRHelper.cs
+++ b/wp7/template/cordovalib/XHRHelper.cs
@@ -16,7 +16,7 @@ namespace WPCordovaClassLib.CordovaLib
         public WebBrowser Browser { get; set; }
         public PhoneApplicationPage Page { get; set; }
 
-        public void InjectScript() 
+        public void InjectScript()
         {
 
 
@@ -111,8 +111,7 @@ namespace WPCordovaClassLib.CordovaLib
                 {
                     this.isAsync = isAsync;
                     this.reqType = reqType;
-                    var newUrl = uri;
-                    this._url = newUrl;
+                    this._url = uri;
                 }
             },
             statusText: '',
@@ -133,6 +132,9 @@ namespace WPCordovaClassLib.CordovaLib
             getAllResponseHeaders: function() {
                 return this.wrappedXHR ? this.wrappedXHR.getAllResponseHeaders() : '';
             },
+            overrideMimeType: function(mimetype) {
+                return this.wrappedXHR ? this.wrappedXHR.overrideMimeType(mimetype) : '';
+            },
             responseText: '',
             responseXML: '',
             onResult: function(res) {
@@ -160,6 +162,37 @@ namespace WPCordovaClassLib.CordovaLib
                 else {
                     this.changeReadyState(XHRShim.OPENED);
                     var alias = this;
+                    var root = window.location.href; 
+                    var basePath = root.substr(0,root.lastIndexOf('/')) + '/';
+                    
+
+                    var resolvedUrl = this._url.split('//').join('/');
+
+                    var wwwFolderPath = navigator.userAgent.indexOf('MSIE 9.0') > -1 ?
'app/www/' : 'www/';
+
+                    console.log('original resolvedUrl = ' + resolvedUrl);
+
+                    if(resolvedUrl.indexOf('/') == 0) {
+                        console.log('removing leading /');
+                        resolvedUrl = resolvedUrl.substr(1);
+                    }
+
+                    if( resolvedUrl.indexOf('app/www') == 0 ) {
+                        
+                        resolvedUrl = window.location.protocol  + wwwFolderPath + resolvedUrl.substr(7);
+                    }
+                    else if( resolvedUrl.indexOf('www') == 0) {
+
+                        resolvedUrl = window.location.protocol  + wwwFolderPath + resolvedUrl.substr(4);
+                    }
+
+                    if(resolvedUrl.indexOf(':') < 0) {
+                        resolvedUrl = basePath + resolvedUrl; // consider it relative
+                    }
+
+                    console.log('sanitized resolvedUrl = ' + resolvedUrl);
+
+
                     var funk = function () {
                         window.__onXHRLocalCallback = function (responseCode, responseText)
{
                             alias.status = responseCode;
@@ -175,7 +208,7 @@ namespace WPCordovaClassLib.CordovaLib
                             
                         }
                         alias.changeReadyState(XHRShim.LOADING);
-                        window.external.Notify('XHRLOCAL/' + alias._url); 
+                        window.external.Notify('XHRLOCAL/' + resolvedUrl); 
                     }
                     if (this.isAsync) {
                         setTimeout(funk, 0);
@@ -185,16 +218,6 @@ namespace WPCordovaClassLib.CordovaLib
                     }
                 }
             },
-            getContentLocation: function() {
-                if (window.contentLocation === undefined) {
-                    window.contentLocation = navigator.userAgent.toUpperCase().indexOf('MSIE
10') > -1 ? this.contentLocation.RESOURCES : this.contentLocation.ISOLATED_STORAGE;
-                }
-                return window.contentLocation;
-            },
-            contentLocation: {
-                ISOLATED_STORAGE: 0,
-                RESOURCES: 1
-            },
             status: 404
         };
     }
@@ -204,7 +227,7 @@ namespace WPCordovaClassLib.CordovaLib
             Browser.InvokeScript("execScript", new string[] { script });
         }
 
-        public bool HandleCommand(string commandStr) 
+        public bool HandleCommand(string commandStr)
         {
             if (commandStr.IndexOf("XHRLOCAL") == 0)
             {
@@ -222,11 +245,11 @@ namespace WPCordovaClassLib.CordovaLib
                             Browser.InvokeScript("__onXHRLocalCallback", new string[] { "200",
text });
                             return true;
                         }
-                    }       
+                    }
                 }
 
-                Uri relUri = new Uri(uri.AbsolutePath,UriKind.Relative);
-                
+                Uri relUri = new Uri(uri.AbsolutePath, UriKind.Relative);
+
                 var resource = Application.GetResourceStream(relUri);
 
                 if (resource == null)
@@ -235,7 +258,7 @@ namespace WPCordovaClassLib.CordovaLib
                     Browser.InvokeScript("__onXHRLocalCallback", new string[] { "404" });
                     return true;
                 }
-                else 
+                else
                 {
                     using (StreamReader streamReader = new StreamReader(resource.Stream))
                     {

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/84c1395b/wp8/template/cordovalib/XHRHelper.cs
----------------------------------------------------------------------
diff --git a/wp8/template/cordovalib/XHRHelper.cs b/wp8/template/cordovalib/XHRHelper.cs
index 7c2fe10..35b8bd3 100644
--- a/wp8/template/cordovalib/XHRHelper.cs
+++ b/wp8/template/cordovalib/XHRHelper.cs
@@ -16,7 +16,7 @@ namespace WPCordovaClassLib.CordovaLib
         public WebBrowser Browser { get; set; }
         public PhoneApplicationPage Page { get; set; }
 
-        public void InjectScript() 
+        public void InjectScript()
         {
 
 
@@ -111,8 +111,7 @@ namespace WPCordovaClassLib.CordovaLib
                 {
                     this.isAsync = isAsync;
                     this.reqType = reqType;
-                    var newUrl = uri;
-                    this._url = newUrl;
+                    this._url = uri;
                 }
             },
             statusText: '',
@@ -133,6 +132,9 @@ namespace WPCordovaClassLib.CordovaLib
             getAllResponseHeaders: function() {
                 return this.wrappedXHR ? this.wrappedXHR.getAllResponseHeaders() : '';
             },
+            overrideMimeType: function(mimetype) {
+                return this.wrappedXHR ? this.wrappedXHR.overrideMimeType(mimetype) : '';
+            },
             responseText: '',
             responseXML: '',
             onResult: function(res) {
@@ -160,6 +162,37 @@ namespace WPCordovaClassLib.CordovaLib
                 else {
                     this.changeReadyState(XHRShim.OPENED);
                     var alias = this;
+                    var root = window.location.href; 
+                    var basePath = root.substr(0,root.lastIndexOf('/')) + '/';
+                    
+
+                    var resolvedUrl = this._url.split('//').join('/');
+
+                    var wwwFolderPath = navigator.userAgent.indexOf('MSIE 9.0') > -1 ?
'app/www/' : 'www/';
+
+                    console.log('original resolvedUrl = ' + resolvedUrl);
+
+                    if(resolvedUrl.indexOf('/') == 0) {
+                        console.log('removing leading /');
+                        resolvedUrl = resolvedUrl.substr(1);
+                    }
+
+                    if( resolvedUrl.indexOf('app/www') == 0 ) {
+                        
+                        resolvedUrl = window.location.protocol  + wwwFolderPath + resolvedUrl.substr(7);
+                    }
+                    else if( resolvedUrl.indexOf('www') == 0) {
+
+                        resolvedUrl = window.location.protocol  + wwwFolderPath + resolvedUrl.substr(4);
+                    }
+
+                    if(resolvedUrl.indexOf(':') < 0) {
+                        resolvedUrl = basePath + resolvedUrl; // consider it relative
+                    }
+
+                    console.log('sanitized resolvedUrl = ' + resolvedUrl);
+
+
                     var funk = function () {
                         window.__onXHRLocalCallback = function (responseCode, responseText)
{
                             alias.status = responseCode;
@@ -175,7 +208,7 @@ namespace WPCordovaClassLib.CordovaLib
                             
                         }
                         alias.changeReadyState(XHRShim.LOADING);
-                        window.external.Notify('XHRLOCAL/' + alias._url); 
+                        window.external.Notify('XHRLOCAL/' + resolvedUrl); 
                     }
                     if (this.isAsync) {
                         setTimeout(funk, 0);
@@ -185,16 +218,6 @@ namespace WPCordovaClassLib.CordovaLib
                     }
                 }
             },
-            getContentLocation: function() {
-                if (window.contentLocation === undefined) {
-                    window.contentLocation = navigator.userAgent.toUpperCase().indexOf('MSIE
10') > -1 ? this.contentLocation.RESOURCES : this.contentLocation.ISOLATED_STORAGE;
-                }
-                return window.contentLocation;
-            },
-            contentLocation: {
-                ISOLATED_STORAGE: 0,
-                RESOURCES: 1
-            },
             status: 404
         };
     }
@@ -204,7 +227,7 @@ namespace WPCordovaClassLib.CordovaLib
             Browser.InvokeScript("execScript", new string[] { script });
         }
 
-        public bool HandleCommand(string commandStr) 
+        public bool HandleCommand(string commandStr)
         {
             if (commandStr.IndexOf("XHRLOCAL") == 0)
             {
@@ -222,11 +245,11 @@ namespace WPCordovaClassLib.CordovaLib
                             Browser.InvokeScript("__onXHRLocalCallback", new string[] { "200",
text });
                             return true;
                         }
-                    }       
+                    }
                 }
 
-                Uri relUri = new Uri(uri.AbsolutePath,UriKind.Relative);
-                
+                Uri relUri = new Uri(uri.AbsolutePath, UriKind.Relative);
+
                 var resource = Application.GetResourceStream(relUri);
 
                 if (resource == null)
@@ -235,7 +258,7 @@ namespace WPCordovaClassLib.CordovaLib
                     Browser.InvokeScript("__onXHRLocalCallback", new string[] { "404" });
                     return true;
                 }
-                else 
+                else
                 {
                     using (StreamReader streamReader = new StreamReader(resource.Stream))
                     {


Mime
View raw message