Declares the URL variable globally. If the feature is not
supported, the variable will still be declared, but have the
"undefined" value.
Supported by:
- Firefox 4
Firefox 21 in Web worker
- Chrome 8 (prefixed as webkitURL), 23+ unprefixed
Chrome 10 (prefixed as webkitURL) in Web Worker, 23+ unprefixed
- Opera 15
Opera 15 in Web Worker
- Internet Explorer 10
Internet Explorer 11 in Web Worker
- Safari 6 (prefixed as webkitURL)
Safari 6 (prefixed as webkitURL) in Web Worker
This feature relies on URL.createObjectURL, which is supported by
- Firefox 4
- Chrome 8
- Opera 15
- Internet Explorer 10
If the feature is missing, it falls back to downloading from the server.
The environment-specific code are put in ifdef's. Two methods are
defined:
- noData
This function is used as a fallback in case of failure, it triggers
a download directly from the server.
- triggerSaveAs(String url, optional String blob)
This function attempts to show a Save As dialog for a given URL.
It attempts to use the a.download attribute, if available, and
falls back to window.open(<url>, '_parent') if unavailable.
See also http://caniuse.com/download
The Chrome extension activates PDF.js by inserting the script tags
in a document whose URL and location origin is identical to the PDF
file.
Because of this, the path './images/' was resolved relatively to the
location of the PDF file instead of the extension.
To fix this, the IMAGE_DIR constant is moved outside the local scope,
to allow extensions/chrome/insertviewer.js to override the value.
Originally, the IMAGE_DIR variable was a global variable, but commit
f8f4b3f45d moved the global variable
to the local scope, causing the extension to malfunction.
Impact: low, the only consequence is that some rarely used images
were not visible.
Trivial test:
At the center of page 2, the annotation icon
(images/annotation-comment.svg) should be visible:
http://linorg.usp.br/CTAN/macros/latex/contrib/pdfcomment/doc/pdfcomment.pdf
Fix download button for top frames and sub frames
When PDF.js is the top frame, and the PDF URL is identical to
the top URL, download would fail. Fixed by adding a ? or & in these
cases.
When PDF.js is embedded in a frame from a different origin, download
would fail because window.open(url, '_parent') is ignored.
Fixed by using a.click() when available.
a.click() works in Chrome 25, Firefox 19, Opera 12.00 and IE 8.
Safari 5.1 does not support a.click()
Use a.download if available + documentation
Previously, when the XHTML doctype + header is active, checks
would fail because a <div>'s tag name is "div" instead of "DIV".
document.activeElement does not exist in Chrome for XHTML documents
== -> ===