Fix for bug 388183 (Reloading this testcase causes crash [@
authorpeterv@propagandism.org
Wed, 18 Jul 2007 02:44:22 -0700
changeset 3605 8fdaaac41ead43e4a3717dadbb1a56ba63d50f2e
parent 3604 414b5814669fb4f1392fe7f0e34e14b3edec3813
child 3606 11a09cc5ce2fde68d4c327a8b8475b543699e614
push idunknown
push userunknown
push dateunknown
bugs388183
milestone1.9a7pre
Fix for bug 388183 (Reloading this testcase causes crash [@ nsHTMLDocument::ChangeContentEditableCount] with null editor). r/sr=jst.
content/html/document/src/nsHTMLDocument.cpp
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -3757,19 +3757,18 @@ nsHTMLDocument::ChangeContentEditableCou
       if (!docshell)
         return NS_ERROR_FAILURE;
 
       nsCOMPtr<nsIEditorDocShell> editorDocShell =
         do_QueryInterface(docshell, &rv);
       NS_ENSURE_SUCCESS(rv, rv);
 
       nsCOMPtr<nsIEditor> editor;
-      rv = editorDocShell->GetEditor(getter_AddRefs(editor));
-      NS_ENSURE_SUCCESS(rv, rv);
-
+      editorDocShell->GetEditor(getter_AddRefs(editor));
+      if (editor) {
       nsCOMPtr<nsIDOMRange> range;
       rv = NS_NewRange(getter_AddRefs(range));
       NS_ENSURE_SUCCESS(rv, rv);
 
       rv = range->SelectNode(node);
       NS_ENSURE_SUCCESS(rv, rv);
 
       nsCOMPtr<nsIInlineSpellChecker> spellChecker;
@@ -3778,16 +3777,17 @@ nsHTMLDocument::ChangeContentEditableCou
       NS_ENSURE_SUCCESS(rv, rv);
 
       if (spellChecker) {
         rv = spellChecker->SpellCheckRange(range);
         NS_ENSURE_SUCCESS(rv, rv);
       }
     }
   }
+  }
 
   return NS_OK;
 }
 
 static void
 NotifyEditableStateChange(nsINode *aNode, nsIDocument *aDocument,
                           PRBool aEditable)
 {
@@ -3816,34 +3816,33 @@ nsHTMLDocument::TurnEditingOff()
   if (!docshell)
     return NS_ERROR_FAILURE;
 
   nsresult rv;
   nsCOMPtr<nsIEditorDocShell> editorDocShell =
     do_QueryInterface(docshell, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIEditor> editor;
-  rv = editorDocShell->GetEditor(getter_AddRefs(editor));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   nsCOMPtr<nsIEditingSession> editSession = do_GetInterface(docshell, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // turn editing off
   rv = editSession->TearDownEditorOnWindow(window, PR_TRUE);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIEditorStyleSheets> editorss = do_QueryInterface(editor, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
+  nsCOMPtr<nsIEditor> editor;
+  editorDocShell->GetEditor(getter_AddRefs(editor));
+  nsCOMPtr<nsIEditorStyleSheets> editorss = do_QueryInterface(editor);
+  if (editorss) {
   editorss->RemoveOverrideStyleSheet(NS_LITERAL_STRING("resource:/res/contenteditable.css"));
-  if (mEditingState == eDesignMode) {
+    if (mEditingState == eDesignMode)
     editorss->RemoveOverrideStyleSheet(NS_LITERAL_STRING("resource:/res/designmode.css"));
-
+  }
+
+  if (mEditingState == eDesignMode) {
     rv = docshell->SetAllowJavascript(mScriptsEnabled);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = docshell->SetAllowPlugins(mPluginsEnabled);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   mEditingState = eOff;
@@ -3902,18 +3901,19 @@ nsHTMLDocument::EditingStateChanged()
   }
 
   // XXX Need to call TearDownEditorOnWindow for all failures.
   nsCOMPtr<nsIEditorDocShell> editorDocShell =
     do_QueryInterface(docshell, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIEditor> editor;
-  rv = editorDocShell->GetEditor(getter_AddRefs(editor));
-  NS_ENSURE_SUCCESS(rv, rv);
+  editorDocShell->GetEditor(getter_AddRefs(editor));
+  if (!editor)
+    return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsIEditorStyleSheets> editorss = do_QueryInterface(editor, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   editorss->AddOverrideStyleSheet(NS_LITERAL_STRING("resource:/res/contenteditable.css"));
 
   // Should we update the editable state of all the nodes in the document? We
   // need to do this when the designMode value changes, as that overrides