Bug 800556; remove nsIDOMCanvasRenderingContext2D; r=Ms2ger,sr=bz
authorNicholas Cameron <ncameron@mozilla.com>
Tue, 13 Nov 2012 16:35:36 -0800
changeset 121839 f2efbff15c831ef1b6cae49e216714bb87825941
parent 121838 3fd41b40e88f930d9220171e43e261ce694d29c4
child 121840 70859e1ddfe71a17fe92a78623e2fc8e53fb4f84
push id273
push userlsblakk@mozilla.com
push dateThu, 14 Feb 2013 23:19:38 +0000
treeherdermozilla-release@c5e807a3f8b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger, bz
bugs800556
milestone19.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 800556; remove nsIDOMCanvasRenderingContext2D; r=Ms2ger,sr=bz
content/canvas/src/CanvasRenderingContext2D.cpp
content/canvas/src/CanvasRenderingContext2D.h
content/canvas/src/Makefile.in
content/html/content/src/nsHTMLCanvasElement.cpp
dom/interfaces/canvas/nsIDOMCanvasRenderingContext2D.idl
layout/build/nsLayoutModule.cpp
widget/nsITaskbarPreviewController.idl
widget/windows/TaskbarPreview.cpp
widget/windows/WinTaskbar.cpp
--- a/content/canvas/src/CanvasRenderingContext2D.cpp
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp
@@ -112,27 +112,16 @@ using namespace mozilla::gfx;
 using namespace mozilla::ipc;
 using namespace mozilla::layers;
 
 namespace mgfx = mozilla::gfx;
 
 #define NS_TEXTMETRICSAZURE_PRIVATE_IID \
   {0x9793f9e7, 0x9dc1, 0x4e9c, {0x81, 0xc8, 0xfc, 0xa7, 0x14, 0xf4, 0x30, 0x79}}
 
-nsresult
-NS_NewCanvasRenderingContext2D(nsIDOMCanvasRenderingContext2D** aResult)
-{
-  Telemetry::Accumulate(Telemetry::CANVAS_2D_USED, 1);
-  nsRefPtr<nsIDOMCanvasRenderingContext2D> ctx =
-    new mozilla::dom::CanvasRenderingContext2D();
-
-  ctx.forget(aResult);
-  return NS_OK;
-}
-
 namespace mozilla {
 namespace dom {
 
 static float kDefaultFontSize = 10.0;
 static NS_NAMED_LITERAL_STRING(kDefaultFontName, "sans-serif");
 static NS_NAMED_LITERAL_STRING(kDefaultFontStyle, "10px sans-serif");
 
 // Cap sigma to avoid overly large temp surfaces.
@@ -529,20 +518,18 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
 
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(CanvasRenderingContext2D)
   return nsCCUncollectableMarker::sGeneration && tmp->IsBlack();
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CanvasRenderingContext2D)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsIDOMCanvasRenderingContext2D)
   NS_INTERFACE_MAP_ENTRY(nsICanvasRenderingContextInternal)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports,
-                                   nsICanvasRenderingContextInternal)
+  NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 /**
  ** CanvasRenderingContext2D impl
  **/
 
 
 // Initialize our static variables.
@@ -662,43 +649,16 @@ CanvasRenderingContext2D::SetStyleFromSt
   nscolor color;
   if (!ParseColor(str, &color)) {
     return;
   }
 
   CurrentState().SetColorStyle(whichStyle, color);
 }
 
-void
-CanvasRenderingContext2D::SetStyleFromStringOrInterface(const nsAString& aStr,
-                                                        nsISupports *aInterface,
-                                                        Style aWhichStyle)
-{
-  if (!aStr.IsVoid()) {
-    SetStyleFromString(aStr, aWhichStyle);
-    return;
-  }
-
-  if (aInterface) {
-    nsCOMPtr<CanvasGradient> grad(do_QueryInterface(aInterface));
-    if (grad) {
-      SetStyleFromGradient(grad, aWhichStyle);
-      return;
-    }
-
-    nsCOMPtr<CanvasPattern> pattern(do_QueryInterface(aInterface));
-    if (pattern) {
-      SetStyleFromPattern(pattern, aWhichStyle);
-      return;
-    }
-  }
-
-  WarnAboutUnexpectedStyle(mCanvasElement);
-}
-
 nsISupports*
 CanvasRenderingContext2D::GetStyleAsStringOrInterface(nsAString& aStr,
                                                       CanvasMultiGetterType& aType,
                                                       Style aWhichStyle)
 {
   const ContextState &state = CurrentState();
   nsISupports* supports;
   if (state.patternStyles[aWhichStyle]) {
@@ -1062,49 +1022,28 @@ CanvasRenderingContext2D::GetInputStream
 
 SurfaceFormat
 CanvasRenderingContext2D::GetSurfaceFormat() const
 {
   return mOpaque ? FORMAT_B8G8R8X8 : FORMAT_B8G8R8A8;
 }
 
 //
-// CanvasRenderingContext2D impl
-//
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetCanvas(nsIDOMHTMLCanvasElement **canvas)
-{
-  if (mCanvasElement) {
-    NS_IF_ADDREF(*canvas = mCanvasElement->GetOriginalCanvas());
-  }
-
-  return NS_OK;
-}
-
-//
 // state
 //
 
 void
 CanvasRenderingContext2D::Save()
 {
   EnsureTarget();
   mStyleStack[mStyleStack.Length() - 1].transform = mTarget->GetTransform();
   mStyleStack.SetCapacity(mStyleStack.Length() + 1);
   mStyleStack.AppendElement(CurrentState());
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::MozSave()
-{
-  Save();
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::Restore()
 {
   if (mStyleStack.Length() - 1 == 0)
     return;
 
   TransformWillUpdate();
 
@@ -1112,23 +1051,16 @@ CanvasRenderingContext2D::Restore()
     mTarget->PopClip();
   }
 
   mStyleStack.RemoveElementAt(mStyleStack.Length() - 1);
 
   mTarget->SetTransform(CurrentState().transform);
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::MozRestore()
-{
-  Restore();
-  return NS_OK;
-}
-
 //
 // transformations
 //
 
 void
 CanvasRenderingContext2D::Scale(double x, double y, ErrorResult& error)
 {
   if (!FloatValidate(x,y)) {
@@ -1140,24 +1072,16 @@ CanvasRenderingContext2D::Scale(double x
     error.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   Matrix newMatrix = mTarget->GetTransform();
   mTarget->SetTransform(newMatrix.Scale(x, y));
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::Scale(float x, float y)
-{
-  ErrorResult rv;
-  Scale((double)x, (double)y, rv);
-  return rv.ErrorCode();
-}
-
 void
 CanvasRenderingContext2D::Rotate(double angle, ErrorResult& error)
 {
   if (!FloatValidate(angle)) {
     return;
   }
 
   TransformWillUpdate();
@@ -1166,24 +1090,16 @@ CanvasRenderingContext2D::Rotate(double 
     return;
   }
 
 
   Matrix rotation = Matrix::Rotation(angle);
   mTarget->SetTransform(rotation * mTarget->GetTransform());
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::Rotate(float angle)
-{
-  ErrorResult rv;
-  Rotate((double)angle, rv);
-  return rv.ErrorCode();
-}
-
 void
 CanvasRenderingContext2D::Translate(double x, double y, ErrorResult& error)
 {
   if (!FloatValidate(x,y)) {
     return;
   }
 
   TransformWillUpdate();
@@ -1191,24 +1107,16 @@ CanvasRenderingContext2D::Translate(doub
     error.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   Matrix newMatrix = mTarget->GetTransform();
   mTarget->SetTransform(newMatrix.Translate(x, y));
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::Translate(float x, float y)
-{
-  ErrorResult rv;
-  Translate((double)x, (double)y, rv);
-  return rv.ErrorCode();
-}
-
 void
 CanvasRenderingContext2D::Transform(double m11, double m12, double m21,
                                     double m22, double dx, double dy,
                                     ErrorResult& error)
 {
   if (!FloatValidate(m11,m12,m21,m22,dx,dy)) {
     return;
   }
@@ -1218,25 +1126,16 @@ CanvasRenderingContext2D::Transform(doub
     error.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   Matrix matrix(m11, m12, m21, m22, dx, dy);
   mTarget->SetTransform(matrix * mTarget->GetTransform());
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::Transform(float m11, float m12, float m21, float m22, float dx, float dy)
-{
-  ErrorResult rv;
-  Transform((double)m11, (double)m12, (double)m21, (double)m22, (double)dx,
-            (double)dy, rv);
-  return rv.ErrorCode();
-}
-
 void
 CanvasRenderingContext2D::SetTransform(double m11, double m12,
                                        double m21, double m22,
                                        double dx, double dy,
                                        ErrorResult& error)
 {
   if (!FloatValidate(m11,m12,m21,m22,dx,dy)) {
     return;
@@ -1247,25 +1146,16 @@ CanvasRenderingContext2D::SetTransform(d
     error.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   Matrix matrix(m11, m12, m21, m22, dx, dy);
   mTarget->SetTransform(matrix);
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetTransform(float m11, float m12, float m21, float m22, float dx, float dy)
-{
-  ErrorResult rv;
-  SetTransform((double)m11, (double)m12, (double)m21, (double)m22, (double)dx,
-               (double)dy, rv);
-  return rv.ErrorCode();
-}
-
 JSObject*
 MatrixToJSObject(JSContext* cx, const Matrix& matrix, ErrorResult& error)
 {
   jsval elts[] = {
     DOUBLE_TO_JSVAL(matrix._11), DOUBLE_TO_JSVAL(matrix._12),
     DOUBLE_TO_JSVAL(matrix._21), DOUBLE_TO_JSVAL(matrix._22),
     DOUBLE_TO_JSVAL(matrix._31), DOUBLE_TO_JSVAL(matrix._32)
   };
@@ -1322,48 +1212,23 @@ CanvasRenderingContext2D::SetMozCurrentT
   }
 
   Matrix newCTM;
   if (ObjectToMatrix(cx, currentTransform, newCTM, error)) {
     mTarget->SetTransform(newCTM);
   }
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetMozCurrentTransform(JSContext* cx,
-                                                 const jsval& matrix)
-{
-  if (!matrix.isObject()) {
-    return NS_ERROR_INVALID_ARG;
-  }
-
-  ErrorResult rv;
-  SetMozCurrentTransform(cx, matrix.toObject(), rv);
-  return rv.ErrorCode();
-}
-
 JSObject*
 CanvasRenderingContext2D::GetMozCurrentTransform(JSContext* cx,
                                                  ErrorResult& error) const
 {
   return MatrixToJSObject(cx, mTarget ? mTarget->GetTransform() : Matrix(), error);
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetMozCurrentTransform(JSContext* cx,
-                                                 jsval* matrix)
-{
-  ErrorResult rv;
-  JSObject* obj = GetMozCurrentTransform(cx, rv);
-  if (!rv.Failed()) {
-    *matrix = OBJECT_TO_JSVAL(obj);
-  }
-  return rv.ErrorCode();
-}
-
 void
 CanvasRenderingContext2D::SetMozCurrentTransformInverse(JSContext* cx,
                                                         JSObject& currentTransform,
                                                         ErrorResult& error)
 {
   EnsureTarget();
   if (!IsTargetValid()) {
     error.Throw(NS_ERROR_FAILURE);
@@ -1374,29 +1239,16 @@ CanvasRenderingContext2D::SetMozCurrentT
   if (ObjectToMatrix(cx, currentTransform, newCTMInverse, error)) {
     // XXX ERRMSG we need to report an error to developers here! (bug 329026)
     if (newCTMInverse.Invert()) {
       mTarget->SetTransform(newCTMInverse);
     }
   }
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetMozCurrentTransformInverse(JSContext* cx,
-                                                        const jsval& matrix)
-{
-  if (!matrix.isObject()) {
-    return NS_ERROR_INVALID_ARG;
-  }
-
-  ErrorResult rv;
-  SetMozCurrentTransformInverse(cx, matrix.toObject(), rv);
-  return rv.ErrorCode();
-}
-
 JSObject*
 CanvasRenderingContext2D::GetMozCurrentTransformInverse(JSContext* cx,
                                                         ErrorResult& error) const
 {
   if (!mTarget) {
     return MatrixToJSObject(cx, Matrix(), error);
   }
 
@@ -1405,46 +1257,20 @@ CanvasRenderingContext2D::GetMozCurrentT
   if (!ctm.Invert()) {
     double NaN = JSVAL_TO_DOUBLE(JS_GetNaNValue(cx));
     ctm = Matrix(NaN, NaN, NaN, NaN, NaN, NaN);
   }
 
   return MatrixToJSObject(cx, ctm, error);
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetMozCurrentTransformInverse(JSContext* cx,
-                                                        jsval* matrix)
-{
-  ErrorResult rv;
-  JSObject* obj = GetMozCurrentTransformInverse(cx, rv);
-  if (!rv.Failed()) {
-    *matrix = OBJECT_TO_JSVAL(obj);
-  }
-  return rv.ErrorCode();
-}
-
 //
 // colors
 //
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetGlobalAlpha(float aGlobalAlpha)
-{
-  SetGlobalAlpha((double)aGlobalAlpha);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetGlobalAlpha(float *aGlobalAlpha)
-{
-  *aGlobalAlpha = GlobalAlpha();
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::SetStyleFromJSValue(JSContext* cx,
                                               JS::Value& value,
                                               Style whichStyle)
 {
   if (value.isString()) {
     nsDependentJSString strokeStyle;
     if (strokeStyle.init(cx, value.toString())) {
@@ -1475,257 +1301,88 @@ CanvasRenderingContext2D::SetStyleFromJS
     }
   }
 
   WarnAboutUnexpectedStyle(mCanvasElement);
 }
 
 static JS::Value
 WrapStyle(JSContext* cx, JSObject* obj,
-          nsIDOMCanvasRenderingContext2D::CanvasMultiGetterType type,
+          CanvasRenderingContext2D::CanvasMultiGetterType type,
           nsAString& str, nsISupports* supports, ErrorResult& error)
 {
   JS::Value v;
   bool ok;
   switch (type) {
-    case nsIDOMCanvasRenderingContext2D::CMG_STYLE_STRING:
+    case CanvasRenderingContext2D::CMG_STYLE_STRING:
     {
       ok = xpc::StringToJsval(cx, str, &v);
       break;
     }
-    case nsIDOMCanvasRenderingContext2D::CMG_STYLE_PATTERN:
-    case nsIDOMCanvasRenderingContext2D::CMG_STYLE_GRADIENT:
+    case CanvasRenderingContext2D::CMG_STYLE_PATTERN:
+    case CanvasRenderingContext2D::CMG_STYLE_GRADIENT:
     {
       ok = dom::WrapObject(cx, obj, supports, &v);
       break;
     }
     default:
       MOZ_NOT_REACHED("unexpected CanvasMultiGetterType");
   }
   if (!ok) {
     error.Throw(NS_ERROR_FAILURE);
   }
   return v;
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetStrokeStyle(nsIVariant *aValue)
-{
-  if (!aValue)
-      return NS_ERROR_FAILURE;
-
-  nsString str;
-
-  nsresult rv;
-  uint16_t vtype;
-  rv = aValue->GetDataType(&vtype);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (vtype == nsIDataType::VTYPE_INTERFACE ||
-      vtype == nsIDataType::VTYPE_INTERFACE_IS)
-  {
-    nsIID *iid;
-    nsCOMPtr<nsISupports> sup;
-    rv = aValue->GetAsInterface(&iid, getter_AddRefs(sup));
-    NS_ENSURE_SUCCESS(rv, rv);
-    if (iid) {
-      NS_Free(iid);
-    }
-
-    str.SetIsVoid(true);
-    return SetStrokeStyle_multi(str, sup);
-  }
-
-  rv = aValue->GetAsAString(str);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return SetStrokeStyle_multi(str, nullptr);
-}
 
 JS::Value
 CanvasRenderingContext2D::GetStrokeStyle(JSContext* cx,
                                          ErrorResult& error)
 {
   nsString str;
   CanvasMultiGetterType t;
   nsISupports* supports = GetStyleAsStringOrInterface(str, t, STYLE_STROKE);
   return WrapStyle(cx, GetWrapper(), t, str, supports, error);
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetStrokeStyle(nsIVariant **aResult)
-{
-  nsCOMPtr<nsIWritableVariant> wv = do_CreateInstance(NS_VARIANT_CONTRACTID);
-
-  nsCOMPtr<nsISupports> sup;
-  nsString str;
-  int32_t t;
-  nsresult rv = GetStrokeStyle_multi(str, getter_AddRefs(sup), &t);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (t == CMG_STYLE_STRING) {
-    rv = wv->SetAsAString(str);
-  } else if (t == CMG_STYLE_PATTERN) {
-    rv = wv->SetAsInterface(NS_GET_IID(nsIDOMCanvasPattern),
-                            sup);
-  } else if (t == CMG_STYLE_GRADIENT) {
-    rv = wv->SetAsInterface(NS_GET_IID(nsIDOMCanvasGradient),
-                            sup);
-  } else {
-    NS_ERROR("Unknown type from GetStroke/FillStyle_multi!");
-    return NS_ERROR_FAILURE;
-  }
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  NS_IF_ADDREF(*aResult = wv.get());
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetFillStyle(nsIVariant *aValue)
-{
-  if (!aValue) {
-    return NS_ERROR_FAILURE;
-  }
-
-  nsString str;
-  nsresult rv;
-  uint16_t vtype;
-  rv = aValue->GetDataType(&vtype);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (vtype == nsIDataType::VTYPE_INTERFACE ||
-      vtype == nsIDataType::VTYPE_INTERFACE_IS)
-  {
-    nsIID *iid;
-    nsCOMPtr<nsISupports> sup;
-    rv = aValue->GetAsInterface(&iid, getter_AddRefs(sup));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    str.SetIsVoid(true);
-    return SetFillStyle_multi(str, sup);
-  }
-
-  rv = aValue->GetAsAString(str);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return SetFillStyle_multi(str, nullptr);
-}
-
 JS::Value
 CanvasRenderingContext2D::GetFillStyle(JSContext* cx,
                                        ErrorResult& error)
 {
   nsString str;
   CanvasMultiGetterType t;
   nsISupports* supports = GetStyleAsStringOrInterface(str, t, STYLE_FILL);
   return WrapStyle(cx, GetWrapper(), t, str, supports, error);
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetFillStyle(nsIVariant **aResult)
-{
-  nsCOMPtr<nsIWritableVariant> wv = do_CreateInstance(NS_VARIANT_CONTRACTID);
-
-  nsCOMPtr<nsISupports> sup;
-  nsString str;
-  int32_t t;
-  nsresult rv = GetFillStyle_multi(str, getter_AddRefs(sup), &t);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (t == CMG_STYLE_STRING) {
-    rv = wv->SetAsAString(str);
-  } else if (t == CMG_STYLE_PATTERN) {
-    rv = wv->SetAsInterface(NS_GET_IID(nsIDOMCanvasPattern),
-                            sup);
-  } else if (t == CMG_STYLE_GRADIENT) {
-    rv = wv->SetAsInterface(NS_GET_IID(nsIDOMCanvasGradient),
-                            sup);
-  } else {
-    NS_ERROR("Unknown type from GetStroke/FillStyle_multi!");
-    return NS_ERROR_FAILURE;
-  }
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  NS_IF_ADDREF(*aResult = wv.get());
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::SetFillRule(const nsAString& aString)
 {
   FillRule rule;
 
   if (aString.EqualsLiteral("evenodd"))
     rule = FILL_EVEN_ODD;
   else if (aString.EqualsLiteral("nonzero"))
     rule = FILL_WINDING;
   else
     return;
 
   CurrentState().fillRule = rule;
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetMozFillRule(const nsAString& aString)
-{
-  SetFillRule(aString);
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::GetFillRule(nsAString& aString)
 {
-    switch (CurrentState().fillRule) {
-    case FILL_WINDING:
-      aString.AssignLiteral("nonzero"); break;
-    case FILL_EVEN_ODD:
-      aString.AssignLiteral("evenodd"); break;
-    }
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetMozFillRule(nsAString& aString)
-{
-  GetFillRule(aString);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetStrokeStyle_multi(const nsAString& aStr, nsISupports *aInterface)
-{
-  SetStyleFromStringOrInterface(aStr, aInterface, STYLE_STROKE);
-  return NS_OK;
+  switch (CurrentState().fillRule) {
+  case FILL_WINDING:
+    aString.AssignLiteral("nonzero"); break;
+  case FILL_EVEN_ODD:
+    aString.AssignLiteral("evenodd"); break;
+  }
 }
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetStrokeStyle_multi(nsAString& aStr, nsISupports **aInterface, int32_t *aType)
-{
-  CanvasMultiGetterType type;
-  NS_IF_ADDREF(*aInterface = GetStyleAsStringOrInterface(aStr, type, STYLE_STROKE));
-  *aType = type;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetFillStyle_multi(const nsAString& aStr, nsISupports *aInterface)
-{
-  SetStyleFromStringOrInterface(aStr, aInterface, STYLE_FILL);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetFillStyle_multi(nsAString& aStr, nsISupports **aInterface, int32_t *aType)
-{
-  CanvasMultiGetterType type;
-  NS_IF_ADDREF(*aInterface = GetStyleAsStringOrInterface(aStr, type, STYLE_FILL));
-  *aType = type;
-  return NS_OK;
-}
-
 //
 // gradients and patterns
 //
 already_AddRefed<nsIDOMCanvasGradient>
 CanvasRenderingContext2D::CreateLinearGradient(double x0, double y0, double x1, double y1,
                                                ErrorResult& aError)
 {
   if (!FloatValidate(x0,y0,x1,y1)) {
@@ -1734,25 +1391,16 @@ CanvasRenderingContext2D::CreateLinearGr
   }
 
   nsRefPtr<nsIDOMCanvasGradient> grad =
     new CanvasLinearGradient(Point(x0, y0), Point(x1, y1));
 
   return grad.forget();
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::CreateLinearGradient(float x0, float y0, float x1, float y1,
-                                               nsIDOMCanvasGradient **_retval)
-{
-  ErrorResult rv;
-  *_retval = CreateLinearGradient(x0, y0, x1, y1, rv).get();
-  return rv.ErrorCode();
-}
-
 already_AddRefed<nsIDOMCanvasGradient>
 CanvasRenderingContext2D::CreateRadialGradient(double x0, double y0, double r0,
                                                double x1, double y1, double r1,
                                                ErrorResult& aError)
 {
   if (!FloatValidate(x0,y0,r0,x1,y1,r1)) {
     aError.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
     return nullptr;
@@ -1764,26 +1412,16 @@ CanvasRenderingContext2D::CreateRadialGr
   }
 
   nsRefPtr<nsIDOMCanvasGradient> grad =
     new CanvasRadialGradient(Point(x0, y0), r0, Point(x1, y1), r1);
 
   return grad.forget();
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::CreateRadialGradient(float x0, float y0, float r0,
-                                               float x1, float y1, float r1,
-                                               nsIDOMCanvasGradient **_retval)
-{
-  ErrorResult rv;
-  *_retval = CreateRadialGradient(x0, y0, r0, x1, y1, r1, rv).get();
-  return rv.ErrorCode();
-}
-
 already_AddRefed<nsIDOMCanvasPattern>
 CanvasRenderingContext2D::CreatePattern(const HTMLImageOrCanvasOrVideoElement& element,
                                         const nsAString& repeat,
                                         ErrorResult& error)
 {
   CanvasPattern::RepeatMode repeatMode =
     CanvasPattern::NOREPEAT;
 
@@ -1850,101 +1488,30 @@ CanvasRenderingContext2D::CreatePattern(
 
   nsRefPtr<CanvasPattern> pat =
     new CanvasPattern(srcSurf, repeatMode, res.mPrincipal,
                              res.mIsWriteOnly, res.mCORSUsed);
 
   return pat.forget();
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::CreatePattern(nsIDOMHTMLElement *image,
-                                        const nsAString& repeat,
-                                        nsIDOMCanvasPattern **_retval)
-{
-  HTMLImageOrCanvasOrVideoElement element;
-  if (!ToHTMLImageOrCanvasOrVideoElement(image, element)) {
-    return NS_ERROR_DOM_TYPE_MISMATCH_ERR;
-  }
-
-  ErrorResult rv;
-  *_retval = CreatePattern(element, repeat, rv).get();
-  return rv.ErrorCode();
-}
-
 //
 // shadows
 //
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetShadowOffsetX(float x)
-{
-  SetShadowOffsetX((double)x);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetShadowOffsetX(float *x)
-{
-  *x = static_cast<float>(ShadowOffsetX());
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetShadowOffsetY(float y)
-{
-  SetShadowOffsetY((double)y);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetShadowOffsetY(float *y)
-{
-  *y = static_cast<float>(ShadowOffsetY());
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetShadowBlur(float blur)
-{
-  SetShadowBlur((double)blur);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetShadowBlur(float *blur)
-{
-  *blur = ShadowBlur();
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::SetShadowColor(const nsAString& shadowColor)
 {
   nscolor color;
   if (!ParseColor(shadowColor, &color)) {
     return;
   }
 
   CurrentState().shadowColor = color;
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetMozShadowColor(const nsAString& colorstr)
-{
-  SetShadowColor(colorstr);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetMozShadowColor(nsAString& color)
-{
-  GetShadowColor(color);
-  return NS_OK;
-}
-
 //
 // rects
 //
 
 void
 CanvasRenderingContext2D::ClearRect(double x, double y, double w,
                                     double h)
 {
@@ -1952,23 +1519,16 @@ CanvasRenderingContext2D::ClearRect(doub
     return;
   }
 
   mTarget->ClearRect(mgfx::Rect(x, y, w, h));
 
   RedrawUser(gfxRect(x, y, w, h));
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::ClearRect(float x, float y, float w, float h)
-{
-  ClearRect((double)x, (double)y, (double)w, (double)h);
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::FillRect(double x, double y, double w,
                                    double h)
 {
   if (!FloatValidate(x,y,w,h)) {
     return;
   }
 
@@ -2031,23 +1591,16 @@ CanvasRenderingContext2D::FillRect(doubl
   AdjustedTarget(this, bounds.IsEmpty() ? nullptr : &bounds)->
     FillRect(mgfx::Rect(x, y, w, h),
              CanvasGeneralPattern().ForStyle(this, STYLE_FILL, mTarget),
              DrawOptions(state.globalAlpha, UsedOperation()));
 
   RedrawUser(gfxRect(x, y, w, h));
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::FillRect(float x, float y, float w, float h)
-{
-  FillRect((double)x, (double)y, (double)w, (double)h);
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::StrokeRect(double x, double y, double w,
                                      double h)
 {
   if (!FloatValidate(x,y,w,h)) {
     return;
   }
 
@@ -2112,50 +1665,29 @@ CanvasRenderingContext2D::StrokeRect(dou
                               state.dash.Length(),
                               state.dash.Elements(),
                               state.dashOffset),
                 DrawOptions(state.globalAlpha, UsedOperation()));
 
   Redraw();
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::StrokeRect(float x, float y, float w, float h)
-{
-  StrokeRect((double)x, (double)y, (double)w, (double)h);
-  return NS_OK;
-}
-
 //
 // path bits
 //
 
 void
 CanvasRenderingContext2D::BeginPath()
 {
   mPath = nullptr;
   mPathBuilder = nullptr;
   mDSPathBuilder = nullptr;
   mPathTransformWillUpdate = false;
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::MozBeginPath()
-{
-  BeginPath();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::MozClosePath()
-{
-  ClosePath();
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::Fill()
 {
   EnsureUserSpacePath();
 
   if (!mPath) {
     return;
   }
@@ -2168,23 +1700,16 @@ CanvasRenderingContext2D::Fill()
 
   AdjustedTarget(this, bounds.IsEmpty() ? nullptr : &bounds)->
     Fill(mPath, CanvasGeneralPattern().ForStyle(this, STYLE_FILL, mTarget),
          DrawOptions(CurrentState().globalAlpha, UsedOperation()));
 
   Redraw();
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::MozFill()
-{
-  Fill();
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::Stroke()
 {
   EnsureUserSpacePath();
 
   if (!mPath) {
     return;
   }
@@ -2204,75 +1729,29 @@ CanvasRenderingContext2D::Stroke()
 
   AdjustedTarget(this, bounds.IsEmpty() ? nullptr : &bounds)->
     Stroke(mPath, CanvasGeneralPattern().ForStyle(this, STYLE_STROKE, mTarget),
            strokeOptions, DrawOptions(state.globalAlpha, UsedOperation()));
 
   Redraw();
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::MozStroke()
-{
-  Stroke();
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::Clip()
 {
   EnsureUserSpacePath();
 
   if (!mPath) {
     return;
   }
 
   mTarget->PushClip(mPath);
   CurrentState().clipsPushed.push_back(mPath);
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::MozClip()
-{
-  Clip();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::MoveTo(float x, float y)
-{
-  MoveTo((double)x, (double)y);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::LineTo(float x, float y)
-{
-  LineTo((double)x, (double)y);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::QuadraticCurveTo(float cpx, float cpy, float x,
-                                           float y)
-{
-  QuadraticCurveTo((double)cpx, (double)cpy, (double)x, (double)y);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::BezierCurveTo(float cp1x, float cp1y,
-                                        float cp2x, float cp2y,
-                                        float x, float y)
-{
-  BezierCurveTo((double)cp1x, (double)cp1y, (double)cp2x, (double)cp2y,
-                (double)x, (double)y);
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::ArcTo(double x1, double y1, double x2,
                                 double y2, double radius,
                                 ErrorResult& error)
 {
   if (!FloatValidate(x1, y1, x2, y2, radius)) {
     return;
   }
@@ -2342,25 +1821,17 @@ CanvasRenderingContext2D::ArcTo(double x
   cx = x3 + any*radius*(anticlockwise ? 1 : -1);
   cy = y3 - anx*radius*(anticlockwise ? 1 : -1);
   angle0 = atan2((y3-cy), (x3-cx));
   angle1 = atan2((y4-cy), (x4-cx));
 
 
   LineTo(x3, y3);
 
-  Arc(cx, cy, radius, angle0, angle1, anticlockwise);
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::ArcTo(float x1, float y1, float x2, float y2, float radius)
-{
-  ErrorResult rv;
-  ArcTo(x1, y1, x2, y2, radius, rv);
-  return rv.ErrorCode();
+  Arc(cx, cy, radius, angle0, angle1, anticlockwise, error);
 }
 
 void
 CanvasRenderingContext2D::Arc(double x, double y, double r,
                               double startAngle, double endAngle,
                               bool anticlockwise, ErrorResult& error)
 {
   if (!FloatValidate(x, y, r, startAngle, endAngle)) {
@@ -2372,27 +1843,16 @@ CanvasRenderingContext2D::Arc(double x, 
     return;
   }
 
   EnsureWritablePath();
 
   ArcToBezier(this, Point(x, y), r, startAngle, endAngle, anticlockwise);
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::Arc(float x, float y,
-                              float r,
-                              float startAngle, float endAngle,
-                              bool ccw)
-{
-  ErrorResult rv;
-  Arc(x, y, r, startAngle, endAngle, ccw, rv);
-  return rv.ErrorCode();
-}
-
 void
 CanvasRenderingContext2D::Rect(double x, double y, double w, double h)
 {
   if (!FloatValidate(x, y, w, h)) {
     return;
   }
 
   EnsureWritablePath();
@@ -2407,23 +1867,16 @@ CanvasRenderingContext2D::Rect(double x,
     mDSPathBuilder->MoveTo(mTarget->GetTransform() * Point(x, y));
     mDSPathBuilder->LineTo(mTarget->GetTransform() * Point(x + w, y));
     mDSPathBuilder->LineTo(mTarget->GetTransform() * Point(x + w, y + h));
     mDSPathBuilder->LineTo(mTarget->GetTransform() * Point(x, y + h));
     mDSPathBuilder->Close();
   }
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::Rect(float x, float y, float w, float h)
-{
-  Rect((double)x, (double)y, (double)w, (double)h);
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::EnsureWritablePath()
 {
   if (mDSPathBuilder) {
     return;
   }
 
   FillRule fillRule = CurrentState().fillRule;
@@ -2709,53 +2162,31 @@ CanvasRenderingContext2D::SetFont(const 
 
   // The font getter is required to be reserialized based on what we
   // parsed (including having line-height removed).  (Older drafts of
   // the spec required font sizes be converted to pixels, but that no
   // longer seems to be required.)
   declaration->GetValue(eCSSProperty_font, CurrentState().font);
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetMozFont(const nsAString& font)
-{
-  ErrorResult rv;
-  SetFont(font, rv);
-  return rv.ErrorCode();
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetMozFont(nsAString& font)
-{
-  font = GetFont();
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::SetTextAlign(const nsAString& ta)
 {
   if (ta.EqualsLiteral("start"))
     CurrentState().textAlign = TEXT_ALIGN_START;
   else if (ta.EqualsLiteral("end"))
     CurrentState().textAlign = TEXT_ALIGN_END;
   else if (ta.EqualsLiteral("left"))
     CurrentState().textAlign = TEXT_ALIGN_LEFT;
   else if (ta.EqualsLiteral("right"))
     CurrentState().textAlign = TEXT_ALIGN_RIGHT;
   else if (ta.EqualsLiteral("center"))
     CurrentState().textAlign = TEXT_ALIGN_CENTER;
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetMozTextAlign(const nsAString& ta)
-{
-  SetTextAlign(ta);
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::GetTextAlign(nsAString& ta)
 {
   switch (CurrentState().textAlign)
   {
   case TEXT_ALIGN_START:
     ta.AssignLiteral("start");
     break;
@@ -2769,23 +2200,16 @@ CanvasRenderingContext2D::GetTextAlign(n
     ta.AssignLiteral("right");
     break;
   case TEXT_ALIGN_CENTER:
     ta.AssignLiteral("center");
     break;
   }
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetMozTextAlign(nsAString& ta)
-{
-  GetTextAlign(ta);
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::SetTextBaseline(const nsAString& tb)
 {
   if (tb.EqualsLiteral("top"))
     CurrentState().textBaseline = TEXT_BASELINE_TOP;
   else if (tb.EqualsLiteral("hanging"))
     CurrentState().textBaseline = TEXT_BASELINE_HANGING;
   else if (tb.EqualsLiteral("middle"))
@@ -2793,23 +2217,16 @@ CanvasRenderingContext2D::SetTextBaselin
   else if (tb.EqualsLiteral("alphabetic"))
     CurrentState().textBaseline = TEXT_BASELINE_ALPHABETIC;
   else if (tb.EqualsLiteral("ideographic"))
     CurrentState().textBaseline = TEXT_BASELINE_IDEOGRAPHIC;
   else if (tb.EqualsLiteral("bottom"))
     CurrentState().textBaseline = TEXT_BASELINE_BOTTOM;
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetMozTextBaseline(const nsAString& tb)
-{
-  SetTextBaseline(tb);
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::GetTextBaseline(nsAString& tb)
 {
   switch (CurrentState().textBaseline)
   {
   case TEXT_BASELINE_TOP:
     tb.AssignLiteral("top");
     break;
@@ -2826,23 +2243,16 @@ CanvasRenderingContext2D::GetTextBaselin
     tb.AssignLiteral("ideographic");
     break;
   case TEXT_BASELINE_BOTTOM:
     tb.AssignLiteral("bottom");
     break;
   }
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetMozTextBaseline(nsAString& tb)
-{
-  GetTextBaseline(tb);
-  return NS_OK;
-}
-
 /*
  * Helper function that replaces the whitespace characters in a string
  * with U+0020 SPACE. The whitespace characters are defined as U+0020 SPACE,
  * U+0009 CHARACTER TABULATION (tab), U+000A LINE FEED (LF), U+000B LINE
  * TABULATION, U+000C FORM FEED (FF), and U+000D CARRIAGE RETURN (CR).
  * @param str The string whose whitespace characters to replace.
  */
 static inline void
@@ -2855,72 +2265,41 @@ void
 CanvasRenderingContext2D::FillText(const nsAString& text, double x,
                                    double y,
                                    const Optional<double>& maxWidth,
                                    ErrorResult& error)
 {
   error = DrawOrMeasureText(text, x, y, maxWidth, TEXT_DRAW_OPERATION_FILL, nullptr);
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::FillText(const nsAString& text, float x, float y, float maxWidth)
-{
-  ErrorResult rv;
-  Optional<double> optionalMaxWidth;
-  optionalMaxWidth.Construct();
-  optionalMaxWidth.Value() = maxWidth;
-  FillText(text, x, y, optionalMaxWidth, rv);
-  return rv.ErrorCode();
-}
-
 void
 CanvasRenderingContext2D::StrokeText(const nsAString& text, double x,
                                      double y,
                                      const Optional<double>& maxWidth,
                                      ErrorResult& error)
 {
   error = DrawOrMeasureText(text, x, y, maxWidth, TEXT_DRAW_OPERATION_STROKE, nullptr);
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::StrokeText(const nsAString& text, float x, float y, float maxWidth)
-{
-  ErrorResult rv;
-  Optional<double> optionalMaxWidth;
-  optionalMaxWidth.Construct();
-  optionalMaxWidth.Value() = maxWidth;
-  StrokeText(text, x, y, optionalMaxWidth, rv);
-  return rv.ErrorCode();
-}
-
 already_AddRefed<nsIDOMTextMetrics>
 CanvasRenderingContext2D::MeasureText(const nsAString& rawText,
                                       ErrorResult& error)
 {
   float width;
   Optional<double> maxWidth;
   error = DrawOrMeasureText(rawText, 0, 0, maxWidth, TEXT_DRAW_OPERATION_MEASURE, &width);
   if (error.Failed()) {
     return NULL;
   }
 
   nsRefPtr<nsIDOMTextMetrics> textMetrics = new TextMetrics(width);
 
   return textMetrics.forget();
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::MeasureText(const nsAString& rawText,
-                                      nsIDOMTextMetrics** _retval)
-{
-  ErrorResult rv;
-  *_retval = MeasureText(rawText, rv).get();
-  return rv.ErrorCode();
-}
-
 /**
  * Used for nsBidiPresUtils::ProcessText
  */
 struct NS_STACK_CLASS CanvasBidiProcessor : public nsBidiPresUtils::BidiProcessor
 {
   typedef CanvasRenderingContext2D::ContextState ContextState;
 
   virtual void SetText(const PRUnichar* text, int32_t length, nsBidiDirection direction)
@@ -3381,75 +2760,45 @@ CanvasRenderingContext2D::DrawOrMeasureT
     RedrawUser(boundingBox);
     return NS_OK;
   }
 
   Redraw();
   return NS_OK;
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetTextStyle(const nsAString& textStyle)
-{
-  ErrorResult rv;
-  SetMozTextStyle(textStyle, rv);
-  return rv.ErrorCode();
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetTextStyle(nsAString& textStyle)
-{
-  GetMozTextStyle(textStyle);
-  return NS_OK;
-}
-
 gfxFontGroup *CanvasRenderingContext2D::GetCurrentFontStyle()
 {
   // use lazy initilization for the font group since it's rather expensive
   if (!CurrentState().fontGroup) {
-    nsresult rv = SetMozFont(kDefaultFontStyle);
-    if (NS_FAILED(rv)) {
+    ErrorResult err;
+    SetFont(kDefaultFontStyle, err);
+    if (err.Failed()) {
       gfxFontStyle style;
       style.size = kDefaultFontSize;
       CurrentState().fontGroup =
         gfxPlatform::GetPlatform()->CreateFontGroup(kDefaultFontName,
                                                     &style,
                                                     nullptr);
       if (CurrentState().fontGroup) {
         CurrentState().font = kDefaultFontStyle;
-        rv = NS_OK;
       } else {
-        rv = NS_ERROR_OUT_OF_MEMORY;
+        NS_ERROR("Default canvas font is invalid");
       }
     }
 
-    NS_ASSERTION(NS_SUCCEEDED(rv), "Default canvas font is invalid");
   }
 
   return CurrentState().fontGroup;
 }
 
 //
 // line caps/joins
 //
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetLineWidth(float width)
-{
-  SetLineWidth((double)width);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetLineWidth(float *width)
-{
-  *width = LineWidth();
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::SetLineCap(const nsAString& capstyle)
 {
   CapStyle cap;
 
   if (capstyle.EqualsLiteral("butt")) {
     cap = CAP_BUTT;
   } else if (capstyle.EqualsLiteral("round")) {
@@ -3459,46 +2808,32 @@ CanvasRenderingContext2D::SetLineCap(con
   } else {
     // XXX ERRMSG we need to report an error to developers here! (bug 329026)
     return;
   }
 
   CurrentState().lineCap = cap;
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetMozLineCap(const nsAString& capstyle)
-{
-  SetLineCap(capstyle);
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::GetLineCap(nsAString& capstyle)
 {
   switch (CurrentState().lineCap) {
   case CAP_BUTT:
     capstyle.AssignLiteral("butt");
     break;
   case CAP_ROUND:
     capstyle.AssignLiteral("round");
     break;
   case CAP_SQUARE:
     capstyle.AssignLiteral("square");
     break;
   }
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetMozLineCap(nsAString& capstyle)
-{
-  GetLineCap(capstyle);
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::SetLineJoin(const nsAString& joinstyle)
 {
   JoinStyle j;
 
   if (joinstyle.EqualsLiteral("round")) {
     j = JOIN_ROUND;
   } else if (joinstyle.EqualsLiteral("bevel")) {
@@ -3508,23 +2843,16 @@ CanvasRenderingContext2D::SetLineJoin(co
   } else {
     // XXX ERRMSG we need to report an error to developers here! (bug 329026)
     return;
   }
 
   CurrentState().lineJoin = j;
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetMozLineJoin(const nsAString& joinstyle)
-{
-  SetLineJoin(joinstyle);
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::GetLineJoin(nsAString& joinstyle, ErrorResult& error)
 {
   switch (CurrentState().lineJoin) {
   case JOIN_ROUND:
     joinstyle.AssignLiteral("round");
     break;
   case JOIN_BEVEL:
@@ -3533,100 +2861,51 @@ CanvasRenderingContext2D::GetLineJoin(ns
   case JOIN_MITER_OR_BEVEL:
     joinstyle.AssignLiteral("miter");
     break;
   default:
     error.Throw(NS_ERROR_FAILURE);
   }
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetMozLineJoin(nsAString& joinstyle)
-{
-  ErrorResult rv;
-  nsString linejoin;
-  GetLineJoin(linejoin, rv);
-  if (!rv.Failed()) {
-    joinstyle = linejoin;
-  }
-  return rv.ErrorCode();
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetMiterLimit(float miter)
-{
-  SetMiterLimit((double)miter);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetMiterLimit(float *miter)
-{
-  *miter = MiterLimit();
-  return NS_OK;
-}
-
 void
 CanvasRenderingContext2D::SetMozDash(JSContext* cx,
                                      const JS::Value& mozDash,
                                      ErrorResult& error)
 {
   FallibleTArray<Float> dash;
   error = JSValToDashArray(cx, mozDash, dash);
   if (!error.Failed()) {
     ContextState& state = CurrentState();
     state.dash = dash;
     if (state.dash.IsEmpty()) {
       state.dashOffset = 0;
     }
   }
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetMozDash(JSContext *cx, const jsval& patternArray)
-{
-  ErrorResult rv;
-  SetMozDash(cx, patternArray, rv);
-  return rv.ErrorCode();
-}
-
 JS::Value
 CanvasRenderingContext2D::GetMozDash(JSContext* cx, ErrorResult& error)
 {
   JS::Value mozDash;
   error = DashArrayToJSVal(CurrentState().dash, cx, &mozDash);
   return mozDash;
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetMozDash(JSContext* cx, jsval* dashArray)
-{
-  ErrorResult rv;
-  *dashArray = GetMozDash(cx, rv);
-  return rv.ErrorCode();
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetMozDashOffset(float offset)
+void
+CanvasRenderingContext2D::SetMozDashOffset(double mozDashOffset)
 {
-  if (!FloatValidate(offset)) {
-    return NS_ERROR_ILLEGAL_VALUE;
-  }
-  ContextState& state = CurrentState();
-  if (!state.dash.IsEmpty()) {
-    state.dashOffset = offset;
+  if (!FloatValidate(mozDashOffset)) {
+    return;
   }
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetMozDashOffset(float* offset)
-{
-  *offset = MozDashOffset();
-  return NS_OK;
+
+  ContextState& state = CurrentState();
+  if (!state.dash.IsEmpty()) {
+    state.dashOffset = mozDashOffset;
+  }
 }
 
 bool
 CanvasRenderingContext2D::IsPointInPath(double x, double y)
 {
   if (!FloatValidate(x,y)) {
     return false;
   }
@@ -3636,23 +2915,16 @@ CanvasRenderingContext2D::IsPointInPath(
     return false;
   }
   if (mPathTransformWillUpdate) {
     return mPath->ContainsPoint(Point(x, y), mPathToDS);
   }
   return mPath->ContainsPoint(Point(x, y), mTarget->GetTransform());
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::IsPointInPath(float x, float y, bool *retVal)
-{
-  *retVal = IsPointInPath(x, y);
-  return NS_OK;
-}
-
 bool
 CanvasRenderingContext2D::MozIsPointInStroke(double x, double y)
 {
   if (!FloatValidate(x,y)) {
     return false;
   }
 
   EnsureUserSpacePath(false);
@@ -3671,23 +2943,16 @@ CanvasRenderingContext2D::MozIsPointInSt
                               state.dashOffset);
 
   if (mPathTransformWillUpdate) {
     return mPath->StrokeContainsPoint(strokeOptions, Point(x, y), mPathToDS);
   }
   return mPath->StrokeContainsPoint(strokeOptions, Point(x, y), mTarget->GetTransform());
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::MozIsPointInStroke(float x, float y, bool *retVal)
-{
-  *retVal = MozIsPointInStroke(x, y);
-  return NS_OK;
-}
-
 //
 // image
 //
 
 // drawImage(in HTMLImageElement image, in float dx, in float dy);
 //   -- render image from 0,0 at dx,dy top-left coords
 // drawImage(in HTMLImageElement image, in float dx, in float dy, in float sw, in float sh);
 //   -- render image from 0,0 at dx,dy top-left coords clipping it to sw,sh
@@ -3846,51 +3111,16 @@ CanvasRenderingContext2D::DrawImage(cons
                 mgfx::Rect(dx, dy, dw, dh),
                 mgfx::Rect(sx, sy, sw, sh),
                 DrawSurfaceOptions(filter),
                 DrawOptions(CurrentState().globalAlpha, UsedOperation()));
 
   RedrawUser(gfxRect(dx, dy, dw, dh));
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::DrawImage(nsIDOMElement *imgElt, float a1,
-                                    float a2, float a3, float a4, float a5,
-                                    float a6, float a7, float a8,
-                                    uint8_t optional_argc)
-{
-  if (!(optional_argc == 0 || optional_argc == 2 || optional_argc == 6)) {
-    return NS_ERROR_INVALID_ARG;
-  }
-
-  HTMLImageOrCanvasOrVideoElement element;
-  if (!ToHTMLImageOrCanvasOrVideoElement(imgElt, element)) {
-    return NS_ERROR_DOM_TYPE_MISMATCH_ERR;
-  }
-
-  ErrorResult rv;
-  if (optional_argc == 0) {
-    if (!FloatValidate(a1, a2)) {
-      return NS_OK;
-    }
-    DrawImage(element, 0, 0, 0, 0, a1, a2, 0, 0, 0, rv);
-  } else if (optional_argc == 2) {
-    if (!FloatValidate(a1, a2, a3, a4)) {
-      return NS_OK;
-    }
-    DrawImage(element, 0, 0, 0, 0, a1, a2, a3, a4, 2, rv);
-  } else if (optional_argc == 6) {
-    if (!FloatValidate(a1, a2, a3, a4) || !FloatValidate(a5, a6, a7, a8)) {
-      return NS_OK;
-    }
-    DrawImage(element, a1, a2, a3, a4, a5, a6, a7, a8, 6, rv);
-  }
-  return rv.ErrorCode();
-}
-
 void
 CanvasRenderingContext2D::SetGlobalCompositeOperation(const nsAString& op,
                                                       ErrorResult& error)
 {
   CompositionOp comp_op;
 
 #define CANVAS_OP_TO_GFX_OP(cvsop, op2d) \
   if (op.EqualsLiteral(cvsop))   \
@@ -3909,24 +3139,16 @@ CanvasRenderingContext2D::SetGlobalCompo
   else CANVAS_OP_TO_GFX_OP("xor", XOR)
   // XXX ERRMSG we need to report an error to developers here! (bug 329026)
   else return;
 
 #undef CANVAS_OP_TO_GFX_OP
   CurrentState().op = comp_op;
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetGlobalCompositeOperation(const nsAString& op)
-{
-  ErrorResult rv;
-  SetGlobalCompositeOperation(op, rv);
-  return rv.ErrorCode();
-}
-
 void
 CanvasRenderingContext2D::GetGlobalCompositeOperation(nsAString& op,
                                                       ErrorResult& error)
 {
   CompositionOp comp_op = CurrentState().op;
 
 #define CANVAS_OP_TO_GFX_OP(cvsop, op2d) \
   if (comp_op == OP_##op2d) \
@@ -3945,28 +3167,16 @@ CanvasRenderingContext2D::GetGlobalCompo
   else CANVAS_OP_TO_GFX_OP("xor", XOR)
   else {
     error.Throw(NS_ERROR_FAILURE);
   }
 
 #undef CANVAS_OP_TO_GFX_OP
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetGlobalCompositeOperation(nsAString& op)
-{
-  nsString globalCompositeOperation;
-  ErrorResult rv;
-  GetGlobalCompositeOperation(globalCompositeOperation, rv);
-  if (!rv.Failed()) {
-    op = globalCompositeOperation;
-  }
-  return rv.ErrorCode();
-}
-
 void
 CanvasRenderingContext2D::DrawWindow(nsIDOMWindow* window, double x,
                                      double y, double w, double h,
                                      const nsAString& bgColor,
                                      uint32_t flags, ErrorResult& error)
 {
   // protect against too-large surfaces that will cause allocation
   // or overflow issues
@@ -4052,29 +3262,16 @@ CanvasRenderingContext2D::DrawWindow(nsI
   mTarget->SetTransform(matrix);
 
   // note that x and y are coordinates in the document that
   // we're drawing; x and y are drawn to 0,0 in current user
   // space.
   RedrawUser(gfxRect(0, 0, w, h));
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::DrawWindow(nsIDOMWindow* aWindow, float aX, float aY,
-                                     float aW, float aH,
-                                     const nsAString& aBGColor,
-                                     uint32_t flags)
-{
-  NS_ENSURE_ARG(aWindow);
-
-  ErrorResult rv;
-  DrawWindow(aWindow, aX, aY, aW, aH, aBGColor, flags, rv);
-  return rv.ErrorCode();
-}
-
 void
 CanvasRenderingContext2D::AsyncDrawXULElement(nsIDOMXULElement* elem,
                                               double x, double y,
                                               double w, double h,
                                               const nsAString& bgColor,
                                               uint32_t flags,
                                               ErrorResult& error)
 {
@@ -4151,30 +3348,16 @@ CanvasRenderingContext2D::AsyncDrawXULEl
     DocumentRendererParent *docrender =
       static_cast<DocumentRendererParent *>(pdocrender);
 
     docrender->SetCanvasContext(this, mThebes);
   }
 #endif
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::AsyncDrawXULElement(nsIDOMXULElement* aElem,
-                                              float aX, float aY,
-                                              float aW, float aH,
-                                              const nsAString& aBGColor,
-                                              uint32_t flags)
-{
-  NS_ENSURE_ARG(aElem);
-
-  ErrorResult rv;
-  AsyncDrawXULElement(aElem, aX, aY, aW, aH, aBGColor, flags, rv);
-  return rv.ErrorCode();
-}
-
 //
 // device pixel getting/setting
 //
 
 void
 CanvasRenderingContext2D::EnsureUnpremultiplyTable() {
   if (sUnpremultiplyTable)
     return;
@@ -4273,27 +3456,16 @@ CanvasRenderingContext2D::GetImageData(J
     return NULL;
   }
   MOZ_ASSERT(array);
 
   nsRefPtr<ImageData> imageData = new ImageData(w, h, *array);
   return imageData.forget();
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetImageData(double aSx, double aSy,
-                                       double aSw, double aSh,
-                                       JSContext* aCx,
-                                       nsISupports** aRetval)
-{
-  ErrorResult rv;
-  *aRetval = GetImageData(aCx, aSx, aSy, aSw, aSh, rv).get();
-  return rv.ErrorCode();
-}
-
 nsresult
 CanvasRenderingContext2D::GetImageDataArray(JSContext* aCx,
                                             int32_t aX,
                                             int32_t aY,
                                             uint32_t aWidth,
                                             uint32_t aHeight,
                                             JSObject** aRetval)
 {
@@ -4461,27 +3633,18 @@ CanvasRenderingContext2D::PutImageData(J
                                 JS_DoubleToInt32(dirtyX),
                                 JS_DoubleToInt32(dirtyY),
                                 JS_DoubleToInt32(dirtyWidth),
                                 JS_DoubleToInt32(dirtyHeight));
 }
 
 // void putImageData (in ImageData d, in float x, in float y);
 // void putImageData (in ImageData d, in double x, in double y, in double dirtyX, in double dirtyY, in double dirtyWidth, in double dirtyHeight);
-NS_IMETHODIMP
-CanvasRenderingContext2D::PutImageData(const JS::Value&, double, double,
-                                       double, double, double, double,
-                                       JSContext*, uint8_t)
-{
-  /* Should never be called -- the new binding code handles it, and
-     C++ callers should call PutImageData_explicit */
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
+
+nsresult
 CanvasRenderingContext2D::PutImageData_explicit(int32_t x, int32_t y, uint32_t w, uint32_t h,
                                                 unsigned char *aData, uint32_t aDataLen,
                                                 bool hasDirtyRect, int32_t dirtyX, int32_t dirtyY,
                                                 int32_t dirtyWidth, int32_t dirtyHeight)
 {
   if (w == 0 || h == 0) {
     return NS_ERROR_DOM_SYNTAX_ERR;
   }
@@ -4666,41 +3829,16 @@ already_AddRefed<ImageData>
 CanvasRenderingContext2D::CreateImageData(JSContext* cx,
                                           ImageData& imagedata,
                                           ErrorResult& error)
 {
   return mozilla::dom::CreateImageData(cx, this, imagedata.Width(),
                                        imagedata.Height(), error);
 }
 
-NS_IMETHODIMP
-CanvasRenderingContext2D::CreateImageData(const JS::Value &arg1,
-                                          const JS::Value &arg2,
-                                          JSContext* cx,
-                                          uint8_t optional_argc,
-                                          nsISupports** retval)
-{
-  /* Should never be called; handled entirely in new bindings */
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::GetMozImageSmoothingEnabled(bool *retVal)
-{
-  *retVal = ImageSmoothingEnabled();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-CanvasRenderingContext2D::SetMozImageSmoothingEnabled(bool val)
-{
-  SetImageSmoothingEnabled(val);
-  return NS_OK;
-}
-
 static uint8_t g2DContextLayerUserData;
 
 already_AddRefed<CanvasLayer>
 CanvasRenderingContext2D::GetCanvasLayer(nsDisplayListBuilder* aBuilder,
                                          CanvasLayer *aOldLayer,
                                          LayerManager *aManager)
 {
   // Don't call EnsureTarget() ... if there isn't already a surface, then
--- a/content/canvas/src/CanvasRenderingContext2D.h
+++ b/content/canvas/src/CanvasRenderingContext2D.h
@@ -6,29 +6,30 @@
 #define CanvasRenderingContext2D_h
 
 #include <vector>
 #include "nsIDOMCanvasRenderingContext2D.h"
 #include "nsICanvasRenderingContextInternal.h"
 #include "mozilla/RefPtr.h"
 #include "nsColor.h"
 #include "nsHTMLCanvasElement.h"
+#include "nsHTMLVideoElement.h"
 #include "CanvasUtils.h"
-#include "nsHTMLImageElement.h"
-#include "nsHTMLVideoElement.h"
 #include "gfxFont.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/dom/ImageData.h"
 #include "mozilla/dom/UnionTypes.h"
 
 #define NS_CANVASGRADIENTAZURE_PRIVATE_IID \
     {0x28425a6a, 0x90e0, 0x4d42, {0x9c, 0x75, 0xff, 0x60, 0x09, 0xb3, 0x10, 0xa8}}
 #define NS_CANVASPATTERNAZURE_PRIVATE_IID \
     {0xc9bacc25, 0x28da, 0x421e, {0x9a, 0x4b, 0xbb, 0xd6, 0x93, 0x05, 0x12, 0xbc}}
 
+class nsIDOMXULElement;
+
 namespace mozilla {
 namespace gfx {
 struct Rect;
 class SourceSurface;
 }
 
 namespace dom {
 extern const mozilla::gfx::Float SIGMA_MAX;
@@ -122,17 +123,16 @@ public:
 
 struct CanvasBidiProcessor;
 class CanvasRenderingContext2DUserData;
 
 /**
  ** CanvasRenderingContext2D
  **/
 class CanvasRenderingContext2D :
-  public nsIDOMCanvasRenderingContext2D,
   public nsICanvasRenderingContextInternal,
   public nsWrapperCache
 {
 typedef mozilla::dom::HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement
   HTMLImageOrCanvasOrVideoElement;
 
 public:
   CanvasRenderingContext2D();
@@ -423,18 +423,17 @@ public:
   JS::Value GetMozDash(JSContext* cx, mozilla::ErrorResult& error);
   void SetMozDash(JSContext* cx, const JS::Value& mozDash,
                   mozilla::ErrorResult& error);
 
   double MozDashOffset()
   {
     return CurrentState().dashOffset;
   }
-
-  void SetMozDashOffset(double mozDashOffset, mozilla::ErrorResult& error);
+  void SetMozDashOffset(double mozDashOffset);
 
   void GetMozTextStyle(nsAString& mozTextStyle)
   {
     GetFont(mozTextStyle);
   }
 
   void SetMozTextStyle(const nsAString& mozTextStyle,
                        mozilla::ErrorResult& error)
@@ -491,21 +490,23 @@ public:
   NS_IMETHOD Redraw(const gfxRect &r) { Redraw(ToRect(r)); return NS_OK; }
 
   // this rect is in mTarget's current user space
   void RedrawUser(const gfxRect &r);
 
   // nsISupports interface + CC
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
 
-  NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(CanvasRenderingContext2D,
-                                                                   nsIDOMCanvasRenderingContext2D)
+  NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(CanvasRenderingContext2D)
 
-  // nsIDOMCanvasRenderingContext2D interface
-  NS_DECL_NSIDOMCANVASRENDERINGCONTEXT2D
+  enum CanvasMultiGetterType {
+    CMG_STYLE_STRING = 0,
+    CMG_STYLE_PATTERN = 1,
+    CMG_STYLE_GRADIENT = 2
+  };
 
   enum Style {
     STYLE_STROKE = 0,
     STYLE_FILL,
     STYLE_MAX
   };
 
   nsINode* GetParentObject()
@@ -538,16 +539,21 @@ public:
 
   friend class CanvasRenderingContext2DUserData;
 
 protected:
   nsresult GetImageDataArray(JSContext* aCx, int32_t aX, int32_t aY,
                              uint32_t aWidth, uint32_t aHeight,
                              JSObject** aRetval);
 
+  nsresult PutImageData_explicit(int32_t x, int32_t y, uint32_t w, uint32_t h,
+                                 unsigned char *aData, uint32_t aDataLen,
+                                 bool hasDirtyRect, int32_t dirtyX, int32_t dirtyY,
+                                 int32_t dirtyWidth, int32_t dirtyHeight);
+
   /**
    * Internal method to complete initialisation, expects mTarget to have been set
    */
   nsresult Initialize(int32_t width, int32_t height);
 
   nsresult InitializeWithTarget(mozilla::gfx::DrawTarget *surface,
                                 int32_t width, int32_t height);
 
@@ -578,17 +584,16 @@ protected:
     CurrentState().SetGradientStyle(whichStyle, gradient);
   }
 
   void SetStyleFromPattern(CanvasPattern *pattern, Style whichStyle)
   {
     CurrentState().SetPatternStyle(whichStyle, pattern);
   }
 
-  void SetStyleFromStringOrInterface(const nsAString& aStr, nsISupports *aInterface, Style aWhichStyle);
   nsISupports* GetStyleAsStringOrInterface(nsAString& aStr, CanvasMultiGetterType& aType, Style aWhichStyle);
 
   // Returns whether a color was successfully parsed.
   bool ParseColor(const nsAString& aString, nscolor* aColor);
 
   static void StyleColorToString(const nscolor& aColor, nsAString& aStr);
 
   /**
@@ -659,42 +664,16 @@ protected:
   nsString& GetFont()
   {
     /* will initilize the value if not set, else does nothing */
     GetCurrentFontStyle();
 
     return CurrentState().font;
   }
 
-  static bool
-  ToHTMLImageOrCanvasOrVideoElement(nsIDOMElement* html,
-                                    HTMLImageOrCanvasOrVideoElement& element)
-  {
-    nsCOMPtr<nsIContent> content = do_QueryInterface(html);
-    if (content) {
-      if (content->IsHTML(nsGkAtoms::canvas)) {
-        element.SetAsHTMLCanvasElement() =
-          static_cast<nsHTMLCanvasElement*>(html);
-        return true;
-      }
-      if (content->IsHTML(nsGkAtoms::img)) {
-        element.SetAsHTMLImageElement() =
-          static_cast<nsHTMLImageElement*>(html);
-        return true;
-      }
-      if (content->IsHTML(nsGkAtoms::video)) {
-        element.SetAsHTMLVideoElement() =
-          static_cast<nsHTMLVideoElement*>(html);
-        return true;
-      }
-    }
-
-    return false;
-  }
-
   // Member vars
   int32_t mWidth, mHeight;
 
   // This is true when the canvas is valid, but of zero size, this requires
   // specific behavior on some operations.
   bool mZero;
 
   bool mOpaque;
--- a/content/canvas/src/Makefile.in
+++ b/content/canvas/src/Makefile.in
@@ -14,16 +14,17 @@ include $(DEPTH)/config/autoconf.mk
 
 MODULE		= content
 LIBRARY_NAME	= gkconcvs_s
 LIBXUL_LIBRARY  = 1
 
 EXPORTS_NAMESPACES = mozilla/dom
 
 EXPORTS_mozilla/dom = \
+	CanvasUtils.h \
 	CanvasRenderingContext2D.h \
   ImageData.h \
   $(NULL)
 
 CPPSRCS	= \
 	CanvasImageCache.cpp \
 	CanvasRenderingContext2D.cpp \
 	CanvasUtils.cpp \
--- a/content/html/content/src/nsHTMLCanvasElement.cpp
+++ b/content/html/content/src/nsHTMLCanvasElement.cpp
@@ -9,18 +9,17 @@
 #include "mozilla/Base64.h"
 #include "mozilla/CheckedInt.h"
 #include "mozilla/gfx/Rect.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Telemetry.h"
 #include "nsNetUtil.h"
 #include "nsDOMFile.h"
 
-#include "nsICanvasRenderingContextInternal.h"
-#include "nsIDOMCanvasRenderingContext2D.h"
+#include "mozilla/dom/CanvasRenderingContext2D.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIXPConnect.h"
 #include "jsapi.h"
 #include "jsfriendapi.h"
 #include "nsContentUtils.h"
 #include "nsJSUtils.h"
 #include "nsMathUtils.h"
 #include "nsStreamUtils.h"
@@ -38,16 +37,19 @@
 #define DEFAULT_CANVAS_HEIGHT 150
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::layers;
 
 namespace {
 
+typedef mozilla::dom::HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement
+HTMLImageOrCanvasOrVideoElement;
+
 class ToBlobRunnable : public nsRunnable
 {
 public:
   ToBlobRunnable(nsIFileCallback* aCallback,
                  nsIDOMBlob* aBlob)
     : mCallback(aCallback),
       mBlob(aBlob)
   {
@@ -306,33 +308,37 @@ nsHTMLCanvasElement::IsPrintCallbackDone
 }
 
 nsIDOMHTMLCanvasElement*
 nsHTMLCanvasElement::GetOriginalCanvas()
 {
   return mOriginalCanvas ? mOriginalCanvas.get() : this;
 }
 
-
 nsresult
 nsHTMLCanvasElement::CopyInnerTo(nsGenericElement* aDest)
 {
   nsresult rv = nsGenericHTMLElement::CopyInnerTo(aDest);
   NS_ENSURE_SUCCESS(rv, rv);
   if (aDest->OwnerDoc()->IsStaticDocument()) {
     nsHTMLCanvasElement* dest = static_cast<nsHTMLCanvasElement*>(aDest);
     nsHTMLCanvasElement* self = const_cast<nsHTMLCanvasElement*>(this);
     dest->mOriginalCanvas = self;
 
+    HTMLImageOrCanvasOrVideoElement element;
+    element.SetAsHTMLCanvasElement() = this;
     nsCOMPtr<nsISupports> cxt;
     dest->GetContext(NS_LITERAL_STRING("2d"), JSVAL_VOID, getter_AddRefs(cxt));
-    nsCOMPtr<nsIDOMCanvasRenderingContext2D> context2d = do_QueryInterface(cxt);
+    nsRefPtr<CanvasRenderingContext2D> context2d =
+      static_cast<CanvasRenderingContext2D*>(cxt.get());
     if (context2d && !self->mPrintCallback) {
-      context2d->DrawImage(self,
-                           0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
+      ErrorResult err;
+      context2d->DrawImage(element,
+                           0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, err);
+      rv = err.ErrorCode();
     }
   }
   return rv;
 }
 
 nsChangeHint
 nsHTMLCanvasElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
                                             int32_t aModType) const
@@ -686,16 +692,26 @@ nsHTMLCanvasElement::MozGetAsFileImpl(co
 }
 
 nsresult
 nsHTMLCanvasElement::GetContextHelper(const nsAString& aContextId,
                                       nsICanvasRenderingContextInternal **aContext)
 {
   NS_ENSURE_ARG(aContext);
 
+  if (aContextId.EqualsLiteral("2d")) {
+    Telemetry::Accumulate(Telemetry::CANVAS_2D_USED, 1);
+    nsRefPtr<CanvasRenderingContext2D> ctx =
+      new CanvasRenderingContext2D();
+
+    ctx->SetCanvasElement(this);
+    ctx.forget(aContext);
+    return NS_OK;
+  }
+
   NS_ConvertUTF16toUTF8 ctxId(aContextId);
 
   // check that ctxId is clamped to A-Za-z0-9_-
   for (uint32_t i = 0; i < ctxId.Length(); i++) {
     if ((ctxId[i] < 'A' || ctxId[i] > 'Z') &&
         (ctxId[i] < 'a' || ctxId[i] > 'z') &&
         (ctxId[i] < '0' || ctxId[i] > '9') &&
         (ctxId[i] != '-') &&
--- a/dom/interfaces/canvas/nsIDOMCanvasRenderingContext2D.idl
+++ b/dom/interfaces/canvas/nsIDOMCanvasRenderingContext2D.idl
@@ -1,22 +1,14 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 "nsISupports.idl"
-#include "nsIVariant.idl"
-
-interface nsIDOMWindow;
-interface nsIDOMElement;
-interface nsIDOMHTMLElement;
-interface nsIDOMHTMLImageElement;
-interface nsIDOMHTMLCanvasElement;
-interface nsIDOMXULElement;
 
 [scriptable, uuid(bbb20a59-524e-4662-981e-5e142814b20c)]
 interface nsIDOMCanvasGradient : nsISupports
 {
   void addColorStop(in float offset, in DOMString color);
 };
 
 [scriptable, uuid(21dea65c-5c08-4eb1-ac82-81fe95be77b8)]
@@ -25,237 +17,34 @@ interface nsIDOMCanvasPattern : nsISuppo
 };
 
 [scriptable, uuid(2d01715c-ec7d-424a-ab85-e0fd70c8665c)]
 interface nsIDOMTextMetrics : nsISupports
 {
   readonly attribute float width;
 };
 
-[scriptable, uuid(438fe14d-6501-40ab-b6c2-130fa38bd2c9)]
+/**
+ * This interface remains only for the constants, for a context, use the
+ * WebIDL/Paris bindings instead (CanvasRenderingContext2D.webidl).
+ * The constants are used by CanvasRenderingContext2D::DrawWindow and are
+ * used in WindowsPreviewPerTab.jsm and some extensions. The constants can
+ * be referenced directly via a canvas context 2d rather than this interface,
+ * and that should be preferred in new code. 
+ */
+[scriptable, uuid(4417cab7-c7eb-4e0c-b00a-c43842f0cba8)]
 interface nsIDOMCanvasRenderingContext2D : nsISupports
 {
-  // back-reference to the canvas element for which
-  // this context was created
-  readonly attribute nsIDOMHTMLCanvasElement canvas;
-
-  // state
-  [binaryname(MozSave)]
-  void save();
-  [binaryname(MozRestore)]
-  void restore();
-
-  // transformations
-  void scale(in float x, in float y);
-  void rotate(in float angle);
-  void translate(in float x, in float y);
-  void transform(in float m11, in float m12, in float m21, in float m22, in float dx, in float dy);
-  void setTransform(in float m11, in float m12, in float m21, in float m22, in float dx, in float dy);
-  [implicit_jscontext]
-  attribute jsval mozCurrentTransform; // [ m11, m12, m21, m22, dx, dy ], i.e. row major
-  [implicit_jscontext]
-  attribute jsval mozCurrentTransformInverse;
-
-  // compositing
-  attribute float globalAlpha; /* default 1.0 -- opaque */
-  attribute DOMString globalCompositeOperation; /* default "over" */
-
-  // Colors and Styles
-
-  // These attributes work, but are quickstubbed for JS code.  Native
-  // code should use the _multi variants below.
-  attribute nsIVariant strokeStyle;
-  attribute nsIVariant fillStyle;
-
-  // These do the actual work.  Use these from c++ -- only one of str or iface
-  // should be specified; the one that's not null/void is used.  For the getter,
-  // ifaceType is 0 if it's a string, 1 if it's a pattern, or 2 if it's a gradient
-%{C++
-enum CanvasMultiGetterType {
-      CMG_STYLE_STRING = 0,
-      CMG_STYLE_PATTERN = 1,
-      CMG_STYLE_GRADIENT = 2
-};
-%}
-  [noscript] void setStrokeStyle_multi(in DOMString str, in nsISupports iface);
-  [noscript] void getStrokeStyle_multi(out DOMString str, out nsISupports iface, out long type);
-  [noscript] void setFillStyle_multi(in DOMString str, in nsISupports iface);
-  [noscript] void getFillStyle_multi(out DOMString str, out nsISupports iface, out long type);
-
-  //attribute DOMString fillRule;
-  attribute DOMString mozFillRule; /* "evenodd", "nonzero" (default) */
-
-  nsIDOMCanvasGradient createLinearGradient (in float x0, in float y0, in float x1, in float y1);
-  nsIDOMCanvasGradient createRadialGradient(in float x0, in float y0, in float r0, in float x1, in float y1, in float r1);
-  nsIDOMCanvasPattern createPattern(in nsIDOMHTMLElement image, in DOMString repetition);
-  attribute float lineWidth; /* default 1 */
-  [binaryname(MozLineCap)]
-  attribute DOMString lineCap; /* "butt", "round", "square" (default) */
-  [binaryname(MozLineJoin)]
-  attribute DOMString lineJoin; /* "round", "bevel", "miter" (default) */
-  attribute float miterLimit; /* default 10 */
-
-  [implicit_jscontext]
-  attribute jsval mozDash; /* default |null| */
-  attribute float mozDashOffset; /* default 0.0 */
-
-  // shadows
-  attribute float shadowOffsetX;
-  attribute float shadowOffsetY;
-  attribute float shadowBlur;
-  [binaryname(MozShadowColor)]
-  attribute DOMString shadowColor;
-
-  // rects
-  void clearRect(in float x, in float y, in float w, in float h);
-  void fillRect(in float x, in float y, in float w, in float h);
-  void strokeRect(in float x, in float y, in float w, in float h);
-
-  // path API
-  [binaryname(MozBeginPath)]
-  void beginPath();
-  [binaryname(MozClosePath)]
-  void closePath();
-
-  void moveTo(in float x, in float y);
-  void lineTo(in float x, in float y);
-  void quadraticCurveTo(in float cpx, in float cpy, in float x, in float y);
-  void bezierCurveTo(in float cp1x, in float cp1y, in float cp2x, in float cp2y, in float x, in float y);
-  void arcTo(in float x1, in float y1, in float x2, in float y2, in float radius);
-  void arc(in float x, in float y, in float r, in float startAngle, in float endAngle, [optional] in boolean anticlockwise);
-  void rect(in float x, in float y, in float w, in float h);
-
-  [binaryname(MozFill)]
-  void fill();
-  [binaryname(MozStroke)]
-  void stroke();
-  [binaryname(MozClip)]
-  void clip();
-
-  // text api
-  [binaryname(MozFont)]
-  attribute DOMString font; /* default "10px sans-serif" */
-  [binaryname(MozTextAlign)]
-  attribute DOMString textAlign; /* "start" (default), "end", "left", "right",
-                                 "center" */
-  [binaryname(MozTextBaseline)]
-  attribute DOMString textBaseline; /* "alphabetic" (default), "top", "hanging",
-                                    "middle", "ideographic", "bottom" */
-
-  void fillText(in DOMString text, in float x, in float y, [optional] in float maxWidth);
-  void strokeText(in DOMString text, in float x, in float y, [optional] in float maxWidth);
-  nsIDOMTextMetrics measureText(in DOMString text);
-
-  [binaryname(TextStyle)]
-  attribute DOMString mozTextStyle;
-
-  // image api
-
-  [optional_argc] void drawImage(in nsIDOMElement image,
-                                 in float a1, in float a2,
-                                 [optional] in float a3,
-                                 [optional] in float a4,
-                                 [optional] in float a5,
-                                 [optional] in float a6,
-                                 [optional] in float a7,
-                                 [optional] in float a8);
-
-/*
-  void drawImage(in HTMLImageElement image, in float dx, in float dy);
-  void drawImage(in HTMLImageElement image, in float dx, in float dy, in float sw, in float sh);
-  void drawImage(in HTMLImageElement image, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh);
-*/
-
-  // point-membership test
-  boolean isPointInPath(in float x, in float y);
-  boolean mozIsPointInStroke(in float x, in float y);
-
-  // pixel manipulation
-  // ImageData getImageData (in float x, in float y, in float width, in float height);
-  // void putImageData (in ImageData d, in float x, in float y);
-  // ImageData = { width: #, height: #, data: [r, g, b, a, ...] }
-
-  // nsISupports is OK, because the binding code will deal correctly
-  [implicit_jscontext]
-  nsISupports getImageData(in double sx, in double sy, in double sw, in double sh);
-
-
-  // void putImageData(ImageData imagedata, double dx, double dy);
-  // void putImageDataHD(ImageData imagedata, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight);
-  // We use jsval for the imageData because that's what our C++ code wants
-  [implicit_jscontext, optional_argc]
-  void putImageData(in jsval imageData, in double dx, in double dy,
-                    [optional] in double dirtyX, [optional] in double dirtyY,
-                    [optional] in double dirtyWidth,
-                    [optional] in double dirtyHeight);
-
-  // dataLen must be == width*height*4 in this call
-  [noscript] void putImageData_explicit(in long x, in long y, in unsigned long width, in unsigned long height,
-                                        [array, size_is(dataLen)] in octet dataPtr, in unsigned long dataLen, in boolean hasDirtyRect,
-                                        in long dirtyX, in long dirtyY, in long dirtyWidth, in long dirtyHeight);
-
-  // ImageData createImageData(double w, double h);
-  // ImageData createImageData(ImageData data);
-  // nsISupports is OK, because the binding code will deal correctly
-  [implicit_jscontext, optional_argc]
-  nsISupports createImageData(in jsval arg1, [optional] in jsval arg2);
-
-  // image smoothing mode -- if disabled, images won't be smoothed
-  // if scaled.
-  attribute boolean mozImageSmoothingEnabled;
-
   // Show the caret if appropriate when drawing
   const unsigned long DRAWWINDOW_DRAW_CARET   = 0x01;
   // Don't flush pending layout notifications that could otherwise
   // be batched up
   const unsigned long DRAWWINDOW_DO_NOT_FLUSH = 0x02;
   // Draw scrollbars and scroll the viewport if they are present
   const unsigned long DRAWWINDOW_DRAW_VIEW    = 0x04;
   // Use the widget layer manager if available. This means hardware
   // acceleration may be used, but it might actually be slower or
   // lower quality than normal. It will however more accurately reflect
   // the pixels rendered to the screen.
   const unsigned long DRAWWINDOW_USE_WIDGET_LAYERS = 0x08;
   // Don't synchronously decode images - draw what we have
   const unsigned long DRAWWINDOW_ASYNC_DECODE_IMAGES = 0x10;
-
-  /**
-   * Renders a region of a window into the canvas.  The contents of
-   * the window's viewport are rendered, ignoring viewport clipping
-   * and scrolling.
-   *
-   * @param x
-   * @param y
-   * @param w
-   * @param h specify the area of the window to render, in CSS
-   * pixels.
-   *
-   * @param backgroundColor the canvas is filled with this color
-   * before we render the window into it. This color may be
-   * transparent/translucent. It is given as a CSS color string
-   * (e.g., rgb() or rgba()).
-   *
-   * @param flags Used to better control the drawWindow call.
-   * Flags can be ORed together.
-   *
-   * Of course, the rendering obeys the current scale, transform and
-   * globalAlpha values.
-   *
-   * Hints:
-   * -- If 'rgba(0,0,0,0)' is used for the background color, the
-   * drawing will be transparent wherever the window is transparent.
-   * -- Top-level browsed documents are usually not transparent
-   * because the user's background-color preference is applied,
-   * but IFRAMEs are transparent if the page doesn't set a background.
-   * -- If an opaque color is used for the background color, rendering
-   * will be faster because we won't have to compute the window's
-   * transparency.
-   *
-   * This API cannot currently be used by Web content. It is chrome
-   * only.
-   */
-  void drawWindow(in nsIDOMWindow window, in float x, in float y,
-                  in float w, in float h, in DOMString bgColor,
-                  [optional] in unsigned long flags);
-  void asyncDrawXULElement(in nsIDOMXULElement elem, in float x, in float y,
-                  in float w, in float h, in DOMString bgColor,
-                  [optional] in unsigned long flags);
 };
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -170,17 +170,16 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextSer
 #include "nsHTMLEditorLog.h"
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLEditorLog)
 #else
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLEditor)
 #endif
 
 #include "nsHTMLCanvasFrame.h"
 
-#include "nsIDOMCanvasRenderingContext2D.h"
 #include "nsIDOMWebGLRenderingContext.h"
 
 class nsIDocumentLoaderFactory;
 
 #define PRODUCT_NAME "Gecko"
 
 #define NS_HTMLIMGELEMENT_CONTRACTID \
   "@mozilla.org/content/element/html;1?name=img"
@@ -437,17 +436,16 @@ nsresult NS_NewBoxObject(nsIBoxObject** 
 nsresult NS_NewListBoxObject(nsIBoxObject** aResult);
 nsresult NS_NewScrollBoxObject(nsIBoxObject** aResult);
 nsresult NS_NewMenuBoxObject(nsIBoxObject** aResult);
 nsresult NS_NewPopupBoxObject(nsIBoxObject** aResult);
 nsresult NS_NewContainerBoxObject(nsIBoxObject** aResult);
 nsresult NS_NewTreeBoxObject(nsIBoxObject** aResult);
 #endif
 
-nsresult NS_NewCanvasRenderingContext2D(nsIDOMCanvasRenderingContext2D** aResult);
 nsresult NS_NewCanvasRenderingContextWebGL(nsIDOMWebGLRenderingContext** aResult);
 
 nsresult NS_CreateFrameTraversal(nsIFrameTraversal** aResult);
 
 nsresult NS_NewDomSelection(nsISelection** aResult);
 nsresult NS_NewContentViewer(nsIContentViewer** aResult);
 nsresult NS_NewGenRegularIterator(nsIContentIterator** aResult);
 nsresult NS_NewGenSubtreeIterator(nsIContentIterator** aInstancePtrResult);
@@ -561,17 +559,16 @@ MAKE_CTOR(CreateChildMessageManager,    
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsDataDocumentContentPolicy)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsNoDataProtocolContentPolicy)
 MAKE_CTOR(CreatePluginDocument,           nsIDocument,                 NS_NewPluginDocument)
 #ifdef MOZ_MEDIA
 MAKE_CTOR(CreateVideoDocument,            nsIDocument,                 NS_NewVideoDocument)
 #endif
 MAKE_CTOR(CreateFocusManager,             nsIFocusManager,      NS_NewFocusManager)
 
-MAKE_CTOR(CreateCanvasRenderingContext2D, nsIDOMCanvasRenderingContext2D, NS_NewCanvasRenderingContext2D)
 MAKE_CTOR(CreateCanvasRenderingContextWebGL, nsIDOMWebGLRenderingContext, NS_NewCanvasRenderingContextWebGL)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsStyleSheetService, Init)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSURI)
 
 // views are not refcounted, so this is the same as
 // NS_GENERIC_FACTORY_CONSTRUCTOR without the NS_ADDREF/NS_RELEASE
@@ -724,17 +721,16 @@ NS_DEFINE_NAMED_CID(NS_DOMSELECTION_CID)
 NS_DEFINE_NAMED_CID(NS_CONTENTITERATOR_CID);
 NS_DEFINE_NAMED_CID(NS_PRECONTENTITERATOR_CID);
 NS_DEFINE_NAMED_CID(NS_SUBTREEITERATOR_CID);
 NS_DEFINE_NAMED_CID(NS_HTMLIMAGEELEMENT_CID);
 NS_DEFINE_NAMED_CID(NS_HTMLOPTIONELEMENT_CID);
 #ifdef MOZ_MEDIA
 NS_DEFINE_NAMED_CID(NS_HTMLAUDIOELEMENT_CID);
 #endif
-NS_DEFINE_NAMED_CID(NS_CANVASRENDERINGCONTEXT2D_CID);
 NS_DEFINE_NAMED_CID(NS_CANVASRENDERINGCONTEXTWEBGL_CID);
 NS_DEFINE_NAMED_CID(NS_TEXT_ENCODER_CID);
 NS_DEFINE_NAMED_CID(NS_HTMLCOPY_TEXT_ENCODER_CID);
 NS_DEFINE_NAMED_CID(NS_XMLCONTENTSERIALIZER_CID);
 NS_DEFINE_NAMED_CID(NS_XHTMLCONTENTSERIALIZER_CID);
 NS_DEFINE_NAMED_CID(NS_HTMLCONTENTSERIALIZER_CID);
 NS_DEFINE_NAMED_CID(NS_PLAINTEXTSERIALIZER_CID);
 NS_DEFINE_NAMED_CID(NS_PARSERUTILS_CID);
@@ -1010,17 +1006,16 @@ static const mozilla::Module::CIDEntry k
   { &kNS_CONTENTITERATOR_CID, false, NULL, CreateContentIterator },
   { &kNS_PRECONTENTITERATOR_CID, false, NULL, CreatePreContentIterator },
   { &kNS_SUBTREEITERATOR_CID, false, NULL, CreateSubtreeIterator },
   { &kNS_HTMLIMAGEELEMENT_CID, false, NULL, CreateHTMLImgElement },
   { &kNS_HTMLOPTIONELEMENT_CID, false, NULL, CreateHTMLOptionElement },
 #ifdef MOZ_MEDIA
   { &kNS_HTMLAUDIOELEMENT_CID, false, NULL, CreateHTMLAudioElement },
 #endif
-  { &kNS_CANVASRENDERINGCONTEXT2D_CID, false, NULL, CreateCanvasRenderingContext2D },
   { &kNS_CANVASRENDERINGCONTEXTWEBGL_CID, false, NULL, CreateCanvasRenderingContextWebGL },
   { &kNS_TEXT_ENCODER_CID, false, NULL, CreateTextEncoder },
   { &kNS_HTMLCOPY_TEXT_ENCODER_CID, false, NULL, CreateHTMLCopyTextEncoder },
   { &kNS_XMLCONTENTSERIALIZER_CID, false, NULL, CreateXMLContentSerializer },
   { &kNS_HTMLCONTENTSERIALIZER_CID, false, NULL, CreateHTMLContentSerializer },
   { &kNS_XHTMLCONTENTSERIALIZER_CID, false, NULL, CreateXHTMLContentSerializer },
   { &kNS_PLAINTEXTSERIALIZER_CID, false, NULL, CreatePlainTextSerializer },
   { &kNS_PARSERUTILS_CID, false, NULL, nsParserUtilsConstructor },
@@ -1157,17 +1152,16 @@ static const mozilla::Module::ContractID
   { "@mozilla.org/content/post-content-iterator;1", &kNS_CONTENTITERATOR_CID },
   { "@mozilla.org/content/pre-content-iterator;1", &kNS_PRECONTENTITERATOR_CID },
   { "@mozilla.org/content/subtree-content-iterator;1", &kNS_SUBTREEITERATOR_CID },
   { NS_HTMLIMGELEMENT_CONTRACTID, &kNS_HTMLIMAGEELEMENT_CID },
   { NS_HTMLOPTIONELEMENT_CONTRACTID, &kNS_HTMLOPTIONELEMENT_CID },
 #ifdef MOZ_MEDIA
   { NS_HTMLAUDIOELEMENT_CONTRACTID, &kNS_HTMLAUDIOELEMENT_CID },
 #endif
-  { "@mozilla.org/content/canvas-rendering-context;1?id=2d", &kNS_CANVASRENDERINGCONTEXT2D_CID },
   { "@mozilla.org/content/canvas-rendering-context;1?id=moz-webgl", &kNS_CANVASRENDERINGCONTEXTWEBGL_CID },
   { "@mozilla.org/content/canvas-rendering-context;1?id=experimental-webgl", &kNS_CANVASRENDERINGCONTEXTWEBGL_CID },
   { NS_DOC_ENCODER_CONTRACTID_BASE "text/xml", &kNS_TEXT_ENCODER_CID },
   { NS_DOC_ENCODER_CONTRACTID_BASE "application/xml", &kNS_TEXT_ENCODER_CID },
   { NS_DOC_ENCODER_CONTRACTID_BASE "application/xhtml+xml", &kNS_TEXT_ENCODER_CID },
   { NS_DOC_ENCODER_CONTRACTID_BASE "image/svg+xml", &kNS_TEXT_ENCODER_CID },
   { NS_DOC_ENCODER_CONTRACTID_BASE "text/html", &kNS_TEXT_ENCODER_CID },
   { NS_DOC_ENCODER_CONTRACTID_BASE "text/plain", &kNS_TEXT_ENCODER_CID },
--- a/widget/nsITaskbarPreviewController.idl
+++ b/widget/nsITaskbarPreviewController.idl
@@ -3,17 +3,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/. */
 
 #include "nsISupports.idl"
 
 interface nsIDocShell;
-interface nsIDOMCanvasRenderingContext2D;
 interface nsITaskbarPreview;
 interface nsITaskbarPreviewButton;
 
 /**
  * nsITaskbarPreviewController
  *
  * nsITaskbarPreviewController provides the behavior for the taskbar previews.
  * Its methods and properties are used by nsITaskbarPreview. Clients are
@@ -47,32 +46,32 @@ interface nsITaskbarPreviewController : 
    * Invoked by nsITaskbarPreview when it needs to render the preview. The
    * context is attached to a surface with the controller's width and height
    * which are obtained immediately before the call.
    *
    * Note that the context is not attached to a canvas element.
    *
    * @param ctx Canvas drawing context
    */
-  boolean drawPreview(in nsIDOMCanvasRenderingContext2D ctx);
+  boolean drawPreview(in nsISupports ctx);
 
   /**
    * Invoked by the taskbar preview when it needs to draw the thumbnail in the
    * taskbar's application preview window.
    *
    * Note: it is guaranteed that width/height == thumbnailAspectRatio
    * (modulo rounding errors)
    *
    * Also note that the context is not attached to a canvas element.
    *
    * @param ctx Canvas drawing context
    * @param width The width of the surface backing the drawing context
    * @param height The height of the surface backing the drawing context
    */
-  boolean drawThumbnail(in nsIDOMCanvasRenderingContext2D ctx, in unsigned long width, in unsigned long height);
+  boolean drawThumbnail(in nsISupports ctx, in unsigned long width, in unsigned long height);
 
   /**
    * Invoked when the user presses the close button on the tab preview.
    */
   void onClose();
 
   /**
    * Invoked when the user clicks on the tab preview.
--- a/widget/windows/TaskbarPreview.cpp
+++ b/widget/windows/TaskbarPreview.cpp
@@ -19,82 +19,69 @@
 #include "nsUXThemeData.h"
 #include "nsWindow.h"
 #include "nsAppShell.h"
 #include "TaskbarPreviewButton.h"
 #include "WinUtils.h"
 
 #include <nsIBaseWindow.h>
 #include <nsICanvasRenderingContextInternal.h>
-#include <nsIDOMCanvasRenderingContext2D.h>
+#include "mozilla/dom/CanvasRenderingContext2D.h"
 #include <imgIContainer.h>
 #include <nsIDocShell.h>
 
+#include "mozilla/Telemetry.h"
+
 // Defined in dwmapi in a header that needs a higher numbered _WINNT #define
 #define DWM_SIT_DISPLAYFRAME 0x1
 
 namespace mozilla {
 namespace widget {
 
 namespace {
 
 // Shared by all TaskbarPreviews to avoid the expensive creation process.
 // Manually refcounted (see gInstCount) by the ctor and dtor of TaskbarPreview.
 // This is done because static constructors aren't allowed for perf reasons.
-nsIDOMCanvasRenderingContext2D* gCtx = NULL;
+dom::CanvasRenderingContext2D* gCtx = NULL;
 // Used in tracking the number of previews. Used in freeing
 // the static 2d rendering context on shutdown.
 uint32_t gInstCount = 0;
 
 /* Helper method to lazily create a canvas rendering context and associate a given
  * surface with it.
  *
  * @param shell The docShell used by the canvas context for text settings and other
  *              misc things.
  * @param surface The gfxSurface backing the context
  * @param width The width of the given surface
  * @param height The height of the given surface
  */
 nsresult
 GetRenderingContext(nsIDocShell *shell, gfxASurface *surface,
                     uint32_t width, uint32_t height) {
-  nsresult rv;
-  nsCOMPtr<nsIDOMCanvasRenderingContext2D> ctx = gCtx;
-
-  if (!ctx) {
+  if (!gCtx) {
     // create the canvas rendering context
-    ctx = do_CreateInstance("@mozilla.org/content/canvas-rendering-context;1?id=2d", &rv);
-    if (NS_FAILED(rv)) {
-      NS_WARNING("Could not create nsICanvasRenderingContext2D for tab previews!");
-      return rv;
-    }
-    gCtx = ctx;
+    Telemetry::Accumulate(Telemetry::CANVAS_2D_USED, 1);
+    gCtx = new mozilla::dom::CanvasRenderingContext2D();
     NS_ADDREF(gCtx);
   }
 
-  nsCOMPtr<nsICanvasRenderingContextInternal> ctxI = do_QueryInterface(ctx, &rv);
-  if (NS_FAILED(rv))
-    return rv;
-
   // Set the surface we'll use to render.
-  return ctxI->InitializeWithSurface(shell, surface, width, height);
+  return gCtx->InitializeWithSurface(shell, surface, width, height);
 }
 
 /* Helper method for freeing surface resources associated with the rendering context.
  */
 void
 ResetRenderingContext() {
   if (!gCtx)
     return;
 
-  nsresult rv;
-  nsCOMPtr<nsICanvasRenderingContextInternal> ctxI = do_QueryInterface(gCtx, &rv);
-  if (NS_FAILED(rv))
-    return;
-  if (NS_FAILED(ctxI->Reset())) {
+  if (NS_FAILED(gCtx->Reset())) {
     NS_RELEASE(gCtx);
     gCtx = nullptr;
   }
 }
 
 }
 
 TaskbarPreview::TaskbarPreview(ITaskbarList4 *aTaskbar, nsITaskbarPreviewController *aController, HWND aHWND, nsIDocShell *aShell)
--- a/widget/windows/WinTaskbar.cpp
+++ b/widget/windows/WinTaskbar.cpp
@@ -158,23 +158,23 @@ DefaultController::GetThumbnailAspectRat
   if (!height)
     height = 1;
 
   *aThumbnailAspectRatio = width/float(height);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-DefaultController::DrawPreview(nsIDOMCanvasRenderingContext2D *ctx, bool *rDrawFrame) {
+DefaultController::DrawPreview(nsISupports *ctx, bool *rDrawFrame) {
   *rDrawFrame = true;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-DefaultController::DrawThumbnail(nsIDOMCanvasRenderingContext2D *ctx, uint32_t width, uint32_t height, bool *rDrawFrame) {
+DefaultController::DrawThumbnail(nsISupports *ctx, uint32_t width, uint32_t height, bool *rDrawFrame) {
   *rDrawFrame = false;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 DefaultController::OnClose(void) {
   NS_NOTREACHED("OnClose should not be called for TaskbarWindowPreviews");
   return NS_OK;