Bug 1486772 - Refactor the screen-orientation types and headers r=smaug
authorGabriele Svelto <gsvelto@mozilla.com>
Wed, 29 Aug 2018 20:54:56 +0000
changeset 489057 000a3f46f36c9c400d35af815c7b19a9db6f7a9a
parent 489056 1d6495af4aa99c430e42a32551a488a9449201fb
child 489058 16710b8f5b70af0c3a4543d937222c58e7b3c2e6
push id9738
push useraciure@mozilla.com
push dateMon, 03 Sep 2018 16:13:51 +0000
treeherdermozilla-beta@f5841408a66c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1486772
milestone63.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 1486772 - Refactor the screen-orientation types and headers r=smaug This patch removes the 'ScreenOrientationInternal' type from dom/base/ScreenOrientation.h and moves it into the HalScreenConfiguration.h header, renaming it simply to 'ScreenOrientation' in the process. This has several knock-off effects: - It allows files that needed ScreenOrientationInternal to include a much smaller header than before - It greatly reduces the number of headers pulled in when including Hal.h - It clarifies the role of the type. The 'Internal' part in the name had nothing to do with it being part of the implementation. The type was public and called that way only to avoid clashing with the 'ScreenOrientation' class. Since we moved it into a different namespace it can be renamed safely. - It allows a file that was manually re-declaring 'ScreenConfigurationInternal' type to use the original one - Finally this fixes a few files which were missing headers they actually required but that would still build because unified compilation put them into units that already had those headers thanks to ScreenConfiguration.h Differential Revision: https://phabricator.services.mozilla.com/D4458
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
dom/base/ScreenOrientation.cpp
dom/base/ScreenOrientation.h
dom/base/nsScreen.cpp
dom/clients/manager/ClientOpenWindowUtils.cpp
dom/clients/manager/ClientPrefs.cpp
dom/ipc/DOMTypes.ipdlh
dom/ipc/TabChild.cpp
dom/ipc/TabChild.h
dom/ipc/TabParent.cpp
dom/ipc/TabParent.h
gfx/layers/client/ClientLayerManager.cpp
gfx/layers/composite/AsyncCompositionManager.cpp
gfx/layers/composite/AsyncCompositionManager.h
gfx/layers/ipc/LayersMessages.ipdlh
gfx/layers/ipc/ShadowLayers.cpp
gfx/layers/ipc/ShadowLayers.h
gfx/vr/ipc/VRManagerChild.h
hal/Hal.cpp
hal/Hal.h
hal/HalScreenConfiguration.h
hal/android/AndroidHal.cpp
hal/fallback/FallbackScreenConfiguration.cpp
hal/fallback/FallbackScreenConfiguration.h
hal/sandbox/PHal.ipdl
hal/sandbox/SandboxHal.cpp
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java
widget/android/AndroidBridge.cpp
widget/android/GeckoScreenOrientation.h
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -314,17 +314,17 @@ DecreasePrivateDocShellCount()
 nsDocShell::nsDocShell()
   : nsDocLoader()
   , mForcedCharset(nullptr)
   , mParentCharset(nullptr)
   , mTreeOwner(nullptr)
   , mChromeEventHandler(nullptr)
   , mDefaultScrollbarPref(Scrollbar_Auto, Scrollbar_Auto)
   , mCharsetReloadState(eCharsetReloadInit)
-  , mOrientationLock(eScreenOrientation_None)
+  , mOrientationLock(hal::eScreenOrientation_None)
   , mParentCharsetSource(0)
   , mMarginWidth(-1)
   , mMarginHeight(-1)
   , mItemType(typeContent)
   , mPreviousTransIndex(-1)
   , mLoadedTransIndex(-1)
   , mChildOffset(0)
   , mSandboxFlags(0)
@@ -2024,24 +2024,24 @@ nsDocShell::SetFullscreenAllowed(bool aF
     // propagate the value of the parent's "mozFullscreenAllowed" attribute
     // across process boundaries.
     return NS_ERROR_UNEXPECTED;
   }
   mFullscreenAllowed = (aFullscreenAllowed ? PARENT_ALLOWS : PARENT_PROHIBITS);
   return NS_OK;
 }
 
-ScreenOrientationInternal
+hal::ScreenOrientation
 nsDocShell::OrientationLock()
 {
   return mOrientationLock;
 }
 
 void
-nsDocShell::SetOrientationLock(ScreenOrientationInternal aOrientationLock)
+nsDocShell::SetOrientationLock(hal::ScreenOrientation aOrientationLock)
 {
   mOrientationLock = aOrientationLock;
 }
 
 NS_IMETHODIMP
 nsDocShell::GetMayEnableCharacterEncodingMenu(
     bool* aMayEnableCharacterEncodingMenu)
 {
@@ -10156,25 +10156,26 @@ nsDocShell::InternalLoad(nsIURI* aURI,
       return NS_OK;
     }
   }
 
   // Whenever a top-level browsing context is navigated, the user agent MUST
   // lock the orientation of the document to the document's default
   // orientation. We don't explicitly check for a top-level browsing context
   // here because orientation is only set on top-level browsing contexts.
-  if (OrientationLock() != eScreenOrientation_None) {
+  if (OrientationLock() != hal::eScreenOrientation_None) {
 #ifdef DEBUG
     nsCOMPtr<nsIDocShellTreeItem> parent;
     GetSameTypeParent(getter_AddRefs(parent));
     MOZ_ASSERT(!parent);
 #endif
-    SetOrientationLock(eScreenOrientation_None);
+    SetOrientationLock(hal::eScreenOrientation_None);
     if (mIsActive) {
-      ScreenOrientation::UpdateActiveOrientationLock(eScreenOrientation_None);
+      ScreenOrientation::UpdateActiveOrientationLock(
+        hal::eScreenOrientation_None);
     }
   }
 
   // Check for saving the presentation here, before calling Stop().
   // This is necessary so that we can catch any pending requests.
   // Since the new request has not been created yet, we pass null for the
   // new request parameter.
   // Also pass nullptr for the document, since it doesn't affect the return
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -3,16 +3,17 @@
 /* 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/. */
 
 #ifndef nsDocShell_h__
 #define nsDocShell_h__
 
 #include "mozilla/BasePrincipal.h"
+#include "mozilla/HalScreenConfiguration.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/Move.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/WeakPtr.h"
 
 #include "mozilla/dom/BrowsingContext.h"
@@ -64,17 +65,16 @@
 namespace mozilla {
 class Encoding;
 class HTMLEditor;
 enum class TaskCategory;
 namespace dom {
 class ClientInfo;
 class ClientSource;
 class EventTarget;
-typedef uint32_t ScreenOrientationInternal;
 } // namespace dom
 } // namespace mozilla
 
 class nsICommandManager;
 class nsIContentViewer;
 class nsIController;
 class nsIDocShellTreeOwner;
 class nsIDocument;
@@ -1014,19 +1014,17 @@ private: // data members
 
   nsIDocShellTreeOwner* mTreeOwner; // Weak Reference
   mozilla::dom::EventTarget* mChromeEventHandler; // Weak Reference
 
   nsIntPoint mDefaultScrollbarPref; // persistent across doc loads
 
   eCharsetReloadState mCharsetReloadState;
 
-  // The orientation lock as described by
-  // https://w3c.github.io/screen-orientation/
-  mozilla::dom::ScreenOrientationInternal mOrientationLock;
+  mozilla::hal::ScreenOrientation mOrientationLock;
 
   int32_t mParentCharsetSource;
   int32_t mMarginWidth;
   int32_t mMarginHeight;
 
   // This can either be a content docshell or a chrome docshell. After
   // Create() is called, the type is not expected to change.
   int32_t mItemType;
--- a/dom/base/ScreenOrientation.cpp
+++ b/dom/base/ScreenOrientation.cpp
@@ -29,44 +29,44 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(Scree
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ScreenOrientation)
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(ScreenOrientation, DOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(ScreenOrientation, DOMEventTargetHelper)
 
 static OrientationType
-InternalOrientationToType(ScreenOrientationInternal aOrientation)
+InternalOrientationToType(hal::ScreenOrientation aOrientation)
 {
   switch (aOrientation) {
-  case eScreenOrientation_PortraitPrimary:
+  case hal::eScreenOrientation_PortraitPrimary:
     return OrientationType::Portrait_primary;
-  case eScreenOrientation_PortraitSecondary:
+  case hal::eScreenOrientation_PortraitSecondary:
     return OrientationType::Portrait_secondary;
-  case eScreenOrientation_LandscapePrimary:
+  case hal::eScreenOrientation_LandscapePrimary:
     return OrientationType::Landscape_primary;
-  case eScreenOrientation_LandscapeSecondary:
+  case hal::eScreenOrientation_LandscapeSecondary:
     return OrientationType::Landscape_secondary;
   default:
     MOZ_CRASH("Bad aOrientation value");
   }
 }
 
-static ScreenOrientationInternal
+static hal::ScreenOrientation
 OrientationTypeToInternal(OrientationType aOrientation)
 {
   switch (aOrientation) {
   case OrientationType::Portrait_primary:
-    return eScreenOrientation_PortraitPrimary;
+    return hal::eScreenOrientation_PortraitPrimary;
   case OrientationType::Portrait_secondary:
-    return eScreenOrientation_PortraitSecondary;
+    return hal::eScreenOrientation_PortraitSecondary;
   case OrientationType::Landscape_primary:
-    return eScreenOrientation_LandscapePrimary;
+    return hal::eScreenOrientation_LandscapePrimary;
   case OrientationType::Landscape_secondary:
-    return eScreenOrientation_LandscapeSecondary;
+    return hal::eScreenOrientation_LandscapeSecondary;
   default:
     MOZ_CRASH("Bad aOrientation value");
   }
 }
 
 ScreenOrientation::ScreenOrientation(nsPIDOMWindowInner* aWindow, nsScreen* aScreen)
   : DOMEventTargetHelper(aWindow), mScreen(aScreen)
 {
@@ -116,34 +116,34 @@ class ScreenOrientation::LockOrientation
 {
   ~LockOrientationTask();
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   LockOrientationTask(ScreenOrientation* aScreenOrientation,
                       Promise* aPromise,
-                      ScreenOrientationInternal aOrientationLock,
+                      hal::ScreenOrientation aOrientationLock,
                       nsIDocument* aDocument,
                       bool aIsFullScreen);
 protected:
   bool OrientationLockContains(OrientationType aOrientationType);
 
   RefPtr<ScreenOrientation> mScreenOrientation;
   RefPtr<Promise> mPromise;
-  ScreenOrientationInternal mOrientationLock;
+  hal::ScreenOrientation mOrientationLock;
   nsCOMPtr<nsIDocument> mDocument;
   bool mIsFullScreen;
 };
 
 NS_IMPL_ISUPPORTS(ScreenOrientation::LockOrientationTask, nsIRunnable)
 
 ScreenOrientation::LockOrientationTask::LockOrientationTask(
   ScreenOrientation* aScreenOrientation, Promise* aPromise,
-  ScreenOrientationInternal aOrientationLock,
+  hal::ScreenOrientation aOrientationLock,
   nsIDocument* aDocument, bool aIsFullScreen)
   : mScreenOrientation(aScreenOrientation), mPromise(aPromise),
     mOrientationLock(aOrientationLock), mDocument(aDocument),
     mIsFullScreen(aIsFullScreen)
 {
   MOZ_ASSERT(aScreenOrientation);
   MOZ_ASSERT(aPromise);
   MOZ_ASSERT(aDocument);
@@ -175,17 +175,17 @@ ScreenOrientation::LockOrientationTask::
 
   if (mDocument->Hidden()) {
     // Active orientation lock is not the document's orientation lock.
     mPromise->MaybeResolveWithUndefined();
     mDocument->SetOrientationPendingPromise(nullptr);
     return NS_OK;
   }
 
-  if (mOrientationLock == eScreenOrientation_None) {
+  if (mOrientationLock == hal::eScreenOrientation_None) {
     mScreenOrientation->UnlockDeviceOrientation();
     mPromise->MaybeResolveWithUndefined();
     mDocument->SetOrientationPendingPromise(nullptr);
     return NS_OK;
   }
 
   ErrorResult rv;
   bool result = mScreenOrientation->LockDeviceOrientation(mOrientationLock,
@@ -196,60 +196,60 @@ ScreenOrientation::LockOrientationTask::
 
   if (NS_WARN_IF(!result)) {
     mPromise->MaybeReject(NS_ERROR_UNEXPECTED);
     mDocument->SetOrientationPendingPromise(nullptr);
     return NS_OK;
   }
 
   if (OrientationLockContains(mDocument->CurrentOrientationType()) ||
-      (mOrientationLock == eScreenOrientation_Default &&
+      (mOrientationLock == hal::eScreenOrientation_Default &&
        mDocument->CurrentOrientationAngle() == 0)) {
     // Orientation lock will not cause an orientation change.
     mPromise->MaybeResolveWithUndefined();
     mDocument->SetOrientationPendingPromise(nullptr);
   }
 
   return NS_OK;
 }
 
 already_AddRefed<Promise>
 ScreenOrientation::Lock(OrientationLockType aOrientation, ErrorResult& aRv)
 {
-  ScreenOrientationInternal orientation = eScreenOrientation_None;
+  hal::ScreenOrientation orientation = hal::eScreenOrientation_None;
 
   switch (aOrientation) {
   case OrientationLockType::Any:
-    orientation = eScreenOrientation_PortraitPrimary |
-                  eScreenOrientation_PortraitSecondary |
-                  eScreenOrientation_LandscapePrimary |
-                  eScreenOrientation_LandscapeSecondary;
+    orientation = hal::eScreenOrientation_PortraitPrimary |
+                  hal::eScreenOrientation_PortraitSecondary |
+                  hal::eScreenOrientation_LandscapePrimary |
+                  hal::eScreenOrientation_LandscapeSecondary;
     break;
   case OrientationLockType::Natural:
-    orientation |= eScreenOrientation_Default;
+    orientation |= hal::eScreenOrientation_Default;
     break;
   case OrientationLockType::Landscape:
-    orientation = eScreenOrientation_LandscapePrimary |
-                  eScreenOrientation_LandscapeSecondary;
+    orientation = hal::eScreenOrientation_LandscapePrimary |
+                  hal::eScreenOrientation_LandscapeSecondary;
     break;
   case OrientationLockType::Portrait:
-    orientation = eScreenOrientation_PortraitPrimary |
-                  eScreenOrientation_PortraitSecondary;
+    orientation = hal::eScreenOrientation_PortraitPrimary |
+                  hal::eScreenOrientation_PortraitSecondary;
     break;
   case OrientationLockType::Portrait_primary:
-    orientation = eScreenOrientation_PortraitPrimary;
+    orientation = hal::eScreenOrientation_PortraitPrimary;
     break;
   case OrientationLockType::Portrait_secondary:
-    orientation = eScreenOrientation_PortraitSecondary;
+    orientation = hal::eScreenOrientation_PortraitSecondary;
     break;
   case OrientationLockType::Landscape_primary:
-    orientation = eScreenOrientation_LandscapePrimary;
+    orientation = hal::eScreenOrientation_LandscapePrimary;
     break;
   case OrientationLockType::Landscape_secondary:
-    orientation = eScreenOrientation_LandscapeSecondary;
+    orientation = hal::eScreenOrientation_LandscapeSecondary;
     break;
   default:
     NS_WARNING("Unexpected orientation type");
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return nullptr;
   }
 
   return LockInternal(orientation, aRv);
@@ -278,17 +278,18 @@ AbortOrientationPromises(nsIDocShell* aD
       if (childShell) {
         AbortOrientationPromises(childShell);
       }
     }
   }
 }
 
 already_AddRefed<Promise>
-ScreenOrientation::LockInternal(ScreenOrientationInternal aOrientation, ErrorResult& aRv)
+ScreenOrientation::LockInternal(hal::ScreenOrientation aOrientation,
+                                ErrorResult& aRv)
 {
   // Steps to apply an orientation lock as defined in spec.
 
   nsIDocument* doc = GetResponsibleDocument();
   if (NS_WARN_IF(!doc)) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return nullptr;
   }
@@ -344,17 +345,17 @@ ScreenOrientation::LockInternal(ScreenOr
     return nullptr;
   }
 
   return p.forget();
 #endif
 }
 
 bool
-ScreenOrientation::LockDeviceOrientation(ScreenOrientationInternal aOrientation,
+ScreenOrientation::LockDeviceOrientation(hal::ScreenOrientation aOrientation,
                                          bool aIsFullScreen, ErrorResult& aRv)
 {
   if (!GetOwner()) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return false;
   }
 
   nsCOMPtr<EventTarget> target = do_QueryInterface(GetOwner()->GetDoc());
@@ -384,17 +385,17 @@ ScreenOrientation::LockDeviceOrientation
   }
 
   return true;
 }
 
 void
 ScreenOrientation::Unlock(ErrorResult& aRv)
 {
-  RefPtr<Promise> p = LockInternal(eScreenOrientation_None, aRv);
+  RefPtr<Promise> p = LockInternal(hal::eScreenOrientation_None, aRv);
 }
 
 void
 ScreenOrientation::UnlockDeviceOrientation()
 {
   hal::UnlockScreenOrientation();
 
   if (!mFullScreenListener || !GetOwner()) {
@@ -509,21 +510,21 @@ ScreenOrientation::Notify(const hal::Scr
     return;
   }
 
   nsIDocument* doc = GetResponsibleDocument();
   if (!doc) {
     return;
   }
 
-  ScreenOrientationInternal orientation = aConfiguration.orientation();
-  if (orientation != eScreenOrientation_PortraitPrimary &&
-      orientation != eScreenOrientation_PortraitSecondary &&
-      orientation != eScreenOrientation_LandscapePrimary &&
-      orientation != eScreenOrientation_LandscapeSecondary) {
+  hal::ScreenOrientation orientation = aConfiguration.orientation();
+  if (orientation != hal::eScreenOrientation_PortraitPrimary &&
+      orientation != hal::eScreenOrientation_PortraitSecondary &&
+      orientation != hal::eScreenOrientation_LandscapePrimary &&
+      orientation != hal::eScreenOrientation_LandscapeSecondary) {
     // The platform may notify of some other values from
     // an orientation lock, but we only care about real
     // changes to screen orientation which result in one of
     // the values we care about.
     return;
   }
 
   OrientationType previousOrientation = mType;
@@ -559,19 +560,20 @@ ScreenOrientation::Notify(const hal::Scr
                         this,
                         &ScreenOrientation::DispatchChangeEvent);
     rv = NS_DispatchToMainThread(runnable);
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToMainThread failed");
   }
 }
 
 void
-ScreenOrientation::UpdateActiveOrientationLock(ScreenOrientationInternal aOrientation)
+ScreenOrientation::UpdateActiveOrientationLock(
+  hal::ScreenOrientation aOrientation)
 {
-  if (aOrientation == eScreenOrientation_None) {
+  if (aOrientation == hal::eScreenOrientation_None) {
     hal::UnlockScreenOrientation();
   } else {
     DebugOnly<bool> ok = hal::LockScreenOrientation(aOrientation);
     NS_WARNING_ASSERTION(ok, "hal::LockScreenOrientation failed");
   }
 }
 
 void
--- a/dom/base/ScreenOrientation.h
+++ b/dom/base/ScreenOrientation.h
@@ -13,28 +13,16 @@
 #include "mozilla/HalScreenConfiguration.h"
 
 class nsScreen;
 
 namespace mozilla {
 namespace dom {
 
 class Promise;
-// Make sure that any change to ScreenOrientationInternal values are
-// also made in mobile/android/base/GeckoScreenOrientation.java
-typedef uint32_t ScreenOrientationInternal;
-
-static const ScreenOrientationInternal eScreenOrientation_None               = 0;
-static const ScreenOrientationInternal eScreenOrientation_PortraitPrimary    = 1u << 0;
-static const ScreenOrientationInternal eScreenOrientation_PortraitSecondary  = 1u << 1;
-static const ScreenOrientationInternal eScreenOrientation_LandscapePrimary   = 1u << 2;
-static const ScreenOrientationInternal eScreenOrientation_LandscapeSecondary = 1u << 3;
-//eScreenOrientation_Default will use the natural orientation for the deivce,
-//it could be PortraitPrimary or LandscapePrimary depends on display resolution
-static const ScreenOrientationInternal eScreenOrientation_Default            = 1u << 4;
 
 class ScreenOrientation final : public DOMEventTargetHelper,
                                 public mozilla::hal::ScreenConfigurationObserver
 {
   // nsScreen has deprecated API that shares implementation.
   friend class ::nsScreen;
 
 public:
@@ -58,17 +46,17 @@ public:
   // (as defined in specification).
   OrientationType GetType(CallerType aCallerType, ErrorResult& aRv) const;
   uint16_t GetAngle(CallerType aCallerType, ErrorResult& aRv) const;
 
   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   void Notify(const mozilla::hal::ScreenConfiguration& aConfiguration) override;
 
-  static void UpdateActiveOrientationLock(ScreenOrientationInternal aOrientation);
+  static void UpdateActiveOrientationLock(hal::ScreenOrientation aOrientation);
 
 private:
   virtual ~ScreenOrientation();
 
   // Listener to unlock orientation if we leave fullscreen.
   class FullScreenEventListener;
 
   // Listener to update document's orienation lock when document becomes
@@ -81,28 +69,28 @@ private:
   enum LockPermission {
     LOCK_DENIED,
     FULLSCREEN_LOCK_ALLOWED,
     LOCK_ALLOWED
   };
 
   // This method calls into the HAL to lock the device and sets
   // up listeners for full screen change.
-  bool LockDeviceOrientation(ScreenOrientationInternal aOrientation,
+  bool LockDeviceOrientation(hal::ScreenOrientation aOrientation,
                              bool aIsFullscreen, ErrorResult& aRv);
 
   // This method calls in to the HAL to unlock the device and removes
   // full screen change listener.
   void UnlockDeviceOrientation();
 
   // This method performs the same function as |Lock| except it takes
-  // a ScreenOrientationInternal argument instead of an OrientationType.
+  // a hal::ScreenOrientation argument instead of an OrientationType.
   // This method exists in order to share implementation with nsScreen that
-  // uses ScreenOrientationInternal.
-  already_AddRefed<Promise> LockInternal(ScreenOrientationInternal aOrientation,
+  // uses ScreenOrientation.
+  already_AddRefed<Promise> LockInternal(hal::ScreenOrientation aOrientation,
                                          ErrorResult& aRv);
 
   void DispatchChangeEvent();
 
   bool ShouldResistFingerprinting() const;
 
   LockPermission GetLockOrientationPermission(bool aCheckSandbox) const;
 
--- a/dom/base/nsScreen.cpp
+++ b/dom/base/nsScreen.cpp
@@ -183,17 +183,17 @@ nsScreen::GetMozOrientation(nsString& aO
     break;
   default:
     MOZ_CRASH("Unacceptable screen orientation type.");
   }
 }
 
 static void
 UpdateDocShellOrientationLock(nsPIDOMWindowInner* aWindow,
-                              ScreenOrientationInternal aOrientation)
+                              hal::ScreenOrientation aOrientation)
 {
   if (!aWindow) {
     return;
   }
 
   nsCOMPtr<nsIDocShell> docShell = aWindow->GetDocShell();
   if (!docShell) {
     return;
@@ -223,37 +223,37 @@ nsScreen::MozLockOrientation(const nsASt
 
 bool
 nsScreen::MozLockOrientation(const Sequence<nsString>& aOrientations,
                              ErrorResult& aRv)
 {
   if (ShouldResistFingerprinting()) {
     return false;
   }
-  ScreenOrientationInternal orientation = eScreenOrientation_None;
+  hal::ScreenOrientation orientation = hal::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;
+      orientation |= hal::eScreenOrientation_PortraitPrimary |
+                     hal::eScreenOrientation_PortraitSecondary;
     } else if (item.EqualsLiteral("portrait-primary")) {
-      orientation |= eScreenOrientation_PortraitPrimary;
+      orientation |= hal::eScreenOrientation_PortraitPrimary;
     } else if (item.EqualsLiteral("portrait-secondary")) {
-      orientation |= eScreenOrientation_PortraitSecondary;
+      orientation |= hal::eScreenOrientation_PortraitSecondary;
     } else if (item.EqualsLiteral("landscape")) {
-      orientation |= eScreenOrientation_LandscapePrimary |
-                     eScreenOrientation_LandscapeSecondary;
+      orientation |= hal::eScreenOrientation_LandscapePrimary |
+                     hal::eScreenOrientation_LandscapeSecondary;
     } else if (item.EqualsLiteral("landscape-primary")) {
-      orientation |= eScreenOrientation_LandscapePrimary;
+      orientation |= hal::eScreenOrientation_LandscapePrimary;
     } else if (item.EqualsLiteral("landscape-secondary")) {
-      orientation |= eScreenOrientation_LandscapeSecondary;
+      orientation |= hal::eScreenOrientation_LandscapeSecondary;
     } else if (item.EqualsLiteral("default")) {
-      orientation |= eScreenOrientation_Default;
+      orientation |= hal::eScreenOrientation_Default;
     } else {
       // If we don't recognize the token, we should just return 'false'
       // without throwing.
       return false;
     }
   }
 
   switch (mScreenOrientation->GetLockOrientationPermission(false)) {
@@ -273,17 +273,17 @@ nsScreen::MozLockOrientation(const Seque
 }
 
 void
 nsScreen::MozUnlockOrientation()
 {
   if (ShouldResistFingerprinting()) {
     return;
   }
-  UpdateDocShellOrientationLock(GetOwner(), eScreenOrientation_None);
+  UpdateDocShellOrientationLock(GetOwner(), hal::eScreenOrientation_None);
   mScreenOrientation->UnlockDeviceOrientation();
 }
 
 bool
 nsScreen::IsDeviceSizePageSize()
 {
   if (nsPIDOMWindowInner* owner = GetOwner()) {
     nsIDocShell* docShell = owner->GetDocShell();
--- a/dom/clients/manager/ClientOpenWindowUtils.cpp
+++ b/dom/clients/manager/ClientOpenWindowUtils.cpp
@@ -12,16 +12,17 @@
 #include "nsContentUtils.h"
 #include "nsIBrowserDOMWindow.h"
 #include "nsIDocShell.h"
 #include "nsIDOMChromeWindow.h"
 #include "nsIURI.h"
 #include "nsIWebProgress.h"
 #include "nsIWebProgressListener.h"
 #include "nsIWindowWatcher.h"
+#include "nsIXPConnect.h"
 #include "nsNetUtil.h"
 #include "nsPIDOMWindow.h"
 #include "nsPIWindowWatcher.h"
 
 #ifdef MOZ_WIDGET_ANDROID
 #include "FennecJNIWrappers.h"
 #endif
 
--- a/dom/clients/manager/ClientPrefs.cpp
+++ b/dom/clients/manager/ClientPrefs.cpp
@@ -1,16 +1,18 @@
 /* -*- 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 "ClientPrefs.h"
 
+#include "mozilla/Preferences.h"
+
 namespace mozilla {
 namespace dom {
 
 namespace {
 
 bool gDataURLUniqueOpaqueOrigin = false;
 
 } // anonymous namespace
--- a/dom/ipc/DOMTypes.ipdlh
+++ b/dom/ipc/DOMTypes.ipdlh
@@ -19,17 +19,17 @@ using struct mozilla::SerializedStructur
 
 using LayoutDeviceIntRect from "Units.h";
 using DesktopIntRect from "Units.h";
 using DesktopToLayoutDeviceScale from "Units.h";
 using CSSToLayoutDeviceScale from "Units.h";
 using CSSRect from "Units.h";
 using CSSSize from "Units.h";
 using mozilla::LayoutDeviceIntPoint from "Units.h";
-using mozilla::dom::ScreenOrientationInternal from "mozilla/dom/ScreenOrientation.h";
+using hal::ScreenOrientation from "mozilla/HalScreenConfiguration.h";
 using struct mozilla::layers::TextureFactoryIdentifier from "mozilla/layers/CompositorTypes.h";
 using mozilla::layers::CompositorOptions from "mozilla/layers/CompositorOptions.h";
 using mozilla::layers::LayersId from "mozilla/layers/LayersTypes.h";
 using mozilla::gfx::SurfaceFormat from "mozilla/gfx/Types.h";
 
 
 namespace mozilla {
 namespace dom {
@@ -95,17 +95,17 @@ struct ScreenDetails {
   CSSToLayoutDeviceScale defaultCSSScaleFactor;
   float dpi;
 };
 
 struct DimensionInfo
 {
   CSSRect rect;
   CSSSize size;
-  ScreenOrientationInternal orientation;
+  ScreenOrientation orientation;
   LayoutDeviceIntPoint clientOffset;
   LayoutDeviceIntPoint chromeOffset;
 };
 
 struct FrameScriptInfo
 {
   nsString url;
   bool runInGlobalScope;
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -403,17 +403,17 @@ TabChild::TabChild(nsIContentChild* aMan
   , mManager(aManager)
   , mChromeFlags(aChromeFlags)
   , mMaxTouchPoints(0)
   , mLayersId{0}
   , mBeforeUnloadListeners(0)
   , mDidFakeShow(false)
   , mNotified(false)
   , mTriedBrowserInit(false)
-  , mOrientation(eScreenOrientation_PortraitPrimary)
+  , mOrientation(hal::eScreenOrientation_PortraitPrimary)
   , mIgnoreKeyPressEvent(false)
   , mHasValidInnerSize(false)
   , mDestroyed(false)
   , mUniqueId(aTabId)
   , mHasSiblings(false)
   , mIsTransparent(false)
   , mIPCOpen(false)
   , mParentIsActive(false)
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -472,17 +472,17 @@ public:
     *aTouchPoints = mMaxTouchPoints;
   }
 
   void SetMaxTouchPoints(uint32_t aMaxTouchPoints)
   {
     mMaxTouchPoints = aMaxTouchPoints;
   }
 
-  ScreenOrientationInternal GetOrientation() const { return mOrientation; }
+  hal::ScreenOrientation GetOrientation() const { return mOrientation; }
 
   void SetBackgroundColor(const nscolor& aColor);
 
   void NotifyPainted();
 
   void RequestEditCommands(nsIWidget::NativeKeyBindingsType aType,
                            const WidgetKeyboardEvent& aEvent,
                            nsTArray<CommandInt>& aCommands);
@@ -823,17 +823,17 @@ private:
   uint32_t mMaxTouchPoints;
   layers::LayersId mLayersId;
   int64_t mBeforeUnloadListeners;
   CSSRect mUnscaledOuterRect;
   Maybe<bool> mLayersConnected;
   bool mDidFakeShow;
   bool mNotified;
   bool mTriedBrowserInit;
-  ScreenOrientationInternal mOrientation;
+  hal::ScreenOrientation mOrientation;
 
   bool mIgnoreKeyPressEvent;
   RefPtr<APZEventState> mAPZEventState;
   SetAllowedTouchBehaviorCallback mSetAllowedTouchBehaviorCallback;
   bool mHasValidInnerSize;
   bool mDestroyed;
   // Position of client area relative to the outer window
   LayoutDeviceIntPoint mClientOffset;
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -764,17 +764,17 @@ TabParent::UpdateDimensions(const nsIntR
   nsCOMPtr<nsIWidget> widget = GetWidget();
   if (!widget) {
     NS_WARNING("No widget found in TabParent::UpdateDimensions");
     return;
   }
 
   hal::ScreenConfiguration config;
   hal::GetCurrentScreenConfiguration(&config);
-  ScreenOrientationInternal orientation = config.orientation();
+  hal::ScreenOrientation orientation = config.orientation();
   LayoutDeviceIntPoint clientOffset = GetClientOffset();
   LayoutDeviceIntPoint chromeOffset = -GetChildProcessOffset();
 
   if (!mUpdatedDimensions || mOrientation != orientation ||
       mDimensions != size || !mRect.IsEqualEdges(rect) ||
       clientOffset != mClientOffset ||
       chromeOffset != mChromeOffset) {
 
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -632,17 +632,17 @@ protected:
   RecvSetSystemFont(const nsCString& aFontName) override;
   mozilla::ipc::IPCResult
   RecvGetSystemFont(nsCString* aFontName) override;
 
   ContentCacheInParent mContentCache;
 
   nsIntRect mRect;
   ScreenIntSize mDimensions;
-  ScreenOrientationInternal mOrientation;
+  hal::ScreenOrientation mOrientation;
   float mDPI;
   int32_t mRounding;
   CSSToLayoutDeviceScale mDefaultScale;
   bool mUpdatedDimensions;
   nsSizeMode mSizeMode;
   LayoutDeviceIntPoint mClientOffset;
   LayoutDeviceIntPoint mChromeOffset;
 
--- a/gfx/layers/client/ClientLayerManager.cpp
+++ b/gfx/layers/client/ClientLayerManager.cpp
@@ -5,17 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ClientLayerManager.h"
 #include "GeckoProfiler.h"              // for AUTO_PROFILER_LABEL
 #include "gfxEnv.h"                     // for gfxEnv
 #include "gfxPrefs.h"                   // for gfxPrefs::LayersTile...
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
 #include "mozilla/Hal.h"
-#include "mozilla/dom/ScreenOrientation.h"  // for ScreenOrientation
 #include "mozilla/dom/TabChild.h"       // for TabChild
 #include "mozilla/dom/TabGroup.h"       // for TabGroup
 #include "mozilla/hal_sandbox/PHal.h"   // for ScreenConfiguration
 #include "mozilla/layers/CompositableClient.h"
 #include "mozilla/layers/CompositorBridgeChild.h" // for CompositorBridgeChild
 #include "mozilla/layers/FrameUniformityData.h"
 #include "mozilla/layers/ISurfaceAllocator.h"
 #include "mozilla/layers/LayersMessages.h"  // for EditReply, etc
@@ -208,17 +207,17 @@ ClientLayerManager::BeginTransactionWith
   NS_ASSERTION(!InTransaction(), "Nested transactions not allowed");
   mPhase = PHASE_CONSTRUCTION;
 
   MOZ_ASSERT(mKeepAlive.IsEmpty(), "uncommitted txn?");
 
   // If the last transaction was incomplete (a failed DoEmptyTransaction),
   // don't signal a new transaction to ShadowLayerForwarder. Carry on adding
   // to the previous transaction.
-  dom::ScreenOrientationInternal orientation;
+  hal::ScreenOrientation orientation;
   if (dom::TabChild* window = mWidget->GetOwningTabChild()) {
     orientation = window->GetOrientation();
   } else {
     hal::ScreenConfiguration currentConfig;
     hal::GetCurrentScreenConfiguration(&currentConfig);
     orientation = currentConfig.orientation();
   }
   LayoutDeviceIntRect targetBounds = mWidget->GetNaturalBounds();
--- a/gfx/layers/composite/AsyncCompositionManager.cpp
+++ b/gfx/layers/composite/AsyncCompositionManager.cpp
@@ -50,20 +50,20 @@
 struct nsCSSValueSharedList;
 
 namespace mozilla {
 namespace layers {
 
 using namespace mozilla::gfx;
 
 static bool
-IsSameDimension(dom::ScreenOrientationInternal o1, dom::ScreenOrientationInternal o2)
+IsSameDimension(hal::ScreenOrientation o1, hal::ScreenOrientation o2)
 {
-  bool isO1portrait = (o1 == dom::eScreenOrientation_PortraitPrimary || o1 == dom::eScreenOrientation_PortraitSecondary);
-  bool isO2portrait = (o2 == dom::eScreenOrientation_PortraitPrimary || o2 == dom::eScreenOrientation_PortraitSecondary);
+  bool isO1portrait = (o1 == hal::eScreenOrientation_PortraitPrimary || o1 == hal::eScreenOrientation_PortraitSecondary);
+  bool isO2portrait = (o2 == hal::eScreenOrientation_PortraitPrimary || o2 == hal::eScreenOrientation_PortraitSecondary);
   return !(isO1portrait ^ isO2portrait);
 }
 
 static bool
 ContentMightReflowOnOrientationChange(const IntRect& rect)
 {
   return rect.Width() != rect.Height();
 }
@@ -127,19 +127,18 @@ AsyncCompositionManager::ResolveRefLayer
       }
 
       Layer* referent = state->mRoot;
       if (!referent) {
         return;
       }
 
       if (!refLayer->GetLocalVisibleRegion().IsEmpty()) {
-        dom::ScreenOrientationInternal chromeOrientation =
-          mTargetConfig.orientation();
-        dom::ScreenOrientationInternal contentOrientation =
+        hal::ScreenOrientation chromeOrientation = mTargetConfig.orientation();
+        hal::ScreenOrientation contentOrientation =
           state->mTargetConfig.orientation();
         if (!IsSameDimension(chromeOrientation, contentOrientation) &&
             ContentMightReflowOnOrientationChange(mTargetConfig.naturalBounds())) {
           mReadyForCompose = false;
         }
       }
 
       refLayer->ConnectReferentLayer(referent);
--- a/gfx/layers/composite/AsyncCompositionManager.h
+++ b/gfx/layers/composite/AsyncCompositionManager.h
@@ -7,19 +7,19 @@
 #ifndef GFX_ASYNCCOMPOSITIONMANAGER_H
 #define GFX_ASYNCCOMPOSITIONMANAGER_H
 
 #include "Units.h"                      // for ScreenPoint, etc
 #include "mozilla/layers/LayerManagerComposite.h"  // for LayerManagerComposite
 #include "mozilla/Attributes.h"         // for final, etc
 #include "mozilla/RefPtr.h"             // for RefCounted
 #include "mozilla/TimeStamp.h"          // for TimeStamp
-#include "mozilla/dom/ScreenOrientation.h"  // for ScreenOrientation
 #include "mozilla/gfx/BasePoint.h"      // for BasePoint
 #include "mozilla/gfx/Matrix.h"         // for Matrix4x4
+#include "mozilla/HalScreenConfiguration.h" // For ScreenOrientation
 #include "mozilla/layers/FrameUniformityData.h" // For FrameUniformityData
 #include "mozilla/layers/LayersMessages.h"  // for TargetConfig
 #include "mozilla/RefPtr.h"                   // for nsRefPtr
 #include "nsISupportsImpl.h"            // for LayerManager::AddRef, etc
 #include "CompositorBridgeParent.h"     // for TransformsToSkip
 
 namespace mozilla {
 namespace layers {
@@ -97,17 +97,17 @@ public:
   // Call after updating our layer tree.
   void Updated(bool isFirstPaint, const TargetConfig& aTargetConfig)
   {
     mIsFirstPaint |= isFirstPaint;
     mLayersUpdated = true;
     mTargetConfig = aTargetConfig;
   }
 
-  bool RequiresReorientation(mozilla::dom::ScreenOrientationInternal aOrientation) const
+  bool RequiresReorientation(hal::ScreenOrientation aOrientation) const
   {
     return mTargetConfig.orientation() != aOrientation;
   }
 
   // True if the underlying layer tree is ready to be composited.
   bool ReadyForCompose() { return mReadyForCompose; }
 
   // Returns true if the next composition will be the first for a
--- a/gfx/layers/ipc/LayersMessages.ipdlh
+++ b/gfx/layers/ipc/LayersMessages.ipdlh
@@ -22,17 +22,17 @@ using mozilla::gfx::IntPoint from "mozil
 using class mozilla::gfx::Matrix4x4 from "mozilla/gfx/Matrix.h";
 using nscoord from "nsCoord.h";
 using struct nsRect from "nsRect.h";
 using struct nsPoint from "nsPoint.h";
 using class mozilla::TimeDuration from "mozilla/TimeStamp.h";
 using class mozilla::TimeStamp from "mozilla/TimeStamp.h";
 using mozilla::ScreenRotation from "mozilla/WidgetUtils.h";
 using nsCSSPropertyID from "nsCSSPropertyID.h";
-using mozilla::dom::ScreenOrientationInternal from "mozilla/dom/ScreenOrientation.h";
+using hal::ScreenOrientation from "mozilla/HalScreenConfiguration.h";
 using struct mozilla::layers::TextureInfo from "mozilla/layers/CompositorTypes.h";
 using mozilla::LayerMargin from "Units.h";
 using mozilla::LayerPoint from "Units.h";
 using mozilla::LayerCoord from "Units.h";
 using mozilla::LayerSize from "Units.h";
 using mozilla::LayerRect from "Units.h";
 using mozilla::LayerIntRegion from "Units.h";
 using mozilla::ParentLayerIntRect from "Units.h";
@@ -55,17 +55,17 @@ using mozilla::layers::LayersId from "mo
 using mozilla::layers::TransactionId from "mozilla/layers/LayersTypes.h";
 
 namespace mozilla {
 namespace layers {
 
 struct TargetConfig {
   IntRect naturalBounds;
   ScreenRotation rotation;
-  ScreenOrientationInternal orientation;
+  ScreenOrientation orientation;
   nsIntRegion clearRegion;
 };
 
 // Create a shadow layer for |layer|
 struct OpCreatePaintedLayer    { LayerHandle layer; };
 struct OpCreateContainerLayer  { LayerHandle layer; };
 struct OpCreateImageLayer      { LayerHandle layer; };
 struct OpCreateColorLayer      { LayerHandle layer; };
--- a/gfx/layers/ipc/ShadowLayers.cpp
+++ b/gfx/layers/ipc/ShadowLayers.cpp
@@ -60,23 +60,23 @@ typedef nsTArray<Edit> EditVector;
 typedef nsTHashtable<nsPtrHashKey<ShadowableLayer>> ShadowableLayerSet;
 typedef nsTArray<OpDestroy> OpDestroyVector;
 
 class Transaction
 {
 public:
   Transaction()
     : mTargetRotation(ROTATION_0)
-    , mTargetOrientation(dom::eScreenOrientation_None)
+    , mTargetOrientation(hal::eScreenOrientation_None)
     , mOpen(false)
     , mRotationChanged(false)
   {}
 
   void Begin(const gfx::IntRect& aTargetBounds, ScreenRotation aRotation,
-             dom::ScreenOrientationInternal aOrientation)
+             hal::ScreenOrientation aOrientation)
   {
     mOpen = true;
     mTargetBounds = aTargetBounds;
     if (aRotation != mTargetRotation) {
       // the first time this is called, mRotationChanged will be false if
       // aRotation is 0, but we should be OK because for the first transaction
       // we should only compose if it is non-empty. See the caller(s) of
       // RotationChanged.
@@ -137,17 +137,17 @@ public:
 
   EditVector mCset;
   nsTArray<CompositableOperation> mPaints;
   OpDestroyVector mDestroyedActors;
   ShadowableLayerSet mMutants;
   ShadowableLayerSet mSimpleMutants;
   gfx::IntRect mTargetBounds;
   ScreenRotation mTargetRotation;
-  dom::ScreenOrientationInternal mTargetOrientation;
+  hal::ScreenOrientation mTargetOrientation;
 
 private:
   bool mOpen;
   bool mRotationChanged;
 
   // disabled
   Transaction(const Transaction&);
   Transaction& operator=(const Transaction&);
@@ -280,17 +280,17 @@ ShadowLayerForwarder::~ShadowLayerForwar
       NS_DispatchToMainThread(event);
     }
   }
 }
 
 void
 ShadowLayerForwarder::BeginTransaction(const gfx::IntRect& aTargetBounds,
                                        ScreenRotation aRotation,
-                                       dom::ScreenOrientationInternal aOrientation)
+                                       hal::ScreenOrientation aOrientation)
 {
   MOZ_ASSERT(IPCOpen(), "no manager to forward to");
   MOZ_ASSERT(mTxn->Finished(), "uncommitted txn?");
   UpdateFwdTransactionId();
   mTxn->Begin(aTargetBounds, aRotation, aOrientation);
 }
 
 static const LayerHandle&
--- a/gfx/layers/ipc/ShadowLayers.h
+++ b/gfx/layers/ipc/ShadowLayers.h
@@ -8,18 +8,18 @@
 #define mozilla_layers_ShadowLayers_h 1
 
 #include <stddef.h>                     // for size_t
 #include <stdint.h>                     // for uint64_t
 #include "gfxTypes.h"
 #include "mozilla/Attributes.h"         // for override
 #include "mozilla/gfx/Rect.h"
 #include "mozilla/WidgetUtils.h"        // for ScreenRotation
-#include "mozilla/dom/ScreenOrientation.h"  // for ScreenOrientation
 #include "mozilla/ipc/SharedMemory.h"   // for SharedMemory, etc
+#include "mozilla/HalScreenConfiguration.h" // for ScreenOrientation
 #include "mozilla/layers/CompositableForwarder.h"
 #include "mozilla/layers/FocusTarget.h"
 #include "mozilla/layers/LayersTypes.h"
 #include "mozilla/layers/TextureForwarder.h"
 #include "mozilla/layers/CompositorTypes.h"  // for OpenMode, etc
 #include "mozilla/layers/CompositorBridgeChild.h"
 #include "nsCOMPtr.h"                   // for already_AddRefed
 #include "nsRegion.h"                   // for nsIntRegion
@@ -153,17 +153,17 @@ public:
                                ShadowableLayer* aLayer);
 
   /**
    * Begin recording a transaction to be forwarded atomically to a
    * LayerManagerComposite.
    */
   void BeginTransaction(const gfx::IntRect& aTargetBounds,
                         ScreenRotation aRotation,
-                        mozilla::dom::ScreenOrientationInternal aOrientation);
+                        hal::ScreenOrientation aOrientation);
 
   /**
    * The following methods may only be called after BeginTransaction()
    * but before EndTransaction().  They mirror the LayerManager
    * interface in Layers.h.
    */
 
   /**
--- a/gfx/vr/ipc/VRManagerChild.h
+++ b/gfx/vr/ipc/VRManagerChild.h
@@ -2,16 +2,17 @@
 /* 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/. */
 
 #ifndef MOZILLA_GFX_VR_VRMANAGERCHILD_H
 #define MOZILLA_GFX_VR_VRMANAGERCHILD_H
 
+#include "mozilla/dom/WindowBinding.h" // For FrameRequestCallback
 #include "mozilla/gfx/PVRManagerChild.h"
 #include "mozilla/ipc/SharedMemory.h"   // for SharedMemory, etc
 #include "ThreadSafeRefcountingWithMainThreadDestruction.h"
 #include "mozilla/layers/ISurfaceAllocator.h"  // for ISurfaceAllocator
 #include "mozilla/layers/LayersTypes.h"  // for LayersBackend
 #include "mozilla/layers/TextureForwarder.h"
 
 namespace mozilla {
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -16,17 +16,16 @@
 #include "nsIWebNavigation.h"
 #include "nsThreadUtils.h"
 #include "nsXULAppAPI.h"
 #include "nsPIDOMWindow.h"
 #include "nsJSUtils.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/Observer.h"
 #include "mozilla/dom/ContentChild.h"
-#include "mozilla/dom/ScreenOrientation.h"
 #include "WindowIdentifier.h"
 
 #ifdef XP_WIN
 #include <process.h>
 #define getpid _getpid
 #endif
 
 using namespace mozilla::services;
@@ -534,17 +533,17 @@ GetCurrentScreenConfiguration(ScreenConf
 void
 NotifyScreenConfigurationChange(const ScreenConfiguration& aScreenConfiguration)
 {
   ScreenConfigurationObservers().CacheInformation(aScreenConfiguration);
   ScreenConfigurationObservers().BroadcastCachedInformation();
 }
 
 bool
-LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation)
+LockScreenOrientation(const ScreenOrientation& aOrientation)
 {
   AssertMainThread();
   RETURN_PROXY_IF_SANDBOXED(LockScreenOrientation(aOrientation), false);
 }
 
 void
 UnlockScreenOrientation()
 {
--- a/hal/Hal.h
+++ b/hal/Hal.h
@@ -5,17 +5,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_Hal_h
 #define mozilla_Hal_h
 
 #include "base/basictypes.h"
 #include "base/platform_thread.h"
 #include "nsTArray.h"
-#include "mozilla/dom/ScreenOrientation.h"
 #include "mozilla/hal_sandbox/PHal.h"
 #include "mozilla/HalBatteryInformation.h"
 #include "mozilla/HalNetworkInformation.h"
 #include "mozilla/HalScreenConfiguration.h"
 #include "mozilla/HalWakeLockInformation.h"
 #include "mozilla/HalTypes.h"
 #include "mozilla/Types.h"
 
@@ -220,17 +219,17 @@ void GetCurrentScreenConfiguration(hal::
  * @param aScreenConfiguration The new screen orientation.
  */
 void NotifyScreenConfigurationChange(const hal::ScreenConfiguration& aScreenConfiguration);
 
 /**
  * Lock the screen orientation to the specific orientation.
  * @return Whether the lock has been accepted.
  */
-MOZ_MUST_USE bool LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation);
+MOZ_MUST_USE bool LockScreenOrientation(const hal::ScreenOrientation& aOrientation);
 
 /**
  * Unlock the screen orientation.
  */
 void UnlockScreenOrientation();
 
 /**
  * Return true if the current platform supports the setting of process
--- a/hal/HalScreenConfiguration.h
+++ b/hal/HalScreenConfiguration.h
@@ -6,15 +6,30 @@
 
 #ifndef mozilla_HalScreenConfiguration_h
 #define mozilla_HalScreenConfiguration_h
 
 #include "mozilla/Observer.h"
 
 namespace mozilla {
 namespace hal {
+
+// Make sure that any change to ScreenOrientation values are also made in
+// mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java
+typedef uint32_t ScreenOrientation;
+
+static const ScreenOrientation eScreenOrientation_None               = 0;
+static const ScreenOrientation eScreenOrientation_PortraitPrimary    = 1u << 0;
+static const ScreenOrientation eScreenOrientation_PortraitSecondary  = 1u << 1;
+static const ScreenOrientation eScreenOrientation_LandscapePrimary   = 1u << 2;
+static const ScreenOrientation eScreenOrientation_LandscapeSecondary = 1u << 3;
+//eScreenOrientation_Default will use the natural orientation for the deivce,
+//it could be PortraitPrimary or LandscapePrimary depends on display resolution
+static const ScreenOrientation eScreenOrientation_Default            = 1u << 4;
+
 class ScreenConfiguration;
 typedef Observer<ScreenConfiguration> ScreenConfigurationObserver;
+
 } // namespace hal
 } // namespace mozilla
 
 #endif  // mozilla_HalScreenConfiguration_h
 
--- a/hal/android/AndroidHal.cpp
+++ b/hal/android/AndroidHal.cpp
@@ -3,18 +3,18 @@
  * 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 "Hal.h"
 #include "HalImpl.h"
 #include "WindowIdentifier.h"
 #include "AndroidBridge.h"
 #include "mozilla/dom/network/Constants.h"
-#include "mozilla/dom/ScreenOrientation.h"
 #include "nsIScreenManager.h"
+#include "nsPIDOMWindow.h"
 #include "nsServiceManagerUtils.h"
 
 using namespace mozilla::dom;
 using namespace mozilla::hal;
 
 namespace java = mozilla::java;
 
 namespace mozilla {
@@ -120,39 +120,39 @@ GetCurrentScreenConfiguration(ScreenConf
     do_GetService("@mozilla.org/gfx/screenmanager;1", &rv);
   if (NS_FAILED(rv)) {
     NS_ERROR("Can't find nsIScreenManager!");
     return;
   }
 
   int32_t colorDepth, pixelDepth;
   int16_t angle;
-  ScreenOrientationInternal orientation;
+  ScreenOrientation orientation;
   nsCOMPtr<nsIScreen> screen;
 
   int32_t rectX, rectY, rectWidth, rectHeight;
 
   screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
   
   screen->GetRect(&rectX, &rectY, &rectWidth, &rectHeight);
   screen->GetColorDepth(&colorDepth);
   screen->GetPixelDepth(&pixelDepth);
-  orientation = static_cast<ScreenOrientationInternal>(bridge->GetScreenOrientation());
+  orientation = static_cast<ScreenOrientation>(bridge->GetScreenOrientation());
   angle = bridge->GetScreenAngle();
 
   *aScreenConfiguration =
     hal::ScreenConfiguration(nsIntRect(rectX, rectY, rectWidth, rectHeight),
                              orientation, angle, colorDepth, pixelDepth);
 }
 
 bool
-LockScreenOrientation(const ScreenOrientationInternal& aOrientation)
+LockScreenOrientation(const ScreenOrientation& aOrientation)
 {
   // Force the default orientation to be portrait-primary.
-  ScreenOrientationInternal orientation =
+  ScreenOrientation orientation =
     aOrientation == eScreenOrientation_Default ? eScreenOrientation_PortraitPrimary
                                                : aOrientation;
 
   switch (orientation) {
     // The Android backend only supports these orientations.
     case eScreenOrientation_PortraitPrimary:
     case eScreenOrientation_PortraitSecondary:
     case eScreenOrientation_PortraitPrimary | eScreenOrientation_PortraitSecondary:
--- a/hal/fallback/FallbackScreenConfiguration.cpp
+++ b/hal/fallback/FallbackScreenConfiguration.cpp
@@ -19,17 +19,17 @@ DisableScreenConfigurationNotifications(
 
 void
 GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration)
 {
   fallback::GetCurrentScreenConfiguration(aScreenConfiguration);
 }
 
 bool
-LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation)
+LockScreenOrientation(const ScreenOrientation& aOrientation)
 {
   return false;
 }
 
 void
 UnlockScreenOrientation()
 {
 }
--- a/hal/fallback/FallbackScreenConfiguration.h
+++ b/hal/fallback/FallbackScreenConfiguration.h
@@ -1,17 +1,16 @@
 /* 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/. */
 
 #ifndef mozilla_fallback_FallbackScreenConfiguration_h
 #define mozilla_fallback_FallbackScreenConfiguration_h
 
 #include "Hal.h"
-#include "mozilla/dom/ScreenOrientation.h"
 #include "nsIScreenManager.h"
 #include "nsServiceManagerUtils.h"
 
 namespace mozilla {
 namespace fallback {
 
 inline void
 GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration)
@@ -20,26 +19,26 @@ GetCurrentScreenConfiguration(hal::Scree
   nsCOMPtr<nsIScreenManager> screenMgr =
     do_GetService("@mozilla.org/gfx/screenmanager;1", &rv);
   if (NS_FAILED(rv)) {
     NS_ERROR("Can't find nsIScreenManager!");
     return;
   }
 
   int32_t colorDepth, pixelDepth, x, y, w, h;
-  dom::ScreenOrientationInternal orientation;
+  ScreenOrientation orientation;
   nsCOMPtr<nsIScreen> screen;
 
   screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
   screen->GetRect(&x, &y, &w, &h);
   screen->GetColorDepth(&colorDepth);
   screen->GetPixelDepth(&pixelDepth);
   orientation = w >= h
-                ? dom::eScreenOrientation_LandscapePrimary
-                : dom::eScreenOrientation_PortraitPrimary;
+                ? hal::eScreenOrientation_LandscapePrimary
+                : hal::eScreenOrientation_PortraitPrimary;
 
   *aScreenConfiguration = hal::ScreenConfiguration(nsIntRect(x, y, w, h),
 						   orientation, 0,
 						   colorDepth, pixelDepth);
 }
 
 }
 }
--- a/hal/sandbox/PHal.ipdl
+++ b/hal/sandbox/PHal.ipdl
@@ -4,17 +4,17 @@
  * 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 protocol PContent;
 include protocol PBrowser;
 
 include "mozilla/GfxMessageUtils.h";
 
-using mozilla::dom::ScreenOrientationInternal from "mozilla/dom/ScreenOrientation.h";
+using hal::ScreenOrientation from "mozilla/HalScreenConfiguration.h";
 using mozilla::hal::SensorType from "mozilla/HalSensor.h";
 using mozilla::hal::WakeLockControl from "mozilla/HalTypes.h";
 using mozilla::hal::ProcessPriority from "mozilla/HalTypes.h";
 using nsIntRect from "nsRect.h";
 using PRTime from "prtime.h";
 
 namespace mozilla {
 
@@ -41,17 +41,17 @@ struct WakeLockInformation {
   nsString topic;
   uint32_t numLocks;
   uint32_t numHidden;
   uint64_t[] lockingProcesses;
 };
 
 struct ScreenConfiguration {
   nsIntRect rect;
-  ScreenOrientationInternal orientation;
+  ScreenOrientation orientation;
   uint16_t angle;
   uint32_t colorDepth;
   uint32_t pixelDepth;
 };
 
 } // namespace hal
 
 namespace hal_sandbox {
@@ -85,17 +85,17 @@ parent:
                          uint64_t aProcessID);
     async EnableWakeLockNotifications();
     async DisableWakeLockNotifications();
     sync GetWakeLockInfo(nsString aTopic)
       returns (WakeLockInformation aWakeLockInfo);
 
     async EnableScreenConfigurationNotifications();
     async DisableScreenConfigurationNotifications();
-    sync LockScreenOrientation(ScreenOrientationInternal aOrientation)
+    sync LockScreenOrientation(ScreenOrientation aOrientation)
       returns (bool allowed);
     async UnlockScreenOrientation();
 
 child:
     async NotifySensorChange(SensorData aSensorData);
 
 parent:
     async EnableSensorNotifications(SensorType aSensor);
--- a/hal/sandbox/SandboxHal.cpp
+++ b/hal/sandbox/SandboxHal.cpp
@@ -7,17 +7,16 @@
 #include "Hal.h"
 #include "HalLog.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/hal_sandbox/PHalChild.h"
 #include "mozilla/hal_sandbox/PHalParent.h"
 #include "mozilla/dom/TabParent.h"
 #include "mozilla/dom/TabChild.h"
-#include "mozilla/dom/ScreenOrientation.h"
 #include "mozilla/fallback/FallbackScreenConfiguration.h"
 #include "mozilla/EnumeratedRange.h"
 #include "mozilla/Observer.h"
 #include "mozilla/Unused.h"
 #include "nsAutoPtr.h"
 #include "WindowIdentifier.h"
 
 using namespace mozilla;
@@ -117,17 +116,17 @@ DisableScreenConfigurationNotifications(
 
 void
 GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
 {
   fallback::GetCurrentScreenConfiguration(aScreenConfiguration);
 }
 
 bool
-LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation)
+LockScreenOrientation(const ScreenOrientation& aOrientation)
 {
   bool allowed;
   Hal()->SendLockScreenOrientation(aOrientation, &allowed);
   return allowed;
 }
 
 void
 UnlockScreenOrientation()
@@ -327,17 +326,17 @@ public:
 
   virtual mozilla::ipc::IPCResult
   RecvDisableScreenConfigurationNotifications() override {
     hal::UnregisterScreenConfigurationObserver(this);
     return IPC_OK();
   }
 
   virtual mozilla::ipc::IPCResult
-  RecvLockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation, bool* aAllowed) override
+  RecvLockScreenOrientation(const ScreenOrientation& aOrientation, bool* aAllowed) override
   {
     // FIXME/bug 777980: unprivileged content may only lock
     // orientation while fullscreen.  We should check whether the
     // request comes from an actor in a process that might be
     // fullscreen.  We don't have that information currently.
     *aAllowed = hal::LockScreenOrientation(aOrientation);
     return IPC_OK();
   }
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java
@@ -23,17 +23,17 @@ import java.util.List;
  * Updates, locks and unlocks the screen orientation.
  *
  * Note: Replaces the OnOrientationChangeListener to avoid redundant rotation
  * event handling.
  */
 public class GeckoScreenOrientation {
     private static final String LOGTAG = "GeckoScreenOrientation";
 
-    // Make sure that any change in dom/base/ScreenOrientation.h happens here too.
+    // Make sure that any change in hal/HalScreenConfiguration.h happens here too.
     public enum ScreenOrientation {
         NONE(0),
         PORTRAIT_PRIMARY(1 << 0),
         PORTRAIT_SECONDARY(1 << 1),
         PORTRAIT(PORTRAIT_PRIMARY.value | PORTRAIT_SECONDARY.value),
         LANDSCAPE_PRIMARY(1 << 2),
         LANDSCAPE_SECONDARY(1 << 3),
         LANDSCAPE(LANDSCAPE_PRIMARY.value | LANDSCAPE_SECONDARY.value),
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -25,17 +25,16 @@
 #include "nsIThreadManager.h"
 #include "gfxPlatform.h"
 #include "gfxContext.h"
 #include "mozilla/gfx/2D.h"
 #include "gfxUtils.h"
 #include "nsPresContext.h"
 #include "nsIDocShell.h"
 #include "nsPIDOMWindow.h"
-#include "mozilla/dom/ScreenOrientation.h"
 #include "nsIDOMWindowUtils.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "nsPrintfCString.h"
 #include "nsContentUtils.h"
 #include "nsIScriptError.h"
 #include "nsIHttpChannel.h"
 
 #include "EventDispatcher.h"
@@ -729,19 +728,19 @@ nsAndroidBridge::RemoveObservers()
 uint32_t
 AndroidBridge::GetScreenOrientation()
 {
     ALOG_BRIDGE("AndroidBridge::GetScreenOrientation");
 
     int16_t orientation = GeckoAppShell::GetScreenOrientation();
 
     if (!orientation)
-        return dom::eScreenOrientation_None;
+        return hal::eScreenOrientation_None;
 
-    return static_cast<dom::ScreenOrientationInternal>(orientation);
+    return static_cast<hal::ScreenOrientation>(orientation);
 }
 
 uint16_t
 AndroidBridge::GetScreenAngle()
 {
     return GeckoAppShell::GetScreenAngle();
 }
 
--- a/widget/android/GeckoScreenOrientation.h
+++ b/widget/android/GeckoScreenOrientation.h
@@ -7,17 +7,16 @@
 #define GeckoScreenOrientation_h
 
 #include "GeneratedJNINatives.h"
 #include "nsAppShell.h"
 #include "nsCOMPtr.h"
 #include "nsIScreenManager.h"
 
 #include "mozilla/Hal.h"
-#include "mozilla/dom/ScreenOrientation.h"
 
 namespace mozilla {
 
 class GeckoScreenOrientation final
     : public java::GeckoScreenOrientation::Natives<GeckoScreenOrientation>
 {
     GeckoScreenOrientation() = delete;
 
@@ -40,16 +39,16 @@ public:
         if (NS_FAILED(screen->GetRect(&rect.x, &rect.y,
                                       &rect.width, &rect.height)) ||
                 NS_FAILED(screen->GetColorDepth(&colorDepth)) ||
                 NS_FAILED(screen->GetPixelDepth(&pixelDepth))) {
             return;
         }
 
         hal::NotifyScreenConfigurationChange(hal::ScreenConfiguration(
-                rect, static_cast<dom::ScreenOrientationInternal>(aOrientation),
+                rect, static_cast<hal::ScreenOrientation>(aOrientation),
                 aAngle, colorDepth, pixelDepth));
     }
 };
 
 } // namespace mozilla
 
 #endif // GeckoScreenOrientation_h