/* -*- 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/. */ #ifndef nsDocShell_h__ #define nsDocShell_h__ #include "nsITimer.h" #include "nsContentPolicyUtils.h" #include "nsIDocShell.h" #include "nsIDocShellTreeItem.h" #include "nsIBaseWindow.h" #include "nsINetworkInterceptController.h" #include "nsIScrollable.h" #include "nsITextScroll.h" #include "nsIContentViewerContainer.h" #include "nsIDOMStorageManager.h" #include "nsDocLoader.h" #include "mozilla/BasePrincipal.h" #include "mozilla/Move.h" #include "mozilla/UniquePtr.h" #include "mozilla/WeakPtr.h" #include "mozilla/TimeStamp.h" #include "GeckoProfiler.h" #include "mozilla/dom/ProfileTimelineMarkerBinding.h" #include "mozilla/LinkedList.h" #include "jsapi.h" // Helper Classes #include "nsCOMPtr.h" #include "nsPoint.h" // mCurrent/mDefaultScrollbarPreferences #include "nsString.h" #include "nsAutoPtr.h" #include "nsThreadUtils.h" #include "nsContentUtils.h" #include "timeline/ObservedDocShell.h" #include "timeline/TimelineConsumers.h" #include "timeline/TimelineMarker.h" // Threshold value in ms for META refresh based redirects #define REFRESH_REDIRECT_TIMER 15000 // Interfaces Needed #include "nsIDocCharset.h" #include "nsIInterfaceRequestor.h" #include "nsINamed.h" #include "nsIRefreshURI.h" #include "nsIWebNavigation.h" #include "nsIWebPageDescriptor.h" #include "nsIWebProgressListener.h" #include "nsIDocShellLoadInfo.h" #include "nsIAuthPromptProvider.h" #include "nsILoadContext.h" #include "nsIWebShellServices.h" #include "nsILinkHandler.h" #include "nsIClipboardCommands.h" #include "nsITabParent.h" #include "nsCRT.h" #include "prtime.h" #include "nsRect.h" #include "Units.h" #include "nsIDeprecationWarner.h" #include "nsILoadURIDelegate.h" namespace mozilla { class Encoding; class HTMLEditor; enum class TaskCategory; namespace dom { class EventTarget; class PendingGlobalHistoryEntry; typedef uint32_t ScreenOrientationInternal; } // namespace dom } // namespace mozilla class nsDocShell; class nsDOMNavigationTiming; class nsGlobalWindow; class nsIController; class nsIScrollableFrame; class OnLinkClickEvent; class nsDSURIContentListener; class nsDocShellEditorData; class nsIClipboardDragDropHookList; class nsICommandManager; class nsIContentViewer; class nsIDocument; class nsIDOMNode; class nsIDocShellTreeOwner; class nsIGlobalHistory2; class nsIHttpChannel; class nsIMutableArray; class nsIPrompt; class nsISHistory; class nsISecureBrowserUI; class nsIStringBundle; class nsIURIFixup; class nsIURILoader; class nsIWebBrowserFind; class nsIWidget; class FramingChecker; /* internally used ViewMode types */ enum ViewMode { viewNormal = 0x0, viewSource = 0x1 }; class nsRefreshTimer : public nsITimerCallback , public nsINamed { public: nsRefreshTimer(nsDocShell* aDocShell, nsIURI* aURI, int32_t aDelay, bool aRepeat, bool aMetaRefresh); NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSITIMERCALLBACK NS_DECL_NSINAMED int32_t GetDelay() { return mDelay ;} RefPtr mDocShell; nsCOMPtr mURI; int32_t mDelay; bool mRepeat; bool mMetaRefresh; protected: virtual ~nsRefreshTimer(); }; enum eCharsetReloadState { eCharsetReloadInit, eCharsetReloadRequested, eCharsetReloadStopOrigional }; class nsDocShell final : public nsDocLoader , public nsIDocShell , public nsIWebNavigation , public nsIBaseWindow , public nsIScrollable , public nsITextScroll , public nsIDocCharset , public nsIContentViewerContainer , public nsIRefreshURI , public nsIWebProgressListener , public nsIWebPageDescriptor , public nsIAuthPromptProvider , public nsILoadContext , public nsIWebShellServices , public nsILinkHandler , public nsIClipboardCommands , public nsIDOMStorageManager , public nsINetworkInterceptController , public nsIDeprecationWarner , public mozilla::SupportsWeakPtr { friend class nsDSURIContentListener; friend class FramingChecker; using Encoding = mozilla::Encoding; public: MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsDocShell) nsDocShell(); virtual nsresult Init() override; NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIDOCSHELL NS_DECL_NSIDOCSHELLTREEITEM NS_DECL_NSIWEBNAVIGATION NS_DECL_NSIBASEWINDOW NS_DECL_NSISCROLLABLE NS_DECL_NSITEXTSCROLL NS_DECL_NSIDOCCHARSET NS_DECL_NSIINTERFACEREQUESTOR NS_DECL_NSIWEBPROGRESSLISTENER NS_DECL_NSIREFRESHURI NS_DECL_NSICONTENTVIEWERCONTAINER NS_DECL_NSIWEBPAGEDESCRIPTOR NS_DECL_NSIAUTHPROMPTPROVIDER NS_DECL_NSICLIPBOARDCOMMANDS NS_DECL_NSIWEBSHELLSERVICES NS_DECL_NSINETWORKINTERCEPTCONTROLLER NS_DECL_NSIDEPRECATIONWARNER NS_FORWARD_SAFE_NSIDOMSTORAGEMANAGER(TopSessionStorageManager()) NS_IMETHOD Stop() override { // Need this here because otherwise nsIWebNavigation::Stop // overrides the docloader's Stop() return nsDocLoader::Stop(); } // Need to implement (and forward) nsISecurityEventSink, because // nsIWebProgressListener has methods with identical names... NS_FORWARD_NSISECURITYEVENTSINK(nsDocLoader::) // nsILinkHandler NS_IMETHOD OnLinkClick(nsIContent* aContent, nsIURI* aURI, const char16_t* aTargetSpec, const nsAString& aFileName, nsIInputStream* aPostDataStream, int64_t aPostDataStreamLength, nsIInputStream* aHeadersDataStream, bool aIsTrusted, nsIPrincipal* aTriggeringPrincipal) override; NS_IMETHOD OnLinkClickSync(nsIContent* aContent, nsIURI* aURI, const char16_t* aTargetSpec, const nsAString& aFileName, nsIInputStream* aPostDataStream = 0, int64_t aPostDataStreamLength = -1, nsIInputStream* aHeadersDataStream = 0, bool aNoOpenerImplied = false, nsIDocShell** aDocShell = 0, nsIRequest** aRequest = 0, nsIPrincipal* aTriggeringPrincipal = nullptr) override; NS_IMETHOD OnOverLink(nsIContent* aContent, nsIURI* aURI, const char16_t* aTargetSpec) override; NS_IMETHOD OnLeaveLink() override; nsDocShellInfoLoadType ConvertLoadTypeToDocShellLoadInfo(uint32_t aLoadType); uint32_t ConvertDocShellLoadInfoToLoadType( nsDocShellInfoLoadType aDocShellLoadType); // Don't use NS_DECL_NSILOADCONTEXT because some of nsILoadContext's methods // are shared with nsIDocShell (appID, etc.) and can't be declared twice. NS_IMETHOD GetAssociatedWindow(mozIDOMWindowProxy**) override; NS_IMETHOD GetTopWindow(mozIDOMWindowProxy**) override; NS_IMETHOD GetTopFrameElement(nsIDOMElement**) override; NS_IMETHOD GetNestedFrameId(uint64_t*) override; NS_IMETHOD GetIsContent(bool*) override; NS_IMETHOD GetUsePrivateBrowsing(bool*) override; NS_IMETHOD SetUsePrivateBrowsing(bool) override; NS_IMETHOD SetPrivateBrowsing(bool) override; NS_IMETHOD GetUseRemoteTabs(bool*) override; NS_IMETHOD SetRemoteTabs(bool) override; NS_IMETHOD GetScriptableOriginAttributes(JS::MutableHandle) override; // Restores a cached presentation from history (mLSHE). // This method swaps out the content viewer and simulates loads for // subframes. It then simulates the completion of the toplevel load. nsresult RestoreFromHistory(); // Perform a URI load from a refresh timer. This is just like the // ForceRefreshURI method on nsIRefreshURI, but makes sure to take // the timer involved out of mRefreshURIList if it's there. // aTimer must not be null. nsresult ForceRefreshURIFromTimer(nsIURI* aURI, int32_t aDelay, bool aMetaRefresh, nsITimer* aTimer); friend class OnLinkClickEvent; static bool SandboxFlagsImplyCookies(const uint32_t &aSandboxFlags); // We need dummy OnLocationChange in some cases to update the UI without // updating security info. void FireDummyOnLocationChange() { FireOnLocationChange(this, nullptr, mCurrentURI, LOCATION_CHANGE_SAME_DOCUMENT); } nsresult HistoryTransactionRemoved(int32_t aIndex); // Notify Scroll observers when an async panning/zooming transform // has started being applied void NotifyAsyncPanZoomStarted(); // Notify Scroll observers when an async panning/zooming transform // is no longer applied void NotifyAsyncPanZoomStopped(); void SetInFrameSwap(bool aInSwap) { mInFrameSwap = aInSwap; } bool InFrameSwap(); const Encoding* GetForcedCharset() { return mForcedCharset; } mozilla::HTMLEditor* GetHTMLEditorInternal(); nsresult SetHTMLEditorInternal(mozilla::HTMLEditor* aHTMLEditor); nsDOMNavigationTiming* GetNavigationTiming() const; /** * Get the list of ancestor principals for this docshell. The list is meant * to be the list of principals of the documents this docshell is "nested * through" in the sense of * . * In practice, it is defined as follows: * * If this is an