Did some research with this:
-Does the UA always for each PDF open, or only the first PDF load
-Only the first time
-Can we load pdfs in an iframe, does this trigger the bug?
-PDFs do load in iframes, but don't trigger the bug.
-Can we detect PDF loads?
-They have a nil URL in their request object when webViewDidStartLoad is called, but not webViewDidFinishLoad nor shouldLoad
-It's likely that we could identify a PDF in our NSURLProtocol handler, but only if we proxy the request
So..., some possible Solutions:
#1 - After loading first page, load a background UIWebView with a PDF (maybe even use data URL)
#2 - Detect PDF load (via the nil URL), and let it load without changing the user-agent.
- Make sure the load works by temporarily adding the URL to the container's whitelist
- If the user tries to navigate anywhere else with the UIWebView, close it and make a new one
- This method still messes things up if there are more than one active CDV webviews
#3 - Block all PDF loads
- Not sure this is easy to do without proxying every request, which has other side-effects
I think the first option is probably the best for starters, it's possible the the UA bug is triggered from some sub-system being loaded the first time a PDF is loaded, and so doing it every time will cause the app to use more memory than it requires. Maybe we could have a user-pref that would allow the bug work-around to be disabled if they are sure that their app can't be used to navigate to a PDF, or if they don't use a whitelist anyways.