[canvaskit] Remove isNode and saveAsPicture

This should fix https://github.com/flutter/flutter/issues/80221

Change-Id: I25e0ad58bcaad95b43cc94476af0e241e17ac244
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/397289
Reviewed-by: Kevin Lubick <kjlubick@google.com>
diff --git a/modules/canvaskit/CHANGELOG.md b/modules/canvaskit/CHANGELOG.md
index da199ea..dd446cc 100644
--- a/modules/canvaskit/CHANGELOG.md
+++ b/modules/canvaskit/CHANGELOG.md
@@ -14,6 +14,10 @@
    to `RuntimeEffect.makeShader` as floats (like all other uniforms), and will be converted to
    integers internally, to match the expectations of the shader.
 
+### Removed
+ - `Picture.saveAsFile()`, in favor of `Picture.serialize()` where clients can control how to
+    store/encode the bytes.
+
 ## [0.25.1] - 2021-03-30
 
 ### Added
diff --git a/modules/canvaskit/externs.js b/modules/canvaskit/externs.js
index da7d808..3d9436e 100644
--- a/modules/canvaskit/externs.js
+++ b/modules/canvaskit/externs.js
@@ -1018,8 +1018,6 @@
 CanvasKit.Paragraph.prototype.getRectsForRange = function() {};
 CanvasKit.Paragraph.prototype.getRectsForPlaceholders = function() {};
 
-CanvasKit.Picture.prototype.saveAsFile = function() {};
-
 CanvasKit.Surface.prototype.dispose = function() {};
 CanvasKit.Surface.prototype.flush = function() {};
 CanvasKit.Surface.prototype.requestAnimationFrame = function() {};
diff --git a/modules/canvaskit/htmlcanvas/util.js b/modules/canvaskit/htmlcanvas/util.js
index 4ea121d..42cbce1 100644
--- a/modules/canvaskit/htmlcanvas/util.js
+++ b/modules/canvaskit/htmlcanvas/util.js
@@ -12,7 +12,7 @@
 }
 
 function toBase64String(bytes) {
-  if (isNode) {
+  if (typeof Buffer !== 'undefined') { // Are we on node?
     return Buffer.from(bytes).toString('base64');
   } else {
     // From https://stackoverflow.com/a/25644409
diff --git a/modules/canvaskit/skp.js b/modules/canvaskit/skp.js
index bddccdb..9248d76 100644
--- a/modules/canvaskit/skp.js
+++ b/modules/canvaskit/skp.js
@@ -14,16 +14,4 @@
     }
     return pic;
   };
-
-  // The serialized format of an Picture (informally called an "skp"), is not something
-  // that clients should ever rely on. The format may change at anytime and no promises
-  // are made for backwards or forward compatibility.
-  CanvasKit.Picture.prototype.saveAsFile = function(skpName) {
-    var bytes = this.serialize();
-    if (!bytes) {
-      Debug('Could not serialize to skpicture.');
-      return;
-    }
-    saveBytesToFile(bytes, skpName);
-  }
 });
diff --git a/modules/canvaskit/tests/core.spec.js b/modules/canvaskit/tests/core.spec.js
index b2b0baf..45eb6c1 100644
--- a/modules/canvaskit/tests/core.spec.js
+++ b/modules/canvaskit/tests/core.spec.js
@@ -34,10 +34,8 @@
 
         canvas.drawPicture(pic);
 
-        // test that file saving functionality throws no errors
-        // Unfortunately jasmine spy objects can't fake their type so we can't verify it downloads
-        // a nonzero sized file.
-        pic.saveAsFile('foo.skp');
+        const bytes = pic.serialize();
+        expect(bytes).toBeTruthy();
 
         pic.delete();
     });
diff --git a/modules/canvaskit/util.js b/modules/canvaskit/util.js
index be8e4a2..69c3a60 100644
--- a/modules/canvaskit/util.js
+++ b/modules/canvaskit/util.js
@@ -13,37 +13,6 @@
   return (deg / 180) * Math.PI;
 }
 
-// See https://stackoverflow.com/a/31090240
-// This contraption keeps closure from minifying away the check
-// if btoa is defined *and* prevents runtime 'btoa' or 'window' is not defined.
-// Defined outside any scopes to make it available in all files.
-var isNode = !(new Function('try {return this===window;}catch(e){ return false;}')());
-
 function almostEqual(floata, floatb) {
   return Math.abs(floata - floatb) < 0.00001;
 }
-
-function saveBytesToFile(bytes, fileName) {
-  if (!isNode) {
-    // https://stackoverflow.com/a/32094834
-    var blob = new Blob([bytes], {type: 'application/octet-stream'});
-    url = window.URL.createObjectURL(blob);
-    var a = document.createElement('a');
-    document.body.appendChild(a);
-    a.href = url;
-    a.download = fileName;
-    a.click();
-    // clean up after because FF might not download it synchronously
-    setTimeout(function() {
-      URL.revokeObjectURL(url);
-      a.remove();
-    }, 50);
-  } else {
-    var fs = require('fs');
-    // https://stackoverflow.com/a/42006750
-    // https://stackoverflow.com/a/47018122
-    fs.writeFile(fileName, new Buffer(bytes), function(err) {
-      if (err) throw err;
-    });
-  }
-}
\ No newline at end of file