Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
support for client and target to handle multi-user
client and target now accept an "id" after a hash character (#)
in places where URLs are expected, like the primary client URL,
and the URL for the target script you inject.  This id will
be used at connection time to scope per-user sessions on a
server that supports multiple users.
  • Loading branch information
pmuellr committed May 2, 2011
1 parent 55ab592 commit 18b81657d408c421d74a2cd6619f26f91a6692a6
Showing 11 changed files with 101 additions and 30 deletions.
@@ -13,7 +13,6 @@
import java.io.Reader;
import java.util.List;

import javax.management.RuntimeErrorException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
@@ -10,13 +10,13 @@
<meta name="viewport" content="user-scalable=no, width=device-width, height=device-height">
<title>weinre demo</title>
<link rel="stylesheet" href="weinre-demo.css">
<script src="weinre-demo.js"></script>
<script src="/target/target-script-min.js"></script>

<script type="text/javascript">
require("weinre/common/Weinre").showNotImplemented()
</script>

<script src="weinre-demo.js"></script>
</head>

<body onload="onLoad()">
@@ -10,6 +10,7 @@
<meta name="viewport" content="user-scalable=no, width=device-width, height=device-height">
<title>weinre demo</title>
<link rel="stylesheet" href="weinre-demo.css">
<script src="weinre-demo.js"></script>
<script src="/modjewel-require.js"></script>
<script type="text/javascript">require("modjewel").warnOnRecursiveRequire(true)</script>
<script src="/scooj.transportd.js"></script>
@@ -48,8 +49,6 @@
require("weinre/common/Weinre").showNotImplemented()
require('weinre/target/Target').main()
</script>

<script src="weinre-demo.js"></script>
</head>

<body onload="onLoad()">
@@ -10,13 +10,12 @@
<meta name="viewport" content="user-scalable=no, width=device-width, height=device-height">
<title>weinre demo</title>
<link rel="stylesheet" href="weinre-demo.css">
<script src="weinre-demo.js"></script>
<script src="/target/target-script.js"></script>

<script type="text/javascript">
require("weinre/common/Weinre").showNotImplemented()
</script>

<script src="weinre-demo.js"></script>
</head>

<body onload="onLoad()">
@@ -13,6 +13,11 @@ var buttonClearOutput
var outputElement
var storageIndex = 0

// set the id based on the hash
var hash = location.href.split("#")[1]
if (!hash) hash = "anonymous"
window.WeinreServerId = hash

//------------------------------------------------------------------------------
function onLoad() {
if (!buttonStartStuff) buttonStartStuff = document.getElementById("button-start-stuff")
@@ -33,6 +33,9 @@
textarea {
width: 100%;
}
pre, .indent {
margin-left: 2em;
}
</style>
</head>
<body>
@@ -47,15 +50,36 @@ <h2>Access Points</h2>
<tr><td>target demo: <td> <span id="url-target-demo-min">???</span> <br><i>(<span id="url-target-demo-pieces"></span>)</i>
</table>

<h2>Target Script</h2>

<p>You can use this script to inject the weinre target code into your web page.

<p class="indent"><code><span id="url-target-script">???</span></code>

<p>Example:

<pre>
&ltscript src="<span id="url-target-script-raw">???</span>"&gt;&lt;/script&gt;
</pre>

<h2>Target Bookmarklet</h2>

<p>link: <span id="url-target-bookmarklet">???</span> (drag to your bookmarks)
<p>You can use this bookmarklet to inject the weinre target code into any
web page you are viewing.

<p>link you can drag to your bookmarks:

<div class="indent">
<span id="url-target-bookmarklet">???</span>
</div>

<p>bookmarklet url in a pre:
<pre id="target-bookmarklet-src-pre"></pre>

<p>bookmarklet url in a textarea:
<div class="indent">
<textarea id="target-bookmarklet-src-text-area"></textarea>
</div>

<h2>Development</h2>

@@ -9,12 +9,19 @@ var weinre_protocol = location.protocol
var weinre_host = location.hostname
var weinre_port = location.port
var weinre_pathname = location.pathname
var weinre_id = "anonymous"

replaceURL("url-client-ui", buildHttpURL("client/"))
var hash = location.href.split("#")[1]
if (hash) {
weinre_id = hash
}

replaceURL("url-client-ui", buildHttpURL("client/#" + weinre_id))
replaceURL("url-interfaces", buildHttpURL("interfaces/interfaces.html"))
replaceURL("url-target-demo", buildHttpURL("demo/weinre-demo.html"))
replaceURL("url-target-demo-min", buildHttpURL("demo/weinre-demo-min.html"))
replaceURL("url-target-demo-pieces", buildHttpURL("demo/weinre-demo-pieces.html"), "pieces version")
replaceURL("url-target-demo", buildHttpURL("demo/weinre-demo.html#" + weinre_id))
replaceURL("url-target-demo-min", buildHttpURL("demo/weinre-demo-min.html#" + weinre_id))
replaceURL("url-target-demo-pieces", buildHttpURL("demo/weinre-demo-pieces.html#" + weinre_id), "pieces version")
replaceURL("url-target-script", buildHttpURL("target/target-script-min.js#" + weinre_id))
replaceURL("url-target-bookmarklet", getTargetBookmarklet(), "weinre target debug")
replaceURL("url-target-documentation", buildHttpURL("doc/"))
//replaceURL("url-client-protocol", buildHttpURL("ws/client/"))
@@ -34,6 +41,8 @@ replaceText("version-modjewel", Weinre.Versions.modjewel)
replaceText("target-bookmarklet-src-pre", getTargetBookmarklet())
replaceText("target-bookmarklet-src-text-area", getTargetBookmarklet())

replaceText("url-target-script-raw", buildHttpURL("target/target-script-min.js#" + weinre_id))

//---------------------------------------------------------------------
function buildHttpURL(uri) {
var port = weinre_port
@@ -70,7 +79,7 @@ function getTargetBookmarklet() {
script = script.replace(/\n/g, "")
script = script.replace("targetBookmarkletFunction","")
script = script.replace(/\s*/g, "")
script = script.replace("???", buildHttpURL("target/target-script-min.js"))
script = script.replace("???", buildHttpURL("target/target-script-min.js#" + weinre_id))
script = "(" + script + ')(document.createElement("script"));void(0);'
return 'javascript:' + script
}
@@ -38,7 +38,7 @@ method initialize
window.addEventListener("load", Binding(this, "onLoaded"), false)

// create the socket
var messageDispatcher = new MessageDispatcher("../ws/client")
var messageDispatcher = new MessageDispatcher("../ws/client", this._getId())
Weinre.messageDispatcher = messageDispatcher

// finish setting up InspectorBackend
@@ -54,6 +54,12 @@ method initialize
WebInspector.mainResource = {}
WebInspector.mainResource.url = location.href

//-----------------------------------------------------------------------------
method _getId
var hash = location.href.split("#")[1]
if (hash) return hash
return "anonymous"

//-----------------------------------------------------------------------------
method uiAvailable
return WebInspector.panels && WebInspector.panels.remote
@@ -14,8 +14,13 @@ requireClass ./Ex
requireClass ./Callback

//-----------------------------------------------------------------------------
class MessageDispatcher(url)
class MessageDispatcher(url, id)
if (!id) {
id = "anonymous"
}

this._url = url
this._id = id

this.error = null
this._opening = false
@@ -48,7 +53,7 @@ method _open
if (this._closed) throw new Ex(arguments, "socket has already been closed")

this._opening = true
this._socket = new WebSocketXhr(this._url)
this._socket = new WebSocketXhr(this._url, this._id)
this._socket.addEventListener("open", Binding(this, "_handleOpen"))
this._socket.addEventListener("error", Binding(this, "_handleError"))
this._socket.addEventListener("message", Binding(this, "_handleMessage"))
@@ -12,8 +12,8 @@ requireClass ./EventListeners
requireClass ./Native

//-----------------------------------------------------------------------------
class WebSocketXhr(url)
this.initialize(url)
class WebSocketXhr(url, id)
this.initialize(url, id)

//-----------------------------------------------------------------------------
init
@@ -25,9 +25,14 @@ init
WebSocketXhr.CLOSED = 3

//-----------------------------------------------------------------------------
method initialize(url)
method initialize(url, id)
if (!id) {
id = "anonymous"
}

this.readyState = WebSocketXhr.CONNECTING
this._url = url
this._id = id
this._urlChannel = null
this._queuedSends = []
this._sendInProgress = true
@@ -43,7 +48,8 @@ method initialize(url)

//-----------------------------------------------------------------------------
method _getChannel
this._xhr(this._url, "POST", "", this._handleXhrResponseGetChannel)
var body = JSON.stringify({ id: this._id})
this._xhr(this._url, "POST", body, this._handleXhrResponseGetChannel)

//-----------------------------------------------------------------------------
method _handleXhrResponseGetChannel(xhr)
@@ -47,7 +47,34 @@ static method main
//------------------------------------------------------------------------------
method setWeinreServerURLFromScriptSrc()
if (window.WeinreServerURL) return

var element = this.getTargetScriptElement()
var pattern = /(http:\/\/(.*?)\/)/
var match = pattern.exec(element.src)
if (match) {
window.WeinreServerURL = match[1]
return
}

var message = "unable to calculate the weinre server url; explicity set the variable window.WeinreServerURL instead"
alert(message)
throw new Ex(arguments, message)


//-----------------------------------------------------------------------------
method setWeinreServerIdFromScriptSrc()
if (window.WeinreServerId) return

var element = this.getTargetScriptElement()

var hash = element.src.split("#")[1]
if (!hash) hash = "anonymous"

window.WeinreServerId = hash

//-----------------------------------------------------------------------------
method getTargetScriptElement

var elements = document.getElementsByTagName("script")

var scripts = ["Target.", "target-script.", "target-script-min."]
@@ -56,23 +83,15 @@ method setWeinreServerURLFromScriptSrc()

for (j=0; j<scripts.length; j++) {
if (-1 != element.src.indexOf("/" + scripts[j])) {
var pattern = /(http:\/\/(.*?)\/)/
var match = pattern.exec(element.src)
if (match) {
window.WeinreServerURL = match[1]
return
}
return element
}
}
}

var message = "unable to calculate the weinre server url; explicity set the variable window.WeinreServerURL instead"
alert(message)
throw new Ex(arguments, message)

//-----------------------------------------------------------------------------
method initialize()
this.setWeinreServerURLFromScriptSrc()
this.setWeinreServerIdFromScriptSrc()

if (window.WeinreServerURL[window.WeinreServerURL.length-1] != "/") {
window.WeinreServerURL += "/"
@@ -83,7 +102,7 @@ method initialize()

window.addEventListener("load", Binding(this, "onLoaded"), false)

var messageDispatcher = new MessageDispatcher(window.WeinreServerURL + "ws/target")
var messageDispatcher = new MessageDispatcher(window.WeinreServerURL + "ws/target", window.WeinreServerId)
Weinre.messageDispatcher = messageDispatcher

Weinre.wi = {}

0 comments on commit 18b8165

Please sign in to comment.