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