$OpenBSD$ index 2dd4c5f..7b80f8e 100644 --- dom/base/nsScreen.cpp.orig Fri Feb 20 15:40:37 2015 +++ dom/base/nsScreen.cpp Fri Feb 20 15:40:37 2015 @@ -67,6 +67,9 @@ NS_IMPL_RELEASE_INHERITED(nsScreen, DOMEventTargetHelper) int32_t nsScreen::GetPixelDepth(ErrorResult& aRv) { + // For non-chrome callers, always return 24 to prevent fingerprinting. + if (!IsChrome()) return 24; + nsDeviceContext* context = GetDeviceContext(); if (!context) { @@ -110,6 +113,9 @@ nsScreen::GetDeviceContext() nsresult nsScreen::GetRect(nsRect& aRect) { + // For non-chrome callers, return window inner rect to prevent fingerprinting. + if (!IsChrome()) return GetWindowInnerRect(aRect); + nsDeviceContext *context = GetDeviceContext(); if (!context) { @@ -129,6 +135,9 @@ nsScreen::GetRect(nsRect& aRect) nsresult nsScreen::GetAvailRect(nsRect& aRect) { + // For non-chrome callers, return window inner rect to prevent fingerprinting. + if (!IsChrome()) return GetWindowInnerRect(aRect); + nsDeviceContext *context = GetDeviceContext(); if (!context) { @@ -165,22 +174,26 @@ nsScreen::Notify(const hal::ScreenConfiguration& aConfiguration) void nsScreen::GetMozOrientation(nsString& aOrientation) { - switch (mOrientation) { - case eScreenOrientation_PortraitPrimary: - aOrientation.AssignLiteral("portrait-primary"); - break; - case eScreenOrientation_PortraitSecondary: - aOrientation.AssignLiteral("portrait-secondary"); - break; - case eScreenOrientation_LandscapePrimary: + if (!IsChrome()) { aOrientation.AssignLiteral("landscape-primary"); - break; - case eScreenOrientation_LandscapeSecondary: - aOrientation.AssignLiteral("landscape-secondary"); - break; - case eScreenOrientation_None: - default: - MOZ_CRASH("Unacceptable mOrientation value"); + } else { + switch (mOrientation) { + case eScreenOrientation_PortraitPrimary: + aOrientation.AssignLiteral("portrait-primary"); + break; + case eScreenOrientation_PortraitSecondary: + aOrientation.AssignLiteral("portrait-secondary"); + break; + case eScreenOrientation_LandscapePrimary: + aOrientation.AssignLiteral("landscape-primary"); + break; + case eScreenOrientation_LandscapeSecondary: + aOrientation.AssignLiteral("landscape-secondary"); + break; + case eScreenOrientation_None: + default: + MOZ_CRASH("Unacceptable mOrientation value"); + } } } @@ -359,3 +372,43 @@ nsScreen::FullScreenEventListener::HandleEvent(nsIDOMEvent* aEvent) return NS_OK; } + +bool +nsScreen::IsChrome() +{ + nsCOMPtr owner = GetOwner(); + if (owner && owner->GetDocShell()) { + return owner->GetDocShell()->ItemType() == nsIDocShellTreeItem::typeChrome; + } + return false; +} + +nsresult +nsScreen::GetDOMWindow(nsIDOMWindow **aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + *aResult = NULL; + + nsCOMPtr owner = GetOwner(); + if (!owner) + return NS_ERROR_FAILURE; + + nsCOMPtr win = do_QueryInterface(owner); + NS_ENSURE_STATE(win); + win.swap(*aResult); + + return NS_OK; +} + +nsresult +nsScreen::GetWindowInnerRect(nsRect& aRect) +{ + aRect.x = 0; + aRect.y = 0; + nsCOMPtr win; + nsresult rv = GetDOMWindow(getter_AddRefs(win)); + NS_ENSURE_SUCCESS(rv, rv); + rv = win->GetInnerWidth(&aRect.width); + NS_ENSURE_SUCCESS(rv, rv); + return win->GetInnerHeight(&aRect.height); +}