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/. */
11 #include "mozilla/Encoding.h"
12 #include "mozilla/Maybe.h"
13 #include "mozilla/NotNull.h"
14 #include "mozilla/ScrollbarPreferences.h"
15 #include "mozilla/UniquePtr.h"
16 #include "mozilla/WeakPtr.h"
17 #include "mozilla/dom/BrowsingContext.h"
18 #include "mozilla/dom/WindowProxyHolder.h"
20 #include "nsCharsetSource.h"
21 #include "nsDocLoader.h"
22 #include "nsIAuthPromptProvider.h"
23 #include "nsIBaseWindow.h"
24 #include "nsIDocShell.h"
25 #include "nsIDocShellTreeItem.h"
26 #include "nsIInterfaceRequestor.h"
27 #include "nsILoadContext.h"
28 #include "nsINetworkInterceptController.h"
29 #include "nsIRefreshURI.h"
30 #include "nsIWebNavigation.h"
31 #include "nsIWebPageDescriptor.h"
32 #include "nsIWebProgressListener.h"
33 #include "nsPoint.h" // mCurrent/mDefaultScrollbarPreferences
36 #include "nsThreadUtils.h"
44 class ObservedDocShell
;
45 enum class TaskCategory
;
50 class SessionHistoryInfo
;
51 struct LoadingSessionHistoryInfo
;
56 class DocumentLoadListener
;
58 } // namespace mozilla
61 class nsIDocShellTreeOwner
;
62 class nsIDocumentViewer
;
64 class nsIMutableArray
;
66 class nsIScrollableFrame
;
67 class nsIStringBundle
;
69 class nsIURIFixupInfo
;
71 class nsIWebBrowserFind
;
73 class nsIReferrerInfo
;
75 class nsCommandManager
;
76 class nsDocShellEditorData
;
77 class nsDOMNavigationTiming
;
78 class nsDSURIContentListener
;
79 class nsGlobalWindowOuter
;
82 class OnLinkClickEvent
;
84 /* internally used ViewMode types */
85 enum ViewMode
{ viewNormal
= 0x0, viewSource
= 0x1 };
87 enum eCharsetReloadState
{
89 eCharsetReloadRequested
,
90 eCharsetReloadStopOrigional
93 class nsDocShell final
: public nsDocLoader
,
95 public nsIWebNavigation
,
98 public nsIWebProgressListener
,
99 public nsIWebPageDescriptor
,
100 public nsIAuthPromptProvider
,
101 public nsILoadContext
,
102 public nsINetworkInterceptController
,
103 public mozilla::SupportsWeakPtr
{
105 enum InternalLoad
: uint32_t {
106 INTERNAL_LOAD_FLAGS_NONE
= 0x0,
107 INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL
= 0x1,
108 INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER
= 0x2,
109 INTERNAL_LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP
= 0x4,
111 // This flag marks the first load in this object
112 // @see nsIWebNavigation::LOAD_FLAGS_FIRST_LOAD
113 INTERNAL_LOAD_FLAGS_FIRST_LOAD
= 0x8,
115 // The set of flags that should not be set before calling into
116 // nsDocShell::LoadURI and other nsDocShell loading functions.
117 INTERNAL_LOAD_FLAGS_LOADURI_SETUP_FLAGS
= 0xf,
119 INTERNAL_LOAD_FLAGS_BYPASS_CLASSIFIER
= 0x10,
120 INTERNAL_LOAD_FLAGS_FORCE_ALLOW_COOKIES
= 0x20,
122 // Whether the load should be treated as srcdoc load, rather than a URI one.
123 INTERNAL_LOAD_FLAGS_IS_SRCDOC
= 0x40,
125 // Whether this is the load of a frame's original src attribute
126 INTERNAL_LOAD_FLAGS_ORIGINAL_FRAME_SRC
= 0x80,
128 INTERNAL_LOAD_FLAGS_NO_OPENER
= 0x100,
130 // Whether a top-level data URI navigation is allowed for that load
131 INTERNAL_LOAD_FLAGS_FORCE_ALLOW_DATA_URI
= 0x200,
133 // Whether the load should go through LoadURIDelegate.
134 INTERNAL_LOAD_FLAGS_BYPASS_LOAD_URI_DELEGATE
= 0x2000,
137 // Event type dispatched by RestorePresentation
138 class RestorePresentationEvent
: public mozilla::Runnable
{
141 explicit RestorePresentationEvent(nsDocShell
* aDs
)
142 : mozilla::Runnable("nsDocShell::RestorePresentationEvent"),
144 void Revoke() { mDocShell
= nullptr; }
147 RefPtr
<nsDocShell
> mDocShell
;
150 class InterfaceRequestorProxy
: public nsIInterfaceRequestor
{
152 explicit InterfaceRequestorProxy(nsIInterfaceRequestor
* aRequestor
);
153 NS_DECL_THREADSAFE_ISUPPORTS
154 NS_DECL_NSIINTERFACEREQUESTOR
157 virtual ~InterfaceRequestorProxy();
158 InterfaceRequestorProxy() = default;
162 NS_DECL_ISUPPORTS_INHERITED
163 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDocShell
, nsDocLoader
)
165 NS_DECL_NSIDOCSHELLTREEITEM
166 NS_DECL_NSIWEBNAVIGATION
167 NS_DECL_NSIBASEWINDOW
168 NS_DECL_NSIINTERFACEREQUESTOR
169 NS_DECL_NSIWEBPROGRESSLISTENER
170 NS_DECL_NSIREFRESHURI
171 NS_DECL_NSIWEBPAGEDESCRIPTOR
172 NS_DECL_NSIAUTHPROMPTPROVIDER
173 NS_DECL_NSINETWORKINTERCEPTCONTROLLER
175 // Create a new nsDocShell object.
176 static already_AddRefed
<nsDocShell
> Create(
177 mozilla::dom::BrowsingContext
* aBrowsingContext
,
178 uint64_t aContentWindowID
= 0);
182 NS_IMETHOD
Stop() override
{
183 // Need this here because otherwise nsIWebNavigation::Stop
184 // overrides the docloader's Stop()
185 return nsDocLoader::Stop();
188 mozilla::ScrollbarPreference
ScrollbarPreference() const {
189 return mScrollbarPref
;
191 void SetScrollbarPreference(mozilla::ScrollbarPreference
);
194 * The size, in CSS pixels, of the margins for the <body> of an HTML document
195 * in this docshell; used to implement the marginwidth attribute on HTML
196 * <frame>/<iframe> elements. A value smaller than zero indicates that the
197 * attribute was not set.
199 const mozilla::CSSIntSize
& GetFrameMargins() const { return mFrameMargins
; }
201 bool UpdateFrameMargins(const mozilla::CSSIntSize
& aMargins
) {
202 if (mFrameMargins
== aMargins
) {
205 mFrameMargins
= aMargins
;
210 * Process a click on a link.
212 * @param aContent the content object used for triggering the link.
213 * @param aURI a URI object that defines the destination for the link
214 * @param aTargetSpec indicates where the link is targeted (may be an empty
216 * @param aFileName non-null when the link should be downloaded as the given
218 * @param aPostDataStream the POST data to send
219 * @param aHeadersDataStream ??? (only used for plugins)
220 * @param aIsTrusted false if the triggerer is an untrusted DOM event.
221 * @param aTriggeringPrincipal, if not passed explicitly we fall back to
222 * the document's principal.
223 * @param aCsp, the CSP to be used for the load, that is the CSP of the
224 * entity responsible for causing the load to occur. Most likely
225 * this is the CSP of the document that started the load. In case
226 * aCsp was not passed explicitly we fall back to using
227 * aContent's document's CSP if that document holds any.
229 nsresult
OnLinkClick(nsIContent
* aContent
, nsIURI
* aURI
,
230 const nsAString
& aTargetSpec
, const nsAString
& aFileName
,
231 nsIInputStream
* aPostDataStream
,
232 nsIInputStream
* aHeadersDataStream
,
233 bool aIsUserTriggered
, bool aIsTrusted
,
234 nsIPrincipal
* aTriggeringPrincipal
,
235 nsIContentSecurityPolicy
* aCsp
);
237 * Process a click on a link.
239 * Works the same as OnLinkClick() except it happens immediately rather than
242 * @param aContent the content object used for triggering the link.
243 * @param aDocShellLoadState the extended load info for this load.
244 * @param aNoOpenerImplied if the link implies "noopener"
245 * @param aTriggeringPrincipal, if not passed explicitly we fall back to
246 * the document's principal.
248 nsresult
OnLinkClickSync(nsIContent
* aContent
,
249 nsDocShellLoadState
* aLoadState
,
250 bool aNoOpenerImplied
,
251 nsIPrincipal
* aTriggeringPrincipal
);
254 * Process a mouse-over a link.
256 * @param aContent the linked content.
257 * @param aURI an URI object that defines the destination for the link
258 * @param aTargetSpec indicates where the link is targeted (it may be an empty
261 nsresult
OnOverLink(nsIContent
* aContent
, nsIURI
* aURI
,
262 const nsAString
& aTargetSpec
);
264 * Process the mouse leaving a link.
266 nsresult
OnLeaveLink();
268 // Don't use NS_DECL_NSILOADCONTEXT because some of nsILoadContext's methods
269 // are shared with nsIDocShell and can't be declared twice.
270 NS_IMETHOD
GetAssociatedWindow(mozIDOMWindowProxy
**) override
;
271 NS_IMETHOD
GetTopWindow(mozIDOMWindowProxy
**) override
;
272 NS_IMETHOD
GetTopFrameElement(mozilla::dom::Element
**) override
;
273 NS_IMETHOD
GetIsContent(bool*) override
;
274 NS_IMETHOD
GetUsePrivateBrowsing(bool*) override
;
275 NS_IMETHOD
SetUsePrivateBrowsing(bool) override
;
276 NS_IMETHOD
SetPrivateBrowsing(bool) override
;
277 NS_IMETHOD
GetUseRemoteTabs(bool*) override
;
278 NS_IMETHOD
SetRemoteTabs(bool) override
;
279 NS_IMETHOD
GetUseRemoteSubframes(bool*) override
;
280 NS_IMETHOD
SetRemoteSubframes(bool) override
;
281 NS_IMETHOD
GetScriptableOriginAttributes(
282 JSContext
*, JS::MutableHandle
<JS::Value
>) override
;
284 GetOriginAttributes(mozilla::OriginAttributes
& aAttrs
) override
;
286 // Restores a cached presentation from history (mLSHE).
287 // This method swaps out the content viewer and simulates loads for
288 // subframes. It then simulates the completion of the toplevel load.
289 nsresult
RestoreFromHistory();
292 * Parses the passed in header string and sets up a refreshURI if a "refresh"
293 * header is found. If docshell is busy loading a page currently, the request
294 * will be queued and executed when the current page finishes loading.
296 * @param aDocument document to which the refresh header applies.
297 * @param aHeader The meta refresh header string.
299 void SetupRefreshURIFromHeader(mozilla::dom::Document
* aDocument
,
300 const nsAString
& aHeader
);
302 // Perform a URI load from a refresh timer. This is just like the
303 // ForceRefreshURI method on nsIRefreshURI, but makes sure to take
304 // the timer involved out of mRefreshURIList if it's there.
305 // aTimer must not be null.
306 nsresult
ForceRefreshURIFromTimer(nsIURI
* aURI
, nsIPrincipal
* aPrincipal
,
307 uint32_t aDelay
, nsITimer
* aTimer
);
309 // We need dummy OnLocationChange in some cases to update the UI without
310 // updating security info.
311 void FireDummyOnLocationChange() {
312 FireOnLocationChange(this, nullptr, mCurrentURI
,
313 LOCATION_CHANGE_SAME_DOCUMENT
);
316 nsresult
HistoryEntryRemoved(int32_t aIndex
);
318 // Notify Scroll observers when an async panning/zooming transform
319 // has started being applied
320 MOZ_CAN_RUN_SCRIPT_BOUNDARY
321 void NotifyAsyncPanZoomStarted();
323 // Notify Scroll observers when an async panning/zooming transform
324 // is no longer applied
325 MOZ_CAN_RUN_SCRIPT_BOUNDARY
326 void NotifyAsyncPanZoomStopped();
328 void SetInFrameSwap(bool aInSwap
) { mInFrameSwap
= aInSwap
; }
331 bool GetForcedAutodetection() { return mForcedAutodetection
; }
333 void ResetForcedAutodetection() { mForcedAutodetection
= false; }
335 mozilla::HTMLEditor
* GetHTMLEditorInternal();
336 nsresult
SetHTMLEditorInternal(mozilla::HTMLEditor
* aHTMLEditor
);
338 // Handle page navigation due to charset changes
339 nsresult
CharsetChangeReloadDocument(
340 mozilla::NotNull
<const mozilla::Encoding
*> aEncoding
, int32_t aSource
);
341 nsresult
CharsetChangeStopDocumentLoad();
343 nsDOMNavigationTiming
* GetNavigationTiming() const;
345 nsresult
SetOriginAttributes(const mozilla::OriginAttributes
& aAttrs
);
347 const mozilla::OriginAttributes
& GetOriginAttributes() {
348 return mBrowsingContext
->OriginAttributesRef();
351 // Determine whether this docshell corresponds to the given history entry,
352 // via having a pointer to it in mOSHE or mLSHE.
353 bool HasHistoryEntry(nsISHEntry
* aEntry
) const {
354 return aEntry
&& (aEntry
== mOSHE
|| aEntry
== mLSHE
);
357 // Update any pointers (mOSHE or mLSHE) to aOldEntry to point to aNewEntry
358 void SwapHistoryEntries(nsISHEntry
* aOldEntry
, nsISHEntry
* aNewEntry
);
360 bool GetCreatedDynamically() const {
361 return mBrowsingContext
&& mBrowsingContext
->CreatedDynamically();
364 mozilla::gfx::Matrix5x4
* GetColorMatrix() { return mColorMatrix
.get(); }
366 static bool SandboxFlagsImplyCookies(const uint32_t& aSandboxFlags
);
368 // Tell the favicon service that aNewURI has the same favicon as aOldURI.
369 static void CopyFavicon(nsIURI
* aOldURI
, nsIURI
* aNewURI
,
370 bool aInPrivateBrowsing
);
372 static nsDocShell
* Cast(nsIDocShell
* aDocShell
) {
373 return static_cast<nsDocShell
*>(aDocShell
);
376 static bool CanLoadInParentProcess(nsIURI
* aURI
);
378 // Returns true if the current load is a force reload (started by holding
379 // shift while triggering reload)
380 bool IsForceReloading();
382 mozilla::dom::WindowProxyHolder
GetWindowProxy() {
383 EnsureScriptEnvironment();
384 return mozilla::dom::WindowProxyHolder(mBrowsingContext
);
388 * Loads the given URI. See comments on nsDocShellLoadState members for more
389 * information on information used.
390 * `aCacheKey` gets passed to DoURILoad call.
392 MOZ_CAN_RUN_SCRIPT_BOUNDARY
393 nsresult
InternalLoad(
394 nsDocShellLoadState
* aLoadState
,
395 mozilla::Maybe
<uint32_t> aCacheKey
= mozilla::Nothing());
397 void MaybeRestoreWindowName();
399 void StoreWindowNameToSHEntries();
401 void SetWillChangeProcess() { mWillChangeProcess
= true; }
402 bool WillChangeProcess() { return mWillChangeProcess
; }
404 // Create a content viewer within this nsDocShell for the given
405 // `WindowGlobalChild` actor.
406 nsresult
CreateDocumentViewerForActor(
407 mozilla::dom::WindowGlobalChild
* aWindowActor
);
409 // Creates a real network channel (not a DocumentChannel) using the specified
411 // Used by nsDocShell when not using DocumentChannel, by DocumentLoadListener
412 // (parent-process DocumentChannel), and by DocumentChannelChild/ContentChild
413 // to transfer the resulting channel into the final process.
414 static nsresult
CreateRealChannelForDocument(
415 nsIChannel
** aChannel
, nsIURI
* aURI
, nsILoadInfo
* aLoadInfo
,
416 nsIInterfaceRequestor
* aCallbacks
, nsLoadFlags aLoadFlags
,
417 const nsAString
& aSrcdoc
, nsIURI
* aBaseURI
);
419 // Creates a real (not DocumentChannel) channel, and configures it using the
420 // supplied nsDocShellLoadState.
421 // Configuration options here are ones that should be applied to only the
422 // real channel, especially ones that need to QI to channel subclasses.
423 static bool CreateAndConfigureRealChannelForLoadState(
424 mozilla::dom::BrowsingContext
* aBrowsingContext
,
425 nsDocShellLoadState
* aLoadState
, mozilla::net::LoadInfo
* aLoadInfo
,
426 nsIInterfaceRequestor
* aCallbacks
, nsDocShell
* aDocShell
,
427 const mozilla::OriginAttributes
& aOriginAttributes
,
428 nsLoadFlags aLoadFlags
, uint32_t aCacheKey
, nsresult
& rv
,
429 nsIChannel
** aChannel
);
431 // This is used to deal with errors resulting from a failed page load.
432 // Errors are handled as follows:
433 // 1. Check to see if it's a file not found error or bad content
435 // 2. Send the URI to a keyword server (if enabled)
436 // 3. If the error was DNS failure, then add www and .com to the URI
438 // 4. If the www .com additions don't work, try those with an HTTPS scheme
440 static already_AddRefed
<nsIURI
> AttemptURIFixup(
441 nsIChannel
* aChannel
, nsresult aStatus
,
442 const mozilla::Maybe
<nsCString
>& aOriginalURIString
, uint32_t aLoadType
,
443 bool aIsTopFrame
, bool aAllowKeywordFixup
, bool aUsePrivateBrowsing
,
444 bool aNotifyKeywordSearchLoading
= false,
445 nsIInputStream
** aNewPostData
= nullptr,
446 bool* outWasSchemelessInput
= nullptr);
448 static already_AddRefed
<nsIURI
> MaybeFixBadCertDomainErrorURI(
449 nsIChannel
* aChannel
, nsIURI
* aUrl
);
451 // Takes aStatus and filters out results that should not display
453 // If this returns a failed result, then we should display an error
454 // page with that result.
455 // aSkippedUnknownProtocolNavigation will be set to true if we chose
456 // to skip displaying an error page for an NS_ERROR_UNKNOWN_PROTOCOL
458 static nsresult
FilterStatusForErrorPage(
459 nsresult aStatus
, nsIChannel
* aChannel
, uint32_t aLoadType
,
460 bool aIsTopFrame
, bool aUseErrorPages
, bool aIsInitialDocument
,
461 bool* aSkippedUnknownProtocolNavigation
= nullptr);
463 // Notify consumers of a search being loaded through the observer service:
464 static void MaybeNotifyKeywordSearchLoading(const nsString
& aProvider
,
465 const nsString
& aKeyword
);
467 nsDocShell
* GetInProcessChildAt(int32_t aIndex
);
469 static bool ShouldAddURIVisit(nsIChannel
* aChannel
);
472 * Helper function that finds the last URI and its transition flags for a
475 * This method first checks the channel's property bag to see if previous
476 * info has been saved. If not, it gives back the referrer of the channel.
479 * The channel we are transitioning to
481 * Output parameter with the previous URI, not addref'd
482 * @param aChannelRedirectFlags
483 * If a redirect, output parameter with the previous redirect flags
484 * from nsIChannelEventSink
486 static void ExtractLastVisit(nsIChannel
* aChannel
, nsIURI
** aURI
,
487 uint32_t* aChannelRedirectFlags
);
489 bool HasDocumentViewer() const { return !!mDocumentViewer
; }
491 static uint32_t ComputeURILoaderFlags(
492 mozilla::dom::BrowsingContext
* aBrowsingContext
, uint32_t aLoadType
,
493 bool aIsDocumentLoad
= true);
495 void SetLoadingSessionHistoryInfo(
496 const mozilla::dom::LoadingSessionHistoryInfo
& aLoadingInfo
,
497 bool aNeedToReportActiveAfterLoadingBecomesActive
= false);
498 const mozilla::dom::LoadingSessionHistoryInfo
*
499 GetLoadingSessionHistoryInfo() {
500 return mLoadingEntry
.get();
503 already_AddRefed
<nsIInputStream
> GetPostDataFromCurrentEntry() const;
504 mozilla::Maybe
<uint32_t> GetCacheKeyFromCurrentEntry() const;
506 // Loading and/or active entries are only set when session history
507 // in the parent is on.
508 bool FillLoadStateFromCurrentEntry(nsDocShellLoadState
& aLoadState
);
510 static bool ShouldAddToSessionHistory(nsIURI
* aURI
, nsIChannel
* aChannel
);
512 bool IsOSHE(nsISHEntry
* aEntry
) const { return mOSHE
== aEntry
; }
514 mozilla::dom::ChildSHistory
* GetSessionHistory() {
515 return mBrowsingContext
->GetChildSessionHistory();
518 // This returns true only when using session history in parent.
519 bool IsLoadingFromSessionHistory();
521 NS_IMETHODIMP
OnStartRequest(nsIRequest
* aRequest
) override
;
522 NS_IMETHODIMP
OnStopRequest(nsIRequest
* aRequest
,
523 nsresult aStatusCode
) override
;
525 private: // member functions
526 friend class nsAppShellService
;
527 friend class nsDSURIContentListener
;
528 friend class FramingChecker
;
529 friend class OnLinkClickEvent
;
530 friend class nsIDocShell
;
531 friend class mozilla::dom::BrowsingContext
;
532 friend class mozilla::net::DocumentLoadListener
;
533 friend class nsGlobalWindowOuter
;
535 nsDocShell(mozilla::dom::BrowsingContext
* aBrowsingContext
,
536 uint64_t aContentWindowID
);
538 static inline uint32_t PRTimeToSeconds(PRTime aTimeUsec
) {
539 return uint32_t(aTimeUsec
/ PR_USEC_PER_SEC
);
542 virtual ~nsDocShell();
548 virtual void DestroyChildren() override
;
550 // Overridden from nsDocLoader, this provides more information than the
551 // normal OnStateChange with flags STATE_REDIRECTING
552 virtual void OnRedirectStateChange(nsIChannel
* aOldChannel
,
553 nsIChannel
* aNewChannel
,
554 uint32_t aRedirectFlags
,
555 uint32_t aStateFlags
) override
;
557 // Override the parent setter from nsDocLoader
558 virtual nsresult
SetDocLoaderParent(nsDocLoader
* aLoader
) override
;
561 // Content Viewer Management
564 nsresult
EnsureDocumentViewer();
566 // aPrincipal can be passed in if the caller wants. If null is
567 // passed in, the about:blank principal will end up being used.
568 // aCSP, if any, will be used for the new about:blank load.
569 nsresult
CreateAboutBlankDocumentViewer(
570 nsIPrincipal
* aPrincipal
, nsIPrincipal
* aPartitionedPrincipal
,
571 nsIContentSecurityPolicy
* aCSP
, nsIURI
* aBaseURI
, bool aIsInitialDocument
,
572 const mozilla::Maybe
<nsILoadInfo::CrossOriginEmbedderPolicy
>& aCOEP
=
574 bool aTryToSaveOldPresentation
= true, bool aCheckPermitUnload
= true,
575 mozilla::dom::WindowGlobalChild
* aActor
= nullptr);
577 nsresult
CreateDocumentViewer(const nsACString
& aContentType
,
578 nsIRequest
* aRequest
,
579 nsIStreamListener
** aContentHandler
);
581 nsresult
NewDocumentViewerObj(const nsACString
& aContentType
,
582 nsIRequest
* aRequest
, nsILoadGroup
* aLoadGroup
,
583 nsIStreamListener
** aContentHandler
,
584 nsIDocumentViewer
** aViewer
);
586 already_AddRefed
<nsILoadURIDelegate
> GetLoadURIDelegate();
588 nsresult
SetupNewViewer(
589 nsIDocumentViewer
* aNewViewer
,
590 mozilla::dom::WindowGlobalChild
* aWindowActor
= nullptr);
596 // Either aChannel or aOwner must be null. If aChannel is
597 // present, the owner should be gotten from it.
598 // If aCloneChildren is true, then our current session history's
599 // children will be cloned onto the new entry. This should be
600 // used when we aren't actually changing the document while adding
601 // the new session history entry.
602 // aCsp is the CSP to be used for the load. That is *not* the CSP
603 // that will be applied to subresource loads within that document
604 // but the CSP for the document load itself. E.g. if that CSP
605 // includes upgrade-insecure-requests, then the new top-level load
606 // will be upgraded to HTTPS.
607 nsresult
AddToSessionHistory(nsIURI
* aURI
, nsIChannel
* aChannel
,
608 nsIPrincipal
* aTriggeringPrincipal
,
609 nsIPrincipal
* aPrincipalToInherit
,
610 nsIPrincipal
* aPartitionedPrincipalToInherit
,
611 nsIContentSecurityPolicy
* aCsp
,
612 bool aCloneChildren
, nsISHEntry
** aNewEntry
);
614 void UpdateActiveEntry(
615 bool aReplace
, const mozilla::Maybe
<nsPoint
>& aPreviousScrollPos
,
616 nsIURI
* aURI
, nsIURI
* aOriginalURI
, nsIReferrerInfo
* aReferrerInfo
,
617 nsIPrincipal
* aTriggeringPrincipal
, nsIContentSecurityPolicy
* aCsp
,
618 const nsAString
& aTitle
, bool aScrollRestorationIsManual
,
619 nsIStructuredCloneContainer
* aData
, bool aURIWasModified
);
621 nsresult
AddChildSHEntry(nsISHEntry
* aCloneRef
, nsISHEntry
* aNewEntry
,
622 int32_t aChildOffset
, uint32_t aLoadType
,
623 bool aCloneChildren
);
625 nsresult
AddChildSHEntryToParent(nsISHEntry
* aNewEntry
, int32_t aChildOffset
,
626 bool aCloneChildren
);
628 // Call this method to swap in a new history entry to m[OL]SHE, rather than
629 // setting it directly. This completes the navigation in all docshells
630 // in the case of a subframe navigation.
631 // Returns old mOSHE/mLSHE.
632 already_AddRefed
<nsISHEntry
> SetHistoryEntry(nsCOMPtr
<nsISHEntry
>* aPtr
,
635 // This method calls SetHistoryEntry and updates mOSHE and mLSHE in BC to be
636 // the same as in docshell
637 void SetHistoryEntryAndUpdateBC(const mozilla::Maybe
<nsISHEntry
*>& aLSHE
,
638 const mozilla::Maybe
<nsISHEntry
*>& aOSHE
);
640 // If aNotifiedBeforeUnloadListeners is true, "beforeunload" event listeners
641 // were notified by the caller and given the chance to abort the navigation,
642 // and should not be notified again.
643 static nsresult
ReloadDocument(
644 nsDocShell
* aDocShell
, mozilla::dom::Document
* aDocument
,
645 uint32_t aLoadType
, mozilla::dom::BrowsingContext
* aBrowsingContext
,
646 nsIURI
* aCurrentURI
, nsIReferrerInfo
* aReferrerInfo
,
647 bool aNotifiedBeforeUnloadListeners
= false);
650 bool IsAboutBlankLoadOntoInitialAboutBlank(nsIURI
* aURI
,
651 bool aInheritPrincipal
,
652 nsIPrincipal
* aPrincipalToInherit
);
659 // Actually open a channel and perform a URI load. Callers need to pass a
660 // non-null aLoadState->TriggeringPrincipal() which initiated the URI load.
661 // Please note that the TriggeringPrincipal will be used for performing
662 // security checks. If aLoadState->URI() is provided by the web, then please
663 // do not pass a SystemPrincipal as the triggeringPrincipal. If
664 // aLoadState()->PrincipalToInherit is null, then no inheritance of any sort
665 // will happen and the load will get a principal based on the URI being
666 // loaded. If the Srcdoc flag is set (INTERNAL_LOAD_FLAGS_IS_SRCDOC), the load
667 // will be considered as a srcdoc load, and the contents of Srcdoc will be
668 // loaded instead of the URI. aLoadState->OriginalURI() will be set as the
669 // originalURI on the channel that does the load. If OriginalURI is null, URI
670 // will be set as the originalURI. If LoadReplace is true, LOAD_REPLACE flag
671 // will be set on the nsIChannel.
672 // If `aCacheKey` is supplied, use it for the session history entry.
673 nsresult
DoURILoad(nsDocShellLoadState
* aLoadState
,
674 mozilla::Maybe
<uint32_t> aCacheKey
, nsIRequest
** aRequest
);
676 static nsresult
AddHeadersToChannel(nsIInputStream
* aHeadersData
,
677 nsIChannel
* aChannel
);
679 nsresult
OpenInitializedChannel(nsIChannel
* aChannel
,
680 nsIURILoader
* aURILoader
,
681 uint32_t aOpenFlags
);
682 nsresult
OpenRedirectedChannel(nsDocShellLoadState
* aLoadState
);
684 void UpdateMixedContentChannelForNewLoad(nsIChannel
* aChannel
);
687 nsresult
ScrollToAnchor(bool aCurHasRef
, bool aNewHasRef
,
688 nsACString
& aNewHash
, uint32_t aLoadType
);
690 // This returns the load type for a form submission (see
691 // https://html.spec.whatwg.org/#form-submission-algorithm). The load type
692 // should be set as soon as the target BC has been determined.
693 uint32_t GetLoadTypeForFormSubmission(
694 mozilla::dom::BrowsingContext
* aTargetBC
,
695 nsDocShellLoadState
* aLoadState
);
698 // Returns true if it is the caller's responsibility to ensure
699 // FireOnLocationChange is called.
700 // In all other cases false is returned.
701 // Either aChannel or aTriggeringPrincipal must be null. If aChannel is
702 // present, the owner should be gotten from it.
703 // If OnNewURI calls AddToSessionHistory, it will pass its
704 // aCloneSHChildren argument as aCloneChildren.
705 // aCsp is the CSP to be used for the load. That is *not* the CSP
706 // that will be applied to subresource loads within that document
707 // but the CSP for the document load itself. E.g. if that CSP
708 // includes upgrade-insecure-requests, then the new top-level load
709 // will be upgraded to HTTPS.
710 bool OnNewURI(nsIURI
* aURI
, nsIChannel
* aChannel
,
711 nsIPrincipal
* aTriggeringPrincipal
,
712 nsIPrincipal
* aPrincipalToInherit
,
713 nsIPrincipal
* aPartitionedPrincipalToInherit
,
714 nsIContentSecurityPolicy
* aCsp
, bool aAddToGlobalHistory
,
715 bool aCloneSHChildren
);
718 // If wireframe collection is enabled, will attempt to gather the
719 // wireframe for the document.
720 mozilla::Maybe
<mozilla::dom::Wireframe
> GetWireframe();
722 // If wireframe collection is enabled, will attempt to gather the
723 // wireframe for the document and stash it inside of the active history
724 // entry. Returns true if wireframes were collected.
725 bool CollectWireframe();
727 // Helper method that is called when a new document (including any
728 // sub-documents - ie. frames) has been completely loaded.
729 MOZ_CAN_RUN_SCRIPT_BOUNDARY
730 nsresult
EndPageLoad(nsIWebProgress
* aProgress
, nsIChannel
* aChannel
,
733 // Builds an error page URI (e.g. about:neterror?etc) for the given aURI
734 // and displays it via the LoadErrorPage() overload below.
735 nsresult
LoadErrorPage(nsIURI
* aURI
, const char16_t
* aURL
,
736 const char* aErrorPage
, const char* aErrorType
,
737 const char16_t
* aDescription
, const char* aCSSClass
,
738 nsIChannel
* aFailedChannel
);
740 // This method directly loads aErrorURI as an error page. aFailedURI and
741 // aFailedChannel come from DisplayLoadError() or the LoadErrorPage() overload
743 nsresult
LoadErrorPage(nsIURI
* aErrorURI
, nsIURI
* aFailedURI
,
744 nsIChannel
* aFailedChannel
);
746 bool DisplayLoadError(nsresult aError
, nsIURI
* aURI
, const char16_t
* aURL
,
747 nsIChannel
* aFailedChannel
) {
748 bool didDisplayLoadError
= false;
749 DisplayLoadError(aError
, aURI
, aURL
, aFailedChannel
, &didDisplayLoadError
);
750 return didDisplayLoadError
;
757 // Get the principal that we'll set on the channel if we're inheriting. If
758 // aConsiderCurrentDocument is true, we try to use the current document if
759 // at all possible. If that fails, we fall back on the parent document.
760 // If that fails too, we force creation of a content viewer and use the
761 // resulting principal. If aConsiderCurrentDocument is false, we just look
763 // If aConsiderPartitionedPrincipal is true, we consider the partitioned
764 // principal instead of the node principal.
765 nsIPrincipal
* GetInheritedPrincipal(
766 bool aConsiderCurrentDocument
,
767 bool aConsiderPartitionedPrincipal
= false);
770 * Helper function that caches a URI and a transition for saving later.
773 * Channel that will have these properties saved
775 * The URI to save for later
776 * @param aChannelRedirectFlags
777 * The nsIChannelEventSink redirect flags to save for later
779 static void SaveLastVisit(nsIChannel
* aChannel
, nsIURI
* aURI
,
780 uint32_t aChannelRedirectFlags
);
783 * Helper function for adding a URI visit using IHistory.
785 * The IHistory API maintains chains of visits, tracking both HTTP referrers
786 * and redirects for a user session. VisitURI requires the current URI and
787 * the previous URI in the chain.
789 * Visits can be saved either during a redirect or when the request has
790 * reached its final destination. The previous URI in the visit may be
791 * from another redirect.
793 * @pre aURI is not null.
796 * The URI that was just visited
797 * @param aPreviousURI
798 * The previous URI of this visit
799 * @param aChannelRedirectFlags
800 * For redirects, the redirect flags from nsIChannelEventSink
802 * @param aResponseStatus
803 * For HTTP channels, the response code (0 otherwise).
805 void AddURIVisit(nsIURI
* aURI
, nsIURI
* aPreviousURI
,
806 uint32_t aChannelRedirectFlags
,
807 uint32_t aResponseStatus
= 0);
810 * Internal helper funtion
812 static void InternalAddURIVisit(
813 nsIURI
* aURI
, nsIURI
* aPreviousURI
, uint32_t aChannelRedirectFlags
,
814 uint32_t aResponseStatus
, mozilla::dom::BrowsingContext
* aBrowsingContext
,
815 nsIWidget
* aWidget
, uint32_t aLoadType
, bool aWasUpgraded
);
817 static already_AddRefed
<nsIURIFixupInfo
> KeywordToURI(
818 const nsACString
& aKeyword
, bool aIsPrivateContext
);
820 // Sets the current document's current state object to the given SHEntry's
821 // state object. The current state object is eventually given to the page
822 // in the PopState event.
823 void SetDocCurrentStateObj(nsISHEntry
* aShEntry
,
824 mozilla::dom::SessionHistoryInfo
* aInfo
);
826 // Returns true if would have called FireOnLocationChange,
827 // but did not because aFireOnLocationChange was false on entry.
828 // In this case it is the caller's responsibility to ensure
829 // FireOnLocationChange is called.
830 // In all other cases false is returned.
831 bool SetCurrentURI(nsIURI
* aURI
, nsIRequest
* aRequest
,
832 bool aFireOnLocationChange
, bool aIsInitialAboutBlank
,
833 uint32_t aLocationFlags
);
835 // The following methods deal with saving and restoring content viewers
836 // in session history.
838 // mDocumentViewer points to the current content viewer associated with
839 // this docshell. When loading a new document, the content viewer is
840 // either destroyed or stored into a session history entry. To make sure
841 // that destruction happens in a controlled fashion, a given content viewer
842 // is always owned in exactly one of these ways:
843 // 1) The content viewer is active and owned by a docshell's
845 // 2) The content viewer is still being displayed while we begin loading
846 // a new document. The content viewer is owned by the _new_
847 // content viewer's mPreviousViewer, and has a pointer to the
848 // nsISHEntry where it will eventually be stored. The content viewer
849 // has been close()d by the docshell, which detaches the document from
850 // the window object.
851 // 3) The content viewer is cached in session history. The nsISHEntry
852 // has the only owning reference to the content viewer. The viewer
853 // has released its nsISHEntry pointer to prevent circular ownership.
855 // When restoring a content viewer from session history, open() is called
856 // to reattach the document to the window object. The content viewer is
857 // then placed into mDocumentViewer and removed from the history entry.
858 // (mDocumentViewer is put into session history as described above, if
861 // Determines whether we can safely cache the current mDocumentViewer in
862 // session history. This checks a number of factors such as cache policy,
863 // pending requests, and unload handlers.
864 // |aLoadType| should be the load type that will replace the current
865 // presentation. |aNewRequest| should be the request for the document to
866 // be loaded in place of the current document, or null if such a request
867 // has not been created yet. |aNewDocument| should be the document that will
868 // replace the current document.
869 bool CanSavePresentation(uint32_t aLoadType
, nsIRequest
* aNewRequest
,
870 mozilla::dom::Document
* aNewDocument
,
871 bool aReportBFCacheComboTelemetry
);
873 static void ReportBFCacheComboTelemetry(uint32_t aCombo
);
875 // Captures the state of the supporting elements of the presentation
876 // (the "window" object, docshell tree, meta-refresh loads, and security
877 // state) and stores them on |mOSHE|.
878 nsresult
CaptureState();
880 // Begin the toplevel restore process for |aSHEntry|.
881 // This simulates a channel open, and defers the real work until
882 // RestoreFromHistory is called from a PLEvent.
883 nsresult
RestorePresentation(nsISHEntry
* aSHEntry
, bool* aRestoring
);
885 // Call BeginRestore(nullptr, false) for each child of this shell.
886 nsresult
BeginRestoreChildren();
888 // Method to get our current position and size without flushing
889 void DoGetPositionAndSize(int32_t* aX
, int32_t* aY
, int32_t* aWidth
,
892 // Call this when a URI load is handed to us (via OnLinkClick or
893 // InternalLoad). This makes sure that we're not inside unload, or that if
894 // we are it's still OK to load this URI.
895 bool IsOKToLoadURI(nsIURI
* aURI
);
897 // helpers for executing commands
898 nsresult
GetControllerForCommand(const char* aCommand
,
899 nsIController
** aResult
);
901 // Possibly create a ClientSource object to represent an initial about:blank
902 // window that has not been allocated yet. Normally we try not to create
903 // this about:blank window until something calls GetDocument(). We still need
904 // the ClientSource to exist for this conceptual window, though.
906 // The ClientSource is created with the given principal if specified. If
907 // the principal is not provided we will attempt to inherit it when we
908 // are sure it will match what the real about:blank window principal
909 // would have been. There are some corner cases where we cannot easily
910 // determine the correct principal and will not create the ClientSource.
911 // In these cases the initial about:blank will appear to not exist until
912 // its real document and window are created.
913 void MaybeCreateInitialClientSource(nsIPrincipal
* aPrincipal
= nullptr);
915 // Determine if a service worker is allowed to control a window in this
916 // docshell with the given URL. If there are any reasons it should not,
917 // this will return false. If true is returned then the window *may* be
918 // controlled. The caller must still consult either the parent controller
919 // or the ServiceWorkerManager to determine if a service worker should
920 // actually control the window.
921 bool ServiceWorkerAllowedToControlWindow(nsIPrincipal
* aPrincipal
,
924 // Return the ClientInfo for the initial about:blank window, if it exists
925 // or we have speculatively created a ClientSource in
926 // MaybeCreateInitialClientSource(). This can return a ClientInfo object
927 // even if GetExtantDoc() returns nullptr.
928 mozilla::Maybe
<mozilla::dom::ClientInfo
> GetInitialClientInfo() const;
931 * Initializes mTiming if it isn't yet.
932 * After calling this, mTiming is non-null. This method returns true if the
933 * initialization of the Timing can be reset (basically this is true if a new
934 * Timing object is created).
935 * In case the loading is aborted, MaybeResetInitTiming() can be called
936 * passing the return value of MaybeInitTiming(): if it's possible to reset
937 * the Timing, this method will do it.
939 [[nodiscard
]] bool MaybeInitTiming();
940 void MaybeResetInitTiming(bool aReset
);
942 // Convenience method for getting our parent docshell. Can return null
943 already_AddRefed
<nsDocShell
> GetInProcessParentDocshell();
945 // Internal implementation of nsIDocShell::FirePageHideNotification.
946 // If aSkipCheckingDynEntries is true, it will not try to remove dynamic
947 // subframe entries. This is to avoid redundant RemoveDynEntries calls in all
948 // children docshells.
949 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
950 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void FirePageHideNotificationInternal(
951 bool aIsUnload
, bool aSkipCheckingDynEntries
);
953 void ThawFreezeNonRecursive(bool aThaw
);
954 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
955 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void FirePageHideShowNonRecursive(bool aShow
);
957 nsresult
Dispatch(already_AddRefed
<nsIRunnable
>&& aRunnable
);
959 void ReattachEditorToWindow(nsISHEntry
* aSHEntry
);
960 void ClearFrameHistory(nsISHEntry
* aEntry
);
961 // Determine if this type of load should update history.
962 static bool ShouldUpdateGlobalHistory(uint32_t aLoadType
);
963 void UpdateGlobalHistoryTitle(nsIURI
* aURI
);
964 bool IsSubframe() { return mBrowsingContext
->IsSubframe(); }
965 bool CanSetOriginAttributes();
966 bool ShouldBlockLoadingForBackButton();
967 static bool ShouldDiscardLayoutState(nsIHttpChannel
* aChannel
);
968 bool HasUnloadedParent();
969 bool JustStartedNetworkLoad();
970 bool NavigationBlockedByPrinting(bool aDisplayErrorDialog
= true);
971 bool IsNavigationAllowed(bool aDisplayPrintErrorDialog
= true,
972 bool aCheckIfUnloadFired
= true);
973 nsIScrollableFrame
* GetRootScrollFrame();
974 nsIChannel
* GetCurrentDocChannel();
975 nsresult
EnsureScriptEnvironment();
976 nsresult
EnsureEditorData();
977 nsresult
EnsureTransferableHookData();
978 nsresult
EnsureFind();
979 nsresult
EnsureCommandHandler();
980 nsresult
RefreshURIFromQueue();
981 void RefreshURIToQueue();
982 nsresult
Embed(nsIDocumentViewer
* aDocumentViewer
,
983 mozilla::dom::WindowGlobalChild
* aWindowActor
,
984 bool aIsTransientAboutBlank
, bool aPersist
,
985 nsIRequest
* aRequest
, nsIURI
* aPreviousURI
);
986 nsPresContext
* GetEldestPresContext();
987 nsresult
CheckLoadingPermissions();
988 nsresult
LoadHistoryEntry(nsISHEntry
* aEntry
, uint32_t aLoadType
,
989 bool aUserActivation
);
990 nsresult
LoadHistoryEntry(
991 const mozilla::dom::LoadingSessionHistoryInfo
& aEntry
, uint32_t aLoadType
,
992 bool aUserActivation
);
993 nsresult
LoadHistoryEntry(nsDocShellLoadState
* aLoadState
, uint32_t aLoadType
,
994 bool aLoadingCurrentEntry
);
995 nsresult
GetHttpChannel(nsIChannel
* aChannel
, nsIHttpChannel
** aReturn
);
996 nsresult
ConfirmRepost(bool* aRepost
);
997 nsresult
GetPromptAndStringBundle(nsIPrompt
** aPrompt
,
998 nsIStringBundle
** aStringBundle
);
999 nsresult
SetCurScrollPosEx(int32_t aCurHorizontalPos
,
1000 int32_t aCurVerticalPos
);
1001 nsPoint
GetCurScrollPos();
1003 already_AddRefed
<mozilla::dom::ChildSHistory
> GetRootSessionHistory();
1005 bool CSSErrorReportingEnabled() const { return mCSSErrorReportingEnabled
; }
1007 // Handles retrieval of subframe session history for nsDocShell::LoadURI. If a
1008 // load is requested in a subframe of the current DocShell, the subframe
1009 // loadType may need to reflect the loadType of the parent document, or in
1010 // some cases (like reloads), the history load may need to be cancelled. See
1011 // function comments for in-depth logic descriptions.
1012 // Returns true if the method itself deals with the load.
1013 bool MaybeHandleSubframeHistory(nsDocShellLoadState
* aLoadState
,
1014 bool aContinueHandlingSubframeHistory
);
1016 // If we are passed a named target during InternalLoad, this method handles
1017 // moving the load to the browsing context the target name resolves to.
1018 nsresult
PerformRetargeting(nsDocShellLoadState
* aLoadState
);
1020 // Returns one of nsIContentPolicy::TYPE_DOCUMENT,
1021 // nsIContentPolicy::TYPE_INTERNAL_IFRAME, or
1022 // nsIContentPolicy::TYPE_INTERNAL_FRAME depending on who is responsible for
1024 nsContentPolicyType
DetermineContentType();
1026 // If this is an iframe, and the embedder is OOP, then notifes the
1027 // embedder that loading has finished and we shouldn't be blocking
1028 // load of the embedder. Only called when we fail to load, as we wait
1029 // for the load event of our Document before notifying success.
1031 // If aFireFrameErrorEvent is true, then fires an error event at the
1032 // embedder element, for both in-process and OOP embedders.
1033 void UnblockEmbedderLoadEventForFailure(bool aFireFrameErrorEvent
= false);
1035 struct SameDocumentNavigationState
{
1036 nsAutoCString mCurrentHash
;
1037 nsAutoCString mNewHash
;
1038 bool mCurrentURIHasRef
= false;
1039 bool mNewURIHasRef
= false;
1040 bool mSameExceptHashes
= false;
1041 bool mSecureUpgradeURI
= false;
1042 bool mHistoryNavBetweenSameDoc
= false;
1045 // Check to see if we're loading a prior history entry or doing a fragment
1046 // navigation in the same document.
1047 // NOTE: In case we are doing a fragment navigation, and HTTPS-Only/ -First
1048 // mode is enabled and upgraded the underlying document, we update the URI of
1049 // aLoadState from HTTP to HTTPS (if neccessary).
1050 bool IsSameDocumentNavigation(nsDocShellLoadState
* aLoadState
,
1051 SameDocumentNavigationState
& aState
);
1053 // ... If so, handle the scrolling or other action required instead of
1054 // continuing with new document navigation.
1056 nsresult
HandleSameDocumentNavigation(nsDocShellLoadState
* aLoadState
,
1057 SameDocumentNavigationState
& aState
,
1058 bool& aSameDocument
);
1060 uint32_t GetSameDocumentNavigationFlags(nsIURI
* aNewURI
);
1062 // Called when the Private Browsing state of a nsDocShell changes.
1063 void NotifyPrivateBrowsingChanged();
1065 // Internal helpers for BrowsingContext to pass update values to nsIDocShell's
1067 void SetLoadGroupDefaultLoadFlags(nsLoadFlags aLoadFlags
);
1069 void SetTitleOnHistoryEntry(bool aUpdateEntryInSessionHistory
);
1071 void SetScrollRestorationIsManualOnHistoryEntry(nsISHEntry
* aSHEntry
,
1074 void SetCacheKeyOnHistoryEntry(nsISHEntry
* aSHEntry
, uint32_t aCacheKey
);
1076 // If the LoadState's URI is a javascript: URI, checks that the triggering
1077 // principal subsumes the principal of the current document, and returns
1078 // NS_ERROR_DOM_BAD_CROSS_ORIGIN_URI if it does not.
1079 nsresult
CheckDisallowedJavascriptLoad(nsDocShellLoadState
* aLoadState
);
1081 nsresult
LoadURI(nsDocShellLoadState
* aLoadState
, bool aSetNavigating
,
1082 bool aContinueHandlingSubframeHistory
);
1084 // Sets the active entry to the current loading entry. aPersist is used in the
1085 // case a new session history entry is added to the session history.
1086 // aExpired is true if the relevant nsIChannel has its cache token expired.
1087 // aCacheKey is the channel's cache key.
1088 // aPreviousURI should be the URI that was previously loaded into the
1090 void MoveLoadingToActiveEntry(bool aPersist
, bool aExpired
,
1091 uint32_t aCacheKey
, nsIURI
* aPreviousURI
);
1093 void ActivenessMaybeChanged();
1096 * Returns true if `noopener` will be force-enabled by any attempt to create
1097 * a popup window, even if rel="opener" is requested.
1099 bool NoopenerForceEnabled();
1101 bool ShouldOpenInBlankTarget(const nsAString
& aOriginalTarget
,
1102 nsIURI
* aLinkURI
, nsIContent
* aContent
,
1103 bool aIsUserTriggered
);
1105 void RecordSingleChannelId(bool aStartRequest
, nsIRequest
* aRequest
);
1107 void SetChannelToDisconnectOnPageHide(uint64_t aChannelId
) {
1108 MOZ_ASSERT(mChannelToDisconnectOnPageHide
== 0);
1109 mChannelToDisconnectOnPageHide
= aChannelId
;
1111 void MaybeDisconnectChildListenersOnPageHide();
1114 * Helper for addState and document.open that does just the
1115 * history-manipulation guts.
1117 * Arguments the spec defines:
1119 * @param aDocument the document we're manipulating. This will get the new
1121 * @param aNewURI the new URI.
1122 * @param aData The serialized state data. May be null.
1123 * @param aTitle The new title. May be empty.
1124 * @param aReplace whether this should replace the exising SHEntry.
1126 * Arguments we need internally because deriving them from the
1127 * others is a bit complicated:
1129 * @param aCurrentURI the current URI we're working with. Might be null.
1130 * @param aEqualURIs whether the two URIs involved are equal.
1132 nsresult
UpdateURLAndHistory(mozilla::dom::Document
* aDocument
,
1134 nsIStructuredCloneContainer
* aData
,
1135 const nsAString
& aTitle
, bool aReplace
,
1136 nsIURI
* aCurrentURI
, bool aEqualURIs
);
1139 void SetCurrentURIInternal(nsIURI
* aURI
);
1143 nsCString mOriginalUriString
;
1144 nsTObserverArray
<nsWeakPtr
> mPrivacyObservers
;
1145 nsTObserverArray
<nsWeakPtr
> mReflowObservers
;
1146 nsTObserverArray
<nsWeakPtr
> mScrollObservers
;
1147 mozilla::UniquePtr
<mozilla::dom::ClientSource
> mInitialClientSource
;
1148 nsCOMPtr
<nsINetworkInterceptController
> mInterceptController
;
1149 RefPtr
<nsDOMNavigationTiming
> mTiming
;
1150 RefPtr
<nsDSURIContentListener
> mContentListener
;
1151 RefPtr
<nsGlobalWindowOuter
> mScriptGlobal
;
1152 nsCOMPtr
<nsIPrincipal
> mParentCharsetPrincipal
;
1153 // The following 3 lists contain either nsITimer or nsRefreshTimer objects.
1154 // URIs to refresh are collected to mRefreshURIList.
1155 nsCOMPtr
<nsIMutableArray
> mRefreshURIList
;
1156 // mSavedRefreshURIList is used to move the entries from mRefreshURIList to
1158 nsCOMPtr
<nsIMutableArray
> mSavedRefreshURIList
;
1159 // BFCache-in-parent implementation caches the entries in
1160 // mBFCachedRefreshURIList.
1161 nsCOMPtr
<nsIMutableArray
> mBFCachedRefreshURIList
;
1162 uint64_t mContentWindowID
;
1163 nsCOMPtr
<nsIDocumentViewer
> mDocumentViewer
;
1164 nsCOMPtr
<nsIWidget
> mParentWidget
;
1165 RefPtr
<mozilla::dom::ChildSHistory
> mSessionHistory
;
1166 nsCOMPtr
<nsIWebBrowserFind
> mFind
;
1167 RefPtr
<nsCommandManager
> mCommandManager
;
1168 RefPtr
<mozilla::dom::BrowsingContext
> mBrowsingContext
;
1170 // Weak reference to our BrowserChild actor.
1171 nsWeakPtr mBrowserChild
;
1173 // Dimensions of the docshell
1177 * Content-Type Hint of the most-recently initiated load. Used for
1178 * session history entries.
1180 nsCString mContentTypeHint
;
1182 // mCurrentURI should be marked immutable on set if possible.
1183 // Change mCurrentURI only through SetCurrentURIInternal method.
1184 nsCOMPtr
<nsIURI
> mCurrentURI
;
1185 nsCOMPtr
<nsIReferrerInfo
> mReferrerInfo
;
1188 // We're counting the number of |nsDocShells| to help find leaks
1189 static unsigned long gNumberOfDocShells
;
1191 nsCOMPtr
<nsIURI
> mLastOpenedURI
;
1194 // Reference to the SHEntry for this docshell until the page is destroyed.
1195 // Somebody give me better name
1196 // Only used when SHIP is disabled.
1197 nsCOMPtr
<nsISHEntry
> mOSHE
;
1199 // Reference to the SHEntry for this docshell until the page is loaded
1200 // Somebody give me better name.
1201 // If mLSHE is non-null, non-pushState subframe loads don't create separate
1202 // root history entries. That is, frames loaded during the parent page
1203 // load don't generate history entries the way frame navigation after the
1204 // parent has loaded does. (This isn't the only purpose of mLSHE.)
1205 // Only used when SHIP is disabled.
1206 nsCOMPtr
<nsISHEntry
> mLSHE
;
1208 // These are only set when fission.sessionHistoryInParent is set.
1209 mozilla::UniquePtr
<mozilla::dom::SessionHistoryInfo
> mActiveEntry
;
1210 bool mActiveEntryIsLoadingFromSessionHistory
= false;
1211 // mLoadingEntry is set when we're about to start loading. Whenever
1212 // setting mLoadingEntry, be sure to also set
1213 // mNeedToReportActiveAfterLoadingBecomesActive.
1214 mozilla::UniquePtr
<mozilla::dom::LoadingSessionHistoryInfo
> mLoadingEntry
;
1216 // Holds a weak pointer to a RestorePresentationEvent object if any that
1217 // holds a weak pointer back to us. We use this pointer to possibly revoke
1218 // the event whenever necessary.
1219 nsRevocableEventPtr
<RestorePresentationEvent
> mRestorePresentationEvent
;
1221 // Editor data, if this document is designMode or contentEditable.
1222 mozilla::UniquePtr
<nsDocShellEditorData
> mEditorData
;
1224 // The URI we're currently loading. This is only relevant during the
1225 // firing of a pagehide/unload. The caller of FirePageHideNotification()
1226 // is responsible for setting it and unsetting it. It may be null if the
1227 // pagehide/unload is happening for some reason other than just loading a
1229 nsCOMPtr
<nsIURI
> mLoadingURI
;
1231 // Set in LoadErrorPage from the method argument and used later
1232 // in CreateDocumentViewer. We have to delay an shistory entry creation
1233 // for which these objects are needed.
1234 nsCOMPtr
<nsIURI
> mFailedURI
;
1235 nsCOMPtr
<nsIChannel
> mFailedChannel
;
1237 mozilla::UniquePtr
<mozilla::gfx::Matrix5x4
> mColorMatrix
;
1239 const mozilla::Encoding
* mParentCharset
;
1241 // WEAK REFERENCES BELOW HERE.
1242 // Note these are intentionally not addrefd. Doing so will create a cycle.
1243 // For that reasons don't use nsCOMPtr.
1245 nsIDocShellTreeOwner
* mTreeOwner
; // Weak Reference
1247 RefPtr
<mozilla::dom::EventTarget
> mChromeEventHandler
;
1249 mozilla::ScrollbarPreference mScrollbarPref
; // persistent across doc loads
1251 eCharsetReloadState mCharsetReloadState
;
1253 int32_t mParentCharsetSource
;
1254 mozilla::CSSIntSize mFrameMargins
;
1256 // This can either be a content docshell or a chrome docshell.
1257 const int32_t mItemType
;
1259 // Index into the nsISHEntry array, indicating the previous and current
1260 // entry at the time that this DocShell begins to load. Consequently
1261 // root docshell's indices can differ from child docshells'.
1262 int32_t mPreviousEntryIndex
;
1263 int32_t mLoadedEntryIndex
;
1265 BusyFlags mBusyFlags
;
1268 uint32_t mFailedLoadType
;
1270 // See WindowGlobalParent::mSingleChannelId.
1271 mozilla::Maybe
<uint64_t> mSingleChannelId
;
1272 uint32_t mRequestForBlockingFromBFCacheCount
= 0;
1274 uint64_t mChannelToDisconnectOnPageHide
;
1276 uint32_t mPendingReloadCount
= 0;
1278 // The following two fields cannot be declared as bit fields
1279 // because of uses with AutoRestore.
1280 bool mCreatingDocument
; // (should be) debugging only
1282 bool mInEnsureScriptEnv
;
1283 uint64_t mDocShellID
= 0;
1286 bool mInitialized
: 1;
1287 bool mAllowSubframes
: 1;
1288 bool mAllowMetaRedirects
: 1;
1289 bool mAllowImages
: 1;
1290 bool mAllowMedia
: 1;
1291 bool mAllowDNSPrefetch
: 1;
1292 bool mAllowWindowControl
: 1;
1293 bool mCSSErrorReportingEnabled
: 1;
1294 bool mAllowAuth
: 1;
1295 bool mAllowKeywordFixup
: 1;
1296 bool mDisableMetaRefreshWhenInactive
: 1;
1298 bool mWindowDraggingAllowed
: 1;
1299 bool mInFrameSwap
: 1;
1301 // This boolean is set to true right before we fire pagehide and generally
1302 // unset when we embed a new content viewer. While it's true no navigation
1303 // is allowed in this docshell.
1304 bool mFiredUnloadEvent
: 1;
1306 // this flag is for bug #21358. a docshell may load many urls
1307 // which don't result in new documents being created (i.e. a new
1308 // content viewer) we want to make sure we don't call a on load
1309 // event more than once for a given content viewer.
1310 bool mEODForCurrentDocument
: 1;
1311 bool mURIResultedInDocument
: 1;
1313 bool mIsBeingDestroyed
: 1;
1315 bool mIsExecutingOnLoadHandler
: 1;
1317 // Indicates to CreateDocumentViewer() that it is safe to cache the old
1318 // presentation of the page, and to SetupNewViewer() that the old viewer
1319 // should be passed a SHEntry to save itself into.
1320 // Only used with SHIP disabled.
1321 bool mSavingOldViewer
: 1;
1323 bool mInvisible
: 1;
1324 bool mHasLoadedNonBlankURI
: 1;
1326 // This flag means that mTiming has been initialized but nulled out.
1327 // We will check the innerWin's timing before creating a new one
1328 // in MaybeInitTiming()
1329 bool mBlankTiming
: 1;
1331 // This flag indicates when the title is valid for the current URI.
1332 bool mTitleValidForCurrentURI
: 1;
1334 // If mWillChangeProcess is set to true, then when the docshell is destroyed,
1335 // we prepare the browsing context to change process.
1336 bool mWillChangeProcess
: 1;
1338 // This flag indicates whether or not the DocShell is currently executing an
1339 // nsIWebNavigation navigation method.
1340 bool mIsNavigating
: 1;
1342 // Whether we have a pending encoding autodetection request from the
1343 // menu for all encodings.
1344 bool mForcedAutodetection
: 1;
1347 * Set to true if we're checking session history (in the parent process) for
1348 * a possible history load. Used only with iframes.
1350 bool mCheckingSessionHistory
: 1;
1352 // Whether mBrowsingContext->SetActiveSessionHistoryEntry() needs to be called
1353 // when the loading entry becomes the active entry. This is used for the
1354 // initial about:blank-replacing about:blank in order to make the history
1355 // length WPTs pass.
1356 bool mNeedToReportActiveAfterLoadingBecomesActive
: 1;
1359 inline nsISupports
* ToSupports(nsDocShell
* aDocShell
) {
1360 return static_cast<nsIDocumentLoader
*>(aDocShell
);
1363 #endif /* nsDocShell_h__ */