1 /* 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. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 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. 19 * 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. 30 */ 31 32 #ifndef FrameLoader_h 33 #define FrameLoader_h 34 35 #include "core/dom/IconURL.h" 36 #include "core/dom/SandboxFlags.h" 37 #include "core/dom/SecurityContext.h" 38 #include "core/fetch/ResourceLoaderOptions.h" 39 #include "core/loader/FrameLoaderStateMachine.h" 40 #include "core/loader/FrameLoaderTypes.h" 41 #include "core/loader/HistoryItem.h" 42 #include "core/loader/MixedContentChecker.h" 43 #include "platform/Timer.h" 44 #include "platform/network/ResourceRequest.h" 45 #include "wtf/Forward.h" 46 #include "wtf/HashSet.h" 47 #include "wtf/OwnPtr.h" 48 49 namespace WebCore { 50 51 class Resource; 52 class Chrome; 53 class DOMWrapperWorld; 54 class DocumentLoader; 55 class Event; 56 class FetchContext; 57 class FormState; 58 class FormSubmission; 59 class FrameLoaderClient; 60 class IconController; 61 class NavigationAction; 62 class Page; 63 class ProgressTracker; 64 class ResourceError; 65 class ResourceResponse; 66 class SecurityOrigin; 67 class SerializedScriptValue; 68 class SubstituteData; 69 70 struct FrameLoadRequest; 71 struct WindowFeatures; 72 73 bool isBackForwardLoadType(FrameLoadType); 74 75 class FrameLoader { 76 WTF_MAKE_NONCOPYABLE(FrameLoader); 77 public: 78 FrameLoader(LocalFrame*); 79 ~FrameLoader(); 80 81 void init(); 82 frame()83 LocalFrame* frame() const { return m_frame; } 84 mixedContentChecker()85 MixedContentChecker* mixedContentChecker() const { return &m_mixedContentChecker; } progress()86 ProgressTracker& progress() const { return *m_progressTracker; } 87 88 // These functions start a load. All eventually call into loadWithNavigationAction() or loadInSameDocument(). 89 void load(const FrameLoadRequest&); // The entry point for non-reload, non-history loads. 90 void reload(ReloadPolicy = NormalReload, const KURL& overrideURL = KURL(), const AtomicString& overrideEncoding = nullAtom); 91 void loadHistoryItem(HistoryItem*, HistoryLoadType = HistoryDifferentDocumentLoad, ResourceRequestCachePolicy = UseProtocolCachePolicy); // The entry point for all back/forward loads 92 93 static void reportLocalLoadFailed(LocalFrame*, const String& url); 94 95 // FIXME: These are all functions which stop loads. We have too many. 96 // Warning: stopAllLoaders can and will detach the LocalFrame out from under you. All callers need to either protect the LocalFrame 97 // or guarantee they won't in any way access the LocalFrame after stopAllLoaders returns. 98 void stopAllLoaders(); 99 void stopLoading(); 100 bool closeURL(); 101 // FIXME: clear() is trying to do too many things. We should break it down into smaller functions. 102 void clear(); 103 104 // Sets a timer to notify the client that the initial empty document has 105 // been accessed, and thus it is no longer safe to show a provisional URL 106 // above the document without risking a URL spoof. 107 void didAccessInitialDocument(); 108 109 // If the initial empty document is showing and has been accessed, this 110 // cancels the timer and immediately notifies the client in cases that 111 // waiting to notify would allow a URL spoof. 112 void notifyIfInitialDocumentAccessed(); 113 114 bool isLoading() const; 115 documentLoader()116 DocumentLoader* documentLoader() const { return m_documentLoader.get(); } policyDocumentLoader()117 DocumentLoader* policyDocumentLoader() const { return m_policyDocumentLoader.get(); } provisionalDocumentLoader()118 DocumentLoader* provisionalDocumentLoader() const { return m_provisionalDocumentLoader.get(); } state()119 FrameState state() const { return m_state; } fetchContext()120 FetchContext& fetchContext() const { return *m_fetchContext; } 121 122 void receivedMainResourceError(const ResourceError&); 123 124 bool isLoadingMainFrame() const; 125 126 bool shouldTreatURLAsSameAsCurrent(const KURL&) const; 127 bool shouldTreatURLAsSrcdocDocument(const KURL&) const; 128 129 FrameLoadType loadType() const; setLoadType(FrameLoadType loadType)130 void setLoadType(FrameLoadType loadType) { m_loadType = loadType; } 131 132 void checkLoadComplete(); 133 134 static void addHTTPOriginIfNeeded(ResourceRequest&, const AtomicString& origin); 135 136 FrameLoaderClient* client() const; 137 138 void setDefersLoading(bool); 139 140 void didExplicitOpen(); 141 142 // Callbacks from DocumentWriter 143 void didBeginDocument(bool dispatchWindowObjectAvailable); 144 145 void receivedFirstData(); 146 147 String userAgent(const KURL&) const; 148 149 void dispatchDidClearWindowObjectInMainWorld(); 150 void dispatchDidClearDocumentOfWindowObject(); 151 void dispatchDocumentElementAvailable(); 152 153 // The following sandbox flags will be forced, regardless of changes to 154 // the sandbox attribute of any parent frames. forceSandboxFlags(SandboxFlags flags)155 void forceSandboxFlags(SandboxFlags flags) { m_forcedSandboxFlags |= flags; } 156 SandboxFlags effectiveSandboxFlags() const; 157 158 LocalFrame* opener(); 159 void setOpener(LocalFrame*); 160 161 void frameDetached(); 162 163 void loadDone(); 164 void finishedParsing(); 165 void checkCompleted(); 166 167 void commitProvisionalLoad(); 168 stateMachine()169 FrameLoaderStateMachine* stateMachine() const { return &m_stateMachine; } 170 171 LocalFrame* findFrameForNavigation(const AtomicString& name, Document* activeDocument); 172 173 void applyUserAgent(ResourceRequest&); 174 175 bool shouldInterruptLoadForXFrameOptions(const String&, const KURL&, unsigned long requestIdentifier); 176 177 bool allAncestorsAreComplete() const; // including this 178 179 bool shouldClose(); 180 181 void started(); 182 183 bool allowPlugins(ReasonForCallingAllowPlugins); 184 185 void updateForSameDocumentNavigation(const KURL&, SameDocumentNavigationSource, PassRefPtr<SerializedScriptValue>, FrameLoadType); 186 currentItem()187 HistoryItem* currentItem() const { return m_currentItem.get(); } 188 void saveScrollState(); 189 void clearScrollPositionAndViewState(); 190 191 void restoreScrollPositionAndViewState(); 192 193 private: 194 bool allChildrenAreComplete() const; // immediate children, not all descendants 195 196 void completed(); 197 198 void checkTimerFired(Timer<FrameLoader>*); 199 void didAccessInitialDocumentTimerFired(Timer<FrameLoader>*); 200 201 bool prepareRequestForThisFrame(FrameLoadRequest&); 202 void setReferrerForFrameRequest(ResourceRequest&, ShouldSendReferrer, Document*); 203 FrameLoadType determineFrameLoadType(const FrameLoadRequest&); 204 bool isScriptTriggeredFormSubmissionInChildFrame(const FrameLoadRequest&) const; 205 206 SubstituteData defaultSubstituteDataForURL(const KURL&); 207 208 bool shouldPerformFragmentNavigation(bool isFormSubmission, const String& httpMethod, FrameLoadType, const KURL&); 209 void scrollToFragmentWithParentBoundary(const KURL&); 210 211 bool checkLoadCompleteForThisFrame(); 212 213 // Calls continueLoadAfterNavigationPolicy 214 void loadWithNavigationAction(const NavigationAction&, FrameLoadType, PassRefPtrWillBeRawPtr<FormState>, 215 const SubstituteData&, ClientRedirectPolicy = NotClientRedirect, const AtomicString& overrideEncoding = nullAtom); 216 217 void detachFromParent(); 218 void detachChildren(); 219 void detachClient(); 220 221 void setHistoryItemStateForCommit(HistoryCommitType, bool isPushOrReplaceState = false, PassRefPtr<SerializedScriptValue> = nullptr); 222 223 void loadInSameDocument(const KURL&, PassRefPtr<SerializedScriptValue> stateObject, FrameLoadType, ClientRedirectPolicy); 224 225 void scheduleCheckCompleted(); 226 void startCheckCompleteTimer(); 227 228 LocalFrame* m_frame; 229 230 // FIXME: These should be OwnPtr<T> to reduce build times and simplify 231 // header dependencies unless performance testing proves otherwise. 232 // Some of these could be lazily created for memory savings on devices. 233 mutable FrameLoaderStateMachine m_stateMachine; 234 mutable MixedContentChecker m_mixedContentChecker; 235 236 OwnPtr<ProgressTracker> m_progressTracker; 237 238 FrameState m_state; 239 FrameLoadType m_loadType; 240 241 // Document loaders for the three phases of frame loading. Note that while 242 // a new request is being loaded, the old document loader may still be referenced. 243 // E.g. while a new request is in the "policy" state, the old document loader may 244 // be consulted in particular as it makes sense to imply certain settings on the new loader. 245 RefPtr<DocumentLoader> m_documentLoader; 246 RefPtr<DocumentLoader> m_provisionalDocumentLoader; 247 RefPtr<DocumentLoader> m_policyDocumentLoader; 248 OwnPtr<FetchContext> m_fetchContext; 249 250 RefPtr<HistoryItem> m_currentItem; 251 RefPtr<HistoryItem> m_provisionalItem; 252 struct DeferredHistoryLoad { DeferredHistoryLoadDeferredHistoryLoad253 DeferredHistoryLoad(HistoryItem* item, HistoryLoadType type, ResourceRequestCachePolicy cachePolicy) 254 : m_item(item) 255 , m_type(type) 256 , m_cachePolicy(cachePolicy) 257 { 258 } 259 DeferredHistoryLoadDeferredHistoryLoad260 DeferredHistoryLoad() { } 261 isValidDeferredHistoryLoad262 bool isValid() { return m_item; } 263 264 RefPtr<HistoryItem> m_item; 265 HistoryLoadType m_type; 266 ResourceRequestCachePolicy m_cachePolicy; 267 }; 268 DeferredHistoryLoad m_deferredHistoryLoad; 269 270 bool m_inStopAllLoaders; 271 272 // FIXME: This is only used in checkCompleted(). Figure out a way to disentangle it. 273 bool m_isComplete; 274 275 Timer<FrameLoader> m_checkTimer; 276 bool m_shouldCallCheckCompleted; 277 278 bool m_didAccessInitialDocument; 279 Timer<FrameLoader> m_didAccessInitialDocumentTimer; 280 281 SandboxFlags m_forcedSandboxFlags; 282 283 bool m_willDetachClient; 284 }; 285 286 } // namespace WebCore 287 288 #endif // FrameLoader_h 289