Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDF-friendly book home button in the viewer #940

Merged
merged 1 commit into from
Jun 8, 2023
Merged

Conversation

veloman-yunkan
Copy link
Collaborator

Fixes #912

In firefox, when PDF content is displayed in the viewer, changing the viewer URL in the address bar had no effect. The most prominent manifestation of this bug was the broken book home button but the same issue was present even if the fragment component of the viewer URL was edited manually. The bug was a result of

  1. an optimization preventing any actions if the new content URL is the same as the old content URL (this was needed to break the infinite loop of mutual updates of the top-window and content window/iframe URLs when any one of them changes).

  2. sandboxing of the iframe and inability to access the content URL in iframe because of cross-origin restrictions when the content is a PDF displayed by the builtin viewer.

Now that issue is fixed. A slight remaining defect is that the addressbar URL is still not updated when a PDF file is loaded/displayed in the viewer.

@rgaudin
Copy link
Member

rgaudin commented Apr 22, 2023

I'm sorry but it's becoming a pain to test. I can't compile on macOS and neither can I on a debian:bullseye container

[4/102] ccache c++ -Itest/library.p -Iinclude -I../../SOURCE/libkiwix/include -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -DCURL_STATICLIB -pthread -isystem../../SOURCE/libkiwix/subprojects/googletest-release-1.8.1/googletest -isystemsubprojects/googletest-release-1.8.1/googletest -isystem../../SOURCE/libkiwix/subprojects/googletest-release-1.8.1/googletest/include -MD -MQ test/library.p/.._subprojects_googletest-release-1.8.1_googletest_src_gtest_main.cc.o -MF test/library.p/.._subprojects_googletest-release-1.8.1_googletest_src_gtest_main.cc.o.d -o test/library.p/.._subprojects_googletest-release-1.8.1_googletest_src_gtest_main.cc.o -c ../../SOURCE/libkiwix/subprojects/googletest-release-1.8.1/googletest/src/gtest_main.cc
[5/102] ccache c++ -Itest/regex.p -Iinclude -I../../SOURCE/libkiwix/include -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -DCURL_STATICLIB -pthread -isystem../../SOURCE/libkiwix/subprojects/googletest-release-1.8.1/googletest -isystemsubprojects/googletest-release-1.8.1/googletest -isystem../../SOURCE/libkiwix/subprojects/googletest-release-1.8.1/googletest/include -MD -MQ test/regex.p/regex.cpp.o -MF test/regex.p/regex.cpp.o.d -o test/regex.p/regex.cpp.o -c ../../SOURCE/libkiwix/test/regex.cpp
[6/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/meson-generated_.._.._static_libkiwix-resources.cpp.o -MF src/libkiwix.a.p/meson-generated_.._.._static_libkiwix-resources.cpp.o.d -o src/libkiwix.a.p/meson-generated_.._.._static_libkiwix-resources.cpp.o -c static/libkiwix-resources.cpp
[7/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/meson-generated_.._.._static_libkiwix-i18n-resources.cpp.o -MF src/libkiwix.a.p/meson-generated_.._.._static_libkiwix-i18n-resources.cpp.o.d -o src/libkiwix.a.p/meson-generated_.._.._static_libkiwix-i18n-resources.cpp.o -c static/libkiwix-i18n-resources.cpp
[8/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/bookmark.cpp.o -MF src/libkiwix.a.p/bookmark.cpp.o.d -o src/libkiwix.a.p/bookmark.cpp.o -c ../../SOURCE/libkiwix/src/bookmark.cpp
[9/102] ccache c++ -Itest/library.p -Iinclude -I../../SOURCE/libkiwix/include -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -DCURL_STATICLIB -pthread -isystem../../SOURCE/libkiwix/subprojects/googletest-release-1.8.1/googletest -isystemsubprojects/googletest-release-1.8.1/googletest -isystem../../SOURCE/libkiwix/subprojects/googletest-release-1.8.1/googletest/include -MD -MQ test/library.p/library.cpp.o -MF test/library.p/library.cpp.o.d -o test/library.p/library.cpp.o -c ../../SOURCE/libkiwix/test/library.cpp
[10/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/book.cpp.o -MF src/libkiwix.a.p/book.cpp.o.d -o src/libkiwix.a.p/book.cpp.o -c ../../SOURCE/libkiwix/src/book.cpp
[11/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/manager.cpp.o -MF src/libkiwix.a.p/manager.cpp.o.d -o src/libkiwix.a.p/manager.cpp.o -c ../../SOURCE/libkiwix/src/manager.cpp
[12/102] ccache c++ -Itest/library.p -Iinclude -I../../SOURCE/libkiwix/include -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -DCURL_STATICLIB -pthread -isystem../../SOURCE/libkiwix/subprojects/googletest-release-1.8.1/googletest -isystemsubprojects/googletest-release-1.8.1/googletest -isystem../../SOURCE/libkiwix/subprojects/googletest-release-1.8.1/googletest/include -MD -MQ test/library.p/.._subprojects_googletest-release-1.8.1_googletest_src_gtest-all.cc.o -MF test/library.p/.._subprojects_googletest-release-1.8.1_googletest_src_gtest-all.cc.o.d -o test/library.p/.._subprojects_googletest-release-1.8.1_googletest_src_gtest-all.cc.o -c ../../SOURCE/libkiwix/subprojects/googletest-release-1.8.1/googletest/src/gtest-all.cc
[13/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/libxml_dumper.cpp.o -MF src/libkiwix.a.p/libxml_dumper.cpp.o.d -o src/libkiwix.a.p/libxml_dumper.cpp.o -c ../../SOURCE/libkiwix/src/libxml_dumper.cpp
[14/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/opds_dumper.cpp.o -MF src/libkiwix.a.p/opds_dumper.cpp.o.d -o src/libkiwix.a.p/opds_dumper.cpp.o -c ../../SOURCE/libkiwix/src/opds_dumper.cpp
[15/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/downloader.cpp.o -MF src/libkiwix.a.p/downloader.cpp.o.d -o src/libkiwix.a.p/downloader.cpp.o -c ../../SOURCE/libkiwix/src/downloader.cpp
[16/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/library_dumper.cpp.o -MF src/libkiwix.a.p/library_dumper.cpp.o.d -o src/libkiwix.a.p/library_dumper.cpp.o -c ../../SOURCE/libkiwix/src/library_dumper.cpp
[17/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/html_dumper.cpp.o -MF src/libkiwix.a.p/html_dumper.cpp.o.d -o src/libkiwix.a.p/html_dumper.cpp.o -c ../../SOURCE/libkiwix/src/html_dumper.cpp
[18/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/subprocess.cpp.o -MF src/libkiwix.a.p/subprocess.cpp.o.d -o src/libkiwix.a.p/subprocess.cpp.o -c ../../SOURCE/libkiwix/src/subprocess.cpp
[19/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/server.cpp.o -MF src/libkiwix.a.p/server.cpp.o.d -o src/libkiwix.a.p/server.cpp.o -c ../../SOURCE/libkiwix/src/server.cpp
[20/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/tools_base64.cpp.o -MF src/libkiwix.a.p/tools_base64.cpp.o.d -o src/libkiwix.a.p/tools_base64.cpp.o -c ../../SOURCE/libkiwix/src/tools/base64.cpp
[21/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/aria2.cpp.o -MF src/libkiwix.a.p/aria2.cpp.o.d -o src/libkiwix.a.p/aria2.cpp.o -c ../../SOURCE/libkiwix/src/aria2.cpp
[22/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/library.cpp.o -MF src/libkiwix.a.p/library.cpp.o.d -o src/libkiwix.a.p/library.cpp.o -c ../../SOURCE/libkiwix/src/library.cpp
FAILED: src/libkiwix.a.p/library.cpp.o
ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/library.cpp.o -MF src/libkiwix.a.p/library.cpp.o.d -o src/libkiwix.a.p/library.cpp.o -c ../../SOURCE/libkiwix/src/library.cpp
In file included from /kiwix-build/./BUILD_native_static/INSTALL/include/xapian.h:80,
                 from ../../SOURCE/libkiwix/src/library.cpp:37:
/kiwix-build/./BUILD_native_static/INSTALL/include/xapian/queryparser.h: In member function ‘void Xapian::QueryParser::add_valuerangeprocessor(Xapian::ValueRangeProcessor*)’:
/kiwix-build/./BUILD_native_static/INSTALL/include/xapian/queryparser.h:1266:26: error: ‘void Xapian::QueryParser::add_valuerangeprocessor(Xapian::ValueRangeProcessor*)’ is deprecated [-Werror=deprecated-declarations]
 1266 |  add_rangeprocessor((new ShimRangeProcessor(vrproc))->release());
      |                          ^~~~~~~~~~~~~~~~~~
In file included from /kiwix-build/./BUILD_native_static/INSTALL/include/xapian/types.h:28,
                 from /kiwix-build/./BUILD_native_static/INSTALL/include/xapian.h:47,
                 from ../../SOURCE/libkiwix/src/library.cpp:37:
/kiwix-build/./BUILD_native_static/INSTALL/include/xapian/queryparser.h:1246:28: note: declared here
 1246 |     XAPIAN_DEPRECATED(void add_valuerangeprocessor(Xapian::ValueRangeProcessor * vrproc)) {
      |                            ^~~~~~~~~~~~~~~~~~~~~~~
/kiwix-build/./BUILD_native_static/INSTALL/include/xapian/deprecated.h:50:32: note: in definition of macro ‘XAPIAN_DEPRECATED’
   50 | #  define XAPIAN_DEPRECATED(D) D __attribute__((__deprecated__))
      |                                ^
cc1plus: all warnings being treated as errors
[23/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/tools_regexTools.cpp.o -MF src/libkiwix.a.p/tools_regexTools.cpp.o.d -o src/libkiwix.a.p/tools_regexTools.cpp.o -c ../../SOURCE/libkiwix/src/tools/regexTools.cpp
[24/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/tools_pathTools.cpp.o -MF src/libkiwix.a.p/tools_pathTools.cpp.o.d -o src/libkiwix.a.p/tools_pathTools.cpp.o -c ../../SOURCE/libkiwix/src/tools/pathTools.cpp
[25/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/tools_stringTools.cpp.o -MF src/libkiwix.a.p/tools_stringTools.cpp.o.d -o src/libkiwix.a.p/tools_stringTools.cpp.o -c ../../SOURCE/libkiwix/src/tools/stringTools.cpp
[26/102] ccache c++ -Isrc/libkiwix.a.p -Isrc -I../../SOURCE/libkiwix/src -Iinclude -I../../SOURCE/libkiwix/include -Istatic -I/kiwix-build/./BUILD_native_static/INSTALL/include -I/kiwix-build/BUILD_native_static/INSTALL/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c++11 -O0 -g -fPIC -DCURL_STATICLIB -pthread -MD -MQ src/libkiwix.a.p/search_renderer.cpp.o -MF src/libkiwix.a.p/search_renderer.cpp.o.d -o src/libkiwix.a.p/search_renderer.cpp.o -c ../../SOURCE/libkiwix/src/search_renderer.cpp
ninja: build stopped: subcommand failed.

@kelson42
Copy link
Collaborator

kelson42 commented Apr 26, 2023

Now that issue is fixed. A slight remaining defect is that the addressbar URL is still not updated when a PDF file is loaded/displayed in the viewer.

IMO, this should better be fixed. URL should match content.

@kelson42
Copy link
Collaborator

kelson42 commented May 3, 2023

@mgautierfr What has to be fixed (which ticket are we talking about) so @rgaudin can compile properly?
@veloman-yunkan Can you please update the URL bar?

@mgautierfr
Copy link
Member

This is kiwix/kiwix-build#599

@kelson42
Copy link
Collaborator

kelson42 commented May 3, 2023

@rgaudin You should be able to compile/test easily now. Let us know.

@rgaudin
Copy link
Member

rgaudin commented May 3, 2023

No, I can compile on Linux now but I still can't on macOS due to the gtest issue.

Copy link
Member

@rgaudin rgaudin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as described: PDF is rendered properly and home button is now working.

As indicated in the PR, the URL is not updated so it's not possible to share the URL to a PDF that is being rendered in the viewer.

@veloman-yunkan
Copy link
Collaborator Author

@veloman-yunkan Can you please update the URL bar?

Under Firefox sandboxing of the viewer content and cross-origin restrictions (PDF-viewer is not considered same origin) prevent the viewer JS code from finding out the URL of the PDF. A partial workaround is to intercept click events for links and use that information instead but that won't work if the PDF is loaded not as a result of the user clicking on a direct link (e.g. via JS).

@kelson42
Copy link
Collaborator

kelson42 commented May 28, 2023

@veloman-yunkan I'm not sure about the current status of this PR. It seems to be fixed but the URL is wrong. Do you confirm?
@veloman-yunkan Can you plase rebase (and fix conflict)?
@rgaudin @mgautierfr @Jaifroid Is that something we should give up on and live with?

@Jaifroid
Copy link
Member

My view is that if this PR fixes the most glaring aspect of the issue minus the URL problem, then at least you've increased usability, even if it isn't perfect (yet). Merging this to the dev server would allow testing for those of us who can't compile it.

Having said that, in Kiwix JS we no longer even attempt to open PDFs in the iframe as they are considered cross-origin and therefore not only a (slight) security risk, but also are blocked by some browsers with a sandboxed iframe. We simply have to treat them as external content, like https:// URLs, OpenOffice/Word documents, and epubs.

@kelson42
Copy link
Collaborator

@Jaifroid thx, so if i understand right, the most obvious solutions to the url problem are either:

  • live with it (merge and see if something better can be done later) or
  • force download and open via third party software

@Jaifroid
Copy link
Member

If I remember rightly (I'm getting confused!), the solution adopted here for showing PDFs in the iframe was not to serve sandbox headers when loading a PDF. It's probably best not to go back on that PR, or we'll really be going round in circles.... (The problem here relates to the fact that some browsers consider PDFs to be cross-origin.)

Which leaves "live with it", unless someone can see a better solution. Maybe things will become clearer once this and #946 (in whatever form) are merged, and can be thoroughly tested before deployment.

@rgaudin
Copy link
Member

rgaudin commented May 29, 2023

@Jaifroid thx, so if i understand right, the most obvious solutions to the url problem are either:
* live with it (merge and see if something better can be done later) or

There's one partial solution that @veloman-yunkan indicated that would work for links to PDFs. I think it's worth implementing. But I'd advise we merge this and open a ticket to fix it separately (or find another solution) as @Jaifroid suggests.

* force download and open via third party software

Not sure we can afford that. We have thousands of Android devices with no PDF external reader accessing PDF files in the field. Maybe we should test on said devices if their browser includes PDF rendering and if it gets triggered and used the @Jaifroid way.

@Jaifroid
Copy link
Member

Not sure we can afford that. We have thousands of Android devices with no PDF external reader accessing PDF files in the field. Maybe we should test on said devices if their browser includes PDF rendering

Ooh, does Kiwix Serve run on Android, or does the Android app depend on it in some way? If so, it's an important consideration. My phone asks me which app I want to use to open a PDF when a Web site offers one to me: would this be any different?

@rgaudin
Copy link
Member

rgaudin commented May 29, 2023

I am referring to Kiwix Hotspot setups composed of RaspberryPis running kiwix-serve accessed by old Android Tablets without PDF readers

@Jaifroid
Copy link
Member

OK, I'm all for taking into account support for old devices! From a quick look, lilote_fr_test_2023-01.zim doesn't appear to serve its PDFs in a special way (i.e. it doesn't appear to load a non-browser-provided pdf.js or similar). I know Firefox uses pdf.js internally, but it's not the default browser on Android, and it's probably not the same as using pdf.js explicitly -- since that would render the PDF as HTML, maybe it wouldn't have the same cross-origin problems. Definitely a separate issue!

@codecov
Copy link

codecov bot commented May 31, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (af2dfdc) 38.88% compared to head (c1ad65d) 38.88%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #940   +/-   ##
=======================================
  Coverage   38.88%   38.88%           
=======================================
  Files          56       56           
  Lines        3973     3973           
  Branches     2186     2186           
=======================================
  Hits         1545     1545           
  Misses       1097     1097           
  Partials     1331     1331           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@veloman-yunkan
Copy link
Collaborator Author

@veloman-yunkan I'm not sure about the current status of this PR. It seems to be fixed but the URL is wrong. Do you confirm?

Yes

@veloman-yunkan Can you plase rebase (and fix conflict)?

Done

static/skin/viewer.js Outdated Show resolved Hide resolved
@kelson42
Copy link
Collaborator

kelson42 commented Jun 7, 2023

@veloman-yunkan Can you please fix the last details so we can move forward?

In firefox, when PDF content is displayed in the viewer, changing the
viewer URL in the address bar had no effect. The most prominent
manifestation of this bug was the broken book home button but the same
issue was present even if the fragment component of the viewer URL was
edited manually. The bug was a result of

1. an optimization preventing any actions if the new content URL is the
   same as the old content URL (this was needed to break the infinite loop
   of mutual updates of the top-window and content window/iframe URLs when
   any one of them changes).

2. sandboxing of the iframe and inability to access the content URL in
   iframe because of cross-origin restrictions when the content is a PDF
   displayed by the builtin viewer.

Now that issue is fixed. A slight remaining defect is that the
addressbar URL is still not updated when a PDF file is loaded/displayed
in the viewer.
@kelson42 kelson42 merged commit 144945c into main Jun 8, 2023
@kelson42 kelson42 deleted the fix_for_issue912 branch June 8, 2023 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Book Home button not working as expected
5 participants