Bug 1172796 - Part 2: Add write-only flag for origin-clean check. r=roc draft
authorMorris Tseng <mtseng@mozilla.com>
Wed, 18 Nov 2015 12:02:19 +0800
changeset 309548 5bafe42caca81078cb01c62578791612cb36fc35
parent 309547 b90ecae85bae6982869ba9c4a7ec84c7ff256b2b
child 309549 646525cfff7182a84a5c782624bf7809039a0143
push id7622
push usermtseng@mozilla.com
push dateWed, 18 Nov 2015 04:04:35 +0000
reviewersroc
bugs1172796
milestone45.0a1
Bug 1172796 - Part 2: Add write-only flag for origin-clean check. r=roc
dom/canvas/OffscreenCanvas.cpp
dom/canvas/OffscreenCanvas.h
dom/html/HTMLCanvasElement.cpp
--- a/dom/canvas/OffscreenCanvas.cpp
+++ b/dom/canvas/OffscreenCanvas.cpp
@@ -19,35 +19,37 @@
 #include "WebGL2Context.h"
 
 namespace mozilla {
 namespace dom {
 
 OffscreenCanvasCloneData::OffscreenCanvasCloneData(layers::AsyncCanvasRenderer* aRenderer,
                                                    uint32_t aWidth, uint32_t aHeight,
                                                    layers::LayersBackend aCompositorBackend,
-                                                   bool aNeutered)
+                                                   bool aNeutered, bool aIsWriteOnly)
   : mRenderer(aRenderer)
   , mWidth(aWidth)
   , mHeight(aHeight)
   , mCompositorBackendType(aCompositorBackend)
   , mNeutered(aNeutered)
+  , mIsWriteOnly(aIsWriteOnly)
 {
 }
 
 OffscreenCanvasCloneData::~OffscreenCanvasCloneData()
 {
 }
 
 OffscreenCanvas::OffscreenCanvas(uint32_t aWidth,
                                  uint32_t aHeight,
                                  layers::LayersBackend aCompositorBackend,
                                  layers::AsyncCanvasRenderer* aRenderer)
   : mAttrDirty(false)
   , mNeutered(false)
+  , mIsWriteOnly(false)
   , mWidth(aWidth)
   , mHeight(aHeight)
   , mCompositorBackendType(aCompositorBackend)
   , mCanvasClient(nullptr)
   , mCanvasRenderer(aRenderer)
 {}
 
 OffscreenCanvas::~OffscreenCanvas()
@@ -186,17 +188,17 @@ OffscreenCanvas::CommitFrameToCompositor
       UpdateAsyncCanvasRenderer(mCanvasRenderer);
   }
 }
 
 OffscreenCanvasCloneData*
 OffscreenCanvas::ToCloneData()
 {
   return new OffscreenCanvasCloneData(mCanvasRenderer, mWidth, mHeight,
-                                      mCompositorBackendType, mNeutered);
+                                      mCompositorBackendType, mNeutered, mIsWriteOnly);
 }
 
 /* static */ already_AddRefed<OffscreenCanvas>
 OffscreenCanvas::CreateFromCloneData(OffscreenCanvasCloneData* aData)
 {
   MOZ_ASSERT(aData);
   RefPtr<OffscreenCanvas> wc =
     new OffscreenCanvas(aData->mWidth, aData->mHeight,
--- a/dom/canvas/OffscreenCanvas.h
+++ b/dom/canvas/OffscreenCanvas.h
@@ -30,24 +30,25 @@ namespace dom {
 // Because OffscreenCanvas is not thread-safe. So we cannot pass Offscreen-
 // Canvas to worker thread directly. Thus, we create this helper class and
 // store necessary data in it then pass it to worker thread.
 struct OffscreenCanvasCloneData final
 {
   OffscreenCanvasCloneData(layers::AsyncCanvasRenderer* aRenderer,
                            uint32_t aWidth, uint32_t aHeight,
                            layers::LayersBackend aCompositorBackend,
-                           bool aNeutered);
+                           bool aNeutered, bool aIsWriteOnly);
   ~OffscreenCanvasCloneData();
 
   RefPtr<layers::AsyncCanvasRenderer> mRenderer;
   uint32_t mWidth;
   uint32_t mHeight;
   layers::LayersBackend mCompositorBackendType;
   bool mNeutered;
+  bool mIsWriteOnly;
 };
 
 class OffscreenCanvas final : public DOMEventTargetHelper
                             , public CanvasRenderingContextHelper
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(OffscreenCanvas, DOMEventTargetHelper)
@@ -142,16 +143,26 @@ public:
     mNeutered = true;
   }
 
   bool IsNeutered() const
   {
     return mNeutered;
   }
 
+  void SetWriteOnly()
+  {
+    mIsWriteOnly = true;
+  }
+
+  bool IsWriteOnly() const
+  {
+    return mIsWriteOnly;
+  }
+
   layers::LayersBackend GetCompositorBackendType() const
   {
     return mCompositorBackendType;
   }
 
 private:
   ~OffscreenCanvas();
 
@@ -159,16 +170,17 @@ private:
   {
     mAttrDirty = true;
     ErrorResult dummy;
     UpdateContext(nullptr, JS::NullHandleValue, dummy);
   }
 
   bool mAttrDirty;
   bool mNeutered;
+  bool mIsWriteOnly;
 
   uint32_t mWidth;
   uint32_t mHeight;
 
   layers::LayersBackend mCompositorBackendType;
 
   layers::CanvasClient* mCanvasClient;
   RefPtr<layers::AsyncCanvasRenderer> mCanvasRenderer;
--- a/dom/html/HTMLCanvasElement.cpp
+++ b/dom/html/HTMLCanvasElement.cpp
@@ -778,16 +778,20 @@ HTMLCanvasElement::TransferControlToOffs
     RefPtr<AsyncCanvasRenderer> renderer = GetAsyncCanvasRenderer();
     renderer->SetWidth(sz.width);
     renderer->SetHeight(sz.height);
 
     mOffscreenCanvas = new OffscreenCanvas(sz.width,
                                            sz.height,
                                            GetCompositorBackendType(),
                                            renderer);
+    if (mWriteOnly) {
+      mOffscreenCanvas->SetWriteOnly();
+    }
+
     if (!mContextObserver) {
       mContextObserver = new HTMLCanvasElementObserver(this);
     }
   } else {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
   }
 
   return mOffscreenCanvas;