W3C home > Mailing lists > Public > public-web-intents@w3.org > March 2012

CFC: Attaching 'extras' to the intent payload

From: James Hawkins <jhawkins@google.com>
Date: Mon, 5 Mar 2012 13:53:35 -0800
Message-ID: <CAO800Sw+M_hiSYFfqNRENovZneAtO5LXCvrs74K15Y+OvZt6Ug@mail.gmail.com>
To: WebIntents <public-web-intents@w3.org>
TL;DR - We need a method to set extra data on the intent payload.  Ideas?

For several use cases, extra data which augments the payload needs to
be passed either to or from the client.  For example a picker which
returns files may want to pass along the filename of the picked file.

There are several ways to augment the API to allow providing extras.
Let's go over constraints first:
* Must be allowed to pass several extras.
* It follows from above that the extras must be named.
  - We could impose ordering in an array as a solution, but that is
extremely fragile!

>From the constraints it's clear we need a dictionary for extras.
Android Intents agrees and uses a 'Bundle', which is "a mapping from
String values to various Parcelable types."  Different parlance, same
concept.

Android
======

>From the Android Intents spec:

  Intent putExtra(String name, [type] value);

putExtra is overloaded for each native [type], e.g., double, int,
Bundle, Parcelable, etc.


Possible Solutions
==============

A) Add an |extras| parameter to the Intent constructor:

Currently:
  [Constructor(in string action, in string type, in any data) raises
DOMException]

Modified:
  [Constructor(in string action, in string type, in any data, in
Dictionary extras) raises DOMException]

e.g.,

  var dict = {filename: 'image.png', size: 20000};
  var intent = new Intent('http://webintents.org/save', 'image/png',
imageData, dict);


B) Add a method to set an extra on Intent:

  interface Intent {
    ...
    void setExtra(DOMString name, any value);
  }

e.g.,

  var intent = new Intent('http://webintents.org/save', 'image/png', imageData);
  intent.setExtra('filename', 'image.png');
  intent.setExtra('size', 20000);


C) Add a method to set the entire |extras| dictionary on Intent:

  interface Intent {
    ...
    void setExtras(Dictionary extras);
  }

e.g.,

  var intent = new Intent('http://webintents.org/save', 'image/png', imageData);

  var dict = {filename: 'image.png', size: 20000};
  intent.setExtras(dict);


What are your thoughts, preferences, anecdotal evidence?  I'd love to
hear your feedback on the issue.  Any other methods than those I
listed?

Thanks,
James
Received on Monday, 5 March 2012 21:54:34 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 5 March 2012 21:54:34 GMT