Bug 1388001 - part1: Create nsIEditingSession::GetHTMLEditorForWindow() r?smaug
Some users of HTMLEditor retrieve pointer to editors with nsIEditingSession::GetEditorForWindow() but it returns nsIEditor. So, there should be a method which returns HTMLEditor*.
MozReview-Commit-ID: Bzc1LIlTSDF
--- a/editor/composer/nsEditingSession.cpp
+++ b/editor/composer/nsEditingSession.cpp
@@ -591,21 +591,22 @@ nsEditingSession::TearDownEditorOnWindow
GetEditorForFrame
nsIEditor getEditorForFrame (in nsIDOMWindow aWindow);
----------------------------------------------------------------------------*/
NS_IMETHODIMP
nsEditingSession::GetEditorForWindow(mozIDOMWindowProxy* aWindow,
nsIEditor **outEditor)
{
- NS_ENSURE_STATE(aWindow);
- nsCOMPtr<nsIDocShell> docShell = nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
- NS_ENSURE_STATE(docShell);
-
- return docShell->GetEditor(outEditor);
+ if (NS_WARN_IF(!aWindow)) {
+ return NS_ERROR_INVALID_ARG;
+ }
+ nsCOMPtr<nsIEditor> editor = GetHTMLEditorForWindow(aWindow);
+ editor.forget(outEditor);
+ return NS_OK;
}
/*---------------------------------------------------------------------------
OnStateChange
----------------------------------------------------------------------------*/
NS_IMETHODIMP
@@ -1389,8 +1390,24 @@ nsEditingSession::ReattachToWindow(mozID
rv = WindowIsEditable(aWindow, &isEditable);
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(isEditable, "Window is not editable after reattaching editor.");
}
#endif // DEBUG
return NS_OK;
}
+
+HTMLEditor*
+nsIEditingSession::GetHTMLEditorForWindow(mozIDOMWindowProxy* aWindow)
+{
+ if (NS_WARN_IF(!aWindow)) {
+ return nullptr;
+ }
+
+ nsCOMPtr<nsIDocShell> docShell =
+ nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
+ if (NS_WARN_IF(!docShell)) {
+ return nullptr;
+ }
+
+ return docShell->GetHTMLEditor();
+}
--- a/editor/composer/nsIEditingSession.idl
+++ b/editor/composer/nsIEditingSession.idl
@@ -4,16 +4,23 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
#include "domstubs.idl"
interface mozIDOMWindowProxy;
interface nsIEditor;
+%{ C++
+class mozIDOMWindowProxy;
+namespace mozilla {
+class HTMLEditor;
+} // namespace mozilla
+%}
+
[scriptable, builtinclass, uuid(24f963d1-e6fc-43ea-a206-99ac5fcc5265)]
interface nsIEditingSession : nsISupports
{
/**
* Error codes when we fail to create an editor
* is placed in attribute editorStatus
*/
@@ -95,10 +102,20 @@ interface nsIEditingSession : nsISupport
* to the window.
*/
void reattachToWindow(in mozIDOMWindowProxy aWindow);
/**
* Whether this session has disabled JS and plugins.
*/
readonly attribute boolean jsAndPluginsDisabled;
+
+%{C++
+ /**
+ * This method is implemented with nsIDocShell::GetHTMLEditor(). I.e.,
+ * This method doesn't depend on nsEditingSession. Therefore, even if
+ * there were some implementation of nsIEditingSession interface, this
+ * would be safe to use.
+ */
+ mozilla::HTMLEditor* GetHTMLEditorForWindow(mozIDOMWindowProxy* aWindow);
+%}
};