1 /* -*- Mode: C++; tab-width: 2; 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 
6 #ifndef nsWebShellWindow_h__
7 #define nsWebShellWindow_h__
8 
9 #include "mozilla/Mutex.h"
10 #include "nsIWebProgressListener.h"
11 #include "nsITimer.h"
12 #include "nsCOMPtr.h"
13 #include "nsXULWindow.h"
14 #include "nsIWidgetListener.h"
15 #include "nsITabParent.h"
16 
17 /* Forward declarations.... */
18 class nsIURI;
19 
20 struct nsWidgetInitData;
21 
22 namespace mozilla {
23 class WebShellWindowTimerCallback;
24 } // namespace mozilla
25 
26 class nsWebShellWindow final : public nsXULWindow,
27                                public nsIWebProgressListener
28 {
29 public:
30 
31   // The implementation of non-refcounted nsIWidgetListener, which would hold a
32   // strong reference on stack before calling nsWebShellWindow
33   class WidgetListenerDelegate : public nsIWidgetListener
34   {
35   public:
WidgetListenerDelegate(nsWebShellWindow * aWebShellWindow)36     explicit WidgetListenerDelegate(nsWebShellWindow* aWebShellWindow)
37       : mWebShellWindow(aWebShellWindow) {}
38 
39     virtual nsIXULWindow* GetXULWindow() override;
40     virtual nsIPresShell* GetPresShell() override;
41     virtual bool WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y) override;
42     virtual bool WindowResized(nsIWidget* aWidget, int32_t aWidth, int32_t aHeight) override;
43     virtual bool RequestWindowClose(nsIWidget* aWidget) override;
44     virtual void SizeModeChanged(nsSizeMode sizeMode) override;
45     virtual void UIResolutionChanged() override;
46     virtual void FullscreenChanged(bool aInFullscreen) override;
47     virtual void OSToolbarButtonPressed() override;
48     virtual bool ZLevelChanged(bool aImmediate,
49                                nsWindowZ *aPlacement,
50                                nsIWidget* aRequestBelow,
51                                nsIWidget** aActualBelow) override;
52     virtual void WindowActivated() override;
53     virtual void WindowDeactivated() override;
54 
55   private:
56     // The lifetime of WidgetListenerDelegate is bound to nsWebShellWindow so
57     // we just use a raw pointer here.
58     nsWebShellWindow* mWebShellWindow;
59   };
60 
61   explicit nsWebShellWindow(uint32_t aChromeFlags);
62 
63   // nsISupports interface...
64   NS_DECL_ISUPPORTS_INHERITED
65 
66   // nsWebShellWindow methods...
67   nsresult Initialize(nsIXULWindow * aParent, nsIXULWindow * aOpener,
68                       nsIURI* aUrl,
69                       int32_t aInitialWidth, int32_t aInitialHeight,
70                       bool aIsHiddenWindow,
71                       nsITabParent *aOpeningTab,
72                       mozIDOMWindowProxy *aOpenerWIndow,
73                       nsWidgetInitData& widgetInitData);
74 
75   nsresult Toolbar();
76 
77   // nsIWebProgressListener
78   NS_DECL_NSIWEBPROGRESSLISTENER
79 
80   // nsIBaseWindow
81   NS_IMETHOD Destroy() override;
82 
83   // nsIWidgetListener
GetXULWindow()84   nsIXULWindow* GetXULWindow() { return this; }
85   nsIPresShell* GetPresShell();
86   bool WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y);
87   bool WindowResized(nsIWidget* aWidget, int32_t aWidth, int32_t aHeight);
88   bool RequestWindowClose(nsIWidget* aWidget);
89   void SizeModeChanged(nsSizeMode sizeMode);
90   void UIResolutionChanged();
91   void FullscreenChanged(bool aInFullscreen);
92   void OSToolbarButtonPressed();
93   bool ZLevelChanged(bool aImmediate, nsWindowZ *aPlacement,
94                      nsIWidget* aRequestBelow, nsIWidget** aActualBelow);
95   void WindowActivated();
96   void WindowDeactivated();
97 
98 protected:
99   friend class mozilla::WebShellWindowTimerCallback;
100 
101   virtual ~nsWebShellWindow();
102 
103   void                     LoadContentAreas();
104   bool                     ExecuteCloseHandler();
105   void                     ConstrainToOpenerScreen(int32_t* aX, int32_t* aY);
106 
107   nsCOMPtr<nsITimer>      mSPTimer;
108   mozilla::Mutex          mSPTimerLock;
109   WidgetListenerDelegate  mWidgetListenerDelegate;
110 
111   void        SetPersistenceTimer(uint32_t aDirtyFlags);
112   void        FirePersistenceTimer();
113 };
114 
115 
116 #endif /* nsWebShellWindow_h__ */
117