WebAPI/WidgetAPI
Contents
Goals
The widget API allows privileged application have ability to embed other applications in their own iframe, e.g. homescreen, lockscreen ....etc.
Use case
Proposal
extend manifest.webapp
An application exposes its widget view via declaring details of widget in mainfest.
{ name: "MyApp2000", ... widgets: { "mywidget1": { "name": "MyApp2000 Widget", "launch_path": "/widget.html", "description": "This is my cool widget", "preview_image": "foo.jpg", "locales": { "en-US": { "launch_path": "/widget_en-US.html", "name":"MyApp2000 Widget", "description":"This is my cool widget", "preview_image": "foo_en-US.jpg" } } }, "myotherwidget": { ... } }, widgetPages: [ "/widget.html", "/widget_en-US.html", "/news_reader_settings.html", "/some_other_page.html" ] }
Manifest with Entry Points
For some app with entry_points declared, we still use "widgets" field at the top level of manifest to decouple the relationship between entry points and widgets.
Localization of Widget Info
Similar to app's localization, the localization of widget MUST be embedded in its declaration.
embed-widgets bug 1005818
In order to expose to privileged APPs and consider security issue.
- "embed-widgets" is a new permission for "mozwidget" attribute, it is similar to 'embed-apps' but is more restricted. Please refer to next section.
- Set manifest entry in "widget" attribute.
<iframe mozbrowser=“true" mozwidget="manifestURL" src=“widget.html” remote=“true”>
permission requirements
- embed-widgets
- homescreen-webapp-manage (bug 899994, bug 1000313)
- browser-api (combine with embed-widget would be downgrade )
Restriction
- iframe SRC MUST BE one of widgetPages list.
- Disallow parts of security sensitive browser API
- Ignore mozLockOrientation/mozUnlockOrientation
examples
- APP:
<iframe mozbrowser=“true" mozapp=“manifestURL” remote=“true” src=“appURL”>
- Widget:
<iframe mozbrowser=“true" mozwidget=“manifestURL” remote=“true” src=”widgetURL”>
- Open Bookmark:
//browser (full-set) <iframe mozbrowser=“true" remote="true" src="http://example.com">
Prevent Pages to Be Embedded bug 1043110
Widgets' pages MUST be listed in "widgetPages" field which is the white list of widget pages. All pages in this list can be accessed through widget iframe. Others are shown as error pages, including other app pages and external pages. If the widget frame's src points to a page which is NOT listed in widgetPages,
- for existing app page: show NS_ERROR_MALFORMED_URI
- for missing app page: show NS_ERROR_MALFORMED_URI
- for external web page: show NS_ERROR_MALFORMED_URI
Other Notes
The Timing of Granting Permissions and Limiting Browser API
All permissions and the browser APIs are granted at iframe attached to DOM tree. Once done, Gecko creates/finds a process for this widget and associates them. The permissions and APIs are defined at that time. There is nothing happened when embedder tries to remove the mozwidget attribute or swap mozwidget to mozapp after that. If embedder removes mozwidget and changes the src, iframe still follows the widgetPages rule to check it.
Limited Browser API
Browser API
Need to clarify which methods/Events are safe or unsafe.
Not security sensitive
- Performance methods
- setVisible()
- getVisible()
- Event methods
- addNextPaintListener()
- removeNextPaintListener()
- Events
- mozbrowserclose
- mozbrowsererror
- mozbrowserloadend
- mozbrowserloadstart
- mozbrowserfirstpaint
- mozbrowserdocumentfirstpaint
Security sensitive
- Event methods
- sendMouseEvent() - cross-origin interaction, can cause unexpected actions in web apps
- sendTouchEvent() - cross-origin interaction, can cause unexpected actions in web apps
- getScreenshot()
- Events
- mozbrowserusernameandpasswordrequired - leaks host and realm
- mozbrowseropenwindow (i.e. window.open)
- mozbrowsershowmodalprompt (i.e. alert(), confirm(), prompt())
- mozbrowsercontextmenu
- mozbrowsersecuritychange - can tell is page is https or not
- mozbrowserlocationchange - discloses URL (can contain secrets)
- mozbrowsericonchange - discloses the icon URL. Might be a privacy issue.
- mozbrowsertitlechange - discloses title, privacy issue.
- mozbrowseropensearch - I assume this discloses the link value, maybe a privacy issue?
- mozbrowsermanifestchange
- mozbrowsermetachange
no use case
- Navigation methods
reload()stop()getCanGoBack()goBack()getCanGoForward()goForward()
- Performance methods
purgeHistory()
- Events
mozbrowserasyncscrollmozbrowserresizemozbrowseractivitydonemozbrowserscroll
Q&A
- Why we need an app to explicitly expose its widget view? Is there any use case that an app doesn't want to be opened as a widget?
- The app thinks its function can't be performed in widget mode, like lockscreen app or camera app.
- Just doesn't want itself to be embeded by other apps for various concerns, like Facebook app or bank apps.
- Is it possible to navigate to an external link within a widget?
- It should be fine to navigate an external link within a widget because window.location is changed by widget itself under its window context, not caused by the widget embedder.
- A widget is also an iframe. It follows "X-Frame-Options" restrictions. If a web page declare X-Frame-Options, the widget cannot shows that page.
- May a widget request to enlarge itself to full screen as its app mode?
- No, we don't have a better idea for this case now. Issues like how to force homescreen app to deal with the the resize event requested by widget, how to update mozbrowser iframe attributes to indicate the frame is in app mode...
- Some apps want to app.launch() its app mode while user click its widget, but some want to be enlarged. Is there a way to specify?
- We may introduce an attribute in manifest which tells widget embedder how to process the enlarging behavior. But we have to discuss it with Web API team.
- What happens when embedder removes the mozwidget attribute of existing iframe?
- Nothing. We still follows the widget API rules to manage the iframe, the limited APIs and the same permissions.
- What happens when embedder uses mozapp originally and swap it as mozwidget?
- Nothing. We still follows the mozapp API rules to manage the iframe, the full-set browser API and the same permissions.
- What happens when embedder removes the mozwidget and changes the src of an existing iframe?
- Nothing. We still follows the widget API rules. If the src is in widgetPages, nothing happens. If the src is not in widgetPages, an error is emitted NS_ERROR_DOM_INVALID_ACCESS_ERR or NS_ERROR_FILE_NOT_FOUND.
Bugs
-
bug 1005818A new 'embed-widgets' permission exposing to privileged apps for solving widget case.- Part 1: Load a widget as an app if the |src| is in the |widgetPages|
- Part 2: Only limited browser API are available to a widget
- bug 1043110 an appropriate way to prevent forbidden pages to be embedded in a widget iframe
- bug 1052328 Let privileged apps be able to launch a widget via APP protocol URIs
- bug 1052334 create a function to retrieve preview image of widget
- bug 1053724 Prevent Widget Frame to Listen/Handle System Message