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
);
494 void SetLoadingSessionHistoryInfo(
495 const mozilla::dom::LoadingSessionHistoryInfo
& aLoadingInfo
,
496 bool aNeedToReportActiveAfterLoadingBecomesActive
= false);
497 const mozilla::dom::LoadingSessionHistoryInfo
*
498 GetLoadingSessionHistoryInfo() {
499 return mLoadingEntry
.get();
502 already_AddRefed
<nsIInputStream
> GetPostDataFromCurrentEntry() const;
503 mozilla::Maybe
<uint32_t> GetCacheKeyFromCurrentEntry() const;
505 // Loading and/or active entries are only set when session history
506 // in the parent is on.
507 bool FillLoadStateFromCurrentEntry(nsDocShellLoadState
& aLoadState
);
509 static bool ShouldAddToSessionHistory(nsIURI
* aURI
, nsIChannel
* aChannel
);
511 bool IsOSHE(nsISHEntry
* aEntry
) const { return mOSHE
== aEntry
; }
513 mozilla::dom::ChildSHistory
* GetSessionHistory() {
514 return mBrowsingContext
->GetChildSessionHistory();
517 // This returns true only when using session history in parent.
518 bool IsLoadingFromSessionHistory();
520 NS_IMETHODIMP
OnStartRequest(nsIRequest
* aRequest
) override
;
521 NS_IMETHODIMP
OnStopRequest(nsIRequest
* aRequest
,
522 nsresult aStatusCode
) override
;
524 private: // member functions
525 friend class nsAppShellService
;
526 friend class nsDSURIContentListener
;
527 friend class FramingChecker
;
528 friend class OnLinkClickEvent
;
529 friend class nsIDocShell
;
530 friend class mozilla::dom::BrowsingContext
;
531 friend class mozilla::net::DocumentLoadListener
;
532 friend class nsGlobalWindowOuter
;
534 nsDocShell(mozilla::dom::BrowsingContext
* aBrowsingContext
,
535 uint64_t aContentWindowID
);
537 static inline uint32_t PRTimeToSeconds(PRTime aTimeUsec
) {
538 return uint32_t(aTimeUsec
/ PR_USEC_PER_SEC
);
541 virtual ~nsDocShell();
547 virtual void DestroyChildren() override
;
549 // Overridden from nsDocLoader, this provides more information than the
550 // normal OnStateChange with flags STATE_REDIRECTING
551 virtual void OnRedirectStateChange(nsIChannel
* aOldChannel
,
552 nsIChannel
* aNewChannel
,
553 uint32_t aRedirectFlags
,
554 uint32_t aStateFlags
) override
;
556 // Override the parent setter from nsDocLoader
557 virtual nsresult
SetDocLoaderParent(nsDocLoader
* aLoader
) override
;
560 // Content Viewer Management
563 nsresult
EnsureDocumentViewer();
565 // aPrincipal can be passed in if the caller wants. If null is
566 // passed in, the about:blank principal will end up being used.
567 // aCSP, if any, will be used for the new about:blank load.
568 nsresult
CreateAboutBlankDocumentViewer(
569 nsIPrincipal
* aPrincipal
, nsIPrincipal
* aPartitionedPrincipal
,
570 nsIContentSecurityPolicy
* aCSP
, nsIURI
* aBaseURI
, bool aIsInitialDocument
,
571 const mozilla::Maybe
<nsILoadInfo::CrossOriginEmbedderPolicy
>& aCOEP
=
573 bool aTryToSaveOldPresentation
= true, bool aCheckPermitUnload
= true,
574 mozilla::dom::WindowGlobalChild
* aActor
= nullptr);
576 nsresult
CreateDocumentViewer(const nsACString
& aContentType
,
577 nsIRequest
* aRequest
,
578 nsIStreamListener
** aContentHandler
);
580 nsresult
NewDocumentViewerObj(const nsACString
& aContentType
,
581 nsIRequest
* aRequest
, nsILoadGroup
* aLoadGroup
,
582 nsIStreamListener
** aContentHandler
,
583 nsIDocumentViewer
** aViewer
);
585 already_AddRefed
<nsILoadURIDelegate
> GetLoadURIDelegate();
587 nsresult
SetupNewViewer(
588 nsIDocumentViewer
* aNewViewer
,
589 mozilla::dom::WindowGlobalChild
* aWindowActor
= nullptr);
595 // Either aChannel or aOwner must be null. If aChannel is
596 // present, the owner should be gotten from it.
597 // If aCloneChildren is true, then our current session history's
598 // children will be cloned onto the new entry. This should be
599 // used when we aren't actually changing the document while adding
600 // the new session history entry.
601 // aCsp is the CSP to be used for the load. That is *not* the CSP
602 // that will be applied to subresource loads within that document
603 // but the CSP for the document load itself. E.g. if that CSP
604 // includes upgrade-insecure-requests, then the new top-level load
605 // will be upgraded to HTTPS.
606 nsresult
AddToSessionHistory(nsIURI
* aURI
, nsIChannel
* aChannel
,
607 nsIPrincipal
* aTriggeringPrincipal
,
608 nsIPrincipal
* aPrincipalToInherit
,
609 nsIPrincipal
* aPartitionedPrincipalToInherit
,
610 nsIContentSecurityPolicy
* aCsp
,
611 bool aCloneChildren
, nsISHEntry
** aNewEntry
);
613 void UpdateActiveEntry(
614 bool aReplace
, const mozilla::Maybe
<nsPoint
>& aPreviousScrollPos
,
615 nsIURI
* aURI
, nsIURI
* aOriginalURI
, nsIReferrerInfo
* aReferrerInfo
,
616 nsIPrincipal
* aTriggeringPrincipal
, nsIContentSecurityPolicy
* aCsp
,
617 const nsAString
& aTitle
, bool aScrollRestorationIsManual
,
618 nsIStructuredCloneContainer
* aData
, bool aURIWasModified
);
620 nsresult
AddChildSHEntry(nsISHEntry
* aCloneRef
, nsISHEntry
* aNewEntry
,
621 int32_t aChildOffset
, uint32_t aLoadType
,
622 bool aCloneChildren
);
624 nsresult
AddChildSHEntryToParent(nsISHEntry
* aNewEntry
, int32_t aChildOffset
,
625 bool aCloneChildren
);
627 // Call this method to swap in a new history entry to m[OL]SHE, rather than
628 // setting it directly. This completes the navigation in all docshells
629 // in the case of a subframe navigation.
630 // Returns old mOSHE/mLSHE.
631 already_AddRefed
<nsISHEntry
> SetHistoryEntry(nsCOMPtr
<nsISHEntry
>* aPtr
,
634 // This method calls SetHistoryEntry and updates mOSHE and mLSHE in BC to be
635 // the same as in docshell
636 void SetHistoryEntryAndUpdateBC(const mozilla::Maybe
<nsISHEntry
*>& aLSHE
,
637 const mozilla::Maybe
<nsISHEntry
*>& aOSHE
);
639 // If aNotifiedBeforeUnloadListeners is true, "beforeunload" event listeners
640 // were notified by the caller and given the chance to abort the navigation,
641 // and should not be notified again.
642 static nsresult
ReloadDocument(
643 nsDocShell
* aDocShell
, mozilla::dom::Document
* aDocument
,
644 uint32_t aLoadType
, mozilla::dom::BrowsingContext
* aBrowsingContext
,
645 nsIURI
* aCurrentURI
, nsIReferrerInfo
* aReferrerInfo
,
646 bool aNotifiedBeforeUnloadListeners
= false);
649 bool IsAboutBlankLoadOntoInitialAboutBlank(nsIURI
* aURI
,
650 bool aInheritPrincipal
,
651 nsIPrincipal
* aPrincipalToInherit
);
658 // Actually open a channel and perform a URI load. Callers need to pass a
659 // non-null aLoadState->TriggeringPrincipal() which initiated the URI load.
660 // Please note that the TriggeringPrincipal will be used for performing
661 // security checks. If aLoadState->URI() is provided by the web, then please
662 // do not pass a SystemPrincipal as the triggeringPrincipal. If
663 // aLoadState()->PrincipalToInherit is null, then no inheritance of any sort
664 // will happen and the load will get a principal based on the URI being
665 // loaded. If the Srcdoc flag is set (INTERNAL_LOAD_FLAGS_IS_SRCDOC), the load
666 // will be considered as a srcdoc load, and the contents of Srcdoc will be
667 // loaded instead of the URI. aLoadState->OriginalURI() will be set as the
668 // originalURI on the channel that does the load. If OriginalURI is null, URI
669 // will be set as the originalURI. If LoadReplace is true, LOAD_REPLACE flag
670 // will be set on the nsIChannel.
671 // If `aCacheKey` is supplied, use it for the session history entry.
672 nsresult
DoURILoad(nsDocShellLoadState
* aLoadState
,
673 mozilla::Maybe
<uint32_t> aCacheKey
, nsIRequest
** aRequest
);
675 static nsresult
AddHeadersToChannel(nsIInputStream
* aHeadersData
,
676 nsIChannel
* aChannel
);
678 nsresult
OpenInitializedChannel(nsIChannel
* aChannel
,
679 nsIURILoader
* aURILoader
,
680 uint32_t aOpenFlags
);
681 nsresult
OpenRedirectedChannel(nsDocShellLoadState
* aLoadState
);
683 void UpdateMixedContentChannelForNewLoad(nsIChannel
* aChannel
);
686 nsresult
ScrollToAnchor(bool aCurHasRef
, bool aNewHasRef
,
687 nsACString
& aNewHash
, uint32_t aLoadType
);
689 // This returns the load type for a form submission (see
690 // https://html.spec.whatwg.org/#form-submission-algorithm). The load type
691 // should be set as soon as the target BC has been determined.
692 uint32_t GetLoadTypeForFormSubmission(
693 mozilla::dom::BrowsingContext
* aTargetBC
,
694 nsDocShellLoadState
* aLoadState
);
697 // Returns true if it is the caller's responsibility to ensure
698 // FireOnLocationChange is called.
699 // In all other cases false is returned.
700 // Either aChannel or aTriggeringPrincipal must be null. If aChannel is
701 // present, the owner should be gotten from it.
702 // If OnNewURI calls AddToSessionHistory, it will pass its
703 // aCloneSHChildren argument as aCloneChildren.
704 // aCsp is the CSP to be used for the load. That is *not* the CSP
705 // that will be applied to subresource loads within that document
706 // but the CSP for the document load itself. E.g. if that CSP
707 // includes upgrade-insecure-requests, then the new top-level load
708 // will be upgraded to HTTPS.
709 bool OnNewURI(nsIURI
* aURI
, nsIChannel
* aChannel
,
710 nsIPrincipal
* aTriggeringPrincipal
,
711 nsIPrincipal
* aPrincipalToInherit
,
712 nsIPrincipal
* aPartitionedPrincipalToInherit
,
713 nsIContentSecurityPolicy
* aCsp
, bool aAddToGlobalHistory
,
714 bool aCloneSHChildren
);
717 // If wireframe collection is enabled, will attempt to gather the
718 // wireframe for the document.
719 mozilla::Maybe
<mozilla::dom::Wireframe
> GetWireframe();
721 // If wireframe collection is enabled, will attempt to gather the
722 // wireframe for the document and stash it inside of the active history
723 // entry. Returns true if wireframes were collected.
724 bool CollectWireframe();
726 // Helper method that is called when a new document (including any
727 // sub-documents - ie. frames) has been completely loaded.
728 MOZ_CAN_RUN_SCRIPT_BOUNDARY
729 nsresult
EndPageLoad(nsIWebProgress
* aProgress
, nsIChannel
* aChannel
,
732 // Builds an error page URI (e.g. about:neterror?etc) for the given aURI
733 // and displays it via the LoadErrorPage() overload below.
734 nsresult
LoadErrorPage(nsIURI
* aURI
, const char16_t
* aURL
,
735 const char* aErrorPage
, const char* aErrorType
,
736 const char16_t
* aDescription
, const char* aCSSClass
,
737 nsIChannel
* aFailedChannel
);
739 // This method directly loads aErrorURI as an error page. aFailedURI and
740 // aFailedChannel come from DisplayLoadError() or the LoadErrorPage() overload
742 nsresult
LoadErrorPage(nsIURI
* aErrorURI
, nsIURI
* aFailedURI
,
743 nsIChannel
* aFailedChannel
);
745 bool DisplayLoadError(nsresult aError
, nsIURI
* aURI
, const char16_t
* aURL
,
746 nsIChannel
* aFailedChannel
) {
747 bool didDisplayLoadError
= false;
748 DisplayLoadError(aError
, aURI
, aURL
, aFailedChannel
, &didDisplayLoadError
);
749 return didDisplayLoadError
;
756 // Get the principal that we'll set on the channel if we're inheriting. If
757 // aConsiderCurrentDocument is true, we try to use the current document if
758 // at all possible. If that fails, we fall back on the parent document.
759 // If that fails too, we force creation of a content viewer and use the
760 // resulting principal. If aConsiderCurrentDocument is false, we just look
762 // If aConsiderPartitionedPrincipal is true, we consider the partitioned
763 // principal instead of the node principal.
764 nsIPrincipal
* GetInheritedPrincipal(
765 bool aConsiderCurrentDocument
,
766 bool aConsiderPartitionedPrincipal
= false);
769 * Helper function that caches a URI and a transition for saving later.
772 * Channel that will have these properties saved
774 * The URI to save for later
775 * @param aChannelRedirectFlags
776 * The nsIChannelEventSink redirect flags to save for later
778 static void SaveLastVisit(nsIChannel
* aChannel
, nsIURI
* aURI
,
779 uint32_t aChannelRedirectFlags
);
782 * Helper function for adding a URI visit using IHistory.
784 * The IHistory API maintains chains of visits, tracking both HTTP referrers
785 * and redirects for a user session. VisitURI requires the current URI and
786 * the previous URI in the chain.
788 * Visits can be saved either during a redirect or when the request has
789 * reached its final destination. The previous URI in the visit may be
790 * from another redirect.
792 * @pre aURI is not null.
795 * The URI that was just visited
796 * @param aPreviousURI
797 * The previous URI of this visit
798 * @param aChannelRedirectFlags
799 * For redirects, the redirect flags from nsIChannelEventSink
801 * @param aResponseStatus
802 * For HTTP channels, the response code (0 otherwise).
804 void AddURIVisit(nsIURI
* aURI
, nsIURI
* aPreviousURI
,
805 uint32_t aChannelRedirectFlags
,
806 uint32_t aResponseStatus
= 0);
809 * Internal helper funtion
811 static void InternalAddURIVisit(
812 nsIURI
* aURI
, nsIURI
* aPreviousURI
, uint32_t aChannelRedirectFlags
,
813 uint32_t aResponseStatus
, mozilla::dom::BrowsingContext
* aBrowsingContext
,
814 nsIWidget
* aWidget
, uint32_t aLoadType
, bool aWasUpgraded
);
816 static already_AddRefed
<nsIURIFixupInfo
> KeywordToURI(
817 const nsACString
& aKeyword
, bool aIsPrivateContext
);
819 // Sets the current document's current state object to the given SHEntry's
820 // state object. The current state object is eventually given to the page
821 // in the PopState event.
822 void SetDocCurrentStateObj(nsISHEntry
* aShEntry
,
823 mozilla::dom::SessionHistoryInfo
* aInfo
);
825 // Returns true if would have called FireOnLocationChange,
826 // but did not because aFireOnLocationChange was false on entry.
827 // In this case it is the caller's responsibility to ensure
828 // FireOnLocationChange is called.
829 // In all other cases false is returned.
830 bool SetCurrentURI(nsIURI
* aURI
, nsIRequest
* aRequest
,
831 bool aFireOnLocationChange
, bool aIsInitialAboutBlank
,
832 uint32_t aLocationFlags
);
834 // The following methods deal with saving and restoring content viewers
835 // in session history.
837 // mDocumentViewer points to the current content viewer associated with
838 // this docshell. When loading a new document, the content viewer is
839 // either destroyed or stored into a session history entry. To make sure
840 // that destruction happens in a controlled fashion, a given content viewer
841 // is always owned in exactly one of these ways:
842 // 1) The content viewer is active and owned by a docshell's
844 // 2) The content viewer is still being displayed while we begin loading
845 // a new document. The content viewer is owned by the _new_
846 // content viewer's mPreviousViewer, and has a pointer to the
847 // nsISHEntry where it will eventually be stored. The content viewer
848 // has been close()d by the docshell, which detaches the document from
849 // the window object.
850 // 3) The content viewer is cached in session history. The nsISHEntry
851 // has the only owning reference to the content viewer. The viewer
852 // has released its nsISHEntry pointer to prevent circular ownership.
854 // When restoring a content viewer from session history, open() is called
855 // to reattach the document to the window object. The content viewer is
856 // then placed into mDocumentViewer and removed from the history entry.
857 // (mDocumentViewer is put into session history as described above, if
860 // Determines whether we can safely cache the current mDocumentViewer in
861 // session history. This checks a number of factors such as cache policy,
862 // pending requests, and unload handlers.
863 // |aLoadType| should be the load type that will replace the current
864 // presentation. |aNewRequest| should be the request for the document to
865 // be loaded in place of the current document, or null if such a request
866 // has not been created yet. |aNewDocument| should be the document that will
867 // replace the current document.
868 bool CanSavePresentation(uint32_t aLoadType
, nsIRequest
* aNewRequest
,
869 mozilla::dom::Document
* aNewDocument
,
870 bool aReportBFCacheComboTelemetry
);
872 static void ReportBFCacheComboTelemetry(uint32_t aCombo
);
874 // Captures the state of the supporting elements of the presentation
875 // (the "window" object, docshell tree, meta-refresh loads, and security
876 // state) and stores them on |mOSHE|.
877 nsresult
CaptureState();
879 // Begin the toplevel restore process for |aSHEntry|.
880 // This simulates a channel open, and defers the real work until
881 // RestoreFromHistory is called from a PLEvent.
882 nsresult
RestorePresentation(nsISHEntry
* aSHEntry
, bool* aRestoring
);
884 // Call BeginRestore(nullptr, false) for each child of this shell.
885 nsresult
BeginRestoreChildren();
887 // Method to get our current position and size without flushing
888 void DoGetPositionAndSize(int32_t* aX
, int32_t* aY
, int32_t* aWidth
,
891 // Call this when a URI load is handed to us (via OnLinkClick or
892 // InternalLoad). This makes sure that we're not inside unload, or that if
893 // we are it's still OK to load this URI.
894 bool IsOKToLoadURI(nsIURI
* aURI
);
896 // helpers for executing commands
897 nsresult
GetControllerForCommand(const char* aCommand
,
898 nsIController
** aResult
);
900 // Possibly create a ClientSource object to represent an initial about:blank
901 // window that has not been allocated yet. Normally we try not to create
902 // this about:blank window until something calls GetDocument(). We still need
903 // the ClientSource to exist for this conceptual window, though.
905 // The ClientSource is created with the given principal if specified. If
906 // the principal is not provided we will attempt to inherit it when we
907 // are sure it will match what the real about:blank window principal
908 // would have been. There are some corner cases where we cannot easily
909 // determine the correct principal and will not create the ClientSource.
910 // In these cases the initial about:blank will appear to not exist until
911 // its real document and window are created.
912 void MaybeCreateInitialClientSource(nsIPrincipal
* aPrincipal
= nullptr);
914 // Determine if a service worker is allowed to control a window in this
915 // docshell with the given URL. If there are any reasons it should not,
916 // this will return false. If true is returned then the window *may* be
917 // controlled. The caller must still consult either the parent controller
918 // or the ServiceWorkerManager to determine if a service worker should
919 // actually control the window.
920 bool ServiceWorkerAllowedToControlWindow(nsIPrincipal
* aPrincipal
,
923 // Return the ClientInfo for the initial about:blank window, if it exists
924 // or we have speculatively created a ClientSource in
925 // MaybeCreateInitialClientSource(). This can return a ClientInfo object
926 // even if GetExtantDoc() returns nullptr.
927 mozilla::Maybe
<mozilla::dom::ClientInfo
> GetInitialClientInfo() const;
930 * Initializes mTiming if it isn't yet.
931 * After calling this, mTiming is non-null. This method returns true if the
932 * initialization of the Timing can be reset (basically this is true if a new
933 * Timing object is created).
934 * In case the loading is aborted, MaybeResetInitTiming() can be called
935 * passing the return value of MaybeInitTiming(): if it's possible to reset
936 * the Timing, this method will do it.
938 [[nodiscard
]] bool MaybeInitTiming();
939 void MaybeResetInitTiming(bool aReset
);
941 // Convenience method for getting our parent docshell. Can return null
942 already_AddRefed
<nsDocShell
> GetInProcessParentDocshell();
944 // Internal implementation of nsIDocShell::FirePageHideNotification.
945 // If aSkipCheckingDynEntries is true, it will not try to remove dynamic
946 // subframe entries. This is to avoid redundant RemoveDynEntries calls in all
947 // children docshells.
948 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
949 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void FirePageHideNotificationInternal(
950 bool aIsUnload
, bool aSkipCheckingDynEntries
);
952 void ThawFreezeNonRecursive(bool aThaw
);
953 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
954 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void FirePageHideShowNonRecursive(bool aShow
);
956 nsresult
Dispatch(already_AddRefed
<nsIRunnable
>&& aRunnable
);
958 void ReattachEditorToWindow(nsISHEntry
* aSHEntry
);
959 void ClearFrameHistory(nsISHEntry
* aEntry
);
960 // Determine if this type of load should update history.
961 static bool ShouldUpdateGlobalHistory(uint32_t aLoadType
);
962 void UpdateGlobalHistoryTitle(nsIURI
* aURI
);
963 bool IsSubframe() { return mBrowsingContext
->IsSubframe(); }
964 bool CanSetOriginAttributes();
965 bool ShouldBlockLoadingForBackButton();
966 static bool ShouldDiscardLayoutState(nsIHttpChannel
* aChannel
);
967 bool HasUnloadedParent();
968 bool JustStartedNetworkLoad();
969 bool NavigationBlockedByPrinting(bool aDisplayErrorDialog
= true);
970 bool IsNavigationAllowed(bool aDisplayPrintErrorDialog
= true,
971 bool aCheckIfUnloadFired
= true);
972 nsIScrollableFrame
* GetRootScrollFrame();
973 nsIChannel
* GetCurrentDocChannel();
974 nsresult
EnsureScriptEnvironment();
975 nsresult
EnsureEditorData();
976 nsresult
EnsureTransferableHookData();
977 nsresult
EnsureFind();
978 nsresult
EnsureCommandHandler();
979 nsresult
RefreshURIFromQueue();
980 void RefreshURIToQueue();
981 nsresult
Embed(nsIDocumentViewer
* aDocumentViewer
,
982 mozilla::dom::WindowGlobalChild
* aWindowActor
,
983 bool aIsTransientAboutBlank
, bool aPersist
,
984 nsIRequest
* aRequest
, nsIURI
* aPreviousURI
);
985 nsPresContext
* GetEldestPresContext();
986 nsresult
CheckLoadingPermissions();
987 nsresult
LoadHistoryEntry(nsISHEntry
* aEntry
, uint32_t aLoadType
,
988 bool aUserActivation
);
989 nsresult
LoadHistoryEntry(
990 const mozilla::dom::LoadingSessionHistoryInfo
& aEntry
, uint32_t aLoadType
,
991 bool aUserActivation
);
992 nsresult
LoadHistoryEntry(nsDocShellLoadState
* aLoadState
, uint32_t aLoadType
,
993 bool aLoadingCurrentEntry
);
994 nsresult
GetHttpChannel(nsIChannel
* aChannel
, nsIHttpChannel
** aReturn
);
995 nsresult
ConfirmRepost(bool* aRepost
);
996 nsresult
GetPromptAndStringBundle(nsIPrompt
** aPrompt
,
997 nsIStringBundle
** aStringBundle
);
998 nsresult
SetCurScrollPosEx(int32_t aCurHorizontalPos
,
999 int32_t aCurVerticalPos
);
1000 nsPoint
GetCurScrollPos();
1002 already_AddRefed
<mozilla::dom::ChildSHistory
> GetRootSessionHistory();
1004 bool CSSErrorReportingEnabled() const { return mCSSErrorReportingEnabled
; }
1006 // Handles retrieval of subframe session history for nsDocShell::LoadURI. If a
1007 // load is requested in a subframe of the current DocShell, the subframe
1008 // loadType may need to reflect the loadType of the parent document, or in
1009 // some cases (like reloads), the history load may need to be cancelled. See
1010 // function comments for in-depth logic descriptions.
1011 // Returns true if the method itself deals with the load.
1012 bool MaybeHandleSubframeHistory(nsDocShellLoadState
* aLoadState
,
1013 bool aContinueHandlingSubframeHistory
);
1015 // If we are passed a named target during InternalLoad, this method handles
1016 // moving the load to the browsing context the target name resolves to.
1017 nsresult
PerformRetargeting(nsDocShellLoadState
* aLoadState
);
1019 // Returns one of nsIContentPolicy::TYPE_DOCUMENT,
1020 // nsIContentPolicy::TYPE_INTERNAL_IFRAME, or
1021 // nsIContentPolicy::TYPE_INTERNAL_FRAME depending on who is responsible for
1023 nsContentPolicyType
DetermineContentType();
1025 // If this is an iframe, and the embedder is OOP, then notifes the
1026 // embedder that loading has finished and we shouldn't be blocking
1027 // load of the embedder. Only called when we fail to load, as we wait
1028 // for the load event of our Document before notifying success.
1030 // If aFireFrameErrorEvent is true, then fires an error event at the
1031 // embedder element, for both in-process and OOP embedders.
1032 void UnblockEmbedderLoadEventForFailure(bool aFireFrameErrorEvent
= false);
1034 struct SameDocumentNavigationState
{
1035 nsAutoCString mCurrentHash
;
1036 nsAutoCString mNewHash
;
1037 bool mCurrentURIHasRef
= false;
1038 bool mNewURIHasRef
= false;
1039 bool mSameExceptHashes
= false;
1040 bool mSecureUpgradeURI
= false;
1041 bool mHistoryNavBetweenSameDoc
= false;
1044 // Check to see if we're loading a prior history entry or doing a fragment
1045 // navigation in the same document.
1046 // NOTE: In case we are doing a fragment navigation, and HTTPS-Only/ -First
1047 // mode is enabled and upgraded the underlying document, we update the URI of
1048 // aLoadState from HTTP to HTTPS (if neccessary).
1049 bool IsSameDocumentNavigation(nsDocShellLoadState
* aLoadState
,
1050 SameDocumentNavigationState
& aState
);
1052 // ... If so, handle the scrolling or other action required instead of
1053 // continuing with new document navigation.
1055 nsresult
HandleSameDocumentNavigation(nsDocShellLoadState
* aLoadState
,
1056 SameDocumentNavigationState
& aState
,
1057 bool& aSameDocument
);
1059 uint32_t GetSameDocumentNavigationFlags(nsIURI
* aNewURI
);
1061 // Called when the Private Browsing state of a nsDocShell changes.
1062 void NotifyPrivateBrowsingChanged();
1064 // Internal helpers for BrowsingContext to pass update values to nsIDocShell's
1066 void SetLoadGroupDefaultLoadFlags(nsLoadFlags aLoadFlags
);
1068 void SetTitleOnHistoryEntry(bool aUpdateEntryInSessionHistory
);
1070 void SetScrollRestorationIsManualOnHistoryEntry(nsISHEntry
* aSHEntry
,
1073 void SetCacheKeyOnHistoryEntry(nsISHEntry
* aSHEntry
, uint32_t aCacheKey
);
1075 // If the LoadState's URI is a javascript: URI, checks that the triggering
1076 // principal subsumes the principal of the current document, and returns
1077 // NS_ERROR_DOM_BAD_CROSS_ORIGIN_URI if it does not.
1078 nsresult
CheckDisallowedJavascriptLoad(nsDocShellLoadState
* aLoadState
);
1080 nsresult
LoadURI(nsDocShellLoadState
* aLoadState
, bool aSetNavigating
,
1081 bool aContinueHandlingSubframeHistory
);
1083 // Sets the active entry to the current loading entry. aPersist is used in the
1084 // case a new session history entry is added to the session history.
1085 // aExpired is true if the relevant nsIChannel has its cache token expired.
1086 // aCacheKey is the channel's cache key.
1087 // aPreviousURI should be the URI that was previously loaded into the
1089 void MoveLoadingToActiveEntry(bool aPersist
, bool aExpired
,
1090 uint32_t aCacheKey
, nsIURI
* aPreviousURI
);
1092 void ActivenessMaybeChanged();
1095 * Returns true if `noopener` will be force-enabled by any attempt to create
1096 * a popup window, even if rel="opener" is requested.
1098 bool NoopenerForceEnabled();
1100 bool ShouldOpenInBlankTarget(const nsAString
& aOriginalTarget
,
1101 nsIURI
* aLinkURI
, nsIContent
* aContent
,
1102 bool aIsUserTriggered
);
1104 void RecordSingleChannelId(bool aStartRequest
, nsIRequest
* aRequest
);
1106 void SetChannelToDisconnectOnPageHide(uint64_t aChannelId
) {
1107 MOZ_ASSERT(mChannelToDisconnectOnPageHide
== 0);
1108 mChannelToDisconnectOnPageHide
= aChannelId
;
1110 void MaybeDisconnectChildListenersOnPageHide();
1113 * Helper for addState and document.open that does just the
1114 * history-manipulation guts.
1116 * Arguments the spec defines:
1118 * @param aDocument the document we're manipulating. This will get the new
1120 * @param aNewURI the new URI.
1121 * @param aData The serialized state data. May be null.
1122 * @param aTitle The new title. May be empty.
1123 * @param aReplace whether this should replace the exising SHEntry.
1125 * Arguments we need internally because deriving them from the
1126 * others is a bit complicated:
1128 * @param aCurrentURI the current URI we're working with. Might be null.
1129 * @param aEqualURIs whether the two URIs involved are equal.
1131 nsresult
UpdateURLAndHistory(mozilla::dom::Document
* aDocument
,
1133 nsIStructuredCloneContainer
* aData
,
1134 const nsAString
& aTitle
, bool aReplace
,
1135 nsIURI
* aCurrentURI
, bool aEqualURIs
);
1138 void SetCurrentURIInternal(nsIURI
* aURI
);
1142 nsCString mOriginalUriString
;
1143 nsTObserverArray
<nsWeakPtr
> mPrivacyObservers
;
1144 nsTObserverArray
<nsWeakPtr
> mReflowObservers
;
1145 nsTObserverArray
<nsWeakPtr
> mScrollObservers
;
1146 mozilla::UniquePtr
<mozilla::dom::ClientSource
> mInitialClientSource
;
1147 nsCOMPtr
<nsINetworkInterceptController
> mInterceptController
;
1148 RefPtr
<nsDOMNavigationTiming
> mTiming
;
1149 RefPtr
<nsDSURIContentListener
> mContentListener
;
1150 RefPtr
<nsGlobalWindowOuter
> mScriptGlobal
;
1151 nsCOMPtr
<nsIPrincipal
> mParentCharsetPrincipal
;
1152 // The following 3 lists contain either nsITimer or nsRefreshTimer objects.
1153 // URIs to refresh are collected to mRefreshURIList.
1154 nsCOMPtr
<nsIMutableArray
> mRefreshURIList
;
1155 // mSavedRefreshURIList is used to move the entries from mRefreshURIList to
1157 nsCOMPtr
<nsIMutableArray
> mSavedRefreshURIList
;
1158 // BFCache-in-parent implementation caches the entries in
1159 // mBFCachedRefreshURIList.
1160 nsCOMPtr
<nsIMutableArray
> mBFCachedRefreshURIList
;
1161 uint64_t mContentWindowID
;
1162 nsCOMPtr
<nsIDocumentViewer
> mDocumentViewer
;
1163 nsCOMPtr
<nsIWidget
> mParentWidget
;
1164 RefPtr
<mozilla::dom::ChildSHistory
> mSessionHistory
;
1165 nsCOMPtr
<nsIWebBrowserFind
> mFind
;
1166 RefPtr
<nsCommandManager
> mCommandManager
;
1167 RefPtr
<mozilla::dom::BrowsingContext
> mBrowsingContext
;
1169 // Weak reference to our BrowserChild actor.
1170 nsWeakPtr mBrowserChild
;
1172 // Dimensions of the docshell
1176 * Content-Type Hint of the most-recently initiated load. Used for
1177 * session history entries.
1179 nsCString mContentTypeHint
;
1181 // mCurrentURI should be marked immutable on set if possible.
1182 // Change mCurrentURI only through SetCurrentURIInternal method.
1183 nsCOMPtr
<nsIURI
> mCurrentURI
;
1184 nsCOMPtr
<nsIReferrerInfo
> mReferrerInfo
;
1187 // We're counting the number of |nsDocShells| to help find leaks
1188 static unsigned long gNumberOfDocShells
;
1190 nsCOMPtr
<nsIURI
> mLastOpenedURI
;
1193 // Reference to the SHEntry for this docshell until the page is destroyed.
1194 // Somebody give me better name
1195 // Only used when SHIP is disabled.
1196 nsCOMPtr
<nsISHEntry
> mOSHE
;
1198 // Reference to the SHEntry for this docshell until the page is loaded
1199 // Somebody give me better name.
1200 // If mLSHE is non-null, non-pushState subframe loads don't create separate
1201 // root history entries. That is, frames loaded during the parent page
1202 // load don't generate history entries the way frame navigation after the
1203 // parent has loaded does. (This isn't the only purpose of mLSHE.)
1204 // Only used when SHIP is disabled.
1205 nsCOMPtr
<nsISHEntry
> mLSHE
;
1207 // These are only set when fission.sessionHistoryInParent is set.
1208 mozilla::UniquePtr
<mozilla::dom::SessionHistoryInfo
> mActiveEntry
;
1209 bool mActiveEntryIsLoadingFromSessionHistory
= false;
1210 // mLoadingEntry is set when we're about to start loading. Whenever
1211 // setting mLoadingEntry, be sure to also set
1212 // mNeedToReportActiveAfterLoadingBecomesActive.
1213 mozilla::UniquePtr
<mozilla::dom::LoadingSessionHistoryInfo
> mLoadingEntry
;
1215 // Holds a weak pointer to a RestorePresentationEvent object if any that
1216 // holds a weak pointer back to us. We use this pointer to possibly revoke
1217 // the event whenever necessary.
1218 nsRevocableEventPtr
<RestorePresentationEvent
> mRestorePresentationEvent
;
1220 // Editor data, if this document is designMode or contentEditable.
1221 mozilla::UniquePtr
<nsDocShellEditorData
> mEditorData
;
1223 // The URI we're currently loading. This is only relevant during the
1224 // firing of a pagehide/unload. The caller of FirePageHideNotification()
1225 // is responsible for setting it and unsetting it. It may be null if the
1226 // pagehide/unload is happening for some reason other than just loading a
1228 nsCOMPtr
<nsIURI
> mLoadingURI
;
1230 // Set in LoadErrorPage from the method argument and used later
1231 // in CreateDocumentViewer. We have to delay an shistory entry creation
1232 // for which these objects are needed.
1233 nsCOMPtr
<nsIURI
> mFailedURI
;
1234 nsCOMPtr
<nsIChannel
> mFailedChannel
;
1236 mozilla::UniquePtr
<mozilla::gfx::Matrix5x4
> mColorMatrix
;
1238 const mozilla::Encoding
* mParentCharset
;
1240 // WEAK REFERENCES BELOW HERE.
1241 // Note these are intentionally not addrefd. Doing so will create a cycle.
1242 // For that reasons don't use nsCOMPtr.
1244 nsIDocShellTreeOwner
* mTreeOwner
; // Weak Reference
1246 RefPtr
<mozilla::dom::EventTarget
> mChromeEventHandler
;
1248 mozilla::ScrollbarPreference mScrollbarPref
; // persistent across doc loads
1250 eCharsetReloadState mCharsetReloadState
;
1252 int32_t mParentCharsetSource
;
1253 mozilla::CSSIntSize mFrameMargins
;
1255 // This can either be a content docshell or a chrome docshell.
1256 const int32_t mItemType
;
1258 // Index into the nsISHEntry array, indicating the previous and current
1259 // entry at the time that this DocShell begins to load. Consequently
1260 // root docshell's indices can differ from child docshells'.
1261 int32_t mPreviousEntryIndex
;
1262 int32_t mLoadedEntryIndex
;
1264 BusyFlags mBusyFlags
;
1267 uint32_t mFailedLoadType
;
1269 // Whether or not handling of the <meta name="viewport"> tag is overridden.
1270 // Possible values are defined as constants in nsIDocShell.idl.
1271 MetaViewportOverride mMetaViewportOverride
;
1273 // See WindowGlobalParent::mSingleChannelId.
1274 mozilla::Maybe
<uint64_t> mSingleChannelId
;
1275 uint32_t mRequestForBlockingFromBFCacheCount
= 0;
1277 uint64_t mChannelToDisconnectOnPageHide
;
1279 uint32_t mPendingReloadCount
= 0;
1281 // The following two fields cannot be declared as bit fields
1282 // because of uses with AutoRestore.
1283 bool mCreatingDocument
; // (should be) debugging only
1285 bool mInEnsureScriptEnv
;
1286 uint64_t mDocShellID
= 0;
1289 bool mInitialized
: 1;
1290 bool mAllowSubframes
: 1;
1291 bool mAllowMetaRedirects
: 1;
1292 bool mAllowImages
: 1;
1293 bool mAllowMedia
: 1;
1294 bool mAllowDNSPrefetch
: 1;
1295 bool mAllowWindowControl
: 1;
1296 bool mCSSErrorReportingEnabled
: 1;
1297 bool mAllowAuth
: 1;
1298 bool mAllowKeywordFixup
: 1;
1299 bool mDisableMetaRefreshWhenInactive
: 1;
1301 bool mWindowDraggingAllowed
: 1;
1302 bool mInFrameSwap
: 1;
1304 // This boolean is set to true right before we fire pagehide and generally
1305 // unset when we embed a new content viewer. While it's true no navigation
1306 // is allowed in this docshell.
1307 bool mFiredUnloadEvent
: 1;
1309 // this flag is for bug #21358. a docshell may load many urls
1310 // which don't result in new documents being created (i.e. a new
1311 // content viewer) we want to make sure we don't call a on load
1312 // event more than once for a given content viewer.
1313 bool mEODForCurrentDocument
: 1;
1314 bool mURIResultedInDocument
: 1;
1316 bool mIsBeingDestroyed
: 1;
1318 bool mIsExecutingOnLoadHandler
: 1;
1320 // Indicates to CreateDocumentViewer() that it is safe to cache the old
1321 // presentation of the page, and to SetupNewViewer() that the old viewer
1322 // should be passed a SHEntry to save itself into.
1323 // Only used with SHIP disabled.
1324 bool mSavingOldViewer
: 1;
1326 bool mInvisible
: 1;
1327 bool mHasLoadedNonBlankURI
: 1;
1329 // This flag means that mTiming has been initialized but nulled out.
1330 // We will check the innerWin's timing before creating a new one
1331 // in MaybeInitTiming()
1332 bool mBlankTiming
: 1;
1334 // This flag indicates when the title is valid for the current URI.
1335 bool mTitleValidForCurrentURI
: 1;
1337 // If mWillChangeProcess is set to true, then when the docshell is destroyed,
1338 // we prepare the browsing context to change process.
1339 bool mWillChangeProcess
: 1;
1341 // This flag indicates whether or not the DocShell is currently executing an
1342 // nsIWebNavigation navigation method.
1343 bool mIsNavigating
: 1;
1345 // Whether we have a pending encoding autodetection request from the
1346 // menu for all encodings.
1347 bool mForcedAutodetection
: 1;
1350 * Set to true if we're checking session history (in the parent process) for
1351 * a possible history load. Used only with iframes.
1353 bool mCheckingSessionHistory
: 1;
1355 // Whether mBrowsingContext->SetActiveSessionHistoryEntry() needs to be called
1356 // when the loading entry becomes the active entry. This is used for the
1357 // initial about:blank-replacing about:blank in order to make the history
1358 // length WPTs pass.
1359 bool mNeedToReportActiveAfterLoadingBecomesActive
: 1;
1362 inline nsISupports
* ToSupports(nsDocShell
* aDocShell
) {
1363 return static_cast<nsIDocumentLoader
*>(aDocShell
);
1366 #endif /* nsDocShell_h__ */