Bug 778044. Add a way to pref off Paris binding constructor objects. r=peterv

This commit is contained in:
Boris Zbarsky 2012-09-05 13:37:28 -04:00
parent 60ef34b89f
commit 437a27a6d1
7 changed files with 49 additions and 7 deletions

View File

@ -4639,7 +4639,8 @@ nsDOMClassInfo::Init()
mozilla::dom::oldproxybindings::Register(nameSpaceManager);
if (!AzureCanvasEnabled()) {
nameSpaceManager->RegisterDefineDOMInterface(NS_LITERAL_STRING("CanvasRenderingContext2D"), NULL);
nameSpaceManager->RegisterDefineDOMInterface(NS_LITERAL_STRING("CanvasRenderingContext2D"),
nullptr, nullptr);
}
sIsInitialized = true;
@ -6790,6 +6791,10 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
return NS_OK;
}
if (name_struct->mPrefEnabled && !(*name_struct->mPrefEnabled)()) {
return NS_OK;
}
if (mozilla::dom::DefineConstructor(cx, obj, define, &rv)) {
*did_resolve = NS_SUCCEEDED(rv);

View File

@ -781,7 +781,8 @@ nsScriptNameSpaceManager::Observe(nsISupports* aSubject, const char* aTopic,
void
nsScriptNameSpaceManager::RegisterDefineDOMInterface(const nsAFlatString& aName,
mozilla::dom::DefineInterface aDefineDOMInterface)
mozilla::dom::DefineInterface aDefineDOMInterface,
mozilla::dom::PrefEnabled aPrefEnabled)
{
nsGlobalNameStruct *s = AddToHash(&mGlobalNames, &aName);
if (s) {
@ -789,5 +790,6 @@ nsScriptNameSpaceManager::RegisterDefineDOMInterface(const nsAFlatString& aName,
s->mType = nsGlobalNameStruct::eTypeNewDOMBinding;
}
s->mDefineDOMInterface = aDefineDOMInterface;
s->mPrefEnabled = aPrefEnabled;
}
}

View File

@ -68,6 +68,7 @@ struct nsGlobalNameStruct
// For new style DOM bindings.
mozilla::dom::DefineInterface mDefineDOMInterface;
mozilla::dom::PrefEnabled mPrefEnabled; // May be null if not pref controlled
private:
@ -139,7 +140,8 @@ public:
nsGlobalNameStruct* GetConstructorProto(const nsGlobalNameStruct* aStruct);
void RegisterDefineDOMInterface(const nsAFlatString& aName,
mozilla::dom::DefineInterface aDefineDOMInterface);
mozilla::dom::DefineInterface aDefineDOMInterface,
mozilla::dom::PrefEnabled aPrefEnabled);
private:
// Adds a new entry to the hash and returns the nsGlobalNameStruct

View File

@ -1338,6 +1338,24 @@ class CGDefineDOMInterfaceMethod(CGAbstractMethod):
*aEnabled = true;
return !!%s(aCx, global, aReceiver);""" % (getter))
class CGPrefEnabled(CGAbstractMethod):
"""
A method for testing whether the preference controlling this
interface is enabled. When it's not, the interface should not be
visible on the global.
"""
def __init__(self, descriptor):
CGAbstractMethod.__init__(self, descriptor, 'PrefEnabled', 'bool', [])
def declare(self):
return CGAbstractMethod.declare(self)
def define(self):
return CGAbstractMethod.define(self)
def definition_body(self):
return " return %s::PrefEnabled();" % self.descriptor.nativeType
class CGIsMethod(CGAbstractMethod):
def __init__(self, descriptor):
args = [Argument('JSObject*', 'obj')]
@ -4999,6 +5017,11 @@ class CGDescriptor(CGThing):
if descriptor.interface.hasInterfaceObject():
cgThings.append(CGDefineDOMInterfaceMethod(descriptor))
if (not descriptor.interface.isExternal() and
# Workers stuff is never pref-controlled
not descriptor.workers and
descriptor.interface.getExtendedAttribute("PrefControlled") is not None):
cgThings.append(CGPrefEnabled(descriptor))
if descriptor.interface.hasInterfacePrototypeObject():
cgThings.append(CGNativePropertyHooks(descriptor))
@ -5310,12 +5333,16 @@ class CGRegisterProtos(CGAbstractMethod):
def _defineMacro(self):
return """
#define REGISTER_PROTO(_dom_class) \\
aNameSpaceManager->RegisterDefineDOMInterface(NS_LITERAL_STRING(#_dom_class), _dom_class##Binding::DefineDOMInterface);\n\n"""
#define REGISTER_PROTO(_dom_class, _pref_check) \\
aNameSpaceManager->RegisterDefineDOMInterface(NS_LITERAL_STRING(#_dom_class), _dom_class##Binding::DefineDOMInterface, _pref_check);\n\n"""
def _undefineMacro(self):
return "\n#undef REGISTER_PROTO"
def _registerProtos(self):
lines = ["REGISTER_PROTO(%s);" % desc.name
def getPrefCheck(desc):
if desc.interface.getExtendedAttribute("PrefControlled") is None:
return "nullptr"
return "%sBinding::PrefEnabled" % desc.name
lines = ["REGISTER_PROTO(%s, %s);" % (desc.name, getPrefCheck(desc))
for desc in self.config.getDescriptors(hasInterfaceObject=True,
isExternal=False,
workers=False,

View File

@ -738,6 +738,9 @@ class IDLInterface(IDLObjectWithScope):
return loopPoint
return None
def getExtendedAttribute(self, name):
return self._extendedAttrDict.get(name, None)
class IDLDictionary(IDLObjectWithScope):
def __init__(self, location, parentScope, name, parent, members):
assert isinstance(parentScope, IDLScope)

View File

@ -736,7 +736,7 @@ def writeStubFile(filename, config, interfaces):
"Register(nsScriptNameSpaceManager* aNameSpaceManager)\n"
"{\n"
"#define REGISTER_PROTO(_dom_class) \\\n"
" aNameSpaceManager->RegisterDefineDOMInterface(NS_LITERAL_STRING(#_dom_class), _dom_class##Wrapper::DefineDOMInterface);\n\n"""
" aNameSpaceManager->RegisterDefineDOMInterface(NS_LITERAL_STRING(#_dom_class), _dom_class##Wrapper::DefineDOMInterface, nullptr);\n\n"""
"\n")
for clazz in config.list_classes.itervalues():
f.write(" REGISTER_PROTO(%s);\n" % clazz.name)

View File

@ -345,6 +345,9 @@ inline bool IsDOMProxy(JSObject *obj)
typedef bool
(*DefineInterface)(JSContext *cx, JSObject *global, bool *enabled);
typedef bool
(*PrefEnabled)();
extern bool
DefineStaticJSVals(JSContext *cx);
void