2 * Copyright (C) 2006, 2007, 2008, 2009, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
4 * Copyright (C) Research In Motion Limited 2009. All rights reserved.
5 * Copyright (C) 2011 Google Inc. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "core/CoreExport.h"
36 #include "core/dom/IconURL.h"
37 #include "core/dom/SandboxFlags.h"
38 #include "core/dom/SecurityContext.h"
39 #include "core/fetch/ResourceLoaderOptions.h"
40 #include "core/frame/FrameTypes.h"
41 #include "core/loader/FrameLoaderStateMachine.h"
42 #include "core/loader/FrameLoaderTypes.h"
43 #include "core/loader/HistoryItem.h"
44 #include "core/loader/NavigationPolicy.h"
45 #include "platform/Timer.h"
46 #include "platform/heap/Handle.h"
47 #include "platform/network/ResourceRequest.h"
48 #include "wtf/Forward.h"
49 #include "wtf/HashSet.h"
55 class FrameLoaderClient
;
56 class ProgressTracker
;
58 class SerializedScriptValue
;
61 struct FrameLoadRequest
;
63 CORE_EXPORT
bool isBackForwardLoadType(FrameLoadType
);
65 class CORE_EXPORT FrameLoader final
{
66 WTF_MAKE_NONCOPYABLE(FrameLoader
);
67 DISALLOW_ALLOCATION();
69 static ResourceRequest
resourceRequestFromHistoryItem(HistoryItem
*, ResourceRequestCachePolicy
);
71 FrameLoader(LocalFrame
*);
76 ResourceRequest
resourceRequestForReload(FrameLoadType
, const KURL
& overrideURL
= KURL(),
77 ClientRedirectPolicy
= NotClientRedirect
);
79 ProgressTracker
& progress() const { return *m_progressTracker
; }
81 // Starts a load. It will eventually call startLoad() or
82 // loadInSameDocument(). For history navigations or reloads, an appropriate
83 // FrameLoadType should be given. Otherwise, FrameLoadTypeStandard should be
84 // used (and the final FrameLoadType will be computed). For history
85 // navigations, a history item and a HistoryLoadType should also be provided.
86 void load(const FrameLoadRequest
&, FrameLoadType
= FrameLoadTypeStandard
,
87 HistoryItem
* = nullptr, HistoryLoadType
= HistoryDifferentDocumentLoad
);
89 static void reportLocalLoadFailed(LocalFrame
*, const String
& url
);
91 // Warning: stopAllLoaders can and will detach the LocalFrame out from under you. All callers need to either protect the LocalFrame
92 // or guarantee they won't in any way access the LocalFrame after stopAllLoaders returns.
93 void stopAllLoaders();
95 // FIXME: clear() is trying to do too many things. We should break it down into smaller functions.
98 void replaceDocumentWhileExecutingJavaScriptURL(const String
& source
, Document
* ownerDocument
);
100 // Sets a timer to notify the client that the initial empty document has
101 // been accessed, and thus it is no longer safe to show a provisional URL
102 // above the document without risking a URL spoof.
103 void didAccessInitialDocument();
105 // If the initial empty document is showing and has been accessed, this
106 // cancels the timer and immediately notifies the client in cases that
107 // waiting to notify would allow a URL spoof.
108 void notifyIfInitialDocumentAccessed();
110 DocumentLoader
* documentLoader() const { return m_documentLoader
.get(); }
111 DocumentLoader
* policyDocumentLoader() const { return m_policyDocumentLoader
.get(); }
112 DocumentLoader
* provisionalDocumentLoader() const { return m_provisionalDocumentLoader
.get(); }
114 void receivedMainResourceError(DocumentLoader
*, const ResourceError
&);
116 bool isLoadingMainFrame() const;
118 bool shouldTreatURLAsSameAsCurrent(const KURL
&) const;
119 bool shouldTreatURLAsSrcdocDocument(const KURL
&) const;
121 FrameLoadType
loadType() const;
122 void setLoadType(FrameLoadType loadType
) { m_loadType
= loadType
; }
124 FrameLoaderClient
* client() const;
126 void setDefersLoading(bool);
128 void didExplicitOpen();
130 // Callbacks from DocumentWriter
131 void didBeginDocument(bool dispatchWindowObjectAvailable
);
133 void receivedFirstData();
135 String
userAgent(const KURL
&) const;
137 void dispatchDidClearWindowObjectInMainWorld();
138 void dispatchDidClearDocumentOfWindowObject();
139 void dispatchDocumentElementAvailable();
141 // The following sandbox flags will be forced, regardless of changes to
142 // the sandbox attribute of any parent frames.
143 void forceSandboxFlags(SandboxFlags flags
) { m_forcedSandboxFlags
|= flags
; }
144 SandboxFlags
effectiveSandboxFlags() const;
146 bool shouldEnforceStrictMixedContentChecking() const;
148 SecurityContext::InsecureRequestsPolicy
insecureRequestsPolicy() const;
149 SecurityContext::InsecureNavigationsSet
* insecureNavigationsToUpgrade() const;
152 void setOpener(LocalFrame
*);
156 void finishedParsing();
157 void checkCompleted();
159 void receivedMainResourceRedirect(const KURL
& newURL
);
161 // This prepares the FrameLoader for the next commit. It will dispatch
162 // unload events, abort XHR requests and detach the document. Returns true
163 // if the frame is ready to receive the next commit, or false otherwise.
164 bool prepareForCommit();
166 void commitProvisionalLoad();
168 FrameLoaderStateMachine
* stateMachine() const { return &m_stateMachine
; }
170 void applyUserAgent(ResourceRequest
&);
172 bool shouldInterruptLoadForXFrameOptions(const String
&, const KURL
&, unsigned long requestIdentifier
);
174 bool allAncestorsAreComplete() const; // including this
177 void dispatchUnloadEvent();
179 bool allowPlugins(ReasonForCallingAllowPlugins
);
181 void updateForSameDocumentNavigation(const KURL
&, SameDocumentNavigationSource
, PassRefPtr
<SerializedScriptValue
>, HistoryScrollRestorationType
, FrameLoadType
);
183 HistoryItem
* currentItem() const { return m_currentItem
.get(); }
184 void saveScrollState();
186 void restoreScrollPositionAndViewState();
191 void checkTimerFired(Timer
<FrameLoader
>*);
192 void didAccessInitialDocumentTimerFired(Timer
<FrameLoader
>*);
194 bool prepareRequestForThisFrame(FrameLoadRequest
&);
195 static void setReferrerForFrameRequest(ResourceRequest
&, ShouldSendReferrer
, Document
*);
196 FrameLoadType
determineFrameLoadType(const FrameLoadRequest
&);
198 SubstituteData
defaultSubstituteDataForURL(const KURL
&);
200 bool shouldPerformFragmentNavigation(bool isFormSubmission
, const String
& httpMethod
, FrameLoadType
, const KURL
&);
201 void processFragment(const KURL
&, LoadStartType
);
203 void startLoad(FrameLoadRequest
&, FrameLoadType
, NavigationPolicy
);
205 enum class HistoryNavigationType
{
210 void setHistoryItemStateForCommit(HistoryCommitType
, HistoryNavigationType
);
212 void loadInSameDocument(const KURL
&, PassRefPtr
<SerializedScriptValue
> stateObject
, FrameLoadType
, ClientRedirectPolicy
);
214 void scheduleCheckCompleted();
216 void detachDocumentLoader(RefPtrWillBeMember
<DocumentLoader
>&);
218 RawPtrWillBeMember
<LocalFrame
> m_frame
;
220 // FIXME: These should be OwnPtr<T> to reduce build times and simplify
221 // header dependencies unless performance testing proves otherwise.
222 // Some of these could be lazily created for memory savings on devices.
223 mutable FrameLoaderStateMachine m_stateMachine
;
225 OwnPtrWillBeMember
<ProgressTracker
> m_progressTracker
;
227 FrameLoadType m_loadType
;
229 // Document loaders for the three phases of frame loading. Note that while
230 // a new request is being loaded, the old document loader may still be referenced.
231 // E.g. while a new request is in the "policy" state, the old document loader may
232 // be consulted in particular as it makes sense to imply certain settings on the new loader.
233 RefPtrWillBeMember
<DocumentLoader
> m_documentLoader
;
234 RefPtrWillBeMember
<DocumentLoader
> m_provisionalDocumentLoader
;
235 RefPtrWillBeMember
<DocumentLoader
> m_policyDocumentLoader
;
237 RefPtrWillBeMember
<HistoryItem
> m_currentItem
;
238 RefPtrWillBeMember
<HistoryItem
> m_provisionalItem
;
240 class DeferredHistoryLoad
: public NoBaseWillBeGarbageCollectedFinalized
<DeferredHistoryLoad
> {
241 DISALLOW_COPY(DeferredHistoryLoad
);
243 static PassOwnPtrWillBeRawPtr
<DeferredHistoryLoad
> create(ResourceRequest request
, HistoryItem
* item
, FrameLoadType loadType
, HistoryLoadType historyLoadType
)
245 return adoptPtrWillBeNoop(new DeferredHistoryLoad(request
, item
, loadType
, historyLoadType
));
248 DeferredHistoryLoad(ResourceRequest request
, HistoryItem
* item
, FrameLoadType loadType
,
249 HistoryLoadType historyLoadType
)
252 , m_loadType(loadType
)
253 , m_historyLoadType(historyLoadType
)
257 DEFINE_INLINE_TRACE()
259 visitor
->trace(m_item
);
262 ResourceRequest m_request
;
263 RefPtrWillBeMember
<HistoryItem
> m_item
;
264 FrameLoadType m_loadType
;
265 HistoryLoadType m_historyLoadType
;
268 OwnPtrWillBeMember
<DeferredHistoryLoad
> m_deferredHistoryLoad
;
270 bool m_inStopAllLoaders
;
272 Timer
<FrameLoader
> m_checkTimer
;
274 bool m_didAccessInitialDocument
;
275 Timer
<FrameLoader
> m_didAccessInitialDocumentTimer
;
277 SandboxFlags m_forcedSandboxFlags
;
279 bool m_dispatchingDidClearWindowObjectInMainWorld
;
284 #endif // FrameLoader_h