Bug 388665 Javascript interferes with STATE_EDITABLE
authorginn.chen@sun.com
Tue, 24 Jul 2007 23:24:00 -0700
changeset 3945 2faab68da25c8810270a37f65cbb46864691cda5
parent 3944 fdce96ce1525f99cd03ab153ac86a4cc0fb976bb
child 3946 5b614cfe95ff0d8dae6fafc79c4314b4aff0deb2
push idunknown
push userunknown
push dateunknown
bugs388665
milestone1.9a7pre
Bug 388665 Javascript interferes with STATE_EDITABLE r=aaronleventhal sr=bzbarsky
accessible/src/html/Makefile.in
accessible/src/html/nsHTMLFormControlAccessible.cpp
--- a/accessible/src/html/Makefile.in
+++ b/accessible/src/html/Makefile.in
@@ -49,23 +49,25 @@ LIBXUL_LIBRARY = 1
 
 REQUIRES	= content \
 		  docshell \
 		  dom \
 		  editor \
 		  gfx \
 		  imglib2 \
 		  intl \
+		  js \
 		  layout \
 		  locale \
 		  necko \
 		  string \
 		  webshell \
 		  widget \
 		  xpcom \
+		  xpconnect \
 		  $(NULL)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
 REQUIRES += editor
 endif
 
 CPPSRCS = \
   nsHTMLAreaAccessible.cpp \
--- a/accessible/src/html/nsHTMLFormControlAccessible.cpp
+++ b/accessible/src/html/nsHTMLFormControlAccessible.cpp
@@ -46,16 +46,19 @@
 #include "nsIDOMNSEditableElement.h"
 #include "nsIDOMNSHTMLButtonElement.h"
 #include "nsIDOMHTMLFormElement.h"
 #include "nsIDOMHTMLLegendElement.h"
 #include "nsIDOMHTMLTextAreaElement.h"
 #include "nsIFrame.h"
 #include "nsINameSpaceManager.h"
 #include "nsISelectionController.h"
+#include "jsapi.h"
+#include "nsIJSContextStack.h"
+#include "nsIServiceManager.h"
 #include "nsITextControlFrame.h"
 
 // --- checkbox -----
 
 nsHTMLCheckboxAccessible::nsHTMLCheckboxAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell):
 nsFormControlAccessible(aNode, aShell)
 { 
 }
@@ -551,21 +554,34 @@ void nsHTMLTextFieldAccessible::SetEdito
 
 void nsHTMLTextFieldAccessible::CheckForEditor()
 {
   nsCOMPtr<nsIDOMNSEditableElement> editableElt(do_QueryInterface(mDOMNode));
   if (!editableElt) {
     return;
   }
 
+  // nsGenericHTMLElement::GetEditor has a security check.
+  // Make sure we're not restricted by the permissions of
+  // whatever script is currently running.
+  nsCOMPtr<nsIJSContextStack> stack =
+    do_GetService("@mozilla.org/js/xpc/ContextStack;1");
+  PRBool pushed = stack && NS_SUCCEEDED(stack->Push(nsnull));
+
   nsCOMPtr<nsIEditor> editor;
   nsresult rv = editableElt->GetEditor(getter_AddRefs(editor));
   if (NS_SUCCEEDED(rv)) {
     SetEditor(editor);
   }
+
+  if (pushed) {
+    JSContext* cx;
+    stack->Pop(&cx);
+    NS_ASSERTION(!cx, "context should be null");
+  }
 }
 
 // --- groupbox  -----
 
 /*
  * The HTML for this is <fieldset> <legend>box-title</legend> form elements </fieldset> 
  */