Skip to content
  • Igor Kushnir's avatar
    Documentation view: fix overriding CSS on Web Engine pages · 8ec324c8
    Igor Kushnir authored
    The current runJavaScript()-based code doesn't work for two reasons:
    1. The URL passed to StandardDocumentationView::setOverrideCss() always
    points to a local file (file:///) in practice. Qt WebEngine does not
    allow loading such local resources.
    2. The JavaScript code passed to runJavaScript() attempts to manipulate
    DOM but runs before the HTML document is loaded, and therefore has no
    effect.
    
    Fix the local file security issue (1) by embedding CSS inline instead of
    referencing an external CSS file.
    
    Fix the JavaScript execution timing issue (2) by replacing
    runJavaScript() with QWebEngineScript injected at DocumentReady point.
    
    Don't override CSS in ManPageDocumentation::documentationWidget() if the
    CSS file was not found.
    
    This gets rid of the following warnings in KDevelop's output:
      js: Not allowed to load local resource: file:///tmp/kdevelop.qWHueg
      js: Not allowed to load local resource: file:///usr/share/kdevmanpage/manpagedocumentation.css
    
    manpagedocumentation.css is applied to man pages now: the top banner and
    the extra margins are removed.
    8ec324c8