Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mullvad Browser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dan Ballard
Mullvad Browser
Commits
a22dea6e
Commit
a22dea6e
authored
1 year ago
by
ma1
Committed by
Pier Angelo Vendrame
10 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Bug 41631: Prevent weird initial window dimensions caused by subpixel computations
parent
1ee14db7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
toolkit/components/resistfingerprinting/RFPHelper.sys.mjs
+79
-46
79 additions, 46 deletions
toolkit/components/resistfingerprinting/RFPHelper.sys.mjs
with
79 additions
and
46 deletions
toolkit/components/resistfingerprinting/RFPHelper.sys.mjs
+
79
−
46
View file @
a22dea6e
...
...
@@ -21,16 +21,31 @@ const kPrefLetterboxingGradient =
const
kTopicDOMWindowOpened
=
"
domwindowopened
"
;
var
logConsole
;
function
log
(
msg
)
{
if
(
!
logConsole
)
{
logConsole
=
console
.
createInstance
({
prefix
:
"
RFPHelper.jsm
"
,
maxLogLevelPref
:
"
privacy.resistFingerprinting.jsmloglevel
"
,
})
;
}
const
lazy
=
{}
;
XPCOMUtils
.
defineLazyGetter
(
lazy
,
"
logConsole
"
,
()
=>
console
.
createInstance
({
prefix
:
"
RFPHelper.jsm
"
,
maxLogLevelPref
:
"
privacy.resistFingerprinting.jsmloglevel
"
,
})
);
logConsole
.
log
(
msg
);
function
log
(...
args
)
{
lazy
.
logConsole
.
log
(...
args
);
}
function
forEachWindow
(
callback
)
{
const
windowList
=
Services
.
wm
.
getEnumerator
(
"
navigator:browser
"
);
while
(
windowList
.
hasMoreElements
())
{
const
win
=
windowList
.
getNext
();
if
(
win
.
gBrowser
&&
!
win
.
closed
)
{
try
{
callback
(
win
);
}
catch
(
e
)
{
lazy
.
logConsole
.
error
(
e
);
}
}
}
}
class
_RFPHelper
{
...
...
@@ -170,7 +185,11 @@ class _RFPHelper {
(
this
.
rfpEnabled
=
Services
.
prefs
.
getBoolPref
(
kPrefResistFingerprinting
))
)
{
this
.
_addRFPObservers
();
Services
.
ww
.
registerNotification
(
this
);
forEachWindow
(
win
=>
this
.
_attachWindow
(
win
));
}
else
{
forEachWindow
(
win
=>
this
.
_detachWindow
(
win
));
Services
.
ww
.
unregisterNotification
(
this
);
this
.
_removeRFPObservers
();
}
}
...
...
@@ -310,12 +329,12 @@ class _RFPHelper {
}
_handleLetterboxingPrefChanged
()
{
if
(
Services
.
prefs
.
getBoolPref
(
kPrefLetterboxing
,
false
))
{
Services
.
ww
.
registerNotification
(
this
);
this
.
_attachAllWindows
();
}
else
{
this
.
_detachAllWindows
();
Services
.
ww
.
unregisterNotification
(
this
);
this
.
letterboxingEnabled
=
Services
.
prefs
.
getBoolPref
(
kPrefLetterboxing
,
false
);
if
(
this
.
rfpEnabled
)
{
forEachWindow
(
win
=>
this
.
_updateSizeForTabsInWindow
(
win
)
);
}
}
...
...
@@ -415,11 +434,13 @@ class _RFPHelper {
let
logPrefix
=
`_roundContentSize[
${
Math
.
random
()}
]`
;
log
(
logPrefix
);
let
win
=
aBrowser
.
ownerGlobal
;
let
browserContainer
=
aBrowser
.
getTabBrowser
()
.
getBrowserContainer
(
aBrowser
);
let
browserParent
=
aBrowser
.
parentElement
;
browserParent
.
classList
.
remove
(
"
exclude-letterboxing
"
);
let
[
[
contentWidth
,
contentHeight
],
[
parentWidth
,
parentHeight
],
...
...
@@ -432,6 +453,17 @@ class _RFPHelper {
])
);
const
isInitialSize
=
win
.
_rfpOriginalSize
&&
win
.
outerWidth
===
win
.
_rfpOriginalSize
.
width
&&
win
.
outerHeight
===
win
.
_rfpOriginalSize
.
height
;
// We may need to shrink this window to rounded size if the browser container
// area is taller than the original, meaning extra chrome (like the optional
// "Only Show on New Tab" bookmarks toobar) was present and now gone.
const
needToShrink
=
isInitialSize
&&
containerHeight
>
win
.
_rfpOriginalSize
.
containerHeight
;
log
(
`
${
logPrefix
}
contentWidth=
${
contentWidth
}
contentHeight=
${
contentHeight
}
parentWidth=
${
parentWidth
}
parentHeight=
${
parentHeight
}
containerWidth=
${
containerWidth
}
containerHeight=
${
containerHeight
}${
isNewTab
?
"
(new tab).
"
:
"
.
"
...
...
@@ -459,7 +491,10 @@ class _RFPHelper {
log
(
`
${
logPrefix
}
roundDimensions(
${
aWidth
}
,
${
aHeight
}
)`
);
let
result
;
if
(
!
(
isInitialSize
||
this
.
letterboxingEnabled
))
{
// just round size to int
return
r
(
aWidth
,
aHeight
);
}
// If the set is empty, we will round the content with the default
// stepping size.
...
...
@@ -511,9 +546,13 @@ class _RFPHelper {
try
{
change
();
}
catch
(
e
)
{
logConsole
.
error
(
e
);
lazy
.
logConsole
.
error
(
e
);
}
}
if
(
needToShrink
)
{
win
.
shrinkToLetterbox
();
this
.
_recordWindowSize
(
win
);
}
});
},
});
...
...
@@ -594,7 +633,6 @@ class _RFPHelper {
_updateSizeForTabsInWindow
(
aWindow
)
{
let
tabBrowser
=
aWindow
.
gBrowser
;
tabBrowser
.
tabpanels
?.
classList
.
add
(
"
letterboxing
"
);
tabBrowser
.
tabpanels
?.
classList
.
toggle
(
"
letterboxing-vcenter
"
,
...
...
@@ -612,9 +650,32 @@ class _RFPHelper {
// we need to add this class late because otherwise new windows get maximized
aWindow
.
setTimeout
(()
=>
{
tabBrowser
.
tabpanels
?.
classList
.
add
(
"
letterboxing-ready
"
);
if
(
!
aWindow
.
_rfpOriginalSize
)
{
this
.
_recordWindowSize
(
aWindow
);
}
});
}
_recordWindowSize
(
aWindow
)
{
aWindow
.
_rfpOriginalSize
=
{
width
:
aWindow
.
outerWidth
,
height
:
aWindow
.
outerHeight
,
containerHeight
:
aWindow
.
gBrowser
.
getBrowserContainer
()?.
clientHeight
,
};
log
(
"
Recording original window size
"
,
aWindow
.
_rfpOriginalSize
);
}
// We will attach this method to each browser window. When called
// it will instantly resize the window to exactly fit the selected
// (possibly letterboxed) browser.
shrinkToLetterbox
()
{
let
{
selectedBrowser
}
=
this
.
gBrowser
;
let
stack
=
selectedBrowser
.
closest
(
"
.browserStack
"
);
const
outer
=
stack
.
getBoundingClientRect
();
const
inner
=
selectedBrowser
.
getBoundingClientRect
();
this
.
resizeBy
(
inner
.
width
-
outer
.
width
,
inner
.
height
-
outer
.
height
);
}
_attachWindow
(
aWindow
)
{
aWindow
.
gBrowser
.
addTabsProgressListener
(
this
);
aWindow
.
addEventListener
(
"
TabOpen
"
,
this
);
...
...
@@ -632,20 +693,6 @@ class _RFPHelper {
this
.
_updateSizeForTabsInWindow
(
aWindow
);
}
_attachAllWindows
()
{
let
windowList
=
Services
.
wm
.
getEnumerator
(
"
navigator:browser
"
);
while
(
windowList
.
hasMoreElements
())
{
let
win
=
windowList
.
getNext
();
if
(
win
.
closed
||
!
win
.
gBrowser
)
{
continue
;
}
this
.
_attachWindow
(
win
);
}
}
_detachWindow
(
aWindow
)
{
let
tabBrowser
=
aWindow
.
gBrowser
;
tabBrowser
.
removeTabsProgressListener
(
this
);
...
...
@@ -663,20 +710,6 @@ class _RFPHelper {
}
}
_detachAllWindows
()
{
let
windowList
=
Services
.
wm
.
getEnumerator
(
"
navigator:browser
"
);
while
(
windowList
.
hasMoreElements
())
{
let
win
=
windowList
.
getNext
();
if
(
win
.
closed
||
!
win
.
gBrowser
)
{
continue
;
}
this
.
_detachWindow
(
win
);
}
}
_handleDOMWindowOpened
(
win
)
{
let
self
=
this
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment