webplot: Allow the server to trigger saving a plot

Currently there isn't a way for the server to tell the browser to
save a plot.  The message has to come from the browser TO the server
since the browser is the only one with the image data.

This CL adds a message handler to the webpage's javascript that
will act as though the user pressed "s" in the browser when the
server sends the command "save" to the webpage.  This effectively
will allow the server to save the output of the plot to disk at will.

This feature is needed to use webplot as the visualizer for the touch
firmware test, so that the test framework can programatically save
snapshots of the plot when it wants to.

BUG=chromium:473383
TEST=manual testing.  Again, by setting up a dummy signal handler on
the server I could send it SIGUSR1 to trigger a "save" message being
sent to the webpage.  Each time it would immediately respond with the
png data and the server's normal handlers kicked in and saved it to
/tmp/webplot.png as expected.

Change-Id: I111f88f4b42916274fc1f5d0bda3183dfee2415e
Signed-off-by: Charlie Mooney <charliemooney@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/263784
Reviewed-by: Shyh-In Hwang <josephsih@chromium.org>
diff --git a/webplot/webplot.js b/webplot/webplot.js
index 21e6c37..7c352a0 100644
--- a/webplot/webplot.js
+++ b/webplot/webplot.js
@@ -395,6 +395,8 @@
         quit(true);
       } else if (event.data == 'clear') {
         clear(true);
+      } else if (event.data == 'save') {
+        save();
       } else {
         var snapshot = JSON.parse(event.data);
         webplot.processSnapshot(snapshot);