Fix for
bug 388183 (Reloading this testcase causes crash [@
nsHTMLDocument::ChangeContentEditableCount] with null editor). r/sr=jst.
--- 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