Skip to content
  • Stefano Crocco's avatar
    Restore the ability to view man and info pages from Konqueror · d0842c88
    Stefano Crocco authored
    Summary:
    Add a QWebEngineUrlSchemeHandler which uses `KIO::get` to produce HTML code to be sent using `QWebEngineUrlRequestJob::reply`. This scheme handler is added whenever `WebEnginePart::openUrl` is called for an URL for which `KProtocolManager::defaultMimetype` returns `text/html`.
    
    The basic idea is taken from the implementation used in the `webengine_stream` branch, but instead of changing the way `KonqView::openUrl` works, it only adds the appropriate scheme handler.
    
    The main issue for this implementation to work is that QWebEngine refuses to load local resources in the generated HTML (images and CSS files) because of cross-origin rules. The only way to work around this limitation that I could think of is to parse the HTML code produced by `KIO::get` and to replace, in `img` and `link` elements the URL with a `data` URL embedding the content of the file. To do this, the scheme handler uses the external program **htmltidy** to convert the HTML generated by KIO into `XHTML`, then uses `QDomDocument` to parse the resulting XHTML file and replace the URLs appropriately. If one of these two steps fails, the original HTML will be used: this means that the user won't be able to see most of the formatting in the man/info pages but will be able to read the text.
    
    Unfortunately, there's still a problem I couldn't solve: some resources in the HTML produced by KIO use a `help` URL rather than the standard `file` one, but I couldn't find out to which file they point, so they aren't changed, meaning that the page is not displayed completely as it was intended.
    
    Test Plan: Open man and info pages from location bar and following links between such pages.
    
    Reviewers: dfaure
    
    Reviewed By: dfaure
    
    Subscribers: pino
    
    Differential Revision: https://phabricator.kde.org/D13924
    d0842c88