Bug 825924 Input events which are dispatched by editor should be trusted always r=smaug+ehsan

This commit is contained in:
Masayuki Nakano 2013-01-12 10:49:29 +09:00
parent cd9ce5e64f
commit 6a5e7ea70a
5 changed files with 5 additions and 77 deletions

View File

@ -142,7 +142,6 @@ nsEditor::nsEditor()
, mUpdateCount(0)
, mPlaceHolderBatch(0)
, mAction(EditAction::none)
, mHandlingActionCount(0)
, mIMETextOffset(0)
, mIMEBufferLength(0)
, mDirection(eNone)
@ -153,7 +152,6 @@ nsEditor::nsEditor()
, mShouldTxnSetSelection(true)
, mDidPreDestroy(false)
, mDidPostCreate(false)
, mHandlingTrustedAction(false)
, mDispatchInputEvent(true)
{
}
@ -1817,9 +1815,8 @@ class EditorInputEventDispatcher : public nsRunnable
{
public:
EditorInputEventDispatcher(nsEditor* aEditor,
bool aIsTrusted,
nsIContent* aTarget) :
mEditor(aEditor), mTarget(aTarget), mIsTrusted(aIsTrusted)
mEditor(aEditor), mTarget(aTarget)
{
}
@ -1837,7 +1834,9 @@ public:
return NS_OK;
}
nsEvent inputEvent(mIsTrusted, NS_FORM_INPUT);
// Even if the change is caused by untrusted event, we need to dispatch
// trusted input event since it's a fact.
nsEvent inputEvent(true, NS_FORM_INPUT);
inputEvent.mFlags.mCancelable = false;
inputEvent.time = static_cast<uint64_t>(PR_Now() / 1000);
nsEventStatus status = nsEventStatus_eIgnore;
@ -1850,7 +1849,6 @@ public:
private:
nsRefPtr<nsEditor> mEditor;
nsCOMPtr<nsIContent> mTarget;
bool mIsTrusted;
};
void nsEditor::NotifyEditorObservers(void)
@ -1872,7 +1870,7 @@ void nsEditor::NotifyEditorObservers(void)
NS_ENSURE_TRUE_VOID(target);
nsContentUtils::AddScriptRunner(
new EditorInputEventDispatcher(this, mHandlingTrustedAction, target));
new EditorInputEventDispatcher(this, target));
}
NS_IMETHODIMP
@ -5308,13 +5306,3 @@ nsEditor::SetSuppressDispatchingInputEvent(bool aSuppress)
mDispatchInputEvent = !aSuppress;
return NS_OK;
}
nsEditor::HandlingTrustedAction::HandlingTrustedAction(nsEditor* aSelf,
nsIDOMEvent* aEvent)
{
MOZ_ASSERT(aEvent);
bool isTrusted = false;
aEvent->GetIsTrusted(&isTrusted);
Init(aSelf, isTrusted);
}

View File

@ -791,45 +791,6 @@ public:
virtual already_AddRefed<nsIDOMNode> FindUserSelectAllNode(nsIDOMNode* aNode) { return nullptr; }
NS_STACK_CLASS class HandlingTrustedAction
{
public:
explicit HandlingTrustedAction(nsEditor* aSelf, bool aIsTrusted = true)
{
Init(aSelf, aIsTrusted);
}
HandlingTrustedAction(nsEditor* aSelf, nsIDOMEvent* aEvent);
~HandlingTrustedAction()
{
mEditor->mHandlingTrustedAction = mWasHandlingTrustedAction;
mEditor->mHandlingActionCount--;
}
private:
nsRefPtr<nsEditor> mEditor;
bool mWasHandlingTrustedAction;
void Init(nsEditor* aSelf, bool aIsTrusted)
{
MOZ_ASSERT(aSelf);
mEditor = aSelf;
mWasHandlingTrustedAction = aSelf->mHandlingTrustedAction;
if (aIsTrusted) {
// If action is nested and the outer event is not trusted,
// we shouldn't override it.
if (aSelf->mHandlingActionCount == 0) {
aSelf->mHandlingTrustedAction = true;
}
} else {
aSelf->mHandlingTrustedAction = false;
}
aSelf->mHandlingActionCount++;
}
};
protected:
enum Tristate {
eTriUnset,
@ -869,7 +830,6 @@ protected:
int32_t mPlaceHolderBatch; // nesting count for batching
EditAction mAction; // the current editor action
uint32_t mHandlingActionCount;
uint32_t mIMETextOffset; // offset in text node where IME comp string begins
uint32_t mIMEBufferLength; // current length of IME comp string
@ -885,7 +845,6 @@ protected:
bool mShouldTxnSetSelection; // turn off for conservative selection adjustment by txns
bool mDidPreDestroy; // whether PreDestroy has been called
bool mDidPostCreate; // whether PostCreate has been called
bool mHandlingTrustedAction;
bool mDispatchInputEvent;
friend bool NSCanUnload(nsISupports* serviceMgr);

View File

@ -431,9 +431,6 @@ nsEditorEventListener::KeyPress(nsIDOMEvent* aKeyEvent)
return NS_OK;
}
// Transfer the event's trusted-ness to our editor
nsEditor::HandlingTrustedAction operation(mEditor, aKeyEvent);
// DOM event handling happens in two passes, the client pass and the system
// pass. We do all of our processing in the system pass, to allow client
// handlers the opportunity to cancel events and prevent typing in the editor.
@ -585,9 +582,6 @@ nsEditorEventListener::HandleText(nsIDOMEvent* aTextEvent)
return NS_OK;
}
// Transfer the event's trusted-ness to our editor
nsEditor::HandlingTrustedAction operation(mEditor, aTextEvent);
return mEditor->UpdateIMEComposition(composedText, textRangeList);
}
@ -826,9 +820,6 @@ nsEditorEventListener::HandleEndComposition(nsIDOMEvent* aCompositionEvent)
return;
}
// Transfer the event's trusted-ness to our editor
nsEditor::HandlingTrustedAction operation(mEditor, aCompositionEvent);
mEditor->EndIMEComposition();
}

View File

@ -104,8 +104,6 @@ NS_IMETHODIMP nsPlaintextEditor::InsertTextFromTransferable(nsITransferable *aTr
int32_t aDestOffset,
bool aDoDeleteSelection)
{
HandlingTrustedAction trusted(this);
nsresult rv = NS_OK;
char* bestFlavor = nullptr;
nsCOMPtr<nsISupports> genericDataObj;

View File

@ -640,8 +640,6 @@ nsPlaintextEditor::DeleteSelection(EDirection aAction,
nsresult result;
HandlingTrustedAction trusted(this, aAction != eNone);
// delete placeholder txns merge.
nsAutoPlaceHolderBatch batch(this, nsGkAtoms::DeleteTxnName);
nsAutoRules beginRulesSniffing(this, EditAction::deleteSelection, aAction);
@ -1080,8 +1078,6 @@ nsPlaintextEditor::Undo(uint32_t aCount)
// Protect the edit rules object from dying
nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
HandlingTrustedAction trusted(this);
nsAutoUpdateViewBatch beginViewBatching(this);
ForceCompositionEnd();
@ -1109,8 +1105,6 @@ nsPlaintextEditor::Redo(uint32_t aCount)
// Protect the edit rules object from dying
nsCOMPtr<nsIEditRules> kungFuDeathGrip(mRules);
HandlingTrustedAction trusted(this);
nsAutoUpdateViewBatch beginViewBatching(this);
ForceCompositionEnd();
@ -1165,8 +1159,6 @@ nsPlaintextEditor::FireClipboardEvent(int32_t aType)
NS_IMETHODIMP nsPlaintextEditor::Cut()
{
HandlingTrustedAction trusted(this);
if (FireClipboardEvent(NS_CUT))
return DeleteSelection(eNone, eStrip);
return NS_OK;