Bug 960866 part.5 nsEditor shouldn't allow composition and text events created by chrome JS r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 12 Feb 2014 22:02:56 +0900
changeset 168378 48191ef36ffc171afb33043a561fd627dc6b5975
parent 168377 5159f90e44eff593513507f74fc496648ced101b
child 168379 5a547a926c48757008c96ca0983289f20c40aa71
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerssmaug
bugs960866
milestone30.0a1
Bug 960866 part.5 nsEditor shouldn't allow composition and text events created by chrome JS r=smaug
editor/libeditor/base/nsEditor.cpp
--- a/editor/libeditor/base/nsEditor.cpp
+++ b/editor/libeditor/base/nsEditor.cpp
@@ -5203,16 +5203,33 @@ nsEditor::IsAcceptableInputEvent(nsIDOME
   // If this is mouse event but this editor doesn't have focus, we shouldn't
   // handle it.
   nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent);
   if (mouseEvent) {
     nsCOMPtr<nsIContent> focusedContent = GetFocusedContent();
     if (!focusedContent) {
       return false;
     }
+  } else {
+    nsAutoString eventType;
+    aEvent->GetType(eventType);
+    // If composition event or text event isn't dispatched via widget,
+    // we need to ignore them since they cannot be managed by TextComposition.
+    // E.g., the event was created by chrome JS.
+    // Note that if we allow to handle such events, editor may be confused by
+    // strange event order.
+    if (eventType.EqualsLiteral("text") ||
+        eventType.EqualsLiteral("compositionstart") ||
+        eventType.EqualsLiteral("compositionend")) {
+      WidgetGUIEvent* widgetGUIEvent =
+        aEvent->GetInternalNSEvent()->AsGUIEvent();
+      if (!widgetGUIEvent || !widgetGUIEvent->widget) {
+        return false;
+      }
+    }
   }
 
   bool isTrusted;
   nsresult rv = aEvent->GetIsTrusted(&isTrusted);
   NS_ENSURE_SUCCESS(rv, false);
   if (isTrusted) {
     return true;
   }