mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
cbff465051
- Bug 1167420 - Handle fallible AppendElement call in netwerk/base/Dashboard.cpp. r=valentin (a485b8990) - Bug 968520 - Add mozilla::fallible to FallibleTArray::AppendElement calls. r=froydnj (12a529a0e) - Bug 1172584 - Avoid coping FallibleTArray in SendRequestRunnable constructor. r=dragana (c3a4a4253) - Bug 948466: Rename gfxPangoFonts to gfxFontconfigFonts. r=nical (43eed1f5f) - Bug 968520 - Add mozilla::fallible to more FallibleTArray calls. r=froydnj (339968a1d) - Bug 1166544 - Assume successful InsertElementAt calls in DOMSVG*List::MaybeInsertNullInAnimValListAt. r=dholbert (cf687dad7) - Bug 968520 - Add mozilla::fallible to FallibleTArray::InsertElementAt calls. r=froydnj (cc5c68ff2) - Bug 968520 - Add mozilla::fallible to more FallibleTArray::InsertElementsAt calls. r=froydnj (66df1d034) - Bug 1165735 - Make ThreadSharedFloatArrayBufferList::mContents infallible. r=roc (eda2839db) - Bug 1166544 - Use ReplaceElementAt instead of Clear and InsertElementAt in SVGMotionSMILType::Add. r=dholbert (474887a8c) - Bug 1167418 - Check AppendElement call in MediaQueryList. r=heycam (b6ed6d153) - Bug 1167418 - Use nsTArray instead of FallibleTArray in MediaQueryList. r=heycam (c9e3816d0) - Bug 1167418 - Follow-up: Fix bustage (5015e91ce) - Bug 1174220 - Part 1: Remove capacity constructor of MediaLargeByteBuffer. r=jya (66819d3e4) - Bug 1179282 - Use nsTArray::Assign instead of the assignment operator in dom/svg/. r=dholbert (cb3d43c19) - Bug 968520 - Add nsTArray::Assign. r=froydnj (e5eccf354) - Bug 1182277, don't leak when using nsAutoTArray inside nsTArray, r=nfroyd (bba32394c) - Bug 1143575. Avoid including Android's GraphicBuffer.h from LayersTypes.h. r=nical (99e4e2816) - Bug 1143575. Avoid use of COMPARE macro which can clash with Android headers. r=bent (99cfc74c4) - Bug 1143575. Add RefBase #include to stagefright stubs. r=cpearce (f9e327600) - Bug 1143575. test_HaveMetadataUnbufferedSeek should not wait for canplay since preload='metadata' elements may not fire canplay. r=cpearce (f1b0eee27) - Bug 1143575. Make GL context current before cleaning up programs. r=nical (d7b05b2bd) - partial Bug 1143575. Android's screenshotting code should invalidate the LayrManagerComposite to ensure composition will actually happen. r=nical (58fb296ab) - Bug 1143575. Remove unused Image::IsSentToCompositor tracking. r=nical (808d0b3f0) - Bug 1143575. Remove unused CompositionNotifySink. r=nical (98a332305) - Bug 1143575. Remove unused VideoFrameContainer::Reset. r=nical (e292bc722) - Bug 1143575. Rename mAsyncTransactionTrackeres to mAsyncTransactionTrackers. r=nical (df71ebf4f) - Bug 1143575. Remove unused ImageContainer::ResetPaintCount. r=nical (a92c5bf6e) - Bug 1143575. Remove unused VideoFrameContainer::ClearCurrentFrame aResetSize parameter. r=nical (5d3c9b83a) - Bug 1143575. Remove unused ReturnReleaseFence. r=nical (9d6ea92b5) - Bug 1143575. LayerManagerComposite can't get END_NO_COMPOSITE. r=mattwoodrow (0c5c364b5) - Bug 1143575. Remove unused AttachAsyncCompositable overload. r=nical (5fd3d4f6d) - Bug 1143575. Rename ImageBridgeChild's AutoRemoteTextures to AutoRemoveTexturesFromImageBridge to avoid clashes with later work. r=nical (34d67fcc0) - Bug 1143575. Fix some code formatting. r=nical (1d7f30f60) - Bug 1143575. Move mLayer from ImageClientBridge up into its superclass ImageClient. r=nical (40c902a36) - Bug 1127336 - Label HW-decoded frames with correct origin. - r=vlad (fd1580bcd) - Bug 1167504 - Part 1: Remove BindableName - Framebuffer. r=jgilbert (b3133eee6) - Bug 1167504 - Part 2: Remove BindableName - Renderbuffer. r=jgilbert (155a7e796) - Bug 1167504 - Part 3: Remove BindableName - Sampler. r=jgilbert (8c5c68960) - Bug 1167504 - Part 4: Remove BindableName - Texture. r=jgilbert (28077db04) - Bug 1167504 - Part 5: Remove BindableName - Transform Feedback. r=jgilbert (4fd839598) - Bug 1170454: Fix up instance type for VAOs. r=smaug,r=jgilbert (cc62d993a) - Bug 1167504 - Part 6: Remove BindableName - Vertex Array. r=jgilbert (1d54d5bc1) - Bug 1048724 - Implement GetBufferSubData. r=jgilbert, r=smaug (06570aa84) - Bug 1167504 - Part 7: Remove BindableName - Buffer. r=jgilbert (b2ddf3fc6)
419 lines
12 KiB
C++
419 lines
12 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "mozilla/Hal.h"
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
|
#include "mozilla/dom/ScreenBinding.h"
|
|
#include "nsScreen.h"
|
|
#include "nsIDocument.h"
|
|
#include "nsIDocShell.h"
|
|
#include "nsIDocument.h"
|
|
#include "nsPresContext.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsIDocShellTreeItem.h"
|
|
#include "nsLayoutUtils.h"
|
|
#include "nsJSUtils.h"
|
|
#include "nsDeviceContext.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::dom;
|
|
|
|
/* static */ already_AddRefed<nsScreen>
|
|
nsScreen::Create(nsPIDOMWindow* aWindow)
|
|
{
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
if (!aWindow->GetDocShell()) {
|
|
return nullptr;
|
|
}
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo =
|
|
do_QueryInterface(static_cast<nsPIDOMWindow*>(aWindow));
|
|
NS_ENSURE_TRUE(sgo, nullptr);
|
|
|
|
nsRefPtr<nsScreen> screen = new nsScreen(aWindow);
|
|
|
|
hal::RegisterScreenConfigurationObserver(screen);
|
|
hal::ScreenConfiguration config;
|
|
hal::GetCurrentScreenConfiguration(&config);
|
|
screen->mOrientation = config.orientation();
|
|
|
|
return screen.forget();
|
|
}
|
|
|
|
nsScreen::nsScreen(nsPIDOMWindow* aWindow)
|
|
: DOMEventTargetHelper(aWindow)
|
|
, mEventListener(nullptr)
|
|
{
|
|
}
|
|
|
|
nsScreen::~nsScreen()
|
|
{
|
|
MOZ_ASSERT(!mEventListener);
|
|
hal::UnregisterScreenConfigurationObserver(this);
|
|
}
|
|
|
|
|
|
// QueryInterface implementation for nsScreen
|
|
NS_INTERFACE_MAP_BEGIN(nsScreen)
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMScreen)
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsScreen, DOMEventTargetHelper)
|
|
NS_IMPL_RELEASE_INHERITED(nsScreen, DOMEventTargetHelper)
|
|
|
|
int32_t
|
|
nsScreen::GetPixelDepth(ErrorResult& aRv)
|
|
{
|
|
// Return 24 to prevent fingerprinting.
|
|
if (ShouldResistFingerprinting()) {
|
|
return 24;
|
|
}
|
|
|
|
nsDeviceContext* context = GetDeviceContext();
|
|
|
|
if (!context) {
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
return -1;
|
|
}
|
|
|
|
uint32_t depth;
|
|
context->GetDepth(depth);
|
|
return depth;
|
|
}
|
|
|
|
#define FORWARD_LONG_GETTER(_name) \
|
|
NS_IMETHODIMP \
|
|
nsScreen::Get ## _name(int32_t* aOut) \
|
|
{ \
|
|
ErrorResult rv; \
|
|
*aOut = Get ## _name(rv); \
|
|
return rv.StealNSResult(); \
|
|
}
|
|
|
|
FORWARD_LONG_GETTER(AvailWidth)
|
|
FORWARD_LONG_GETTER(AvailHeight)
|
|
FORWARD_LONG_GETTER(Width)
|
|
FORWARD_LONG_GETTER(Height)
|
|
|
|
FORWARD_LONG_GETTER(Top)
|
|
FORWARD_LONG_GETTER(Left)
|
|
FORWARD_LONG_GETTER(AvailTop)
|
|
FORWARD_LONG_GETTER(AvailLeft)
|
|
|
|
FORWARD_LONG_GETTER(PixelDepth)
|
|
FORWARD_LONG_GETTER(ColorDepth)
|
|
|
|
nsDeviceContext*
|
|
nsScreen::GetDeviceContext()
|
|
{
|
|
return nsLayoutUtils::GetDeviceContextForScreenInfo(GetOwner());
|
|
}
|
|
|
|
nsresult
|
|
nsScreen::GetRect(nsRect& aRect)
|
|
{
|
|
// Return window inner rect to prevent fingerprinting.
|
|
if (ShouldResistFingerprinting()) {
|
|
return GetWindowInnerRect(aRect);
|
|
}
|
|
|
|
nsDeviceContext *context = GetDeviceContext();
|
|
|
|
if (!context) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
context->GetRect(aRect);
|
|
|
|
aRect.x = nsPresContext::AppUnitsToIntCSSPixels(aRect.x);
|
|
aRect.y = nsPresContext::AppUnitsToIntCSSPixels(aRect.y);
|
|
aRect.height = nsPresContext::AppUnitsToIntCSSPixels(aRect.height);
|
|
aRect.width = nsPresContext::AppUnitsToIntCSSPixels(aRect.width);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsScreen::GetAvailRect(nsRect& aRect)
|
|
{
|
|
// Return window inner rect to prevent fingerprinting.
|
|
if (ShouldResistFingerprinting()) {
|
|
return GetWindowInnerRect(aRect);
|
|
}
|
|
|
|
nsDeviceContext *context = GetDeviceContext();
|
|
|
|
if (!context) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
context->GetClientRect(aRect);
|
|
|
|
aRect.x = nsPresContext::AppUnitsToIntCSSPixels(aRect.x);
|
|
aRect.y = nsPresContext::AppUnitsToIntCSSPixels(aRect.y);
|
|
aRect.height = nsPresContext::AppUnitsToIntCSSPixels(aRect.height);
|
|
aRect.width = nsPresContext::AppUnitsToIntCSSPixels(aRect.width);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
nsScreen::Notify(const hal::ScreenConfiguration& aConfiguration)
|
|
{
|
|
ScreenOrientation previousOrientation = mOrientation;
|
|
mOrientation = aConfiguration.orientation();
|
|
|
|
NS_ASSERTION(mOrientation == eScreenOrientation_PortraitPrimary ||
|
|
mOrientation == eScreenOrientation_PortraitSecondary ||
|
|
mOrientation == eScreenOrientation_LandscapePrimary ||
|
|
mOrientation == eScreenOrientation_LandscapeSecondary,
|
|
"Invalid orientation value passed to notify method!");
|
|
|
|
if (mOrientation != previousOrientation) {
|
|
DispatchTrustedEvent(NS_LITERAL_STRING("mozorientationchange"));
|
|
}
|
|
}
|
|
|
|
void
|
|
nsScreen::GetMozOrientation(nsString& aOrientation)
|
|
{
|
|
if (ShouldResistFingerprinting()) {
|
|
aOrientation.AssignLiteral("landscape-primary");
|
|
} 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");
|
|
}
|
|
}
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsScreen::GetSlowMozOrientation(nsAString& aOrientation)
|
|
{
|
|
nsString orientation;
|
|
GetMozOrientation(orientation);
|
|
aOrientation = orientation;
|
|
return NS_OK;
|
|
}
|
|
|
|
nsScreen::LockPermission
|
|
nsScreen::GetLockOrientationPermission() const
|
|
{
|
|
nsCOMPtr<nsPIDOMWindow> owner = GetOwner();
|
|
if (!owner) {
|
|
return LOCK_DENIED;
|
|
}
|
|
|
|
// Chrome can always lock the screen orientation.
|
|
nsIDocShell* docShell = owner->GetDocShell();
|
|
if (docShell && docShell->ItemType() == nsIDocShellTreeItem::typeChrome) {
|
|
return LOCK_ALLOWED;
|
|
}
|
|
|
|
nsCOMPtr<nsIDocument> doc = owner->GetDoc();
|
|
if (!doc || doc->Hidden()) {
|
|
return LOCK_DENIED;
|
|
}
|
|
|
|
// Apps can always lock the screen orientation.
|
|
if (doc->NodePrincipal()->GetAppStatus() >=
|
|
nsIPrincipal::APP_STATUS_INSTALLED) {
|
|
return LOCK_ALLOWED;
|
|
}
|
|
|
|
// Other content must be full-screen in order to lock orientation.
|
|
return doc->MozFullScreen() ? FULLSCREEN_LOCK_ALLOWED : LOCK_DENIED;
|
|
}
|
|
|
|
bool
|
|
nsScreen::MozLockOrientation(const nsAString& aOrientation, ErrorResult& aRv)
|
|
{
|
|
nsString orientation(aOrientation);
|
|
Sequence<nsString> orientations;
|
|
if (!orientations.AppendElement(orientation, fallible)) {
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
return false;
|
|
}
|
|
return MozLockOrientation(orientations, aRv);
|
|
}
|
|
|
|
bool
|
|
nsScreen::MozLockOrientation(const Sequence<nsString>& aOrientations,
|
|
ErrorResult& aRv)
|
|
{
|
|
ScreenOrientation orientation = eScreenOrientation_None;
|
|
|
|
for (uint32_t i = 0; i < aOrientations.Length(); ++i) {
|
|
const nsString& item = aOrientations[i];
|
|
|
|
if (item.EqualsLiteral("portrait")) {
|
|
orientation |= eScreenOrientation_PortraitPrimary |
|
|
eScreenOrientation_PortraitSecondary;
|
|
} else if (item.EqualsLiteral("portrait-primary")) {
|
|
orientation |= eScreenOrientation_PortraitPrimary;
|
|
} else if (item.EqualsLiteral("portrait-secondary")) {
|
|
orientation |= eScreenOrientation_PortraitSecondary;
|
|
} else if (item.EqualsLiteral("landscape")) {
|
|
orientation |= eScreenOrientation_LandscapePrimary |
|
|
eScreenOrientation_LandscapeSecondary;
|
|
} else if (item.EqualsLiteral("landscape-primary")) {
|
|
orientation |= eScreenOrientation_LandscapePrimary;
|
|
} else if (item.EqualsLiteral("landscape-secondary")) {
|
|
orientation |= eScreenOrientation_LandscapeSecondary;
|
|
} else if (item.EqualsLiteral("default")) {
|
|
orientation |= eScreenOrientation_Default;
|
|
} else {
|
|
// If we don't recognize the token, we should just return 'false'
|
|
// without throwing.
|
|
return false;
|
|
}
|
|
}
|
|
|
|
switch (GetLockOrientationPermission()) {
|
|
case LOCK_DENIED:
|
|
return false;
|
|
case LOCK_ALLOWED:
|
|
return hal::LockScreenOrientation(orientation);
|
|
case FULLSCREEN_LOCK_ALLOWED: {
|
|
// We need to register a listener so we learn when we leave full-screen
|
|
// and when we will have to unlock the screen.
|
|
// This needs to be done before LockScreenOrientation call to make sure
|
|
// the locking can be unlocked.
|
|
nsCOMPtr<EventTarget> target = do_QueryInterface(GetOwner()->GetDoc());
|
|
if (!target) {
|
|
return false;
|
|
}
|
|
|
|
if (!hal::LockScreenOrientation(orientation)) {
|
|
return false;
|
|
}
|
|
|
|
// We are fullscreen and lock has been accepted.
|
|
if (!mEventListener) {
|
|
mEventListener = new FullScreenEventListener();
|
|
}
|
|
|
|
aRv = target->AddSystemEventListener(NS_LITERAL_STRING("mozfullscreenchange"),
|
|
mEventListener, /* useCapture = */ true);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// This is only for compilers that don't understand that the previous switch
|
|
// will always return.
|
|
MOZ_CRASH("unexpected lock orientation permission value");
|
|
}
|
|
|
|
void
|
|
nsScreen::MozUnlockOrientation()
|
|
{
|
|
hal::UnlockScreenOrientation();
|
|
|
|
if (!mEventListener) {
|
|
return;
|
|
}
|
|
|
|
// Remove event listener in case of fullscreen lock.
|
|
nsCOMPtr<EventTarget> target = do_QueryInterface(GetOwner()->GetDoc());
|
|
if (target) {
|
|
target->RemoveSystemEventListener(NS_LITERAL_STRING("mozfullscreenchange"),
|
|
mEventListener, /* useCapture */ true);
|
|
}
|
|
|
|
mEventListener = nullptr;
|
|
}
|
|
|
|
bool
|
|
nsScreen::IsDeviceSizePageSize()
|
|
{
|
|
nsPIDOMWindow* owner = GetOwner();
|
|
if (owner) {
|
|
nsIDocShell* docShell = owner->GetDocShell();
|
|
if (docShell) {
|
|
return docShell->GetDeviceSizeIsPageSize();
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/* virtual */
|
|
JSObject*
|
|
nsScreen::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
|
{
|
|
return ScreenBinding::Wrap(aCx, this, aGivenProto);
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS(nsScreen::FullScreenEventListener, nsIDOMEventListener)
|
|
|
|
NS_IMETHODIMP
|
|
nsScreen::FullScreenEventListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
{
|
|
#ifdef DEBUG
|
|
nsAutoString eventType;
|
|
aEvent->GetType(eventType);
|
|
|
|
MOZ_ASSERT(eventType.EqualsLiteral("mozfullscreenchange"));
|
|
#endif
|
|
|
|
nsCOMPtr<EventTarget> target = aEvent->InternalDOMEvent()->GetCurrentTarget();
|
|
MOZ_ASSERT(target);
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(target);
|
|
MOZ_ASSERT(doc);
|
|
|
|
// We have to make sure that the event we got is the event sent when
|
|
// fullscreen is disabled because we could get one when fullscreen
|
|
// got enabled if the lock call is done at the same moment.
|
|
if (doc->MozFullScreen()) {
|
|
return NS_OK;
|
|
}
|
|
|
|
target->RemoveSystemEventListener(NS_LITERAL_STRING("mozfullscreenchange"),
|
|
this, true);
|
|
|
|
hal::UnlockScreenOrientation();
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsScreen::GetWindowInnerRect(nsRect& aRect)
|
|
{
|
|
aRect.x = 0;
|
|
aRect.y = 0;
|
|
nsCOMPtr<nsIDOMWindow> win = GetOwner();
|
|
if (!win) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
nsresult rv = win->GetInnerWidth(&aRect.width);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
return win->GetInnerHeight(&aRect.height);
|
|
}
|
|
|
|
bool nsScreen::ShouldResistFingerprinting() const
|
|
{
|
|
bool resist = false;
|
|
nsCOMPtr<nsPIDOMWindow> owner = GetOwner();
|
|
if (owner) {
|
|
resist = nsContentUtils::ShouldResistFingerprinting(owner->GetDocShell());
|
|
}
|
|
return resist;
|
|
}
|