Bug 1387406 - part2: nsIDocShell should have GetHTMLEditor() and SetHTMLEditor() r?smaug
C++ code should be accessible to editor of nsDocShell. However, nsIDocShell needs to have the methods. Therefore, this patch assumes that nsDocShell is the only subclass of nsIDocShell and creates 2 inline methods to access nsDocShell methods.
MozReview-Commit-ID: ByXtTB5X4cB
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -13147,46 +13147,51 @@ nsDocShell::ShouldDiscardLayoutState(nsI
Unused << aChannel->IsNoStoreResponse(&noStore);
return noStore;
}
NS_IMETHODIMP
nsDocShell::GetEditor(nsIEditor** aEditor)
{
NS_ENSURE_ARG_POINTER(aEditor);
-
- if (!mEditorData) {
- *aEditor = nullptr;
- return NS_OK;
- }
-
- RefPtr<HTMLEditor> htmlEditor = mEditorData->GetHTMLEditor();
+ RefPtr<HTMLEditor> htmlEditor = GetHTMLEditorInternal();
htmlEditor.forget(aEditor);
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::SetEditor(nsIEditor* aEditor)
{
- if (!aEditor && !mEditorData) {
- return NS_OK;
- }
-
HTMLEditor* htmlEditor = aEditor ? aEditor->AsHTMLEditor() : nullptr;
// If TextEditor comes, throw an error.
if (aEditor && !htmlEditor) {
return NS_ERROR_INVALID_ARG;
}
+ return SetHTMLEditorInternal(htmlEditor);
+}
+
+HTMLEditor*
+nsDocShell::GetHTMLEditorInternal()
+{
+ return mEditorData ? mEditorData->GetHTMLEditor() : nullptr;
+}
+
+nsresult
+nsDocShell::SetHTMLEditorInternal(HTMLEditor* aHTMLEditor)
+{
+ if (!aHTMLEditor && !mEditorData) {
+ return NS_OK;
+ }
nsresult rv = EnsureEditorData();
if (NS_FAILED(rv)) {
return rv;
}
- return mEditorData->SetHTMLEditor(htmlEditor);
+ return mEditorData->SetHTMLEditor(aHTMLEditor);
}
NS_IMETHODIMP
nsDocShell::GetEditable(bool* aEditable)
{
NS_ENSURE_ARG_POINTER(aEditable);
*aEditable = mEditorData && mEditorData->GetEditable();
return NS_OK;
@@ -15063,8 +15068,22 @@ nsDocShell::GetAwaitingLargeAlloc(bool*
return NS_OK;
}
NS_IMETHODIMP_(void)
nsDocShell::GetOriginAttributes(mozilla::OriginAttributes& aAttrs)
{
aAttrs = mOriginAttributes;
}
+
+HTMLEditor*
+nsIDocShell::GetHTMLEditor()
+{
+ nsDocShell* docShell = static_cast<nsDocShell*>(this);
+ return docShell->GetHTMLEditorInternal();
+}
+
+nsresult
+nsIDocShell::SetHTMLEditor(HTMLEditor* aHTMLEditor)
+{
+ nsDocShell* docShell = static_cast<nsDocShell*>(this);
+ return docShell->SetHTMLEditorInternal(aHTMLEditor);
+}
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -59,16 +59,17 @@
#include "nsCRT.h"
#include "prtime.h"
#include "nsRect.h"
#include "Units.h"
#include "nsIDeprecationWarner.h"
namespace mozilla {
class Encoding;
+class HTMLEditor;
enum class TaskCategory;
namespace dom {
class EventTarget;
class PendingGlobalHistoryEntry;
typedef uint32_t ScreenOrientationInternal;
} // namespace dom
} // namespace mozilla
@@ -279,16 +280,19 @@ public:
void SetInFrameSwap(bool aInSwap)
{
mInFrameSwap = aInSwap;
}
bool InFrameSwap();
const Encoding* GetForcedCharset() { return mForcedCharset; }
+ mozilla::HTMLEditor* GetHTMLEditorInternal();
+ nsresult SetHTMLEditorInternal(mozilla::HTMLEditor* aHTMLEditor);
+
private:
bool CanSetOriginAttributes();
public:
const mozilla::OriginAttributes&
GetOriginAttributes()
{
return mOriginAttributes;
--- a/docshell/base/nsIDocShell.idl
+++ b/docshell/base/nsIDocShell.idl
@@ -11,16 +11,17 @@
%{ C++
#include "js/TypeDecls.h"
#include "mozilla/Maybe.h"
#include "mozilla/NotNull.h"
class nsPresContext;
class nsIPresShell;
namespace mozilla {
class Encoding;
+class HTMLEditor;
}
%}
/**
* The nsIDocShell interface.
*/
[ptr] native nsPresContext(nsPresContext);
@@ -1149,9 +1150,18 @@ interface nsIDocShell : nsIDocShellTreeI
* Attribute that determines whether tracking protection is enabled.
*/
attribute boolean useTrackingProtection;
/**
* Fire a dummy location change event asynchronously.
*/
[noscript] void dispatchLocationChangeEvent();
+
+%{C++
+ /**
+ * These methods call nsDocShell::GetHTMLEditorInternal() and
+ * nsDocShell::SetHTMLEditorInternal() with static_cast.
+ */
+ mozilla::HTMLEditor* GetHTMLEditor();
+ nsresult SetHTMLEditor(mozilla::HTMLEditor* aHTMLEditor);
+%}
};