Author: sashee
Date: 2009-04-23 20:06:00 +0000 (Thu, 23 Apr 2009)
New Revision: 27271
Added:
trunk/freenet/src/freenet/clients/http/staticfiles/js/
trunk/freenet/src/freenet/clients/http/staticfiles/js/progresspage.js
Modified:
trunk/freenet/src/freenet/clients/http/FProxyToadlet.java
trunk/freenet/src/freenet/clients/http/ToadletContainer.java
trunk/freenet/src/freenet/clients/http/ToadletContextImpl.java
Log:
The progress page is now refreshed with AJAX, if enabled in the configuration
and in the browser.
Modified: trunk/freenet/src/freenet/clients/http/FProxyToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/FProxyToadlet.java 2009-04-23
20:04:56 UTC (rev 27270)
+++ trunk/freenet/src/freenet/clients/http/FProxyToadlet.java 2009-04-23
20:06:00 UTC (rev 27271)
@@ -513,12 +513,26 @@
break;
} else {
// Still in progress
+ boolean
isJsEnabled=ctx.getContainer().isFProxyJavascriptEnabled();
HTMLNode pageNode =
ctx.getPageMaker().getPageNode(l10n("fetchingPageTitle"), ctx);
+ String location = getLink(key,
requestedMimeType, maxSize, httprequest.getParam("force", null),
httprequest.isParameterSet("forcedownload"));
+ HTMLNode
headNode=ctx.getPageMaker().getHeadNode(pageNode);
+ if(isJsEnabled){
+ //If the user has enabled javascript,
we add a <noscript> http refresh(if he has disabled it in the browser)
+ //And the script file
+
headNode.addChild("noscript").addChild("meta", "http-equiv",
"Refresh").addAttribute("content", "2;URL=" + location);
+ HTMLNode
scriptNode=headNode.addChild("script","//abc");
+ scriptNode.addAttribute("type",
"text/javascript");
+ scriptNode.addAttribute("src",
"/static/js/progresspage.js");
+ }else{
+ //If he disabled it, we just put the
http refresh meta, without the noscript
+ headNode.addChild("meta", "http-equiv",
"Refresh").addAttribute("content", "2;URL=" + location);
+ }
HTMLNode contentNode =
ctx.getPageMaker().getContentNode(pageNode);
-
HTMLNode infobox = contentNode.addChild("div",
"class", "infobox infobox-information");
infobox.addChild("div", "class",
"infobox-header", l10n("fetchingPageBox"));
HTMLNode infoboxContent =
infobox.addChild("div", "class", "infobox-content");
+ infoboxContent.addAttribute("id",
"infoContent");
infoboxContent.addChild("#",
l10n("filenameLabel")+ " ");
infoboxContent.addChild("a", "href",
"/"+key.toString(false, false), key.getPreferredFilename());
if(fr.mimeType != null)
infoboxContent.addChild("br", l10n("contentTypeLabel")+" "+fr.mimeType);
@@ -586,9 +600,8 @@
ul.addChild("li").addChild("p").addChild("a",
new String[] { "href", "title" }, new String[] { "/",
L10n.getString("Toadlet.homepage") }, l10n("abortToHomepage"));
- String location = getLink(key,
requestedMimeType, maxSize, httprequest.getParam("force", null),
httprequest.isParameterSet("forcedownload"));
MultiValueTable<String, String> retHeaders =
new MultiValueTable<String, String>();
- retHeaders.put("Refresh", "2; url="+location);
+ //retHeaders.put("Refresh", "2; url="+location);
writeHTMLReply(ctx, 200, "OK", retHeaders,
pageNode.generate());
fr.close();
fetch.close();
Modified: trunk/freenet/src/freenet/clients/http/ToadletContainer.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/ToadletContainer.java
2009-04-23 20:04:56 UTC (rev 27270)
+++ trunk/freenet/src/freenet/clients/http/ToadletContainer.java
2009-04-23 20:06:00 UTC (rev 27271)
@@ -64,4 +64,6 @@
public boolean publicGatewayMode();
public boolean enableActivelinks();
+
+ public boolean isFProxyJavascriptEnabled();
}
Modified: trunk/freenet/src/freenet/clients/http/ToadletContextImpl.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/ToadletContextImpl.java
2009-04-23 20:04:56 UTC (rev 27270)
+++ trunk/freenet/src/freenet/clients/http/ToadletContextImpl.java
2009-04-23 20:06:00 UTC (rev 27271)
@@ -375,6 +375,8 @@
} catch (RedirectException re) {
uri = re.newuri;
redirect = true;
+ } catch(Exception e){
+
Logger.error(ToadletContextImpl.class, "Caught exception",e);
} finally {
req.freeParts();
}
Added: trunk/freenet/src/freenet/clients/http/staticfiles/js/progresspage.js
===================================================================
--- trunk/freenet/src/freenet/clients/http/staticfiles/js/progresspage.js
(rev 0)
+++ trunk/freenet/src/freenet/clients/http/staticfiles/js/progresspage.js
2009-04-23 20:06:00 UTC (rev 27271)
@@ -0,0 +1,70 @@
+window.onload = started;
+
+var req;
+
+function loadXMLDoc(url) {
+ req = false;
+ if (window.XMLHttpRequest && !(window.ActiveXObject)) {
+ try {
+ req = new XMLHttpRequest();
+ } catch (e) {
+ req = false;
+ }
+ } else if (window.ActiveXObject) {
+ try {
+ req = new ActiveXObject("Msxml2.XMLHTTP");
+ } catch (e) {
+ try {
+ req = new ActiveXObject("Microsoft.XMLHTTP");
+ } catch (e) {
+ req = false;
+ }
+ }
+ }
+ if (req) {
+ req.overrideMimeType("text/xml");
+ req.onreadystatechange = processReqChange;
+ req.open("GET", url, true);
+ req.send("");
+ }
+}
+
+function substringTillClosing(str,fromIndex){
+ var opentags=0;
+ var i=fromIndex;
+ for(;i<str.length-1;i++){
+ if(str.charAt(i)=="<" && str.charAt(i+1)=="/"){
+ opentags--;
+ }else if(str.charAt(i)=="<"){
+ opentags++;
+ }else if(str.charAt(i)=="/" && str.charAt(i)==">"){
+ opentags--;
+ }
+ if(opentags==-1){
+ return str.substring(str.indexOf(">",fromIndex)+1,i-1);
+ }
+ }
+}
+
+function processReqChange() {
+ if (req.readyState == 4) {
+ if (req.status == 200) {
+ if(req.responseText.indexOf("infoContent")==-1){
+ window.location.reload();
+ }else{
+
document.getElementById('infoContent').innerHTML=substringTillClosing(req.responseText,req.responseText.indexOf("id=\"infoContent\""))
+ }
+ }else if(req.status==500){
+ window.location.reload();
+ }
+ setTimeout(sendRequest, 2000);
+ }
+}
+
+function sendRequest() {
+ loadXMLDoc(document.location.href);
+}
+
+function started() {
+ setTimeout(sendRequest, 2000);
+}
\ No newline at end of file
_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs