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 opened window
21 class MaybeCloseWindowHelper final
: public nsITimerCallback
, public nsINamed
{
24 NS_DECL_NSITIMERCALLBACK
27 explicit MaybeCloseWindowHelper(
28 mozilla::dom::BrowsingContext
* aContentContext
);
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
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
38 mozilla::dom::BrowsingContext
* MaybeCloseWindow();
40 void SetShouldCloseWindow(bool aShouldCloseWindow
);
43 ~MaybeCloseWindowHelper();
46 already_AddRefed
<mozilla::dom::BrowsingContext
> ChooseNewBrowsingContext(
47 mozilla::dom::BrowsingContext
* aBC
);
50 * The dom window associated to handle content.
52 RefPtr
<mozilla::dom::BrowsingContext
> mBrowsingContext
;
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
;
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
66 bool mShouldCloseWindow
;
69 class nsDSURIContentListener final
: public nsIURIContentListener
,
70 public nsSupportsWeakReference
{
71 friend class nsDocShell
;
74 NS_DECL_THREADSAFE_ISUPPORTS
75 NS_DECL_NSIURICONTENTLISTENER
78 explicit nsDSURIContentListener(nsDocShell
* aDocShell
);
79 virtual ~nsDSURIContentListener();
81 void DropDocShellReference() {
83 mExistingJPEGRequest
= nullptr;
84 mExistingJPEGStreamListener
= nullptr;
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__ */