From 1ed4d04a8a5a0c1d39efe1c6347fd86543c981c3 Mon Sep 17 00:00:00 2001 From: Masatoshi Kimura Date: Fri, 9 Aug 2013 23:35:53 +0900 Subject: [PATCH] Bug 899388 - Part 2: Implement allowXBL option for xpc bindings. r=bz --- dom/base/nsDOMClassInfo.cpp | 63 ++++++++++++--------------- dom/base/nsDOMClassInfo.h | 5 ++- dom/base/nsScriptNameSpaceManager.cpp | 2 + dom/base/nsScriptNameSpaceManager.h | 6 ++- 4 files changed, 36 insertions(+), 40 deletions(-) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 057a122d4eab..292fa3e3b409 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -331,44 +331,31 @@ DOMCI_DATA_NO_CLASS(XULButtonElement) DOMCI_DATA_NO_CLASS(XULCheckboxElement) DOMCI_DATA_NO_CLASS(XULPopupElement) -#define NS_DEFINE_CLASSINFO_DATA_WITH_NAME(_class, _name, _helper, \ - _flags) \ - { #_name, \ - nullptr, \ +#define NS_DEFINE_CLASSINFO_DATA_HELPER(_class, _helper, _flags, \ + _chromeOnly, _allowXBL) \ + { #_class, \ + nullptr, \ { _helper::doCreate }, \ - nullptr, \ - nullptr, \ - nullptr, \ + nullptr, \ + nullptr, \ + nullptr, \ _flags, \ - true, \ + true, \ 0, \ - false, \ - false, \ - NS_DEFINE_CLASSINFO_DATA_DEBUG(_class) \ - }, - -#define NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA_WITH_NAME(_class, _name, \ - _helper, _flags) \ - { #_name, \ - nullptr, \ - { _helper::doCreate }, \ - nullptr, \ - nullptr, \ - nullptr, \ - _flags, \ - true, \ - 0, \ - true, \ - false, \ + _chromeOnly, \ + _allowXBL, \ + false, \ NS_DEFINE_CLASSINFO_DATA_DEBUG(_class) \ }, #define NS_DEFINE_CLASSINFO_DATA(_class, _helper, _flags) \ - NS_DEFINE_CLASSINFO_DATA_WITH_NAME(_class, _class, _helper, _flags) + NS_DEFINE_CLASSINFO_DATA_HELPER(_class, _helper, _flags, false, false) -#define NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(_class, _helper, _flags) \ - NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA_WITH_NAME(_class, _class, _helper, \ - _flags) +#define NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(_class, _helper, _flags) \ + NS_DEFINE_CLASSINFO_DATA_HELPER(_class, _helper, _flags, true, false) + +#define NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(_class, _helper, _flags) \ + NS_DEFINE_CLASSINFO_DATA_HELPER(_class, _helper, _flags, true, true) namespace { @@ -1654,7 +1641,8 @@ nsDOMClassInfo::Init() for (i = 0; i < eDOMClassInfoIDCount; ++i) { nsDOMClassInfoData& data = sClassInfoData[i]; nameSpaceManager->RegisterClassName(data.mName, i, data.mChromeOnly, - data.mDisabled, &data.mNameUTF16); + data.mAllowXBL, data.mDisabled, + &data.mNameUTF16); } for (i = 0; i < eDOMClassInfoIDCount; ++i) { @@ -3463,14 +3451,15 @@ ResolvePrototype(nsIXPConnect *aXPConnect, nsGlobalWindow *aWin, JSContext *cx, static bool OldBindingConstructorEnabled(const nsGlobalNameStruct *aStruct, - nsGlobalWindow *aWin) + nsGlobalWindow *aWin, JSContext *cx) { MOZ_ASSERT(aStruct->mType == nsGlobalNameStruct::eTypeClassConstructor || aStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo); // Don't expose chrome only constructors to content windows. if (aStruct->mChromeOnly && - !nsContentUtils::IsSystemPrincipal(aWin->GetPrincipal())) { + (aStruct->mAllowXBL ? !IsChromeOrXBL(cx, nullptr) : + !nsContentUtils::IsSystemPrincipal(aWin->GetPrincipal()))) { return false; } @@ -3532,7 +3521,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx, name_struct->mDefineDOMInterface; if (define) { if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor && - !OldBindingConstructorEnabled(name_struct, aWin)) { + !OldBindingConstructorEnabled(name_struct, aWin, cx)) { return NS_OK; } @@ -3627,7 +3616,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx, if (name_struct->mType == nsGlobalNameStruct::eTypeClassConstructor || name_struct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) { - if (!OldBindingConstructorEnabled(name_struct, aWin)) { + if (!OldBindingConstructorEnabled(name_struct, aWin, cx)) { return NS_OK; } @@ -3720,7 +3709,9 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx, } if (name_struct->mType == nsGlobalNameStruct::eTypeProperty) { - if (name_struct->mChromeOnly && !nsContentUtils::IsCallerChrome()) + if (name_struct->mChromeOnly && + (name_struct->mAllowXBL ? !IsChromeOrXBL(cx, nullptr) : + !nsContentUtils::IsCallerChrome())) return NS_OK; // Before defining a global property, check for a named subframe of the diff --git a/dom/base/nsDOMClassInfo.h b/dom/base/nsDOMClassInfo.h index b0e3fad001aa..af4a61a510de 100644 --- a/dom/base/nsDOMClassInfo.h +++ b/dom/base/nsDOMClassInfo.h @@ -59,8 +59,9 @@ struct nsDOMClassInfoData uint32_t mScriptableFlags : 31; // flags must not use more than 31 bits! uint32_t mHasClassInterface : 1; uint32_t mInterfacesBitmap; - bool mChromeOnly; - bool mDisabled; + bool mChromeOnly : 1; + bool mAllowXBL : 1; + bool mDisabled : 1; #ifdef DEBUG uint32_t mDebugID; #endif diff --git a/dom/base/nsScriptNameSpaceManager.cpp b/dom/base/nsScriptNameSpaceManager.cpp index c18a214771bb..e15e4f5a7768 100644 --- a/dom/base/nsScriptNameSpaceManager.cpp +++ b/dom/base/nsScriptNameSpaceManager.cpp @@ -479,6 +479,7 @@ nsresult nsScriptNameSpaceManager::RegisterClassName(const char *aClassName, int32_t aDOMClassInfoID, bool aPrivileged, + bool aXBLAllowed, bool aDisabled, const PRUnichar **aResult) { @@ -508,6 +509,7 @@ nsScriptNameSpaceManager::RegisterClassName(const char *aClassName, s->mType = nsGlobalNameStruct::eTypeClassConstructor; s->mDOMClassInfoID = aDOMClassInfoID; s->mChromeOnly = aPrivileged; + s->mAllowXBL = aXBLAllowed; s->mDisabled = aDisabled; return NS_OK; diff --git a/dom/base/nsScriptNameSpaceManager.h b/dom/base/nsScriptNameSpaceManager.h index 41e8d144fa26..31fae9224245 100644 --- a/dom/base/nsScriptNameSpaceManager.h +++ b/dom/base/nsScriptNameSpaceManager.h @@ -59,8 +59,9 @@ struct nsGlobalNameStruct // mChromeOnly is only used for structs that define non-WebIDL things // (possibly in addition to WebIDL ones). In particular, it's not even // initialized for eTypeNewDOMBinding structs. - bool mChromeOnly; - bool mDisabled; + bool mChromeOnly : 1; + bool mAllowXBL : 1; + bool mDisabled : 1; union { int32_t mDOMClassInfoID; // eTypeClassConstructor @@ -119,6 +120,7 @@ public: nsresult RegisterClassName(const char *aClassName, int32_t aDOMClassInfoID, bool aPrivileged, + bool aXBLAllowed, bool aDisabled, const PRUnichar **aResult);