Bug 1602347 - When asked for the DPI from an undisplayed subdocument, try to get it from ancestor documents before giving up and returning 1.0. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D84437
This commit is contained in:
Emilio Cobos Álvarez 2020-07-21 22:01:10 +00:00
Родитель f6b4b8e27c
Коммит 2cee4550de
2 изменённых файлов: 39 добавлений и 4 удалений

Просмотреть файл

@ -25,6 +25,7 @@
#include "mozilla/dom/BrowserChild.h"
#include "mozilla/dom/BrowsingContextBinding.h"
#include "mozilla/dom/ContentFrameMessageManager.h"
#include "mozilla/dom/DocumentInlines.h"
#include "mozilla/dom/EventTarget.h"
#include "mozilla/dom/LocalStorage.h"
#include "mozilla/dom/LSObject.h"
@ -3855,13 +3856,28 @@ float nsGlobalWindowOuter::GetMozInnerScreenYOuter(CallerType aCallerType) {
}
double nsGlobalWindowOuter::GetDevicePixelRatioOuter(CallerType aCallerType) {
if (!mDocShell) {
if (NS_WARN_IF(!mDoc)) {
return 1.0;
}
RefPtr<nsPresContext> presContext = mDocShell->GetPresContext();
if (!presContext) {
return 1.0;
RefPtr<nsPresContext> presContext = mDoc->GetPresContext();
if (NS_WARN_IF(!presContext)) {
// We're in an undisplayed subdocument... There's not really an awesome way
// to tell what the right DPI is from here, so we try to walk up our parent
// document chain to the extent that the docs can observe each other.
Document* doc = mDoc;
while (doc->StyleOrLayoutObservablyDependsOnParentDocumentLayout()) {
doc = doc->GetInProcessParentDocument();
presContext = doc->GetPresContext();
if (presContext) {
break;
}
}
if (!presContext) {
// Still nothing, oh well.
return 1.0;
}
}
if (nsContentUtils::ResistFingerprinting(aCallerType)) {

Просмотреть файл

@ -0,0 +1,19 @@
<!doctype html>
<link rel="help" href="https://drafts.csswg.org/cssom-view/#dom-window-devicepixelratio">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1602347">
<link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez">
<link rel="author" href="https://mozilla.org" title="Mozilla">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<title>window.devicePixelRatio in an undisplayed iframe matches the dpi of the parent document</title>
<div style="display: none">
<iframe src="about:blank"></iframe>
</div>
<script>
onload = function() {
test(function() {
let win = document.querySelector("iframe").contentWindow;
assert_equals(win.devicePixelRatio, window.devicePixelRatio, "window.devicePixelRatio in an undisplayed iframe matches the dpi of the parent document");
});
};
</script>