operasoftware / pdf.js

PDF Reader in JavaScript
Apache License 2.0
20 stars 4 forks source link

What is the purpose of insertFakeXML? #2

Closed Rob--W closed 10 years ago

Rob--W commented 11 years ago

I've audited the source of https://addons.opera.com/en/extensions/details/pdf-viewer, and noticed that it slightly differs from the source in this repository.

At the background page, insertFakeXML is called right after detecting that the captured request is a PDF file. This function inserts a content script, and dispatches a message to the tab.

In the content script, the message is handled as follows:

else if (message && message.type === 'showFakeXML' &&
  message.url === location.href) {
    window.stop();
    document.body.textContent = '';
  }

What is the purpose of this addition? The only functional difference from the original code is that the new code is also activated for PDF downloads (triggered by PDF.js).

pdfHandler.js (the background script) looks like this at the moment:

insertFakeXML(details.tabId, details.url);
if (isPdfDownloadable(details)) { ..........cut..............
  return;
}
// Replace frame's content with the PDF viewer
// This approach maintains the friendly URL in the location bar
activatePDFJSForTab(details.tabId, details.url);

This change seems unnecessary to me, because activatePDFJSForTab does the same (+one thing more) as insertFakeXML. Did you have a specific reason for this change?

miketaylr commented 11 years ago

Hey @Rob--W. The motivations for this tweak are purely cosmetic. On OSX, we found you could still see the "flash of unhidden XML error page", or FOUXEP as everyone calls it for a split second when viewing a PDF. Which is strange, admittedly. This was (at least last week) also reproducible on Canary.

insertFakeXML was basically a quick fix so we could release the extension. We'll have to take a closer look to see what the real issue is.

Rob--W commented 11 years ago

I think that the FOUXEP is unavoidable. For example, keep F5 pressed, and the FOUXEP will constanty be shown (because the viewer did not get a chance to load).

This method was used to maintain a "nice" URL in the omnibox, because Chromium 27 and earlier just show a blank space for extension URLs.

Chrome 28+ shows a long chrome-extension://EXTENSION-ID-HERE/web/viewer.html?file=URL-ENCODED-URL-HERE. Which option would you prefer, FOUXEP or that long URL?

5953lc commented 11 years ago

I'm not sure why I'm getting this email about FOUXEP or insertFakeXML.

I'd prefer not seeing anything at all since 1) there's nothing to display 2) crappy web programming ? :) 3) the faster that PDF.js works the better as far as I'm concerned...

Thanks though for all the great work - it's lovely not having to load Adobe.

On Fri, Jul 5, 2013 at 9:08 AM, Rob Wu notifications@github.com wrote:

I think that the FOUXEP is unavoidable. For example, keep F5 pressed, and the FOUXEP will constanty be shown (because the viewer did not get a chance to load).

This method was used to maintain a "nice" URL in the omnibox, because Chromium 27 and earlier just show a blank space for extension URLs.

Chrome 28+ shows a long chrome-extension://EXTENSION-ID-HERE/web/viewer.html?file=URL-ENCODED-URL-HERE. Which option would you prefer, FOUXEP or that long URL?

— Reply to this email directly or view it on GitHubhttps://github.com/operasoftware/pdf.js/issues/2#issuecomment-20526640 .