Bug 1009645 - Remove FeatureDetectible, add things with CheckPermissions or AvailableIn to the feature list instead. r=smaug

This commit is contained in:
Reuben Morais 2014-07-24 16:57:02 -03:00
parent 8a0a83fb86
commit 9ef413e461
10 changed files with 185 additions and 66 deletions

View File

@ -1542,9 +1542,82 @@ Navigator::GetFeature(const nsAString& aName, ErrorResult& aRv)
}
}
p->MaybeResolve(JS::UndefinedHandleValue);
return p.forget();
}
already_AddRefed<Promise>
Navigator::HasFeature(const nsAString& aName, ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
nsRefPtr<Promise> p = Promise::Create(go, aRv);
if (aRv.Failed()) {
return nullptr;
}
NS_NAMED_LITERAL_STRING(apiWindowPrefix, "api.window.");
if (StringBeginsWith(aName, apiWindowPrefix)) {
const nsAString& featureName = Substring(aName, apiWindowPrefix.Length());
// Temporary hardcoded entry points due to technical constraints
if (featureName.EqualsLiteral("Navigator.mozTCPSocket")) {
p->MaybeResolve(Preferences::GetBool("dom.mozTCPSocket.enabled"));
return p.forget();
}
if (featureName.EqualsLiteral("Navigator.mozMobileConnections") ||
featureName.EqualsLiteral("MozMobileNetworkInfo")) {
p->MaybeResolve(Preferences::GetBool("dom.mobileconnection.enabled"));
return p.forget();
}
if (featureName.EqualsLiteral("Navigator.mozInputMethod")) {
p->MaybeResolve(Preferences::GetBool("dom.mozInputMethod.enabled"));
return p.forget();
}
if (featureName.EqualsLiteral("Navigator.mozContacts")) {
p->MaybeResolve(true);
return p.forget();
}
if (featureName.EqualsLiteral("Navigator.getDeviceStorage")) {
p->MaybeResolve(Preferences::GetBool("device.storage.enabled"));
return p.forget();
}
if (featureName.EqualsLiteral("Navigator.mozNetworkStats")) {
p->MaybeResolve(Preferences::GetBool("dom.mozNetworkStats.enabled"));
return p.forget();
}
if (featureName.EqualsLiteral("Navigator.push")) {
p->MaybeResolve(Preferences::GetBool("services.push.enabled"));
return p.forget();
}
if (featureName.EqualsLiteral("Navigator.mozAlarms")) {
p->MaybeResolve(Preferences::GetBool("dom.mozAlarms.enabled"));
return p.forget();
}
if (featureName.EqualsLiteral("Navigator.mozCameras")) {
p->MaybeResolve(true);
return p.forget();
}
#ifdef MOZ_B2G
if (featureName.EqualsLiteral("Navigator.getMobileIdAssertion")) {
p->MaybeResolve(true);
return p.forget();
}
#endif
if (featureName.EqualsLiteral("XMLHttpRequest.mozSystem")) {
p->MaybeResolve(true);
return p.forget();
}
if (IsFeatureDetectible(featureName)) {
p->MaybeResolve(true);
} else {
@ -1559,7 +1632,6 @@ Navigator::GetFeature(const nsAString& aName, ErrorResult& aRv)
return p.forget();
}
PowerManager*
Navigator::GetMozPower(ErrorResult& aRv)
{
@ -2371,7 +2443,8 @@ Navigator::HasMobileIdSupport(JSContext* aCx, JSObject* aGlobal)
uint32_t permission = nsIPermissionManager::UNKNOWN_ACTION;
permMgr->TestPermissionFromPrincipal(principal, "mobileid", &permission);
return permission != nsIPermissionManager::UNKNOWN_ACTION;
return permission == nsIPermissionManager::PROMPT_ACTION ||
permission == nsIPermissionManager::ALLOW_ACTION;
}
#endif

View File

@ -172,6 +172,9 @@ public:
already_AddRefed<Promise> GetFeature(const nsAString& aName,
ErrorResult& aRv);
already_AddRefed<Promise> HasFeature(const nsAString &aName,
ErrorResult& aRv);
bool Vibrate(uint32_t aDuration);
bool Vibrate(const nsTArray<uint32_t>& aDuration);
uint32_t MaxTouchPoints();

View File

@ -43,6 +43,7 @@ skip-if = buildapp == 'mulet' || buildapp == 'b2g' || toolkit == 'android' || e1
[test_gsp-standards.html]
[test_getFeature_with_perm.html]
[test_getFeature_without_perm.html]
[test_hasFeature.html]
[test_history_document_open.html]
[test_history_state_null.html]
[test_Image_constructor.html]

View File

@ -0,0 +1,78 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1009645
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1009645</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1009645">Mozilla Bug 1009645</a>
<script type="application/javascript">
function testAPIs() {
function pref(name) {
try {
return SpecialPowers.getBoolPref(name);
} catch (e) {
return false;
}
}
var b2gOnly = (function() {
var isAndroid = !!navigator.userAgent.contains("Android");
var isB2g = !isAndroid && /Mobile|Tablet/.test(navigator.userAgent);
return isB2g ? true : undefined;
})();
var APIEndPoints = [
{ name: "MozMobileNetworkInfo", enabled: pref("dom.mobileconnection.enabled") },
// { name: "Navigator.mozBluetooth", enabled: b2gOnly }, // conditional on MOZ_B2G_BT, tricky to test
{ name: "Navigator.mozContacts", enabled: pref("dom.mozContacts.enabled") },
{ name: "Navigator.getDeviceStorage", enabled: pref("device.storage.enabled") },
{ name: "Navigator.addIdleObserver", enabled: true },
{ name: "Navigator.mozNetworkStats", enabled: pref("dom.mozNetworkStats.enabled") },
{ name: "Navigator.push", enabled: pref("services.push.enabled") },
{ name: "Navigator.mozTime", enabled: b2gOnly },
// { name: "Navigator.mozFMRadio", enabled: b2gOnly }, // conditional on MOZ_B2G_FM, tricky to test
{ name: "Navigator.mozCameras", enabled: true },
{ name: "Navigator.mozAlarms", enabled: pref("dom.mozAlarms.enabled") },
{ name: "Navigator.mozTCPSocket", enabled: pref("dom.mozTCPSocket.enabled") },
{ name: "Navigator.mozInputMethod", enabled: pref("dom.mozInputMethod.enabled") },
{ name: "Navigator.mozMobileConnections", enabled: pref("dom.mobileconnection.enabled") },
{ name: "Navigator.getMobileIdAssertion", enabled: b2gOnly },
{ name: "XMLHttpRequest.mozSystem", enabled: true }
];
var promises = [];
APIEndPoints.forEach(function(v) {
promises.push(navigator.hasFeature("api.window." + v.name));
});
Promise.all(promises).then(function(values) {
for (var i = 0; i < values.length; ++i) {
ise(values[i], APIEndPoints[i].enabled,
"Endpoint " + APIEndPoints[i].name + " resolved with the correct value. " +
"If this is failing because you're changing how an API is exposed, you " +
"must contact the Marketplace team to let them know about the change.");
}
SimpleTest.finish();
}, function() {
ok(false, "The Promise should not be rejected");
SimpleTest.finish();
});
}
SpecialPowers.pushPermissions([
{type: "feature-detection", allow: true, context: document}
], function() {
ok('hasFeature' in navigator, "navigator.hasFeature should exist");
testAPIs();
});
SimpleTest.waitForExplicitFinish();
</script>
</body>
</html>

View File

@ -447,17 +447,27 @@ class Descriptor(DescriptorProvider):
if permissionsIndex is not None:
self.checkPermissionsIndicesForMembers[m.identifier.name] = permissionsIndex
self.featureDetectibleThings = set()
if self.interface.getExtendedAttribute("FeatureDetectible") is not None:
if self.interface.getNavigatorProperty():
self.featureDetectibleThings.add("Navigator.%s" % self.interface.getNavigatorProperty())
else:
assert(self.interface.ctor() is not None)
self.featureDetectibleThings.add(self.interface.identifier.name)
def isTestInterface(iface):
return (iface.identifier.name in ["TestInterface",
"TestJSImplInterface",
"TestRenamedInterface"])
for m in self.interface.members:
if m.getExtendedAttribute("FeatureDetectible") is not None:
self.featureDetectibleThings.add("%s.%s" % (self.interface.identifier.name, m.identifier.name))
self.featureDetectibleThings = set()
if not isTestInterface(self.interface):
if (self.interface.getExtendedAttribute("CheckPermissions") or
self.interface.getExtendedAttribute("AvailableIn") == "PrivilegedApps"):
if self.interface.getNavigatorProperty():
self.featureDetectibleThings.add("Navigator.%s" % self.interface.getNavigatorProperty())
else:
iface = self.interface.identifier.name
self.featureDetectibleThings.add(iface)
for m in self.interface.members:
self.featureDetectibleThings.add("%s.%s" % (iface, m.identifier.name))
for m in self.interface.members:
if (m.getExtendedAttribute("CheckPermissions") or
m.getExtendedAttribute("AvailableIn") == "PrivilegedApps"):
self.featureDetectibleThings.add("%s.%s" % (self.interface.identifier.name, m.identifier.name))
# Build the prototype chain.
self.prototypeChain = []

View File

@ -669,22 +669,6 @@ class IDLInterface(IDLObjectWithScope):
[self.location])
assert not parent or isinstance(parent, IDLInterface)
if self.getExtendedAttribute("FeatureDetectible"):
if not (self.getExtendedAttribute("Func") or
self.getExtendedAttribute("AvailableIn") or
self.getExtendedAttribute("CheckPermissions")):
raise WebIDLError("[FeatureDetectible] is only allowed in combination "
"with [Func], [AvailableIn] or [CheckPermissions]",
[self.location])
if self.getExtendedAttribute("Pref"):
raise WebIDLError("[FeatureDetectible] must not be specified "
"in combination with [Pref]",
[self.location])
if not self.hasInterfaceObject():
raise WebIDLError("[FeatureDetectible] not allowed on interface "
"with [NoInterfaceObject]",
[self.location])
self.parent = parent
assert iter(self.members)
@ -1207,8 +1191,7 @@ class IDLInterface(IDLObjectWithScope):
identifier == "OverrideBuiltins" or
identifier == "ChromeOnly" or
identifier == "Unforgeable" or
identifier == "LegacyEventInit" or
identifier == "FeatureDetectible"):
identifier == "LegacyEventInit"):
# Known extended attributes that do not take values
if not attr.noArguments():
raise WebIDLError("[%s] must take no arguments" % identifier,
@ -3174,18 +3157,6 @@ class IDLAttribute(IDLInterfaceMember):
raise WebIDLError("An attribute with [SameObject] must have an "
"interface type as its type", [self.location])
if self.getExtendedAttribute("FeatureDetectible"):
if not (self.getExtendedAttribute("Func") or
self.getExtendedAttribute("AvailableIn") or
self.getExtendedAttribute("CheckPermissions")):
raise WebIDLError("[FeatureDetectible] is only allowed in combination "
"with [Func], [AvailableIn] or [CheckPermissions]",
[self.location])
if self.getExtendedAttribute("Pref"):
raise WebIDLError("[FeatureDetectible] must not be specified "
"in combination with [Pref]",
[self.location])
def validate(self):
IDLInterfaceMember.validate(self)
@ -3324,8 +3295,7 @@ class IDLAttribute(IDLInterfaceMember):
identifier == "Frozen" or
identifier == "AvailableIn" or
identifier == "NewObject" or
identifier == "CheckPermissions" or
identifier == "FeatureDetectible"):
identifier == "CheckPermissions"):
# Known attributes that we don't need to do anything with here
pass
else:
@ -3730,18 +3700,6 @@ class IDLMethod(IDLInterfaceMember, IDLScope):
def finish(self, scope):
IDLInterfaceMember.finish(self, scope)
if self.getExtendedAttribute("FeatureDetectible"):
if not (self.getExtendedAttribute("Func") or
self.getExtendedAttribute("AvailableIn") or
self.getExtendedAttribute("CheckPermissions")):
raise WebIDLError("[FeatureDetectible] is only allowed in combination "
"with [Func], [AvailableIn] or [CheckPermissions]",
[self.location])
if self.getExtendedAttribute("Pref"):
raise WebIDLError("[FeatureDetectible] must not be specified "
"in combination with [Pref]",
[self.location])
overloadWithPromiseReturnType = None
overloadWithoutPromiseReturnType = None
for overload in self._overloads:
@ -3922,8 +3880,7 @@ class IDLMethod(IDLInterfaceMember, IDLScope):
convertExposedAttrToGlobalNameSet(attr, self._exposureGlobalNames)
elif (identifier == "Pure" or
identifier == "CrossOriginCallable" or
identifier == "WebGLHandlesContextLoss" or
identifier == "FeatureDetectible"):
identifier == "WebGLHandlesContextLoss"):
# Known no-argument attributes.
if not attr.noArguments():
raise WebIDLError("[%s] must take no arguments" % identifier,

View File

@ -36,7 +36,6 @@ function verifier(success, failure) {
var gData = [
{
perm: ["idle"],
settings: [["dom.idle-observers-api.enabled", true]],
verifier: verifier.toSource(),
}
]

View File

@ -86,6 +86,9 @@ interface NavigatorStorageUtils {
interface NavigatorFeatures {
[CheckPermissions="feature-detection", Throws]
Promise<any> getFeature(DOMString name);
[CheckPermissions="feature-detection", Throws]
Promise<any> hasFeature(DOMString name);
};
// Things that definitely need to be in the spec and and are not for some
@ -195,13 +198,13 @@ partial interface Navigator {
/**
* Navigator requests to add an idle observer to the existing window.
*/
[Throws, CheckPermissions="idle", Pref="dom.idle-observers-api.enabled"]
[Throws, CheckPermissions="idle"]
void addIdleObserver(MozIdleObserver aIdleObserver);
/**
* Navigator requests to remove an idle observer from the existing window.
*/
[Throws, CheckPermissions="idle", Pref="dom.idle-observers-api.enabled"]
[Throws, CheckPermissions="idle"]
void removeIdleObserver(MozIdleObserver aIdleObserver);
/**

View File

@ -7,7 +7,6 @@
[CheckPermissions="resourcestats-manage",
Pref="dom.resource_stats.enabled",
AvailableIn="CertifiedApps",
// FeatureDetectible, // This should be specified after Bug 1009645 is resolved.
JSImplementation="@mozilla.org/networkStatsData;1"]
interface NetworkStatsData
{
@ -19,7 +18,6 @@ interface NetworkStatsData
[CheckPermissions="resourcestats-manage",
Pref="dom.resource_stats.enabled",
AvailableIn="CertifiedApps",
// FeatureDetectible, // This should be specified after Bug 1009645 is resolved.
JSImplementation="@mozilla.org/powerStatsData;1"]
interface PowerStatsData
{
@ -30,7 +28,6 @@ interface PowerStatsData
[CheckPermissions="resourcestats-manage",
Pref="dom.resource_stats.enabled",
AvailableIn="CertifiedApps",
// FeatureDetectible, // This should be specified after Bug 1009645 is resolved.
JSImplementation="@mozilla.org/resourceStats;1"]
interface ResourceStats
{

View File

@ -73,7 +73,6 @@ dictionary ResourceStatsAlarmOptions
[CheckPermissions="resourcestats-manage",
Pref="dom.resource_stats.enabled",
AvailableIn="CertifiedApps",
// FeatureDetectible, // This should be specified after Bug 1009645 is resolved.
JSImplementation="@mozilla.org/resourceStatsAlarm;1"]
interface ResourceStatsAlarm
{
@ -117,7 +116,6 @@ interface ResourceStatsAlarm
Pref="dom.resource_stats.enabled",
Constructor(ResourceType type),
AvailableIn="CertifiedApps",
// FeatureDetectible, // This should be specified after Bug 1009645 is resolved.
JSImplementation="@mozilla.org/resourceStatsManager;1"]
interface ResourceStatsManager
{