Bug 1387406 - part2: nsIDocShell should have GetHTMLEditor() and SetHTMLEditor() r?smaug draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 04 Aug 2017 22:12:03 +0900
changeset 643905 71279f8f5269e0bd00293d88376aaa569a0564a7
parent 643904 c62283bdcd72f02ba894bded8ed9ac99baa1d2d5
child 643906 d3cbadeaf0049975e0757fd8d7688ffd6a49b11e
push id73250
push usermasayuki@d-toybox.com
push dateThu, 10 Aug 2017 07:58:50 +0000
reviewerssmaug
bugs1387406
milestone57.0a1
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
docshell/base/nsDocShell.cpp
docshell/base/nsDocShell.h
docshell/base/nsIDocShell.idl
--- 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);
+%}
 };