[tor-commits] [flashproxy/master] Add basic outline for JS proxy.
dcf at torproject.org
dcf at torproject.org
Mon Apr 9 04:08:41 UTC 2012
commit 4e5cfcee07dc68aa6774fe81704a224904a47b2e
Author: David Fifield <david at bamsoftware.com>
Date: Sun Mar 11 23:26:21 2012 -0700
Add basic outline for JS proxy.
---
embed.html | 9 ++++
flashproxy.js | 132 +++++++++++++++++++-------------------------------------
2 files changed, 54 insertions(+), 87 deletions(-)
diff --git a/embed.html b/embed.html
index ce3c1b4..de90209 100644
--- a/embed.html
+++ b/embed.html
@@ -7,6 +7,15 @@ body {
margin: 0;
padding: 0;
}
+#flashproxy-badge.debug {
+ position: absolute;
+ left: 0;
+ top: 0;
+ width: 100%;
+ height: 100%;
+ color: #44cc44;
+ background-color: #001f0f;
+}
</style>
</head>
<body>
diff --git a/flashproxy.js b/flashproxy.js
index 30ad616..ab55f07 100644
--- a/flashproxy.js
+++ b/flashproxy.js
@@ -1,3 +1,40 @@
+function FlashProxy()
+{
+ this.debug_div = document.createElement("div");
+ this.debug_div.className = "debug";
+
+ this.badge_elem = this.debug_div;
+ this.badge_elem.setAttribute("id", "flashproxy-badge");
+
+ this.puts = function(s) {
+ if (this.debug_div) {
+ this.debug_div.appendChild(document.createTextNode(s));
+ this.debug_div.appendChild(document.createElement("br"));
+ }
+ };
+
+ this.start = function() {
+ this.puts("Hello world!");
+ }
+}
+
+/* This is the non-functional badge that occupies space when
+ flashproxy_should_disable decides that the proxy shouldn't run. */
+function DummyFlashProxy()
+{
+ var img;
+
+ img = document.createElement("img");
+ img.setAttribute("src", "https://crypto.stanford.edu/flashproxy/badge.png");
+ img.setAttribute("border", 0);
+ img.setAttribute("id", "flashproxy-badge");
+
+ this.badge_elem = img;
+
+ this.start = function() {
+ };
+}
+
/* Are circumstances such that we should self-disable and not be a
proxy? We take a best-effort guess as to whether this device runs on
a battery or the data transfer might be expensive.
@@ -36,97 +73,15 @@ function flashproxy_should_disable()
return false;
}
-/* Create and return a DOM fragment:
-<span id=BADGE_ID>
-<a href=FLASHPROXY_INFO_URL>
- child
-</a>
-</span>
-*/
-function flashproxy_make_container(child)
-{
- var BADGE_ID = "flashproxy-badge";
- var FLASHPROXY_INFO_URL = "https://crypto.stanford.edu/flashproxy/";
-
- var container;
- var a;
-
- container = document.createElement("span");
- container.setAttribute("id", "flashproxy-badge");
- a = document.createElement("a");
- a.setAttribute("href", FLASHPROXY_INFO_URL);
- a.appendChild(child)
- container.appendChild(a);
-
- return container;
-}
-
-/* Create and return a DOM fragment:
-<object width=WIDTH height=HEIGHT>
- <param name="movie" value=SWFCAT_URL>
- <param name="flashvars" value=FLASHVARS>
- <embed src=SWFCAT_URL width=WIDTH height=HEIGHT flashvars=FLASHVARS></embed>
-</object>
-*/
-function flashproxy_make_badge()
-{
- var WIDTH = 70;
- var HEIGHT = 23;
- var FLASHVARS = "";
- var SWFCAT_URL = "https://crypto.stanford.edu/flashproxy/swfcat.swf";
-
- var object;
- var param;
- var embed;
-
- object = document.createElement("object");
- object.setAttribute("width", WIDTH);
- object.setAttribute("height", HEIGHT);
-
- param = document.createElement("param");
- param.setAttribute("name", "movie");
- param.setAttribute("value", SWFCAT_URL);
- object.appendChild(param);
- param = document.createElement("param");
- param.setAttribute("name", "flashvars");
- param.setAttribute("value", FLASHVARS);
- object.appendChild(param);
-
- embed = document.createElement("embed");
- embed.setAttribute("src", SWFCAT_URL);
- embed.setAttribute("width", WIDTH);
- embed.setAttribute("height", HEIGHT);
- embed.setAttribute("flashvars", FLASHVARS);
- object.appendChild(embed);
-
- return object;
-}
-
-/* Create and return a non-functional placeholder badge DOM fragment:
-<img src=BADGE_IMAGE_URL border="0">
-*/
-function flashproxy_make_dummy_badge()
-{
- var BADGE_IMAGE_URL = "https://crypto.stanford.edu/flashproxy/badge.png";
-
- var img;
-
- img = document.createElement("img");
- img.setAttribute("src", BADGE_IMAGE_URL);
- img.setAttribute("border", 0);
-
- return img;
-}
-
function flashproxy_badge_insert()
{
- var badge;
+ var fp;
var e;
if (flashproxy_should_disable()) {
- badge = flashproxy_make_dummy_badge();
+ fp = new DummyFlashProxy();
} else {
- badge = flashproxy_make_badge();
+ fp = new FlashProxy();
}
/* http://intertwingly.net/blog/2006/11/10/Thats-Not-Write for this trick to
@@ -135,7 +90,10 @@ function flashproxy_badge_insert()
while (e.lastChild && e.lastChild.nodeType == 1) {
e = e.lastChild;
}
- e.parentNode.appendChild(flashproxy_make_container(badge));
+ e.parentNode.appendChild(fp.badge_elem);
+
+ return fp;
}
-flashproxy_badge_insert();
+fp = flashproxy_badge_insert();
+fp.start();
More information about the tor-commits
mailing list