From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/base/nsFrameLoader.cpp | 3925 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 3925 insertions(+) create mode 100644 dom/base/nsFrameLoader.cpp (limited to 'dom/base/nsFrameLoader.cpp') diff --git a/dom/base/nsFrameLoader.cpp b/dom/base/nsFrameLoader.cpp new file mode 100644 index 0000000000..0b809adece --- /dev/null +++ b/dom/base/nsFrameLoader.cpp @@ -0,0 +1,3925 @@ +/* -*- 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). + */ + +#include "nsFrameLoader.h" + +#include "base/basictypes.h" + +#include "prenv.h" + +#include "nsDocShell.h" +#include "nsIContentInlines.h" +#include "nsIContentViewer.h" +#include "nsIPrintSettings.h" +#include "nsIPrintSettingsService.h" +#include "mozilla/dom/Document.h" +#include "nsPIDOMWindow.h" +#include "nsIWebNavigation.h" +#include "nsIWebProgress.h" +#include "nsIDocShell.h" +#include "nsIDocShellTreeOwner.h" +#include "nsDocShellLoadState.h" +#include "nsIBaseWindow.h" +#include "nsIBrowser.h" +#include "nsContentUtils.h" +#include "nsUnicharUtils.h" +#include "nsIScriptGlobalObject.h" +#include "nsIScriptSecurityManager.h" +#include "nsFrameLoaderOwner.h" +#include "nsIFrame.h" +#include "nsIScrollableFrame.h" +#include "nsSubDocumentFrame.h" +#include "nsError.h" +#include "nsIAppWindow.h" +#include "nsIMozBrowserFrame.h" +#include "nsIScriptError.h" +#include "nsGlobalWindow.h" +#include "nsHTMLDocument.h" +#include "nsPIWindowRoot.h" +#include "nsLayoutUtils.h" +#include "nsMappedAttributes.h" +#include "nsView.h" +#include "nsBaseWidget.h" +#include "nsQueryObject.h" +#include "ReferrerInfo.h" +#include "nsIOpenWindowInfo.h" +#include "nsISHistory.h" +#include "nsIURI.h" +#include "nsIXULRuntime.h" +#include "nsNetUtil.h" +#include "nsFocusManager.h" +#include "nsIINIParser.h" +#include "nsAppRunner.h" +#include "nsDirectoryService.h" +#include "nsDirectoryServiceDefs.h" + +#include "nsGkAtoms.h" +#include "nsNameSpaceManager.h" + +#include "nsThreadUtils.h" + +#include "nsIDOMChromeWindow.h" +#include "InProcessBrowserChildMessageManager.h" + +#include "ContentParent.h" +#include "BrowserParent.h" +#include "mozilla/AsyncEventDispatcher.h" +#include "mozilla/BasePrincipal.h" +#include "mozilla/ExpandedPrincipal.h" +#include "mozilla/FlushType.h" +#include "mozilla/HTMLEditor.h" +#include "mozilla/NullPrincipal.h" +#include "mozilla/Preferences.h" +#include "mozilla/PresShell.h" +#include "mozilla/PresShellInlines.h" +#include "mozilla/ProcessPriorityManager.h" +#include "mozilla/ScopeExit.h" +#include "mozilla/StaticPrefs_fission.h" +#include "mozilla/Unused.h" +#include "mozilla/dom/BrowsingContext.h" +#include "mozilla/dom/ChromeMessageSender.h" +#include "mozilla/dom/Element.h" +#include "mozilla/dom/FrameCrashedEvent.h" +#include "mozilla/dom/FrameLoaderBinding.h" +#include "mozilla/dom/InProcessChild.h" +#include "mozilla/dom/MozFrameLoaderOwnerBinding.h" +#include "mozilla/dom/PBrowser.h" +#include "mozilla/dom/SessionHistoryEntry.h" +#include "mozilla/dom/SessionStoreChild.h" +#include "mozilla/dom/SessionStoreParent.h" +#include "mozilla/dom/SessionStoreUtils.h" +#include "mozilla/dom/WindowGlobalParent.h" +#include "mozilla/dom/XULFrameElement.h" +#include "mozilla/gfx/CrossProcessPaint.h" +#include "mozilla/ProfilerLabels.h" +#include "nsGenericHTMLFrameElement.h" + +#include "jsapi.h" +#include "mozilla/dom/HTMLIFrameElement.h" +#include "nsSandboxFlags.h" +#include "mozilla/layers/CompositorBridgeChild.h" +#include "mozilla/dom/CustomEvent.h" + +#include "mozilla/dom/ipc/StructuredCloneData.h" +#include "mozilla/WebBrowserPersistLocalDocument.h" +#include "mozilla/dom/Promise.h" +#include "mozilla/dom/PromiseNativeHandler.h" +#include "mozilla/dom/ChildSHistory.h" +#include "mozilla/dom/CanonicalBrowsingContext.h" +#include "mozilla/dom/ContentChild.h" +#include "mozilla/dom/ContentProcessManager.h" +#include "mozilla/dom/BrowserBridgeChild.h" +#include "mozilla/dom/BrowserHost.h" +#include "mozilla/dom/BrowserBridgeHost.h" +#include "mozilla/dom/BrowsingContextGroup.h" + +#include "mozilla/dom/SessionStorageManager.h" +#include "mozilla/ipc/BackgroundChild.h" +#include "mozilla/ipc/PBackgroundChild.h" +#include "mozilla/dom/PBackgroundSessionStorageCache.h" +#include "mozilla/ipc/BackgroundUtils.h" + +#include "mozilla/dom/HTMLBodyElement.h" + +#include "mozilla/ContentPrincipal.h" + +#include "nsXULPopupManager.h" + +#ifdef NS_PRINTING +# include "nsIWebBrowserPrint.h" +#endif + +#if defined(MOZ_TELEMETRY_REPORTING) +# include "mozilla/Telemetry.h" +#endif // defined(MOZ_TELEMETRY_REPORTING) + +using namespace mozilla; +using namespace mozilla::hal; +using namespace mozilla::dom; +using namespace mozilla::dom::ipc; +using namespace mozilla::ipc; +using namespace mozilla::layers; +using namespace mozilla::layout; +using ViewID = ScrollableLayerGuid::ViewID; + +using PrintPreviewResolver = std::function; + +// Bug 8065: Limit content frame depth to some reasonable level. This +// does not count chrome frames when determining depth, nor does it +// prevent chrome recursion. Number is fairly arbitrary, but meant to +// keep number of shells to a reasonable number on accidental recursion with a +// small (but not 1) branching factor. With large branching factors the number +// of shells can rapidly become huge and run us out of memory. To solve that, +// we'd need to re-institute a fixed version of bug 98158. +#define MAX_DEPTH_CONTENT_FRAMES 10 + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsFrameLoader, mPendingBrowsingContext, + mMessageManager, mChildMessageManager, + mRemoteBrowser, mSessionStoreChild) +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFrameLoader) +NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFrameLoader) + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFrameLoader) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY_CONCRETE(nsFrameLoader) + NS_INTERFACE_MAP_ENTRY(nsIMutationObserver) + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +nsFrameLoader::nsFrameLoader(Element* aOwner, BrowsingContext* aBrowsingContext, + bool aIsRemoteFrame, bool aNetworkCreated) + : mPendingBrowsingContext(aBrowsingContext), + mOwnerContent(aOwner), + mDetachedSubdocFrame(nullptr), + mPendingSwitchID(0), + mChildID(0), + mRemoteType(NOT_REMOTE_TYPE), + mInitialized(false), + mDepthTooGreat(false), + mIsTopLevelContent(false), + mDestroyCalled(false), + mNeedsAsyncDestroy(false), + mInSwap(false), + mInShow(false), + mHideCalled(false), + mNetworkCreated(aNetworkCreated), + mLoadingOriginalSrc(false), + mRemoteBrowserShown(false), + mIsRemoteFrame(aIsRemoteFrame), + mWillChangeProcess(false), + mObservingOwnerContent(false), + mTabProcessCrashFired(false) { + nsCOMPtr owner = do_QueryInterface(aOwner); + owner->AttachFrameLoader(this); +} + +nsFrameLoader::~nsFrameLoader() { + if (mMessageManager) { + mMessageManager->Disconnect(); + } + + MOZ_ASSERT(!mOwnerContent); + MOZ_RELEASE_ASSERT(mDestroyCalled); +} + +static nsAtom* TypeAttrName(Element* aOwnerContent) { + return aOwnerContent->IsXULElement() ? nsGkAtoms::type + : nsGkAtoms::mozframetype; +} + +static void GetFrameName(Element* aOwnerContent, nsAString& aFrameName) { + int32_t namespaceID = aOwnerContent->GetNameSpaceID(); + if (namespaceID == kNameSpaceID_XHTML && !aOwnerContent->IsInHTMLDocument()) { + aOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::id, aFrameName); + } else { + aOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::name, aFrameName); + // XXX if no NAME then use ID, after a transition period this will be + // changed so that XUL only uses ID too (bug 254284). + if (aFrameName.IsEmpty() && namespaceID == kNameSpaceID_XUL) { + aOwnerContent->GetAttr(kNameSpaceID_None, nsGkAtoms::id, aFrameName); + } + } +} + +// If this method returns true, the nsFrameLoader will act as a boundary, as is +// the case for