nsWebBrowser.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsWebBrowser_h__
  6. #define nsWebBrowser_h__
  7. // Local Includes
  8. #include "nsDocShellTreeOwner.h"
  9. // Core Includes
  10. #include "nsAutoPtr.h"
  11. #include "nsCOMPtr.h"
  12. // Interfaces needed
  13. #include "nsCWebBrowser.h"
  14. #include "nsIBaseWindow.h"
  15. #include "nsIDocShell.h"
  16. #include "nsIDocShellTreeItem.h"
  17. #include "nsIInterfaceRequestor.h"
  18. #include "nsIInterfaceRequestorUtils.h"
  19. #include "nsIScrollable.h"
  20. #include "nsISHistory.h"
  21. #include "nsITextScroll.h"
  22. #include "nsIWidget.h"
  23. #include "nsIWebProgress.h"
  24. #include "nsISecureBrowserUI.h"
  25. #include "nsIWebBrowser.h"
  26. #include "nsIWebNavigation.h"
  27. #include "nsIWebBrowserSetup.h"
  28. #include "nsIWebBrowserPersist.h"
  29. #include "nsIWebBrowserFocus.h"
  30. #include "nsIWebBrowserStream.h"
  31. #include "nsIWindowWatcher.h"
  32. #include "nsIPrintSettings.h"
  33. #include "nsEmbedStream.h"
  34. #include "nsIWidgetListener.h"
  35. #include "mozilla/BasePrincipal.h"
  36. #include "nsTArray.h"
  37. #include "nsWeakPtr.h"
  38. class nsWebBrowserInitInfo
  39. {
  40. public:
  41. // nsIBaseWindow Stuff
  42. int32_t x;
  43. int32_t y;
  44. int32_t cx;
  45. int32_t cy;
  46. bool visible;
  47. nsCOMPtr<nsISHistory> sessionHistory;
  48. nsString name;
  49. };
  50. class nsWebBrowserListenerState
  51. {
  52. public:
  53. bool Equals(nsIWeakReference* aListener, const nsIID& aID)
  54. {
  55. return mWeakPtr.get() == aListener && mID.Equals(aID);
  56. }
  57. nsWeakPtr mWeakPtr;
  58. nsIID mID;
  59. };
  60. // {cda5863a-aa9c-411e-be49-ea0d525ab4b5} -
  61. #define NS_WEBBROWSER_CID \
  62. { 0xcda5863a, 0xaa9c, 0x411e, { 0xbe, 0x49, 0xea, 0x0d, 0x52, 0x5a, 0xb4, 0xb5 } }
  63. class nsWebBrowser final : public nsIWebBrowser,
  64. public nsIWebNavigation,
  65. public nsIWebBrowserSetup,
  66. public nsIDocShellTreeItem,
  67. public nsIBaseWindow,
  68. public nsIScrollable,
  69. public nsITextScroll,
  70. public nsIInterfaceRequestor,
  71. public nsIWebBrowserPersist,
  72. public nsIWebBrowserFocus,
  73. public nsIWebProgressListener,
  74. public nsIWebBrowserStream,
  75. public nsSupportsWeakReference
  76. {
  77. friend class nsDocShellTreeOwner;
  78. public:
  79. // The implementation of non-refcounted nsIWidgetListener, which would hold a
  80. // strong reference on stack before calling nsWebBrowser.
  81. class WidgetListenerDelegate : public nsIWidgetListener
  82. {
  83. public:
  84. explicit WidgetListenerDelegate(nsWebBrowser* aWebBrowser)
  85. : mWebBrowser(aWebBrowser) {}
  86. virtual bool PaintWindow(
  87. nsIWidget* aWidget, mozilla::LayoutDeviceIntRegion aRegion) override;
  88. private:
  89. // The lifetime of WidgetListenerDelegate is bound to nsWebBrowser so we
  90. // just use raw pointer here.
  91. nsWebBrowser* mWebBrowser;
  92. };
  93. nsWebBrowser();
  94. NS_DECL_ISUPPORTS
  95. NS_DECL_NSIBASEWINDOW
  96. NS_DECL_NSIDOCSHELLTREEITEM
  97. NS_DECL_NSIINTERFACEREQUESTOR
  98. NS_DECL_NSISCROLLABLE
  99. NS_DECL_NSITEXTSCROLL
  100. NS_DECL_NSIWEBBROWSER
  101. NS_DECL_NSIWEBNAVIGATION
  102. NS_DECL_NSIWEBBROWSERSETUP
  103. NS_DECL_NSIWEBBROWSERPERSIST
  104. NS_DECL_NSICANCELABLE
  105. NS_DECL_NSIWEBBROWSERFOCUS
  106. NS_DECL_NSIWEBBROWSERSTREAM
  107. NS_DECL_NSIWEBPROGRESSLISTENER
  108. protected:
  109. virtual ~nsWebBrowser();
  110. NS_IMETHOD InternalDestroy();
  111. // XXXbz why are these NS_IMETHOD? They're not interface methods!
  112. NS_IMETHOD SetDocShell(nsIDocShell* aDocShell);
  113. NS_IMETHOD EnsureDocShellTreeOwner();
  114. NS_IMETHOD BindListener(nsISupports* aListener, const nsIID& aIID);
  115. NS_IMETHOD UnBindListener(nsISupports* aListener, const nsIID& aIID);
  116. NS_IMETHOD EnableGlobalHistory(bool aEnable);
  117. // nsIWidgetListener
  118. virtual void WindowRaised(nsIWidget* aWidget);
  119. virtual void WindowLowered(nsIWidget* aWidget);
  120. bool PaintWindow(nsIWidget* aWidget, mozilla::LayoutDeviceIntRegion aRegion);
  121. protected:
  122. RefPtr<nsDocShellTreeOwner> mDocShellTreeOwner;
  123. nsCOMPtr<nsIDocShell> mDocShell;
  124. nsCOMPtr<nsIInterfaceRequestor> mDocShellAsReq;
  125. nsCOMPtr<nsIBaseWindow> mDocShellAsWin;
  126. nsCOMPtr<nsIWebNavigation> mDocShellAsNav;
  127. nsCOMPtr<nsIScrollable> mDocShellAsScrollable;
  128. nsCOMPtr<nsITextScroll> mDocShellAsTextScroll;
  129. mozilla::DocShellOriginAttributes mOriginAttributes;
  130. nsCOMPtr<nsIWidget> mInternalWidget;
  131. nsCOMPtr<nsIWindowWatcher> mWWatch;
  132. nsAutoPtr<nsWebBrowserInitInfo> mInitInfo;
  133. uint32_t mContentType;
  134. bool mActivating;
  135. bool mShouldEnableHistory;
  136. bool mIsActive;
  137. nativeWindow mParentNativeWindow;
  138. nsIWebProgressListener* mProgressListener;
  139. nsCOMPtr<nsIWebProgress> mWebProgress;
  140. nsCOMPtr<nsIPrintSettings> mPrintSettings;
  141. WidgetListenerDelegate mWidgetListenerDelegate;
  142. // cached background color
  143. nscolor mBackgroundColor;
  144. // persistence object
  145. nsCOMPtr<nsIWebBrowserPersist> mPersist;
  146. uint32_t mPersistCurrentState;
  147. nsresult mPersistResult;
  148. uint32_t mPersistFlags;
  149. // stream
  150. RefPtr<nsEmbedStream> mStream;
  151. // Weak Reference interfaces...
  152. nsIWidget* mParentWidget;
  153. nsAutoPtr<nsTArray<nsWebBrowserListenerState> > mListenerArray;
  154. };
  155. #endif /* nsWebBrowser_h__ */