WebView fails to load and display Webarchives from Mail and Notes

Originator:tempelmann
Number:rdar://13403911 Date Originated:12-Mar-2013 10:11 PM
Status:Open Resolved:
Product:Mac OS X Product Version:10.8.2
Classification:Other Bug Reproducible:Always
 
Summary:

NSWebView doesn't load webarchives that contain a base URL using a custom scheme such as "x-msg". This affects webarchives put into the pasteboard by Mail and Notes, for instance.

I found that this is caused by the webarchive containing a unusual URL reference, such as: "x-msg://4/". If I change that to start with "http" instead, or if I remove the entry entirely, then the problematic webviews load fine.

Steps to Reproduce:

I've attached a project. It comes with a webarchive as it was produced by Mail in the pasteboard, called "mail-bad.webarchive". You can open it in Safari to see that it contains some text. The demo project loads this archive into the WebFrame. It also loads a valid webarchive created by Safari.

Both get loaded into a WebView each. The "mail-bad" one doesn't display, while the "safari-good" displays fine.

The project also contains code that actively decodes the webarchive and removes the offending URL - if that code is activated, the load works fine even for the archive from Mail, proving that this is indeed an issue with the URL.

Notes:

What's odd is that not only Safari can show the "mail-bad.webarchive" (Safari might not be using the same WebKit APIs that us mere mortals can use), but it's curious that even Xcode displays the "mail-bad.webarchive" just fine. This suggests to me that this issue can be fixed in other ways than messing with the archive data directly, because I'm sure Xcode doesn't do that, either. So, Xcode must be doing something "right" that my demo code doesn't, which may mean that this isn't a real bug. But I had already contacted DTS with a TSI about this and they responded to file a bug instead.

Still, if there's a solution as it is used by Xcode, please communicate that back to me, as I don't really like messing with the archive contents directly, which is currently my only option, I hope you agree.

(Note just for Open Radar: the demo project is available here: http://files.tempel.org/Various/Mail-WebArchive-Display-Issue.zip )

Comments

Solved it!

After brooding over what Xcode might be doing I found a solution:

This does not work:

WebArchive *archive = [[WebArchive alloc] initWithData:webData];
[[webView mainFrame] loadArchive:archive];

But this does:

[[webView mainFrame] loadData:webData MIMEType:@"application/x-webarchive" textEncodingName:@"" baseURL:NULL];

So, the explicit function to load the archive is faulty while the one that wants an explicit URL, even though I give it none, works.

Go figure.

By tempelmann at March 12, 2013, 9:38 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!