Bug 1855360 - Fix the skip-if syntax. a=bustage-fix
[gecko.git] / docshell / base / nsDSURIContentListener.h
blob61ed36456f2f044a3f293a903cee6949bc3fb407
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/. */
7 #ifndef nsDSURIContentListener_h__
8 #define nsDSURIContentListener_h__
10 #include "nsCOMPtr.h"
11 #include "nsIURIContentListener.h"
12 #include "nsWeakReference.h"
13 #include "nsITimer.h"
15 class nsDocShell;
16 class nsIInterfaceRequestor;
17 class nsIWebNavigationInfo;
18 class nsPIDOMWindowOuter;
20 // Helper Class to eventually close an already opened window
21 class MaybeCloseWindowHelper final : public nsITimerCallback, public nsINamed {
22 public:
23 NS_DECL_ISUPPORTS
24 NS_DECL_NSITIMERCALLBACK
25 NS_DECL_NSINAMED
27 explicit MaybeCloseWindowHelper(
28 mozilla::dom::BrowsingContext* aContentContext);
30 /**
31 * Closes the provided window async (if mShouldCloseWindow is true) and
32 * returns a valid browsingContext to be used instead as parent for dialogs or
33 * similar things.
34 * In case mShouldCloseWindow is true, the returned BrowsingContext will be
35 * the window's opener (or original cross-group opener in the case of a
36 * `noopener` popup).
38 mozilla::dom::BrowsingContext* MaybeCloseWindow();
40 void SetShouldCloseWindow(bool aShouldCloseWindow);
42 protected:
43 ~MaybeCloseWindowHelper();
45 private:
46 already_AddRefed<mozilla::dom::BrowsingContext> ChooseNewBrowsingContext(
47 mozilla::dom::BrowsingContext* aBC);
49 /**
50 * The dom window associated to handle content.
52 RefPtr<mozilla::dom::BrowsingContext> mBrowsingContext;
54 /**
55 * Used to close the window on a timer, to avoid any exceptions that are
56 * thrown if we try to close the window before it's fully loaded.
58 RefPtr<mozilla::dom::BrowsingContext> mBCToClose;
59 nsCOMPtr<nsITimer> mTimer;
61 /**
62 * This is set based on whether the channel indicates that a new window
63 * was opened, e.g. for a download, or was blocked. If so, then we
64 * close it.
66 bool mShouldCloseWindow;
69 class nsDSURIContentListener final : public nsIURIContentListener,
70 public nsSupportsWeakReference {
71 friend class nsDocShell;
73 public:
74 NS_DECL_THREADSAFE_ISUPPORTS
75 NS_DECL_NSIURICONTENTLISTENER
77 protected:
78 explicit nsDSURIContentListener(nsDocShell* aDocShell);
79 virtual ~nsDSURIContentListener();
81 void DropDocShellReference() {
82 mDocShell = nullptr;
83 mExistingJPEGRequest = nullptr;
84 mExistingJPEGStreamListener = nullptr;
87 protected:
88 nsDocShell* mDocShell;
89 // Hack to handle multipart images without creating a new viewer
90 nsCOMPtr<nsIStreamListener> mExistingJPEGStreamListener;
91 nsCOMPtr<nsIChannel> mExistingJPEGRequest;
93 // Store the parent listener in either of these depending on
94 // if supports weak references or not. Proper weak refs are
95 // preferred and encouraged!
96 nsWeakPtr mWeakParentContentListener;
97 nsIURIContentListener* mParentContentListener;
100 #endif /* nsDSURIContentListener_h__ */