Coverage Report

Created: 2018-09-25 14:53

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