Bug 1286548 - SecureContext makes sense for interface with NoInterfaceObject, since it is also propagated to interface members; r?bz draft
authorEdgar Chen <echen@mozilla.com>
Thu, 14 Jul 2016 17:48:20 +0800
changeset 387937 331204ac24dc85c67aac73210697448e2bd34e54
parent 386010 679118259e91f40d4a8f968f03ec4cff066cdb5b
child 525488 e803f06fa1460b51794b0ad7241b943a1b80f995
push id23111
push userechen@mozilla.com
push dateFri, 15 Jul 2016 03:35:25 +0000
reviewersbz
bugs1286548
milestone50.0a1
Bug 1286548 - SecureContext makes sense for interface with NoInterfaceObject, since it is also propagated to interface members; r?bz MozReview-Commit-ID: K7Z3r2YRt7M
dom/bindings/parser/WebIDL.py
dom/bindings/parser/tests/test_securecontext_extended_attribute.py
--- a/dom/bindings/parser/WebIDL.py
+++ b/dom/bindings/parser/WebIDL.py
@@ -1301,17 +1301,19 @@ class IDLInterfaceOrNamespace(IDLObjectW
                 self._exposureGlobalNames != set([self.parentScope.primaryGlobalName])):
                 raise WebIDLError("[%s] used on an interface that is "
                                   "not %s-only" %
                                   (attribute, self.parentScope.primaryGlobalName),
                                   [self.location])
 
         # Conditional exposure makes no sense for interfaces with no
         # interface object, unless they're navigator properties.
-        if (self.isExposedConditionally() and
+        # And SecureContext makes sense for interfaces with no interface object,
+        # since it is also propagated to interface members.
+        if (self.isExposedConditionally(exclusions=["SecureContext"]) and
             not self.hasInterfaceObject() and
             not self.isNavigatorProperty()):
             raise WebIDLError("Interface with no interface object is "
                               "exposed conditionally",
                               [self.location])
 
         # Value iterators are only allowed on interfaces with indexed getters,
         # and pair iterators are only allowed on interfaces without indexed
@@ -1539,18 +1541,18 @@ class IDLInterfaceOrNamespace(IDLObjectW
 
     def hasMembersInSlots(self):
         return self._ownMembersInSlots != 0
 
     conditionExtendedAttributes = [ "Pref", "ChromeOnly", "Func", "AvailableIn",
                                     "SecureContext",
                                     "CheckAnyPermissions",
                                     "CheckAllPermissions" ]
-    def isExposedConditionally(self):
-        return any(self.getExtendedAttribute(a) for a in self.conditionExtendedAttributes)
+    def isExposedConditionally(self, exclusions=[]):
+        return any(((not a in exclusions) and self.getExtendedAttribute(a)) for a in self.conditionExtendedAttributes)
 
 class IDLInterface(IDLInterfaceOrNamespace):
     def __init__(self, location, parentScope, name, parent, members,
                  isKnownNonPartial):
         IDLInterfaceOrNamespace.__init__(self, location, parentScope, name,
                                          parent, members, isKnownNonPartial)
 
     def __str__(self):
--- a/dom/bindings/parser/tests/test_securecontext_extended_attribute.py
+++ b/dom/bindings/parser/tests/test_securecontext_extended_attribute.py
@@ -311,8 +311,22 @@ def WebIDLTest(parser, harness):
                "[SecureContext] should propagate from interface to constant members even when other members are copied from a non-[SecureContext] interface")
     harness.ok(results[0].members[1].getExtendedAttribute("SecureContext") is None,
                "Constants copied from non-[SecureContext] interface should not be [SecureContext]")
     harness.ok(results[0].members[2].getExtendedAttribute("SecureContext") is None,
                "Attributes copied from non-[SecureContext] interface should not be [SecureContext]")
     harness.ok(results[0].members[3].getExtendedAttribute("SecureContext") is None,
                "Methods copied from non-[SecureContext] interface should not be [SecureContext]")
  
+    # Test SecureContext and NoInterfaceObject
+    parser = parser.reset()
+    parser.parse("""
+        [NoInterfaceObject, SecureContext]
+        interface TestSecureContextNoInterfaceObject {
+          void testSecureMethod(byte foo);
+        };
+    """)
+    results = parser.finish()
+    harness.check(len(results[0].members), 1, "TestSecureContextNoInterfaceObject should have only one member")
+    harness.ok(results[0].getExtendedAttribute("SecureContext"),
+      "Interface should have [SecureContext] extended attribute")
+    harness.ok(results[0].members[0].getExtendedAttribute("SecureContext"),
+      "Interface member should have [SecureContext] extended attribute")