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/TimelineConsumers.h"
16 #include "mozilla/UniquePtr.h"
17 #include "mozilla/WeakPtr.h"
18 #include "mozilla/dom/BrowsingContext.h"
19 #include "mozilla/dom/WindowProxyHolder.h"
21 #include "nsCharsetSource.h"
22 #include "nsDocLoader.h"
23 #include "nsIAuthPromptProvider.h"
24 #include "nsIBaseWindow.h"
25 #include "nsIDocShell.h"
26 #include "nsIDocShellTreeItem.h"
27 #include "nsIInterfaceRequestor.h"
28 #include "nsILoadContext.h"
29 #include "nsINetworkInterceptController.h"
30 #include "nsIRefreshURI.h"
31 #include "nsIWebNavigation.h"
32 #include "nsIWebPageDescriptor.h"
33 #include "nsIWebProgressListener.h"
34 #include "nsPoint.h" // mCurrent/mDefaultScrollbarPreferences
37 #include "nsThreadUtils.h"
45 class ObservedDocShell
;
46 enum class TaskCategory
;
51 class SessionHistoryInfo
;
52 struct LoadingSessionHistoryInfo
;
57 class DocumentLoadListener
;
59 } // namespace mozilla
61 class nsIContentViewer
;
63 class nsIDocShellTreeOwner
;
65 class nsIMutableArray
;
67 class nsIScrollableFrame
;
68 class nsIStringBundle
;
70 class nsIURIFixupInfo
;
72 class nsIWebBrowserFind
;
74 class nsIReferrerInfo
;
76 class nsCommandManager
;
77 class nsDocShellEditorData
;
78 class nsDOMNavigationTiming
;
79 class nsDSURIContentListener
;
80 class nsGlobalWindowOuter
;
83 class OnLinkClickEvent
;
85 /* internally used ViewMode types */
86 enum ViewMode
{ viewNormal
= 0x0, viewSource
= 0x1 };
88 enum eCharsetReloadState
{
90 eCharsetReloadRequested
,
91 eCharsetReloadStopOrigional
94 class nsDocShell final
: public nsDocLoader
,
96 public nsIWebNavigation
,
99 public nsIWebProgressListener
,
100 public nsIWebPageDescriptor
,
101 public nsIAuthPromptProvider
,
102 public nsILoadContext
,
103 public nsINetworkInterceptController
,
104 public mozilla::SupportsWeakPtr
{
106 enum InternalLoad
: uint32_t {
107 INTERNAL_LOAD_FLAGS_NONE
= 0x0,
108 INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL
= 0x1,
109 INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER
= 0x2,
110 INTERNAL_LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP
= 0x4,
112 // This flag marks the first load in this object
113 // @see nsIWebNavigation::LOAD_FLAGS_FIRST_LOAD
114 INTERNAL_LOAD_FLAGS_FIRST_LOAD
= 0x8,
116 // The set of flags that should not be set before calling into
117 // nsDocShell::LoadURI and other nsDocShell loading functions.
118 INTERNAL_LOAD_FLAGS_LOADURI_SETUP_FLAGS
= 0xf,
120 INTERNAL_LOAD_FLAGS_BYPASS_CLASSIFIER
= 0x10,
121 INTERNAL_LOAD_FLAGS_FORCE_ALLOW_COOKIES
= 0x20,
123 // Whether the load should be treated as srcdoc load, rather than a URI one.
124 INTERNAL_LOAD_FLAGS_IS_SRCDOC
= 0x40,
126 // Whether this is the load of a frame's original src attribute
127 INTERNAL_LOAD_FLAGS_ORIGINAL_FRAME_SRC
= 0x80,
129 INTERNAL_LOAD_FLAGS_NO_OPENER
= 0x100,
131 // Whether a top-level data URI navigation is allowed for that load
132 INTERNAL_LOAD_FLAGS_FORCE_ALLOW_DATA_URI
= 0x200,
134 // Whether the load should go through LoadURIDelegate.
135 INTERNAL_LOAD_FLAGS_BYPASS_LOAD_URI_DELEGATE
= 0x2000,
138 // Event type dispatched by RestorePresentation
139 class RestorePresentationEvent
: public mozilla::Runnable
{
142 explicit RestorePresentationEvent(nsDocShell
* aDs
)
143 : mozilla::Runnable("nsDocShell::RestorePresentationEvent"),
145 void Revoke() { mDocShell
= nullptr; }
148 RefPtr
<nsDocShell
> mDocShell
;
151 class InterfaceRequestorProxy
: public nsIInterfaceRequestor
{
153 explicit InterfaceRequestorProxy(nsIInterfaceRequestor
* aRequestor
);
154 NS_DECL_THREADSAFE_ISUPPORTS
155 NS_DECL_NSIINTERFACEREQUESTOR
158 virtual ~InterfaceRequestorProxy();
159 InterfaceRequestorProxy() = default;
163 NS_DECL_ISUPPORTS_INHERITED
164 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDocShell
, nsDocLoader
)
166 NS_DECL_NSIDOCSHELLTREEITEM
167 NS_DECL_NSIWEBNAVIGATION
168 NS_DECL_NSIBASEWINDOW
169 NS_DECL_NSIINTERFACEREQUESTOR
170 NS_DECL_NSIWEBPROGRESSLISTENER
171 NS_DECL_NSIREFRESHURI
172 NS_DECL_NSIWEBPAGEDESCRIPTOR
173 NS_DECL_NSIAUTHPROMPTPROVIDER
174 NS_DECL_NSINETWORKINTERCEPTCONTROLLER
176 // Create a new nsDocShell object.
177 static already_AddRefed
<nsDocShell
> Create(
178 mozilla::dom::BrowsingContext
* aBrowsingContext
,
179 uint64_t aContentWindowID
= 0);
183 NS_IMETHOD
Stop() override
{
184 // Need this here because otherwise nsIWebNavigation::Stop
185 // overrides the docloader's Stop()
186 return nsDocLoader::Stop();
189 mozilla::ScrollbarPreference
ScrollbarPreference() const {
190 return mScrollbarPref
;
192 void SetScrollbarPreference(mozilla::ScrollbarPreference
);
195 * The size, in CSS pixels, of the margins for the <body> of an HTML document
196 * in this docshell; used to implement the marginwidth attribute on HTML
197 * <frame>/<iframe> elements. A value smaller than zero indicates that the
198 * attribute was not set.
200 const mozilla::CSSIntSize
& GetFrameMargins() const { return mFrameMargins
; }
202 bool UpdateFrameMargins(const mozilla::CSSIntSize
& aMargins
) {
203 if (mFrameMargins
== aMargins
) {
206 mFrameMargins
= aMargins
;
211 * Process a click on a link.
213 * @param aContent the content object used for triggering the link.
214 * @param aURI a URI object that defines the destination for the link
215 * @param aTargetSpec indicates where the link is targeted (may be an empty
217 * @param aFileName non-null when the link should be downloaded as the given
219 * @param aPostDataStream the POST data to send
220 * @param aHeadersDataStream ??? (only used for plugins)
221 * @param aIsTrusted false if the triggerer is an untrusted DOM event.
222 * @param aTriggeringPrincipal, if not passed explicitly we fall back to
223 * the document's principal.
224 * @param aCsp, the CSP to be used for the load, that is the CSP of the
225 * entity responsible for causing the load to occur. Most likely
226 * this is the CSP of the document that started the load. In case
227 * aCsp was not passed explicitly we fall back to using
228 * aContent's document's CSP if that document holds any.
230 nsresult
OnLinkClick(nsIContent
* aContent
, nsIURI
* aURI
,
231 const nsAString
& aTargetSpec
, const nsAString
& aFileName
,
232 nsIInputStream
* aPostDataStream
,
233 nsIInputStream
* aHeadersDataStream
,
234 bool aIsUserTriggered
, bool aIsTrusted
,
235 nsIPrincipal
* aTriggeringPrincipal
,
236 nsIContentSecurityPolicy
* aCsp
);
238 * Process a click on a link.
240 * Works the same as OnLinkClick() except it happens immediately rather than
243 * @param aContent the content object used for triggering the link.
244 * @param aDocShellLoadState the extended load info for this load.
245 * @param aNoOpenerImplied if the link implies "noopener"
246 * @param aTriggeringPrincipal, if not passed explicitly we fall back to
247 * the document's principal.
249 nsresult
OnLinkClickSync(nsIContent
* aContent
,
250 nsDocShellLoadState
* aLoadState
,
251 bool aNoOpenerImplied
,
252 nsIPrincipal
* aTriggeringPrincipal
);
255 * Process a mouse-over a link.
257 * @param aContent the linked content.
258 * @param aURI an URI object that defines the destination for the link
259 * @param aTargetSpec indicates where the link is targeted (it may be an empty
262 nsresult
OnOverLink(nsIContent
* aContent
, nsIURI
* aURI
,
263 const nsAString
& aTargetSpec
);
265 * Process the mouse leaving a link.
267 nsresult
OnLeaveLink();
269 // Don't use NS_DECL_NSILOADCONTEXT because some of nsILoadContext's methods
270 // are shared with nsIDocShell and can't be declared twice.
271 NS_IMETHOD
GetAssociatedWindow(mozIDOMWindowProxy
**) override
;
272 NS_IMETHOD
GetTopWindow(mozIDOMWindowProxy
**) override
;
273 NS_IMETHOD
GetTopFrameElement(mozilla::dom::Element
**) override
;
274 NS_IMETHOD
GetIsContent(bool*) override
;
275 NS_IMETHOD
GetUsePrivateBrowsing(bool*) override
;
276 NS_IMETHOD
SetUsePrivateBrowsing(bool) override
;
277 NS_IMETHOD
SetPrivateBrowsing(bool) override
;
278 NS_IMETHOD
GetUseRemoteTabs(bool*) override
;
279 NS_IMETHOD
SetRemoteTabs(bool) override
;
280 NS_IMETHOD
GetUseRemoteSubframes(bool*) override
;
281 NS_IMETHOD
SetRemoteSubframes(bool) override
;
282 NS_IMETHOD
GetScriptableOriginAttributes(
283 JSContext
*, JS::MutableHandle
<JS::Value
>) override
;
285 GetOriginAttributes(mozilla::OriginAttributes
& aAttrs
) override
;
287 // Restores a cached presentation from history (mLSHE).
288 // This method swaps out the content viewer and simulates loads for
289 // subframes. It then simulates the completion of the toplevel load.
290 nsresult
RestoreFromHistory();
293 * Parses the passed in header string and sets up a refreshURI if a "refresh"
294 * header is found. If docshell is busy loading a page currently, the request
295 * will be queued and executed when the current page finishes loading.
297 * @param aDocument document to which the refresh header applies.
298 * @param aHeader The meta refresh header string.
300 void SetupRefreshURIFromHeader(mozilla::dom::Document
* aDocument
,
301 const nsAString
& aHeader
);
303 // Perform a URI load from a refresh timer. This is just like the
304 // ForceRefreshURI method on nsIRefreshURI, but makes sure to take
305 // the timer involved out of mRefreshURIList if it's there.
306 // aTimer must not be null.
307 nsresult
ForceRefreshURIFromTimer(nsIURI
* aURI
, nsIPrincipal
* aPrincipal
,
308 uint32_t aDelay
, nsITimer
* aTimer
);
310 // We need dummy OnLocationChange in some cases to update the UI without
311 // updating security info.
312 void FireDummyOnLocationChange() {
313 FireOnLocationChange(this, nullptr, mCurrentURI
,
314 LOCATION_CHANGE_SAME_DOCUMENT
);
317 // This function is created exclusively for dom.background_loading_iframe is
318 // set. As soon as the current DocShell knows itself can be treated as
319 // background loading, it triggers the parent docshell to see if the parent
320 // document can fire load event earlier.
321 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
322 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void TriggerParentCheckDocShellIsEmpty();
324 nsresult
HistoryEntryRemoved(int32_t aIndex
);
326 // Notify Scroll observers when an async panning/zooming transform
327 // has started being applied
328 MOZ_CAN_RUN_SCRIPT_BOUNDARY
329 void NotifyAsyncPanZoomStarted();
331 // Notify Scroll observers when an async panning/zooming transform
332 // is no longer applied
333 MOZ_CAN_RUN_SCRIPT_BOUNDARY
334 void NotifyAsyncPanZoomStopped();
336 void SetInFrameSwap(bool aInSwap
) { mInFrameSwap
= aInSwap
; }
339 bool GetForcedAutodetection() { return mForcedAutodetection
; }
341 void ResetForcedAutodetection() { mForcedAutodetection
= false; }
343 mozilla::HTMLEditor
* GetHTMLEditorInternal();
344 nsresult
SetHTMLEditorInternal(mozilla::HTMLEditor
* aHTMLEditor
);
346 // Handle page navigation due to charset changes
347 nsresult
CharsetChangeReloadDocument(
348 mozilla::NotNull
<const mozilla::Encoding
*> aEncoding
, int32_t aSource
);
349 nsresult
CharsetChangeStopDocumentLoad();
351 nsDOMNavigationTiming
* GetNavigationTiming() const;
353 nsresult
SetOriginAttributes(const mozilla::OriginAttributes
& aAttrs
);
355 const mozilla::OriginAttributes
& GetOriginAttributes() {
356 return mBrowsingContext
->OriginAttributesRef();
359 // Determine whether this docshell corresponds to the given history entry,
360 // via having a pointer to it in mOSHE or mLSHE.
361 bool HasHistoryEntry(nsISHEntry
* aEntry
) const {
362 return aEntry
&& (aEntry
== mOSHE
|| aEntry
== mLSHE
);
365 // Update any pointers (mOSHE or mLSHE) to aOldEntry to point to aNewEntry
366 void SwapHistoryEntries(nsISHEntry
* aOldEntry
, nsISHEntry
* aNewEntry
);
368 bool GetCreatedDynamically() const {
369 return mBrowsingContext
&& mBrowsingContext
->CreatedDynamically();
372 mozilla::gfx::Matrix5x4
* GetColorMatrix() { return mColorMatrix
.get(); }
374 static bool SandboxFlagsImplyCookies(const uint32_t& aSandboxFlags
);
376 // Tell the favicon service that aNewURI has the same favicon as aOldURI.
377 static void CopyFavicon(nsIURI
* aOldURI
, nsIURI
* aNewURI
,
378 bool aInPrivateBrowsing
);
380 static nsDocShell
* Cast(nsIDocShell
* aDocShell
) {
381 return static_cast<nsDocShell
*>(aDocShell
);
384 static bool CanLoadInParentProcess(nsIURI
* aURI
);
386 // Returns true if the current load is a force reload (started by holding
387 // shift while triggering reload)
388 bool IsForceReloading();
390 mozilla::dom::WindowProxyHolder
GetWindowProxy() {
391 EnsureScriptEnvironment();
392 return mozilla::dom::WindowProxyHolder(mBrowsingContext
);
396 * Loads the given URI. See comments on nsDocShellLoadState members for more
397 * information on information used.
398 * `aCacheKey` gets passed to DoURILoad call.
400 MOZ_CAN_RUN_SCRIPT_BOUNDARY
401 nsresult
InternalLoad(
402 nsDocShellLoadState
* aLoadState
,
403 mozilla::Maybe
<uint32_t> aCacheKey
= mozilla::Nothing());
405 void MaybeRestoreWindowName();
407 void StoreWindowNameToSHEntries();
409 void SetWillChangeProcess() { mWillChangeProcess
= true; }
410 bool WillChangeProcess() { return mWillChangeProcess
; }
412 // Create a content viewer within this nsDocShell for the given
413 // `WindowGlobalChild` actor.
414 nsresult
CreateContentViewerForActor(
415 mozilla::dom::WindowGlobalChild
* aWindowActor
);
417 // Creates a real network channel (not a DocumentChannel) using the specified
419 // Used by nsDocShell when not using DocumentChannel, by DocumentLoadListener
420 // (parent-process DocumentChannel), and by DocumentChannelChild/ContentChild
421 // to transfer the resulting channel into the final process.
422 static nsresult
CreateRealChannelForDocument(
423 nsIChannel
** aChannel
, nsIURI
* aURI
, nsILoadInfo
* aLoadInfo
,
424 nsIInterfaceRequestor
* aCallbacks
, nsLoadFlags aLoadFlags
,
425 const nsAString
& aSrcdoc
, nsIURI
* aBaseURI
);
427 // Creates a real (not DocumentChannel) channel, and configures it using the
428 // supplied nsDocShellLoadState.
429 // Configuration options here are ones that should be applied to only the
430 // real channel, especially ones that need to QI to channel subclasses.
431 static bool CreateAndConfigureRealChannelForLoadState(
432 mozilla::dom::BrowsingContext
* aBrowsingContext
,
433 nsDocShellLoadState
* aLoadState
, mozilla::net::LoadInfo
* aLoadInfo
,
434 nsIInterfaceRequestor
* aCallbacks
, nsDocShell
* aDocShell
,
435 const mozilla::OriginAttributes
& aOriginAttributes
,
436 nsLoadFlags aLoadFlags
, uint32_t aCacheKey
, nsresult
& rv
,
437 nsIChannel
** aChannel
);
439 // This is used to deal with errors resulting from a failed page load.
440 // Errors are handled as follows:
441 // 1. Check to see if it's a file not found error or bad content
443 // 2. Send the URI to a keyword server (if enabled)
444 // 3. If the error was DNS failure, then add www and .com to the URI
446 // 4. If the www .com additions don't work, try those with an HTTPS scheme
448 static already_AddRefed
<nsIURI
> AttemptURIFixup(
449 nsIChannel
* aChannel
, nsresult aStatus
,
450 const mozilla::Maybe
<nsCString
>& aOriginalURIString
, uint32_t aLoadType
,
451 bool aIsTopFrame
, bool aAllowKeywordFixup
, bool aUsePrivateBrowsing
,
452 bool aNotifyKeywordSearchLoading
= false,
453 nsIInputStream
** aNewPostData
= nullptr);
455 static already_AddRefed
<nsIURI
> MaybeFixBadCertDomainErrorURI(
456 nsIChannel
* aChannel
, nsIURI
* aUrl
);
458 // Takes aStatus and filters out results that should not display
460 // If this returns a failed result, then we should display an error
461 // page with that result.
462 // aSkippedUnknownProtocolNavigation will be set to true if we chose
463 // to skip displaying an error page for an NS_ERROR_UNKNOWN_PROTOCOL
465 static nsresult
FilterStatusForErrorPage(
466 nsresult aStatus
, nsIChannel
* aChannel
, uint32_t aLoadType
,
467 bool aIsTopFrame
, bool aUseErrorPages
, bool aIsInitialDocument
,
468 bool* aSkippedUnknownProtocolNavigation
= nullptr);
470 // Notify consumers of a search being loaded through the observer service:
471 static void MaybeNotifyKeywordSearchLoading(const nsString
& aProvider
,
472 const nsString
& aKeyword
);
474 nsDocShell
* GetInProcessChildAt(int32_t aIndex
);
476 static bool ShouldAddURIVisit(nsIChannel
* aChannel
);
479 * Helper function that finds the last URI and its transition flags for a
482 * This method first checks the channel's property bag to see if previous
483 * info has been saved. If not, it gives back the referrer of the channel.
486 * The channel we are transitioning to
488 * Output parameter with the previous URI, not addref'd
489 * @param aChannelRedirectFlags
490 * If a redirect, output parameter with the previous redirect flags
491 * from nsIChannelEventSink
493 static void ExtractLastVisit(nsIChannel
* aChannel
, nsIURI
** aURI
,
494 uint32_t* aChannelRedirectFlags
);
496 bool HasContentViewer() const { return !!mContentViewer
; }
498 static uint32_t ComputeURILoaderFlags(
499 mozilla::dom::BrowsingContext
* aBrowsingContext
, uint32_t aLoadType
);
501 void SetLoadingSessionHistoryInfo(
502 const mozilla::dom::LoadingSessionHistoryInfo
& aLoadingInfo
,
503 bool aNeedToReportActiveAfterLoadingBecomesActive
= false);
504 const mozilla::dom::LoadingSessionHistoryInfo
*
505 GetLoadingSessionHistoryInfo() {
506 return mLoadingEntry
.get();
509 already_AddRefed
<nsIInputStream
> GetPostDataFromCurrentEntry() const;
510 mozilla::Maybe
<uint32_t> GetCacheKeyFromCurrentEntry() const;
512 // Loading and/or active entries are only set when session history
513 // in the parent is on.
514 bool FillLoadStateFromCurrentEntry(nsDocShellLoadState
& aLoadState
);
516 static bool ShouldAddToSessionHistory(nsIURI
* aURI
, nsIChannel
* aChannel
);
518 bool IsOSHE(nsISHEntry
* aEntry
) const { return mOSHE
== aEntry
; }
520 mozilla::dom::ChildSHistory
* GetSessionHistory() {
521 return mBrowsingContext
->GetChildSessionHistory();
524 // This returns true only when using session history in parent.
525 bool IsLoadingFromSessionHistory();
527 NS_IMETHODIMP
OnStartRequest(nsIRequest
* aRequest
) override
;
528 NS_IMETHODIMP
OnStopRequest(nsIRequest
* aRequest
,
529 nsresult aStatusCode
) override
;
531 private: // member functions
532 friend class nsAppShellService
;
533 friend class nsDSURIContentListener
;
534 friend class FramingChecker
;
535 friend class OnLinkClickEvent
;
536 friend class nsIDocShell
;
537 friend class mozilla::dom::BrowsingContext
;
538 friend class mozilla::net::DocumentLoadListener
;
539 friend class nsGlobalWindowOuter
;
541 // It is necessary to allow adding a timeline marker wherever a docshell
542 // instance is available. This operation happens frequently and needs to
543 // be very fast, so instead of using a Map or having to search for some
544 // docshell-specific markers storage, a pointer to an `ObservedDocShell` is
545 // is stored on docshells directly.
546 friend void mozilla::TimelineConsumers::AddConsumer(nsDocShell
*);
547 friend void mozilla::TimelineConsumers::RemoveConsumer(nsDocShell
*);
548 friend void mozilla::TimelineConsumers::AddMarkerForDocShell(
549 nsDocShell
*, const char*, MarkerTracingType
, MarkerStackRequest
);
550 friend void mozilla::TimelineConsumers::AddMarkerForDocShell(
551 nsDocShell
*, const char*, const TimeStamp
&, MarkerTracingType
,
553 friend void mozilla::TimelineConsumers::AddMarkerForDocShell(
554 nsDocShell
*, UniquePtr
<AbstractTimelineMarker
>&&);
555 friend void mozilla::TimelineConsumers::PopMarkers(
556 nsDocShell
*, JSContext
*, nsTArray
<dom::ProfileTimelineMarker
>&);
558 nsDocShell(mozilla::dom::BrowsingContext
* aBrowsingContext
,
559 uint64_t aContentWindowID
);
561 static inline uint32_t PRTimeToSeconds(PRTime aTimeUsec
) {
562 return uint32_t(aTimeUsec
/ PR_USEC_PER_SEC
);
565 virtual ~nsDocShell();
571 virtual void DestroyChildren() override
;
573 // Overridden from nsDocLoader, this provides more information than the
574 // normal OnStateChange with flags STATE_REDIRECTING
575 virtual void OnRedirectStateChange(nsIChannel
* aOldChannel
,
576 nsIChannel
* aNewChannel
,
577 uint32_t aRedirectFlags
,
578 uint32_t aStateFlags
) override
;
580 // Override the parent setter from nsDocLoader
581 virtual nsresult
SetDocLoaderParent(nsDocLoader
* aLoader
) override
;
584 // Content Viewer Management
587 nsresult
EnsureContentViewer();
589 // aPrincipal can be passed in if the caller wants. If null is
590 // passed in, the about:blank principal will end up being used.
591 // aCSP, if any, will be used for the new about:blank load.
592 nsresult
CreateAboutBlankContentViewer(
593 nsIPrincipal
* aPrincipal
, nsIPrincipal
* aPartitionedPrincipal
,
594 nsIContentSecurityPolicy
* aCSP
, nsIURI
* aBaseURI
, bool aIsInitialDocument
,
595 const mozilla::Maybe
<nsILoadInfo::CrossOriginEmbedderPolicy
>& aCOEP
=
597 bool aTryToSaveOldPresentation
= true, bool aCheckPermitUnload
= true,
598 mozilla::dom::WindowGlobalChild
* aActor
= nullptr);
600 nsresult
CreateContentViewer(const nsACString
& aContentType
,
601 nsIRequest
* aRequest
,
602 nsIStreamListener
** aContentHandler
);
604 nsresult
NewContentViewerObj(const nsACString
& aContentType
,
605 nsIRequest
* aRequest
, nsILoadGroup
* aLoadGroup
,
606 nsIStreamListener
** aContentHandler
,
607 nsIContentViewer
** aViewer
);
609 already_AddRefed
<nsILoadURIDelegate
> GetLoadURIDelegate();
611 nsresult
SetupNewViewer(
612 nsIContentViewer
* aNewViewer
,
613 mozilla::dom::WindowGlobalChild
* aWindowActor
= nullptr);
619 // Either aChannel or aOwner must be null. If aChannel is
620 // present, the owner should be gotten from it.
621 // If aCloneChildren is true, then our current session history's
622 // children will be cloned onto the new entry. This should be
623 // used when we aren't actually changing the document while adding
624 // the new session history entry.
625 // aCsp is the CSP to be used for the load. That is *not* the CSP
626 // that will be applied to subresource loads within that document
627 // but the CSP for the document load itself. E.g. if that CSP
628 // includes upgrade-insecure-requests, then the new top-level load
629 // will be upgraded to HTTPS.
630 nsresult
AddToSessionHistory(nsIURI
* aURI
, nsIChannel
* aChannel
,
631 nsIPrincipal
* aTriggeringPrincipal
,
632 nsIPrincipal
* aPrincipalToInherit
,
633 nsIPrincipal
* aPartitionedPrincipalToInherit
,
634 nsIContentSecurityPolicy
* aCsp
,
635 bool aCloneChildren
, nsISHEntry
** aNewEntry
);
637 void UpdateActiveEntry(
638 bool aReplace
, const mozilla::Maybe
<nsPoint
>& aPreviousScrollPos
,
639 nsIURI
* aURI
, nsIURI
* aOriginalURI
, nsIReferrerInfo
* aReferrerInfo
,
640 nsIPrincipal
* aTriggeringPrincipal
, nsIContentSecurityPolicy
* aCsp
,
641 const nsAString
& aTitle
, bool aScrollRestorationIsManual
,
642 nsIStructuredCloneContainer
* aData
, bool aURIWasModified
);
644 nsresult
AddChildSHEntry(nsISHEntry
* aCloneRef
, nsISHEntry
* aNewEntry
,
645 int32_t aChildOffset
, uint32_t aLoadType
,
646 bool aCloneChildren
);
648 nsresult
AddChildSHEntryToParent(nsISHEntry
* aNewEntry
, int32_t aChildOffset
,
649 bool aCloneChildren
);
651 // Call this method to swap in a new history entry to m[OL]SHE, rather than
652 // setting it directly. This completes the navigation in all docshells
653 // in the case of a subframe navigation.
654 // Returns old mOSHE/mLSHE.
655 already_AddRefed
<nsISHEntry
> SetHistoryEntry(nsCOMPtr
<nsISHEntry
>* aPtr
,
658 // This method calls SetHistoryEntry and updates mOSHE and mLSHE in BC to be
659 // the same as in docshell
660 void SetHistoryEntryAndUpdateBC(const mozilla::Maybe
<nsISHEntry
*>& aLSHE
,
661 const mozilla::Maybe
<nsISHEntry
*>& aOSHE
);
663 // If aNotifiedBeforeUnloadListeners is true, "beforeunload" event listeners
664 // were notified by the caller and given the chance to abort the navigation,
665 // and should not be notified again.
666 static nsresult
ReloadDocument(
667 nsDocShell
* aDocShell
, mozilla::dom::Document
* aDocument
,
668 uint32_t aLoadType
, mozilla::dom::BrowsingContext
* aBrowsingContext
,
669 nsIURI
* aCurrentURI
, nsIReferrerInfo
* aReferrerInfo
,
670 bool aNotifiedBeforeUnloadListeners
= false);
673 bool IsAboutBlankLoadOntoInitialAboutBlank(nsIURI
* aURI
,
674 bool aInheritPrincipal
,
675 nsIPrincipal
* aPrincipalToInherit
);
682 // Actually open a channel and perform a URI load. Callers need to pass a
683 // non-null aLoadState->TriggeringPrincipal() which initiated the URI load.
684 // Please note that the TriggeringPrincipal will be used for performing
685 // security checks. If aLoadState->URI() is provided by the web, then please
686 // do not pass a SystemPrincipal as the triggeringPrincipal. If
687 // aLoadState()->PrincipalToInherit is null, then no inheritance of any sort
688 // will happen and the load will get a principal based on the URI being
689 // loaded. If the Srcdoc flag is set (INTERNAL_LOAD_FLAGS_IS_SRCDOC), the load
690 // will be considered as a srcdoc load, and the contents of Srcdoc will be
691 // loaded instead of the URI. aLoadState->OriginalURI() will be set as the
692 // originalURI on the channel that does the load. If OriginalURI is null, URI
693 // will be set as the originalURI. If LoadReplace is true, LOAD_REPLACE flag
694 // will be set on the nsIChannel.
695 // If `aCacheKey` is supplied, use it for the session history entry.
696 nsresult
DoURILoad(nsDocShellLoadState
* aLoadState
,
697 mozilla::Maybe
<uint32_t> aCacheKey
, nsIRequest
** aRequest
);
699 static nsresult
AddHeadersToChannel(nsIInputStream
* aHeadersData
,
700 nsIChannel
* aChannel
);
702 nsresult
OpenInitializedChannel(nsIChannel
* aChannel
,
703 nsIURILoader
* aURILoader
,
704 uint32_t aOpenFlags
);
705 nsresult
OpenRedirectedChannel(nsDocShellLoadState
* aLoadState
);
707 void UpdateMixedContentChannelForNewLoad(nsIChannel
* aChannel
);
710 nsresult
ScrollToAnchor(bool aCurHasRef
, bool aNewHasRef
,
711 nsACString
& aNewHash
, uint32_t aLoadType
);
713 // This returns the load type for a form submission (see
714 // https://html.spec.whatwg.org/#form-submission-algorithm). The load type
715 // should be set as soon as the target BC has been determined.
716 uint32_t GetLoadTypeForFormSubmission(
717 mozilla::dom::BrowsingContext
* aTargetBC
,
718 nsDocShellLoadState
* aLoadState
);
721 // Returns true if would have called FireOnLocationChange,
722 // but did not because aFireOnLocationChange was false on entry.
723 // In this case it is the caller's responsibility to ensure
724 // FireOnLocationChange is called.
725 // In all other cases false is returned.
726 // Either aChannel or aTriggeringPrincipal must be null. If aChannel is
727 // present, the owner should be gotten from it.
728 // If OnNewURI calls AddToSessionHistory, it will pass its
729 // aCloneSHChildren argument as aCloneChildren.
730 // aCsp is the CSP to be used for the load. That is *not* the CSP
731 // that will be applied to subresource loads within that document
732 // but the CSP for the document load itself. E.g. if that CSP
733 // includes upgrade-insecure-requests, then the new top-level load
734 // will be upgraded to HTTPS.
735 bool OnNewURI(nsIURI
* aURI
, nsIChannel
* aChannel
,
736 nsIPrincipal
* aTriggeringPrincipal
,
737 nsIPrincipal
* aPrincipalToInherit
,
738 nsIPrincipal
* aPartitionedPrincipalToInehrit
,
739 nsIContentSecurityPolicy
* aCsp
, bool aFireOnLocationChange
,
740 bool aAddToGlobalHistory
, bool aCloneSHChildren
);
743 // If wireframe collection is enabled, will attempt to gather the
744 // wireframe for the document.
745 mozilla::Maybe
<mozilla::dom::Wireframe
> GetWireframe();
747 // If wireframe collection is enabled, will attempt to gather the
748 // wireframe for the document and stash it inside of the active history
749 // entry. Returns true if wireframes were collected.
750 bool CollectWireframe();
752 // Helper method that is called when a new document (including any
753 // sub-documents - ie. frames) has been completely loaded.
754 MOZ_CAN_RUN_SCRIPT_BOUNDARY
755 nsresult
EndPageLoad(nsIWebProgress
* aProgress
, nsIChannel
* aChannel
,
758 // Builds an error page URI (e.g. about:neterror?etc) for the given aURI
759 // and displays it via the LoadErrorPage() overload below.
760 nsresult
LoadErrorPage(nsIURI
* aURI
, const char16_t
* aURL
,
761 const char* aErrorPage
, const char* aErrorType
,
762 const char16_t
* aDescription
, const char* aCSSClass
,
763 nsIChannel
* aFailedChannel
);
765 // This method directly loads aErrorURI as an error page. aFailedURI and
766 // aFailedChannel come from DisplayLoadError() or the LoadErrorPage() overload
768 nsresult
LoadErrorPage(nsIURI
* aErrorURI
, nsIURI
* aFailedURI
,
769 nsIChannel
* aFailedChannel
);
771 bool DisplayLoadError(nsresult aError
, nsIURI
* aURI
, const char16_t
* aURL
,
772 nsIChannel
* aFailedChannel
) {
773 bool didDisplayLoadError
= false;
774 DisplayLoadError(aError
, aURI
, aURL
, aFailedChannel
, &didDisplayLoadError
);
775 return didDisplayLoadError
;
782 // Get the principal that we'll set on the channel if we're inheriting. If
783 // aConsiderCurrentDocument is true, we try to use the current document if
784 // at all possible. If that fails, we fall back on the parent document.
785 // If that fails too, we force creation of a content viewer and use the
786 // resulting principal. If aConsiderCurrentDocument is false, we just look
788 // If aConsiderPartitionedPrincipal is true, we consider the partitioned
789 // principal instead of the node principal.
790 nsIPrincipal
* GetInheritedPrincipal(
791 bool aConsiderCurrentDocument
,
792 bool aConsiderPartitionedPrincipal
= false);
795 * Helper function that caches a URI and a transition for saving later.
798 * Channel that will have these properties saved
800 * The URI to save for later
801 * @param aChannelRedirectFlags
802 * The nsIChannelEventSink redirect flags to save for later
804 static void SaveLastVisit(nsIChannel
* aChannel
, nsIURI
* aURI
,
805 uint32_t aChannelRedirectFlags
);
808 * Helper function for adding a URI visit using IHistory.
810 * The IHistory API maintains chains of visits, tracking both HTTP referrers
811 * and redirects for a user session. VisitURI requires the current URI and
812 * the previous URI in the chain.
814 * Visits can be saved either during a redirect or when the request has
815 * reached its final destination. The previous URI in the visit may be
816 * from another redirect.
818 * @pre aURI is not null.
821 * The URI that was just visited
822 * @param aPreviousURI
823 * The previous URI of this visit
824 * @param aChannelRedirectFlags
825 * For redirects, the redirect flags from nsIChannelEventSink
827 * @param aResponseStatus
828 * For HTTP channels, the response code (0 otherwise).
830 void AddURIVisit(nsIURI
* aURI
, nsIURI
* aPreviousURI
,
831 uint32_t aChannelRedirectFlags
,
832 uint32_t aResponseStatus
= 0);
835 * Internal helper funtion
837 static void InternalAddURIVisit(
838 nsIURI
* aURI
, nsIURI
* aPreviousURI
, uint32_t aChannelRedirectFlags
,
839 uint32_t aResponseStatus
, mozilla::dom::BrowsingContext
* aBrowsingContext
,
840 nsIWidget
* aWidget
, uint32_t aLoadType
);
842 static already_AddRefed
<nsIURIFixupInfo
> KeywordToURI(
843 const nsACString
& aKeyword
, bool aIsPrivateContext
);
845 // Sets the current document's current state object to the given SHEntry's
846 // state object. The current state object is eventually given to the page
847 // in the PopState event.
848 void SetDocCurrentStateObj(nsISHEntry
* aShEntry
,
849 mozilla::dom::SessionHistoryInfo
* aInfo
);
851 // Returns true if would have called FireOnLocationChange,
852 // but did not because aFireOnLocationChange was false on entry.
853 // In this case it is the caller's responsibility to ensure
854 // FireOnLocationChange is called.
855 // In all other cases false is returned.
856 bool SetCurrentURI(nsIURI
* aURI
, nsIRequest
* aRequest
,
857 bool aFireOnLocationChange
, bool aIsInitialAboutBlank
,
858 uint32_t aLocationFlags
);
860 // The following methods deal with saving and restoring content viewers
861 // in session history.
863 // mContentViewer points to the current content viewer associated with
864 // this docshell. When loading a new document, the content viewer is
865 // either destroyed or stored into a session history entry. To make sure
866 // that destruction happens in a controlled fashion, a given content viewer
867 // is always owned in exactly one of these ways:
868 // 1) The content viewer is active and owned by a docshell's
870 // 2) The content viewer is still being displayed while we begin loading
871 // a new document. The content viewer is owned by the _new_
872 // content viewer's mPreviousViewer, and has a pointer to the
873 // nsISHEntry where it will eventually be stored. The content viewer
874 // has been close()d by the docshell, which detaches the document from
875 // the window object.
876 // 3) The content viewer is cached in session history. The nsISHEntry
877 // has the only owning reference to the content viewer. The viewer
878 // has released its nsISHEntry pointer to prevent circular ownership.
880 // When restoring a content viewer from session history, open() is called
881 // to reattach the document to the window object. The content viewer is
882 // then placed into mContentViewer and removed from the history entry.
883 // (mContentViewer is put into session history as described above, if
886 // Determines whether we can safely cache the current mContentViewer in
887 // session history. This checks a number of factors such as cache policy,
888 // pending requests, and unload handlers.
889 // |aLoadType| should be the load type that will replace the current
890 // presentation. |aNewRequest| should be the request for the document to
891 // be loaded in place of the current document, or null if such a request
892 // has not been created yet. |aNewDocument| should be the document that will
893 // replace the current document.
894 bool CanSavePresentation(uint32_t aLoadType
, nsIRequest
* aNewRequest
,
895 mozilla::dom::Document
* aNewDocument
,
896 bool aReportBFCacheComboTelemetry
);
898 static void ReportBFCacheComboTelemetry(uint32_t aCombo
);
900 // Captures the state of the supporting elements of the presentation
901 // (the "window" object, docshell tree, meta-refresh loads, and security
902 // state) and stores them on |mOSHE|.
903 nsresult
CaptureState();
905 // Begin the toplevel restore process for |aSHEntry|.
906 // This simulates a channel open, and defers the real work until
907 // RestoreFromHistory is called from a PLEvent.
908 nsresult
RestorePresentation(nsISHEntry
* aSHEntry
, bool* aRestoring
);
910 // Call BeginRestore(nullptr, false) for each child of this shell.
911 nsresult
BeginRestoreChildren();
913 // Method to get our current position and size without flushing
914 void DoGetPositionAndSize(int32_t* aX
, int32_t* aY
, int32_t* aWidth
,
917 // Call this when a URI load is handed to us (via OnLinkClick or
918 // InternalLoad). This makes sure that we're not inside unload, or that if
919 // we are it's still OK to load this URI.
920 bool IsOKToLoadURI(nsIURI
* aURI
);
922 // helpers for executing commands
923 nsresult
GetControllerForCommand(const char* aCommand
,
924 nsIController
** aResult
);
926 // Possibly create a ClientSource object to represent an initial about:blank
927 // window that has not been allocated yet. Normally we try not to create
928 // this about:blank window until something calls GetDocument(). We still need
929 // the ClientSource to exist for this conceptual window, though.
931 // The ClientSource is created with the given principal if specified. If
932 // the principal is not provided we will attempt to inherit it when we
933 // are sure it will match what the real about:blank window principal
934 // would have been. There are some corner cases where we cannot easily
935 // determine the correct principal and will not create the ClientSource.
936 // In these cases the initial about:blank will appear to not exist until
937 // its real document and window are created.
938 void MaybeCreateInitialClientSource(nsIPrincipal
* aPrincipal
= nullptr);
940 // Determine if a service worker is allowed to control a window in this
941 // docshell with the given URL. If there are any reasons it should not,
942 // this will return false. If true is returned then the window *may* be
943 // controlled. The caller must still consult either the parent controller
944 // or the ServiceWorkerManager to determine if a service worker should
945 // actually control the window.
946 bool ServiceWorkerAllowedToControlWindow(nsIPrincipal
* aPrincipal
,
949 // Return the ClientInfo for the initial about:blank window, if it exists
950 // or we have speculatively created a ClientSource in
951 // MaybeCreateInitialClientSource(). This can return a ClientInfo object
952 // even if GetExtantDoc() returns nullptr.
953 mozilla::Maybe
<mozilla::dom::ClientInfo
> GetInitialClientInfo() const;
956 * Initializes mTiming if it isn't yet.
957 * After calling this, mTiming is non-null. This method returns true if the
958 * initialization of the Timing can be reset (basically this is true if a new
959 * Timing object is created).
960 * In case the loading is aborted, MaybeResetInitTiming() can be called
961 * passing the return value of MaybeInitTiming(): if it's possible to reset
962 * the Timing, this method will do it.
964 [[nodiscard
]] bool MaybeInitTiming();
965 void MaybeResetInitTiming(bool aReset
);
967 // Convenience method for getting our parent docshell. Can return null
968 already_AddRefed
<nsDocShell
> GetInProcessParentDocshell();
970 // Internal implementation of nsIDocShell::FirePageHideNotification.
971 // If aSkipCheckingDynEntries is true, it will not try to remove dynamic
972 // subframe entries. This is to avoid redundant RemoveDynEntries calls in all
973 // children docshells.
974 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
975 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void FirePageHideNotificationInternal(
976 bool aIsUnload
, bool aSkipCheckingDynEntries
);
978 void ThawFreezeNonRecursive(bool aThaw
);
979 // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
980 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void FirePageHideShowNonRecursive(bool aShow
);
982 nsresult
Dispatch(mozilla::TaskCategory aCategory
,
983 already_AddRefed
<nsIRunnable
>&& aRunnable
);
985 void ReattachEditorToWindow(nsISHEntry
* aSHEntry
);
986 void ClearFrameHistory(nsISHEntry
* aEntry
);
987 // Determine if this type of load should update history.
988 static bool ShouldUpdateGlobalHistory(uint32_t aLoadType
);
989 void UpdateGlobalHistoryTitle(nsIURI
* aURI
);
990 bool IsSubframe() { return mBrowsingContext
->IsSubframe(); }
991 bool CanSetOriginAttributes();
992 bool ShouldBlockLoadingForBackButton();
993 static bool ShouldDiscardLayoutState(nsIHttpChannel
* aChannel
);
994 bool HasUnloadedParent();
995 bool JustStartedNetworkLoad();
996 bool NavigationBlockedByPrinting(bool aDisplayErrorDialog
= true);
997 bool IsNavigationAllowed(bool aDisplayPrintErrorDialog
= true,
998 bool aCheckIfUnloadFired
= true);
999 nsIScrollableFrame
* GetRootScrollFrame();
1000 nsIChannel
* GetCurrentDocChannel();
1001 nsresult
EnsureScriptEnvironment();
1002 nsresult
EnsureEditorData();
1003 nsresult
EnsureTransferableHookData();
1004 nsresult
EnsureFind();
1005 nsresult
EnsureCommandHandler();
1006 nsresult
RefreshURIFromQueue();
1007 void RefreshURIToQueue();
1008 nsresult
Embed(nsIContentViewer
* aContentViewer
,
1009 mozilla::dom::WindowGlobalChild
* aWindowActor
,
1010 bool aIsTransientAboutBlank
, bool aPersist
,
1011 nsIRequest
* aRequest
, nsIURI
* aPreviousURI
);
1012 nsPresContext
* GetEldestPresContext();
1013 nsresult
CheckLoadingPermissions();
1014 nsresult
LoadHistoryEntry(nsISHEntry
* aEntry
, uint32_t aLoadType
,
1015 bool aUserActivation
);
1016 nsresult
LoadHistoryEntry(
1017 const mozilla::dom::LoadingSessionHistoryInfo
& aEntry
, uint32_t aLoadType
,
1018 bool aUserActivation
);
1019 nsresult
LoadHistoryEntry(nsDocShellLoadState
* aLoadState
, uint32_t aLoadType
,
1020 bool aLoadingCurrentEntry
);
1021 nsresult
GetHttpChannel(nsIChannel
* aChannel
, nsIHttpChannel
** aReturn
);
1022 nsresult
ConfirmRepost(bool* aRepost
);
1023 nsresult
GetPromptAndStringBundle(nsIPrompt
** aPrompt
,
1024 nsIStringBundle
** aStringBundle
);
1025 nsresult
SetCurScrollPosEx(int32_t aCurHorizontalPos
,
1026 int32_t aCurVerticalPos
);
1027 nsPoint
GetCurScrollPos();
1029 already_AddRefed
<mozilla::dom::ChildSHistory
> GetRootSessionHistory();
1031 bool CSSErrorReportingEnabled() const { return mCSSErrorReportingEnabled
; }
1033 // Handles retrieval of subframe session history for nsDocShell::LoadURI. If a
1034 // load is requested in a subframe of the current DocShell, the subframe
1035 // loadType may need to reflect the loadType of the parent document, or in
1036 // some cases (like reloads), the history load may need to be cancelled. See
1037 // function comments for in-depth logic descriptions.
1038 // Returns true if the method itself deals with the load.
1039 bool MaybeHandleSubframeHistory(nsDocShellLoadState
* aLoadState
,
1040 bool aContinueHandlingSubframeHistory
);
1042 // If we are passed a named target during InternalLoad, this method handles
1043 // moving the load to the browsing context the target name resolves to.
1044 nsresult
PerformRetargeting(nsDocShellLoadState
* aLoadState
);
1046 // Returns one of nsIContentPolicy::TYPE_DOCUMENT,
1047 // nsIContentPolicy::TYPE_INTERNAL_IFRAME, or
1048 // nsIContentPolicy::TYPE_INTERNAL_FRAME depending on who is responsible for
1050 nsContentPolicyType
DetermineContentType();
1052 // If this is an iframe, and the embedder is OOP, then notifes the
1053 // embedder that loading has finished and we shouldn't be blocking
1054 // load of the embedder. Only called when we fail to load, as we wait
1055 // for the load event of our Document before notifying success.
1057 // If aFireFrameErrorEvent is true, then fires an error event at the
1058 // embedder element, for both in-process and OOP embedders.
1059 void UnblockEmbedderLoadEventForFailure(bool aFireFrameErrorEvent
= false);
1061 struct SameDocumentNavigationState
{
1062 nsAutoCString mCurrentHash
;
1063 nsAutoCString mNewHash
;
1064 bool mCurrentURIHasRef
= false;
1065 bool mNewURIHasRef
= false;
1066 bool mSameExceptHashes
= false;
1067 bool mSecureUpgradeURI
= false;
1068 bool mHistoryNavBetweenSameDoc
= false;
1071 // Check to see if we're loading a prior history entry or doing a fragment
1072 // navigation in the same document.
1073 // NOTE: In case we are doing a fragment navigation, and HTTPS-Only/ -First
1074 // mode is enabled and upgraded the underlying document, we update the URI of
1075 // aLoadState from HTTP to HTTPS (if neccessary).
1076 bool IsSameDocumentNavigation(nsDocShellLoadState
* aLoadState
,
1077 SameDocumentNavigationState
& aState
);
1079 // ... If so, handle the scrolling or other action required instead of
1080 // continuing with new document navigation.
1082 nsresult
HandleSameDocumentNavigation(nsDocShellLoadState
* aLoadState
,
1083 SameDocumentNavigationState
& aState
);
1085 uint32_t GetSameDocumentNavigationFlags(nsIURI
* aNewURI
);
1087 // Called when the Private Browsing state of a nsDocShell changes.
1088 void NotifyPrivateBrowsingChanged();
1090 // Internal helpers for BrowsingContext to pass update values to nsIDocShell's
1092 void SetLoadGroupDefaultLoadFlags(nsLoadFlags aLoadFlags
);
1094 void SetTitleOnHistoryEntry(bool aUpdateEntryInSessionHistory
);
1096 void SetScrollRestorationIsManualOnHistoryEntry(nsISHEntry
* aSHEntry
,
1099 void SetCacheKeyOnHistoryEntry(nsISHEntry
* aSHEntry
, uint32_t aCacheKey
);
1101 // If the LoadState's URI is a javascript: URI, checks that the triggering
1102 // principal subsumes the principal of the current document, and returns
1103 // NS_ERROR_DOM_BAD_CROSS_ORIGIN_URI if it does not.
1104 nsresult
CheckDisallowedJavascriptLoad(nsDocShellLoadState
* aLoadState
);
1106 nsresult
LoadURI(nsDocShellLoadState
* aLoadState
, bool aSetNavigating
,
1107 bool aContinueHandlingSubframeHistory
);
1109 // Sets the active entry to the current loading entry. aPersist is used in the
1110 // case a new session history entry is added to the session history.
1111 // aExpired is true if the relevant nsIChannel has its cache token expired.
1112 // aCacheKey is the channel's cache key.
1113 // aPreviousURI should be the URI that was previously loaded into the
1115 void MoveLoadingToActiveEntry(bool aPersist
, bool aExpired
,
1116 uint32_t aCacheKey
, nsIURI
* aPreviousURI
);
1118 void ActivenessMaybeChanged();
1121 * Returns true if `noopener` will be force-enabled by any attempt to create
1122 * a popup window, even if rel="opener" is requested.
1124 bool NoopenerForceEnabled();
1126 bool ShouldOpenInBlankTarget(const nsAString
& aOriginalTarget
,
1127 nsIURI
* aLinkURI
, nsIContent
* aContent
,
1128 bool aIsUserTriggered
);
1130 void RecordSingleChannelId(bool aStartRequest
, nsIRequest
* aRequest
);
1132 void SetChannelToDisconnectOnPageHide(uint64_t aChannelId
) {
1133 MOZ_ASSERT(mChannelToDisconnectOnPageHide
== 0);
1134 mChannelToDisconnectOnPageHide
= aChannelId
;
1136 void MaybeDisconnectChildListenersOnPageHide();
1139 * Helper for addState and document.open that does just the
1140 * history-manipulation guts.
1142 * Arguments the spec defines:
1144 * @param aDocument the document we're manipulating. This will get the new
1146 * @param aNewURI the new URI.
1147 * @param aData The serialized state data. May be null.
1148 * @param aTitle The new title. May be empty.
1149 * @param aReplace whether this should replace the exising SHEntry.
1151 * Arguments we need internally because deriving them from the
1152 * others is a bit complicated:
1154 * @param aCurrentURI the current URI we're working with. Might be null.
1155 * @param aEqualURIs whether the two URIs involved are equal.
1157 nsresult
UpdateURLAndHistory(mozilla::dom::Document
* aDocument
,
1159 nsIStructuredCloneContainer
* aData
,
1160 const nsAString
& aTitle
, bool aReplace
,
1161 nsIURI
* aCurrentURI
, bool aEqualURIs
);
1164 void SetCurrentURIInternal(nsIURI
* aURI
);
1168 nsCString mOriginalUriString
;
1169 nsTObserverArray
<nsWeakPtr
> mPrivacyObservers
;
1170 nsTObserverArray
<nsWeakPtr
> mReflowObservers
;
1171 nsTObserverArray
<nsWeakPtr
> mScrollObservers
;
1172 mozilla::UniquePtr
<mozilla::dom::ClientSource
> mInitialClientSource
;
1173 nsCOMPtr
<nsINetworkInterceptController
> mInterceptController
;
1174 RefPtr
<nsDOMNavigationTiming
> mTiming
;
1175 RefPtr
<nsDSURIContentListener
> mContentListener
;
1176 RefPtr
<nsGlobalWindowOuter
> mScriptGlobal
;
1177 nsCOMPtr
<nsIPrincipal
> mParentCharsetPrincipal
;
1178 // The following 3 lists contain either nsITimer or nsRefreshTimer objects.
1179 // URIs to refresh are collected to mRefreshURIList.
1180 nsCOMPtr
<nsIMutableArray
> mRefreshURIList
;
1181 // mSavedRefreshURIList is used to move the entries from mRefreshURIList to
1183 nsCOMPtr
<nsIMutableArray
> mSavedRefreshURIList
;
1184 // BFCache-in-parent implementation caches the entries in
1185 // mBFCachedRefreshURIList.
1186 nsCOMPtr
<nsIMutableArray
> mBFCachedRefreshURIList
;
1187 uint64_t mContentWindowID
;
1188 nsCOMPtr
<nsIContentViewer
> mContentViewer
;
1189 nsCOMPtr
<nsIWidget
> mParentWidget
;
1190 RefPtr
<mozilla::dom::ChildSHistory
> mSessionHistory
;
1191 nsCOMPtr
<nsIWebBrowserFind
> mFind
;
1192 RefPtr
<nsCommandManager
> mCommandManager
;
1193 RefPtr
<mozilla::dom::BrowsingContext
> mBrowsingContext
;
1195 // Weak reference to our BrowserChild actor.
1196 nsWeakPtr mBrowserChild
;
1198 // Dimensions of the docshell
1202 * Content-Type Hint of the most-recently initiated load. Used for
1203 * session history entries.
1205 nsCString mContentTypeHint
;
1207 // An observed docshell wrapper is created when recording markers is enabled.
1208 mozilla::UniquePtr
<mozilla::ObservedDocShell
> mObserved
;
1210 // mCurrentURI should be marked immutable on set if possible.
1211 // Change mCurrentURI only through SetCurrentURIInternal method.
1212 nsCOMPtr
<nsIURI
> mCurrentURI
;
1213 nsCOMPtr
<nsIReferrerInfo
> mReferrerInfo
;
1216 // We're counting the number of |nsDocShells| to help find leaks
1217 static unsigned long gNumberOfDocShells
;
1219 nsCOMPtr
<nsIURI
> mLastOpenedURI
;
1222 // Reference to the SHEntry for this docshell until the page is destroyed.
1223 // Somebody give me better name
1224 // Only used when SHIP is disabled.
1225 nsCOMPtr
<nsISHEntry
> mOSHE
;
1227 // Reference to the SHEntry for this docshell until the page is loaded
1228 // Somebody give me better name.
1229 // If mLSHE is non-null, non-pushState subframe loads don't create separate
1230 // root history entries. That is, frames loaded during the parent page
1231 // load don't generate history entries the way frame navigation after the
1232 // parent has loaded does. (This isn't the only purpose of mLSHE.)
1233 // Only used when SHIP is disabled.
1234 nsCOMPtr
<nsISHEntry
> mLSHE
;
1236 // These are only set when fission.sessionHistoryInParent is set.
1237 mozilla::UniquePtr
<mozilla::dom::SessionHistoryInfo
> mActiveEntry
;
1238 bool mActiveEntryIsLoadingFromSessionHistory
= false;
1239 // mLoadingEntry is set when we're about to start loading. Whenever
1240 // setting mLoadingEntry, be sure to also set
1241 // mNeedToReportActiveAfterLoadingBecomesActive.
1242 mozilla::UniquePtr
<mozilla::dom::LoadingSessionHistoryInfo
> mLoadingEntry
;
1244 // Holds a weak pointer to a RestorePresentationEvent object if any that
1245 // holds a weak pointer back to us. We use this pointer to possibly revoke
1246 // the event whenever necessary.
1247 nsRevocableEventPtr
<RestorePresentationEvent
> mRestorePresentationEvent
;
1249 // Editor data, if this document is designMode or contentEditable.
1250 mozilla::UniquePtr
<nsDocShellEditorData
> mEditorData
;
1252 // The URI we're currently loading. This is only relevant during the
1253 // firing of a pagehide/unload. The caller of FirePageHideNotification()
1254 // is responsible for setting it and unsetting it. It may be null if the
1255 // pagehide/unload is happening for some reason other than just loading a
1257 nsCOMPtr
<nsIURI
> mLoadingURI
;
1259 // Set in LoadErrorPage from the method argument and used later
1260 // in CreateContentViewer. We have to delay an shistory entry creation
1261 // for which these objects are needed.
1262 nsCOMPtr
<nsIURI
> mFailedURI
;
1263 nsCOMPtr
<nsIChannel
> mFailedChannel
;
1265 mozilla::UniquePtr
<mozilla::gfx::Matrix5x4
> mColorMatrix
;
1267 const mozilla::Encoding
* mParentCharset
;
1269 // WEAK REFERENCES BELOW HERE.
1270 // Note these are intentionally not addrefd. Doing so will create a cycle.
1271 // For that reasons don't use nsCOMPtr.
1273 nsIDocShellTreeOwner
* mTreeOwner
; // Weak Reference
1275 RefPtr
<mozilla::dom::EventTarget
> mChromeEventHandler
;
1277 mozilla::ScrollbarPreference mScrollbarPref
; // persistent across doc loads
1279 eCharsetReloadState mCharsetReloadState
;
1281 int32_t mParentCharsetSource
;
1282 mozilla::CSSIntSize mFrameMargins
;
1284 // This can either be a content docshell or a chrome docshell.
1285 const int32_t mItemType
;
1287 // Index into the nsISHEntry array, indicating the previous and current
1288 // entry at the time that this DocShell begins to load. Consequently
1289 // root docshell's indices can differ from child docshells'.
1290 int32_t mPreviousEntryIndex
;
1291 int32_t mLoadedEntryIndex
;
1293 BusyFlags mBusyFlags
;
1296 uint32_t mFailedLoadType
;
1298 // A depth count of how many times NotifyRunToCompletionStart
1299 // has been called without a matching NotifyRunToCompletionStop.
1300 uint32_t mJSRunToCompletionDepth
;
1302 // Whether or not handling of the <meta name="viewport"> tag is overridden.
1303 // Possible values are defined as constants in nsIDocShell.idl.
1304 MetaViewportOverride mMetaViewportOverride
;
1306 // See WindowGlobalParent::mSingleChannelId.
1307 mozilla::Maybe
<uint64_t> mSingleChannelId
;
1308 uint32_t mRequestForBlockingFromBFCacheCount
= 0;
1310 uint64_t mChannelToDisconnectOnPageHide
;
1312 uint32_t mPendingReloadCount
= 0;
1314 // The following two fields cannot be declared as bit fields
1315 // because of uses with AutoRestore.
1316 bool mCreatingDocument
; // (should be) debugging only
1318 bool mInEnsureScriptEnv
;
1319 uint64_t mDocShellID
= 0;
1322 bool mInitialized
: 1;
1323 bool mAllowSubframes
: 1;
1324 bool mAllowMetaRedirects
: 1;
1325 bool mAllowImages
: 1;
1326 bool mAllowMedia
: 1;
1327 bool mAllowDNSPrefetch
: 1;
1328 bool mAllowWindowControl
: 1;
1329 bool mCSSErrorReportingEnabled
: 1;
1330 bool mAllowAuth
: 1;
1331 bool mAllowKeywordFixup
: 1;
1332 bool mDisableMetaRefreshWhenInactive
: 1;
1334 bool mWindowDraggingAllowed
: 1;
1335 bool mInFrameSwap
: 1;
1337 // This boolean is set to true right before we fire pagehide and generally
1338 // unset when we embed a new content viewer. While it's true no navigation
1339 // is allowed in this docshell.
1340 bool mFiredUnloadEvent
: 1;
1342 // this flag is for bug #21358. a docshell may load many urls
1343 // which don't result in new documents being created (i.e. a new
1344 // content viewer) we want to make sure we don't call a on load
1345 // event more than once for a given content viewer.
1346 bool mEODForCurrentDocument
: 1;
1347 bool mURIResultedInDocument
: 1;
1349 bool mIsBeingDestroyed
: 1;
1351 bool mIsExecutingOnLoadHandler
: 1;
1353 // Indicates to CreateContentViewer() that it is safe to cache the old
1354 // presentation of the page, and to SetupNewViewer() that the old viewer
1355 // should be passed a SHEntry to save itself into.
1356 // Only used with SHIP disabled.
1357 bool mSavingOldViewer
: 1;
1359 bool mInvisible
: 1;
1360 bool mHasLoadedNonBlankURI
: 1;
1362 // This flag means that mTiming has been initialized but nulled out.
1363 // We will check the innerWin's timing before creating a new one
1364 // in MaybeInitTiming()
1365 bool mBlankTiming
: 1;
1367 // This flag indicates when the title is valid for the current URI.
1368 bool mTitleValidForCurrentURI
: 1;
1370 // If mWillChangeProcess is set to true, then when the docshell is destroyed,
1371 // we prepare the browsing context to change process.
1372 bool mWillChangeProcess
: 1;
1374 // This flag indicates whether or not the DocShell is currently executing an
1375 // nsIWebNavigation navigation method.
1376 bool mIsNavigating
: 1;
1378 // Whether we have a pending encoding autodetection request from the
1379 // menu for all encodings.
1380 bool mForcedAutodetection
: 1;
1383 * Set to true if we're checking session history (in the parent process) for
1384 * a possible history load. Used only with iframes.
1386 bool mCheckingSessionHistory
: 1;
1388 // Whether mBrowsingContext->SetActiveSessionHistoryEntry() needs to be called
1389 // when the loading entry becomes the active entry. This is used for the
1390 // initial about:blank-replacing about:blank in order to make the history
1391 // length WPTs pass.
1392 bool mNeedToReportActiveAfterLoadingBecomesActive
: 1;
1395 inline nsISupports
* ToSupports(nsDocShell
* aDocShell
) {
1396 return static_cast<nsIDocumentLoader
*>(aDocShell
);
1399 #endif /* nsDocShell_h__ */