nsDocShell.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsDocShell_h__
  6. #define nsDocShell_h__
  7. #include "nsITimer.h"
  8. #include "nsContentPolicyUtils.h"
  9. #include "nsIDocShell.h"
  10. #include "nsIDocShellTreeItem.h"
  11. #include "nsIBaseWindow.h"
  12. #include "nsINetworkInterceptController.h"
  13. #include "nsIScrollable.h"
  14. #include "nsITextScroll.h"
  15. #include "nsIContentViewerContainer.h"
  16. #include "nsIDOMStorageManager.h"
  17. #include "nsDocLoader.h"
  18. #include "mozilla/BasePrincipal.h"
  19. #include "mozilla/UniquePtr.h"
  20. #include "mozilla/WeakPtr.h"
  21. #include "mozilla/TimeStamp.h"
  22. #include "GeckoProfiler.h"
  23. #include "mozilla/dom/ProfileTimelineMarkerBinding.h"
  24. #include "mozilla/LinkedList.h"
  25. #include "jsapi.h"
  26. // Helper Classes
  27. #include "nsCOMPtr.h"
  28. #include "nsPoint.h" // mCurrent/mDefaultScrollbarPreferences
  29. #include "nsString.h"
  30. #include "nsAutoPtr.h"
  31. #include "nsThreadUtils.h"
  32. #include "nsContentUtils.h"
  33. #include "timeline/ObservedDocShell.h"
  34. #include "timeline/TimelineConsumers.h"
  35. #include "timeline/TimelineMarker.h"
  36. // Threshold value in ms for META refresh based redirects
  37. #define REFRESH_REDIRECT_TIMER 15000
  38. // Interfaces Needed
  39. #include "nsIDocCharset.h"
  40. #include "nsIInterfaceRequestor.h"
  41. #include "nsIRefreshURI.h"
  42. #include "nsIWebNavigation.h"
  43. #include "nsIWebPageDescriptor.h"
  44. #include "nsIWebProgressListener.h"
  45. #include "nsIDocShellLoadInfo.h"
  46. #include "nsIAuthPromptProvider.h"
  47. #include "nsILoadContext.h"
  48. #include "nsIWebShellServices.h"
  49. #include "nsILinkHandler.h"
  50. #include "nsIClipboardCommands.h"
  51. #include "nsITabParent.h"
  52. #include "nsCRT.h"
  53. #include "prtime.h"
  54. #include "nsRect.h"
  55. #include "Units.h"
  56. #include "nsIDeprecationWarner.h"
  57. namespace mozilla {
  58. namespace dom {
  59. class EventTarget;
  60. typedef uint32_t ScreenOrientationInternal;
  61. } // namespace dom
  62. } // namespace mozilla
  63. class nsDocShell;
  64. class nsDOMNavigationTiming;
  65. class nsGlobalWindow;
  66. class nsIController;
  67. class nsIScrollableFrame;
  68. class OnLinkClickEvent;
  69. class nsDSURIContentListener;
  70. class nsDocShellEditorData;
  71. class nsIClipboardDragDropHookList;
  72. class nsICommandManager;
  73. class nsIContentViewer;
  74. class nsIDocument;
  75. class nsIDOMNode;
  76. class nsIDocShellTreeOwner;
  77. class nsIGlobalHistory2;
  78. class nsIHttpChannel;
  79. class nsIMutableArray;
  80. class nsIPrompt;
  81. class nsISHistory;
  82. class nsISecureBrowserUI;
  83. class nsIStringBundle;
  84. class nsIURIFixup;
  85. class nsIURILoader;
  86. class nsIWebBrowserFind;
  87. class nsIWidget;
  88. /* internally used ViewMode types */
  89. enum ViewMode
  90. {
  91. viewNormal = 0x0,
  92. viewSource = 0x1
  93. };
  94. class nsRefreshTimer : public nsITimerCallback
  95. {
  96. public:
  97. nsRefreshTimer();
  98. NS_DECL_THREADSAFE_ISUPPORTS
  99. NS_DECL_NSITIMERCALLBACK
  100. int32_t GetDelay() { return mDelay ;}
  101. RefPtr<nsDocShell> mDocShell;
  102. nsCOMPtr<nsIURI> mURI;
  103. nsCOMPtr<nsIPrincipal> mPrincipal;
  104. int32_t mDelay;
  105. bool mRepeat;
  106. bool mMetaRefresh;
  107. protected:
  108. virtual ~nsRefreshTimer();
  109. };
  110. enum eCharsetReloadState
  111. {
  112. eCharsetReloadInit,
  113. eCharsetReloadRequested,
  114. eCharsetReloadStopOrigional
  115. };
  116. class nsDocShell final
  117. : public nsDocLoader
  118. , public nsIDocShell
  119. , public nsIWebNavigation
  120. , public nsIBaseWindow
  121. , public nsIScrollable
  122. , public nsITextScroll
  123. , public nsIDocCharset
  124. , public nsIContentViewerContainer
  125. , public nsIRefreshURI
  126. , public nsIWebProgressListener
  127. , public nsIWebPageDescriptor
  128. , public nsIAuthPromptProvider
  129. , public nsILoadContext
  130. , public nsIWebShellServices
  131. , public nsILinkHandler
  132. , public nsIClipboardCommands
  133. , public nsIDOMStorageManager
  134. , public nsINetworkInterceptController
  135. , public nsIDeprecationWarner
  136. , public mozilla::SupportsWeakPtr<nsDocShell>
  137. {
  138. friend class nsDSURIContentListener;
  139. public:
  140. MOZ_DECLARE_WEAKREFERENCE_TYPENAME(nsDocShell)
  141. nsDocShell();
  142. NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
  143. virtual nsresult Init() override;
  144. NS_DECL_ISUPPORTS_INHERITED
  145. NS_DECL_NSIDOCSHELL
  146. NS_DECL_NSIDOCSHELLTREEITEM
  147. NS_DECL_NSIWEBNAVIGATION
  148. NS_DECL_NSIBASEWINDOW
  149. NS_DECL_NSISCROLLABLE
  150. NS_DECL_NSITEXTSCROLL
  151. NS_DECL_NSIDOCCHARSET
  152. NS_DECL_NSIINTERFACEREQUESTOR
  153. NS_DECL_NSIWEBPROGRESSLISTENER
  154. NS_DECL_NSIREFRESHURI
  155. NS_DECL_NSICONTENTVIEWERCONTAINER
  156. NS_DECL_NSIWEBPAGEDESCRIPTOR
  157. NS_DECL_NSIAUTHPROMPTPROVIDER
  158. NS_DECL_NSICLIPBOARDCOMMANDS
  159. NS_DECL_NSIWEBSHELLSERVICES
  160. NS_DECL_NSINETWORKINTERCEPTCONTROLLER
  161. NS_DECL_NSIDEPRECATIONWARNER
  162. NS_FORWARD_SAFE_NSIDOMSTORAGEMANAGER(TopSessionStorageManager())
  163. NS_IMETHOD Stop() override
  164. {
  165. // Need this here because otherwise nsIWebNavigation::Stop
  166. // overrides the docloader's Stop()
  167. return nsDocLoader::Stop();
  168. }
  169. // Need to implement (and forward) nsISecurityEventSink, because
  170. // nsIWebProgressListener has methods with identical names...
  171. NS_FORWARD_NSISECURITYEVENTSINK(nsDocLoader::)
  172. // nsILinkHandler
  173. NS_IMETHOD OnLinkClick(nsIContent* aContent,
  174. nsIURI* aURI,
  175. const char16_t* aTargetSpec,
  176. const nsAString& aFileName,
  177. nsIInputStream* aPostDataStream,
  178. nsIInputStream* aHeadersDataStream,
  179. bool aIsTrusted,
  180. nsIPrincipal* aTriggeringPrincipal) override;
  181. NS_IMETHOD OnLinkClickSync(nsIContent* aContent,
  182. nsIURI* aURI,
  183. const char16_t* aTargetSpec,
  184. const nsAString& aFileName,
  185. nsIInputStream* aPostDataStream = 0,
  186. nsIInputStream* aHeadersDataStream = 0,
  187. nsIDocShell** aDocShell = 0,
  188. nsIRequest** aRequest = 0,
  189. nsIPrincipal* aTriggeringPrincipal = nullptr) override;
  190. NS_IMETHOD OnOverLink(nsIContent* aContent,
  191. nsIURI* aURI,
  192. const char16_t* aTargetSpec) override;
  193. NS_IMETHOD OnLeaveLink() override;
  194. nsDocShellInfoLoadType ConvertLoadTypeToDocShellLoadInfo(uint32_t aLoadType);
  195. uint32_t ConvertDocShellLoadInfoToLoadType(
  196. nsDocShellInfoLoadType aDocShellLoadType);
  197. // Don't use NS_DECL_NSILOADCONTEXT because some of nsILoadContext's methods
  198. // are shared with nsIDocShell (appID, etc.) and can't be declared twice.
  199. NS_IMETHOD GetAssociatedWindow(mozIDOMWindowProxy**) override;
  200. NS_IMETHOD GetTopWindow(mozIDOMWindowProxy**) override;
  201. NS_IMETHOD GetTopFrameElement(nsIDOMElement**) override;
  202. NS_IMETHOD GetNestedFrameId(uint64_t*) override;
  203. NS_IMETHOD GetIsContent(bool*) override;
  204. NS_IMETHOD GetUsePrivateBrowsing(bool*) override;
  205. NS_IMETHOD SetUsePrivateBrowsing(bool) override;
  206. NS_IMETHOD SetPrivateBrowsing(bool) override;
  207. NS_IMETHOD GetUseRemoteTabs(bool*) override;
  208. NS_IMETHOD SetRemoteTabs(bool) override;
  209. NS_IMETHOD GetOriginAttributes(JS::MutableHandle<JS::Value>) override;
  210. NS_IMETHOD IsTrackingProtectionOn(bool*) override;
  211. // Restores a cached presentation from history (mLSHE).
  212. // This method swaps out the content viewer and simulates loads for
  213. // subframes. It then simulates the completion of the toplevel load.
  214. nsresult RestoreFromHistory();
  215. // Perform a URI load from a refresh timer. This is just like the
  216. // ForceRefreshURI method on nsIRefreshURI, but makes sure to take
  217. // the timer involved out of mRefreshURIList if it's there.
  218. // aTimer must not be null.
  219. nsresult ForceRefreshURIFromTimer(nsIURI* aURI, int32_t aDelay,
  220. bool aMetaRefresh, nsITimer* aTimer,
  221. nsIPrincipal* aPrincipal);
  222. friend class OnLinkClickEvent;
  223. // We need dummy OnLocationChange in some cases to update the UI without
  224. // updating security info.
  225. void FireDummyOnLocationChange()
  226. {
  227. FireOnLocationChange(this, nullptr, mCurrentURI,
  228. LOCATION_CHANGE_SAME_DOCUMENT);
  229. }
  230. nsresult HistoryTransactionRemoved(int32_t aIndex);
  231. // Notify Scroll observers when an async panning/zooming transform
  232. // has started being applied
  233. void NotifyAsyncPanZoomStarted();
  234. // Notify Scroll observers when an async panning/zooming transform
  235. // is no longer applied
  236. void NotifyAsyncPanZoomStopped();
  237. void SetInFrameSwap(bool aInSwap)
  238. {
  239. mInFrameSwap = aInSwap;
  240. }
  241. bool InFrameSwap();
  242. private:
  243. bool CanSetOriginAttributes();
  244. public:
  245. const mozilla::DocShellOriginAttributes&
  246. GetOriginAttributes()
  247. {
  248. return mOriginAttributes;
  249. }
  250. nsresult SetOriginAttributes(const mozilla::DocShellOriginAttributes& aAttrs);
  251. void GetInterceptedDocumentId(nsAString& aId)
  252. {
  253. aId = mInterceptedDocumentId;
  254. }
  255. private:
  256. // An observed docshell wrapper is created when recording markers is enabled.
  257. mozilla::UniquePtr<mozilla::ObservedDocShell> mObserved;
  258. // It is necessary to allow adding a timeline marker wherever a docshell
  259. // instance is available. This operation happens frequently and needs to
  260. // be very fast, so instead of using a Map or having to search for some
  261. // docshell-specific markers storage, a pointer to an `ObservedDocShell` is
  262. // is stored on docshells directly.
  263. friend void mozilla::TimelineConsumers::AddConsumer(nsDocShell*);
  264. friend void mozilla::TimelineConsumers::RemoveConsumer(nsDocShell*);
  265. friend void mozilla::TimelineConsumers::AddMarkerForDocShell(
  266. nsDocShell*, const char*, MarkerTracingType, MarkerStackRequest);
  267. friend void mozilla::TimelineConsumers::AddMarkerForDocShell(
  268. nsDocShell*, const char*, const TimeStamp&, MarkerTracingType,
  269. MarkerStackRequest);
  270. friend void mozilla::TimelineConsumers::AddMarkerForDocShell(
  271. nsDocShell*, UniquePtr<AbstractTimelineMarker>&&);
  272. friend void mozilla::TimelineConsumers::PopMarkers(nsDocShell*,
  273. JSContext*, nsTArray<dom::ProfileTimelineMarker>&);
  274. public:
  275. // Tell the favicon service that aNewURI has the same favicon as aOldURI.
  276. static void CopyFavicon(nsIURI* aOldURI,
  277. nsIURI* aNewURI,
  278. nsIPrincipal* aLoadingPrincipal,
  279. bool aInPrivateBrowsing);
  280. static nsDocShell* Cast(nsIDocShell* aDocShell)
  281. {
  282. return static_cast<nsDocShell*>(aDocShell);
  283. }
  284. protected:
  285. virtual ~nsDocShell();
  286. virtual void DestroyChildren() override;
  287. // Content Viewer Management
  288. nsresult EnsureContentViewer();
  289. // aPrincipal can be passed in if the caller wants. If null is
  290. // passed in, the about:blank principal will end up being used.
  291. nsresult CreateAboutBlankContentViewer(nsIPrincipal* aPrincipal,
  292. nsIURI* aBaseURI,
  293. bool aTryToSaveOldPresentation = true);
  294. nsresult CreateContentViewer(const nsACString& aContentType,
  295. nsIRequest* aRequest,
  296. nsIStreamListener** aContentHandler);
  297. nsresult NewContentViewerObj(const nsACString& aContentType,
  298. nsIRequest* aRequest, nsILoadGroup* aLoadGroup,
  299. nsIStreamListener** aContentHandler,
  300. nsIContentViewer** aViewer);
  301. nsresult SetupNewViewer(nsIContentViewer* aNewViewer);
  302. void SetupReferrerFromChannel(nsIChannel* aChannel);
  303. nsresult GetEldestPresContext(nsPresContext** aPresContext);
  304. // Get the principal that we'll set on the channel if we're inheriting. If
  305. // aConsiderCurrentDocument is true, we try to use the current document if
  306. // at all possible. If that fails, we fall back on the parent document.
  307. // If that fails too, we force creation of a content viewer and use the
  308. // resulting principal. If aConsiderCurrentDocument is false, we just look
  309. // at the parent.
  310. nsIPrincipal* GetInheritedPrincipal(bool aConsiderCurrentDocument);
  311. // Actually open a channel and perform a URI load. Callers need to pass a
  312. // non-null aTriggeringPrincipal which initiated the URI load. Please note
  313. // that aTriggeringPrincipal will be used for performing security checks.
  314. // If the argument aURI is provided by the web, then please do not pass a
  315. // SystemPrincipal as the triggeringPrincipal. If principalToInherit is
  316. // null, then no inheritance of any sort will happen and the load will
  317. // get a principal based on the URI being loaded.
  318. // If aSrcdoc is not void, the load will be considered as a srcdoc load,
  319. // and the contents of aSrcdoc will be loaded instead of aURI.
  320. // aOriginalURI will be set as the originalURI on the channel that does the
  321. // load. If aOriginalURI is null, aURI will be set as the originalURI.
  322. // If aLoadReplace is true, LOAD_REPLACE flag will be set to the nsIChannel.
  323. nsresult DoURILoad(nsIURI* aURI,
  324. nsIURI* aOriginalURI,
  325. bool aLoadReplace,
  326. bool aIsFromProcessingFrameAttributes,
  327. bool aLoadFromExternal,
  328. bool aForceAllowDataURI,
  329. nsIURI* aReferrer,
  330. bool aSendReferrer,
  331. uint32_t aReferrerPolicy,
  332. nsIPrincipal* aTriggeringPrincipal,
  333. nsIPrincipal* aPrincipalToInherit,
  334. const char* aTypeHint,
  335. const nsAString& aFileName,
  336. nsIInputStream* aPostData,
  337. nsIInputStream* aHeadersData,
  338. bool aFirstParty,
  339. nsIDocShell** aDocShell,
  340. nsIRequest** aRequest,
  341. bool aIsNewWindowTarget,
  342. bool aBypassClassifier,
  343. bool aForceAllowCookies,
  344. const nsAString& aSrcdoc,
  345. nsIURI* aBaseURI,
  346. nsContentPolicyType aContentPolicyType);
  347. nsresult AddHeadersToChannel(nsIInputStream* aHeadersData,
  348. nsIChannel* aChannel);
  349. nsresult DoChannelLoad(nsIChannel* aChannel,
  350. nsIURILoader* aURILoader,
  351. bool aBypassClassifier);
  352. nsresult ScrollToAnchor(bool aCurHasRef,
  353. bool aNewHasRef,
  354. nsACString& aNewHash,
  355. uint32_t aLoadType);
  356. // Returns true if would have called FireOnLocationChange,
  357. // but did not because aFireOnLocationChange was false on entry.
  358. // In this case it is the caller's responsibility to ensure
  359. // FireOnLocationChange is called.
  360. // In all other cases false is returned.
  361. bool OnLoadingSite(nsIChannel* aChannel,
  362. bool aFireOnLocationChange,
  363. bool aAddToGlobalHistory = true);
  364. // Returns true if would have called FireOnLocationChange,
  365. // but did not because aFireOnLocationChange was false on entry.
  366. // In this case it is the caller's responsibility to ensure
  367. // FireOnLocationChange is called.
  368. // In all other cases false is returned.
  369. // Either aChannel or aTriggeringPrincipal must be null. If aChannel is
  370. // present, the owner should be gotten from it.
  371. // If OnNewURI calls AddToSessionHistory, it will pass its
  372. // aCloneSHChildren argument as aCloneChildren.
  373. bool OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
  374. nsIPrincipal* aTriggeringPrincipal,
  375. nsIPrincipal* aPrincipalToInherit,
  376. uint32_t aLoadType,
  377. bool aFireOnLocationChange,
  378. bool aAddToGlobalHistory,
  379. bool aCloneSHChildren);
  380. void SetReferrerURI(nsIURI* aURI);
  381. void SetReferrerPolicy(uint32_t aReferrerPolicy);
  382. // Session History
  383. bool ShouldAddToSessionHistory(nsIURI* aURI);
  384. // Either aChannel or aOwner must be null. If aChannel is
  385. // present, the owner should be gotten from it.
  386. // If aCloneChildren is true, then our current session history's
  387. // children will be cloned onto the new entry. This should be
  388. // used when we aren't actually changing the document while adding
  389. // the new session history entry.
  390. nsresult AddToSessionHistory(nsIURI* aURI, nsIChannel* aChannel,
  391. nsIPrincipal* aTriggeringPrincipal,
  392. nsIPrincipal* aPrincipalToInherit,
  393. bool aCloneChildren,
  394. nsISHEntry** aNewEntry);
  395. nsresult AddChildSHEntryToParent(nsISHEntry* aNewEntry, int32_t aChildOffset,
  396. bool aCloneChildren);
  397. nsresult AddChildSHEntryInternal(nsISHEntry* aCloneRef, nsISHEntry* aNewEntry,
  398. int32_t aChildOffset, uint32_t aLoadType,
  399. bool aCloneChildren);
  400. nsresult LoadHistoryEntry(nsISHEntry* aEntry, uint32_t aLoadType);
  401. nsresult PersistLayoutHistoryState();
  402. // Clone a session history tree for subframe navigation.
  403. // The tree rooted at |aSrcEntry| will be cloned into |aDestEntry|, except
  404. // for the entry with id |aCloneID|, which will be replaced with
  405. // |aReplaceEntry|. |aSrcShell| is a (possibly null) docshell which
  406. // corresponds to |aSrcEntry| via its mLSHE or mOHE pointers, and will
  407. // have that pointer updated to point to the cloned history entry.
  408. // If aCloneChildren is true then the children of the entry with id
  409. // |aCloneID| will be cloned into |aReplaceEntry|.
  410. static nsresult CloneAndReplace(nsISHEntry* aSrcEntry,
  411. nsDocShell* aSrcShell,
  412. uint32_t aCloneID,
  413. nsISHEntry* aReplaceEntry,
  414. bool aCloneChildren,
  415. nsISHEntry** aDestEntry);
  416. // Child-walking callback for CloneAndReplace
  417. static nsresult CloneAndReplaceChild(nsISHEntry* aEntry, nsDocShell* aShell,
  418. int32_t aChildIndex, void* aData);
  419. nsresult GetRootSessionHistory(nsISHistory** aReturn);
  420. nsresult GetHttpChannel(nsIChannel* aChannel, nsIHttpChannel** aReturn);
  421. bool ShouldDiscardLayoutState(nsIHttpChannel* aChannel);
  422. // Determine whether this docshell corresponds to the given history entry,
  423. // via having a pointer to it in mOSHE or mLSHE.
  424. bool HasHistoryEntry(nsISHEntry* aEntry) const
  425. {
  426. return aEntry && (aEntry == mOSHE || aEntry == mLSHE);
  427. }
  428. // Update any pointers (mOSHE or mLSHE) to aOldEntry to point to aNewEntry
  429. void SwapHistoryEntries(nsISHEntry* aOldEntry, nsISHEntry* aNewEntry);
  430. // Call this method to swap in a new history entry to m[OL]SHE, rather than
  431. // setting it directly. This completes the navigation in all docshells
  432. // in the case of a subframe navigation.
  433. void SetHistoryEntry(nsCOMPtr<nsISHEntry>* aPtr, nsISHEntry* aEntry);
  434. // Child-walking callback for SetHistoryEntry
  435. static nsresult SetChildHistoryEntry(nsISHEntry* aEntry, nsDocShell* aShell,
  436. int32_t aEntryIndex, void* aData);
  437. // Callback prototype for WalkHistoryEntries.
  438. // aEntry is the child history entry, aShell is its corresponding docshell,
  439. // aChildIndex is the child's index in its parent entry, and aData is
  440. // the opaque pointer passed to WalkHistoryEntries.
  441. typedef nsresult(*WalkHistoryEntriesFunc)(nsISHEntry* aEntry,
  442. nsDocShell* aShell,
  443. int32_t aChildIndex,
  444. void* aData);
  445. // For each child of aRootEntry, find the corresponding docshell which is
  446. // a child of aRootShell, and call aCallback. The opaque pointer aData
  447. // is passed to the callback.
  448. static nsresult WalkHistoryEntries(nsISHEntry* aRootEntry,
  449. nsDocShell* aRootShell,
  450. WalkHistoryEntriesFunc aCallback,
  451. void* aData);
  452. // overridden from nsDocLoader, this provides more information than the
  453. // normal OnStateChange with flags STATE_REDIRECTING
  454. virtual void OnRedirectStateChange(nsIChannel* aOldChannel,
  455. nsIChannel* aNewChannel,
  456. uint32_t aRedirectFlags,
  457. uint32_t aStateFlags) override;
  458. /**
  459. * Helper function that determines if channel is an HTTP POST.
  460. *
  461. * @param aChannel
  462. * The channel to test
  463. *
  464. * @return True iff channel is an HTTP post.
  465. */
  466. bool ChannelIsPost(nsIChannel* aChannel);
  467. /**
  468. * Helper function that finds the last URI and its transition flags for a
  469. * channel.
  470. *
  471. * This method first checks the channel's property bag to see if previous
  472. * info has been saved. If not, it gives back the referrer of the channel.
  473. *
  474. * @param aChannel
  475. * The channel we are transitioning to
  476. * @param aURI
  477. * Output parameter with the previous URI, not addref'd
  478. * @param aChannelRedirectFlags
  479. * If a redirect, output parameter with the previous redirect flags
  480. * from nsIChannelEventSink
  481. */
  482. void ExtractLastVisit(nsIChannel* aChannel,
  483. nsIURI** aURI,
  484. uint32_t* aChannelRedirectFlags);
  485. /**
  486. * Helper function that caches a URI and a transition for saving later.
  487. *
  488. * @param aChannel
  489. * Channel that will have these properties saved
  490. * @param aURI
  491. * The URI to save for later
  492. * @param aChannelRedirectFlags
  493. * The nsIChannelEventSink redirect flags to save for later
  494. */
  495. void SaveLastVisit(nsIChannel* aChannel,
  496. nsIURI* aURI,
  497. uint32_t aChannelRedirectFlags);
  498. /**
  499. * Helper function for adding a URI visit using IHistory. If IHistory is
  500. * not available, the method tries nsIGlobalHistory2.
  501. *
  502. * The IHistory API maintains chains of visits, tracking both HTTP referrers
  503. * and redirects for a user session. VisitURI requires the current URI and
  504. * the previous URI in the chain.
  505. *
  506. * Visits can be saved either during a redirect or when the request has
  507. * reached its final destination. The previous URI in the visit may be
  508. * from another redirect or it may be the referrer.
  509. *
  510. * @pre aURI is not null.
  511. *
  512. * @param aURI
  513. * The URI that was just visited
  514. * @param aReferrerURI
  515. * The referrer URI of this request
  516. * @param aPreviousURI
  517. * The previous URI of this visit (may be the same as aReferrerURI)
  518. * @param aChannelRedirectFlags
  519. * For redirects, the redirect flags from nsIChannelEventSink
  520. * (0 otherwise)
  521. * @param aResponseStatus
  522. * For HTTP channels, the response code (0 otherwise).
  523. */
  524. void AddURIVisit(nsIURI* aURI,
  525. nsIURI* aReferrerURI,
  526. nsIURI* aPreviousURI,
  527. uint32_t aChannelRedirectFlags,
  528. uint32_t aResponseStatus = 0);
  529. // Helper Routines
  530. nsresult ConfirmRepost(bool* aRepost);
  531. NS_IMETHOD GetPromptAndStringBundle(nsIPrompt** aPrompt,
  532. nsIStringBundle** aStringBundle);
  533. NS_IMETHOD GetChildOffset(nsIDOMNode* aChild, nsIDOMNode* aParent,
  534. int32_t* aOffset);
  535. nsIScrollableFrame* GetRootScrollFrame();
  536. NS_IMETHOD EnsureScriptEnvironment();
  537. NS_IMETHOD EnsureEditorData();
  538. nsresult EnsureTransferableHookData();
  539. NS_IMETHOD EnsureFind();
  540. nsresult RefreshURIFromQueue();
  541. NS_IMETHOD LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
  542. const char* aErrorPage,
  543. const char16_t* aErrorType,
  544. const char16_t* aDescription,
  545. const char* aCSSClass,
  546. nsIChannel* aFailedChannel);
  547. bool IsPrintingOrPP(bool aDisplayErrorDialog = true);
  548. bool IsNavigationAllowed(bool aDisplayPrintErrorDialog = true,
  549. bool aCheckIfUnloadFired = true);
  550. nsresult SetBaseUrlForWyciwyg(nsIContentViewer* aContentViewer);
  551. static inline uint32_t PRTimeToSeconds(PRTime aTimeUsec)
  552. {
  553. PRTime usecPerSec = PR_USEC_PER_SEC;
  554. return uint32_t(aTimeUsec /= usecPerSec);
  555. }
  556. inline bool UseErrorPages()
  557. {
  558. return (mObserveErrorPages ? sUseErrorPages : mUseErrorPages);
  559. }
  560. bool IsFrame();
  561. //
  562. // Helper method that is called when a new document (including any
  563. // sub-documents - ie. frames) has been completely loaded.
  564. //
  565. virtual nsresult EndPageLoad(nsIWebProgress* aProgress,
  566. nsIChannel* aChannel,
  567. nsresult aResult);
  568. // Sets the current document's current state object to the given SHEntry's
  569. // state object. The current state object is eventually given to the page
  570. // in the PopState event.
  571. nsresult SetDocCurrentStateObj(nsISHEntry* aShEntry);
  572. nsresult CheckLoadingPermissions();
  573. // Security checks to prevent frameset spoofing. See comments at
  574. // implementation sites.
  575. static bool CanAccessItem(nsIDocShellTreeItem* aTargetItem,
  576. nsIDocShellTreeItem* aAccessingItem,
  577. bool aConsiderOpener = true);
  578. static bool ValidateOrigin(nsIDocShellTreeItem* aOriginTreeItem,
  579. nsIDocShellTreeItem* aTargetTreeItem);
  580. // Returns true if would have called FireOnLocationChange,
  581. // but did not because aFireOnLocationChange was false on entry.
  582. // In this case it is the caller's responsibility to ensure
  583. // FireOnLocationChange is called.
  584. // In all other cases false is returned.
  585. bool SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
  586. bool aFireOnLocationChange,
  587. uint32_t aLocationFlags);
  588. // The following methods deal with saving and restoring content viewers
  589. // in session history.
  590. // mContentViewer points to the current content viewer associated with
  591. // this docshell. When loading a new document, the content viewer is
  592. // either destroyed or stored into a session history entry. To make sure
  593. // that destruction happens in a controlled fashion, a given content viewer
  594. // is always owned in exactly one of these ways:
  595. // 1) The content viewer is active and owned by a docshell's
  596. // mContentViewer.
  597. // 2) The content viewer is still being displayed while we begin loading
  598. // a new document. The content viewer is owned by the _new_
  599. // content viewer's mPreviousViewer, and has a pointer to the
  600. // nsISHEntry where it will eventually be stored. The content viewer
  601. // has been close()d by the docshell, which detaches the document from
  602. // the window object.
  603. // 3) The content viewer is cached in session history. The nsISHEntry
  604. // has the only owning reference to the content viewer. The viewer
  605. // has released its nsISHEntry pointer to prevent circular ownership.
  606. //
  607. // When restoring a content viewer from session history, open() is called
  608. // to reattach the document to the window object. The content viewer is
  609. // then placed into mContentViewer and removed from the history entry.
  610. // (mContentViewer is put into session history as described above, if
  611. // applicable).
  612. // Determines whether we can safely cache the current mContentViewer in
  613. // session history. This checks a number of factors such as cache policy,
  614. // pending requests, and unload handlers.
  615. // |aLoadType| should be the load type that will replace the current
  616. // presentation. |aNewRequest| should be the request for the document to
  617. // be loaded in place of the current document, or null if such a request
  618. // has not been created yet. |aNewDocument| should be the document that will
  619. // replace the current document.
  620. bool CanSavePresentation(uint32_t aLoadType,
  621. nsIRequest* aNewRequest,
  622. nsIDocument* aNewDocument);
  623. // Captures the state of the supporting elements of the presentation
  624. // (the "window" object, docshell tree, meta-refresh loads, and security
  625. // state) and stores them on |mOSHE|.
  626. nsresult CaptureState();
  627. // Begin the toplevel restore process for |aSHEntry|.
  628. // This simulates a channel open, and defers the real work until
  629. // RestoreFromHistory is called from a PLEvent.
  630. nsresult RestorePresentation(nsISHEntry* aSHEntry, bool* aRestoring);
  631. // Call BeginRestore(nullptr, false) for each child of this shell.
  632. nsresult BeginRestoreChildren();
  633. // Method to get our current position and size without flushing
  634. void DoGetPositionAndSize(int32_t* aX, int32_t* aY, int32_t* aWidth,
  635. int32_t* aHeight);
  636. // Call this when a URI load is handed to us (via OnLinkClick or
  637. // InternalLoad). This makes sure that we're not inside unload, or that if
  638. // we are it's still OK to load this URI.
  639. bool IsOKToLoadURI(nsIURI* aURI);
  640. void ReattachEditorToWindow(nsISHEntry* aSHEntry);
  641. nsCOMPtr<nsIDOMStorageManager> mSessionStorageManager;
  642. nsIDOMStorageManager* TopSessionStorageManager();
  643. // helpers for executing commands
  644. nsresult GetControllerForCommand(const char* aCommand,
  645. nsIController** aResult);
  646. nsresult EnsureCommandHandler();
  647. nsIChannel* GetCurrentDocChannel();
  648. bool ShouldBlockLoadingForBackButton();
  649. // Convenience method for getting our parent docshell. Can return null
  650. already_AddRefed<nsDocShell> GetParentDocshell();
  651. // Check if aURI is about:newtab.
  652. bool IsAboutNewtab(nsIURI* aURI);
  653. protected:
  654. nsresult GetCurScrollPos(int32_t aScrollOrientation, int32_t* aCurPos);
  655. nsresult SetCurScrollPosEx(int32_t aCurHorizontalPos,
  656. int32_t aCurVerticalPos);
  657. // Override the parent setter from nsDocLoader
  658. virtual nsresult SetDocLoaderParent(nsDocLoader* aLoader) override;
  659. void ClearFrameHistory(nsISHEntry* aEntry);
  660. /**
  661. * Initializes mTiming if it isn't yet.
  662. * After calling this, mTiming is non-null.
  663. */
  664. void MaybeInitTiming();
  665. bool DisplayLoadError(nsresult aError, nsIURI* aURI, const char16_t* aURL,
  666. nsIChannel* aFailedChannel)
  667. {
  668. bool didDisplayLoadError = false;
  669. DisplayLoadError(aError, aURI, aURL, aFailedChannel, &didDisplayLoadError);
  670. return didDisplayLoadError;
  671. }
  672. public:
  673. // Event type dispatched by RestorePresentation
  674. class RestorePresentationEvent : public mozilla::Runnable
  675. {
  676. public:
  677. NS_DECL_NSIRUNNABLE
  678. explicit RestorePresentationEvent(nsDocShell* aDs) : mDocShell(aDs) {}
  679. void Revoke() { mDocShell = nullptr; }
  680. private:
  681. RefPtr<nsDocShell> mDocShell;
  682. };
  683. protected:
  684. bool JustStartedNetworkLoad();
  685. nsresult CreatePrincipalFromReferrer(nsIURI* aReferrer,
  686. nsIPrincipal** aResult);
  687. static const nsCString FrameTypeToString(uint32_t aFrameType)
  688. {
  689. switch (aFrameType) {
  690. case FRAME_TYPE_APP:
  691. return NS_LITERAL_CSTRING("app");
  692. case FRAME_TYPE_BROWSER:
  693. return NS_LITERAL_CSTRING("browser");
  694. case FRAME_TYPE_REGULAR:
  695. return NS_LITERAL_CSTRING("regular");
  696. default:
  697. NS_ERROR("Unknown frame type");
  698. return EmptyCString();
  699. }
  700. }
  701. uint32_t GetInheritedFrameType();
  702. bool HasUnloadedParent();
  703. // Dimensions of the docshell
  704. nsIntRect mBounds;
  705. nsString mName;
  706. nsString mTitle;
  707. nsString mCustomUserAgent;
  708. /**
  709. * Content-Type Hint of the most-recently initiated load. Used for
  710. * session history entries.
  711. */
  712. nsCString mContentTypeHint;
  713. nsIntPoint mDefaultScrollbarPref; // persistent across doc loads
  714. nsCOMPtr<nsIMutableArray> mRefreshURIList;
  715. nsCOMPtr<nsIMutableArray> mSavedRefreshURIList;
  716. RefPtr<nsDSURIContentListener> mContentListener;
  717. nsCOMPtr<nsIContentViewer> mContentViewer;
  718. nsCOMPtr<nsIWidget> mParentWidget;
  719. // mCurrentURI should be marked immutable on set if possible.
  720. nsCOMPtr<nsIURI> mCurrentURI;
  721. nsCOMPtr<nsIURI> mReferrerURI;
  722. uint32_t mReferrerPolicy;
  723. RefPtr<nsGlobalWindow> mScriptGlobal;
  724. nsCOMPtr<nsISHistory> mSessionHistory;
  725. nsCOMPtr<nsIGlobalHistory2> mGlobalHistory;
  726. nsCOMPtr<nsIWebBrowserFind> mFind;
  727. nsCOMPtr<nsICommandManager> mCommandManager;
  728. // Reference to the SHEntry for this docshell until the page is destroyed.
  729. // Somebody give me better name
  730. nsCOMPtr<nsISHEntry> mOSHE;
  731. // Reference to the SHEntry for this docshell until the page is loaded
  732. // Somebody give me better name.
  733. // If mLSHE is non-null, non-pushState subframe loads don't create separate
  734. // root history entries. That is, frames loaded during the parent page
  735. // load don't generate history entries the way frame navigation after the
  736. // parent has loaded does. (This isn't the only purpose of mLSHE.)
  737. nsCOMPtr<nsISHEntry> mLSHE;
  738. // Holds a weak pointer to a RestorePresentationEvent object if any that
  739. // holds a weak pointer back to us. We use this pointer to possibly revoke
  740. // the event whenever necessary.
  741. nsRevocableEventPtr<RestorePresentationEvent> mRestorePresentationEvent;
  742. // Editor data, if this document is designMode or contentEditable.
  743. nsAutoPtr<nsDocShellEditorData> mEditorData;
  744. // Transferable hooks/callbacks
  745. nsCOMPtr<nsIClipboardDragDropHookList> mTransferableHookData;
  746. // Secure browser UI object
  747. nsCOMPtr<nsISecureBrowserUI> mSecurityUI;
  748. // The URI we're currently loading. This is only relevant during the
  749. // firing of a pagehide/unload. The caller of FirePageHideNotification()
  750. // is responsible for setting it and unsetting it. It may be null if the
  751. // pagehide/unload is happening for some reason other than just loading a
  752. // new URI.
  753. nsCOMPtr<nsIURI> mLoadingURI;
  754. // Set in LoadErrorPage from the method argument and used later
  755. // in CreateContentViewer. We have to delay an shistory entry creation
  756. // for which these objects are needed.
  757. nsCOMPtr<nsIURI> mFailedURI;
  758. nsCOMPtr<nsIChannel> mFailedChannel;
  759. uint32_t mFailedLoadType;
  760. // Set in DoURILoad when either the LOAD_RELOAD_ALLOW_MIXED_CONTENT flag or
  761. // the LOAD_NORMAL_ALLOW_MIXED_CONTENT flag is set.
  762. // Checked in nsMixedContentBlocker, to see if the channels match.
  763. nsCOMPtr<nsIChannel> mMixedContentChannel;
  764. // WEAK REFERENCES BELOW HERE.
  765. // Note these are intentionally not addrefd. Doing so will create a cycle.
  766. // For that reasons don't use nsCOMPtr.
  767. nsIDocShellTreeOwner* mTreeOwner; // Weak Reference
  768. mozilla::dom::EventTarget* mChromeEventHandler; // Weak Reference
  769. eCharsetReloadState mCharsetReloadState;
  770. // Offset in the parent's child list.
  771. // -1 if the docshell is added dynamically to the parent shell.
  772. uint32_t mChildOffset;
  773. uint32_t mBusyFlags;
  774. uint32_t mAppType;
  775. uint32_t mLoadType;
  776. int32_t mMarginWidth;
  777. int32_t mMarginHeight;
  778. // This can either be a content docshell or a chrome docshell. After
  779. // Create() is called, the type is not expected to change.
  780. int32_t mItemType;
  781. // Index into the SHTransaction list, indicating the previous and current
  782. // transaction at the time that this DocShell begins to load
  783. int32_t mPreviousTransIndex;
  784. int32_t mLoadedTransIndex;
  785. uint32_t mSandboxFlags;
  786. nsWeakPtr mOnePermittedSandboxedNavigator;
  787. // The orientation lock as described by
  788. // https://w3c.github.io/screen-orientation/
  789. mozilla::dom::ScreenOrientationInternal mOrientationLock;
  790. // mFullscreenAllowed stores how we determine whether fullscreen is allowed
  791. // when GetFullscreenAllowed() is called. Fullscreen is allowed in a
  792. // docshell when all containing iframes have the allowfullscreen
  793. // attribute set to true. When mFullscreenAllowed is CHECK_ATTRIBUTES
  794. // we check this docshell's containing frame for the allowfullscreen
  795. // attribute, and recurse onto the parent docshell to ensure all containing
  796. // frames also have the allowfullscreen attribute. If we find an ancestor
  797. // docshell with mFullscreenAllowed not equal to CHECK_ATTRIBUTES, we've
  798. // reached a content boundary, and mFullscreenAllowed denotes whether the
  799. // parent across the content boundary has allowfullscreen=true in all its
  800. // containing iframes. mFullscreenAllowed defaults to CHECK_ATTRIBUTES and
  801. // is set otherwise when docshells which are content boundaries are created.
  802. enum FullscreenAllowedState : uint8_t
  803. {
  804. CHECK_ATTRIBUTES,
  805. PARENT_ALLOWS,
  806. PARENT_PROHIBITS
  807. };
  808. FullscreenAllowedState mFullscreenAllowed;
  809. // Cached value of the "browser.xul.error_pages.enabled" preference.
  810. static bool sUseErrorPages;
  811. bool mCreated : 1;
  812. bool mAllowSubframes : 1;
  813. bool mAllowPlugins : 1;
  814. bool mAllowJavascript : 1;
  815. bool mAllowMetaRedirects : 1;
  816. bool mAllowImages : 1;
  817. bool mAllowMedia : 1;
  818. bool mAllowDNSPrefetch : 1;
  819. bool mAllowWindowControl : 1;
  820. bool mAllowContentRetargeting : 1;
  821. bool mAllowContentRetargetingOnChildren : 1;
  822. bool mUseErrorPages : 1;
  823. bool mObserveErrorPages : 1;
  824. bool mAllowAuth : 1;
  825. bool mAllowKeywordFixup : 1;
  826. bool mIsOffScreenBrowser : 1;
  827. bool mIsActive : 1;
  828. bool mDisableMetaRefreshWhenInactive : 1;
  829. bool mIsPrerendered : 1;
  830. bool mIsAppTab : 1;
  831. bool mUseGlobalHistory : 1;
  832. bool mUseRemoteTabs : 1;
  833. bool mDeviceSizeIsPageSize : 1;
  834. bool mWindowDraggingAllowed : 1;
  835. bool mInFrameSwap : 1;
  836. bool mInheritPrivateBrowsingId : 1;
  837. // Because scriptability depends on the mAllowJavascript values of our
  838. // ancestors, we cache the effective scriptability and recompute it when
  839. // it might have changed;
  840. bool mCanExecuteScripts : 1;
  841. void RecomputeCanExecuteScripts();
  842. // This boolean is set to true right before we fire pagehide and generally
  843. // unset when we embed a new content viewer. While it's true no navigation
  844. // is allowed in this docshell.
  845. bool mFiredUnloadEvent : 1;
  846. // this flag is for bug #21358. a docshell may load many urls
  847. // which don't result in new documents being created (i.e. a new
  848. // content viewer) we want to make sure we don't call a on load
  849. // event more than once for a given content viewer.
  850. bool mEODForCurrentDocument : 1;
  851. bool mURIResultedInDocument : 1;
  852. bool mIsBeingDestroyed : 1;
  853. bool mIsExecutingOnLoadHandler : 1;
  854. // Indicates that a DocShell in this "docshell tree" is printing
  855. bool mIsPrintingOrPP : 1;
  856. // Indicates to CreateContentViewer() that it is safe to cache the old
  857. // presentation of the page, and to SetupNewViewer() that the old viewer
  858. // should be passed a SHEntry to save itself into.
  859. bool mSavingOldViewer : 1;
  860. // @see nsIDocShellHistory::createdDynamically
  861. bool mDynamicallyCreated : 1;
  862. bool mAffectPrivateSessionLifetime : 1;
  863. bool mInvisible : 1;
  864. bool mHasLoadedNonBlankURI : 1;
  865. // This flag means that mTiming has been initialized but nulled out.
  866. // We will check the innerWin's timing before creating a new one
  867. // in MaybeInitTiming()
  868. bool mBlankTiming : 1;
  869. // The following two fields cannot be declared as bit fields
  870. // because of uses with AutoRestore.
  871. bool mCreatingDocument; // (should be) debugging only
  872. #ifdef DEBUG
  873. bool mInEnsureScriptEnv;
  874. #endif
  875. uint64_t mHistoryID;
  876. uint32_t mDefaultLoadFlags;
  877. static nsIURIFixup* sURIFixup;
  878. RefPtr<nsDOMNavigationTiming> mTiming;
  879. // Are we a regular frame, a browser frame, or an app frame?
  880. uint32_t mFrameType;
  881. // This represents the state of private browsing in the docshell.
  882. // Currently treated as a binary value: 1 - in private mode, 0 - not private mode
  883. // On content docshells mPrivateBrowsingId == mOriginAttributes.mPrivateBrowsingId
  884. // On chrome docshells this value will be set, but not have the corresponding
  885. // origin attribute set.
  886. uint32_t mPrivateBrowsingId;
  887. nsString mInterceptedDocumentId;
  888. private:
  889. nsCString mForcedCharset;
  890. nsCString mParentCharset;
  891. int32_t mParentCharsetSource;
  892. nsCOMPtr<nsIPrincipal> mParentCharsetPrincipal;
  893. nsTObserverArray<nsWeakPtr> mPrivacyObservers;
  894. nsTObserverArray<nsWeakPtr> mReflowObservers;
  895. nsTObserverArray<nsWeakPtr> mScrollObservers;
  896. nsCString mOriginalUriString;
  897. nsWeakPtr mOpener;
  898. mozilla::DocShellOriginAttributes mOriginAttributes;
  899. // A depth count of how many times NotifyRunToCompletionStart
  900. // has been called without a matching NotifyRunToCompletionStop.
  901. uint32_t mJSRunToCompletionDepth;
  902. // Whether or not touch events are overridden. Possible values are defined
  903. // as constants in the nsIDocShell.idl file.
  904. uint32_t mTouchEventsOverride;
  905. // Keep track how how many history state changes we're getting, to catch &
  906. // prevent flooding.
  907. int32_t mStateFloodGuardCount;
  908. mozilla::TimeStamp mStateFloodGuardUpdated;
  909. bool mStateFloodGuardReported;
  910. // We have a limit of pushing 50 states to history every 10 seconds.
  911. const int32_t kStateUpdateLimit = 50;
  912. const double kRefreshTimeSecs = 10.0;
  913. // Keep track how how many history state changes we're getting, to catch &
  914. // prevent flooding.
  915. int32_t mReloadFloodGuardCount;
  916. mozilla::TimeStamp mReloadFloodGuardUpdated;
  917. bool mReloadFloodGuardReported;
  918. // We have a limit of reloading 50 times every 10 seconds.
  919. const int32_t kReloadLimit = 50;
  920. const double kReloadTimeSecs = 10.0;
  921. // Separate function to do the actual name (i.e. not _top, _self etc.)
  922. // searching for FindItemWithName.
  923. nsresult DoFindItemWithName(const nsAString& aName,
  924. nsISupports* aRequestor,
  925. nsIDocShellTreeItem* aOriginalRequestor,
  926. nsIDocShellTreeItem** aResult);
  927. // Helper assertion to enforce that mInPrivateBrowsing is in sync with
  928. // OriginAttributes.mPrivateBrowsingId
  929. void AssertOriginAttributesMatchPrivateBrowsing();
  930. // Notify consumers of a search being loaded through the observer service:
  931. void MaybeNotifyKeywordSearchLoading(const nsString& aProvider,
  932. const nsString& aKeyword);
  933. // Helper method for AddState which checks for excessive calls to PushState or
  934. // ReplaceState.
  935. bool IsStateChangeFlooding();
  936. // Helper method for Reload which checks for excessive calls to Reload.
  937. bool IsReloadFlooding();
  938. #ifdef DEBUG
  939. // We're counting the number of |nsDocShells| to help find leaks
  940. static unsigned long gNumberOfDocShells;
  941. #endif /* DEBUG */
  942. public:
  943. class InterfaceRequestorProxy : public nsIInterfaceRequestor
  944. {
  945. public:
  946. explicit InterfaceRequestorProxy(nsIInterfaceRequestor* aRequestor);
  947. NS_DECL_THREADSAFE_ISUPPORTS
  948. NS_DECL_NSIINTERFACEREQUESTOR
  949. protected:
  950. virtual ~InterfaceRequestorProxy();
  951. InterfaceRequestorProxy() {}
  952. nsWeakPtr mWeakPtr;
  953. };
  954. };
  955. #endif /* nsDocShell_h__ */