You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2013/06/25 02:24:35 UTC

[3/3] git commit: [CB-3993] applied to WP7

[CB-3993] applied to WP7


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

Branch: refs/heads/master
Commit: c6e9b87fcb589a2ebfb29f1307255abd8a65da49
Parents: 1958625
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Mon Jun 24 17:24:14 2013 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Mon Jun 24 17:24:14 2013 -0700

----------------------------------------------------------------------
 wp7/framework/CordovaLib/XHRProxy.cs        | 262 +++++++++++++++++++++++
 wp7/framework/WPCordovaClassLib.csproj      | 197 ++++++++---------
 wp7/template/cordovalib/CordovaView.xaml.cs |   7 +
 wp7/template/cordovalib/NativeExecution.cs  |  23 +-
 wp7/template/cordovalib/XHRProxy.cs         | 262 +++++++++++++++++++++++
 5 files changed, 632 insertions(+), 119 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c6e9b87f/wp7/framework/CordovaLib/XHRProxy.cs
----------------------------------------------------------------------
diff --git a/wp7/framework/CordovaLib/XHRProxy.cs b/wp7/framework/CordovaLib/XHRProxy.cs
new file mode 100644
index 0000000..8a53f0b
--- /dev/null
+++ b/wp7/framework/CordovaLib/XHRProxy.cs
@@ -0,0 +1,262 @@
+using Microsoft.Phone.Controls;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.IO.IsolatedStorage;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace WPCordovaClassLib.CordovaLib
+{
+    public class XHRProxy
+    {
+
+        private WebBrowser webBrowser;
+
+        public XHRProxy(ref WebBrowser browser) 
+        {
+            this.webBrowser = browser;
+            browser.ScriptNotify += browser_ScriptNotify;
+            browser.Navigated += browser_Navigated;
+        }
+
+        void browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
+        {
+
+
+            string script = @"(function(win, doc) {
+
+    var docDomain = null;
+    try {
+        docDomain = doc.domain;
+    } catch (err) {}
+
+    if (!docDomain || docDomain.length === 0) {
+
+        var aliasXHR = win.XMLHttpRequest;
+        
+        var XHRShim = function() {};
+        win.XMLHttpRequest = XHRShim;
+        XHRShim.noConflict = aliasXHR;
+        XHRShim.UNSENT = 0;
+        XHRShim.OPENED = 1;
+        XHRShim.HEADERS_RECEIVED = 2;
+        XHRShim.LOADING = 3;
+        XHRShim.DONE = 4;
+        XHRShim.prototype = {
+            isAsync: false,
+            onreadystatechange: null,
+            readyState: 0,
+            _url: '',
+            timeout: 0,
+            withCredentials: false,
+            _requestHeaders: null,
+            open: function (reqType, uri, isAsync, user, password) {
+                
+                if (uri && uri.indexOf('http') === 0) {
+                    if (!this.wrappedXHR) {
+                        this.wrappedXHR = new aliasXHR();
+                        var self = this;
+                        if (this.timeout > 0) {
+                            this.wrappedXHR.timeout = this.timeout;
+                        }
+                        Object.defineProperty(this, 'timeout', {
+                            set: function(val) {
+                                this.wrappedXHR.timeout = val;
+                            },
+                            get: function() {
+                                return this.wrappedXHR.timeout;
+                            }
+                        });
+                        if (this.withCredentials) {
+                            this.wrappedXHR.withCredentials = this.withCredentials;
+                        }
+                        Object.defineProperty(this, 'withCredentials', {
+                            set: function(val) {
+                                this.wrappedXHR.withCredentials = val;
+                            },
+                            get: function() {
+                                return this.wrappedXHR.withCredentials;
+                            }
+                        });
+                        Object.defineProperty(this, 'status', {
+                            get: function() {
+                                return this.wrappedXHR.status;
+                            }
+                        });
+                        Object.defineProperty(this, 'responseText', {
+                            get: function() {
+                                return this.wrappedXHR.responseText;
+                            }
+                        });
+                        Object.defineProperty(this, 'statusText', {
+                            get: function() {
+                                return this.wrappedXHR.statusText;
+                            }
+                        });
+                        Object.defineProperty(this, 'responseXML', {
+                            get: function() {
+                                return this.wrappedXHR.responseXML;
+                            }
+                        });
+                        this.getResponseHeader = function(header) {
+                            return this.wrappedXHR.getResponseHeader(header);
+                        };
+                        this.getAllResponseHeaders = function() {
+                            return this.wrappedXHR.getAllResponseHeaders();
+                        };
+                        this.wrappedXHR.onreadystatechange = function() {
+                            self.changeReadyState(self.wrappedXHR.readyState);
+                        };
+                    }
+                    return this.wrappedXHR.open(reqType, uri, isAsync, user, password);
+                }
+                else
+                {
+                    this.isAsync = isAsync;
+                    this.reqType = reqType;
+                    var newUrl = uri;
+                    this._url = newUrl;
+                }
+            },
+            statusText: '',
+            changeReadyState: function(newState) {
+                this.readyState = newState;
+                if (this.onreadystatechange) {
+                    this.onreadystatechange();
+                }
+            },
+            setRequestHeader: function(header, value) {
+                if (this.wrappedXHR) {
+                    this.wrappedXHR.setRequestHeader(header, value);
+                }
+            },
+            getResponseHeader: function(header) {
+                return this.wrappedXHR ? this.wrappedXHR.getResponseHeader(header) : '';
+            },
+            getAllResponseHeaders: function() {
+                return this.wrappedXHR ? this.wrappedXHR.getAllResponseHeaders() : '';
+            },
+            responseText: '',
+            responseXML: '',
+            onResult: function(res) {
+                this.status = 200;
+                if (typeof res == 'object') {
+                    res = JSON.stringify(res);
+                }
+                this.responseText = res;
+                this.responseXML = res;
+                this.changeReadyState(XHRShim.DONE);
+            },
+            onError: function(err) {
+                this.status = 404;
+                this.changeReadyState(XHRShim.DONE);
+            },
+            abort: function() {
+                if (this.wrappedXHR) {
+                    return this.wrappedXHR.abort();
+                }
+            },
+            send: function(data) {
+                if (this.wrappedXHR) {
+                    return this.wrappedXHR.send(data);
+                } 
+                else {
+                    this.changeReadyState(XHRShim.OPENED);
+                    var alias = this;
+                    var funk = function () {
+                        window.__onXHRLocalCallback = function (responseCode, responseText) {
+                            alias.status = responseCode;
+                            if (responseCode == '200') {
+                                alias.responseText = responseText;
+                            }
+                            else {
+                                alias.onerror && alias.onerror(responseCode);
+                            }
+
+                            alias.changeReadyState(XHRShim.DONE);
+                            alias.onload && alias.onload();
+                            
+                        }
+                        alias.changeReadyState(XHRShim.LOADING);
+                        window.external.Notify('XHRLOCAL/' + alias._url); 
+                    }
+                    if (this.isAsync) {
+                        setTimeout(funk, 0);
+                    }
+                    else {
+                        funk();
+                    }
+                }
+            },
+            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
+        };
+    }
+})(window, document); ";
+
+
+            webBrowser.InvokeScript("execScript", new string[] { script });
+
+
+        }
+
+        void browser_ScriptNotify(object sender, NotifyEventArgs e)
+        {
+            Debug.WriteLine("ScriptNotify::" + e.Value);
+            string commandStr = e.Value;
+
+            if (commandStr.IndexOf("XHRLOCAL") == 0)
+            {
+                string url = commandStr.Replace("XHRLOCAL/", "");
+
+                Uri uri = new Uri(url, UriKind.RelativeOrAbsolute);
+
+                using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
+                {
+                    if (isoFile.FileExists(uri.AbsolutePath))
+                    {
+                        using (TextReader reader = new StreamReader(isoFile.OpenFile(uri.AbsolutePath, FileMode.Open, FileAccess.Read)))
+                        {
+                            string text = reader.ReadToEnd();
+                            webBrowser.InvokeScript("__onXHRLocalCallback", new string[] { "200", text });
+                            return;
+                        }
+                    }       
+                }
+
+                Uri relUri = new Uri(uri.AbsolutePath,UriKind.Relative);
+                
+                var resource = Application.GetResourceStream(relUri);
+
+                if (resource == null)
+                {
+                    // 404 ? 
+                    webBrowser.InvokeScript("__onXHRLocalCallback", new string[] { "404" });
+                    return;
+                }
+                else 
+                {
+                    using (StreamReader streamReader = new StreamReader(resource.Stream))
+                    {
+                        string text = streamReader.ReadToEnd();
+                        webBrowser.InvokeScript("__onXHRLocalCallback", new string[] { "200", text });
+                        return;
+                    }
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c6e9b87f/wp7/framework/WPCordovaClassLib.csproj
----------------------------------------------------------------------
diff --git a/wp7/framework/WPCordovaClassLib.csproj b/wp7/framework/WPCordovaClassLib.csproj
index b8f76ae..9676f56 100644
--- a/wp7/framework/WPCordovaClassLib.csproj
+++ b/wp7/framework/WPCordovaClassLib.csproj
@@ -80,145 +80,126 @@
     <Reference Include="System.Xml.Linq" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="..\templates\standalone\cordovalib\BaseCommand.cs">
-      <Link>CordovaLib\BaseCommand.cs</Link>
+    <Compile Include="..\..\common\Plugins\Accelerometer.cs">
+      <Link>Plugins\Accelerometer.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\cordovalib\BrowserMouseHelper.cs">
-      <Link>CordovaLib\BrowserMouseHelper.cs</Link>
+    <Compile Include="..\..\common\Plugins\AudioFormatsHelper.cs">
+      <Link>Plugins\AudioFormatsHelper.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\cordovalib\CommandFactory.cs">
-      <Link>CordovaLib\CommandFactory.cs</Link>
+    <Compile Include="..\..\common\Plugins\AudioPlayer.cs">
+      <Link>Plugins\AudioPlayer.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\cordovalib\ConfigHandler.cs">
-      <Link>CordovaLib\ConfigHandler.cs</Link>
+    <Compile Include="..\..\common\Plugins\Battery.cs">
+      <Link>Plugins\Battery.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\cordovalib\CordovaCommandCall.cs">
-      <Link>CordovaLib\CordovaCommandCall.cs</Link>
+    <Compile Include="..\..\common\Plugins\Camera.cs">
+      <Link>Plugins\Camera.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\cordovalib\CordovaView.xaml.cs">
-      <Link>CordovaLib\CordovaView.xaml.cs</Link>
-      <DependentUpon>CordovaView.xaml</DependentUpon>
+    <Compile Include="..\..\common\Plugins\Capture.cs">
+      <Link>Plugins\Capture.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\cordovalib\DOMStorageHelper.cs">
-      <Link>CordovaLib\DOMStorageHelper.cs</Link>
+    <Compile Include="..\..\common\Plugins\Compass.cs">
+      <Link>Plugins\Compass.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\cordovalib\ImageExifHelper.cs">
-      <Link>CordovaLib\ImageExifHelper.cs</Link>
+    <Compile Include="..\..\common\Plugins\Contacts.cs">
+      <Link>Plugins\Contacts.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\cordovalib\JSON\JsonHelper.cs">
-      <Link>CordovaLib\JSON\JsonHelper.cs</Link>
+    <Compile Include="..\..\common\Plugins\DebugConsole.cs">
+      <Link>Plugins\DebugConsole.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\cordovalib\NativeExecution.cs">
-      <Link>CordovaLib\NativeExecution.cs</Link>
+    <Compile Include="..\..\common\Plugins\Device.cs">
+      <Link>Plugins\Device.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\cordovalib\OrientationHelper.cs">
-      <Link>CordovaLib\OrientationHelper.cs</Link>
+    <Compile Include="..\..\common\Plugins\File.cs">
+      <Link>Plugins\File.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\cordovalib\PluginResult.cs">
-      <Link>CordovaLib\PluginResult.cs</Link>
+    <Compile Include="..\..\common\Plugins\FileTransfer.cs">
+      <Link>Plugins\FileTransfer.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\cordovalib\ScriptCallback.cs">
-      <Link>CordovaLib\ScriptCallback.cs</Link>
+    <Compile Include="..\..\common\Plugins\GeoLocation.cs">
+      <Link>Plugins\GeoLocation.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\Accelerometer.cs">
-      <Link>CordovaLib\Plugins\Accelerometer.cs</Link>
+    <Compile Include="..\..\common\Plugins\Globalization.cs">
+      <Link>Plugins\Globalization.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\AudioFormatsHelper.cs">
-      <Link>CordovaLib\Plugins\AudioFormatsHelper.cs</Link>
+    <Compile Include="..\..\common\Plugins\InAppBrowser.cs">
+      <Link>Plugins\InAppBrowser.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\AudioPlayer.cs">
-      <Link>CordovaLib\Plugins\AudioPlayer.cs</Link>
+    <Compile Include="..\..\common\Plugins\Media.cs">
+      <Link>Plugins\Media.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\Battery.cs">
-      <Link>CordovaLib\Plugins\Battery.cs</Link>
+    <Compile Include="..\..\common\Plugins\MimeTypeMapper.cs">
+      <Link>Plugins\MimeTypeMapper.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\Camera.cs">
-      <Link>CordovaLib\Plugins\Camera.cs</Link>
+    <Compile Include="..\..\common\Plugins\NetworkStatus.cs">
+      <Link>Plugins\NetworkStatus.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\Capture.cs">
-      <Link>CordovaLib\Plugins\Capture.cs</Link>
+    <Compile Include="..\..\common\Plugins\Notification.cs">
+      <Link>Plugins\Notification.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\Compass.cs">
-      <Link>CordovaLib\Plugins\Compass.cs</Link>
+    <Compile Include="..\..\common\Plugins\UI\AudioCaptureTask.cs">
+      <Link>Plugins\UI\AudioCaptureTask.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\Contacts.cs">
-      <Link>CordovaLib\Plugins\Contacts.cs</Link>
+    <Compile Include="..\..\common\Plugins\UI\AudioRecorder.xaml.cs">
+      <Link>Plugins\UI\AudioRecorder.xaml.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\DebugConsole.cs">
-      <Link>CordovaLib\Plugins\DebugConsole.cs</Link>
+    <Compile Include="..\..\common\Plugins\UI\ImageCapture.xaml.cs">
+      <Link>Plugins\UI\ImageCapture.xaml.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\Device.cs">
-      <Link>CordovaLib\Plugins\Device.cs</Link>
+    <Compile Include="..\..\common\Plugins\UI\NotificationBox.xaml.cs">
+      <Link>Plugins\UI\NotificationBox.xaml.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\File.cs">
-      <Link>CordovaLib\Plugins\File.cs</Link>
+    <Compile Include="..\..\common\Plugins\UI\VideoCaptureTask.cs">
+      <Link>Plugins\UI\VideoCaptureTask.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\FileTransfer.cs">
-      <Link>CordovaLib\Plugins\FileTransfer.cs</Link>
+    <Compile Include="..\..\common\Plugins\UI\VideoRecorder.xaml.cs">
+      <Link>Plugins\UI\VideoRecorder.xaml.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\GeoLocation.cs">
-      <Link>CordovaLib\Plugins\GeoLocation.cs</Link>
+    <Compile Include="..\..\wp8\template\cordovalib\XHRProxy.cs">
+      <Link>CordovaLib\XHRProxy.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\Globalization.cs">
-      <Link>CordovaLib\Plugins\Globalization.cs</Link>
+    <Compile Include="..\template\cordovalib\BaseCommand.cs">
+      <Link>CordovaLib\BaseCommand.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\InAppBrowser.cs">
-      <Link>CordovaLib\Plugins\InAppBrowser.cs</Link>
+    <Compile Include="..\template\cordovalib\BrowserMouseHelper.cs">
+      <Link>CordovaLib\BrowserMouseHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\template\cordovalib\CommandFactory.cs">
+      <Link>CordovaLib\CommandFactory.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\Media.cs">
-      <Link>CordovaLib\Plugins\Media.cs</Link>
+    <Compile Include="..\template\cordovalib\ConfigHandler.cs">
+      <Link>CordovaLib\ConfigHandler.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\MimeTypeMapper.cs">
-      <Link>CordovaLib\Plugins\MimeTypeMapper.cs</Link>
+    <Compile Include="..\template\cordovalib\CordovaCommandCall.cs">
+      <Link>CordovaLib\CordovaCommandCall.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\NetworkStatus.cs">
-      <Link>CordovaLib\Plugins\NetworkStatus.cs</Link>
+    <Compile Include="..\template\cordovalib\CordovaView.xaml.cs">
+      <Link>CordovaLib\CordovaView.xaml.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\Notification.cs">
-      <Link>CordovaLib\Plugins\Notification.cs</Link>
+    <Compile Include="..\template\cordovalib\DOMStorageHelper.cs">
+      <Link>CordovaLib\DOMStorageHelper.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\UI\AudioCaptureTask.cs">
-      <Link>CordovaLib\Plugins\UI\AudioCaptureTask.cs</Link>
+    <Compile Include="..\template\cordovalib\ImageExifHelper.cs">
+      <Link>CordovaLib\ImageExifHelper.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\UI\AudioRecorder.xaml.cs">
-      <Link>CordovaLib\Plugins\UI\AudioRecorder.xaml.cs</Link>
+    <Compile Include="..\template\cordovalib\JSON\JsonHelper.cs">
+      <Link>CordovaLib\JSON\JsonHelper.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\UI\ImageCapture.xaml.cs">
-      <Link>CordovaLib\Plugins\UI\ImageCapture.xaml.cs</Link>
+    <Compile Include="..\template\cordovalib\NativeExecution.cs">
+      <Link>CordovaLib\NativeExecution.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\UI\NotificationBox.xaml.cs">
-      <Link>CordovaLib\Plugins\UI\NotificationBox.xaml.cs</Link>
+    <Compile Include="..\template\cordovalib\OrientationHelper.cs">
+      <Link>CordovaLib\OrientationHelper.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\UI\VideoCaptureTask.cs">
-      <Link>CordovaLib\Plugins\UI\VideoCaptureTask.cs</Link>
+    <Compile Include="..\template\cordovalib\PluginResult.cs">
+      <Link>CordovaLib\PluginResult.cs</Link>
     </Compile>
-    <Compile Include="..\templates\standalone\Plugins\UI\VideoRecorder.xaml.cs">
-      <Link>CordovaLib\Plugins\UI\VideoRecorder.xaml.cs</Link>
+    <Compile Include="..\template\cordovalib\ScriptCallback.cs">
+      <Link>CordovaLib\ScriptCallback.cs</Link>
     </Compile>
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
-    <Content Include="..\templates\standalone\cordovalib\resources\notification-beep.wav">
-      <Link>CordovaLib\resources\notification-beep.wav</Link>
-    </Content>
-    <Content Include="..\templates\standalone\Images\appbar.back.rest.png">
-      <Link>CordovaLib\Images\appbar.back.rest.png</Link>
-    </Content>
-    <Content Include="..\templates\standalone\Images\appbar.close.rest.png">
-      <Link>CordovaLib\Images\appbar.close.rest.png</Link>
-    </Content>
-    <Content Include="..\templates\standalone\Images\appbar.feature.video.rest.png">
-      <Link>CordovaLib\Images\appbar.feature.video.rest.png</Link>
-    </Content>
-    <Content Include="..\templates\standalone\Images\appbar.next.rest.png">
-      <Link>CordovaLib\Images\appbar.next.rest.png</Link>
-    </Content>
-    <Content Include="..\templates\standalone\Images\appbar.save.rest.png">
-      <Link>CordovaLib\Images\appbar.save.rest.png</Link>
-    </Content>
-    <Content Include="..\templates\standalone\Images\appbar.stop.rest.png">
-      <Link>CordovaLib\Images\appbar.stop.rest.png</Link>
-    </Content>
     <Content Include="Images\appbar.back.rest.png">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </Content>
@@ -245,28 +226,28 @@
     <Resource Include="resources\notification-beep.wav" />
   </ItemGroup>
   <ItemGroup>
-    <Page Include="..\templates\standalone\cordovalib\CordovaView.xaml">
-      <Link>CordovaLib\CordovaView.xaml</Link>
+    <Page Include="..\..\common\Plugins\UI\AudioRecorder.xaml">
+      <Link>Plugins\UI\AudioRecorder.xaml</Link>
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
-    <Page Include="..\templates\standalone\Plugins\UI\AudioRecorder.xaml">
-      <Link>CordovaLib\Plugins\UI\AudioRecorder.xaml</Link>
+    <Page Include="..\..\common\Plugins\UI\ImageCapture.xaml">
+      <Link>Plugins\UI\ImageCapture.xaml</Link>
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
-    <Page Include="..\templates\standalone\Plugins\UI\ImageCapture.xaml">
-      <Link>CordovaLib\Plugins\UI\ImageCapture.xaml</Link>
+    <Page Include="..\..\common\Plugins\UI\NotificationBox.xaml">
+      <Link>Plugins\UI\NotificationBox.xaml</Link>
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
-    <Page Include="..\templates\standalone\Plugins\UI\NotificationBox.xaml">
-      <Link>CordovaLib\Plugins\UI\NotificationBox.xaml</Link>
+    <Page Include="..\..\common\Plugins\UI\VideoRecorder.xaml">
+      <Link>Plugins\UI\VideoRecorder.xaml</Link>
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
-    <Page Include="..\templates\standalone\Plugins\UI\VideoRecorder.xaml">
-      <Link>CordovaLib\Plugins\UI\VideoRecorder.xaml</Link>
+    <Page Include="..\template\cordovalib\CordovaView.xaml">
+      <Link>CordovaLib\CordovaView.xaml</Link>
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c6e9b87f/wp7/template/cordovalib/CordovaView.xaml.cs
----------------------------------------------------------------------
diff --git a/wp7/template/cordovalib/CordovaView.xaml.cs b/wp7/template/cordovalib/CordovaView.xaml.cs
index fc9eaa1..1180776 100644
--- a/wp7/template/cordovalib/CordovaView.xaml.cs
+++ b/wp7/template/cordovalib/CordovaView.xaml.cs
@@ -77,6 +77,7 @@ namespace WPCordovaClassLib
 
         protected DOMStorageHelper domStorageHelper;
         protected OrientationHelper orientationHelper;
+        protected XHRProxy xhrProxy;
 
         private ConfigHandler configHandler;
 
@@ -167,6 +168,7 @@ namespace WPCordovaClassLib
             // initializes native execution logic
             nativeExecution = new NativeExecution(ref this.CordovaBrowser);
             bmHelper = new BrowserMouseHelper(ref this.CordovaBrowser);
+            xhrProxy = new XHRProxy(ref this.CordovaBrowser);
         }
 
 
@@ -433,6 +435,11 @@ namespace WPCordovaClassLib
                 this.orientationHelper.HandleCommand(commandStr);
                 return;
             }
+            else if (commandStr.IndexOf("XHRLOCAL") == 0)
+            {
+                // XHRProxy listens for this itself
+                return;
+            }
 
             CordovaCommandCall commandCallParams = CordovaCommandCall.Parse(commandStr);
 

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c6e9b87f/wp7/template/cordovalib/NativeExecution.cs
----------------------------------------------------------------------
diff --git a/wp7/template/cordovalib/NativeExecution.cs b/wp7/template/cordovalib/NativeExecution.cs
index af6b207..decc51d 100644
--- a/wp7/template/cordovalib/NativeExecution.cs
+++ b/wp7/template/cordovalib/NativeExecution.cs
@@ -133,17 +133,18 @@ namespace WPCordovaClassLib.Cordova
                     }
                 };
 
-                if ((bc is File) || (bc is Accelerometer))
-                {
-                    // Due to some issues with the IsolatedStorage in current version of WP8 SDK we have to run all File Api commands synchronously.
-                    // TODO: test this in WP8 RTM
-                    methodInvokation.Invoke();
-                }
-                else
-                {
-                    new Thread(methodInvokation).Start();
-                }
-
+                //if ((bc is File) || (bc is Accelerometer))
+                //{
+                //    // Due to some issues with the IsolatedStorage in current version of WP8 SDK we have to run all File Api commands synchronously.
+                //    // TODO: test this in WP8 RTM
+                //    methodInvokation.Invoke();
+                //}
+                //else
+                //{
+                //    new Thread(methodInvokation).Start();
+                //}
+
+                new Thread(methodInvokation).Start();
 
             }
             catch (Exception ex)

http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c6e9b87f/wp7/template/cordovalib/XHRProxy.cs
----------------------------------------------------------------------
diff --git a/wp7/template/cordovalib/XHRProxy.cs b/wp7/template/cordovalib/XHRProxy.cs
new file mode 100644
index 0000000..8a53f0b
--- /dev/null
+++ b/wp7/template/cordovalib/XHRProxy.cs
@@ -0,0 +1,262 @@
+using Microsoft.Phone.Controls;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.IO.IsolatedStorage;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace WPCordovaClassLib.CordovaLib
+{
+    public class XHRProxy
+    {
+
+        private WebBrowser webBrowser;
+
+        public XHRProxy(ref WebBrowser browser) 
+        {
+            this.webBrowser = browser;
+            browser.ScriptNotify += browser_ScriptNotify;
+            browser.Navigated += browser_Navigated;
+        }
+
+        void browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
+        {
+
+
+            string script = @"(function(win, doc) {
+
+    var docDomain = null;
+    try {
+        docDomain = doc.domain;
+    } catch (err) {}
+
+    if (!docDomain || docDomain.length === 0) {
+
+        var aliasXHR = win.XMLHttpRequest;
+        
+        var XHRShim = function() {};
+        win.XMLHttpRequest = XHRShim;
+        XHRShim.noConflict = aliasXHR;
+        XHRShim.UNSENT = 0;
+        XHRShim.OPENED = 1;
+        XHRShim.HEADERS_RECEIVED = 2;
+        XHRShim.LOADING = 3;
+        XHRShim.DONE = 4;
+        XHRShim.prototype = {
+            isAsync: false,
+            onreadystatechange: null,
+            readyState: 0,
+            _url: '',
+            timeout: 0,
+            withCredentials: false,
+            _requestHeaders: null,
+            open: function (reqType, uri, isAsync, user, password) {
+                
+                if (uri && uri.indexOf('http') === 0) {
+                    if (!this.wrappedXHR) {
+                        this.wrappedXHR = new aliasXHR();
+                        var self = this;
+                        if (this.timeout > 0) {
+                            this.wrappedXHR.timeout = this.timeout;
+                        }
+                        Object.defineProperty(this, 'timeout', {
+                            set: function(val) {
+                                this.wrappedXHR.timeout = val;
+                            },
+                            get: function() {
+                                return this.wrappedXHR.timeout;
+                            }
+                        });
+                        if (this.withCredentials) {
+                            this.wrappedXHR.withCredentials = this.withCredentials;
+                        }
+                        Object.defineProperty(this, 'withCredentials', {
+                            set: function(val) {
+                                this.wrappedXHR.withCredentials = val;
+                            },
+                            get: function() {
+                                return this.wrappedXHR.withCredentials;
+                            }
+                        });
+                        Object.defineProperty(this, 'status', {
+                            get: function() {
+                                return this.wrappedXHR.status;
+                            }
+                        });
+                        Object.defineProperty(this, 'responseText', {
+                            get: function() {
+                                return this.wrappedXHR.responseText;
+                            }
+                        });
+                        Object.defineProperty(this, 'statusText', {
+                            get: function() {
+                                return this.wrappedXHR.statusText;
+                            }
+                        });
+                        Object.defineProperty(this, 'responseXML', {
+                            get: function() {
+                                return this.wrappedXHR.responseXML;
+                            }
+                        });
+                        this.getResponseHeader = function(header) {
+                            return this.wrappedXHR.getResponseHeader(header);
+                        };
+                        this.getAllResponseHeaders = function() {
+                            return this.wrappedXHR.getAllResponseHeaders();
+                        };
+                        this.wrappedXHR.onreadystatechange = function() {
+                            self.changeReadyState(self.wrappedXHR.readyState);
+                        };
+                    }
+                    return this.wrappedXHR.open(reqType, uri, isAsync, user, password);
+                }
+                else
+                {
+                    this.isAsync = isAsync;
+                    this.reqType = reqType;
+                    var newUrl = uri;
+                    this._url = newUrl;
+                }
+            },
+            statusText: '',
+            changeReadyState: function(newState) {
+                this.readyState = newState;
+                if (this.onreadystatechange) {
+                    this.onreadystatechange();
+                }
+            },
+            setRequestHeader: function(header, value) {
+                if (this.wrappedXHR) {
+                    this.wrappedXHR.setRequestHeader(header, value);
+                }
+            },
+            getResponseHeader: function(header) {
+                return this.wrappedXHR ? this.wrappedXHR.getResponseHeader(header) : '';
+            },
+            getAllResponseHeaders: function() {
+                return this.wrappedXHR ? this.wrappedXHR.getAllResponseHeaders() : '';
+            },
+            responseText: '',
+            responseXML: '',
+            onResult: function(res) {
+                this.status = 200;
+                if (typeof res == 'object') {
+                    res = JSON.stringify(res);
+                }
+                this.responseText = res;
+                this.responseXML = res;
+                this.changeReadyState(XHRShim.DONE);
+            },
+            onError: function(err) {
+                this.status = 404;
+                this.changeReadyState(XHRShim.DONE);
+            },
+            abort: function() {
+                if (this.wrappedXHR) {
+                    return this.wrappedXHR.abort();
+                }
+            },
+            send: function(data) {
+                if (this.wrappedXHR) {
+                    return this.wrappedXHR.send(data);
+                } 
+                else {
+                    this.changeReadyState(XHRShim.OPENED);
+                    var alias = this;
+                    var funk = function () {
+                        window.__onXHRLocalCallback = function (responseCode, responseText) {
+                            alias.status = responseCode;
+                            if (responseCode == '200') {
+                                alias.responseText = responseText;
+                            }
+                            else {
+                                alias.onerror && alias.onerror(responseCode);
+                            }
+
+                            alias.changeReadyState(XHRShim.DONE);
+                            alias.onload && alias.onload();
+                            
+                        }
+                        alias.changeReadyState(XHRShim.LOADING);
+                        window.external.Notify('XHRLOCAL/' + alias._url); 
+                    }
+                    if (this.isAsync) {
+                        setTimeout(funk, 0);
+                    }
+                    else {
+                        funk();
+                    }
+                }
+            },
+            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
+        };
+    }
+})(window, document); ";
+
+
+            webBrowser.InvokeScript("execScript", new string[] { script });
+
+
+        }
+
+        void browser_ScriptNotify(object sender, NotifyEventArgs e)
+        {
+            Debug.WriteLine("ScriptNotify::" + e.Value);
+            string commandStr = e.Value;
+
+            if (commandStr.IndexOf("XHRLOCAL") == 0)
+            {
+                string url = commandStr.Replace("XHRLOCAL/", "");
+
+                Uri uri = new Uri(url, UriKind.RelativeOrAbsolute);
+
+                using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
+                {
+                    if (isoFile.FileExists(uri.AbsolutePath))
+                    {
+                        using (TextReader reader = new StreamReader(isoFile.OpenFile(uri.AbsolutePath, FileMode.Open, FileAccess.Read)))
+                        {
+                            string text = reader.ReadToEnd();
+                            webBrowser.InvokeScript("__onXHRLocalCallback", new string[] { "200", text });
+                            return;
+                        }
+                    }       
+                }
+
+                Uri relUri = new Uri(uri.AbsolutePath,UriKind.Relative);
+                
+                var resource = Application.GetResourceStream(relUri);
+
+                if (resource == null)
+                {
+                    // 404 ? 
+                    webBrowser.InvokeScript("__onXHRLocalCallback", new string[] { "404" });
+                    return;
+                }
+                else 
+                {
+                    using (StreamReader streamReader = new StreamReader(resource.Stream))
+                    {
+                        string text = streamReader.ReadToEnd();
+                        webBrowser.InvokeScript("__onXHRLocalCallback", new string[] { "200", text });
+                        return;
+                    }
+                }
+            }
+        }
+    }
+}