wasm: support serving wasm files

Updates README with instructions.

Change-Id: I5188d3ca267ff88a956dc17f302a70bda1046266
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
pull/7529/head
Ashod Nakashian 2023-10-19 18:57:58 -04:00 committed by Ashod Nakashian
parent 184a4a522e
commit d9d13d7092
2 changed files with 38 additions and 2 deletions

View File

@ -61,6 +61,25 @@ This will install into `/opt/poco.emsc.3.1.30`.
## Build Online itself
# 1. Update the directories in the command below to match your system.
# 2. Make sure that a document called sample.docx exists in the root of
# the directory set as --with-wasm-additional-files.
./autogen.sh
emconfigure ./configure --disable-werror --with-lokit-path=/home/tml/lo/core-cool-wasm/include --with-lo-path=/home/tml/lo/core-cool-wasm/instdir --with-lo-builddir=/home/tml/lo/core-cool-wasm --with-zstd-includes=/opt/zstd.emsc.3.1.30/include --with-zstd-libs=/opt/zstd.emsc.3.1.30/lib --with-poco-includes=/opt/poco.emsc.3.1.30/include --with-poco-libs=/opt/poco.emsc.3.1.30/lib --host=wasm32-local-emscripten --with-wasm-additional-files=/home/tml/lo/online-hacking/my-sample-docs
emmake make
## Running WASM Online
Once the build is done, copy the browser/dist to a safe locataion.
E.g. cp -a browser/dist dist_wasm
Next, re-configure Online and rebuild with normal config/settings (i.e. without WASM).
Alternatively, you may have opted to build WASM in a separate directory.
Either way, in the normal Online build directory, copy the wasm dist directory
into the browser/dist, like this:
cp -a dist_wasm browser/dist/wasm
Now point your browser to https://localhost:9980/browser/c85d8681f3/wasm.html?file_path=/some/unused/path
Notice that as of now, only the default sample.docx will be loaded.
But the above steps should get one up and running.

View File

@ -619,6 +619,8 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request,
mimeType = "image/png";
else if (fileType == "svg")
mimeType = "image/svg+xml";
else if (fileType == "wasm")
mimeType = "application/wasm";
else
mimeType = "text/plain";
@ -647,6 +649,12 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request,
response.set("Server", HTTP_SERVER_STRING);
response.set("Date", Util::getHttpTimeNow());
if (relPath.find("wasm") != std::string::npos)
{
response.add("Cross-Origin-Opener-Policy", "same-origin");
response.add("Cross-Origin-Embedder-Policy", "require-corp");
}
#if ENABLE_DEBUG
if (std::getenv("COOL_SERVE_FROM_FS"))
{
@ -1152,8 +1160,6 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request,
LOG_TRC("Denied all frame ancestors");
}
csp.merge(config.getString("net.content_security_policy", ""));
std::ostringstream oss;
oss << "HTTP/1.1 200 OK\r\n"
"Date: " << Util::getHttpTimeNow() << "\r\n"
@ -1167,6 +1173,17 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request,
"X-XSS-Protection: 1; mode=block\r\n"
"Referrer-Policy: no-referrer\r\n";
const bool wasm = (relPath.find("wasm") != std::string::npos);
if (wasm)
{
oss << "Cross-Origin-Opener-Policy: same-origin\r\n";
oss << "Cross-Origin-Embedder-Policy: require-corp\r\n";
csp.appendDirective("script-src", "'unsafe-eval'");
}
csp.merge(config.getString("net.content_security_policy", ""));
// Append CSP to response headers too
oss << "Content-Security-Policy: " << csp.generate() << "\r\n";