/* -*- 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 "mozilla/BasePrincipal.h" #include "mozilla/HalScreenConfiguration.h" #include "mozilla/LinkedList.h" #include "mozilla/Maybe.h" #include "mozilla/Move.h" #include "mozilla/TimeStamp.h" #include "mozilla/UniquePtr.h" #include "mozilla/WeakPtr.h" #include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/ProfileTimelineMarkerBinding.h" #include "mozilla/gfx/Matrix.h" #include "mozilla/dom/ChildSHistory.h" #include "nsIAuthPromptProvider.h" #include "nsIBaseWindow.h" #include "nsIDeprecationWarner.h" #include "nsIDocShell.h" #include "nsIDocShellTreeItem.h" #include "nsIDOMStorageManager.h" #include "nsIInterfaceRequestor.h" #include "nsILinkHandler.h" #include "nsILoadContext.h" #include "nsILoadURIDelegate.h" #include "nsINetworkInterceptController.h" #include "nsIRefreshURI.h" #include "nsIScrollable.h" #include "nsIRemoteTab.h" #include "nsIWebNavigation.h" #include "nsIWebPageDescriptor.h" #include "nsIWebProgressListener.h" #include "nsAutoPtr.h" #include "nsCharsetSource.h" #include "nsCOMPtr.h" #include "nsContentPolicyUtils.h" #include "nsContentUtils.h" #include "nsCRT.h" #include "nsDocLoader.h" #include "nsPoint.h" // mCurrent/mDefaultScrollbarPreferences #include "nsRect.h" #include "nsString.h" #include "nsThreadUtils.h" #include "GeckoProfiler.h" #include "jsapi.h" #include "prtime.h" #include "Units.h" #include "mozilla/ObservedDocShell.h" #include "mozilla/TimelineConsumers.h" #include "mozilla/TimelineMarker.h" // Interfaces Needed namespace mozilla { class Encoding; class HTMLEditor; enum class TaskCategory; namespace dom { class ClientInfo; class ClientSource; class EventTarget; } // namespace dom } // namespace mozilla class nsIContentViewer; class nsIController; class nsIDocShellTreeOwner; class nsIHttpChannel; class nsIMutableArray; class nsIPrompt; class nsIScrollableFrame; class nsISecureBrowserUI; class nsISHistory; class nsIStringBundle; class nsIURIFixup; class nsIURILoader; class nsIWebBrowserFind; class nsIWidget; class nsIReferrerInfo; class nsCommandManager; class nsDocShell; class nsDocShellEditorData; class nsDOMNavigationTiming; class nsDSURIContentListener; class nsGlobalWindowInner; class nsGlobalWindowOuter; class FramingChecker; class OnLinkClickEvent; /* internally used ViewMode types */ enum ViewMode { viewNormal = 0x0, viewSource = 0x1 }; enum eCharsetReloadState { eCharsetReloadInit, eCharsetReloadRequested, eCharsetReloadStopOrigional }; class nsDocShell final : public nsDocLoader, public nsIDocShell, public nsIWebNavigation, public nsIBaseWindow, public nsIScrollable, public nsIRefreshURI, public nsIWebProgressListener, public nsIWebPageDescriptor, public nsIAuthPromptProvider, public nsILoadContext, public nsILinkHandler, public nsIDOMStorageManager, public nsINetworkInterceptController, public nsIDeprecationWarner, public mozilla::SupportsWeakPtr { public: enum InternalLoad : uint32_t { INTERNAL_LOAD_FLAGS_NONE = 0x0, INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL = 0x1, INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER = 0x2, INTERNAL_LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP = 0x4, // This flag marks the first load in this object // @see nsIWebNavigation::LOAD_FLAGS_FIRST_LOAD INTERNAL_LOAD_FLAGS_FIRST_LOAD = 0x8, // The set of flags that should not be set before calling into // nsDocShell::LoadURI and other nsDocShell loading functions. INTERNAL_LOAD_FLAGS_LOADURI_SETUP_FLAGS = 0xf, INTERNAL_LOAD_FLAGS_BYPASS_CLASSIFIER = 0x10, INTERNAL_LOAD_FLAGS_FORCE_ALLOW_COOKIES = 0x20, // Whether the load should be treated as srcdoc load, rather than a URI one. INTERNAL_LOAD_FLAGS_IS_SRCDOC = 0x40, // Whether this is the load of a frame's original src attribute INTERNAL_LOAD_FLAGS_ORIGINAL_FRAME_SRC = 0x80, INTERNAL_LOAD_FLAGS_NO_OPENER = 0x100, // Whether a top-level data URI navigation is allowed for that load INTERNAL_LOAD_FLAGS_FORCE_ALLOW_DATA_URI = 0x200, // Whether the load was triggered by user interaction. INTERNAL_LOAD_FLAGS_IS_USER_TRIGGERED = 0x1000, }; // Event type dispatched by RestorePresentation class RestorePresentationEvent : public mozilla::Runnable { public: NS_DECL_NSIRUNNABLE explicit RestorePresentationEvent(nsDocShell* aDs) : mozilla::Runnable("nsDocShell::RestorePresentationEvent"), mDocShell(aDs) {} void Revoke() { mDocShell = nullptr; } private: RefPtr mDocShell; }; class InterfaceRequestorProxy : public nsIInterfaceRequestor { public: explicit InterfaceRequestorProxy(nsIInterfaceRequestor* aRequestor); NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSIINTERFACEREQUESTOR private: virtual ~InterfaceRequestorProxy(); InterfaceRequestorProxy() {} nsWeakPtr mWeakPtr; }; MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsDocShell) NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDocShell, nsDocLoader) NS_DECL_NSIDOCSHELL NS_DECL_NSIDOCSHELLTREEITEM NS_DECL_NSIWEBNAVIGATION NS_DECL_NSIBASEWINDOW NS_DECL_NSISCROLLABLE NS_DECL_NSIINTERFACEREQUESTOR NS_DECL_NSIWEBPROGRESSLISTENER NS_DECL_NSIREFRESHURI NS_DECL_NSIWEBPAGEDESCRIPTOR NS_DECL_NSIAUTHPROMPTPROVIDER NS_DECL_NSINETWORKINTERCEPTCONTROLLER NS_DECL_NSIDEPRECATIONWARNER NS_FORWARD_SAFE_NSIDOMSTORAGEMANAGER(TopSessionStorageManager()) // Create a new nsDocShell object, initializing it. static already_AddRefed Create( mozilla::dom::BrowsingContext* aBrowsingContext); NS_IMETHOD Stop() override { // Need this here because otherwise nsIWebNavigation::Stop // overrides the docloader's Stop() return nsDocLoader::Stop(); } // nsILinkHandler NS_IMETHOD OnLinkClick(nsIContent* aContent, nsIURI* aURI, const nsAString& aTargetSpec, const nsAString& aFileName, nsIInputStream* aPostDataStream, nsIInputStream* aHeadersDataStream, bool aIsUserTriggered, bool aIsTrusted, nsIPrincipal* aTriggeringPrincipal, nsIContentSecurityPolicy* aCsp) override; NS_IMETHOD OnLinkClickSync( nsIContent* aContent, nsIURI* aURI, const nsAString& aTargetSpec, const nsAString& aFileName, nsIInputStream* aPostDataStream = 0, nsIInputStream* aHeadersDataStream = 0, bool aNoOpenerImplied = false, nsIDocShell** aDocShell = 0, nsIRequest** aRequest = 0, bool aIsUserTriggered = false, nsIPrincipal* aTriggeringPrincipal = nullptr, nsIContentSecurityPolicy* aCsp = nullptr) override; NS_IMETHOD OnOverLink(nsIContent* aContent, nsIURI* aURI, const nsAString& aTargetSpec) override; NS_IMETHOD OnLeaveLink() override; // Don't use NS_DECL_NSILOADCONTEXT because some of nsILoadContext's methods // are shared with nsIDocShell and can't be declared twice. NS_IMETHOD GetAssociatedWindow(mozIDOMWindowProxy**) override; NS_IMETHOD GetTopWindow(mozIDOMWindowProxy**) override; NS_IMETHOD GetTopFrameElement(mozilla::dom::Element**) 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 GetUseRemoteSubframes(bool*) override; NS_IMETHOD SetRemoteSubframes(bool) override; NS_IMETHOD GetScriptableOriginAttributes( JSContext*, JS::MutableHandle) override; NS_IMETHOD_(void) GetOriginAttributes(mozilla::OriginAttributes& aAttrs) 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, nsIPrincipal* aPrincipal, int32_t aDelay, bool aMetaRefresh, nsITimer* aTimer); // 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 HistoryEntryRemoved(int32_t aIndex); // Notify Scroll observers when an async panning/zooming transform // has started being applied MOZ_CAN_RUN_SCRIPT_BOUNDARY void NotifyAsyncPanZoomStarted(); // Notify Scroll observers when an async panning/zooming transform // is no longer applied MOZ_CAN_RUN_SCRIPT_BOUNDARY void NotifyAsyncPanZoomStopped(); void SetInFrameSwap(bool aInSwap) { mInFrameSwap = aInSwap; } bool InFrameSwap(); void SetIsFrame() { mIsFrame = true; }; const mozilla::Encoding* GetForcedCharset() { return mForcedCharset; } mozilla::HTMLEditor* GetHTMLEditorInternal(); nsresult SetHTMLEditorInternal(mozilla::HTMLEditor* aHTMLEditor); // Handle page navigation due to charset changes nsresult CharsetChangeReloadDocument(const char* aCharset = nullptr, int32_t aSource = kCharsetUninitialized); nsresult CharsetChangeStopDocumentLoad(); nsDOMNavigationTiming* GetNavigationTiming() const; nsresult SetOriginAttributes(const mozilla::OriginAttributes& aAttrs); /** * 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