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:43 UTC

[20/30] git commit: Weinre support.

Weinre support.

Conflicts:
	www/cdvah_js/ContextMenu.js


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/aee835bf
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/aee835bf
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/aee835bf

Branch: refs/heads/master
Commit: aee835bf06db3d3785a07cf0a89d07326c1bc44d
Parents: 9c28a5e
Author: Shravan Narayan <sh...@google.com>
Authored: Sun May 12 14:08:38 2013 -0400
Committer: Braden Shepherdson <br...@google.com>
Committed: Thu May 16 14:37:16 2013 -0400

----------------------------------------------------------------------
 www/cdvah_contextMenu.html              |   67 ++++++++++++++++++++------
 www/cdvah_js/AppsService.js             |    2 +-
 www/cdvah_js/CdvhPackageHandler.js      |    4 +-
 www/cdvah_js/ContextMenu.js             |   15 ++++++
 www/cdvah_js/ContextMenuInjectScript.js |   11 ++++-
 www/cdvah_js/ServeCordovaJSHandler.js   |    2 +-
 6 files changed, 81 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/aee835bf/www/cdvah_contextMenu.html
----------------------------------------------------------------------
diff --git a/www/cdvah_contextMenu.html b/www/cdvah_contextMenu.html
index 6c0e5c1..c00aacb 100644
--- a/www/cdvah_contextMenu.html
+++ b/www/cdvah_contextMenu.html
@@ -1,23 +1,19 @@
 <!DOCTYPE html>
-<html>
+<html onclick="parent.postMessage('ContextMenuHide', '*');">
 <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
+        p, label
         {
             color: white;
             text-align: center;
         }
-        body ul
+        ul
         {
             list-style-type: none;
             margin-left: 20%;
@@ -25,31 +21,72 @@
             padding: 0;
             width: 60%;
         }
-        body li
+        li
         {
             margin-bottom: 0.5cm;
+            width : 100%;
+            min-height: 1cm;
+            border-bottom: 1px solid grey;
         }
-        body li, body button
+        .fullwidthElement
         {
             width: 100%;
-            height: 1cm;
+            min-height: 1cm;
+        }
+        .halfwidthElement
+        {
+            min-height: 1cm;
+            width: 48%;
+            padding-left: 0;
+            padding-right: 0;
         }
     </style>
+    <script type="text/javascript">
+        var currentWeinreName;
+
+        function updateWeinreName(){
+            var newName = document.getElementById("WeinreName").value;
+            if(newName !== currentWeinreName){
+                var el = document.getElementById("WeinreLink");
+                var newVal = "http://debug.phonegap.com/client/#" + newName;
+                el.href = newVal;
+                el.innerText = newVal;
+                parent.postMessage("ContextMenuWeinre:" + newName, "*");
+                currentWeinreName = newName;
+            }
+        }
+
+        // Set up listener for incoming messages
+        window.addEventListener("message", function(e){
+            if(e.data.indexOf("AppHarnessAppName:") === 0){
+                var appName = e.data.substring("AppHarnessAppName:".length);
+                document.getElementById("WeinreName").value = appName;
+            }
+        } , false);
+    </script>
 </head>
-<body onclick="parent.postMessage('ContextMenuHide', '*');">
+<body>
     <p>Tap Anywhere to Close</p>
     <ul>
         <li>
-            <button onclick="parent.postMessage('ContextMenuUpdate', '*');">Update</button>
+            <button class="fullwidthElement" onclick="parent.postMessage('ContextMenuUpdate', '*');">Update</button>
+        </li>
+        <li>
+            <button class="fullwidthElement" onclick="parent.postMessage('ContextMenuRestart', '*');">Restart</button>
         </li>
         <li>
-            <button onclick="parent.postMessage('ContextMenuRestart', '*');">Restart</button>
+            <button class="fullwidthElement" onclick="parent.postMessage('ContextMenuFirebug', '*');">Firebug</button>
         </li>
         <li>
-            <button onclick="parent.postMessage('ContextMenuFirebug', '*');">Firebug</button>
+            <label for="WeinreName"><p>Phonegap Weinre</p></label>
+            <br />
+            <input class="halfwidthElement" id="WeinreName" type="text" value="default" onclick="event.stopPropagation();" />
+            <button class="halfwidthElement" onclick="updateWeinreName();">Add PhoneGap Weinre Link</button>
+            <br />
+            <a href="http://debug.phonegap.com/client/#default"><p id="WeinreLink"></p></a>
         </li>
         <li>
-            <button onclick="parent.postMessage('ContextMenuMainMenu', '*');">Back to Main Menu</button>
+            <button class="fullwidthElement" onclick="parent.postMessage('ContextMenuMainMenu', '*');">Back to Main Menu</button>
         </li>
     </ul>
 </body>

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/aee835bf/www/cdvah_js/AppsService.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/AppsService.js b/www/cdvah_js/AppsService.js
index 34358ce..f7def39 100644
--- a/www/cdvah_js/AppsService.js
+++ b/www/cdvah_js/AppsService.js
@@ -40,7 +40,7 @@
                 if(!extensionHandlers[extension]) {
                     throw new Error("No handler for extension " + extension + " found");
                 }
-                return extensionHandlers[extension].extractPackageToDirectory(fullFilePath, directoryPath);
+                return extensionHandlers[extension].extractPackageToDirectory(appName, fullFilePath, directoryPath);
             })
             .then(function(){
                 return registerApp(appName, "pattern", appSourcePattern);

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/aee835bf/www/cdvah_js/CdvhPackageHandler.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/CdvhPackageHandler.js b/www/cdvah_js/CdvhPackageHandler.js
index edf5245..bea8280 100644
--- a/www/cdvah_js/CdvhPackageHandler.js
+++ b/www/cdvah_js/CdvhPackageHandler.js
@@ -21,8 +21,8 @@
         }
 
         AppsService.registerPackageHandler("cdvh", {
-            extractPackageToDirectory : function (fileName, outputDirectory){
-                var dataToAppend = "\n(" + ContextMenuInjectScript.toString() + ")();";
+            extractPackageToDirectory : function (appName, fileName, outputDirectory){
+                var dataToAppend = ContextMenuInjectScript.getInjectString(appName);
                 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/aee835bf/www/cdvah_js/ContextMenu.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/ContextMenu.js b/www/cdvah_js/ContextMenu.js
index bcfa1b6..48d5ac8 100644
--- a/www/cdvah_js/ContextMenu.js
+++ b/www/cdvah_js/ContextMenu.js
@@ -2,6 +2,7 @@
 
     function initialise() {
         setupIframe();
+        sendAppNameToIframe();
         setupIframeMessaging();
         loadFirebug(false);
         attachErrorListener();
@@ -23,6 +24,15 @@
         }, false);
     }
 
+    function sendAppNameToIframe(){
+        if(window.__cordovaAppHarnessAppName){
+            var el = document.getElementById(contextMenuIframe);
+            el.onload = function(){
+                el.contentWindow.postMessage("AppHarnessAppName:" + window.__cordovaAppHarnessAppName, "*");
+            };
+        }
+    }
+
     function onContextMenuUpdateClicked(){
         window.location = "app-bundle:///cdvah_index.html#/?updateLastLaunched=true";
     }
@@ -59,6 +69,11 @@
     function onContextMenuHideClicked(){
         document.getElementById(contextMenuIframe).style.display = "none";
     }
+    function onContextMenuWeinreNameChanged(newName){
+        var el = document.createElement("script");
+        el.setAttribute("src", "http://debug.phonegap.com/target/target-script-min.js#" + newName);
+        document.head.appendChild(el);
+    }
 
     var messageHandler = {
         "ContextMenuUpdate" : onContextMenuUpdateClicked,

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/aee835bf/www/cdvah_js/ContextMenuInjectScript.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/ContextMenuInjectScript.js b/www/cdvah_js/ContextMenuInjectScript.js
index 7525b70..70c06aa 100644
--- a/www/cdvah_js/ContextMenuInjectScript.js
+++ b/www/cdvah_js/ContextMenuInjectScript.js
@@ -2,12 +2,21 @@
     "use strict";
     /* global myApp */
     myApp.factory("ContextMenuInjectScript", [ function () {
-        return function() {
+        var toInject = 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");
+            window.__cordovaAppHarnessAppName = "appPlaceHolder";
             document.getElementsByTagName("head")[0].appendChild(contextScript);
         };
+
+        return {
+            getInjectString : function(appName){
+                var string = "\n(" + toInject.toString() + ")();";
+                string = string.replace("appPlaceHolder", appName);
+                return string;
+            }
+        };
     }]);
 })();
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/aee835bf/www/cdvah_js/ServeCordovaJSHandler.js
----------------------------------------------------------------------
diff --git a/www/cdvah_js/ServeCordovaJSHandler.js b/www/cdvah_js/ServeCordovaJSHandler.js
index 0154c64..55bad69 100644
--- a/www/cdvah_js/ServeCordovaJSHandler.js
+++ b/www/cdvah_js/ServeCordovaJSHandler.js
@@ -14,7 +14,7 @@
                     return ResourcesLoader.xhrGet(cordovaJSPath);
                 })
                 .then(function(xhr){
-                    var dataToAppend = "\n(" + ContextMenuInjectScript.toString() + ")();";
+                    var dataToAppend = ContextMenuInjectScript.getInjectString(appEntry.Name);
                     var completeText = xhr.responseText + dataToAppend;
                     appInstallLocation += (appInstallLocation.charAt(appInstallLocation.length - 1) === "/")? "" : "/";
                     return ResourcesLoader.writeFileContents(appInstallLocation + "cordova.js", completeText);