Re: [whatwg] Canvas image to blob/dataurl within Worker

On Fri, Mar 20, 2015 at 3:15 PM, Robert O'Callahan <robert@ocallahan.org>
wrote:

> On Sat, Mar 21, 2015 at 1:13 AM, Jake Archibald <jaffathecake@gmail.com>
> wrote:
>
> > Receiving a push message results in a 'push' event within the
> > ServiceWorker. The likely action at this point is to show a notification.
> > It should be possible to generate an image to use as an icon for this
> > notification (
> > https://notifications.spec.whatwg.org/#dom-notificationoptions-icon).
> >
> > This could be a badge showing some kind of unread count, some combination
> > of app icon & avatar, or even a default avatar (Google Inbox generates an
> > avatar from the senders names first letter).
> >
> > This is also useful for generating images to go into the cache API, or
> > transforming images as they pass through the ServiceWorker.
> >
> > API:
> >
> > Almost all the pieces already exist, except a way to get the image data
> of
> > a CanvasRenderingContext2D into a format that can be read from a
> > url. ImageBitmap seems like a good fit for such an API:
> >
> > var context = new CanvasRenderingContext2D(192, 192);
> >
> > Promise.all(
> >   caches.match('/avatars/ben.png')
> >     .then(r => r.blob())
> >     .then(b => createImageBitmap(b)),
> >   caches.match('/avatars/julie.png')
> >     .then(r => r.blob())
> >     .then(b => createImageBitmap(b)),
> > ).then(([ben, julie]) => {
> >   context.drawImage(ben, 0, 0);
> >   context.drawImage(julie, 96, 96);
> >   return createImageBitmap(context);
> > }).then(
> >   // **** and here's the bit we're missing… ****
> >   image => image.toDataURL()
> > ).then(icon => {
> >   self.registration.showNotificaiton("Hello!", {icon});
> > });
> >
>
> My understanding is that the current consensus proposal for canvas in
> Workers is not what's in the spec, but this:
> https://wiki.whatwg.org/wiki/WorkerCanvas
> See "Canvas in Workers" threads from October 2013 for the discussion. svn
> is failing me but the CanvasProxy proposal in the spec definitely predates
> those threads.
>
> Ian, unless I'm wrong, it would be helpful to remove the CanvasProxy stuff
> from the spec to avoid confusion.
>
> That proposal contains WorkerCanvas.toBlob, which needs to be updated to
> use promises
>

Do you know how many site use toBlob in Firefox?
A quick search on github shows a very high number of pages [1] so it might
be too late to change.

Maybe you can keep the callback and return a promise?


1: https://github.com/search?l=javascript&q=toblob&type=Code&utf8=%E2%9C%93
<https://github.com/search?q=toblob&type=Code&utf8=%E2%9C%93>

Received on Saturday, 21 March 2015 02:38:47 UTC