blob: b03a4541ea902d73d245727d03f4a4eb8b7d138e [file] [log] [blame]
abarth@webkit.org450089a2009-10-02 08:03:35 +00001/*
dbates@webkit.org174ac712017-06-30 21:35:23 +00002 * Copyright (C) 2006-2017 Apple Inc. All rights reserved.
abarth@webkit.org450089a2009-10-02 08:03:35 +00003 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
5 * Copyright (C) 2009 Adam Barth. 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.
mjs@apple.com92047332014-03-15 04:08:27 +000016 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
abarth@webkit.org450089a2009-10-02 08:03:35 +000017 * 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#include "config.h"
abarth@webkit.org88b4e6b2010-10-04 22:09:57 +000033#include "NavigationScheduler.h"
abarth@webkit.org450089a2009-10-02 08:03:35 +000034
darin@apple.come10e1282010-10-30 00:44:33 +000035#include "BackForwardController.h"
beidson@apple.com7034ec72017-07-06 00:01:53 +000036#include "CommonVM.h"
inferno@chromium.org1930aab2010-09-17 16:36:53 +000037#include "DOMWindow.h"
abarth@webkit.org450089a2009-10-02 08:03:35 +000038#include "DocumentLoader.h"
39#include "Event.h"
40#include "FormState.h"
dglazkov@chromium.org996fc222010-06-21 16:36:40 +000041#include "FormSubmission.h"
abarth@webkit.org450089a2009-10-02 08:03:35 +000042#include "Frame.h"
43#include "FrameLoadRequest.h"
44#include "FrameLoader.h"
japhet@chromium.org61d4b9c2010-06-21 20:06:02 +000045#include "FrameLoaderStateMachine.h"
abarth@webkit.org450089a2009-10-02 08:03:35 +000046#include "HTMLFormElement.h"
beidson@apple.com1117ef42009-12-12 01:34:17 +000047#include "HTMLFrameOwnerElement.h"
inferno@chromium.org1930aab2010-09-17 16:36:53 +000048#include "HistoryItem.h"
commit-queue@webkit.orgdaffe2f2013-01-24 05:42:33 +000049#include "InspectorInstrumentation.h"
simon.fraser@apple.com78287862017-02-13 22:53:46 +000050#include "Logging.h"
rniwa@webkit.orgf694bd62017-06-30 19:32:41 +000051#include "NavigationDisabler.h"
beidson@apple.com992d69a2009-11-03 21:06:09 +000052#include "Page.h"
cdumez@apple.comf0af1232018-02-13 20:46:47 +000053#include "PolicyChecker.h"
weinig@apple.com123e4aa2013-04-14 00:54:27 +000054#include "ScriptController.h"
abarth@webkit.orgc72185c2010-04-09 06:43:19 +000055#include "UserGestureIndicator.h"
akling@apple.comf8515982013-09-02 18:50:01 +000056#include <wtf/Ref.h>
abarth@webkit.org450089a2009-10-02 08:03:35 +000057
58namespace WebCore {
59
rniwa@webkit.orgf694bd62017-06-30 19:32:41 +000060unsigned NavigationDisabler::s_globalNavigationDisableCount = 0;
rniwa@webkit.orgcf460072011-01-08 02:15:10 +000061
ossy@webkit.org95c1bc42011-01-20 16:30:54 +000062class ScheduledNavigation {
63 WTF_MAKE_NONCOPYABLE(ScheduledNavigation); WTF_MAKE_FAST_ALLOCATED;
eric@webkit.org9b31e482010-03-31 23:22:23 +000064public:
mrowe@apple.combf5eaa62014-04-03 00:51:04 +000065 ScheduledNavigation(double delay, LockHistory lockHistory, LockBackForwardList lockBackForwardList, bool wasDuringLoad, bool isLocationChange)
eric@webkit.org9b31e482010-03-31 23:22:23 +000066 : m_delay(delay)
67 , m_lockHistory(lockHistory)
68 , m_lockBackForwardList(lockBackForwardList)
69 , m_wasDuringLoad(wasDuringLoad)
weinig@apple.come2b28762010-05-12 23:21:59 +000070 , m_isLocationChange(isLocationChange)
weinig@apple.com2e10e102016-07-18 01:07:11 +000071 , m_userGestureToForward(UserGestureIndicator::currentUserGesture())
abarth@webkit.org450089a2009-10-02 08:03:35 +000072 {
abarth@webkit.org450089a2009-10-02 08:03:35 +000073 }
darin@apple.comc04189e2017-01-18 05:17:17 +000074 ScheduledNavigation(double delay, LockHistory lockHistory, LockBackForwardList lockBackForwardList, bool wasDuringLoad, bool isLocationChange, ShouldOpenExternalURLsPolicy externalURLPolicy)
75 : m_delay(delay)
76 , m_lockHistory(lockHistory)
77 , m_lockBackForwardList(lockBackForwardList)
78 , m_wasDuringLoad(wasDuringLoad)
79 , m_isLocationChange(isLocationChange)
80 , m_userGestureToForward(UserGestureIndicator::currentUserGesture())
81 , m_shouldOpenExternalURLsPolicy(externalURLPolicy)
82 {
beidson@apple.com7034ec72017-07-06 00:01:53 +000083 if (auto* frame = lexicalFrameFromCommonVM()) {
84 if (frame->isMainFrame())
dbates@webkit.orgdc3a7cf2017-07-12 17:12:07 +000085 m_initiatedByMainFrame = InitiatedByMainFrame::Yes;
beidson@apple.com7034ec72017-07-06 00:01:53 +000086 }
darin@apple.comc04189e2017-01-18 05:17:17 +000087 }
dbates@webkit.orgf21f3ae2017-10-19 23:48:45 +000088 virtual ~ScheduledNavigation() = default;
abarth@webkit.org450089a2009-10-02 08:03:35 +000089
andersca@apple.com8a458862014-01-11 00:38:16 +000090 virtual void fire(Frame&) = 0;
abarth@webkit.org450089a2009-10-02 08:03:35 +000091
andersca@apple.com8a458862014-01-11 00:38:16 +000092 virtual bool shouldStartTimer(Frame&) { return true; }
jer.noble@apple.com50862fe2014-11-06 23:06:03 +000093 virtual void didStartTimer(Frame&, Timer&) { }
andersca@apple.com8a458862014-01-11 00:38:16 +000094 virtual void didStopTimer(Frame&, bool /* newLoadInProgress */) { }
eric@webkit.org9b31e482010-03-31 23:22:23 +000095
96 double delay() const { return m_delay; }
mrowe@apple.combf5eaa62014-04-03 00:51:04 +000097 LockHistory lockHistory() const { return m_lockHistory; }
98 LockBackForwardList lockBackForwardList() const { return m_lockBackForwardList; }
eric@webkit.org9b31e482010-03-31 23:22:23 +000099 bool wasDuringLoad() const { return m_wasDuringLoad; }
weinig@apple.come2b28762010-05-12 23:21:59 +0000100 bool isLocationChange() const { return m_isLocationChange; }
darin@apple.comc04189e2017-01-18 05:17:17 +0000101 UserGestureToken* userGestureToForward() const { return m_userGestureToForward.get(); }
eric@webkit.org9b31e482010-03-31 23:22:23 +0000102
jnd@chromium.orgae563162010-12-02 20:17:06 +0000103protected:
weinig@apple.com2e10e102016-07-18 01:07:11 +0000104 void clearUserGesture() { m_userGestureToForward = nullptr; }
darin@apple.comc04189e2017-01-18 05:17:17 +0000105 ShouldOpenExternalURLsPolicy shouldOpenExternalURLs() const { return m_shouldOpenExternalURLsPolicy; }
dbates@webkit.orgdc3a7cf2017-07-12 17:12:07 +0000106 InitiatedByMainFrame initiatedByMainFrame() const { return m_initiatedByMainFrame; };
beidson@apple.com87dc6312015-06-02 18:43:13 +0000107
eric@webkit.org9b31e482010-03-31 23:22:23 +0000108private:
109 double m_delay;
mrowe@apple.combf5eaa62014-04-03 00:51:04 +0000110 LockHistory m_lockHistory;
111 LockBackForwardList m_lockBackForwardList;
eric@webkit.org9b31e482010-03-31 23:22:23 +0000112 bool m_wasDuringLoad;
weinig@apple.come2b28762010-05-12 23:21:59 +0000113 bool m_isLocationChange;
weinig@apple.com2e10e102016-07-18 01:07:11 +0000114 RefPtr<UserGestureToken> m_userGestureToForward;
darin@apple.comc04189e2017-01-18 05:17:17 +0000115 ShouldOpenExternalURLsPolicy m_shouldOpenExternalURLsPolicy { ShouldOpenExternalURLsPolicy::ShouldNotAllow };
dbates@webkit.orgdc3a7cf2017-07-12 17:12:07 +0000116 InitiatedByMainFrame m_initiatedByMainFrame { InitiatedByMainFrame::Unknown };
eric@webkit.org9b31e482010-03-31 23:22:23 +0000117};
118
119class ScheduledURLNavigation : public ScheduledNavigation {
darin@apple.com1cf3d562010-12-07 16:23:03 +0000120protected:
darin@apple.comc04189e2017-01-18 05:17:17 +0000121 ScheduledURLNavigation(Document& initiatingDocument, double delay, SecurityOrigin* securityOrigin, const URL& url, const String& referrer, LockHistory lockHistory, LockBackForwardList lockBackForwardList, bool duringLoad, bool isLocationChange)
122 : ScheduledNavigation(delay, lockHistory, lockBackForwardList, duringLoad, isLocationChange, initiatingDocument.shouldOpenExternalURLsPolicyToPropagate())
dbates@webkit.org174ac712017-06-30 21:35:23 +0000123 , m_initiatingDocument { makeRef(initiatingDocument) }
124 , m_securityOrigin{ makeRefPtr(securityOrigin) }
125 , m_url { url }
126 , m_referrer { referrer }
abarth@webkit.org450089a2009-10-02 08:03:35 +0000127 {
128 }
129
darin@apple.com11ff47c2016-03-04 16:47:55 +0000130 void didStartTimer(Frame& frame, Timer& timer) override
eric@webkit.org9b31e482010-03-31 23:22:23 +0000131 {
132 if (m_haveToldClient)
133 return;
134 m_haveToldClient = true;
commit-queue@webkit.org88c74ba2011-05-07 23:37:35 +0000135
weinig@apple.com2e10e102016-07-18 01:07:11 +0000136 UserGestureIndicator gestureIndicator(userGestureToForward());
utatane.tea@gmail.comeb3a8092018-02-23 04:18:17 +0000137 frame.loader().clientRedirected(m_url, delay(), WallTime::now() + timer.nextFireInterval(), lockBackForwardList());
eric@webkit.org9b31e482010-03-31 23:22:23 +0000138 }
139
darin@apple.com11ff47c2016-03-04 16:47:55 +0000140 void didStopTimer(Frame& frame, bool newLoadInProgress) override
eric@webkit.org9b31e482010-03-31 23:22:23 +0000141 {
142 if (!m_haveToldClient)
143 return;
commit-queue@webkit.org88c74ba2011-05-07 23:37:35 +0000144
145 // Do not set a UserGestureIndicator because
146 // clientRedirectCancelledOrFinished() is also called from many places
147 // inside FrameLoader, where the gesture state is not set and is in
148 // fact unavailable. We need to be consistent with them, otherwise the
149 // gesture state will sometimes be set and sometimes not within
150 // dispatchDidCancelClientRedirect().
andersca@apple.com8a458862014-01-11 00:38:16 +0000151 frame.loader().clientRedirectCancelledOrFinished(newLoadInProgress);
eric@webkit.org9b31e482010-03-31 23:22:23 +0000152 }
153
dbates@webkit.org174ac712017-06-30 21:35:23 +0000154 Document& initiatingDocument() { return m_initiatingDocument.get(); }
darin@apple.com1cf3d562010-12-07 16:23:03 +0000155 SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); }
darin@apple.com47a20cb2014-04-27 16:06:27 +0000156 const URL& url() const { return m_url; }
eric@webkit.org9b31e482010-03-31 23:22:23 +0000157 String referrer() const { return m_referrer; }
eric@webkit.org9b31e482010-03-31 23:22:23 +0000158
159private:
dbates@webkit.org174ac712017-06-30 21:35:23 +0000160 Ref<Document> m_initiatingDocument;
darin@apple.com1cf3d562010-12-07 16:23:03 +0000161 RefPtr<SecurityOrigin> m_securityOrigin;
darin@apple.com47a20cb2014-04-27 16:06:27 +0000162 URL m_url;
eric@webkit.org9b31e482010-03-31 23:22:23 +0000163 String m_referrer;
darin@apple.comc04189e2017-01-18 05:17:17 +0000164 bool m_haveToldClient { false };
eric@webkit.org9b31e482010-03-31 23:22:23 +0000165};
166
167class ScheduledRedirect : public ScheduledURLNavigation {
168public:
darin@apple.comc04189e2017-01-18 05:17:17 +0000169 ScheduledRedirect(Document& initiatingDocument, double delay, SecurityOrigin* securityOrigin, const URL& url, LockHistory lockHistory, LockBackForwardList lockBackForwardList)
beidson@apple.com87dc6312015-06-02 18:43:13 +0000170 : ScheduledURLNavigation(initiatingDocument, delay, securityOrigin, url, String(), lockHistory, lockBackForwardList, false, false)
abarth@webkit.org41c93442010-10-18 02:59:32 +0000171 {
jnd@chromium.orgae563162010-12-02 20:17:06 +0000172 clearUserGesture();
abarth@webkit.org41c93442010-10-18 02:59:32 +0000173 }
eric@webkit.org9b31e482010-03-31 23:22:23 +0000174
darin@apple.com11ff47c2016-03-04 16:47:55 +0000175 bool shouldStartTimer(Frame& frame) override
andersca@apple.com8a458862014-01-11 00:38:16 +0000176 {
177 return frame.loader().allAncestorsAreComplete();
178 }
robert@webkit.org52019832011-07-03 20:34:14 +0000179
darin@apple.com11ff47c2016-03-04 16:47:55 +0000180 void fire(Frame& frame) override
robert@webkit.org52019832011-07-03 20:34:14 +0000181 {
dbates@webkit.org174ac712017-06-30 21:35:23 +0000182 UserGestureIndicator gestureIndicator { userGestureToForward() };
beidson@apple.comee119d42015-04-28 19:38:13 +0000183
dbates@webkit.org174ac712017-06-30 21:35:23 +0000184 bool refresh = equalIgnoringFragmentIdentifier(frame.document()->url(), url());
commit-queue@webkit.org4833ac52018-02-26 17:38:14 +0000185 ResourceRequest resourceRequest { url(), referrer(), refresh ? ReloadIgnoringCacheData : UseProtocolCachePolicy };
bfulgham@apple.come89a3202018-04-25 19:16:00 +0000186 if (initiatedByMainFrame() == InitiatedByMainFrame::Yes)
187 resourceRequest.setRequester(ResourceRequest::Requester::Main);
dbates@webkit.orgdc3a7cf2017-07-12 17:12:07 +0000188 FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() };
dbates@webkit.org174ac712017-06-30 21:35:23 +0000189
commit-queue@webkit.org79b7c912017-08-31 21:26:24 +0000190 frame.loader().changeLocation(WTFMove(frameLoadRequest));
robert@webkit.org52019832011-07-03 20:34:14 +0000191 }
eric@webkit.org9b31e482010-03-31 23:22:23 +0000192};
193
194class ScheduledLocationChange : public ScheduledURLNavigation {
195public:
darin@apple.comc04189e2017-01-18 05:17:17 +0000196 ScheduledLocationChange(Document& initiatingDocument, SecurityOrigin* securityOrigin, const URL& url, const String& referrer, LockHistory lockHistory, LockBackForwardList lockBackForwardList, bool duringLoad)
beidson@apple.com87dc6312015-06-02 18:43:13 +0000197 : ScheduledURLNavigation(initiatingDocument, 0.0, securityOrigin, url, referrer, lockHistory, lockBackForwardList, duringLoad, true) { }
aestes@apple.com47ac5e12014-08-18 17:48:48 +0000198
darin@apple.com11ff47c2016-03-04 16:47:55 +0000199 void fire(Frame& frame) override
aestes@apple.com47ac5e12014-08-18 17:48:48 +0000200 {
dbates@webkit.org174ac712017-06-30 21:35:23 +0000201 UserGestureIndicator gestureIndicator { userGestureToForward() };
beidson@apple.comee119d42015-04-28 19:38:13 +0000202
dbates@webkit.org174ac712017-06-30 21:35:23 +0000203 ResourceRequest resourceRequest { url(), referrer(), UseProtocolCachePolicy };
dbates@webkit.orgdc3a7cf2017-07-12 17:12:07 +0000204 FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() };
beidson@apple.com7034ec72017-07-06 00:01:53 +0000205
commit-queue@webkit.org79b7c912017-08-31 21:26:24 +0000206 frame.loader().changeLocation(WTFMove(frameLoadRequest));
aestes@apple.com47ac5e12014-08-18 17:48:48 +0000207 }
eric@webkit.org9b31e482010-03-31 23:22:23 +0000208};
209
210class ScheduledRefresh : public ScheduledURLNavigation {
211public:
darin@apple.comc04189e2017-01-18 05:17:17 +0000212 ScheduledRefresh(Document& initiatingDocument, SecurityOrigin* securityOrigin, const URL& url, const String& referrer)
beidson@apple.com87dc6312015-06-02 18:43:13 +0000213 : ScheduledURLNavigation(initiatingDocument, 0.0, securityOrigin, url, referrer, LockHistory::Yes, LockBackForwardList::Yes, false, true)
abarth@webkit.org41c93442010-10-18 02:59:32 +0000214 {
215 }
eric@webkit.org9b31e482010-03-31 23:22:23 +0000216
darin@apple.com11ff47c2016-03-04 16:47:55 +0000217 void fire(Frame& frame) override
eric@webkit.org9b31e482010-03-31 23:22:23 +0000218 {
dbates@webkit.org174ac712017-06-30 21:35:23 +0000219 UserGestureIndicator gestureIndicator { userGestureToForward() };
beidson@apple.comee119d42015-04-28 19:38:13 +0000220
commit-queue@webkit.org4833ac52018-02-26 17:38:14 +0000221 ResourceRequest resourceRequest { url(), referrer(), ReloadIgnoringCacheData };
dbates@webkit.orgdc3a7cf2017-07-12 17:12:07 +0000222 FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() };
beidson@apple.com7034ec72017-07-06 00:01:53 +0000223
dbates@webkit.org174ac712017-06-30 21:35:23 +0000224 frame.loader().changeLocation(WTFMove(frameLoadRequest));
eric@webkit.org9b31e482010-03-31 23:22:23 +0000225 }
226};
227
228class ScheduledHistoryNavigation : public ScheduledNavigation {
229public:
abarth@webkit.org41c93442010-10-18 02:59:32 +0000230 explicit ScheduledHistoryNavigation(int historySteps)
mrowe@apple.combf5eaa62014-04-03 00:51:04 +0000231 : ScheduledNavigation(0, LockHistory::No, LockBackForwardList::No, false, true)
abarth@webkit.org41c93442010-10-18 02:59:32 +0000232 , m_historySteps(historySteps)
233 {
234 }
eric@webkit.org9b31e482010-03-31 23:22:23 +0000235
darin@apple.com11ff47c2016-03-04 16:47:55 +0000236 void fire(Frame& frame) override
eric@webkit.org9b31e482010-03-31 23:22:23 +0000237 {
weinig@apple.com2e10e102016-07-18 01:07:11 +0000238 UserGestureIndicator gestureIndicator(userGestureToForward());
inferno@chromium.org1930aab2010-09-17 16:36:53 +0000239
eric@webkit.org9b31e482010-03-31 23:22:23 +0000240 if (!m_historySteps) {
241 // Special case for go(0) from a frame -> reload only the frame
inferno@chromium.org1930aab2010-09-17 16:36:53 +0000242 // To follow Firefox and IE's behavior, history reload can only navigate the self frame.
darin@apple.comc04189e2017-01-18 05:17:17 +0000243 frame.loader().urlSelected(frame.document()->url(), "_self", 0, lockHistory(), lockBackForwardList(), MaybeSendReferrer, shouldOpenExternalURLs());
eric@webkit.org9b31e482010-03-31 23:22:23 +0000244 return;
245 }
andersca@apple.com8a458862014-01-11 00:38:16 +0000246
eric@webkit.org9b31e482010-03-31 23:22:23 +0000247 // go(i!=0) from a frame navigates into the history of the frame only,
248 // in both IE and NS (but not in Mozilla). We can't easily do that.
andersca@apple.com8a458862014-01-11 00:38:16 +0000249 frame.page()->backForward().goBackOrForward(m_historySteps);
eric@webkit.org9b31e482010-03-31 23:22:23 +0000250 }
251
252private:
253 int m_historySteps;
254};
255
256class ScheduledFormSubmission : public ScheduledNavigation {
257public:
darin@apple.comc04189e2017-01-18 05:17:17 +0000258 ScheduledFormSubmission(Ref<FormSubmission>&& submission, LockBackForwardList lockBackForwardList, bool duringLoad)
259 : ScheduledNavigation(0, submission->lockHistory(), lockBackForwardList, duringLoad, true, submission->state().sourceDocument().shouldOpenExternalURLsPolicyToPropagate())
260 , m_submission(WTFMove(submission))
abarth@webkit.org450089a2009-10-02 08:03:35 +0000261 {
abarth@webkit.org450089a2009-10-02 08:03:35 +0000262 }
eric@webkit.org9b31e482010-03-31 23:22:23 +0000263
darin@apple.com11ff47c2016-03-04 16:47:55 +0000264 void fire(Frame& frame) override
eric@webkit.org9b31e482010-03-31 23:22:23 +0000265 {
weinig@apple.com2e10e102016-07-18 01:07:11 +0000266 UserGestureIndicator gestureIndicator(userGestureToForward());
commit-queue@webkit.org572a9b62010-09-03 18:21:29 +0000267
eric@webkit.org9b31e482010-03-31 23:22:23 +0000268 // The submitForm function will find a target frame before using the redirection timer.
269 // Now that the timer has fired, we need to repeat the security check which normally is done when
270 // selecting a target, in case conditions have changed. Other code paths avoid this by targeting
271 // without leaving a time window. If we fail the check just silently drop the form submission.
darin@apple.comc04189e2017-01-18 05:17:17 +0000272 auto& requestingDocument = m_submission->state().sourceDocument();
273 if (!requestingDocument.canNavigate(&frame))
eric@webkit.org9b31e482010-03-31 23:22:23 +0000274 return;
dbates@webkit.orgdc3a7cf2017-07-12 17:12:07 +0000275 FrameLoadRequest frameLoadRequest { requestingDocument, requestingDocument.securityOrigin(), { }, { }, lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() };
dbates@webkit.orgb8a43fd2017-06-21 21:19:05 +0000276 m_submission->populateFrameLoadRequest(frameLoadRequest);
bfulgham@apple.com657c5c72018-05-24 05:23:00 +0000277 frame.loader().loadFrameRequest(WTFMove(frameLoadRequest), m_submission->event(), m_submission->takeState());
eric@webkit.org9b31e482010-03-31 23:22:23 +0000278 }
darin@apple.comc04189e2017-01-18 05:17:17 +0000279
darin@apple.com11ff47c2016-03-04 16:47:55 +0000280 void didStartTimer(Frame& frame, Timer& timer) override
commit-queue@webkit.org4cbfdfd2010-08-13 23:35:34 +0000281 {
282 if (m_haveToldClient)
283 return;
284 m_haveToldClient = true;
commit-queue@webkit.org88c74ba2011-05-07 23:37:35 +0000285
weinig@apple.com2e10e102016-07-18 01:07:11 +0000286 UserGestureIndicator gestureIndicator(userGestureToForward());
utatane.tea@gmail.comeb3a8092018-02-23 04:18:17 +0000287 frame.loader().clientRedirected(m_submission->requestURL(), delay(), WallTime::now() + timer.nextFireInterval(), lockBackForwardList());
commit-queue@webkit.org4cbfdfd2010-08-13 23:35:34 +0000288 }
eric@webkit.org9b31e482010-03-31 23:22:23 +0000289
darin@apple.com11ff47c2016-03-04 16:47:55 +0000290 void didStopTimer(Frame& frame, bool newLoadInProgress) override
commit-queue@webkit.org4cbfdfd2010-08-13 23:35:34 +0000291 {
292 if (!m_haveToldClient)
293 return;
commit-queue@webkit.org88c74ba2011-05-07 23:37:35 +0000294
295 // Do not set a UserGestureIndicator because
296 // clientRedirectCancelledOrFinished() is also called from many places
297 // inside FrameLoader, where the gesture state is not set and is in
298 // fact unavailable. We need to be consistent with them, otherwise the
299 // gesture state will sometimes be set and sometimes not within
300 // dispatchDidCancelClientRedirect().
andersca@apple.com8a458862014-01-11 00:38:16 +0000301 frame.loader().clientRedirectCancelledOrFinished(newLoadInProgress);
commit-queue@webkit.org4cbfdfd2010-08-13 23:35:34 +0000302 }
eric@webkit.org9b31e482010-03-31 23:22:23 +0000303
304private:
darin@apple.comc04189e2017-01-18 05:17:17 +0000305 Ref<FormSubmission> m_submission;
306 bool m_haveToldClient { false };
abarth@webkit.org450089a2009-10-02 08:03:35 +0000307};
308
dbates@webkit.orgdb7c48d2016-01-12 22:28:59 +0000309class ScheduledPageBlock final : public ScheduledNavigation {
310public:
311 ScheduledPageBlock(Document& originDocument)
312 : ScheduledNavigation(0, LockHistory::Yes, LockBackForwardList::Yes, false, false)
313 , m_originDocument(originDocument)
314 {
315 }
316
317 void fire(Frame& frame) override
318 {
dbates@webkit.org174ac712017-06-30 21:35:23 +0000319 UserGestureIndicator gestureIndicator { userGestureToForward() };
dbates@webkit.orgdb7c48d2016-01-12 22:28:59 +0000320
utatane.tea@gmail.com84077632018-06-23 08:39:34 +0000321 ResourceResponse replacementResponse { m_originDocument.url(), "text/plain"_s, 0, "UTF-8"_s };
dbates@webkit.org174ac712017-06-30 21:35:23 +0000322 SubstituteData replacementData { SharedBuffer::create(), m_originDocument.url(), replacementResponse, SubstituteData::SessionHistoryVisibility::Hidden };
dbates@webkit.orgdb7c48d2016-01-12 22:28:59 +0000323
commit-queue@webkit.org4833ac52018-02-26 17:38:14 +0000324 ResourceRequest resourceRequest { m_originDocument.url(), emptyString(), ReloadIgnoringCacheData };
dbates@webkit.orgdc3a7cf2017-07-12 17:12:07 +0000325 FrameLoadRequest frameLoadRequest { m_originDocument, m_originDocument.securityOrigin(), resourceRequest, { }, lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() };
dbates@webkit.orgb8a43fd2017-06-21 21:19:05 +0000326 frameLoadRequest.setSubstituteData(replacementData);
dbates@webkit.org7f3a9822017-06-22 19:45:10 +0000327 frame.loader().load(WTFMove(frameLoadRequest));
dbates@webkit.orgdb7c48d2016-01-12 22:28:59 +0000328 }
329
330private:
331 Document& m_originDocument;
332};
333
andersca@apple.com8a458862014-01-11 00:38:16 +0000334NavigationScheduler::NavigationScheduler(Frame& frame)
abarth@webkit.org450089a2009-10-02 08:03:35 +0000335 : m_frame(frame)
andersca@apple.com574a7452014-11-21 20:10:13 +0000336 , m_timer(*this, &NavigationScheduler::timerFired)
abarth@webkit.org450089a2009-10-02 08:03:35 +0000337{
338}
339
dbates@webkit.orgf21f3ae2017-10-19 23:48:45 +0000340NavigationScheduler::~NavigationScheduler() = default;
abarth@webkit.org450089a2009-10-02 08:03:35 +0000341
abarth@webkit.org88b4e6b2010-10-04 22:09:57 +0000342bool NavigationScheduler::redirectScheduledDuringLoad()
abarth@webkit.org450089a2009-10-02 08:03:35 +0000343{
eric@webkit.org9b31e482010-03-31 23:22:23 +0000344 return m_redirect && m_redirect->wasDuringLoad();
abarth@webkit.org450089a2009-10-02 08:03:35 +0000345}
346
abarth@webkit.org88b4e6b2010-10-04 22:09:57 +0000347bool NavigationScheduler::locationChangePending()
weinig@apple.come2b28762010-05-12 23:21:59 +0000348{
349 return m_redirect && m_redirect->isLocationChange();
350}
351
abarth@webkit.org88b4e6b2010-10-04 22:09:57 +0000352void NavigationScheduler::clear()
abarth@webkit.org450089a2009-10-02 08:03:35 +0000353{
commit-queue@webkit.orgdaffe2f2013-01-24 05:42:33 +0000354 if (m_timer.isActive())
355 InspectorInstrumentation::frameClearedScheduledNavigation(m_frame);
abarth@webkit.org450089a2009-10-02 08:03:35 +0000356 m_timer.stop();
andersca@apple.com8a458862014-01-11 00:38:16 +0000357 m_redirect = nullptr;
abarth@webkit.org450089a2009-10-02 08:03:35 +0000358}
359
rniwa@webkit.orgcf460072011-01-08 02:15:10 +0000360inline bool NavigationScheduler::shouldScheduleNavigation() const
361{
andersca@apple.com8a458862014-01-11 00:38:16 +0000362 return m_frame.page();
rniwa@webkit.orgcf460072011-01-08 02:15:10 +0000363}
364
darin@apple.com47a20cb2014-04-27 16:06:27 +0000365inline bool NavigationScheduler::shouldScheduleNavigation(const URL& url) const
rniwa@webkit.orgcf460072011-01-08 02:15:10 +0000366{
darin@apple.com47a20cb2014-04-27 16:06:27 +0000367 if (!shouldScheduleNavigation())
368 return false;
369 if (protocolIsJavaScript(url))
370 return true;
rniwa@webkit.orgf694bd62017-06-30 19:32:41 +0000371 return NavigationDisabler::isNavigationAllowed(m_frame);
rniwa@webkit.orgcf460072011-01-08 02:15:10 +0000372}
373
darin@apple.comc04189e2017-01-18 05:17:17 +0000374void NavigationScheduler::scheduleRedirect(Document& initiatingDocument, double delay, const URL& url)
abarth@webkit.org450089a2009-10-02 08:03:35 +0000375{
rniwa@webkit.orgcf460072011-01-08 02:15:10 +0000376 if (!shouldScheduleNavigation(url))
abarth@webkit.org450089a2009-10-02 08:03:35 +0000377 return;
eric@webkit.org9b31e482010-03-31 23:22:23 +0000378 if (delay < 0 || delay > INT_MAX / 1000)
379 return;
abarth@webkit.org450089a2009-10-02 08:03:35 +0000380 if (url.isEmpty())
381 return;
382
commit-queue@webkit.org4cbfdfd2010-08-13 23:35:34 +0000383 // We want a new back/forward list item if the refresh timeout is > 1 second.
mrowe@apple.combf5eaa62014-04-03 00:51:04 +0000384 if (!m_redirect || delay <= m_redirect->delay()) {
darin@apple.comc04189e2017-01-18 05:17:17 +0000385 auto lockBackForwardList = delay <= 1 ? LockBackForwardList::Yes : LockBackForwardList::No;
akling@apple.com6be0e972017-01-18 19:35:49 +0000386 schedule(std::make_unique<ScheduledRedirect>(initiatingDocument, delay, &m_frame.document()->securityOrigin(), url, LockHistory::Yes, lockBackForwardList));
mrowe@apple.combf5eaa62014-04-03 00:51:04 +0000387 }
abarth@webkit.org450089a2009-10-02 08:03:35 +0000388}
389
mrowe@apple.combf5eaa62014-04-03 00:51:04 +0000390LockBackForwardList NavigationScheduler::mustLockBackForwardList(Frame& targetFrame)
abarth@webkit.org450089a2009-10-02 08:03:35 +0000391{
commit-queue@webkit.org2ca2f772010-08-17 23:40:00 +0000392 // Non-user navigation before the page has finished firing onload should not create a new back/forward item.
commit-queue@webkit.org4cbfdfd2010-08-13 23:35:34 +0000393 // See https://webkit.org/b/42861 for the original motivation for this.
weinig@apple.com2e10e102016-07-18 01:07:11 +0000394 if (!UserGestureIndicator::processingUserGesture() && targetFrame.loader().documentLoader() && !targetFrame.loader().documentLoader()->wasOnloadDispatched())
mrowe@apple.combf5eaa62014-04-03 00:51:04 +0000395 return LockBackForwardList::Yes;
commit-queue@webkit.org4cbfdfd2010-08-13 23:35:34 +0000396
abarth@webkit.org450089a2009-10-02 08:03:35 +0000397 // Navigation of a subframe during loading of an ancestor frame does not create a new back/forward item.
398 // The definition of "during load" is any time before all handlers for the load event have been run.
399 // See https://bugs.webkit.org/show_bug.cgi?id=14957 for the original motivation for this.
andersca@apple.com8a458862014-01-11 00:38:16 +0000400 for (Frame* ancestor = targetFrame.tree().parent(); ancestor; ancestor = ancestor->tree().parent()) {
abarth@webkit.org450089a2009-10-02 08:03:35 +0000401 Document* document = ancestor->document();
andersca@apple.comdf550b92013-08-15 22:17:17 +0000402 if (!ancestor->loader().isComplete() || (document && document->processingLoadEvent()))
mrowe@apple.combf5eaa62014-04-03 00:51:04 +0000403 return LockBackForwardList::Yes;
abarth@webkit.org450089a2009-10-02 08:03:35 +0000404 }
mrowe@apple.combf5eaa62014-04-03 00:51:04 +0000405 return LockBackForwardList::No;
abarth@webkit.org450089a2009-10-02 08:03:35 +0000406}
407
akling@apple.com6be0e972017-01-18 19:35:49 +0000408void NavigationScheduler::scheduleLocationChange(Document& initiatingDocument, SecurityOrigin& securityOrigin, const URL& url, const String& referrer, LockHistory lockHistory, LockBackForwardList lockBackForwardList)
abarth@webkit.org450089a2009-10-02 08:03:35 +0000409{
rniwa@webkit.orgcf460072011-01-08 02:15:10 +0000410 if (!shouldScheduleNavigation(url))
abarth@webkit.org450089a2009-10-02 08:03:35 +0000411 return;
abarth@webkit.org450089a2009-10-02 08:03:35 +0000412
mrowe@apple.combf5eaa62014-04-03 00:51:04 +0000413 if (lockBackForwardList == LockBackForwardList::No)
414 lockBackForwardList = mustLockBackForwardList(m_frame);
abarth@webkit.org450089a2009-10-02 08:03:35 +0000415
andersca@apple.com8a458862014-01-11 00:38:16 +0000416 FrameLoader& loader = m_frame.loader();
eric@webkit.org818318b2011-06-16 23:15:10 +0000417
abarth@webkit.org450089a2009-10-02 08:03:35 +0000418 // If the URL we're going to navigate to is the same as the current one, except for the
419 // fragment part, we don't need to schedule the location change.
darin@apple.com610f27d2015-04-13 15:40:42 +0000420 if (url.hasFragmentIdentifier() && equalIgnoringFragmentIdentifier(m_frame.document()->url(), url)) {
dbates@webkit.orgb8a43fd2017-06-21 21:19:05 +0000421 ResourceRequest resourceRequest { m_frame.document()->completeURL(url), referrer, UseProtocolCachePolicy };
beidson@apple.com7034ec72017-07-06 00:01:53 +0000422 auto* frame = lexicalFrameFromCommonVM();
dbates@webkit.orgdc3a7cf2017-07-12 17:12:07 +0000423 auto initiatedByMainFrame = frame && frame->isMainFrame() ? InitiatedByMainFrame::Yes : InitiatedByMainFrame::Unknown;
beidson@apple.com7034ec72017-07-06 00:01:53 +0000424
utatane.tea@gmail.com84077632018-06-23 08:39:34 +0000425 FrameLoadRequest frameLoadRequest { initiatingDocument, securityOrigin, resourceRequest, "_self"_s, lockHistory, lockBackForwardList, MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, initiatingDocument.shouldOpenExternalURLsPolicyToPropagate(), initiatedByMainFrame };
dbates@webkit.org7f3a9822017-06-22 19:45:10 +0000426 loader.changeLocation(WTFMove(frameLoadRequest));
abarth@webkit.org450089a2009-10-02 08:03:35 +0000427 return;
428 }
429
430 // Handle a location change of a page with no document as a special case.
431 // This may happen when a frame changes the location of another frame.
akling@apple.com63e53cb2014-02-05 20:42:37 +0000432 bool duringLoad = !loader.stateMachine().committedFirstRealDocumentLoad();
abarth@webkit.org450089a2009-10-02 08:03:35 +0000433
akling@apple.com6be0e972017-01-18 19:35:49 +0000434 schedule(std::make_unique<ScheduledLocationChange>(initiatingDocument, &securityOrigin, url, referrer, lockHistory, lockBackForwardList, duringLoad));
abarth@webkit.org450089a2009-10-02 08:03:35 +0000435}
436
darin@apple.comc04189e2017-01-18 05:17:17 +0000437void NavigationScheduler::scheduleFormSubmission(Ref<FormSubmission>&& submission)
abarth@webkit.org450089a2009-10-02 08:03:35 +0000438{
andersca@apple.com8a458862014-01-11 00:38:16 +0000439 ASSERT(m_frame.page());
abarth@webkit.org450089a2009-10-02 08:03:35 +0000440
441 // FIXME: Do we need special handling for form submissions where the URL is the same
442 // as the current one except for the fragment part? See scheduleLocationChange above.
443
444 // Handle a location change of a page with no document as a special case.
445 // This may happen when a frame changes the location of another frame.
akling@apple.com63e53cb2014-02-05 20:42:37 +0000446 bool duringLoad = !m_frame.loader().stateMachine().committedFirstRealDocumentLoad();
abarth@webkit.org450089a2009-10-02 08:03:35 +0000447
beidson@apple.com1117ef42009-12-12 01:34:17 +0000448 // If this is a child frame and the form submission was triggered by a script, lock the back/forward list
449 // to match IE and Opera.
450 // See https://bugs.webkit.org/show_bug.cgi?id=32383 for the original motivation for this.
mrowe@apple.combf5eaa62014-04-03 00:51:04 +0000451 LockBackForwardList lockBackForwardList = mustLockBackForwardList(m_frame);
452 if (lockBackForwardList == LockBackForwardList::No
darin@apple.comc04189e2017-01-18 05:17:17 +0000453 && (submission->state().formSubmissionTrigger() == SubmittedByJavaScript && m_frame.tree().parent() && !UserGestureIndicator::processingUserGesture())) {
mrowe@apple.combf5eaa62014-04-03 00:51:04 +0000454 lockBackForwardList = LockBackForwardList::Yes;
455 }
456
darin@apple.comc04189e2017-01-18 05:17:17 +0000457 schedule(std::make_unique<ScheduledFormSubmission>(WTFMove(submission), lockBackForwardList, duringLoad));
abarth@webkit.org450089a2009-10-02 08:03:35 +0000458}
459
darin@apple.comc04189e2017-01-18 05:17:17 +0000460void NavigationScheduler::scheduleRefresh(Document& initiatingDocument)
abarth@webkit.org450089a2009-10-02 08:03:35 +0000461{
rniwa@webkit.orgcf460072011-01-08 02:15:10 +0000462 if (!shouldScheduleNavigation())
abarth@webkit.org450089a2009-10-02 08:03:35 +0000463 return;
andersca@apple.com8a458862014-01-11 00:38:16 +0000464 const URL& url = m_frame.document()->url();
abarth@webkit.org450089a2009-10-02 08:03:35 +0000465 if (url.isEmpty())
466 return;
467
akling@apple.com6be0e972017-01-18 19:35:49 +0000468 schedule(std::make_unique<ScheduledRefresh>(initiatingDocument, &m_frame.document()->securityOrigin(), url, m_frame.loader().outgoingReferrer()));
abarth@webkit.org450089a2009-10-02 08:03:35 +0000469}
470
abarth@webkit.org88b4e6b2010-10-04 22:09:57 +0000471void NavigationScheduler::scheduleHistoryNavigation(int steps)
abarth@webkit.org450089a2009-10-02 08:03:35 +0000472{
simon.fraser@apple.com78287862017-02-13 22:53:46 +0000473 LOG(History, "NavigationScheduler %p scheduleHistoryNavigation(%d) - shouldSchedule %d", this, steps, shouldScheduleNavigation());
rniwa@webkit.orgcf460072011-01-08 02:15:10 +0000474 if (!shouldScheduleNavigation())
abarth@webkit.org450089a2009-10-02 08:03:35 +0000475 return;
476
beidson@apple.comaca909e2009-10-26 23:20:25 +0000477 // Invalid history navigations (such as history.forward() during a new load) have the side effect of cancelling any scheduled
478 // redirects. We also avoid the possibility of cancelling the current load by avoiding the scheduled redirection altogether.
andersca@apple.com8a458862014-01-11 00:38:16 +0000479 BackForwardController& backForward = m_frame.page()->backForward();
akling@apple.com31cf0092013-09-11 15:24:45 +0000480 if (steps > backForward.forwardCount() || -steps > backForward.backCount()) {
beidson@apple.combf1584a2010-01-22 04:22:02 +0000481 cancel();
482 return;
483 }
inferno@chromium.org1930aab2010-09-17 16:36:53 +0000484
beidson@apple.combf1584a2010-01-22 04:22:02 +0000485 // In all other cases, schedule the history traversal to occur asynchronously.
andersca@apple.com8a458862014-01-11 00:38:16 +0000486 schedule(std::make_unique<ScheduledHistoryNavigation>(steps));
abarth@webkit.org450089a2009-10-02 08:03:35 +0000487}
488
dbates@webkit.orgdb7c48d2016-01-12 22:28:59 +0000489void NavigationScheduler::schedulePageBlock(Document& originDocument)
490{
491 if (shouldScheduleNavigation())
492 schedule(std::make_unique<ScheduledPageBlock>(originDocument));
493}
494
andersca@apple.com574a7452014-11-21 20:10:13 +0000495void NavigationScheduler::timerFired()
abarth@webkit.org450089a2009-10-02 08:03:35 +0000496{
andersca@apple.com8a458862014-01-11 00:38:16 +0000497 if (!m_frame.page())
eric@webkit.org3c521022009-10-29 00:22:14 +0000498 return;
andersca@apple.com8a458862014-01-11 00:38:16 +0000499 if (m_frame.page()->defersLoading()) {
commit-queue@webkit.orgdaffe2f2013-01-24 05:42:33 +0000500 InspectorInstrumentation::frameClearedScheduledNavigation(m_frame);
abarth@webkit.org450089a2009-10-02 08:03:35 +0000501 return;
commit-queue@webkit.orgdaffe2f2013-01-24 05:42:33 +0000502 }
503
andersca@apple.com8a458862014-01-11 00:38:16 +0000504 Ref<Frame> protect(m_frame);
abarth@webkit.org450089a2009-10-02 08:03:35 +0000505
aestes@apple.com13aae082016-01-02 08:03:08 +0000506 std::unique_ptr<ScheduledNavigation> redirect = WTFMove(m_redirect);
simon.fraser@apple.com78287862017-02-13 22:53:46 +0000507 LOG(History, "NavigationScheduler %p timerFired - firing redirect %p", this, redirect.get());
508
eric@webkit.org9b31e482010-03-31 23:22:23 +0000509 redirect->fire(m_frame);
commit-queue@webkit.orgdaffe2f2013-01-24 05:42:33 +0000510 InspectorInstrumentation::frameClearedScheduledNavigation(m_frame);
abarth@webkit.org450089a2009-10-02 08:03:35 +0000511}
512
andersca@apple.com8a458862014-01-11 00:38:16 +0000513void NavigationScheduler::schedule(std::unique_ptr<ScheduledNavigation> redirect)
abarth@webkit.org450089a2009-10-02 08:03:35 +0000514{
andersca@apple.com8a458862014-01-11 00:38:16 +0000515 ASSERT(m_frame.page());
abarth@webkit.org450089a2009-10-02 08:03:35 +0000516
andersca@apple.com8a458862014-01-11 00:38:16 +0000517 Ref<Frame> protect(m_frame);
inferno@chromium.org01ee2a22012-02-14 21:02:36 +0000518
abarth@webkit.org450089a2009-10-02 08:03:35 +0000519 // If a redirect was scheduled during a load, then stop the current load.
520 // Otherwise when the current load transitions from a provisional to a
521 // committed state, pending redirects may be cancelled.
eric@webkit.org9b31e482010-03-31 23:22:23 +0000522 if (redirect->wasDuringLoad()) {
andersca@apple.com8a458862014-01-11 00:38:16 +0000523 if (DocumentLoader* provisionalDocumentLoader = m_frame.loader().provisionalDocumentLoader())
abarth@webkit.org450089a2009-10-02 08:03:35 +0000524 provisionalDocumentLoader->stopLoading();
andersca@apple.com8a458862014-01-11 00:38:16 +0000525 m_frame.loader().stopLoading(UnloadEventPolicyUnloadAndPageHide);
abarth@webkit.org450089a2009-10-02 08:03:35 +0000526 }
527
528 cancel();
aestes@apple.com13aae082016-01-02 08:03:08 +0000529 m_redirect = WTFMove(redirect);
eric@webkit.org9b31e482010-03-31 23:22:23 +0000530
andersca@apple.com8a458862014-01-11 00:38:16 +0000531 if (!m_frame.loader().isComplete() && m_redirect->isLocationChange())
532 m_frame.loader().completed();
eric@webkit.org9b31e482010-03-31 23:22:23 +0000533
andersca@apple.com8a458862014-01-11 00:38:16 +0000534 if (!m_frame.page())
inferno@chromium.org01ee2a22012-02-14 21:02:36 +0000535 return;
536
abarth@webkit.org450089a2009-10-02 08:03:35 +0000537 startTimer();
538}
539
abarth@webkit.org88b4e6b2010-10-04 22:09:57 +0000540void NavigationScheduler::startTimer()
abarth@webkit.org450089a2009-10-02 08:03:35 +0000541{
eric@webkit.org9b31e482010-03-31 23:22:23 +0000542 if (!m_redirect)
abarth@webkit.org450089a2009-10-02 08:03:35 +0000543 return;
544
andersca@apple.com8a458862014-01-11 00:38:16 +0000545 ASSERT(m_frame.page());
abarth@webkit.org450089a2009-10-02 08:03:35 +0000546 if (m_timer.isActive())
547 return;
eric@webkit.org9b31e482010-03-31 23:22:23 +0000548 if (!m_redirect->shouldStartTimer(m_frame))
abarth@webkit.org450089a2009-10-02 08:03:35 +0000549 return;
550
cdumez@apple.com7d7fe74a2017-04-10 08:02:21 +0000551 Seconds delay = 1_s * m_redirect->delay();
dbates@webkit.orgdbb69522013-10-24 21:40:55 +0000552 m_timer.startOneShot(delay);
553 InspectorInstrumentation::frameScheduledNavigation(m_frame, delay);
andersca@apple.com8a458862014-01-11 00:38:16 +0000554 m_redirect->didStartTimer(m_frame, m_timer); // m_redirect may be null on return (e.g. the client canceled the load)
abarth@webkit.org450089a2009-10-02 08:03:35 +0000555}
556
abarth@webkit.org88b4e6b2010-10-04 22:09:57 +0000557void NavigationScheduler::cancel(bool newLoadInProgress)
abarth@webkit.org450089a2009-10-02 08:03:35 +0000558{
simon.fraser@apple.com78287862017-02-13 22:53:46 +0000559 LOG(History, "NavigationScheduler %p cancel(newLoadInProgress=%d)", this, newLoadInProgress);
560
commit-queue@webkit.orgdaffe2f2013-01-24 05:42:33 +0000561 if (m_timer.isActive())
562 InspectorInstrumentation::frameClearedScheduledNavigation(m_frame);
abarth@webkit.org450089a2009-10-02 08:03:35 +0000563 m_timer.stop();
564
aestes@apple.com13aae082016-01-02 08:03:08 +0000565 if (std::unique_ptr<ScheduledNavigation> redirect = WTFMove(m_redirect))
eric@webkit.org9b31e482010-03-31 23:22:23 +0000566 redirect->didStopTimer(m_frame, newLoadInProgress);
abarth@webkit.org450089a2009-10-02 08:03:35 +0000567}
568
569} // namespace WebCore