Bug 1537955 - Do not spoof DevicePixelRatio for pdfs r=Ehsan
authorTom Ritter <tom@mozilla.com>
Fri, 02 Aug 2019 04:10:09 +0000
changeset 485867 85385b4957e3dc1d043817d0d539ae01e6d6c8bf
parent 485866 f980c4db1343283ffae1c018b12a604a199ffed2
child 485868 a351f679051364c93fd7b014960537a45599c6dc
push id36376
push usermalexandru@mozilla.com
push dateFri, 02 Aug 2019 09:48:35 +0000
treeherdermozilla-central@5ced3811411e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1537955
milestone70.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 1537955 - Do not spoof DevicePixelRatio for pdfs r=Ehsan pdfs should not have a way to exfiltrate the true device pixel ratio, so it is safe to provide the correct value, enabling them to be rendered correctly. Differential Revision: https://phabricator.services.mozilla.com/D39994
dom/base/nsGlobalWindowOuter.cpp
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -3731,17 +3731,28 @@ double nsGlobalWindowOuter::GetDevicePix
   }
 
   RefPtr<nsPresContext> presContext = mDocShell->GetPresContext();
   if (!presContext) {
     return 1.0;
   }
 
   if (nsContentUtils::ResistFingerprinting(aCallerType)) {
-    return 1.0;
+    // Spoofing the DevicePixelRatio causes blurriness in some situations
+    // on HiDPI displays. pdf.js is a non-system caller; but it can't
+    // expose the fingerprintable information, so we can safely disable
+    // spoofing in this situation. It doesn't address the issue for
+    // web-rendered content (including pdf.js instances on the web.)
+    // In the future we hope to have a better solution to fix all HiDPI
+    // blurriness...
+    nsAutoCString origin;
+    nsresult rv = this->GetPrincipal()->GetOrigin(origin);
+    if (NS_FAILED(rv) || origin != NS_LITERAL_CSTRING("resource://pdf.js")) {
+      return 1.0;
+    }
   }
 
   float overrideDPPX = presContext->GetOverrideDPPX();
 
   if (overrideDPPX > 0) {
     return overrideDPPX;
   }