Bug 1446990 - Safely transmit nsTransparencyMode across IPDL for WinCompositorWidget. r=jrmuizel
authorRyan Hunt <rhunt@eqrion.net>
Thu, 05 Apr 2018 22:24:28 -0500
changeset 465597 055d507f2e35e4482614c4eba09d8e473e9850e3
parent 465596 6fce6a9a47b75622d79de27d969134b7e6005e90
child 465598 7047a6811fdc12b5a7f5367f5abc80923c4613cb
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1446990
milestone61.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 1446990 - Safely transmit nsTransparencyMode across IPDL for WinCompositorWidget. r=jrmuizel
widget/WidgetMessageUtils.h
widget/nsIWidget.h
widget/windows/CompositorWidgetChild.cpp
widget/windows/CompositorWidgetParent.cpp
widget/windows/CompositorWidgetParent.h
widget/windows/PCompositorWidget.ipdl
widget/windows/PlatformWidgetTypes.ipdlh
widget/windows/WinCompositorWidget.cpp
--- a/widget/WidgetMessageUtils.h
+++ b/widget/WidgetMessageUtils.h
@@ -2,16 +2,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/. */
 
 #ifndef mozilla_WidgetMessageUtils_h
 #define mozilla_WidgetMessageUtils_h
 
 #include "ipc/IPCMessageUtils.h"
 #include "mozilla/LookAndFeel.h"
+#include "nsIWidget.h"
 
 namespace IPC {
 
 template<>
 struct ParamTraits<LookAndFeelInt>
 {
   typedef LookAndFeelInt paramType;
 
@@ -29,11 +30,15 @@ struct ParamTraits<LookAndFeelInt>
       aResult->id = id;
       aResult->value = value;
       return true;
     }
     return false;
   }
 };
 
+template<>
+struct ParamTraits<nsTransparencyMode> : public ContiguousEnumSerializerInclusive<nsTransparencyMode, eTransparencyOpaque, eTransparencyBorderlessGlass>
+{ };
+
 } // namespace IPC
 
 #endif // WidgetMessageUtils_h
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -160,16 +160,17 @@ typedef void* nsNativeWidget;
  * Transparency modes
  */
 
 enum nsTransparencyMode {
   eTransparencyOpaque = 0,  // Fully opaque
   eTransparencyTransparent, // Parts of the window may be transparent
   eTransparencyGlass,       // Transparent parts of the window have Vista AeroGlass effect applied
   eTransparencyBorderlessGlass // As above, but without a border around the opaque areas when there would otherwise be one with eTransparencyGlass
+  // If you add to the end here, you must update the serialization code in WidgetMessageUtils.h
 };
 
 /**
  * Cursor types.
  */
 
 enum nsCursor {   ///(normal cursor,       usually rendered as an arrow)
                 eCursor_standard,
--- a/widget/windows/CompositorWidgetChild.cpp
+++ b/widget/windows/CompositorWidgetChild.cpp
@@ -41,17 +41,17 @@ CompositorWidgetChild::LeavePresentLock(
 void
 CompositorWidgetChild::OnDestroyWindow()
 {
 }
 
 void
 CompositorWidgetChild::UpdateTransparency(nsTransparencyMode aMode)
 {
-  Unused << SendUpdateTransparency(static_cast<int32_t>(aMode));
+  Unused << SendUpdateTransparency(aMode);
 }
 
 void
 CompositorWidgetChild::ClearTransparentWindow()
 {
   Unused << SendClearTransparentWindow();
 }
 
--- a/widget/windows/CompositorWidgetParent.cpp
+++ b/widget/windows/CompositorWidgetParent.cpp
@@ -32,19 +32,19 @@ CompositorWidgetParent::RecvEnterPresent
 mozilla::ipc::IPCResult
 CompositorWidgetParent::RecvLeavePresentLock()
 {
   LeavePresentLock();
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
-CompositorWidgetParent::RecvUpdateTransparency(const int32_t& aMode)
+CompositorWidgetParent::RecvUpdateTransparency(const nsTransparencyMode& aMode)
 {
-  UpdateTransparency(static_cast<nsTransparencyMode>(aMode));
+  UpdateTransparency(aMode);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 CompositorWidgetParent::RecvClearTransparentWindow()
 {
   ClearTransparentWindow();
   return IPC_OK();
--- a/widget/windows/CompositorWidgetParent.h
+++ b/widget/windows/CompositorWidgetParent.h
@@ -18,17 +18,17 @@ class CompositorWidgetParent final
 {
 public:
   explicit CompositorWidgetParent(const CompositorWidgetInitData& aInitData,
                                   const layers::CompositorOptions& aOptions);
   ~CompositorWidgetParent() override;
 
   mozilla::ipc::IPCResult RecvEnterPresentLock() override;
   mozilla::ipc::IPCResult RecvLeavePresentLock() override;
-  mozilla::ipc::IPCResult RecvUpdateTransparency(const int32_t& aMode) override;
+  mozilla::ipc::IPCResult RecvUpdateTransparency(const nsTransparencyMode& aMode) override;
   mozilla::ipc::IPCResult RecvClearTransparentWindow() override;
   void ActorDestroy(ActorDestroyReason aWhy) override;
 
   nsIWidget* RealWidget() override;
   void ObserveVsync(VsyncObserver* aObserver) override;
   RefPtr<VsyncObserver> GetVsyncObserver() const override;
 
 private:
--- a/widget/windows/PCompositorWidget.ipdl
+++ b/widget/windows/PCompositorWidget.ipdl
@@ -2,28 +2,29 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=99: */
 /* 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 protocol PCompositorBridge;
 
 using mozilla::gfx::IntSize from "mozilla/gfx/Point.h";
+using nsTransparencyMode from "mozilla/widget/WidgetMessageUtils.h";
 
 namespace mozilla {
 namespace widget {
 
 sync protocol PCompositorWidget
 {
   manager PCompositorBridge;
 
 parent:
   sync EnterPresentLock();
   sync LeavePresentLock();
-  async UpdateTransparency(int32_t aMode);
+  async UpdateTransparency(nsTransparencyMode aMode);
   sync ClearTransparentWindow();
   async __delete__();
 
 child:
   async ObserveVsync();
   async UnobserveVsync();
 };
 
--- a/widget/windows/PlatformWidgetTypes.ipdlh
+++ b/widget/windows/PlatformWidgetTypes.ipdlh
@@ -2,25 +2,26 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=99: */
 /* 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 HeadlessWidgetTypes;
 
 using mozilla::WindowsHandle from "ipc/IPCMessageUtils.h";
+using nsTransparencyMode from "mozilla/widget/WidgetMessageUtils.h";
 
 namespace mozilla {
 namespace widget {
 
 struct WinCompositorWidgetInitData
 {
   WindowsHandle hWnd;
   uintptr_t widgetKey;
-  int32_t transparencyMode;
+  nsTransparencyMode transparencyMode;
 };
 
 union CompositorWidgetInitData
 {
   WinCompositorWidgetInitData;
   HeadlessCompositorWidgetInitData;
 };
 
--- a/widget/windows/WinCompositorWidget.cpp
+++ b/widget/windows/WinCompositorWidget.cpp
@@ -21,17 +21,17 @@ namespace widget {
 using namespace mozilla::gfx;
 
 WinCompositorWidget::WinCompositorWidget(const WinCompositorWidgetInitData& aInitData,
                                          const layers::CompositorOptions& aOptions)
  : CompositorWidget(aOptions)
  , mWidgetKey(aInitData.widgetKey()),
    mWnd(reinterpret_cast<HWND>(aInitData.hWnd())),
    mCompositorWnd(nullptr),
-   mTransparencyMode(static_cast<nsTransparencyMode>(aInitData.transparencyMode())),
+   mTransparencyMode(aInitData.transparencyMode()),
    mMemoryDC(nullptr),
    mCompositeDC(nullptr),
    mLockedBackBufferData(nullptr)
 {
   MOZ_ASSERT(mWnd && ::IsWindow(mWnd));
 
   // mNotDeferEndRemoteDrawing is set on the main thread during init,
   // but is only accessed after on the compositor thread.