You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/05/23 22:03:40 UTC

[17/30] git commit: Menu for apps from serve. Menu now in iframe.Priority for startup hooks. Cleaned up AngularJS usage.

Menu for apps from serve. Menu now in iframe.Priority for startup hooks.
Cleaned up AngularJS usage.

Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/94edf0c1
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/94edf0c1
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/94edf0c1

Branch: refs/heads/master
Commit: 94edf0c11d8c6b05d803e5dabc8ad2969ee932b9
Parents: 636794a
Author: Shravan Narayan <sh...@google.com>
Authored: Fri May 10 15:50:52 2013 -0400
Committer: Shravan Narayan <sh...@google.com>
Committed: Fri May 10 15:50:52 2013 -0400

----------------------------------------------------------------------
 www/cdvah_contextMenu.html              |   87 ++++++++++----------
 www/cdvah_index.html                    |    2 +
 www/cdvah_js/AddCtrl.js                 |   35 +++++---
 www/cdvah_js/AppBundleAlias.js          |   32 ++++++-
 www/cdvah_js/AppsService.js             |  112 ++++++++++++++++----------
 www/cdvah_js/CdvhPackageHandler.js      |   12 +---
 www/cdvah_js/ContextMenu.js             |  110 ++++++++++++++-----------
 www/cdvah_js/ContextMenuInjectScript.js |   13 +++
 www/cdvah_js/ResourcesLoader.js         |    4 +-
 www/cdvah_js/ServeCordovaJSHandler.js   |   25 ++++++
 www/cdvah_views/add.html                |   12 ++--
 11 files changed, 273 insertions(+), 171 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/94edf0c1/www/cdvah_contextMenu.html
----------------------------------------------------------------------
diff --git a/www/cdvah_contextMenu.html b/www/cdvah_contextMenu.html
index 8f515c9..6c0e5c1 100644
--- a/www/cdvah_contextMenu.html
+++ b/www/cdvah_contextMenu.html
@@ -1,53 +1,56 @@
-<!-- Keep stylesheet as a part of the html as this file gets injected into the app -->
-<style>
-#__cordovaappharness_contextMenu_div
-{
-    position: fixed;
-    left : 0px;
-    top : 0px;
-    z-index: 2000;
-    background-color:rgba(0,0,0,0.75);
-    width: 100%;
-    height: 100%;
-    display: none;
-}
-#__cordovaappharness_contextMenu_div p
-{
-    color: white;
-    text-align: center;
-}
-#__cordovaappharness_contextMenu_div ul
-{
-    list-style-type: none;
-    margin-left: 20%;
-    margin-right: 20%;
-    padding: 0;
-    width: 60%;
-}
-#__cordovaappharness_contextMenu_div li
-{
-    margin-bottom: 0.5cm;
-}
-#__cordovaappharness_contextMenu_div li, #__cordovaappharness_contextMenu_div button
-{
-    width: 100%;
-    height: 1cm;
-}
-</style>
-<div id="__cordovaappharness_contextMenu_div">
+<!DOCTYPE html>
+<html>
+<head>
+    <style>
+        body
+        {
+            position: fixed;
+            left : 0px;
+            top : 0px;
+            z-index: 2000;
+            background-color:rgba(0,0,0,0.75);
+            width: 100%;
+            height: 100%;
+        }
+        body p
+        {
+            color: white;
+            text-align: center;
+        }
+        body ul
+        {
+            list-style-type: none;
+            margin-left: 20%;
+            margin-right: 20%;
+            padding: 0;
+            width: 60%;
+        }
+        body li
+        {
+            margin-bottom: 0.5cm;
+        }
+        body li, body button
+        {
+            width: 100%;
+            height: 1cm;
+        }
+    </style>
+</head>
+<body onclick="parent.postMessage('ContextMenuHide', '*');">
     <p>Tap Anywhere to Close</p>
     <ul>
         <li>
-            <a href="app-bundle:///cdvah_index.html#/?updateLastLaunched=true"><button>Update</button></a>
+            <button onclick="parent.postMessage('ContextMenuUpdate', '*');">Update</button>
         </li>
         <li>
-            <a href="app-bundle:///cdvah_index.html#/?lastLaunched=true"><button>Restart</button></a>
+            <button onclick="parent.postMessage('ContextMenuRestart', '*');">Restart</button>
         </li>
         <li>
-            <button id="__cordovaappharness_contextMenu_firebug_button">Firebug</button>
+            <button onclick="parent.postMessage('ContextMenuFirebug', '*');">Firebug</button>
         </li>
         <li>
-            <a href="app-bundle:///cdvah_index.html"><button>Back to Main Menu</button></a>
+            <button onclick="parent.postMessage('ContextMenuMainMenu', '*');">Back to Main Menu</button>
         </li>
     </ul>
-</div>
\ No newline at end of file
+</body>
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/94edf0c1/www/cdvah_index.html
----------------------------------------------------------------------
diff --git a/www/cdvah_index.html b/www/cdvah_index.html
index b33fe29..8850f80 100644
--- a/www/cdvah_index.html
+++ b/www/cdvah_index.html
@@ -7,6 +7,8 @@
         <script type="text/javascript" src="cdvah_js/libs/angular.min.js"></script>
         <script type="text/javascript" src="cdvah_js/app.js"></script>
         <script type="text/javascript" src="cdvah_js/AppConstants.js"></script>
+        <script type="text/javascript" src="cdvah_js/ContextMenuInjectScript.js"></script>
+        <script type="text/javascript" src="cdvah_js/ServeCordovaJSHandler.js"></script>
         <script type="text/javascript" src="cdvah_js/ResourcesLoader.js"></script>
         <script type="text/javascript" src="cdvah_js/AppsService.js"></script>
         <script type="text/javascript" src="cdvah_js/AppBundleAlias.js"></script>

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/94edf0c1/www/cdvah_js/AddCtrl.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/AddCtrl.js b/www/cdvah_js/AddCtrl.js
index 7f6a34c..b536d87 100644
--- a/www/cdvah_js/AddCtrl.js
+++ b/www/cdvah_js/AddCtrl.js
@@ -3,28 +3,37 @@
     /* global myApp */
     myApp.controller("AddCtrl", ["$scope", "AppsService", function ($scope, AppsService) {
 
-        $scope.addApp = function(appName, appSource, appSourcePattern, appSourceServe) {
+        $scope.appData = {
+            appName : "",
+            appSource : "pattern",
+            appSourcePattern : "",
+            appSourceServe  : ""
+        };
+
+        $scope.addApp = function() {
             var serviceCall;
-            if(appSource === "pattern") {
-                if(!appSourcePattern) {
+            if($scope.appData.appSource === "pattern") {
+                if(!$scope.appData.appSourcePattern) {
                     alert("Url of package not specified");
                     return;
                 }
-                serviceCall = AppsService.addAppFromPattern(appName, appSourcePattern);
-            } else if(appSource === "serve") {
-                if(!appSourceServe) {
+                serviceCall = AppsService.addAppFromPattern($scope.appData.appName, $scope.appData.appSourcePattern);
+            } else if($scope.appData.appSource === "serve") {
+                if(!$scope.appData.appSourceServe) {
                     alert("Url of config file not specified");
                     return;
                 }
-                serviceCall = AppsService.addAppFromServe(appName, appSourceServe);
+                serviceCall = AppsService.addAppFromServe($scope.appData.appName, $scope.appData.appSourceServe);
             }
 
-            serviceCall.then(function() {
-                alert("Successfully installed");
-            }, function(error) {
-                console.error(error);
-                alert("Unable to add application because: \n" + error);
-            });
+            if(serviceCall) {
+                serviceCall.then(function() {
+                    alert("Successfully installed");
+                }, function(error) {
+                    console.error(error);
+                    alert("Unable to add application because: \n" + error);
+                });
+            }
 
         };
     }]);

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/94edf0c1/www/cdvah_js/AppBundleAlias.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/AppBundleAlias.js b/www/cdvah_js/AppBundleAlias.js
index 1bdfbf8..7c244a6 100644
--- a/www/cdvah_js/AppBundleAlias.js
+++ b/www/cdvah_js/AppBundleAlias.js
@@ -24,13 +24,35 @@
             }
         }
 
-        AppsService.addPreLaunchHook(function(appName, wwwLocation) {
-            console.log("Adding aliases for " + appName);
+        function getRegex(string){
+            return string.replace("[", "\\[")
+            .replace("\\", "\\\\")
+            .replace("^", "\\^")
+            .replace("$", "\\$")
+            .replace(".", "\\.")
+            .replace("|", "\\|")
+            .replace("?", "\\?")
+            .replace("*", "\\*")
+            .replace("+", "\\+")
+            .replace("(", "\\(")
+            .replace(")", "\\)");
+        }
+
+        AppsService.addPreLaunchHook(function(appEntry, appInstallLocation, wwwLocation) {
+            console.log("Adding aliases for " + appEntry.Name);
             wwwLocation += (wwwLocation.charAt(wwwLocation.length - 1) === "/")? "" : "/";
-            wwwLocation = (wwwLocation.indexOf("file://") === 0) ? wwwLocation : "file://" + wwwLocation;
+            appInstallLocation += (appInstallLocation.charAt(appInstallLocation.length - 1) === "/")? "" : "/";
             //Make any direct references to the bundle paths such as file:///android_asset point to the installed location without redirecting
             //{BUNDLE_WWW} in the regex is automatically replaced by the appBundle component
-            return aliasUri("^{BUNDLE_WWW}.*", "^{BUNDLE_WWW}", wwwLocation, false /* redirect */);
-        });
+            return aliasUri("^{BUNDLE_WWW}.*", "^{BUNDLE_WWW}", wwwLocation, false /* redirect */)
+            .then(function(){
+                //For cordova serve apps, we additionally have to redirect requests to the original cordova.js to a modified cordova.js we have locally
+                if(appEntry.Source === "serve"){
+                    var regexWWWLoc = getRegex(wwwLocation);
+                    var regex = "^" + regexWWWLoc + "cordova.js(\\?|#.*)?";
+                    return aliasUri(regex, regex, appInstallLocation + "cordova.js", false);
+                }
+            });
+        }, 500 /* Give it a priority */);
     }]);
 })();

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/94edf0c1/www/cdvah_js/AppsService.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/AppsService.js b/www/cdvah_js/AppsService.js
index 824cb8a..f0d1b86 100644
--- a/www/cdvah_js/AppsService.js
+++ b/www/cdvah_js/AppsService.js
@@ -48,7 +48,13 @@
         }
 
         function addNewAppFromServe(appName, appSourceServe){
-            return registerApp(appName, "serve", appSourceServe);
+            return ResourcesLoader.deleteDirectory(INSTALL_DIRECTORY + appName)
+            .then(function(){
+                return ResourcesLoader.ensureDirectoryExists(INSTALL_DIRECTORY + appName + "/" + platformId);
+            })
+            .then(function(){
+                return registerApp(appName, "serve", appSourceServe);
+            });
         }
 
         function registerApp(appName, appSource, appSourceData) {
@@ -70,12 +76,13 @@
         }
 
         function getAppStartPageFromConfig(configFile, appBaseLocation) {
+            appBaseLocation += (appBaseLocation.charAt(appBaseLocation.length - 1) === "/")? "" : "/";
             return ResourcesLoader.readFileContents(configFile)
             .then(function(contents){
                 if(!contents) {
                     throw new Error("Config file is empty. Unable to find a start page for your app.");
                 } else {
-                    var startLocation = appBaseLocation + "/index.html";
+                    var startLocation = appBaseLocation + "index.html";
                     var parser = new DOMParser();
                     var xmlDoc = parser.parseFromString(contents, "text/xml");
                     var els = xmlDoc.getElementsByTagName("content");
@@ -90,7 +97,7 @@
                                     startLocation = srcValue;
                                 } else {
                                     srcValue = srcValue.charAt(0) === "/" ? srcValue.substring(1) : srcValue;
-                                    startLocation = appBaseLocation + "/" + srcValue;
+                                    startLocation = appBaseLocation + srcValue;
                                 }
                                 break;
                             }
@@ -110,18 +117,15 @@
             })
             .then(function(result){
                 result.installedApps = result.installedApps || [];
-
                 for(var i = 0; i < result.installedApps.length; i++){
                     if(result.installedApps[i].Name === appName) {
                         entry = result.installedApps.splice(i, 1)[0];
                         break;
                     }
                 }
-
                 if(!entry) {
                     throw new Error("The app " + appName + " was not found.");
                 }
-
                 return ResourcesLoader.writeJSONFileContents(APPS_JSON, result);
             })
             .then(function(){
@@ -162,8 +166,7 @@
             });
         }
 
-        function getWWWDirAndStartPageFromConfigForApp(appName){
-            var platformWWWLocation;
+        function getAppEntry(appName){
             return getAppsList(true /* Get full app entry */)
             .then(function(appEntries){
                 var entry;
@@ -176,14 +179,27 @@
                 if(!entry){
                     throw new Error("Could not find the app " + appName + " in the installed apps");
                 }
+                return entry;
+            });
+        }
+
+        // On success, this function returns the following paths
+        // appInstallLocation - INSTALL_DIR/app/platform/
+        // platformWWWLocation - location containing the html, css and js files
+        // configLocation - location of config.xml
+        // startLocation - the path of the page to start the app with
+        function getAppPathsForAppEntry(entry){
+            var appPaths = {};
+            return ResourcesLoader.getFullFilePath(INSTALL_DIRECTORY + entry.Name + "/" + platformId)
+            .then(function(platformLocation){
+                if(!isPathAbsolute(platformLocation)){
+                    // assume file uri
+                    platformLocation = "file://" + platformLocation;
+                }
+                appPaths.appInstallLocation = platformLocation;
                 if(entry.Source === "pattern"){
-                    return ResourcesLoader.getFullFilePath(INSTALL_DIRECTORY + appName + "/" + platformId)
-                    .then(function(platformLocation){
-                        return {
-                            platformWWWLocation : platformLocation + "/www/",
-                            configLocation : platformLocation + "/config.xml"
-                        };
-                    });
+                    appPaths.platformWWWLocation = platformLocation + "/www/";
+                    appPaths.configLocation = platformLocation + "/config.xml";
                 } else if(entry.Source === "serve"){
                     var configFile = entry.Data;
                     var location = configFile.indexOf("/config.xml");
@@ -192,26 +208,30 @@
                     }
                     //grab path including upto last slash
                     var appLocation =  configFile.substring(0, location + 1);
-                    return {
-                        platformWWWLocation : appLocation,
-                        configLocation : configFile
-                    };
+                    appPaths.platformWWWLocation = appLocation;
+                    appPaths.configLocation = configFile;
                 } else {
                     throw new Error("Unknown app source: " + entry.Source);
                 }
-            })
-            .then(function(appPaths){
-                platformWWWLocation = appPaths.platformWWWLocation;
                 return getAppStartPageFromConfig(appPaths.configLocation, appPaths.platformWWWLocation);
             })
             .then(function(startLocation){
-                return {
-                    startLocation : startLocation,
-                    platformWWWLocation : platformWWWLocation
-                };
+                appPaths.startLocation = startLocation;
+                return appPaths;
             });
         }
 
+        function insertObjectAtPriority(objArr, handler, priority){
+            var i = 0;
+            var objToInsert = { "priority" : priority, "handler" : handler };
+            for(i = 0; i < objArr.length; i++){
+                if(objArr[i].priority > objToInsert.priority) {
+                    break;
+                }
+            }
+            objArr.splice(i, 0, objToInsert);
+        }
+
         return {
             //return promise with the array of apps
             getAppsList : function(getFullEntries) {
@@ -219,6 +239,7 @@
             },
 
             launchApp : function(appName) {
+                var appEntry;
                 var startLocation;
                 return ResourcesLoader.readJSONFileContents(METADATA_JSON)
                 .then(function(settings){
@@ -227,15 +248,21 @@
                     return ResourcesLoader.writeJSONFileContents(METADATA_JSON, settings);
                 })
                 .then(function(){
-                    return getWWWDirAndStartPageFromConfigForApp(appName);
+                    return getAppEntry(appName);
                 })
-                .then(function(startLocationAndWWWLocation){
-                    startLocation = startLocationAndWWWLocation.startLocation;
-                    var promises = [];
-                    for (var i = preLaunchHooks.length - 1; i >= 0; i--) {
-                        promises.push(preLaunchHooks[i](appName, startLocationAndWWWLocation.platformWWWLocation));
-                    }
-                    return Q.all(promises);
+                .then(function(_appEntry){
+                    appEntry = _appEntry;
+                    return getAppPathsForAppEntry(appEntry);
+                })
+                .then(function(appPaths){
+                    startLocation = appPaths.startLocation;
+                    var result = Q.resolve(0 /* dummy value to set up chain */);
+                    preLaunchHooks.forEach(function (currHook) {
+                        result = result.then(function(){
+                            return currHook.handler(appEntry, appPaths.appInstallLocation, appPaths.platformWWWLocation);
+                        });
+                    });
+                    return result;
                 })
                 .then(function() {
                     window.location = startLocation;
@@ -284,14 +311,7 @@
                     // Assign a default priority
                     priority = 500;
                 }
-                var i = 0;
-                var objToInsert = { "priority" : priority, "handler" : handler };
-                for(i = 0; i < downloadHandlers.length; i++){
-                    if(downloadHandlers[i].priority > objToInsert.priority) {
-                        break;
-                    }
-                }
-                downloadHandlers.splice(i, 0, objToInsert);
+                insertObjectAtPriority(downloadHandlers, handler, priority);
             },
 
             registerPackageHandler : function(extension, handler) {
@@ -320,11 +340,15 @@
                 return Object.keys(extensionHandlers);
             },
 
-            addPreLaunchHook : function(handler){
+            addPreLaunchHook : function(handler, priority){
                 if(!handler || typeof(handler) !== "function") {
                     throw new Error("Expected (QPromise or void) function(appName, wwwLocation) for handler");
                 }
-                preLaunchHooks.push(handler);
+                if(!priority) {
+                    // Assign a default priority
+                    priority = 500;
+                }
+                insertObjectAtPriority(preLaunchHooks, handler, priority);
             }
         };
     }]);

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/94edf0c1/www/cdvah_js/CdvhPackageHandler.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/CdvhPackageHandler.js b/www/cdvah_js/CdvhPackageHandler.js
index 1ea25ce..edf5245 100644
--- a/www/cdvah_js/CdvhPackageHandler.js
+++ b/www/cdvah_js/CdvhPackageHandler.js
@@ -1,7 +1,7 @@
 (function(){
     "use strict";
     /* global myApp */
-    myApp.run(["AppsService", "ResourcesLoader", function(AppsService, ResourcesLoader){
+    myApp.run(["AppsService", "ResourcesLoader", "ContextMenuInjectScript", function(AppsService, ResourcesLoader, ContextMenuInjectScript){
 
         var platformId = cordova.require("cordova/platform").id;
 
@@ -20,17 +20,9 @@
             });
         }
 
-        var appendScript = function() {
-            console.log("Injecting menu script");
-            var contextScript = document.createElement("script");
-            contextScript.setAttribute("type","text/javascript");
-            contextScript.setAttribute("src", "app-bundle:///cdvah_js/ContextMenu.js");
-            document.getElementsByTagName("head")[0].appendChild(contextScript);
-        };
-
         AppsService.registerPackageHandler("cdvh", {
             extractPackageToDirectory : function (fileName, outputDirectory){
-                var dataToAppend = "\n(" + appendScript.toString() + ")();";
+                var dataToAppend = "\n(" + ContextMenuInjectScript.toString() + ")();";
                 var platformDirectory = outputDirectory + "/" + platformId + "/www/";
                 var cordovaFile = platformDirectory + "cordova.js";
                 var pluginsFile = platformDirectory + "cordova_plugins.json";

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/94edf0c1/www/cdvah_js/ContextMenu.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/ContextMenu.js b/www/cdvah_js/ContextMenu.js
index 8854480..452f656 100644
--- a/www/cdvah_js/ContextMenu.js
+++ b/www/cdvah_js/ContextMenu.js
@@ -1,65 +1,79 @@
 (function () {
 
     function initialise() {
-        var contextHTMLUrl = "app-bundle:///cdvah_contextMenu.html";
-        var xhr = new window.XMLHttpRequest();
-        xhr.onreadystatechange=function()
-        {
-            if (xhr.readyState==4 && xhr.status==200)
-            {
-                var stringifiedHtml = xhr.responseText;
-                onInject(stringifiedHtml);
-            }
-        };
-        // retrieve the context menu
-        xhr.open("GET", contextHTMLUrl, true);
-        xhr.send();
-
+        setupIframe();
+        setupIframeMessaging();
         loadFirebug(false);
         attachErrorListener();
     }
 
-    function onInject(stringifiedHtml) {
-
-        document.body.innerHTML += stringifiedHtml;
-
-        var contextDiv = "__cordovaappharness_contextMenu_div";
-        var showFirebugButton = "__cordovaappharness_contextMenu_firebug_button";
-
+    var contextMenuIframe = "__cordovaappharness_contextMenu_iframe";
+    function setupIframe(){
+        var contextHTMLUrl = "app-bundle:///cdvah_contextMenu.html";
+        var el = document.createElement("iframe");
+        el.setAttribute("id", contextMenuIframe);
+        el.setAttribute("src", contextHTMLUrl);
+        el.setAttribute("style", "position: fixed; left : 0px; top : 0px; z-index: 2000; width: 100%; height: 100%; display : none;");
+        document.body.appendChild(el);
         // Setup the listeners to toggle the context menu
         document.addEventListener("touchmove", function (event) {
             if(event.touches.length >= 3) {
-                document.getElementById(contextDiv).style.display = "inline";
+                document.getElementById(contextMenuIframe).style.display = "inline";
             }
         }, false);
+    }
 
-        document.getElementById(contextDiv).onclick = function() {
-            document.getElementById(contextDiv).style.display = "none";
-        };
-        var firstTime = true;
-        document.getElementById(showFirebugButton).onclick = function(){
-            try {
-                if(firstTime){
-                    console.warn("Note that messages logged to the console at the app startup may not be visible here.");
-                    console.warn("Do not use the close button on Firebug. Your console logs will be cleared. Use minimize instead.");
-                    firstTime = false;
-                }
-                window.Firebug.chrome.open();
-            } catch(e) {
-                // hack - FirebugLite appears to have several bugs. One of which is - open firebug, user shuts down FirebugLite through the UI.
-                // FirebugLite is now in a bad state of neither being usable or removable. Any calls to open throw an error.
-                // The following lines removes the flags that FirebugLite looks for manually and makes it think it has not loaded it yet
-                // Then FirebugLite is loaded into the page again
-                // This hack should be revisited when FirebugLite moves from version 1.4
-                // Either the hack won't be needed anymore or the hack should be checked too see if it still works.
-                var el = document.getElementById("FirebugLite");
-                if(el) {
-                    el.setAttribute("id", "");
-                }
-                delete console.firebuglite;
-                loadFirebug(true);
+    function setupIframeMessaging(){
+        window.addEventListener("message", function(e){
+            if(e.data === "ContextMenuUpdate"){
+                onContextMenuUpdateClicked();
+            } else if(e.data === "ContextMenuRestart"){
+                onContextMenuRestartClicked();
+            } else if(e.data === "ContextMenuFirebug"){
+                onContextMenuFirebugClicked();
+            } else if(e.data === "ContextMenuMainMenu"){
+                onContextMenuMainMenuClicked();
+            }else if(e.data === "ContextMenuHide"){
+                onContextMenuHideClicked();
             }
-        };
+        } , false);
+    }
+
+    function onContextMenuUpdateClicked(){
+        window.location = "app-bundle:///cdvah_index.html#/?updateLastLaunched=true";
+    }
+    function onContextMenuRestartClicked(){
+        window.location = "app-bundle:///cdvah_index.html#/?lastLaunched=true";
+    }
+    var firebugFirstOpen = true;
+    function onContextMenuFirebugClicked(){
+        try {
+            if(firebugFirstOpen){
+                console.warn("Note that messages logged to the console at the app startup may not be visible here.");
+                console.warn("Do not use the close button on Firebug. Your console logs will be cleared. Use minimize instead.");
+                firebugFirstOpen = false;
+            }
+            window.Firebug.chrome.open();
+        } catch(e) {
+            // hack - FirebugLite appears to have several bugs. One of which is - open firebug, user shuts down FirebugLite through the UI.
+            // FirebugLite is now in a bad state of neither being usable or removable. Any calls to open throw an error.
+            // The following lines removes the flags that FirebugLite looks for manually and makes it think it has not loaded it yet
+            // Then FirebugLite is loaded into the page again
+            // This hack should be revisited when FirebugLite moves from version 1.4
+            // Either the hack won't be needed anymore or the hack should be checked too see if it still works.
+            var el = document.getElementById("FirebugLite");
+            if(el) {
+                el.setAttribute("id", "");
+            }
+            delete console.firebuglite;
+            loadFirebug(true);
+        }
+    }
+    function onContextMenuMainMenuClicked(){
+        window.location = "app-bundle:///cdvah_index.html";
+    }
+    function onContextMenuHideClicked(){
+        document.getElementById(contextMenuIframe).style.display = "none";
     }
 
     function loadFirebug(startOpened){

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/94edf0c1/www/cdvah_js/ContextMenuInjectScript.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/ContextMenuInjectScript.js b/www/cdvah_js/ContextMenuInjectScript.js
new file mode 100644
index 0000000..7525b70
--- /dev/null
+++ b/www/cdvah_js/ContextMenuInjectScript.js
@@ -0,0 +1,13 @@
+(function() {
+    "use strict";
+    /* global myApp */
+    myApp.factory("ContextMenuInjectScript", [ function () {
+        return function() {
+            console.log("Injecting menu script");
+            var contextScript = document.createElement("script");
+            contextScript.setAttribute("type","text/javascript");
+            contextScript.setAttribute("src", "app-bundle:///cdvah_js/ContextMenu.js");
+            document.getElementsByTagName("head")[0].appendChild(contextScript);
+        };
+    }]);
+})();
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/94edf0c1/www/cdvah_js/ResourcesLoader.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/ResourcesLoader.js b/www/cdvah_js/ResourcesLoader.js
index e1df6db..b1e55ee 100644
--- a/www/cdvah_js/ResourcesLoader.js
+++ b/www/cdvah_js/ResourcesLoader.js
@@ -426,9 +426,7 @@
                 }
             },
 
-            xhrGet : function(url) {
-                return xhrGet(url);
-            }
+            xhrGet : xhrGet
         };
     }]);
 

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/94edf0c1/www/cdvah_js/ServeCordovaJSHandler.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/ServeCordovaJSHandler.js b/www/cdvah_js/ServeCordovaJSHandler.js
new file mode 100644
index 0000000..0154c64
--- /dev/null
+++ b/www/cdvah_js/ServeCordovaJSHandler.js
@@ -0,0 +1,25 @@
+(function(){
+    "use strict";
+    /* global myApp */
+    myApp.run(["AppsService", "ResourcesLoader", "ContextMenuInjectScript", function(AppsService, ResourcesLoader, ContextMenuInjectScript){
+
+        AppsService.addPreLaunchHook(function(appEntry, appInstallLocation , wwwLocation) {
+            if(appEntry.Source === "serve"){
+                return Q.fcall(function(){
+                    // We can't inject the context menu script into cordova.js remotely
+                    // So we create a local copy of the cordova.js used by the server,
+                    //      append the context menu script (requests for cordova.js are routed to it)
+                    wwwLocation += (wwwLocation.charAt(wwwLocation.length - 1) === "/")? "" : "/";
+                    var cordovaJSPath = wwwLocation + "cordova.js";
+                    return ResourcesLoader.xhrGet(cordovaJSPath);
+                })
+                .then(function(xhr){
+                    var dataToAppend = "\n(" + ContextMenuInjectScript.toString() + ")();";
+                    var completeText = xhr.responseText + dataToAppend;
+                    appInstallLocation += (appInstallLocation.charAt(appInstallLocation.length - 1) === "/")? "" : "/";
+                    return ResourcesLoader.writeFileContents(appInstallLocation + "cordova.js", completeText);
+                });
+            }
+        }, 250 /* Give it a priority */);
+    }]);
+})();

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/94edf0c1/www/cdvah_views/add.html
----------------------------------------------------------------------
diff --git a/www/cdvah_views/add.html b/www/cdvah_views/add.html
index af318b8..77778e6 100644
--- a/www/cdvah_views/add.html
+++ b/www/cdvah_views/add.html
@@ -1,23 +1,23 @@
 <form name="addForm" ng-controller="AddCtrl">
     <label for="inputAppName">Enter the App Name</label><br />
-    <input type="text" name="appName" ng-model="appName" ng-pattern="/^[\w ]*$/" ng-maxlength="64" required />
+    <input type="text" name="appName" ng-model="appData.appName" ng-pattern="/^[\w ]*$/" ng-maxlength="64" required />
     <span ng-show="addForm.appName.$error.required">Required</span>
     <span ng-show="addForm.appName.$error.pattern">Invalid characters used</span>
     <span ng-show="addForm.appName.$error.maxlength">Too long</span>
     <br />
 
-    <input type="radio" ng-model="appSource" name="appSource" value="pattern" ng-init="appSource='pattern'" ng-checked="appSource=='pattern'" />
+    <input type="radio" ng-model="appData.appSource" name="appSource" value="pattern" ng-checked="appData.appSource=='pattern'" />
         <label for="inputAppPattern">Enter the URL to a file</label><br />
-        <input id="inputAppPattern" type="text" name="appSourcePattern" ng-model="appSourcePattern" ng-disabled="appSource!='pattern'" ng-required="appSource=='pattern'" />
+        <input id="inputAppPattern" type="text" name="appSourcePattern" ng-model="appData.appSourcePattern" ng-disabled="appData.appSource!='pattern'" ng-required="appSource=='pattern'" />
         <span ng-show="addForm.appSourcePattern.$error.required">Required</span>
         <br />
-    <input type="radio" ng-model="appSource" name="appSource" value="serve" ng-checked="appSource=='serve'" />
+    <input type="radio" ng-model="appData.appSource" name="appSource" value="serve" ng-checked="appData.appSource=='serve'" />
         <label for="inputAppServe">Enter the URL to the server hosting the app</label><br />
-        <input id="inputAppServe" type="text" name="appSourceServe" ng-model="appSourceServe" ng-disabled="appSource!='serve'" ng-pattern="/.*\/config.xml(\?.*|#.*)?$/" ng-required="appSource=='serve'" />
+        <input id="inputAppServe" type="text" name="appSourceServe" ng-model="appData.appSourceServe" ng-disabled="appData.appSource!='serve'" ng-pattern="/.*\/config.xml(\?.*|#.*)?$/" ng-required="appSource=='serve'" />
         <span ng-show="addForm.appSourceServe.$error.required">Required</span>
         <span ng-show="addForm.appSourceServe.$error.pattern">Url must point to a config.xml file</span>
         <br />
-    <button ng-click="addApp(appName, appSource, appSourcePattern, appSourceServe)" ng-disabled="!(addForm.$valid)">Add</button>
+    <button ng-click="addApp()" ng-disabled="!(addForm.$valid)">Add</button>
     <br />
     <a href="#/">Back To Main Menu</a>
 </form>
\ No newline at end of file