/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* * Class for managing loading of a subframe (creation of the docshell, * handling of loads in it, recursion-checking). */ #ifndef nsFrameLoader_h_ #define nsFrameLoader_h_ #include "nsDocShell.h" #include "nsStringFwd.h" #include "nsPoint.h" #include "nsSize.h" #include "nsWrapperCache.h" #include "nsIURI.h" #include "nsFrameMessageManager.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/RemoteBrowser.h" #include "mozilla/Attributes.h" #include "mozilla/ScrollbarPreferences.h" #include "mozilla/layers/LayersTypes.h" #include "nsStubMutationObserver.h" #include "Units.h" #include "nsIFrame.h" #include "nsPluginTags.h" class nsIURI; class nsSubDocumentFrame; class nsView; class AutoResetInShow; class AutoResetInFrameSwap; class nsFrameLoaderOwner; class nsIRemoteTab; class nsIDocShellTreeItem; class nsIDocShellTreeOwner; class nsILoadContext; class nsIMessageSender; class nsIPrintSettings; class nsIWebBrowserPersistDocumentReceiver; class nsIWebProgressListener; class nsIOpenWindowInfo; namespace mozilla { class OriginAttributes; namespace dom { class ChromeMessageSender; class ContentParent; class TabListener; class InProcessBrowserChildMessageManager; class MessageSender; class PBrowserParent; class ProcessMessageManager; class Promise; class BrowserParent; class MutableTabContext; class BrowserBridgeChild; struct RemotenessOptions; namespace ipc { class StructuredCloneData; } // namespace ipc } // namespace dom namespace ipc { class MessageChannel; } // namespace ipc } // namespace mozilla #if defined(MOZ_WIDGET_GTK) typedef struct _GtkWidget GtkWidget; #endif // IID for nsFrameLoader, because some places want to QI to it. #define NS_FRAMELOADER_IID \ { \ 0x297fd0ea, 0x1b4a, 0x4c9a, { \ 0xa4, 0x04, 0xe5, 0x8b, 0xe8, 0x95, 0x10, 0x50 \ } \ } class nsFrameLoader final : public nsStubMutationObserver, public mozilla::dom::ipc::MessageManagerCallback, public nsWrapperCache { friend class AutoResetInShow; friend class AutoResetInFrameSwap; friend class nsFrameLoaderOwner; typedef mozilla::dom::Document Document; typedef mozilla::dom::Element Element; typedef mozilla::dom::BrowserParent BrowserParent; typedef mozilla::dom::BrowserBridgeChild BrowserBridgeChild; typedef mozilla::dom::BrowsingContext BrowsingContext; public: // Called by Frame Elements to create a new FrameLoader. static already_AddRefed Create( Element* aOwner, bool aNetworkCreated, nsIOpenWindowInfo* aOpenWindowInfo = nullptr); // Called by nsFrameLoaderOwner::ChangeRemoteness when switching out // FrameLoaders. static already_AddRefed Recreate(Element* aOwner, BrowsingContext* aContext, const nsAString& aRemoteType, bool aNetworkCreated, bool aPreserveContext); NS_DECLARE_STATIC_IID_ACCESSOR(NS_FRAMELOADER_IID) NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsFrameLoader) NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED nsresult CheckForRecursiveLoad(nsIURI* aURI); nsresult ReallyStartLoading(); void StartDestroy(bool aForProcessSwitch); void DestroyDocShell(); void DestroyComplete(); nsIDocShell* GetExistingDocShell() const { return mDocShell; } mozilla::dom::InProcessBrowserChildMessageManager* GetBrowserChildMessageManager() const { return mChildMessageManager; } nsresult UpdatePositionAndSize(nsSubDocumentFrame* aIFrame); void SendIsUnderHiddenEmbedderElement(bool aIsUnderHiddenEmbedderElement); // When creating a nsFrameLoaderOwner which is a static clone, a // `nsFrameLoader` is not immediately attached to it. Instead, it is added to // the static clone document's `PendingFrameStaticClones` list. // // After the parent document has been fully cloned, a new frameloader will be // created for the cloned iframe, and `FinishStaticClone` will be called on // it, which will clone the inner document of the source nsFrameLoader. // // The `aCloneDocShell` and `aCloneDocument` outparameters will be filled with // the values from the newly cloned subframe. nsresult FinishStaticClone(nsFrameLoader* aStaticCloneOf, nsIDocShell** aCloneDocShell, Document** aCloneDocument); // WebIDL methods nsDocShell* GetDocShell(mozilla::ErrorResult& aRv); already_AddRefed GetRemoteTab(); already_AddRefed LoadContext(); mozilla::dom::BrowsingContext* GetBrowsingContext(); mozilla::dom::BrowsingContext* GetExtantBrowsingContext(); /** * Start loading the frame. This method figures out what to load * from the owner content in the frame loader. */ void LoadFrame(bool aOriginalSrc); /** * Loads the specified URI in this frame. Behaves identically to loadFrame, * except that this method allows specifying the URI to load. * * @param aURI The URI to load. * @param aTriggeringPrincipal The triggering principal for the load. May be * null, in which case the node principal of the owner content will be * used. * @param aCsp The CSP to be used for the load. That is not the CSP to be * applied to subresources within the frame, but to the iframe load * itself. E.g. if the CSP holds upgrade-insecure-requests the the * frame load is upgraded from http to https. */ nsresult LoadURI(nsIURI* aURI, nsIPrincipal* aTriggeringPrincipal, nsIContentSecurityPolicy* aCsp, bool aOriginalSrc); /** * Resume a redirected load within this frame. * * @param aPendingSwitchID ID of a process-switching load to be reusmed * within this frame. */ void ResumeLoad(uint64_t aPendingSwitchID); /** * Destroy the frame loader and everything inside it. This will * clear the weak owner content reference. */ void Destroy(bool aForProcessSwitch = false); void ActivateRemoteFrame(mozilla::ErrorResult& aRv); void DeactivateRemoteFrame(mozilla::ErrorResult& aRv); void SendCrossProcessMouseEvent(const nsAString& aType, float aX, float aY, int32_t aButton, int32_t aClickCount, int32_t aModifiers, mozilla::ErrorResult& aRv); void ActivateFrameEvent(const nsAString& aType, bool aCapture, mozilla::ErrorResult& aRv); void RequestNotifyAfterRemotePaint(); void RequestUpdatePosition(mozilla::ErrorResult& aRv); bool RequestTabStateFlush(uint32_t aFlushId, bool aIsFinal = false); void RequestEpochUpdate(uint32_t aEpoch); void RequestSHistoryUpdate(bool aImmediately = false); void Print(uint64_t aOuterWindowID, nsIPrintSettings* aPrintSettings, nsIWebProgressListener* aProgressListener, mozilla::ErrorResult& aRv); void StartPersistence(BrowsingContext* aContext, nsIWebBrowserPersistDocumentReceiver* aRecv, mozilla::ErrorResult& aRv); // WebIDL getters already_AddRefed GetMessageManager(); already_AddRefed GetOwnerElement(); uint32_t LazyWidth() const; uint32_t LazyHeight() const; uint64_t ChildID() const { return mChildID; } bool DepthTooGreat() const { return mDepthTooGreat; } bool IsDead() const { return mDestroyCalled; } bool IsNetworkCreated() const { return mNetworkCreated; } /** * Is this a frame loader for a bona fide