Bug 1612477 - part 2: Remove nsIDocumentStateListener.NotifyDocumentCreated() r=m_kato

There is no meaningful listener of this so that we can get rid of it.

Depends on D61357

Differential Revision: https://phabricator.services.mozilla.com/D61358
This commit is contained in:
Masayuki Nakano
2020-02-04 06:19:55 +00:00
parent 8e49f158d6
commit 2336922ae0
4 changed files with 41 additions and 25 deletions

View File

@@ -2884,27 +2884,26 @@ nsINode* EditorBase::GetFirstEditableNode(nsINode* aRoot) {
nsresult EditorBase::NotifyDocumentListeners(
TDocumentListenerNotification aNotificationType) {
RefPtr<ComposerCommandsUpdater> composerCommandsUpdate =
AsHTMLEditor() ? AsHTMLEditor()->mComposerCommandsUpdater : nullptr;
if (!mDocStateListeners.Length() && !composerCommandsUpdate) {
return NS_OK;
}
AutoDocumentStateListenerArray listeners(mDocStateListeners);
switch (aNotificationType) {
case eDocumentCreated:
if (composerCommandsUpdate) {
composerCommandsUpdate->OnHTMLEditorCreated();
if (!AsHTMLEditor()) {
return NS_OK;
}
for (auto& listener : listeners) {
nsresult rv = listener->NotifyDocumentCreated();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (RefPtr<ComposerCommandsUpdater> composerCommandsUpdate =
AsHTMLEditor()->mComposerCommandsUpdater) {
composerCommandsUpdate->OnHTMLEditorCreated();
}
return NS_OK;
case eDocumentToBeDestroyed:
case eDocumentToBeDestroyed: {
RefPtr<ComposerCommandsUpdater> composerCommandsUpdate =
AsHTMLEditor() ? AsHTMLEditor()->mComposerCommandsUpdater : nullptr;
if (!mDocStateListeners.Length() && !composerCommandsUpdate) {
return NS_OK;
}
// Needs to store all listeners before notifying ComposerCommandsUpdate
// since notifying it might change mDocStateListeners.
AutoDocumentStateListenerArray listeners(mDocStateListeners);
if (composerCommandsUpdate) {
composerCommandsUpdate->OnBeforeHTMLEditorDestroyed();
}
@@ -2915,7 +2914,7 @@ nsresult EditorBase::NotifyDocumentListeners(
}
}
return NS_OK;
}
case eDocumentStateChanged: {
bool docIsDirty;
nsresult rv = GetDocumentModified(&docIsDirty);
@@ -2929,6 +2928,14 @@ nsresult EditorBase::NotifyDocumentListeners(
mDocDirtyState = docIsDirty;
RefPtr<ComposerCommandsUpdater> composerCommandsUpdate =
AsHTMLEditor() ? AsHTMLEditor()->mComposerCommandsUpdater : nullptr;
if (!mDocStateListeners.Length() && !composerCommandsUpdate) {
return NS_OK;
}
// Needs to store all listeners before notifying ComposerCommandsUpdate
// since notifying it might change mDocStateListeners.
AutoDocumentStateListenerArray listeners(mDocStateListeners);
if (composerCommandsUpdate) {
composerCommandsUpdate->OnHTMLEditorDirtyStateChanged(mDocDirtyState);
}

View File

@@ -37,9 +37,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=502673
editor.removeDocumentStateListener(this);
},
NotifyDocumentCreated() {
},
NotifyDocumentStateChanged(aNowDirty) {
var editor = SpecialPowers.wrap(this.input).editor;
editor.removeDocumentStateListener(this);
@@ -90,8 +87,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=502673
ok(true, "Multiple listeners removed themselves after " +
"NotifyDocumentWillBeDestroyed notifications - didn't crash");
// TODO: Test for NotifyDocumentCreated
SimpleTest.finish();
}
</script>

View File

@@ -5,13 +5,28 @@
#include "nsISupports.idl"
/**
* Due to the historical reason, this listener interface says "document state",
* but this listener listens to HTML editor state.
*/
[scriptable, uuid(050cdc00-3b8e-11d3-9ce4-a458f454fcbc)]
interface nsIDocumentStateListener : nsISupports
{
[can_run_script]
void NotifyDocumentCreated();
/**
* NotifyDocumentWillBeDestroyed() is called when HTML editor instance is
* being destroyed. Note that related objects may have already gone when
* this is called because that may cause destroying HTML editor.
*/
[can_run_script]
void NotifyDocumentWillBeDestroyed();
/**
* NotifyDocumentStateChanged() is called when dirty state of HTML editor
* is changed.
*
* @param aNowDirty if true, this is called when the HTML editor becomes
* dirty. Otherwise, called when it becomes not dirty.
*/
[can_run_script]
void NotifyDocumentStateChanged(in boolean nowDirty);
void NotifyDocumentStateChanged(in boolean aNowDirty);
};

View File

@@ -1999,7 +1999,6 @@ FinderHighlighter.prototype = {
},
// Unimplemented
notifyDocumentCreated() {},
notifyDocumentStateChanged(aDirty) {},
};
},