Source code

Revision control

Other Tools

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