Labs/Jetpack/Reboot/JEP/117

From MozillaWiki
< Labs‎ | Jetpack‎ | Reboot‎ | JEP
Jump to: navigation, search

JEP 117 - URL

  • Champion: Myk Melez <myk@mozilla.org>
  • Status: Under Review
  • Bug Ticket:
  • Type: API

Proposal

It should be possible to explicitly specify a URL to interfaces that request one, to avoid any confusion when specifying content that can be either a URL or a string of HTML.

Use Cases

  • An extension wants to set the content property of a panel to the URL of a remote site. For example, an Twitter extension wants to specify the URL to http://m.twitter.com/.
  • An extension wants to set the content property of a widget to the URL of an image in its package.

Non-Use Cases

  • Manipulation of the URL and the extraction of its component parts. We may well support this in a future iteration of the API, but we won't support this in the initial version.

Dependencies & Requirements

  • access to the IO service and nsIURI objects

API

The API is provided by the url module. The module exports the following properties:

URL
a constructor for URL objects

The URL constructor instantiates a URL object. It accepts the following parameters:

spec
the string representation of the URL

URL objects have the following properties:

spec
the string representation of the URL

Examples

Display a web site in a panel.

let URL = require("url").URL;
let Panel = require("panel").Panel;
let panel = Panel({ content: URL("http://www.example.com/") });
panel.show();

Display an icon in a widget:

let Widget = require("single-ui-element").Widget;
let data = require("self").data;
let url = data.url("icon.png"); // this is a URL object
let widget = new Widget({ content: url) });
require("single-ui-element").add(widget);

Issues

Discussion

Another option we might want to consider is to put the type in the argument name, by passing a "url:" property instead of a "content:" property. In this style, the first example would be expressed as:

let Panel = require("panel").Panel;
let panel = Panel({ url: "http://www.example.com/" });
panel.show();

Benefits: one fewer module to require, smaller code. Drawbacks: documentation for Panel/etc needs to be longer, to explain two properties instead of just one.

--Brian Warner 23:38, 15 March 2010 (UTC)

It needs to be clear whether this package grants network authority to the add-on code which requires it. Is the URL function just a marker? Or does it grant the ability to do GETs and POSTs? I'd recommend the former, since the ability to control whether an add-on can phone home is one of the big obvious controls we want to be able to impose upon them.

--Brian Warner 23:20, 9 April 2010 (UTC)