Commit 73f6c1e2 authored by Kagami Sascha Rosylight's avatar Kagami Sascha Rosylight
Browse files

Bug 1619574 - Remove HTMLCanvasElement::MozGetAsFile r=emilio

parent bdc5c410
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -155,7 +155,6 @@ tags = imagebitmap
tags = imagebitmap
[test_ImageData_ctor.html]
[test_isPointInStroke.html]
[test_mozGetAsFile.html]
[test_strokeText_throw.html]
[test_toBlob.html]
[test_toBlob_zero_dimension.html]
+0 −61
Original line number Diff line number Diff line
<!DOCTYPE HTML>
<title>Canvas test: mozGetAsFile</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<body>
<canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
<script>

function compareAsync(file, canvas, type, callback)
{
  var reader = new FileReader();
  reader.onload = 
    function(e) {
      is(e.target.result, canvas.toDataURL(type),
 "<canvas>.mozGetAsFile().getAsDataURL() should equal <canvas>.toDataURL()");
      callback(canvas);
    };
  reader.readAsDataURL(file);
}

function test1(canvas)
{
  var pngfile = canvas.mozGetAsFile("foo.png");
  is(pngfile.type, "image/png", "Default type for mozGetAsFile should be PNG");
  compareAsync(pngfile, canvas, "image/png", test2);
  is(pngfile.name, "foo.png", "File name should be what we passed in");
}

function test2(canvas)
{
  var jpegfile = canvas.mozGetAsFile("bar.jpg", "image/jpeg");
  is(jpegfile.type, "image/jpeg",
     "When a valid type is specified that should be returned");
  compareAsync(jpegfile, canvas, "image/jpeg", parent.SimpleTest.finish);
  is(jpegfile.name, "bar.jpg", "File name should be what we passed in");
}

SimpleTest.waitForExplicitFinish();
addLoadEvent(async function () {
  if (location.search == "?framed") {
    is = parent.is;

    var canvas = document.getElementById('c');
    var ctx = canvas.getContext('2d');
    ctx.drawImage(document.getElementById('yellow75.png'), 0, 0);

    test1(canvas);
  } else {
    await SpecialPowers.pushPrefEnv({
      set: [
        ["canvas.mozgetasfile.enabled", true],
      ],
    });
    let iframe = document.querySelector("iframe");
    iframe.src = "test_mozGetAsFile.html?framed";
  }
});
</script>
<img src="image_yellow75.png" id="yellow75.png" class="resource">
<iframe></iframe>
+0 −47
Original line number Diff line number Diff line
@@ -1018,53 +1018,6 @@ OffscreenCanvas* HTMLCanvasElement::TransferControlToOffscreen(
  return mOffscreenCanvas;
}

already_AddRefed<File> HTMLCanvasElement::MozGetAsFile(
    const nsAString& aName, const nsAString& aType,
    nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) {
  // do a trust check if this is a write-only canvas
  if (mWriteOnly && !aSubjectPrincipal.IsSystemPrincipal()) {
    aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
    return nullptr;
  }

  RefPtr<File> file;
  aRv = MozGetAsFileImpl(aName, aType, aSubjectPrincipal, getter_AddRefs(file));
  if (NS_WARN_IF(aRv.Failed())) {
    return nullptr;
  }
  return file.forget();
}

nsresult HTMLCanvasElement::MozGetAsFileImpl(const nsAString& aName,
                                             const nsAString& aType,
                                             nsIPrincipal& aSubjectPrincipal,
                                             File** aResult) {
  nsCOMPtr<nsIInputStream> stream;
  nsAutoString type(aType);
  nsresult rv =
      ExtractData(nsContentUtils::GetCurrentJSContext(), aSubjectPrincipal,
                  type, u""_ns, getter_AddRefs(stream));
  NS_ENSURE_SUCCESS(rv, rv);

  uint64_t imgSize;
  void* imgData = nullptr;
  rv = NS_ReadInputStreamToBuffer(stream, &imgData, -1, &imgSize);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsPIDOMWindowInner> win =
      do_QueryInterface(OwnerDoc()->GetScopeObject());

  // The File takes ownership of the buffer
  RefPtr<File> file = File::CreateMemoryFileWithLastModifiedNow(
      win->AsGlobal(), imgData, imgSize, aName, type);
  if (NS_WARN_IF(!file)) {
    return NS_ERROR_FAILURE;
  }

  file.forget(aResult);
  return NS_OK;
}

nsresult HTMLCanvasElement::GetContext(const nsAString& aContextId,
                                       nsISupports** aContext) {
  ErrorResult rv;
+0 −6
Original line number Diff line number Diff line
@@ -163,10 +163,6 @@ class HTMLCanvasElement final : public nsGenericHTMLElement,

    SetHTMLBoolAttr(nsGkAtoms::moz_opaque, aValue, aRv);
  }
  already_AddRefed<File> MozGetAsFile(const nsAString& aName,
                                      const nsAString& aType,
                                      nsIPrincipal& aSubjectPrincipal,
                                      ErrorResult& aRv);
  already_AddRefed<nsISupports> MozGetIPCContext(const nsAString& aContextId,
                                                 ErrorResult& aRv);
  PrintCallback* GetMozPrintCallback() const;
@@ -325,8 +321,6 @@ class HTMLCanvasElement final : public nsGenericHTMLElement,
  nsresult ToDataURLImpl(JSContext* aCx, nsIPrincipal& aSubjectPrincipal,
                         const nsAString& aMimeType,
                         const JS::Value& aEncoderOptions, nsAString& aDataURL);
  nsresult MozGetAsFileImpl(const nsAString& aName, const nsAString& aType,
                            nsIPrincipal& aSubjectPrincipal, File** aResult);
  MOZ_CAN_RUN_SCRIPT void CallPrintCallback();

  virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
+0 −2
Original line number Diff line number Diff line
@@ -39,8 +39,6 @@ interface HTMLCanvasElement : HTMLElement {
partial interface HTMLCanvasElement {
  [Pure, SetterThrows]
           attribute boolean mozOpaque;
  [Throws, NeedsSubjectPrincipal, Pref="canvas.mozgetasfile.enabled"]
  File mozGetAsFile(DOMString name, optional DOMString? type = null);
  // A Mozilla-only extension to get a canvas context backed by double-buffered
  // shared memory. Only privileged callers can call this.
  [ChromeOnly, Throws]
Loading