Skip to content

Commit

Permalink
Enable Chromium to display PDFs in the viewer iframe
Browse files Browse the repository at this point in the history
This fix requires Chromium version above 90.
  • Loading branch information
veloman-yunkan committed Mar 29, 2023
1 parent cb20317 commit 795c7f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/server/response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,12 @@ ContentResponse::ContentResponse(const std::string& root, bool verbose, const st
m_mimeType(mimetype)
{
add_header(MHD_HTTP_HEADER_CONTENT_TYPE, m_mimeType);
if ( !startsWith(m_mimeType, "application/pdf") ) {
add_header("Content-Security-Policy",
"default-src 'self' data: blob: about: chrome-extension: 'unsafe-inline' 'unsafe-eval'; "
"sandbox allow-scripts allow-same-origin allow-modals allow-popups allow-forms allow-downloads;");
add_header("Referrer-Policy", "no-referrer");
}
}

std::unique_ptr<ContentResponse> ContentResponse::build(
Expand Down
7 changes: 5 additions & 2 deletions static/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' data: 'unsafe-inline' 'unsafe-eval';
frame-src 'self' moz-extension: chrome-extension:;
object-src 'none';">
<title>ZIM Viewer</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link type="text/css" href="./skin/taskbar.css?KIWIXCACHEID" rel="Stylesheet" />
Expand Down Expand Up @@ -65,8 +69,7 @@
</div>

<iframe id="content_iframe"
referrerpolicy="same-origin"
sandbox="allow-same-origin allow-scripts"
referrerpolicy="no-referrer"
onload="on_content_load()"
src="./skin/blank.html?KIWIXCACHEID" title="ZIM content" width="100%"
style="border:0px">
Expand Down

0 comments on commit 795c7f3

Please sign in to comment.