Bug 534113 - [Webkit] (On one client) Webkit opens an html file for download due to incorrect mime configuration on system.
Summary: [Webkit] (On one client) Webkit opens an html file for download due to incorr...
Status: REOPENED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.8   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-04-26 15:33 EDT by Leo Ufimtsev CLA
Modified: 2024-03-06 08:07 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Leo Ufimtsev CLA 2018-04-26 15:33:33 EDT
Continuation from:
533545 – [GTK3.22][Webkit2][regression] Crash on opening html file
https://bugs.eclipse.org/bugs/show_bug.cgi?id=533545

The crash was fixed, but Andrey Loskutov is reporting that for a particular *.html file, the download manager opens instead of rendering the webpage.

Attaching two files to this ticket:
- aboutBAD.html causes browser to open the download manager continuously (20 times). A video of this behavior is observed here:
https://bugs.eclipse.org/bugs/attachment.cgi?id=273681
- aboutGOOD.html opens in browser as expected.


The noticeable difference is the header. It has an xhtml specification:
### aboutBAD.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

### aboutGOOD.html
<!DOCTYPE html>
<html>


Andrey has the following environment:
- RHEL 7.4 with KDE desktop manager
- Eclipse Build I20180411-2000 (i.e, up to date).
- webkitgtk4-2.14.7-2.el7.x86_64  (I.e, Webkit2).

I tried to reproduce it with a RHEL 7.4 with Gnome and a RHEL 7.4 KDE setup, but have not experienced the same issue myself.

I read the webkit code and found that webkit will try to download file types that it cannot show.

       long /*int*/ mime_type = WebKitGTK.webkit_uri_response_get_mime_type(response);
       boolean canShow = WebKitGTK.webkit_web_view_can_show_mime_type (webView, mime_type) != 0;
       System.out.println("SWT INFO: mime type: " + getString(mime_type) + "  canShow?:"+ canShow);
       if (!canShow) {
           WebKitGTK.webkit_policy_decision_download (decision);
       See: https://git.eclipse.org/r/#/c/121420/


We then started to investigate mime types. On my RHEL 7.4 & Fedora, when I run xdg-mime to identify mime type:
xdg-mime query filetype ~/Download/aboutBAD.html 
xdg-mime query filetype ~/Download/aboutGOOD.html 
(or 'file --mime-type aboutBAD.html')

I get: 'text/html'. However Andrey Loskutov reports that his system returns 'application/xhtml+xml'.

I.e, this issue appears to be caused by Andrey's RHEL system reading the file as 'application/xhtml+xml' and subsequently webkitgtk deciding that this type of file cannot be rendered. This leads to a download popup.

This issue appears to be outside of SWT (and webkitgtk) and is instead specific to Andrey's RHEL configuration, as it doesn't occur on my test vms.

This might have been caused by some application installing a mime type that overrides the default one.

I have a theory:
Problem: Andrey's MIME database may be miss-configured on his system or been altered by some application that was installed.
  (I'm suspecting things like additional web browsers other than the built in once??).

  The type hints that the file is associated with an application as oppose to being text : 'application/...'  ? (idk?)

Solution: Fix mime type database.

I don't know how to fix the mime database, I haven't done it before. Also, I think it's different depending on your desktop manager.

Afaik, Gnome and KDE have different ways of dealing with mime types, because KDE and GNOMe are listed as separate implementors of mime database:
https://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec/

So you might have to hunt around and try to figure out how to change KDE's mime associations, so that the about*.html is read as html.
Maybe try kde-config ?

Maybe useful:
https://www.freedesktop.org/wiki/Specifications/mime-apps-spec/
https://webkit.org/blog/68/understanding-html-xml-and-xhtml/
https://www.linuxquestions.org/questions/programming-9/linux-command-to-convert-modify-or-change-mime-types-of-files-4175430291/
https://stackoverflow.com/questions/30931/register-file-extensions-mime-types-in-linux
https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html
https://unix.stackexchange.com/questions/33217/how-to-add-mimetype-bindings
https://askubuntu.com/questions/179865/how-do-i-change-the-mime-type-for-a-file
https://unix.stackexchange.com/questions/33217/how-to-add-mimetype-bindings
  "I am not 100% sure, but I think xdg-open relies on what you set in 'file types' in your KDE's configuration. I guess you are on KDE, so open KDE system settings and specify that file type."

~ Hope this is of some help?



At this point, since it only occurs on your (Andrey's) system, it's a bit difficult for me to investigate as I would grep around/hunt around various files on the system to investigate further. I'm kinda stuck here without being able to reproduce the issue locally.

If you can find a way to reproduce the issue where RHEL's file command:
'file --mime-type aboutBAD.html'
outputs the (incorrect?) application/html-xml and list the steps to reproduce, I could potentially try to find out why the mime type is miss behaving.

Let me know if I can help further.
Comment 1 Leo Ufimtsev CLA 2018-05-07 10:49:15 EDT
@Andrey  For bugzilla house keeping, I'm closing this bug for now as the remaining download window issue seems to be specific to the mime problem on your system. I.e, I cannot reproduce the issue despite best efforts.

However, if you find a way to reproduce it on a general Linux/Rhel box, then please feel free to reopen the bug and post steps to reproduce.

Thank you for reporting the webkit crash in the linked ticket and please feel free to submit further bugs if you come across any.
Comment 2 Andrey Loskutov CLA 2021-01-20 01:57:07 EST
Happens to others as well.
Comment 3 Phil Beauvoir CLA 2022-09-02 12:04:55 EDT
For reference, one user of our RCP app has just come across this exact thing:

https://github.com/archimatetool/archi/issues/866

The HTML files also have the same XHTML header as these are in Eclipse Help file format.
Comment 4 Thomas Piekarski CLA 2024-03-06 08:07:53 EST
Are there any updates about this issue? 

We just stumbled upon this and wanted to check in and ask if some progress has been made. 

Otherwise bump :-)