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