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 nsFrameLoaderOwner_h_
8 #define nsFrameLoaderOwner_h_
11 #include "nsFrameLoader.h"
12 #include "nsISupports.h"
17 class BrowsingContext
;
18 class BrowsingContextGroup
;
19 class BrowserBridgeChild
;
22 struct RemotenessOptions
;
23 struct NavigationIsolationOptions
;
25 } // namespace mozilla
27 // IID for the FrameLoaderOwner interface
28 #define NS_FRAMELOADEROWNER_IID \
30 0x1b4fd25c, 0x2e57, 0x11e9, { \
31 0x9e, 0x5a, 0x5b, 0x86, 0xe9, 0x89, 0xa5, 0xc0 \
35 // Mixin that handles ownership of nsFrameLoader for Frame elements
36 // (XULFrameElement, HTMLI/FrameElement, etc...). Manages information when doing
39 // This class is considered an XPCOM mixin. This means that while we inherit
40 // from ISupports in order to be QI'able, we expect the classes that inherit
41 // nsFrameLoaderOwner to actually implement ISupports for us.
42 class nsFrameLoaderOwner
: public nsISupports
{
44 NS_DECLARE_STATIC_IID_ACCESSOR(NS_FRAMELOADEROWNER_IID
)
46 nsFrameLoaderOwner() = default;
47 already_AddRefed
<nsFrameLoader
> GetFrameLoader();
48 void SetFrameLoader(nsFrameLoader
* aNewFrameLoader
);
50 mozilla::dom::BrowsingContext
* GetBrowsingContext();
51 mozilla::dom::BrowsingContext
* GetExtantBrowsingContext();
53 // Destroy (if it exists) and recreate our frameloader, based on new
54 // remoteness requirements.
56 // This method is called by frontend code when it wants to perform a
57 // remoteness update, and allows for behaviour such as preserving
58 // BrowsingContexts across process switches during navigation.
60 // See the WebIDL definition for more details.
61 void ChangeRemoteness(const mozilla::dom::RemotenessOptions
& aOptions
,
62 mozilla::ErrorResult
& rv
);
64 // Like `ChangeRemoteness` but switches to an already-created
65 // `BrowserBridgeChild`. This method is used when performing remote subframe
67 void ChangeRemotenessWithBridge(mozilla::dom::BrowserBridgeChild
* aBridge
,
68 mozilla::ErrorResult
& rv
);
70 // Like `ChangeRemoteness`, but switches into an already-created
71 // `ContentParent`. This method is used when performing toplevel process
72 // switches. If `aContentParent` is nullptr, switches into the parent process.
74 // If `aReplaceBrowsingContext` is set, BrowsingContext preservation will be
75 // disabled for this process switch.
76 void ChangeRemotenessToProcess(
77 mozilla::dom::ContentParent
* aContentParent
,
78 const mozilla::dom::NavigationIsolationOptions
& aOptions
,
79 mozilla::dom::BrowsingContextGroup
* aGroup
, mozilla::ErrorResult
& rv
);
81 void SubframeCrashed();
83 void RestoreFrameLoaderFromBFCache(nsFrameLoader
* aNewFrameLoader
);
85 void UpdateFocusAndMouseEnterStateAfterFrameLoaderChange();
87 void AttachFrameLoader(nsFrameLoader
* aFrameLoader
);
88 void DetachFrameLoader(nsFrameLoader
* aFrameLoader
);
89 // If aDestroyBFCached is true and aFrameLoader is the current frameloader
90 // (mFrameLoader) then this will also call nsFrameLoader::Destroy on all the
91 // other frame loaders in mFrameLoaderList and remove them from the list.
92 void FrameLoaderDestroying(nsFrameLoader
* aFrameLoader
,
93 bool aDestroyBFCached
);
96 bool UseRemoteSubframes();
98 // The enum class for determine how to handle previous BrowsingContext during
99 // the change remoteness. It could be followings
101 // Create a whole new BrowsingContext.
103 // Preserve the previous BrowsingContext.
104 enum class ChangeRemotenessContextType
{
108 ChangeRemotenessContextType
ShouldPreserveBrowsingContext(
109 bool aIsRemote
, bool aReplaceBrowsingContext
);
111 void ChangeRemotenessCommon(
112 const ChangeRemotenessContextType
& aContextType
,
113 const mozilla::dom::NavigationIsolationOptions
& aOptions
,
114 bool aSwitchingInProgressLoad
, bool aIsRemote
,
115 mozilla::dom::BrowsingContextGroup
* aGroup
,
116 std::function
<void()>& aFrameLoaderInit
, mozilla::ErrorResult
& aRv
);
118 void ChangeFrameLoaderCommon(mozilla::dom::Element
* aOwner
,
121 void UpdateFocusAndMouseEnterStateAfterFrameLoaderChange(
122 mozilla::dom::Element
* aOwner
);
125 virtual ~nsFrameLoaderOwner() = default;
126 RefPtr
<nsFrameLoader
> mFrameLoader
;
128 // The list contains all the nsFrameLoaders created for this owner or moved
129 // from another nsFrameLoaderOwner which haven't been destroyed yet.
130 // In particular it contains all the nsFrameLoaders which are in bfcache.
131 mozilla::LinkedList
<nsFrameLoader
> mFrameLoaderList
;
134 NS_DEFINE_STATIC_IID_ACCESSOR(nsFrameLoaderOwner
, NS_FRAMELOADEROWNER_IID
)
136 #endif // nsFrameLoaderOwner_h_