Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 767E4C3DF for ; Wed, 19 Jun 2013 21:42:24 +0000 (UTC) Received: (qmail 61246 invoked by uid 500); 19 Jun 2013 21:42:24 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 61227 invoked by uid 500); 19 Jun 2013 21:42:24 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 61220 invoked by uid 99); 19 Jun 2013 21:42:24 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Jun 2013 21:42:24 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id EFE2425E6A; Wed, 19 Jun 2013 21:42:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: purplecabbage@apache.org To: commits@cordova.apache.org Message-Id: <70625bc26f5546a08e78bc579307ef6f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: js commit: moved plugin loader script injection to a function so it can also be called when xhr fails just because the json file is not present. Date: Wed, 19 Jun 2013 21:42:23 +0000 (UTC) Updated Branches: refs/heads/2.9.x e2020c3c4 -> 002f33ded moved plugin loader script injection to a function so it can also be called when xhr fails just because the json file is not present. Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/002f33de Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/002f33de Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/002f33de Branch: refs/heads/2.9.x Commit: 002f33dedb0c9f1e9b11319dbb3826af7c4fcdd9 Parents: e2020c3 Author: Jesse MacFadyen Authored: Wed Jun 19 14:35:26 2013 -0700 Committer: Jesse MacFadyen Committed: Wed Jun 19 14:41:12 2013 -0700 ---------------------------------------------------------------------- lib/scripts/plugin_loader.js | 50 +++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-js/blob/002f33de/lib/scripts/plugin_loader.js ---------------------------------------------------------------------- diff --git a/lib/scripts/plugin_loader.js b/lib/scripts/plugin_loader.js index b27216b..d9bea0a 100644 --- a/lib/scripts/plugin_loader.js +++ b/lib/scripts/plugin_loader.js @@ -121,6 +121,30 @@ var plugins_json = path + 'cordova_plugins.json'; var plugins_js = path + 'cordova_plugins.js'; + + // 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 + var injectPluginScript = function injectPluginScript() { + 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(); + } + } + + // Try to XHR the cordova_plugins.json file asynchronously. var xhr = new XMLHttpRequest(); xhr.onload = function() { @@ -139,32 +163,16 @@ } }; xhr.onerror = function() { - finishPluginLoading(); + // In this case, the json file was not present, but XHR was allowed, + // so we should still try the script injection technique with the js file + // in case that is there. + injectPluginScript(); }; 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(); - } + injectPluginScript(); } }(window));