CanonicalBrowsingContext.h (27092B)
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/. */ 6 7 #ifndef mozilla_dom_CanonicalBrowsingContext_h 8 #define mozilla_dom_CanonicalBrowsingContext_h 9 10 #include "mozilla/dom/BrowsingContext.h" 11 #include "mozilla/dom/MediaControlKeySource.h" 12 #include "mozilla/dom/BrowsingContextWebProgress.h" 13 #include "mozilla/dom/EntryList.h" 14 #include "mozilla/dom/FeaturePolicy.h" 15 #include "mozilla/dom/ProcessIsolation.h" 16 #include "mozilla/dom/Promise.h" 17 #include "mozilla/dom/SessionHistoryEntry.h" 18 #include "mozilla/dom/SessionStoreRestoreData.h" 19 #include "mozilla/dom/SessionStoreUtils.h" 20 #include "mozilla/dom/UniqueContentParentKeepAlive.h" 21 #include "mozilla/dom/ipc/IdType.h" 22 #include "mozilla/RefPtr.h" 23 #include "mozilla/MozPromise.h" 24 #include "nsCycleCollectionParticipant.h" 25 #include "nsWrapperCache.h" 26 #include "nsTArray.h" 27 #include "nsTHashtable.h" 28 #include "nsHashKeys.h" 29 #include "nsISecureBrowserUI.h" 30 31 class nsIBrowserDOMWindow; 32 class nsISHistory; 33 class nsIWidget; 34 class nsIPrintSettings; 35 class nsSHistory; 36 class nsBrowserStatusFilter; 37 class nsSecureBrowserUI; 38 class CallerWillNotifyHistoryIndexAndLengthChanges; 39 class nsITimer; 40 41 namespace mozilla { 42 enum class CallState; 43 class BounceTrackingState; 44 45 namespace embedding { 46 class PrintData; 47 } 48 49 namespace net { 50 class DocumentLoadListener; 51 } 52 53 namespace dom { 54 55 class BrowserParent; 56 class BrowserBridgeParent; 57 class FeaturePolicy; 58 struct LoadURIOptions; 59 class MediaController; 60 struct LoadingSessionHistoryInfo; 61 class SSCacheCopy; 62 class WindowGlobalParent; 63 class SessionStoreFormData; 64 class SessionStoreScrollData; 65 66 // CanonicalBrowsingContext is a BrowsingContext living in the parent 67 // process, with whatever extra data that a BrowsingContext in the 68 // parent needs. 69 class CanonicalBrowsingContext final : public BrowsingContext { 70 public: 71 NS_DECL_ISUPPORTS_INHERITED 72 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED( 73 CanonicalBrowsingContext, BrowsingContext) 74 75 static already_AddRefed<CanonicalBrowsingContext> Get(uint64_t aId); 76 static CanonicalBrowsingContext* Cast(BrowsingContext* aContext); 77 static const CanonicalBrowsingContext* Cast(const BrowsingContext* aContext); 78 static already_AddRefed<CanonicalBrowsingContext> Cast( 79 already_AddRefed<BrowsingContext>&& aContext); 80 81 bool IsOwnedByProcess(uint64_t aProcessId) const { 82 return mProcessId == aProcessId; 83 } 84 bool IsEmbeddedInProcess(uint64_t aProcessId) const { 85 return mEmbedderProcessId == aProcessId; 86 } 87 uint64_t OwnerProcessId() const { return mProcessId; } 88 uint64_t EmbedderProcessId() const { return mEmbedderProcessId; } 89 ContentParent* GetContentParent() const; 90 91 void GetCurrentRemoteType(nsACString& aRemoteType, ErrorResult& aRv) const; 92 93 void SetOwnerProcessId(uint64_t aProcessId); 94 95 // The ID of the BrowsingContext which caused this BrowsingContext to be 96 // opened, or `0` if this is unknown. 97 // Only set for toplevel content BrowsingContexts, and may be from a different 98 // BrowsingContextGroup. 99 uint64_t GetCrossGroupOpenerId() const { return mCrossGroupOpenerId; } 100 already_AddRefed<CanonicalBrowsingContext> GetCrossGroupOpener() const; 101 void SetCrossGroupOpenerId(uint64_t aOpenerId); 102 void SetCrossGroupOpener(CanonicalBrowsingContext* aCrossGroupOpener, 103 ErrorResult& aRv); 104 105 void GetWindowGlobals(nsTArray<RefPtr<WindowGlobalParent>>& aWindows); 106 107 // The current active WindowGlobal. 108 WindowGlobalParent* GetCurrentWindowGlobal() const; 109 110 // Same as the methods on `BrowsingContext`, but with the types already cast 111 // to the parent process type. 112 CanonicalBrowsingContext* GetParent() { 113 return Cast(BrowsingContext::GetParent()); 114 } 115 CanonicalBrowsingContext* Top() { return Cast(BrowsingContext::Top()); } 116 WindowGlobalParent* GetParentWindowContext(); 117 WindowGlobalParent* GetTopWindowContext(); 118 119 already_AddRefed<nsIWidget> GetParentProcessWidgetContaining(); 120 already_AddRefed<nsIBrowserDOMWindow> GetBrowserDOMWindow(); 121 122 // Same as `GetParentWindowContext`, but will also cross <browser> and 123 // content/chrome boundaries. 124 already_AddRefed<WindowGlobalParent> GetEmbedderWindowGlobal() const; 125 126 CanonicalBrowsingContext* GetParentCrossChromeBoundary(); 127 CanonicalBrowsingContext* TopCrossChromeBoundary(); 128 Nullable<WindowProxyHolder> GetTopChromeWindow(); 129 130 nsISHistory* GetSessionHistory(); 131 SessionHistoryEntry* GetActiveSessionHistoryEntry(); 132 void SetActiveSessionHistoryEntryFromBFCache(SessionHistoryEntry* aEntry); 133 134 bool ManuallyManagesActiveness() const; 135 136 UniquePtr<LoadingSessionHistoryInfo> CreateLoadingSessionHistoryEntryForLoad( 137 nsDocShellLoadState* aLoadState, SessionHistoryEntry* aExistingEntry, 138 nsIChannel* aChannel); 139 140 UniquePtr<LoadingSessionHistoryInfo> ReplaceLoadingSessionHistoryEntryForLoad( 141 LoadingSessionHistoryInfo* aInfo, nsIChannel* aNewChannel); 142 143 using PrintPromise = 144 MozPromise<MaybeDiscardedBrowsingContext, nsresult, false>; 145 MOZ_CAN_RUN_SCRIPT RefPtr<PrintPromise> Print(nsIPrintSettings*); 146 MOZ_CAN_RUN_SCRIPT already_AddRefed<Promise> PrintJS(nsIPrintSettings*, 147 ErrorResult&); 148 MOZ_CAN_RUN_SCRIPT RefPtr<PrintPromise> PrintWithNoContentAnalysis( 149 nsIPrintSettings* aPrintSettings, bool aForceStaticDocument, 150 const MaybeDiscardedBrowsingContext& aClonedStaticBrowsingContext); 151 MOZ_CAN_RUN_SCRIPT void ReleaseClonedPrint( 152 const MaybeDiscardedBrowsingContext& aClonedStaticBrowsingContext); 153 154 enum class TopDescendantKind { 155 // All top descendants are included, even those inside a nested top 156 // browser. 157 All, 158 // Top descendants that are either direct children or under a non-nested 159 // descendant are included, but not those nested inside a separate top. 160 NonNested, 161 // Only our direct children are included. This is usually slightly less 162 // efficient than the alternatives, but might be needed in some cases. 163 ChildrenOnly, 164 }; 165 // Call the given callback on top-level descendant BrowsingContexts. 166 // Return Callstate::Stop from the callback to stop calling further children. 167 void CallOnTopDescendants( 168 const FunctionRef<CallState(CanonicalBrowsingContext*)>& aCallback, 169 TopDescendantKind aKind); 170 171 void SessionHistoryCommit(uint64_t aLoadId, const nsID& aChangeID, 172 uint32_t aLoadType, bool aCloneEntryChildren, 173 bool aChannelExpired, uint32_t aCacheKey); 174 175 // Calls the session history listeners' OnHistoryReload, storing the result in 176 // aCanReload. If aCanReload is set to true and we have an active or a loading 177 // entry then aLoadState will be initialized from that entry, and 178 // aReloadActiveEntry will be true if we have an active entry. If aCanReload 179 // is true and aLoadState and aReloadActiveEntry are not set then we should 180 // attempt to reload based on the current document in the docshell. 181 void NotifyOnHistoryReload( 182 bool aForceReload, bool& aCanReload, 183 Maybe<NotNull<RefPtr<nsDocShellLoadState>>>& aLoadState, 184 Maybe<bool>& aReloadActiveEntry); 185 186 // See BrowsingContext::SetActiveSessionHistoryEntry. 187 void SetActiveSessionHistoryEntry(const Maybe<nsPoint>& aPreviousScrollPos, 188 SessionHistoryInfo* aInfo, 189 uint32_t aLoadType, 190 uint32_t aUpdatedCacheKey, 191 const nsID& aChangeID); 192 193 void ReplaceActiveSessionHistoryEntry(SessionHistoryInfo* aInfo); 194 195 void RemoveDynEntriesFromActiveSessionHistoryEntry(); 196 197 void RemoveFromSessionHistory(const nsID& aChangeID); 198 199 MOZ_CAN_RUN_SCRIPT Maybe<int32_t> HistoryGo( 200 int32_t aOffset, uint64_t aHistoryEpoch, bool aRequireUserInteraction, 201 bool aUserActivation, bool aCheckForCancelation, 202 Maybe<ContentParentId> aContentId, 203 std::function<void(nsresult)>&& aResolver = [](nsresult) {}); 204 205 MOZ_CAN_RUN_SCRIPT void NavigationTraverse( 206 const nsID& aKey, uint64_t aHistoryEpoch, bool aUserActivation, 207 bool aCheckForCancelation, Maybe<ContentParentId> aContentId, 208 std::function<void(nsresult)>&& aResolver); 209 210 JSObject* WrapObject(JSContext* aCx, 211 JS::Handle<JSObject*> aGivenProto) override; 212 213 // Dispatches a wheel zoom change to the embedder element. 214 void DispatchWheelZoomChange(bool aIncrease); 215 216 // This function is used to start the autoplay media which are delayed to 217 // start. If needed, it would also notify the content browsing context which 218 // are related with the canonical browsing content tree to start delayed 219 // autoplay media. 220 void NotifyStartDelayedAutoplayMedia(); 221 222 // This function is used to mute or unmute all media within a tab. It would 223 // set the media mute property for the top level window and propagate it to 224 // other top level windows in other processes. 225 void NotifyMediaMutedChanged(bool aMuted, ErrorResult& aRv); 226 227 // Return the number of unique site origins by iterating all given BCs, 228 // including their subtrees. 229 static uint32_t CountSiteOrigins( 230 GlobalObject& aGlobal, 231 const Sequence<mozilla::OwningNonNull<BrowsingContext>>& aRoots); 232 233 // Return true if a private browsing session is active. 234 static bool IsPrivateBrowsingActive(); 235 236 // This function would propogate the action to its all child browsing contexts 237 // in content processes. 238 void UpdateMediaControlAction(const MediaControlAction& aAction); 239 240 // Triggers a load in the process 241 using BrowsingContext::LoadURI; 242 void FixupAndLoadURIString(const nsAString& aURI, 243 const LoadURIOptions& aOptions, 244 ErrorResult& aError); 245 void LoadURI(nsIURI* aURI, const LoadURIOptions& aOptions, 246 ErrorResult& aError); 247 248 MOZ_CAN_RUN_SCRIPT 249 void GoBack(const Optional<int32_t>& aCancelContentJSEpoch, 250 bool aRequireUserInteraction, bool aUserActivation); 251 MOZ_CAN_RUN_SCRIPT 252 void GoForward(const Optional<int32_t>& aCancelContentJSEpoch, 253 bool aRequireUserInteraction, bool aUserActivation); 254 MOZ_CAN_RUN_SCRIPT 255 void GoToIndex(int32_t aIndex, const Optional<int32_t>& aCancelContentJSEpoch, 256 bool aUserActivation); 257 MOZ_CAN_RUN_SCRIPT 258 void Reload(uint32_t aReloadFlags); 259 void Stop(uint32_t aStopFlags); 260 261 // Get the publicly exposed current URI loaded in this BrowsingContext. 262 already_AddRefed<nsIURI> GetCurrentURI() const; 263 void SetCurrentRemoteURI(nsIURI* aCurrentRemoteURI); 264 265 BrowserParent* GetBrowserParent() const; 266 void SetCurrentBrowserParent(BrowserParent* aBrowserParent); 267 268 // Internal method to change which process a BrowsingContext is being loaded 269 // in. The returned promise will resolve when the process switch is completed. 270 // The returned CanonicalBrowsingContext may be different than |this| if a BCG 271 // switch was performed. 272 // 273 // A NOT_REMOTE_TYPE aRemoteType argument will perform a process switch into 274 // the parent process, and the method will resolve with a null BrowserParent. 275 using RemotenessPromise = MozPromise< 276 std::pair<RefPtr<BrowserParent>, RefPtr<CanonicalBrowsingContext>>, 277 nsresult, false>; 278 MOZ_CAN_RUN_SCRIPT 279 RefPtr<RemotenessPromise> ChangeRemoteness( 280 const NavigationIsolationOptions& aOptions, uint64_t aPendingSwitchId); 281 282 // Return a media controller from the top-level browsing context that can 283 // control all media belonging to this browsing context tree. Return nullptr 284 // if the top-level browsing context has been discarded. 285 MediaController* GetMediaController(); 286 bool HasCreatedMediaController() const; 287 288 // Attempts to start loading the given load state in this BrowsingContext, 289 // in parallel with a DocumentChannelChild being created in the docshell. 290 // Requires the DocumentChannel to connect with this load for it to 291 // complete successfully. 292 bool AttemptSpeculativeLoadInParent(nsDocShellLoadState* aLoadState); 293 294 // Get or create a secure browser UI for this BrowsingContext 295 nsISecureBrowserUI* GetSecureBrowserUI(); 296 297 BrowsingContextWebProgress* GetWebProgress() { return mWebProgress; } 298 299 // Called when the current URI changes (from an 300 // nsIWebProgressListener::OnLocationChange event, so that we 301 // can update our security UI for the new location, or when the 302 // mixed content/https-only state for our current window is changed. 303 void UpdateSecurityState(); 304 305 // Called when a navigation forces us to recreate our browsing 306 // context (for example, when switching in or out of the parent 307 // process). 308 // aNewContext is the newly created BrowsingContext that is replacing 309 // us. 310 void ReplacedBy(CanonicalBrowsingContext* aNewContext, 311 const NavigationIsolationOptions& aRemotenessOptions); 312 313 bool HasHistoryEntry(nsISHEntry* aEntry); 314 bool HasLoadingHistoryEntry(nsISHEntry* aEntry) { 315 for (const LoadingSessionHistoryEntry& loading : mLoadingEntries) { 316 if (loading.mEntry == aEntry) { 317 return true; 318 } 319 } 320 return false; 321 } 322 323 void SwapHistoryEntries(nsISHEntry* aOldEntry, nsISHEntry* aNewEntry); 324 325 void AddLoadingSessionHistoryEntry(uint64_t aLoadId, 326 SessionHistoryEntry* aEntry); 327 328 void GetLoadingSessionHistoryInfoFromParent( 329 Maybe<LoadingSessionHistoryInfo>& aLoadingInfo); 330 331 void HistoryCommitIndexAndLength(); 332 333 void SynchronizeLayoutHistoryState(); 334 335 void SynchronizeNavigationAPIState(nsIStructuredCloneContainer* aState); 336 337 void ResetScalingZoom(); 338 339 void SetContainerFeaturePolicy( 340 Maybe<FeaturePolicyInfo>&& aContainerFeaturePolicyInfo); 341 const Maybe<FeaturePolicyInfo>& GetContainerFeaturePolicy() const { 342 return mContainerFeaturePolicyInfo; 343 } 344 345 void SetRestoreData(SessionStoreRestoreData* aData, ErrorResult& aError); 346 void ClearRestoreState(); 347 MOZ_CAN_RUN_SCRIPT_BOUNDARY void RequestRestoreTabContent( 348 WindowGlobalParent* aWindow); 349 already_AddRefed<Promise> GetRestorePromise(); 350 351 nsresult WriteSessionStorageToSessionStore( 352 const nsTArray<SSCacheCopy>& aSesssionStorage, uint32_t aEpoch); 353 354 void UpdateSessionStoreSessionStorage(const std::function<void()>& aDone); 355 356 static void UpdateSessionStoreForStorage(uint64_t aBrowsingContextId); 357 358 // Called when a BrowserParent for this BrowsingContext has been fully 359 // destroyed (i.e. `ActorDestroy` was called). 360 void BrowserParentDestroyed(BrowserParent* aBrowserParent, 361 bool aAbnormalShutdown); 362 363 void StartUnloadingHost(uint64_t aChildID); 364 void ClearUnloadingHost(uint64_t aChildID); 365 366 bool AllowedInBFCache(const Maybe<uint64_t>& aChannelId, nsIURI* aNewURI); 367 368 private: 369 static nsresult ContainsSameOriginBfcacheEntry( 370 nsISHEntry* aEntry, mozilla::dom::BrowsingContext* aBC, 371 int32_t aChildIndex, void* aData); 372 373 public: 374 // Removes all bfcache entries that match the origin + originAttributes of the 375 // principal. Must be passed partitionedPrincipal 376 static nsresult ClearBfcacheByPrincipal(nsIPrincipal* aPrincipal); 377 378 // Methods for getting and setting the active state for top level 379 // browsing contexts, for the process priority manager. 380 bool IsPriorityActive() const { 381 MOZ_RELEASE_ASSERT(IsTop()); 382 return mPriorityActive; 383 } 384 void SetPriorityActive(bool aIsActive) { 385 MOZ_RELEASE_ASSERT(IsTop()); 386 mPriorityActive = aIsActive; 387 } 388 389 void SetIsActive(bool aIsActive, ErrorResult& aRv); 390 391 void SetIsActiveInternal(bool aIsActive, ErrorResult& aRv) { 392 ExplicitActiveStatus newValue = aIsActive ? ExplicitActiveStatus::Active 393 : ExplicitActiveStatus::Inactive; 394 bool changed = GetExplicitActive() != newValue; 395 SetExplicitActive(newValue, aRv); 396 if (changed) { 397 nsCOMPtr<nsIObserverService> observerService = 398 mozilla::services::GetObserverService(); 399 if (observerService) { 400 observerService->NotifyObservers( 401 ToSupports(this), "browsing-context-active-change", nullptr); 402 } 403 } 404 } 405 406 void SetTouchEventsOverride(dom::TouchEventsOverride, ErrorResult& aRv); 407 void SetTargetTopLevelLinkClicksToBlank(bool aTargetTopLevelLinkClicksToBlank, 408 ErrorResult& aRv); 409 410 bool IsReplaced() const { return mIsReplaced; } 411 412 const JS::Heap<JS::Value>& PermanentKey() { return mPermanentKey; } 413 void ClearPermanentKey() { mPermanentKey.setNull(); } 414 void MaybeSetPermanentKey(Element* aEmbedder); 415 416 // When request for page awake, it would increase a count that is used to 417 // prevent whole browsing context tree from being suspended. The request can 418 // be called multiple times. When calling the revoke, it would decrease the 419 // count and once the count reaches to zero, the browsing context tree could 420 // be suspended when the tree is inactive. 421 void AddPageAwakeRequest(); 422 void RemovePageAwakeRequest(); 423 424 MOZ_CAN_RUN_SCRIPT 425 void CloneDocumentTreeInto(CanonicalBrowsingContext* aSource, 426 const nsACString& aRemoteType, 427 embedding::PrintData&& aPrintData); 428 429 // Returns a Promise which resolves when cloning documents for printing 430 // finished if this browsing context is cloning document tree. 431 RefPtr<GenericNonExclusivePromise> GetClonePromise() const { 432 return mClonePromise; 433 } 434 435 bool StartApzAutoscroll(float aAnchorX, float aAnchorY, nsViewID aScrollId, 436 uint32_t aPresShellId); 437 void StopApzAutoscroll(nsViewID aScrollId, uint32_t aPresShellId); 438 439 void AddFinalDiscardListener(std::function<void(uint64_t)>&& aListener); 440 441 bool ForceAppWindowActive() const { return mForceAppWindowActive; } 442 void SetForceAppWindowActive(bool, ErrorResult&); 443 void RecomputeAppWindowVisibility(); 444 445 already_AddRefed<nsISHEntry> GetMostRecentLoadingSessionHistoryEntry(); 446 447 already_AddRefed<BounceTrackingState> GetBounceTrackingState(); 448 449 bool CanOpenModalPicker(); 450 451 static bool ShouldEnforceParentalControls(); 452 453 void MaybeReconstructActiveEntryList(); 454 455 // Get the load listener for the current load in this browsing context. 456 already_AddRefed<net::DocumentLoadListener> GetCurrentLoad(); 457 458 // https://html.spec.whatwg.org/#concept-internal-location-ancestor-origin-objects-list 459 void CreateRedactedAncestorOriginsList( 460 nsIPrincipal* aThisDocumentPrincipal, 461 ReferrerPolicy aFrameReferrerPolicyAttribute); 462 463 Span<const nsCOMPtr<nsIPrincipal>> GetPossiblyRedactedAncestorOriginsList() 464 const; 465 void SetPossiblyRedactedAncestorOriginsList( 466 nsTArray<nsCOMPtr<nsIPrincipal>> aAncestorOriginsList); 467 468 void SetEmbedderFrameReferrerPolicy(ReferrerPolicy aPolicy); 469 470 // Called when we need to snap shot referrer policy for ancestorOrigins 471 // and also when building the internal ancestor origins list for about:blank 472 // because it needs special handling. 473 ReferrerPolicy GetEmbedderFrameReferrerPolicy() const { 474 return mEmbedderFrameReferrerPolicy; 475 } 476 477 protected: 478 // Called when the browsing context is being discarded. 479 void CanonicalDiscard(); 480 481 // Called when the browsing context is being attached. 482 void CanonicalAttach(); 483 484 // Called when the browsing context private mode is changed after 485 // being attached, but before being discarded. 486 void AdjustPrivateBrowsingCount(bool aPrivateBrowsing); 487 488 using Type = BrowsingContext::Type; 489 CanonicalBrowsingContext(WindowContext* aParentWindow, 490 BrowsingContextGroup* aGroup, 491 uint64_t aBrowsingContextId, 492 uint64_t aOwnerProcessId, 493 uint64_t aEmbedderProcessId, Type aType, 494 FieldValues&& aInit); 495 496 private: 497 friend class BrowsingContext; 498 499 virtual ~CanonicalBrowsingContext(); 500 501 class PendingRemotenessChange { 502 public: 503 NS_INLINE_DECL_REFCOUNTING(PendingRemotenessChange) 504 505 PendingRemotenessChange(CanonicalBrowsingContext* aTarget, 506 RemotenessPromise::Private* aPromise, 507 uint64_t aPendingSwitchId, 508 const NavigationIsolationOptions& aOptions); 509 510 void Cancel(nsresult aRv); 511 512 private: 513 friend class CanonicalBrowsingContext; 514 515 ~PendingRemotenessChange(); 516 MOZ_CAN_RUN_SCRIPT 517 void ProcessLaunched(); 518 MOZ_CAN_RUN_SCRIPT 519 void ProcessReady(); 520 MOZ_CAN_RUN_SCRIPT 521 void MaybeFinish(); 522 void Clear(); 523 524 MOZ_CAN_RUN_SCRIPT 525 nsresult FinishTopContent(); 526 nsresult FinishSubframe(); 527 528 RefPtr<CanonicalBrowsingContext> mTarget; 529 RefPtr<RemotenessPromise::Private> mPromise; 530 UniqueContentParentKeepAlive mContentParentKeepAlive; 531 RefPtr<BrowsingContextGroup> mSpecificGroup; 532 533 bool mProcessReady = false; 534 bool mWaitingForPrepareToChange = false; 535 536 uint64_t mPendingSwitchId; 537 NavigationIsolationOptions mOptions; 538 }; 539 540 struct RestoreState { 541 NS_INLINE_DECL_REFCOUNTING(RestoreState) 542 543 void ClearData() { mData = nullptr; } 544 void Resolve(); 545 546 RefPtr<SessionStoreRestoreData> mData; 547 RefPtr<Promise> mPromise; 548 uint32_t mRequests = 0; 549 uint32_t mResolves = 0; 550 551 private: 552 ~RestoreState() = default; 553 }; 554 555 friend class net::DocumentLoadListener; 556 // Called when a DocumentLoadListener is created to start a load for 557 // this browsing context. Returns false if a higher priority load is 558 // already in-progress and the new one has been rejected. 559 bool StartDocumentLoad(net::DocumentLoadListener* aLoad); 560 // Called once DocumentLoadListener completes handling a load, and it 561 // is either complete, or handed off to the final channel to deliver 562 // data to the destination docshell. 563 // If aContinueNavigating it set, the reference to the DocumentLoadListener 564 // will be cleared to prevent it being cancelled, however the current load ID 565 // will be preserved until `EndDocumentLoad` is called again. 566 void EndDocumentLoad(bool aContinueNavigating); 567 568 bool SupportsLoadingInParent(nsDocShellLoadState* aLoadState, 569 uint64_t* aOuterWindowId); 570 571 void HistoryCommitIndexAndLength( 572 const nsID& aChangeID, 573 const CallerWillNotifyHistoryIndexAndLengthChanges& aProofOfCaller); 574 575 struct UnloadingHost { 576 uint64_t mChildID; 577 nsTArray<std::function<void()>> mCallbacks; 578 }; 579 nsTArray<UnloadingHost>::iterator FindUnloadingHost(uint64_t aChildID); 580 581 // Called when we want to show the subframe crashed UI as our previous browser 582 // has become unloaded for one reason or another. 583 void ShowSubframeCrashedUI(BrowserBridgeParent* aBridge); 584 585 void MaybeScheduleSessionStoreUpdate(); 586 587 void CancelSessionStoreUpdate(); 588 589 void AddPendingDiscard(); 590 591 void RemovePendingDiscard(); 592 593 bool ShouldAddEntryForRefresh(const SessionHistoryEntry* aEntry) { 594 return ShouldAddEntryForRefresh(aEntry->Info().GetURI(), 595 aEntry->Info().HasPostData()); 596 } 597 bool ShouldAddEntryForRefresh(nsIURI* aNewURI, bool aHasPostData) { 598 nsCOMPtr<nsIURI> currentURI = GetCurrentURI(); 599 return BrowsingContext::ShouldAddEntryForRefresh(currentURI, aNewURI, 600 aHasPostData); 601 } 602 603 already_AddRefed<nsDocShellLoadState> CreateLoadInfo( 604 SessionHistoryEntry* aEntry, NavigationType aNavigationType); 605 606 void GetContiguousEntriesForLoad(LoadingSessionHistoryInfo& aLoadingInfo, 607 const RefPtr<SessionHistoryEntry>& aEntry); 608 609 void MaybeReuseNavigationKeyFromActiveEntry(SessionHistoryEntry* aEntry); 610 611 EntryList* GetActiveEntries(); 612 613 // XXX(farre): Store a ContentParent pointer here rather than mProcessId? 614 // Indicates which process owns the docshell. 615 uint64_t mProcessId; 616 617 // Indicates which process owns the embedder element. 618 uint64_t mEmbedderProcessId; 619 620 uint64_t mCrossGroupOpenerId = 0; 621 622 // This function will make the top window context reset its 623 // "SHEntryHasUserInteraction" cache that prevents documents from repeatedly 624 // setting user interaction on SH entries. Should be called anytime SH 625 // entries are added or replaced. 626 void ResetSHEntryHasUserInteractionCache(); 627 628 RefPtr<BrowserParent> mCurrentBrowserParent; 629 630 nsTArray<UnloadingHost> mUnloadingHosts; 631 632 // The current URI loaded in this BrowsingContext. This value is only set for 633 // BrowsingContexts loaded in content processes. 634 nsCOMPtr<nsIURI> mCurrentRemoteURI; 635 636 // The current remoteness change which is in a pending state. 637 RefPtr<PendingRemotenessChange> mPendingRemotenessChange; 638 639 RefPtr<nsSHistory> mSessionHistory; 640 641 // Tab media controller is used to control all media existing in the same 642 // browsing context tree, so it would only exist in the top level browsing 643 // context. 644 RefPtr<MediaController> mTabMediaController; 645 646 RefPtr<net::DocumentLoadListener> mCurrentLoad; 647 648 struct LoadingSessionHistoryEntry { 649 uint64_t mLoadId = 0; 650 RefPtr<SessionHistoryEntry> mEntry; 651 }; 652 nsTArray<LoadingSessionHistoryEntry> mLoadingEntries; 653 RefPtr<EntryList> mActiveEntryList; 654 RefPtr<SessionHistoryEntry> mActiveEntry; 655 656 RefPtr<nsSecureBrowserUI> mSecureBrowserUI; 657 RefPtr<BrowsingContextWebProgress> mWebProgress; 658 659 nsCOMPtr<nsIWebProgressListener> mDocShellProgressBridge; 660 RefPtr<nsBrowserStatusFilter> mStatusFilter; 661 662 Maybe<FeaturePolicyInfo> mContainerFeaturePolicyInfo; 663 664 friend class BrowserSessionStore; 665 WeakPtr<SessionStoreFormData>& GetSessionStoreFormDataRef() { 666 return mFormdata; 667 } 668 WeakPtr<SessionStoreScrollData>& GetSessionStoreScrollDataRef() { 669 return mScroll; 670 } 671 672 WeakPtr<SessionStoreFormData> mFormdata; 673 WeakPtr<SessionStoreScrollData> mScroll; 674 675 RefPtr<RestoreState> mRestoreState; 676 677 nsCOMPtr<nsITimer> mSessionStoreSessionStorageUpdateTimer; 678 679 // If this is a top level context, this is true if our browser ID is marked as 680 // active in the process priority manager. 681 bool mPriorityActive = false; 682 683 // See CanonicalBrowsingContext.forceAppWindowActive. 684 bool mForceAppWindowActive = false; 685 686 bool mIsReplaced = false; 687 688 // A Promise created when cloning documents for printing. 689 RefPtr<GenericNonExclusivePromise> mClonePromise; 690 691 JS::Heap<JS::Value> mPermanentKey; 692 693 uint32_t mPendingDiscards = 0; 694 695 bool mFullyDiscarded = false; 696 // the referrerPolicy attribute of the iframe hosting this browsing context 697 // defaults to the empty string 698 ReferrerPolicy mEmbedderFrameReferrerPolicy = ReferrerPolicy::_empty; 699 700 nsTArray<std::function<void(uint64_t)>> mFullyDiscardedListeners; 701 702 // https://html.spec.whatwg.org/#concept-internal-location-ancestor-origin-objects-list 703 nsTArray<nsCOMPtr<nsIPrincipal>> mPossiblyRedactedAncestorOriginsList; 704 }; 705 706 } // namespace dom 707 } // namespace mozilla 708 709 #endif // !defined(mozilla_dom_CanonicalBrowsingContext_h)