mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-30 14:17:36 -10:00
Bug 1446342: Don't include forms in the scope chain for XBL datetime bindings. r=smaug
Reviewers: smaug Bug #: 1446342 Differential Revision: https://phabricator.services.mozilla.com/D769 MozReview-Commit-ID: HK7nChYf0X6
This commit is contained in:
1 parent
2a16dda0c9
commit
63543e10fd
14 files changed
+112
-28
No files matched your search
+45
-7
@@ -25,6 +25,7 @@
|
||||
#include "xpcpublic.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "nsXBLPrototypeBinding.h"
|
||||
#include "mozilla/CycleCollectedJSContext.h"
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "mozilla/dom/Date.h"
|
||||
@@ -462,19 +463,31 @@ nsJSUtils::ModuleEvaluate(JSContext* aCx, JS::Handle<JSObject*> aModule)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static bool
|
||||
AddScopeChainItem(JSContext* aCx,
|
||||
nsINode* aNode,
|
||||
JS::AutoObjectVector& aScopeChain)
|
||||
{
|
||||
JS::RootedValue val(aCx);
|
||||
if (!GetOrCreateDOMReflector(aCx, aNode, &val)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!aScopeChain.append(&val.toObject())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool
|
||||
nsJSUtils::GetScopeChainForElement(JSContext* aCx,
|
||||
mozilla::dom::Element* aElement,
|
||||
Element* aElement,
|
||||
JS::AutoObjectVector& aScopeChain)
|
||||
{
|
||||
for (nsINode* cur = aElement; cur; cur = cur->GetScopeChainParent()) {
|
||||
JS::RootedValue val(aCx);
|
||||
if (!GetOrCreateDOMReflector(aCx, cur, &val)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!aScopeChain.append(&val.toObject())) {
|
||||
if (!AddScopeChainItem(aCx, cur, aScopeChain)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -482,6 +495,31 @@ nsJSUtils::GetScopeChainForElement(JSContext* aCx,
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */
|
||||
bool
|
||||
nsJSUtils::GetScopeChainForXBL(JSContext* aCx,
|
||||
Element* aElement,
|
||||
const nsXBLPrototypeBinding& aProtoBinding,
|
||||
JS::AutoObjectVector& aScopeChain)
|
||||
{
|
||||
if (!aElement) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!aProtoBinding.SimpleScopeChain()) {
|
||||
return GetScopeChainForElement(aCx, aElement, aScopeChain);
|
||||
}
|
||||
|
||||
if (!AddScopeChainItem(aCx, aElement, aScopeChain)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!AddScopeChainItem(aCx, aElement->OwnerDoc(), aScopeChain)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void
|
||||
nsJSUtils::ResetTimeZone()
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
class nsIScriptContext;
|
||||
class nsIScriptElement;
|
||||
class nsIScriptGlobalObject;
|
||||
class nsXBLPrototypeBinding;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@@ -202,6 +203,17 @@ public:
|
||||
mozilla::dom::Element* aElement,
|
||||
JS::AutoObjectVector& aScopeChain);
|
||||
|
||||
// Returns a scope chain suitable for XBL execution.
|
||||
//
|
||||
// This is by default GetScopeChainForElemenet, but will be different if the
|
||||
// <binding> element had the simpleScopeChain attribute.
|
||||
//
|
||||
// This is to prevent footguns like bug 1446342.
|
||||
static bool GetScopeChainForXBL(JSContext* aCx,
|
||||
mozilla::dom::Element* aBoundElement,
|
||||
const nsXBLPrototypeBinding& aProtoBinding,
|
||||
JS::AutoObjectVector& aScopeChain);
|
||||
|
||||
static void ResetTimeZone();
|
||||
};
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ InstallXBLField(JSContext* cx,
|
||||
nsXBLProtoImplField* field = protoBinding->FindField(fieldName);
|
||||
MOZ_ASSERT(field);
|
||||
|
||||
nsresult rv = field->InstallField(thisObj, protoBinding->DocURI(), installed);
|
||||
nsresult rv = field->InstallField(thisObj, *protoBinding, installed);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
return true;
|
||||
}
|
||||
@@ -372,7 +372,7 @@ nsXBLProtoImplField::InstallAccessors(JSContext* aCx,
|
||||
|
||||
nsresult
|
||||
nsXBLProtoImplField::InstallField(JS::Handle<JSObject*> aBoundNode,
|
||||
nsIURI* aBindingDocURI,
|
||||
const nsXBLPrototypeBinding& aProtoBinding,
|
||||
bool* aDidInstall) const
|
||||
{
|
||||
NS_PRECONDITION(aBoundNode,
|
||||
@@ -389,7 +389,7 @@ nsXBLProtoImplField::InstallField(JS::Handle<JSObject*> aBoundNode,
|
||||
nsAutoMicroTask mt;
|
||||
|
||||
nsAutoCString uriSpec;
|
||||
nsresult rv = aBindingDocURI->GetSpec(uriSpec);
|
||||
nsresult rv = aProtoBinding.DocURI()->GetSpec(uriSpec);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
@@ -432,7 +432,7 @@ nsXBLProtoImplField::InstallField(JS::Handle<JSObject*> aBoundNode,
|
||||
JS::CompileOptions options(cx);
|
||||
options.setFileAndLine(uriSpec.get(), mLineNumber);
|
||||
JS::AutoObjectVector scopeChain(cx);
|
||||
if (!nsJSUtils::GetScopeChainForElement(cx, boundElement, scopeChain)) {
|
||||
if (!nsJSUtils::GetScopeChainForXBL(cx, boundElement, aProtoBinding, scopeChain)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
rv = NS_OK;
|
||||
|
||||
@@ -33,7 +33,7 @@ public:
|
||||
void SetNext(nsXBLProtoImplField* aNext) { mNext = aNext; }
|
||||
|
||||
nsresult InstallField(JS::Handle<JSObject*> aBoundNode,
|
||||
nsIURI* aBindingDocURI,
|
||||
const nsXBLPrototypeBinding& aProtoBinding,
|
||||
bool* aDidInstall) const;
|
||||
|
||||
nsresult InstallAccessors(JSContext* aCx,
|
||||
|
||||
@@ -259,7 +259,8 @@ nsXBLProtoImplMethod::Write(nsIObjectOutputStream* aStream)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement)
|
||||
nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement,
|
||||
const nsXBLPrototypeBinding& aProtoBinding)
|
||||
{
|
||||
MOZ_ASSERT(aBoundElement->IsElement());
|
||||
NS_PRECONDITION(IsCompiled(), "Can't execute uncompiled method");
|
||||
@@ -300,8 +301,9 @@ nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement)
|
||||
true);
|
||||
JSContext* cx = aes.cx();
|
||||
JS::AutoObjectVector scopeChain(cx);
|
||||
if (!nsJSUtils::GetScopeChainForElement(cx, aBoundElement->AsElement(),
|
||||
scopeChain)) {
|
||||
if (!nsJSUtils::GetScopeChainForXBL(cx, aBoundElement->AsElement(),
|
||||
aProtoBinding,
|
||||
scopeChain)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
MOZ_ASSERT(scopeChain.length() != 0);
|
||||
|
||||
@@ -138,7 +138,7 @@ public:
|
||||
nsXBLProtoImplMethod(aName)
|
||||
{}
|
||||
|
||||
nsresult Execute(nsIContent* aBoundElement);
|
||||
nsresult Execute(nsIContent* aBoundElement, const nsXBLPrototypeBinding&);
|
||||
|
||||
// Override InstallMember; these methods never get installed as members on
|
||||
// binding instantiations (though they may hang out in mMembers on the
|
||||
|
||||
@@ -120,6 +120,7 @@ nsXBLPrototypeBinding::nsXBLPrototypeBinding()
|
||||
mKeyHandlersRegistered(false),
|
||||
mChromeOnlyContent(false),
|
||||
mBindToUntrustedContent(false),
|
||||
mSimpleScopeChain(false),
|
||||
mResources(nullptr),
|
||||
mBaseNameSpaceID(kNameSpaceID_None)
|
||||
{
|
||||
@@ -242,6 +243,11 @@ nsXBLPrototypeBinding::SetBindingElement(Element* aElement)
|
||||
mBindToUntrustedContent = mBinding->AttrValueIs(kNameSpaceID_None,
|
||||
nsGkAtoms::bindToUntrustedContent,
|
||||
nsGkAtoms::_true, eCaseMatters);
|
||||
|
||||
// TODO(emilio): Should we imply mBindToUntrustedContent -> mSimpleScopeChain?
|
||||
mSimpleScopeChain = mBinding->AttrValueIs(kNameSpaceID_None,
|
||||
nsGkAtoms::simpleScopeChain,
|
||||
nsGkAtoms::_true, eCaseMatters);
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -282,7 +288,7 @@ nsXBLPrototypeBinding::BindingAttached(nsIContent* aBoundElement)
|
||||
{
|
||||
if (mImplementation && mImplementation->CompiledMembers() &&
|
||||
mImplementation->mConstructor)
|
||||
return mImplementation->mConstructor->Execute(aBoundElement);
|
||||
return mImplementation->mConstructor->Execute(aBoundElement, *this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -291,7 +297,7 @@ nsXBLPrototypeBinding::BindingDetached(nsIContent* aBoundElement)
|
||||
{
|
||||
if (mImplementation && mImplementation->CompiledMembers() &&
|
||||
mImplementation->mDestructor)
|
||||
return mImplementation->mDestructor->Execute(aBoundElement);
|
||||
return mImplementation->mDestructor->Execute(aBoundElement, *this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -854,6 +860,8 @@ nsXBLPrototypeBinding::Read(nsIObjectInputStream* aStream,
|
||||
(aFlags & XBLBinding_Serialize_ChromeOnlyContent) ? true : false;
|
||||
mBindToUntrustedContent =
|
||||
(aFlags & XBLBinding_Serialize_BindToUntrustedContent) ? true : false;
|
||||
mSimpleScopeChain =
|
||||
(aFlags & XBLBinding_Serialize_SimpleScopeChain) ? true : false;
|
||||
|
||||
// nsXBLContentSink::ConstructBinding doesn't create a binding with an empty
|
||||
// id, so we don't here either.
|
||||
@@ -1077,6 +1085,10 @@ nsXBLPrototypeBinding::Write(nsIObjectOutputStream* aStream)
|
||||
flags |= XBLBinding_Serialize_BindToUntrustedContent;
|
||||
}
|
||||
|
||||
if (mSimpleScopeChain) {
|
||||
flags |= XBLBinding_Serialize_SimpleScopeChain;
|
||||
}
|
||||
|
||||
nsresult rv = aStream->Write8(flags);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
||||
@@ -293,8 +293,9 @@ public:
|
||||
nsIContent* aCopyRoot,
|
||||
mozilla::dom::Element* aTemplChild);
|
||||
|
||||
bool ChromeOnlyContent() { return mChromeOnlyContent; }
|
||||
bool BindToUntrustedContent() { return mBindToUntrustedContent; }
|
||||
bool ChromeOnlyContent() const { return mChromeOnlyContent; }
|
||||
bool SimpleScopeChain() const { return mSimpleScopeChain; }
|
||||
bool BindToUntrustedContent() const { return mBindToUntrustedContent; }
|
||||
|
||||
typedef nsClassHashtable<nsRefPtrHashKey<nsAtom>, nsXBLAttributeEntry> InnerAttributeTable;
|
||||
|
||||
@@ -331,6 +332,9 @@ protected:
|
||||
bool mKeyHandlersRegistered;
|
||||
bool mChromeOnlyContent;
|
||||
bool mBindToUntrustedContent;
|
||||
// True if constructors, handlers, etc for this binding would skip the scope
|
||||
// chain for parent elements and go directly to the document.
|
||||
bool mSimpleScopeChain;
|
||||
|
||||
nsAutoPtr<nsXBLPrototypeResources> mResources; // If we have any resources, this will be non-null.
|
||||
|
||||
|
||||
@@ -365,7 +365,7 @@ nsXBLPrototypeHandler::ExecuteHandler(EventTarget* aTarget,
|
||||
// Build a scope chain in the XBL scope.
|
||||
RefPtr<Element> targetElement = do_QueryObject(scriptTarget);
|
||||
JS::AutoObjectVector scopeChain(cx);
|
||||
ok = nsJSUtils::GetScopeChainForElement(cx, targetElement, scopeChain);
|
||||
ok = nsJSUtils::GetScopeChainForXBL(cx, targetElement, *mPrototypeBinding, scopeChain);
|
||||
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
// Next, clone the generic handler with our desired scope chain.
|
||||
|
||||
@@ -16,19 +16,22 @@ typedef uint8_t XBLBindingSerializeDetails;
|
||||
|
||||
// A version number to ensure we don't load cached data in a different
|
||||
// file format.
|
||||
#define XBLBinding_Serialize_Version 0x00000004
|
||||
#define XBLBinding_Serialize_Version 0x00000005
|
||||
|
||||
// Set for the first binding in a document
|
||||
#define XBLBinding_Serialize_IsFirstBinding 1
|
||||
#define XBLBinding_Serialize_IsFirstBinding (1 << 0)
|
||||
|
||||
// Set to indicate that nsXBLPrototypeBinding::mInheritStyle should be true
|
||||
#define XBLBinding_Serialize_InheritStyle 2
|
||||
#define XBLBinding_Serialize_InheritStyle (1 << 1)
|
||||
|
||||
// Set to indicate that nsXBLPrototypeBinding::mChromeOnlyContent should be true
|
||||
#define XBLBinding_Serialize_ChromeOnlyContent 4
|
||||
#define XBLBinding_Serialize_ChromeOnlyContent (1 << 2)
|
||||
|
||||
// Set to indicate that nsXBLPrototypeBinding::mBindToUntrustedContent should be true
|
||||
#define XBLBinding_Serialize_BindToUntrustedContent 8
|
||||
#define XBLBinding_Serialize_BindToUntrustedContent (1 << 3)
|
||||
|
||||
// Set to indicate that nsXBLPrototypeBinding::mSimpleScopeChain should be true
|
||||
#define XBLBinding_Serialize_SimpleScopeChain (1 << 4)
|
||||
|
||||
// Appears at the end of the serialized data to indicate that no more bindings
|
||||
// are present for this document.
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
<bindings xmlns="http://www.mozilla.org/xbl"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml">
|
||||
<binding id="foo">
|
||||
<binding id="foo" simpleScopeChain="true">
|
||||
<implementation>
|
||||
<field name="bar">baz</field>
|
||||
<constructor>
|
||||
<![CDATA[
|
||||
is(document, this.ownerDocument, "Shouldn't have forms in the scope chain");
|
||||
]]>
|
||||
</constructor>
|
||||
</implementation>
|
||||
</binding>
|
||||
</bindings>
|
||||
@@ -29,6 +29,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1095660
|
||||
|
||||
</div>
|
||||
<pre id="test" style="-moz-binding: url(file_fieldScopeChain.xml#foo)">
|
||||
<form>
|
||||
<input name="document">
|
||||
<input type="text" id="input-test" style="-moz-binding: url(file_fieldScopeChain.xml#foo)">
|
||||
</form>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
@@ -16,6 +16,7 @@
|
||||
xmlns:xbl="http://www.mozilla.org/xbl">
|
||||
|
||||
<binding id="date-input"
|
||||
simpleScopeChain="true"
|
||||
extends="chrome://global/content/bindings/datetimebox.xml#datetime-input-base">
|
||||
<resources>
|
||||
<stylesheet src="chrome://global/content/textbox.css"/>
|
||||
@@ -428,6 +429,7 @@
|
||||
</binding>
|
||||
|
||||
<binding id="time-input"
|
||||
simpleScopeChain="true"
|
||||
extends="chrome://global/content/bindings/datetimebox.xml#datetime-input-base">
|
||||
<resources>
|
||||
<stylesheet src="chrome://global/content/textbox.css"/>
|
||||
@@ -1192,7 +1194,8 @@
|
||||
</implementation>
|
||||
</binding>
|
||||
|
||||
<binding id="datetime-input-base">
|
||||
<binding id="datetime-input-base"
|
||||
simpleScopeChain="true">
|
||||
<resources>
|
||||
<stylesheet src="chrome://global/content/textbox.css"/>
|
||||
<stylesheet src="chrome://global/skin/textbox.css"/>
|
||||
|
||||
@@ -1667,6 +1667,7 @@ GK_ATOM(saturation, "saturation")
|
||||
GK_ATOM(set, "set")
|
||||
GK_ATOM(seed, "seed")
|
||||
GK_ATOM(shape_rendering, "shape-rendering")
|
||||
GK_ATOM(simpleScopeChain, "simpleScopeChain")
|
||||
GK_ATOM(skewX, "skewX")
|
||||
GK_ATOM(skewY, "skewY")
|
||||
GK_ATOM(slope, "slope")
|
||||
|
||||
Reference in new issue
Block a user