Confirmed users
514
edits
BillWalker (talk | contribs) (→Examples: fixed code to work in b2g 3.0) |
|||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
= Navigator. | = Navigator.hasFeature API = | ||
== Use Cases == | == Use Cases == | ||
Line 12: | Line 12: | ||
[NoInterfaceObject] | [NoInterfaceObject] | ||
interface NavigatorFeatures { | interface NavigatorFeatures { | ||
Promise hasFeature(DOMString name); | |||
Promise getFeature(DOMString name); | Promise getFeature(DOMString name); | ||
}; | }; | ||
Line 18: | Line 19: | ||
== Semantics == | == Semantics == | ||
getFeature | Both hasFeature and getFeature accept string arguments to denote the feature names. getFeature resolves the promise with an undefined value if the feature name passed to them is unknown. For the "api" and "manifest" namespaces as described below, hasFeature will fullfill the promise with a true value if the feature exists on the "platform" (which means the current state and version of the hardware and the UA software) albeit hidden behind some runtime permissions, and it will fulfill the promise with a false value if the feature doesn't exist on the "platform". The type of that value depends on the feature being queried. The idea is that hasFeature should be used for mere existence tests, and getFeature should be used for queries involving asking more information about a feature, such as the size of something. | ||
The feature name specifies a namespaced value in the following form: | The feature name specifies a namespaced value in the following form: | ||
Line 32: | Line 33: | ||
=== "api" namespace === | === "api" namespace === | ||
Names under this namespace have this general form: "api.window/worker.InterfaceName.propertyName" | Names under this namespace have this general form: "api.window/worker.InterfaceName.propertyName". These names can be used with hasFeature. | ||
We currently do not support any feature names for the worker context. The following are the names that we support: | We currently do not support any feature names for the worker context. The following are the names that we support: | ||
Line 45: | Line 46: | ||
* api.window.Navigator.mozTime | * api.window.Navigator.mozTime | ||
* api.window.Navigator.mozFMRadio | * api.window.Navigator.mozFMRadio | ||
* api.window.Navigator.mozCameras | * api.window.Navigator.mozCameras | ||
* api.window.Navigator.mozAlarms | * api.window.Navigator.mozAlarms | ||
Line 53: | Line 53: | ||
* api.window.Navigator.getMobileIdAssertion | * api.window.Navigator.getMobileIdAssertion | ||
* api.window.XMLHttpRequest.mozSystem | * api.window.XMLHttpRequest.mozSystem | ||
=== "manifest" namespace === | |||
Names under this namespace have this general form: "manifest.name" or "manifest.name.value". These names can be used with hasFeature. | |||
They are needed to detect whether specifying a field named "name" in the webapp manifest (optionally with a value of "value") will have any effect on the platform. The following names are currently recognized: | |||
* manifest.chrome.navigation | |||
* manifest.origin | |||
* manifest.precompile | |||
* manifest.redirects | |||
== Examples == | == Examples == | ||
Line 65: | Line 75: | ||
The second example checks to see if the privileged FM Radio API is available. | The second example checks to see if the privileged FM Radio API is available. | ||
navigator. | navigator.hasFeature("api.window.Navigator.mozFMRadio").then(function(enabled) { | ||
if (enabled) { | if (enabled) { | ||
alert("FM Radio support detected, my privileged app will work!"); | alert("FM Radio support detected, my privileged app will work!"); | ||
} | } | ||
}); | }); | ||
[[Category:Web APIs]] |