You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/06/19 23:21:11 UTC

[1/3] js commit: Testing non-xhr loader with Fil

Updated Branches:
  refs/heads/2.9.x 11df4b7cb -> e2020c3c4
Updated Tags:  refs/tags/2.9.0rc1 11df4b7cb -> e2020c3c4


Testing non-xhr loader with Fil


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

Branch: refs/heads/2.9.x
Commit: ce87a15b4161197348ebbb2284885d922e764c31
Parents: 11df4b7
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri May 17 17:35:46 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Jun 19 14:20:32 2013 -0700

----------------------------------------------------------------------
 lib/scripts/plugin_loader.js | 57 +++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/ce87a15b/lib/scripts/plugin_loader.js
----------------------------------------------------------------------
diff --git a/lib/scripts/plugin_loader.js b/lib/scripts/plugin_loader.js
index 892bd76..1a38eda 100644
--- a/lib/scripts/plugin_loader.js
+++ b/lib/scripts/plugin_loader.js
@@ -103,30 +103,41 @@
             break;
         }
     }
-    // Try to XHR the cordova_plugins.json file asynchronously.
-    var xhr = new XMLHttpRequest();
-    xhr.onload = function() {
-        // If the response is a JSON string which composes an array, call handlePluginsObject.
-        // If the request fails, or the response is not a JSON array, just call finishPluginLoading.
-        var obj;
-        try {
-            obj = (this.status == 0 || this.status == 200) && this.responseText && JSON.parse(this.responseText);
-        } catch (err) {
-            // obj will be undefined.
-        }
-        if (Array.isArray(obj) && obj.length > 0) {
-            handlePluginsObject(obj, path);
-        } else {
-            finishPluginLoading();
-        }
-    };
-    xhr.onerror = function() {
-        finishPluginLoading();
-    };
-    var plugins_json = path + 'cordova_plugins.json';
+
+    // // Try to XHR the cordova_plugins.json file asynchronously.
+    // var xhr = new XMLHttpRequest();
+    // xhr.onload = function() {
+    //     // If the response is a JSON string which composes an array, call handlePluginsObject.
+    //     // If the request fails, or the response is not a JSON array, just call finishPluginLoading.
+    //     var obj;
+    //     try {
+    //         obj = (this.status == 0 || this.status == 200) && this.responseText && JSON.parse(this.responseText);
+    //     } catch (err) {
+    //         // obj will be undefined.
+    //     }
+    //     if (Array.isArray(obj) && obj.length > 0) {
+    //         handlePluginsObject(obj, path);
+    //     } else {
+    //         finishPluginLoading();
+    //     }
+    // };
+    // xhr.onerror = function() {
+    //     finishPluginLoading();
+    // };
+
+    var plugins_js = path + 'cordova_plugins.js';
     try { // we commented we were going to try, so let us actually try and catch
-        xhr.open('GET', plugins_json, true); // Async
-        xhr.send();
+        //xhr.open('GET', plugins_json, true); // Async
+        //xhr.send();
+        var script = document.createElement("script");
+        script.onload = function(){
+            var list = cordova.require("cordova/plugin_list");
+            handlePluginsObject(list,path);
+
+        };
+        script.src = plugins_js;
+        document.head.appendChild(script);
+
     } catch(err){
         finishPluginLoading();
     }


[3/3] js commit: Combine XHR + script injection technqieues to load the plugins list (either .json or .js file).

Posted by fi...@apache.org.
Combine XHR + script injection technqieues to load the plugins list (either .json or .js file).


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

Branch: refs/heads/2.9.x
Commit: e2020c3c453e12ad021937b82ba530f7a9dd4199
Parents: 3d85be0
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Jun 19 13:39:40 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Jun 19 14:20:45 2013 -0700

----------------------------------------------------------------------
 lib/scripts/plugin_loader.js | 58 +++++++++++++++++++++++++++++----------
 1 file changed, 43 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/e2020c3c/lib/scripts/plugin_loader.js
----------------------------------------------------------------------
diff --git a/lib/scripts/plugin_loader.js b/lib/scripts/plugin_loader.js
index b56f124..b27216b 100644
--- a/lib/scripts/plugin_loader.js
+++ b/lib/scripts/plugin_loader.js
@@ -119,24 +119,52 @@
         }
     }
 
+    var plugins_json = path + 'cordova_plugins.json';
     var plugins_js = path + 'cordova_plugins.js';
-    try {
-        
-        var script = document.createElement("script");
-        script.onload = function(){
-            var list = cordova.require("cordova/plugin_list");
-            handlePluginsObject(list,path);
-        };
-        script.onerror = function() {
-            // Error loading cordova_plugins.js, file not found or something
-            // this is an acceptable error, pre-3.0.0, so we just move on.
+    // Try to XHR the cordova_plugins.json file asynchronously.
+    var xhr = new XMLHttpRequest();
+    xhr.onload = function() {
+        // If the response is a JSON string which composes an array, call handlePluginsObject.
+        // If the request fails, or the response is not a JSON array, just call finishPluginLoading.
+        var obj;
+        try {
+            obj = (this.status == 0 || this.status == 200) && this.responseText && JSON.parse(this.responseText);
+        } catch (err) {
+            // obj will be undefined.
+        }
+        if (Array.isArray(obj) && obj.length > 0) {
+            handlePluginsObject(obj, path);
+        } else {
             finishPluginLoading();
-        };
-        script.src = plugins_js;
-        document.head.appendChild(script);
-
-    } catch(err){
+        }
+    };
+    xhr.onerror = function() {
         finishPluginLoading();
+    };
+    try { // we commented we were going to try, so let us actually try and catch
+        xhr.open('GET', plugins_json, true); // Async
+        xhr.send();
+    } catch(err){
+        // One some phones (Windows) this xhr.open throws an Access Denied exception
+        // So lets keep trying, but with a script tag injection technique instead of XHR
+        try {
+            
+            var script = document.createElement("script");
+            script.onload = function(){
+                var list = cordova.require("cordova/plugin_list");
+                handlePluginsObject(list,path);
+            };
+            script.onerror = function() {
+                // Error loading cordova_plugins.js, file not found or something
+                // this is an acceptable error, pre-3.0.0, so we just move on.
+                finishPluginLoading();
+            };
+            script.src = plugins_js;
+            document.head.appendChild(script);
+
+        } catch(err){
+            finishPluginLoading();
+        }
     }
 }(window));
 


[2/3] js commit: more robust error handling.

Posted by fi...@apache.org.
more robust error handling.


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

Branch: refs/heads/2.9.x
Commit: 3d85be06501e107cadca7e1d4ea555fa632436f7
Parents: ce87a15
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue May 21 18:14:57 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Jun 19 14:20:39 2013 -0700

----------------------------------------------------------------------
 lib/scripts/plugin_loader.js | 85 +++++++++++++++++++--------------------
 1 file changed, 41 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-js/blob/3d85be06/lib/scripts/plugin_loader.js
----------------------------------------------------------------------
diff --git a/lib/scripts/plugin_loader.js b/lib/scripts/plugin_loader.js
index 1a38eda..b56f124 100644
--- a/lib/scripts/plugin_loader.js
+++ b/lib/scripts/plugin_loader.js
@@ -34,11 +34,21 @@
         }
     }
 
+    function scriptErrorCallback(err) {
+        // Open Question: If a script path specified in cordova_plugins.js does not exist, do we fail for all?
+        // this is currently just continuing.
+        scriptCounter--;
+        if (scriptCounter === 0) {
+            onScriptLoadingComplete && onScriptLoadingComplete();
+        }
+    }
+
     // Helper function to inject a <script> tag.
     function injectScript(path) {
         scriptCounter++;
         var script = document.createElement("script");
         script.onload = scriptLoadedCallback;
+        script.onerror = scriptErrorCallback;
         script.src = path;
         document.head.appendChild(script);
     }
@@ -50,10 +60,10 @@
         context.cordova.require('cordova/channel').onPluginsReady.fire();
     }
 
-    // Handler for the cordova_plugins.json content.
+    // Handler for the cordova_plugins.js content.
     // See plugman's plugin_loader.js for the details of this object.
     // This function is only called if the really is a plugins array that isn't empty.
-    // Otherwise the XHR response handler will just call finishPluginLoading().
+    // Otherwise the onerror response handler will just call finishPluginLoading().
     function handlePluginsObject(modules, path) {
         // First create the callback for when all plugins are loaded.
         var mapper = context.cordova.require('cordova/modulemapper');
@@ -61,26 +71,31 @@
             // Loop through all the plugins and then through their clobbers and merges.
             for (var i = 0; i < modules.length; i++) {
                 var module = modules[i];
-                if (!module) continue;
-
-                if (module.clobbers && module.clobbers.length) {
-                    for (var j = 0; j < module.clobbers.length; j++) {
-                        mapper.clobbers(module.id, module.clobbers[j]);
+                if (module) {
+                    try { 
+                        if (module.clobbers && module.clobbers.length) {
+                            for (var j = 0; j < module.clobbers.length; j++) {
+                                mapper.clobbers(module.id, module.clobbers[j]);
+                            }
+                        }
+
+                        if (module.merges && module.merges.length) {
+                            for (var k = 0; k < module.merges.length; k++) {
+                                mapper.merges(module.id, module.merges[k]);
+                            }
+                        }
+
+                        // Finally, if runs is truthy we want to simply require() the module.
+                        // This can be skipped if it had any merges or clobbers, though,
+                        // since the mapper will already have required the module.
+                        if (module.runs && !(module.clobbers && module.clobbers.length) && !(module.merges && module.merges.length)) {
+                            context.cordova.require(module.id);
+                        }
                     }
-                }
-
-                if (module.merges && module.merges.length) {
-                    for (var k = 0; k < module.merges.length; k++) {
-                        mapper.merges(module.id, module.merges[k]);
+                    catch(err) {
+                        // error with module, most likely clobbers, should we continue?
                     }
                 }
-
-                // Finally, if runs is truthy we want to simply require() the module.
-                // This can be skipped if it had any merges or clobbers, though,
-                // since the mapper will already have required the module.
-                if (module.runs && !(module.clobbers && module.clobbers.length) && !(module.merges && module.merges.length)) {
-                    context.cordova.require(module.id);
-                }
             }
 
             finishPluginLoading();
@@ -104,36 +119,18 @@
         }
     }
 
-    // // Try to XHR the cordova_plugins.json file asynchronously.
-    // var xhr = new XMLHttpRequest();
-    // xhr.onload = function() {
-    //     // If the response is a JSON string which composes an array, call handlePluginsObject.
-    //     // If the request fails, or the response is not a JSON array, just call finishPluginLoading.
-    //     var obj;
-    //     try {
-    //         obj = (this.status == 0 || this.status == 200) && this.responseText && JSON.parse(this.responseText);
-    //     } catch (err) {
-    //         // obj will be undefined.
-    //     }
-    //     if (Array.isArray(obj) && obj.length > 0) {
-    //         handlePluginsObject(obj, path);
-    //     } else {
-    //         finishPluginLoading();
-    //     }
-    // };
-    // xhr.onerror = function() {
-    //     finishPluginLoading();
-    // };
-
     var plugins_js = path + 'cordova_plugins.js';
-    try { // we commented we were going to try, so let us actually try and catch
-        //xhr.open('GET', plugins_json, true); // Async
-        //xhr.send();
+    try {
+        
         var script = document.createElement("script");
         script.onload = function(){
             var list = cordova.require("cordova/plugin_list");
             handlePluginsObject(list,path);
-
+        };
+        script.onerror = function() {
+            // Error loading cordova_plugins.js, file not found or something
+            // this is an acceptable error, pre-3.0.0, so we just move on.
+            finishPluginLoading();
         };
         script.src = plugins_js;
         document.head.appendChild(script);