// This is a GET because a bookmarklet can call it from a different origin (JSONP).
if (target.startsWith("/recompile/")) {
String moduleName = target.substring("/recompile/".length());
Outbox box = outboxes.findByOutputModuleName(moduleName);
if (box == null) {
return new ErrorPage("No such module: " + moduleName);
}
// We are passing properties from an unauthenticated GET request directly to the compiler.
// This should be safe, but only because these are binding properties. For each binding
// property, you can only choose from a set of predefined values. So all an attacker can do is
// cause a spurious recompile, resulting in an unexpected permutation being loaded later.
//
// It would be unsafe to allow a configuration property to be changed.
Job job = box.makeJob(getBindingProperties(request), logger);
runner.submit(job);
Job.Result result = job.waitForResult();
JsonObject json = jsonExporter.exportRecompileResponse(result);
return Responses.newJsonResponse(json);
}
// GET the Js that knows how to request the specific permutation recompile.
if (target.startsWith("/recompile-requester/")) {
String moduleName = target.substring("/recompile-requester/".length());
Outbox box = outboxes.findByOutputModuleName(moduleName);
if (box == null) {
return new ErrorPage("No such module: " + moduleName);
}
try {
String recompileJs = runner.getRecompileJs(logger, box);
return Responses.newJavascriptResponse(recompileJs);
} catch (ExecutionException e) {
// Already logged.
return new ErrorPage("Failed to generate the Js recompile requester.");
}
}
if (target.startsWith("/log/")) {
String moduleName = target.substring("/log/".length());
Outbox box = outboxes.findByOutputModuleName(moduleName);
if (box == null) {
return new ErrorPage("No such module: " + moduleName);
} else if (box.containsStubCompile()) {
return new ErrorPage("This module hasn't been compiled yet.");
} else {
return makeLogPage(box);
}
}
if (target.equals("/favicon.ico")) {
InputStream faviconStream = getClass().getResourceAsStream("favicon.ico");
if (faviconStream == null) {
return new ErrorPage("icon not found");
}
// IE8 will not load the favicon in an img tag with the default MIME type,
// so use "image/x-icon" instead.
return Responses.newBinaryStreamResponse("image/x-icon", faviconStream);
}