Bug 1606850 [wpt PR 21024] - Editorial: start using blocklist, a=testonly
[gecko.git] / docshell / base / nsDSURIContentListener.h
blobd0a3b852c2a888a8c68cb4bffd653891ce173e90
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 openend window
21 class MaybeCloseWindowHelper final : public nsITimerCallback {
22 public:
23 NS_DECL_ISUPPORTS
24 NS_DECL_NSITIMERCALLBACK
26 explicit MaybeCloseWindowHelper(
27 mozilla::dom::BrowsingContext* aContentContext);
29 /**
30 * Closes the provided window async (if mShouldCloseWindow is true)
31 * and returns its opener if the window was just opened. Otherwise
32 * returns the BrowsingContext provided in the constructor.
34 mozilla::dom::BrowsingContext* MaybeCloseWindow();
36 void SetShouldCloseWindow(bool aShouldCloseWindow);
38 protected:
39 ~MaybeCloseWindowHelper();
41 private:
42 /**
43 * The dom window associated to handle content.
45 RefPtr<mozilla::dom::BrowsingContext> mBrowsingContext;
47 /**
48 * Used to close the window on a timer, to avoid any exceptions that are
49 * thrown if we try to close the window before it's fully loaded.
51 RefPtr<mozilla::dom::BrowsingContext> mBCToClose;
52 nsCOMPtr<nsITimer> mTimer;
54 /**
55 * This is set based on whether the channel indicates that a new window
56 * was opened, e.g. for a download, or was blocked. If so, then we
57 * close it.
59 bool mShouldCloseWindow;
62 class nsDSURIContentListener final : public nsIURIContentListener,
63 public nsSupportsWeakReference {
64 friend class nsDocShell;
66 public:
67 NS_DECL_THREADSAFE_ISUPPORTS
68 NS_DECL_NSIURICONTENTLISTENER
70 protected:
71 explicit nsDSURIContentListener(nsDocShell* aDocShell);
72 virtual ~nsDSURIContentListener();
74 void DropDocShellReference() {
75 mDocShell = nullptr;
76 mExistingJPEGRequest = nullptr;
77 mExistingJPEGStreamListener = nullptr;
80 protected:
81 nsDocShell* mDocShell;
82 // Hack to handle multipart images without creating a new viewer
83 nsCOMPtr<nsIStreamListener> mExistingJPEGStreamListener;
84 nsCOMPtr<nsIChannel> mExistingJPEGRequest;
86 // Store the parent listener in either of these depending on
87 // if supports weak references or not. Proper weak refs are
88 // preferred and encouraged!
89 nsWeakPtr mWeakParentContentListener;
90 nsIURIContentListener* mParentContentListener;
93 #endif /* nsDSURIContentListener_h__ */