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."); NS_NAMED_LITERAL_STRING(apiWindowPrefix, "api.window.");
if (StringBeginsWith(aName, apiWindowPrefix)) { if (StringBeginsWith(aName, apiWindowPrefix)) {
const nsAString& featureName = Substring(aName, apiWindowPrefix.Length()); 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)) { if (IsFeatureDetectible(featureName)) {
p->MaybeResolve(true); p->MaybeResolve(true);
} else { } else {
@ -1559,7 +1632,6 @@ Navigator::GetFeature(const nsAString& aName, ErrorResult& aRv)
return p.forget(); return p.forget();
} }
PowerManager* PowerManager*
Navigator::GetMozPower(ErrorResult& aRv) Navigator::GetMozPower(ErrorResult& aRv)
{ {
@ -2371,7 +2443,8 @@ Navigator::HasMobileIdSupport(JSContext* aCx, JSObject* aGlobal)
uint32_t permission = nsIPermissionManager::UNKNOWN_ACTION; uint32_t permission = nsIPermissionManager::UNKNOWN_ACTION;
permMgr->TestPermissionFromPrincipal(principal, "mobileid", &permission); permMgr->TestPermissionFromPrincipal(principal, "mobileid", &permission);
return permission != nsIPermissionManager::UNKNOWN_ACTION; return permission == nsIPermissionManager::PROMPT_ACTION ||
permission == nsIPermissionManager::ALLOW_ACTION;
} }
#endif #endif

View File

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

View File

@ -43,6 +43,7 @@ skip-if = buildapp == 'mulet' || buildapp == 'b2g' || toolkit == 'android' || e1
[test_gsp-standards.html] [test_gsp-standards.html]
[test_getFeature_with_perm.html] [test_getFeature_with_perm.html]
[test_getFeature_without_perm.html] [test_getFeature_without_perm.html]
[test_hasFeature.html]
[test_history_document_open.html] [test_history_document_open.html]
[test_history_state_null.html] [test_history_state_null.html]
[test_Image_constructor.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: if permissionsIndex is not None:
self.checkPermissionsIndicesForMembers[m.identifier.name] = permissionsIndex self.checkPermissionsIndicesForMembers[m.identifier.name] = permissionsIndex
self.featureDetectibleThings = set() def isTestInterface(iface):
if self.interface.getExtendedAttribute("FeatureDetectible") is not None: return (iface.identifier.name in ["TestInterface",
if self.interface.getNavigatorProperty(): "TestJSImplInterface",
self.featureDetectibleThings.add("Navigator.%s" % self.interface.getNavigatorProperty()) "TestRenamedInterface"])
else:
assert(self.interface.ctor() is not None)
self.featureDetectibleThings.add(self.interface.identifier.name)
for m in self.interface.members: self.featureDetectibleThings = set()
if m.getExtendedAttribute("FeatureDetectible") is not None: if not isTestInterface(self.interface):
self.featureDetectibleThings.add("%s.%s" % (self.interface.identifier.name, m.identifier.name)) 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. # Build the prototype chain.
self.prototypeChain = [] self.prototypeChain = []

View File

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

View File

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

View File

@ -86,6 +86,9 @@ interface NavigatorStorageUtils {
interface NavigatorFeatures { interface NavigatorFeatures {
[CheckPermissions="feature-detection", Throws] [CheckPermissions="feature-detection", Throws]
Promise<any> getFeature(DOMString name); 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 // 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. * 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); void addIdleObserver(MozIdleObserver aIdleObserver);
/** /**
* Navigator requests to remove an idle observer from the existing window. * 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); void removeIdleObserver(MozIdleObserver aIdleObserver);
/** /**

View File

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

View File

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