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 DOM_BASE_GLOBALTEARDOWNOBSERVER_H_
8 #define DOM_BASE_GLOBALTEARDOWNOBSERVER_H_
10 #include "mozilla/Attributes.h"
11 #include "nsIGlobalObject.h"
12 #include "nsIScriptGlobalObject.h"
16 class GlobalTeardownObserver
19 public LinkedListElement
<GlobalTeardownObserver
> {
21 GlobalTeardownObserver();
22 explicit GlobalTeardownObserver(nsIGlobalObject
* aGlobalObject
,
23 bool aHasOrHasHadOwnerWindow
= false);
25 nsGlobalWindowInner
* GetOwnerWindow() const;
26 nsIGlobalObject
* GetOwnerGlobal() const { return mParentObject
; }
27 bool HasOrHasHadOwnerWindow() const { return mHasOrHasHadOwnerWindow
; }
29 void GetParentObject(nsIScriptGlobalObject
** aParentObject
) {
31 CallQueryInterface(mParentObject
, aParentObject
);
33 *aParentObject
= nullptr;
37 virtual void DisconnectFromOwner();
39 // A global permanently becomes invalid when DisconnectEventTargetObjects() is
40 // called. Normally this means:
41 // - For the main thread, when nsGlobalWindowInner::FreeInnerObjects is
43 // - For a worker thread, when clearing the main event queue. (Which we do
44 // slightly later than when the spec notionally calls for it to be done.)
46 // A global may also become temporarily invalid when:
47 // - For the main thread, if the window is no longer the WindowProxy's current
48 // inner window due to being placed in the bfcache.
49 nsresult
CheckCurrentGlobalCorrectness() const;
52 virtual ~GlobalTeardownObserver();
54 void BindToOwner(nsIGlobalObject
* aOwner
);
57 // The parent global object. The global will clear this when
58 // it is destroyed by calling DisconnectFromOwner().
59 nsIGlobalObject
* MOZ_NON_OWNING_REF mParentObject
= nullptr;
60 // If mParentObject is or has been an inner window, then this is true. It is
61 // obtained in BindToOwner.
62 bool mHasOrHasHadOwnerWindow
= false;
65 } // namespace mozilla