Bug 1449631 part 4. Remove nsIDOMEventTarget::GetContextForEventHandlers. r=smaug

MozReview-Commit-ID: ID0FDvp28HY
This commit is contained in:
Boris Zbarsky
2018-04-05 13:42:40 -04:00
parent bc6b1d8797
commit 1dba91f571
10 changed files with 10 additions and 101 deletions

View File

@@ -6058,35 +6058,6 @@ nsContentUtils::URIIsLocalFile(nsIURI *aURI)
isFile;
}
/* static */
nsIScriptContext*
nsContentUtils::GetContextForEventHandlers(nsINode* aNode,
nsresult* aRv)
{
*aRv = NS_OK;
bool hasHadScriptObject = true;
nsIScriptGlobalObject* sgo =
aNode->OwnerDoc()->GetScriptHandlingObject(hasHadScriptObject);
// It is bad if the document doesn't have event handling context,
// but it used to have one.
if (!sgo && hasHadScriptObject) {
*aRv = NS_ERROR_UNEXPECTED;
return nullptr;
}
if (sgo) {
nsIScriptContext* scx = sgo->GetContext();
// Bad, no context from script global object!
if (!scx) {
*aRv = NS_ERROR_UNEXPECTED;
return nullptr;
}
return scx;
}
return nullptr;
}
/* static */
JSContext *
nsContentUtils::GetCurrentJSContext()

View File

@@ -1990,6 +1990,8 @@ public:
* run anything else, when this function returns false, but this is ok.
*/
static bool IsSafeToRunScript() {
MOZ_ASSERT(NS_IsMainThread(),
"This static variable only makes sense on the main thread!");
return sScriptBlockerCount == 0;
}
@@ -2044,9 +2046,6 @@ public:
static nsresult ProcessViewportInfo(nsIDocument *aDocument,
const nsAString &viewportInfo);
static nsIScriptContext* GetContextForEventHandlers(nsINode* aNode,
nsresult* aRv);
static JSContext *GetCurrentJSContext();
static JSContext *GetCurrentJSContextForThread();

View File

@@ -4588,13 +4588,6 @@ nsGlobalWindowInner::GetExistingListenerManager() const
return mListenerManager;
}
nsIScriptContext*
nsGlobalWindowInner::GetContextForEventHandlers(nsresult* aRv)
{
*aRv = NS_ERROR_UNEXPECTED;
FORWARD_TO_OUTER(GetContextForEventHandlers, (aRv), nullptr);
}
//*****************************************************************************
// nsGlobalWindowInner::nsPIDOMWindow
//*****************************************************************************

View File

@@ -6547,19 +6547,6 @@ nsGlobalWindowOuter::GetExistingListenerManager() const
FORWARD_TO_INNER(GetExistingListenerManager, (), nullptr);
}
nsIScriptContext*
nsGlobalWindowOuter::GetContextForEventHandlers(nsresult* aRv)
{
*aRv = NS_ERROR_UNEXPECTED;
nsIScriptContext* scx;
if ((scx = GetContext())) {
*aRv = NS_OK;
return scx;
}
return nullptr;
}
//*****************************************************************************
// nsGlobalWindowOuter::nsPIDOMWindow
//*****************************************************************************

View File

@@ -1180,12 +1180,6 @@ nsINode::GetExistingListenerManager() const
return nsContentUtils::GetExistingListenerManagerForNode(this);
}
nsIScriptContext*
nsINode::GetContextForEventHandlers(nsresult* aRv)
{
return nsContentUtils::GetContextForEventHandlers(this, aRv);
}
nsPIDOMWindowOuter*
nsINode::GetOwnerGlobalForBindings()
{

View File

@@ -149,13 +149,6 @@ nsWindowRoot::GetExistingListenerManager() const
return mListenerManager;
}
nsIScriptContext*
nsWindowRoot::GetContextForEventHandlers(nsresult* aRv)
{
*aRv = NS_OK;
return nullptr;
}
nsresult
nsWindowRoot::GetEventTargetParent(EventChainPreVisitor& aVisitor)
{

View File

@@ -305,18 +305,6 @@ DOMEventTargetHelper::GetExistingListenerManager() const
return mListenerManager;
}
nsIScriptContext*
DOMEventTargetHelper::GetContextForEventHandlers(nsresult* aRv)
{
*aRv = CheckInnerWindowCorrectness();
if (NS_FAILED(*aRv)) {
return nullptr;
}
nsPIDOMWindowInner* owner = GetOwner();
return owner ? nsGlobalWindowInner::Cast(owner)->GetContextInternal()
: nullptr;
}
nsresult
DOMEventTargetHelper::WantsUntrusted(bool* aRetVal)
{

View File

@@ -548,12 +548,7 @@ DataTransferItem::Data(nsIPrincipal* aPrincipal, ErrorResult& aRv)
if (NS_SUCCEEDED(rv) && data) {
nsCOMPtr<EventTarget> pt = do_QueryInterface(data);
if (pt) {
nsIScriptContext* c = pt->GetContextForEventHandlers(&rv);
if (NS_WARN_IF(NS_FAILED(rv) || !c)) {
return nullptr;
}
nsIGlobalObject* go = c->GetGlobalObject();
nsIGlobalObject* go = pt->GetOwnerGlobal();
if (NS_WARN_IF(!go)) {
return nullptr;
}

View File

@@ -745,17 +745,14 @@ EventDispatcher::Dispatch(nsISupports* aTarget,
}
#ifdef DEBUG
if (aEvent->mMessage != eVoidEvent &&
if (NS_IsMainThread() &&
aEvent->mMessage != eVoidEvent &&
!nsContentUtils::IsSafeToRunScript()) {
nsresult rv = NS_ERROR_FAILURE;
if (target->GetContextForEventHandlers(&rv) ||
NS_FAILED(rv)) {
nsCOMPtr<nsINode> node = do_QueryInterface(target);
if (node && nsContentUtils::IsChromeDoc(node->OwnerDoc())) {
NS_WARNING("Fix the caller!");
} else {
NS_ERROR("This is unsafe! Fix the caller!");
}
nsCOMPtr<nsINode> node = do_QueryInterface(target);
if (node && nsContentUtils::IsChromeDoc(node->OwnerDoc())) {
NS_WARNING("Fix the caller!");
} else {
NS_ERROR("This is unsafe! Fix the caller!");
}
}

View File

@@ -223,14 +223,6 @@ interface nsIDOMEventTarget : nsISupports
*/
[noscript, nostdcall]
void PostHandleEvent(in EventChainPostVisitorRef aVisitor);
/**
* Get the script context in which the event handlers should be run.
* May return null.
* @note Caller *must* check the value of aRv.
*/
[notxpcom, nostdcall]
nsIScriptContext GetContextForEventHandlers(out nsresult aRv);
};
%{C++