Bug 1502448 - work around principal issues with pdfjs and saving local files, r=jkt,jaws
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 07 Jan 2019 16:59:26 +0000
changeset 452739 d0b51a908becadca797abc743899bd7f06dafb63
parent 452738 42dc31f0985903d0c3a55d18439d52a843c21e3a
child 452740 4b9c119d25c32828cf82027ab26a4a6175058dff
push id75563
push usergijskruitbosch@gmail.com
push dateMon, 07 Jan 2019 17:20:23 +0000
treeherderautoland@d0b51a908bec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjkt, jaws
bugs1502448
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1502448 - work around principal issues with pdfjs and saving local files, r=jkt,jaws Differential Revision: https://phabricator.services.mozilla.com/D15568
toolkit/content/contentAreaUtils.js
--- a/toolkit/content/contentAreaUtils.js
+++ b/toolkit/content/contentAreaUtils.js
@@ -157,16 +157,35 @@ function saveImageURL(aURL, aFileName, a
 // This is like saveDocument, but takes any browser/frame-like element
 // and saves the current document inside it,
 // whether in-process or out-of-process.
 function saveBrowser(aBrowser, aSkipPrompt, aOuterWindowID = 0) {
   if (!aBrowser) {
     throw "Must have a browser when calling saveBrowser";
   }
   let persistable = aBrowser.frameLoader;
+  // Because of how pdf.js deals with principals, saving the document the "normal"
+  // way won't work. Work around this by saving the pdf's URL directly:
+  if (aBrowser.contentPrincipal.URI &&
+      aBrowser.contentPrincipal.URI.spec == "resource://pdf.js/web/viewer.html" &&
+      aBrowser.currentURI.schemeIs("file")) {
+    let correctPrincipal = Services.scriptSecurityManager.createCodebasePrincipal(
+        aBrowser.currentURI, aBrowser.contentPrincipal.originAttributes);
+    internalSave(aBrowser.currentURI.spec,
+                 null /* no document */, null /* automatically determine filename */,
+                 null /* no content disposition */,
+                 "application/pdf", false /* don't bypass cache */,
+                 null /* no alternative title */, null /* no auto-chosen file info */,
+                 null /* null referrer will be OK for file: */,
+                 null /* no document */, aSkipPrompt /* caller decides about prompting */,
+                 null /* no cache key because the one for the document will be for pdfjs */,
+                 PrivateBrowsingUtils.isWindowPrivate(aBrowser.ownerGlobal),
+                 correctPrincipal);
+    return;
+  }
   let stack = Components.stack.caller;
   persistable.startPersistence(aOuterWindowID, {
     onDocumentReady(document) {
       saveDocument(document, aSkipPrompt);
     },
     onError(status) {
       throw new Components.Exception("saveBrowser failed asynchronously in startPersistence",
                                      status, stack);