summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorten Sorvig <morten.sorvig@nokia.com>2010-01-27 09:40:13 +0100
committerMorten Sorvig <morten.sorvig@nokia.com>2010-01-27 09:40:13 +0100
commit8eaae0130043127b095f74d4cdca0585a5d49684 (patch)
treef3390d6a8d21782f023c671e31abf9a964f81b2b
parent5665fe77ff645cf3369cd01a6bf3b7126d07930b (diff)
Various demo server improvements.
-rw-r--r--tools/nacldemoserver/httpserver.cpp41
-rw-r--r--tools/nacldemoserver/httpserver.h3
-rw-r--r--tools/nacldemoserver/main.cpp2
-rw-r--r--tools/nacldemoserver/naclhtmltemplate.html24
4 files changed, 42 insertions, 28 deletions
diff --git a/tools/nacldemoserver/httpserver.cpp b/tools/nacldemoserver/httpserver.cpp
index d0500930b0..c64c733842 100644
--- a/tools/nacldemoserver/httpserver.cpp
+++ b/tools/nacldemoserver/httpserver.cpp
@@ -148,7 +148,7 @@ QByteArray HttpResponse::toText()
} else if (eTag.isEmpty() == false) {
text += "eTag: " + eTag + "\r\n";
} else {
- text += QByteArray("Cace-control: no-cache \r\n");
+ text += QByteArray("Cache-control: no-cache \r\n");
text += QByteArray("Cache-control: max-age=0 \r\n");
}
@@ -198,7 +198,7 @@ void Server::dataOnSocket()
HttpRequest request(lines);
HttpResponse response;
- response.setBody(htmlForPath(request.path()));
+ serveResponseFromPath(&response, request.path());
QByteArray responseText = response.toText();
socket->write(responseText);
socket->close();
@@ -210,8 +210,9 @@ void Server::addRootPath(const QString &path)
rootPaths.append(QDir(path).canonicalPath());
}
-QByteArray Server::htmlForPath(QString path)
+void Server::serveResponseFromPath(HttpResponse *response, QString path)
{
+ qDebug() << "";
qDebug() << "htmlForPath" << path;
QByteArray html;
html += "<H2>Qt for Google Native Client Demo Browser </H2>";
@@ -223,7 +224,7 @@ QByteArray Server::htmlForPath(QString path)
html.append("<a href=./" + name + "/>" + name + "</a><br>");
}
- return html;
+ response->setBody(html);
}
if (path.startsWith("/"))
@@ -233,7 +234,7 @@ QByteArray Server::htmlForPath(QString path)
// the root paths.
QString canonicalPath = findCanonicalPath(path);
if (canonicalPath.isEmpty())
- return html;
+ return;
// is the path pointing directly to a nacl file?
bool isNaClFile = (QFile::exists(canonicalPath) && QFileInfo(canonicalPath).isDir() == false);
@@ -245,15 +246,19 @@ QByteArray Server::htmlForPath(QString path)
if (isNaClFile) {
QFile nexeFile(canonicalPath);
nexeFile.open(QIODevice::ReadOnly);
- return nexeFile.readAll();
+ response->setContentType("application/octet-stream");
+ response->setBody(nexeFile.readAll());
+ return;
} else if (isNaClDir) {
// chop of the last directory in the path
- QStringList pathParts = path.split('/');
+ QStringList pathParts = path.split('/', QString::SkipEmptyParts);
+ qDebug() << "nacl dir" << path << pathParts;
+
QString last = pathParts.takeLast();
QString newPath = pathParts.join("/");
- html += "<div style=\"float: left; width: 50%\">";
- html += htmlLinksForPath(findCanonicalPath(newPath), newPath);
+ html += "<div style=\"float: left; width: 30%\">";
+ html += htmlLinksForPath(findCanonicalPath(newPath), newPath, QLatin1String("../"));
html += "</div>";
html += "<div style=\"float: right\">";
@@ -265,7 +270,16 @@ QByteArray Server::htmlForPath(QString path)
html += "</div>";
}
- return html;
+ response->setBody(html);
+}
+
+QByteArray Server::htmlForPath(QString path)
+{
+ HttpResponse response;
+
+ serveResponseFromPath(&response, path);
+
+ return response.toText();
}
QString Server::findCanonicalPath(QString path)
@@ -312,7 +326,7 @@ QString Server::findCanonicalPath(QString path)
return canonicalPath;
}
-QByteArray Server::htmlLinksForPath(QString canonicalPath, QString path)
+QByteArray Server::htmlLinksForPath(QString canonicalPath, QString path, QString linkPrefix)
{
QByteArray html;
if (canonicalPath.isEmpty())
@@ -322,7 +336,7 @@ QByteArray Server::htmlLinksForPath(QString canonicalPath, QString path)
path.append("/");
qDebug() << "link path is" << path;
- html.append("<a href=../>..</a><br>");
+ html.append("<a href=" + linkPrefix + "../>..</a><br>");
QDirIterator it(canonicalPath);
while (it.hasNext()) {
@@ -339,7 +353,7 @@ QByteArray Server::htmlLinksForPath(QString canonicalPath, QString path)
QDir dir(it.filePath());
QString name = dir.dirName();
qDebug() << "payh is" << path;
- html.append("<a href=" + name + "/>" + name + "</a><br>");
+ html.append("<a href=" + linkPrefix + name + "/>" + name + "</a><br>");
}
}
@@ -348,6 +362,7 @@ QByteArray Server::htmlLinksForPath(QString canonicalPath, QString path)
QByteArray Server::instantiateNaclHtmlContent(QString appName)
{
+ qDebug() << "instantiateNaclHtmlContent" << appName;
QByteArray html = naclHtmlContent;
html.replace("NEXE", appName.toUtf8());
return html;
diff --git a/tools/nacldemoserver/httpserver.h b/tools/nacldemoserver/httpserver.h
index 3b45111718..0ca8fbe942 100644
--- a/tools/nacldemoserver/httpserver.h
+++ b/tools/nacldemoserver/httpserver.h
@@ -59,8 +59,9 @@ public:
void addRootPath(const QString&path);
QString findCanonicalPath(QString path);
+ void serveResponseFromPath(HttpResponse *request, QString path);
QByteArray htmlForPath(QString path);
- QByteArray htmlLinksForPath(QString canonicalPath, QString path);
+ QByteArray htmlLinksForPath(QString canonicalPath, QString path, QString prefix = QString());
QByteArray instantiateNaclHtmlContent(QString appName);
QByteArray naclHtmlContent;
void setSaveLocationLineEdit(QLineEdit *lineEdit) { saveLocationLineEdit = lineEdit; }
diff --git a/tools/nacldemoserver/main.cpp b/tools/nacldemoserver/main.cpp
index d6c50586b2..a1172d1330 100644
--- a/tools/nacldemoserver/main.cpp
+++ b/tools/nacldemoserver/main.cpp
@@ -6,7 +6,7 @@ int main(int argc, char *argv[])
{
QApplication a(argc, argv);
- quint16 port = 3001;
+ quint16 port = 5103; // the nacl port (plugin allows executables served from this port)
Server server(port);
server.addRootPath("../../examples");
server.addRootPath("../../demos");
diff --git a/tools/nacldemoserver/naclhtmltemplate.html b/tools/nacldemoserver/naclhtmltemplate.html
index c544547549..ccc3614fd8 100644
--- a/tools/nacldemoserver/naclhtmltemplate.html
+++ b/tools/nacldemoserver/naclhtmltemplate.html
@@ -3,33 +3,31 @@
var plugin;
var startupTimeout;
-var postLoadInit = function() {
+var waitForNaClModuleReady = function() {
if (1 == plugin.__moduleReady) {
clearTimeout(startupTimeout);
// Set up the display size
- canvasWidth = parseFloat(document.getElementById('NEXE').width);
- plugin.setup(canvasWidth);
} else {
if (plugin.__moduleReady == undefined) {
- alert('The Native Client plugin was unable to load');
- document.getElementById('warning')
+ //alert('The Native Client plugin was unable to load');
+ var elem = document.getElementById('warning')
+ elem.innertHtml = "Load Error";
return;
}
- startupTimeout = setTimeout(postLoadInit, 100);
+ startupTimeout = setTimeout(waitForNaClModuleReady, 100);
}
}
-// The page begins by loading the NativeClient module, mandel_nav.nexe.
+// The page begins by loading the NativeClient module
function Init() {
- // Remember the NativeClient plugin element.
- plugin = document.getElementById('NEXE');
- // Wait for the module to finish initializing before scripting.
- postLoadInit();
+ plugin = document.getElementById('NEXE');
+ // Wait for the module to finish initializing before scripting.
+ waitForNaClModuleReady();
}
window.onload = Init;
</script>
<div id="warning"> </div>
-<embed type="application/x-nacl-srpc" id="NEXE" src="NEXE/NEXE"
- class="QtNaClApplication" width="400" height="400" onclick="" />
+<embed type="application/x-nacl-srpc" id="NEXE" src="NEXE"
+ class="QtNaClApplication" width="600" height="400" onclick="" />