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__
11 #include "nsIURIContentListener.h"
12 #include "nsWeakReference.h"
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
{
24 NS_DECL_NSITIMERCALLBACK
26 explicit MaybeCloseWindowHelper(
27 mozilla::dom::BrowsingContext
* aContentContext
);
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
);
39 ~MaybeCloseWindowHelper();
43 * The dom window associated to handle content.
45 RefPtr
<mozilla::dom::BrowsingContext
> mBrowsingContext
;
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
;
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
59 bool mShouldCloseWindow
;
62 class nsDSURIContentListener final
: public nsIURIContentListener
,
63 public nsSupportsWeakReference
{
64 friend class nsDocShell
;
67 NS_DECL_THREADSAFE_ISUPPORTS
68 NS_DECL_NSIURICONTENTLISTENER
71 explicit nsDSURIContentListener(nsDocShell
* aDocShell
);
72 virtual ~nsDSURIContentListener();
74 void DropDocShellReference() {
76 mExistingJPEGRequest
= nullptr;
77 mExistingJPEGStreamListener
= nullptr;
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__ */