abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 1 | /* |
dbates@webkit.org | 174ac71 | 2017-06-30 21:35:23 +0000 | [diff] [blame] | 2 | * Copyright (C) 2006-2017 Apple Inc. All rights reserved. |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 3 | * 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.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 16 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 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 | #include "config.h" |
abarth@webkit.org | 88b4e6b | 2010-10-04 22:09:57 +0000 | [diff] [blame] | 33 | #include "NavigationScheduler.h" |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 34 | |
darin@apple.com | e10e128 | 2010-10-30 00:44:33 +0000 | [diff] [blame] | 35 | #include "BackForwardController.h" |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 36 | #include "CommonVM.h" |
inferno@chromium.org | 1930aab | 2010-09-17 16:36:53 +0000 | [diff] [blame] | 37 | #include "DOMWindow.h" |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 38 | #include "DocumentLoader.h" |
| 39 | #include "Event.h" |
| 40 | #include "FormState.h" |
dglazkov@chromium.org | 996fc22 | 2010-06-21 16:36:40 +0000 | [diff] [blame] | 41 | #include "FormSubmission.h" |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 42 | #include "Frame.h" |
| 43 | #include "FrameLoadRequest.h" |
| 44 | #include "FrameLoader.h" |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 45 | #include "FrameLoaderStateMachine.h" |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 46 | #include "HTMLFormElement.h" |
beidson@apple.com | 1117ef4 | 2009-12-12 01:34:17 +0000 | [diff] [blame] | 47 | #include "HTMLFrameOwnerElement.h" |
inferno@chromium.org | 1930aab | 2010-09-17 16:36:53 +0000 | [diff] [blame] | 48 | #include "HistoryItem.h" |
commit-queue@webkit.org | daffe2f | 2013-01-24 05:42:33 +0000 | [diff] [blame] | 49 | #include "InspectorInstrumentation.h" |
simon.fraser@apple.com | 7828786 | 2017-02-13 22:53:46 +0000 | [diff] [blame] | 50 | #include "Logging.h" |
rniwa@webkit.org | f694bd6 | 2017-06-30 19:32:41 +0000 | [diff] [blame] | 51 | #include "NavigationDisabler.h" |
beidson@apple.com | 992d69a | 2009-11-03 21:06:09 +0000 | [diff] [blame] | 52 | #include "Page.h" |
cdumez@apple.com | f0af123 | 2018-02-13 20:46:47 +0000 | [diff] [blame] | 53 | #include "PolicyChecker.h" |
weinig@apple.com | 123e4aa | 2013-04-14 00:54:27 +0000 | [diff] [blame] | 54 | #include "ScriptController.h" |
abarth@webkit.org | c72185c | 2010-04-09 06:43:19 +0000 | [diff] [blame] | 55 | #include "UserGestureIndicator.h" |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 56 | #include <wtf/Ref.h> |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 57 | |
| 58 | namespace WebCore { |
| 59 | |
rniwa@webkit.org | f694bd6 | 2017-06-30 19:32:41 +0000 | [diff] [blame] | 60 | unsigned NavigationDisabler::s_globalNavigationDisableCount = 0; |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 61 | |
ossy@webkit.org | 95c1bc4 | 2011-01-20 16:30:54 +0000 | [diff] [blame] | 62 | class ScheduledNavigation { |
| 63 | WTF_MAKE_NONCOPYABLE(ScheduledNavigation); WTF_MAKE_FAST_ALLOCATED; |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 64 | public: |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 65 | ScheduledNavigation(double delay, LockHistory lockHistory, LockBackForwardList lockBackForwardList, bool wasDuringLoad, bool isLocationChange) |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 66 | : m_delay(delay) |
| 67 | , m_lockHistory(lockHistory) |
| 68 | , m_lockBackForwardList(lockBackForwardList) |
| 69 | , m_wasDuringLoad(wasDuringLoad) |
weinig@apple.com | e2b2876 | 2010-05-12 23:21:59 +0000 | [diff] [blame] | 70 | , m_isLocationChange(isLocationChange) |
weinig@apple.com | 2e10e10 | 2016-07-18 01:07:11 +0000 | [diff] [blame] | 71 | , m_userGestureToForward(UserGestureIndicator::currentUserGesture()) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 72 | { |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 73 | } |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 74 | 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.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 83 | if (auto* frame = lexicalFrameFromCommonVM()) { |
| 84 | if (frame->isMainFrame()) |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 85 | m_initiatedByMainFrame = InitiatedByMainFrame::Yes; |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 86 | } |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 87 | } |
dbates@webkit.org | f21f3ae | 2017-10-19 23:48:45 +0000 | [diff] [blame] | 88 | virtual ~ScheduledNavigation() = default; |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 89 | |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 90 | virtual void fire(Frame&) = 0; |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 91 | |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 92 | virtual bool shouldStartTimer(Frame&) { return true; } |
jer.noble@apple.com | 50862fe | 2014-11-06 23:06:03 +0000 | [diff] [blame] | 93 | virtual void didStartTimer(Frame&, Timer&) { } |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 94 | virtual void didStopTimer(Frame&, NewLoadInProgress) { } |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 95 | |
| 96 | double delay() const { return m_delay; } |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 97 | LockHistory lockHistory() const { return m_lockHistory; } |
| 98 | LockBackForwardList lockBackForwardList() const { return m_lockBackForwardList; } |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 99 | bool wasDuringLoad() const { return m_wasDuringLoad; } |
weinig@apple.com | e2b2876 | 2010-05-12 23:21:59 +0000 | [diff] [blame] | 100 | bool isLocationChange() const { return m_isLocationChange; } |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 101 | UserGestureToken* userGestureToForward() const { return m_userGestureToForward.get(); } |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 102 | |
jnd@chromium.org | ae56316 | 2010-12-02 20:17:06 +0000 | [diff] [blame] | 103 | protected: |
weinig@apple.com | 2e10e10 | 2016-07-18 01:07:11 +0000 | [diff] [blame] | 104 | void clearUserGesture() { m_userGestureToForward = nullptr; } |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 105 | ShouldOpenExternalURLsPolicy shouldOpenExternalURLs() const { return m_shouldOpenExternalURLsPolicy; } |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 106 | InitiatedByMainFrame initiatedByMainFrame() const { return m_initiatedByMainFrame; }; |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 107 | |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 108 | private: |
| 109 | double m_delay; |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 110 | LockHistory m_lockHistory; |
| 111 | LockBackForwardList m_lockBackForwardList; |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 112 | bool m_wasDuringLoad; |
weinig@apple.com | e2b2876 | 2010-05-12 23:21:59 +0000 | [diff] [blame] | 113 | bool m_isLocationChange; |
weinig@apple.com | 2e10e10 | 2016-07-18 01:07:11 +0000 | [diff] [blame] | 114 | RefPtr<UserGestureToken> m_userGestureToForward; |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 115 | ShouldOpenExternalURLsPolicy m_shouldOpenExternalURLsPolicy { ShouldOpenExternalURLsPolicy::ShouldNotAllow }; |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 116 | InitiatedByMainFrame m_initiatedByMainFrame { InitiatedByMainFrame::Unknown }; |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | class ScheduledURLNavigation : public ScheduledNavigation { |
darin@apple.com | 1cf3d56 | 2010-12-07 16:23:03 +0000 | [diff] [blame] | 120 | protected: |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 121 | 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.org | 174ac71 | 2017-06-30 21:35:23 +0000 | [diff] [blame] | 123 | , m_initiatingDocument { makeRef(initiatingDocument) } |
| 124 | , m_securityOrigin{ makeRefPtr(securityOrigin) } |
| 125 | , m_url { url } |
| 126 | , m_referrer { referrer } |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 127 | { |
| 128 | } |
| 129 | |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame] | 130 | void didStartTimer(Frame& frame, Timer& timer) override |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 131 | { |
| 132 | if (m_haveToldClient) |
| 133 | return; |
| 134 | m_haveToldClient = true; |
commit-queue@webkit.org | 88c74ba | 2011-05-07 23:37:35 +0000 | [diff] [blame] | 135 | |
weinig@apple.com | 2e10e10 | 2016-07-18 01:07:11 +0000 | [diff] [blame] | 136 | UserGestureIndicator gestureIndicator(userGestureToForward()); |
utatane.tea@gmail.com | eb3a809 | 2018-02-23 04:18:17 +0000 | [diff] [blame] | 137 | frame.loader().clientRedirected(m_url, delay(), WallTime::now() + timer.nextFireInterval(), lockBackForwardList()); |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 138 | } |
| 139 | |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 140 | void didStopTimer(Frame& frame, NewLoadInProgress newLoadInProgress) override |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 141 | { |
| 142 | if (!m_haveToldClient) |
| 143 | return; |
commit-queue@webkit.org | 88c74ba | 2011-05-07 23:37:35 +0000 | [diff] [blame] | 144 | |
| 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.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 151 | frame.loader().clientRedirectCancelledOrFinished(newLoadInProgress); |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 152 | } |
| 153 | |
dbates@webkit.org | 174ac71 | 2017-06-30 21:35:23 +0000 | [diff] [blame] | 154 | Document& initiatingDocument() { return m_initiatingDocument.get(); } |
darin@apple.com | 1cf3d56 | 2010-12-07 16:23:03 +0000 | [diff] [blame] | 155 | SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); } |
darin@apple.com | 47a20cb | 2014-04-27 16:06:27 +0000 | [diff] [blame] | 156 | const URL& url() const { return m_url; } |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 157 | String referrer() const { return m_referrer; } |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 158 | |
| 159 | private: |
dbates@webkit.org | 174ac71 | 2017-06-30 21:35:23 +0000 | [diff] [blame] | 160 | Ref<Document> m_initiatingDocument; |
darin@apple.com | 1cf3d56 | 2010-12-07 16:23:03 +0000 | [diff] [blame] | 161 | RefPtr<SecurityOrigin> m_securityOrigin; |
darin@apple.com | 47a20cb | 2014-04-27 16:06:27 +0000 | [diff] [blame] | 162 | URL m_url; |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 163 | String m_referrer; |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 164 | bool m_haveToldClient { false }; |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | class ScheduledRedirect : public ScheduledURLNavigation { |
| 168 | public: |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 169 | ScheduledRedirect(Document& initiatingDocument, double delay, SecurityOrigin* securityOrigin, const URL& url, LockHistory lockHistory, LockBackForwardList lockBackForwardList) |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 170 | : ScheduledURLNavigation(initiatingDocument, delay, securityOrigin, url, String(), lockHistory, lockBackForwardList, false, false) |
abarth@webkit.org | 41c9344 | 2010-10-18 02:59:32 +0000 | [diff] [blame] | 171 | { |
jnd@chromium.org | ae56316 | 2010-12-02 20:17:06 +0000 | [diff] [blame] | 172 | clearUserGesture(); |
abarth@webkit.org | 41c9344 | 2010-10-18 02:59:32 +0000 | [diff] [blame] | 173 | } |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 174 | |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame] | 175 | bool shouldStartTimer(Frame& frame) override |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 176 | { |
| 177 | return frame.loader().allAncestorsAreComplete(); |
| 178 | } |
robert@webkit.org | 5201983 | 2011-07-03 20:34:14 +0000 | [diff] [blame] | 179 | |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame] | 180 | void fire(Frame& frame) override |
robert@webkit.org | 5201983 | 2011-07-03 20:34:14 +0000 | [diff] [blame] | 181 | { |
dbates@webkit.org | 174ac71 | 2017-06-30 21:35:23 +0000 | [diff] [blame] | 182 | UserGestureIndicator gestureIndicator { userGestureToForward() }; |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 183 | |
dbates@webkit.org | 174ac71 | 2017-06-30 21:35:23 +0000 | [diff] [blame] | 184 | bool refresh = equalIgnoringFragmentIdentifier(frame.document()->url(), url()); |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 185 | ResourceRequest resourceRequest { url(), referrer(), refresh ? ResourceRequestCachePolicy::ReloadIgnoringCacheData : ResourceRequestCachePolicy::UseProtocolCachePolicy }; |
bfulgham@apple.com | e89a320 | 2018-04-25 19:16:00 +0000 | [diff] [blame] | 186 | if (initiatedByMainFrame() == InitiatedByMainFrame::Yes) |
| 187 | resourceRequest.setRequester(ResourceRequest::Requester::Main); |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 188 | FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() }; |
dbates@webkit.org | 174ac71 | 2017-06-30 21:35:23 +0000 | [diff] [blame] | 189 | |
commit-queue@webkit.org | 79b7c91 | 2017-08-31 21:26:24 +0000 | [diff] [blame] | 190 | frame.loader().changeLocation(WTFMove(frameLoadRequest)); |
robert@webkit.org | 5201983 | 2011-07-03 20:34:14 +0000 | [diff] [blame] | 191 | } |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 192 | }; |
| 193 | |
| 194 | class ScheduledLocationChange : public ScheduledURLNavigation { |
| 195 | public: |
cdumez@apple.com | e3df2df | 2019-05-02 22:24:27 +0000 | [diff] [blame] | 196 | ScheduledLocationChange(Document& initiatingDocument, SecurityOrigin* securityOrigin, const URL& url, const String& referrer, LockHistory lockHistory, LockBackForwardList lockBackForwardList, bool duringLoad, CompletionHandler<void()>&& completionHandler) |
| 197 | : ScheduledURLNavigation(initiatingDocument, 0.0, securityOrigin, url, referrer, lockHistory, lockBackForwardList, duringLoad, true) |
| 198 | , m_completionHandler(WTFMove(completionHandler)) |
| 199 | { |
| 200 | } |
| 201 | |
| 202 | ~ScheduledLocationChange() |
| 203 | { |
| 204 | if (m_completionHandler) |
| 205 | m_completionHandler(); |
| 206 | } |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 207 | |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame] | 208 | void fire(Frame& frame) override |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 209 | { |
dbates@webkit.org | 174ac71 | 2017-06-30 21:35:23 +0000 | [diff] [blame] | 210 | UserGestureIndicator gestureIndicator { userGestureToForward() }; |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 211 | |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 212 | ResourceRequest resourceRequest { url(), referrer(), ResourceRequestCachePolicy::UseProtocolCachePolicy }; |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 213 | FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() }; |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 214 | |
cdumez@apple.com | e3df2df | 2019-05-02 22:24:27 +0000 | [diff] [blame] | 215 | auto completionHandler = WTFMove(m_completionHandler); |
commit-queue@webkit.org | 79b7c91 | 2017-08-31 21:26:24 +0000 | [diff] [blame] | 216 | frame.loader().changeLocation(WTFMove(frameLoadRequest)); |
cdumez@apple.com | e3df2df | 2019-05-02 22:24:27 +0000 | [diff] [blame] | 217 | completionHandler(); |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 218 | } |
cdumez@apple.com | e3df2df | 2019-05-02 22:24:27 +0000 | [diff] [blame] | 219 | |
| 220 | private: |
| 221 | CompletionHandler<void()> m_completionHandler; |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | class ScheduledRefresh : public ScheduledURLNavigation { |
| 225 | public: |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 226 | ScheduledRefresh(Document& initiatingDocument, SecurityOrigin* securityOrigin, const URL& url, const String& referrer) |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 227 | : ScheduledURLNavigation(initiatingDocument, 0.0, securityOrigin, url, referrer, LockHistory::Yes, LockBackForwardList::Yes, false, true) |
abarth@webkit.org | 41c9344 | 2010-10-18 02:59:32 +0000 | [diff] [blame] | 228 | { |
| 229 | } |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 230 | |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame] | 231 | void fire(Frame& frame) override |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 232 | { |
dbates@webkit.org | 174ac71 | 2017-06-30 21:35:23 +0000 | [diff] [blame] | 233 | UserGestureIndicator gestureIndicator { userGestureToForward() }; |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 234 | |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 235 | ResourceRequest resourceRequest { url(), referrer(), ResourceRequestCachePolicy::ReloadIgnoringCacheData }; |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 236 | FrameLoadRequest frameLoadRequest { initiatingDocument(), *securityOrigin(), resourceRequest, "_self", lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() }; |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 237 | |
dbates@webkit.org | 174ac71 | 2017-06-30 21:35:23 +0000 | [diff] [blame] | 238 | frame.loader().changeLocation(WTFMove(frameLoadRequest)); |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 239 | } |
| 240 | }; |
| 241 | |
| 242 | class ScheduledHistoryNavigation : public ScheduledNavigation { |
| 243 | public: |
abarth@webkit.org | 41c9344 | 2010-10-18 02:59:32 +0000 | [diff] [blame] | 244 | explicit ScheduledHistoryNavigation(int historySteps) |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 245 | : ScheduledNavigation(0, LockHistory::No, LockBackForwardList::No, false, true) |
abarth@webkit.org | 41c9344 | 2010-10-18 02:59:32 +0000 | [diff] [blame] | 246 | , m_historySteps(historySteps) |
| 247 | { |
| 248 | } |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 249 | |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame] | 250 | void fire(Frame& frame) override |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 251 | { |
weinig@apple.com | 2e10e10 | 2016-07-18 01:07:11 +0000 | [diff] [blame] | 252 | UserGestureIndicator gestureIndicator(userGestureToForward()); |
inferno@chromium.org | 1930aab | 2010-09-17 16:36:53 +0000 | [diff] [blame] | 253 | |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 254 | if (!m_historySteps) { |
| 255 | // Special case for go(0) from a frame -> reload only the frame |
inferno@chromium.org | 1930aab | 2010-09-17 16:36:53 +0000 | [diff] [blame] | 256 | // To follow Firefox and IE's behavior, history reload can only navigate the self frame. |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 257 | frame.loader().urlSelected(frame.document()->url(), "_self", 0, lockHistory(), lockBackForwardList(), MaybeSendReferrer, shouldOpenExternalURLs()); |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 258 | return; |
| 259 | } |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 260 | |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 261 | // go(i!=0) from a frame navigates into the history of the frame only, |
| 262 | // in both IE and NS (but not in Mozilla). We can't easily do that. |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 263 | frame.page()->backForward().goBackOrForward(m_historySteps); |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | private: |
| 267 | int m_historySteps; |
| 268 | }; |
| 269 | |
| 270 | class ScheduledFormSubmission : public ScheduledNavigation { |
| 271 | public: |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 272 | ScheduledFormSubmission(Ref<FormSubmission>&& submission, LockBackForwardList lockBackForwardList, bool duringLoad) |
| 273 | : ScheduledNavigation(0, submission->lockHistory(), lockBackForwardList, duringLoad, true, submission->state().sourceDocument().shouldOpenExternalURLsPolicyToPropagate()) |
| 274 | , m_submission(WTFMove(submission)) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 275 | { |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 276 | } |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 277 | |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame] | 278 | void fire(Frame& frame) override |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 279 | { |
cdumez@apple.com | ede5bd3 | 2019-12-20 00:28:57 +0000 | [diff] [blame] | 280 | if (m_submission->wasCancelled()) |
| 281 | return; |
| 282 | |
weinig@apple.com | 2e10e10 | 2016-07-18 01:07:11 +0000 | [diff] [blame] | 283 | UserGestureIndicator gestureIndicator(userGestureToForward()); |
commit-queue@webkit.org | 572a9b6 | 2010-09-03 18:21:29 +0000 | [diff] [blame] | 284 | |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 285 | // The submitForm function will find a target frame before using the redirection timer. |
| 286 | // Now that the timer has fired, we need to repeat the security check which normally is done when |
| 287 | // selecting a target, in case conditions have changed. Other code paths avoid this by targeting |
| 288 | // without leaving a time window. If we fail the check just silently drop the form submission. |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 289 | auto& requestingDocument = m_submission->state().sourceDocument(); |
| 290 | if (!requestingDocument.canNavigate(&frame)) |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 291 | return; |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 292 | FrameLoadRequest frameLoadRequest { requestingDocument, requestingDocument.securityOrigin(), { }, { }, lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() }; |
dbates@webkit.org | b8a43fd | 2017-06-21 21:19:05 +0000 | [diff] [blame] | 293 | m_submission->populateFrameLoadRequest(frameLoadRequest); |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 294 | frame.loader().loadFrameRequest(WTFMove(frameLoadRequest), m_submission->event(), m_submission->takeState()); |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 295 | } |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 296 | |
darin@apple.com | 11ff47c | 2016-03-04 16:47:55 +0000 | [diff] [blame] | 297 | void didStartTimer(Frame& frame, Timer& timer) override |
commit-queue@webkit.org | 4cbfdfd | 2010-08-13 23:35:34 +0000 | [diff] [blame] | 298 | { |
| 299 | if (m_haveToldClient) |
| 300 | return; |
| 301 | m_haveToldClient = true; |
commit-queue@webkit.org | 88c74ba | 2011-05-07 23:37:35 +0000 | [diff] [blame] | 302 | |
weinig@apple.com | 2e10e10 | 2016-07-18 01:07:11 +0000 | [diff] [blame] | 303 | UserGestureIndicator gestureIndicator(userGestureToForward()); |
utatane.tea@gmail.com | eb3a809 | 2018-02-23 04:18:17 +0000 | [diff] [blame] | 304 | frame.loader().clientRedirected(m_submission->requestURL(), delay(), WallTime::now() + timer.nextFireInterval(), lockBackForwardList()); |
commit-queue@webkit.org | 4cbfdfd | 2010-08-13 23:35:34 +0000 | [diff] [blame] | 305 | } |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 306 | |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 307 | void didStopTimer(Frame& frame, NewLoadInProgress newLoadInProgress) override |
commit-queue@webkit.org | 4cbfdfd | 2010-08-13 23:35:34 +0000 | [diff] [blame] | 308 | { |
| 309 | if (!m_haveToldClient) |
| 310 | return; |
commit-queue@webkit.org | 88c74ba | 2011-05-07 23:37:35 +0000 | [diff] [blame] | 311 | |
| 312 | // Do not set a UserGestureIndicator because |
| 313 | // clientRedirectCancelledOrFinished() is also called from many places |
| 314 | // inside FrameLoader, where the gesture state is not set and is in |
| 315 | // fact unavailable. We need to be consistent with them, otherwise the |
| 316 | // gesture state will sometimes be set and sometimes not within |
| 317 | // dispatchDidCancelClientRedirect(). |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 318 | frame.loader().clientRedirectCancelledOrFinished(newLoadInProgress); |
commit-queue@webkit.org | 4cbfdfd | 2010-08-13 23:35:34 +0000 | [diff] [blame] | 319 | } |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 320 | |
| 321 | private: |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 322 | Ref<FormSubmission> m_submission; |
| 323 | bool m_haveToldClient { false }; |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 324 | }; |
| 325 | |
dbates@webkit.org | db7c48d | 2016-01-12 22:28:59 +0000 | [diff] [blame] | 326 | class ScheduledPageBlock final : public ScheduledNavigation { |
| 327 | public: |
| 328 | ScheduledPageBlock(Document& originDocument) |
| 329 | : ScheduledNavigation(0, LockHistory::Yes, LockBackForwardList::Yes, false, false) |
| 330 | , m_originDocument(originDocument) |
| 331 | { |
| 332 | } |
| 333 | |
| 334 | void fire(Frame& frame) override |
| 335 | { |
dbates@webkit.org | 174ac71 | 2017-06-30 21:35:23 +0000 | [diff] [blame] | 336 | UserGestureIndicator gestureIndicator { userGestureToForward() }; |
dbates@webkit.org | db7c48d | 2016-01-12 22:28:59 +0000 | [diff] [blame] | 337 | |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 338 | ResourceResponse replacementResponse { m_originDocument.url(), "text/plain"_s, 0, "UTF-8"_s }; |
dbates@webkit.org | 174ac71 | 2017-06-30 21:35:23 +0000 | [diff] [blame] | 339 | SubstituteData replacementData { SharedBuffer::create(), m_originDocument.url(), replacementResponse, SubstituteData::SessionHistoryVisibility::Hidden }; |
dbates@webkit.org | db7c48d | 2016-01-12 22:28:59 +0000 | [diff] [blame] | 340 | |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 341 | ResourceRequest resourceRequest { m_originDocument.url(), emptyString(), ResourceRequestCachePolicy::ReloadIgnoringCacheData }; |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 342 | FrameLoadRequest frameLoadRequest { m_originDocument, m_originDocument.securityOrigin(), resourceRequest, { }, lockHistory(), lockBackForwardList(), MaybeSendReferrer, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Allow, shouldOpenExternalURLs(), initiatedByMainFrame() }; |
dbates@webkit.org | b8a43fd | 2017-06-21 21:19:05 +0000 | [diff] [blame] | 343 | frameLoadRequest.setSubstituteData(replacementData); |
dbates@webkit.org | 7f3a982 | 2017-06-22 19:45:10 +0000 | [diff] [blame] | 344 | frame.loader().load(WTFMove(frameLoadRequest)); |
dbates@webkit.org | db7c48d | 2016-01-12 22:28:59 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | private: |
| 348 | Document& m_originDocument; |
| 349 | }; |
| 350 | |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 351 | NavigationScheduler::NavigationScheduler(Frame& frame) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 352 | : m_frame(frame) |
andersca@apple.com | 574a745 | 2014-11-21 20:10:13 +0000 | [diff] [blame] | 353 | , m_timer(*this, &NavigationScheduler::timerFired) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 354 | { |
| 355 | } |
| 356 | |
dbates@webkit.org | f21f3ae | 2017-10-19 23:48:45 +0000 | [diff] [blame] | 357 | NavigationScheduler::~NavigationScheduler() = default; |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 358 | |
abarth@webkit.org | 88b4e6b | 2010-10-04 22:09:57 +0000 | [diff] [blame] | 359 | bool NavigationScheduler::redirectScheduledDuringLoad() |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 360 | { |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 361 | return m_redirect && m_redirect->wasDuringLoad(); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 362 | } |
| 363 | |
abarth@webkit.org | 88b4e6b | 2010-10-04 22:09:57 +0000 | [diff] [blame] | 364 | bool NavigationScheduler::locationChangePending() |
weinig@apple.com | e2b2876 | 2010-05-12 23:21:59 +0000 | [diff] [blame] | 365 | { |
| 366 | return m_redirect && m_redirect->isLocationChange(); |
| 367 | } |
| 368 | |
abarth@webkit.org | 88b4e6b | 2010-10-04 22:09:57 +0000 | [diff] [blame] | 369 | void NavigationScheduler::clear() |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 370 | { |
commit-queue@webkit.org | daffe2f | 2013-01-24 05:42:33 +0000 | [diff] [blame] | 371 | if (m_timer.isActive()) |
| 372 | InspectorInstrumentation::frameClearedScheduledNavigation(m_frame); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 373 | m_timer.stop(); |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 374 | m_redirect = nullptr; |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 375 | } |
| 376 | |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 377 | inline bool NavigationScheduler::shouldScheduleNavigation() const |
| 378 | { |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 379 | return m_frame.page(); |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 380 | } |
| 381 | |
darin@apple.com | 47a20cb | 2014-04-27 16:06:27 +0000 | [diff] [blame] | 382 | inline bool NavigationScheduler::shouldScheduleNavigation(const URL& url) const |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 383 | { |
darin@apple.com | 47a20cb | 2014-04-27 16:06:27 +0000 | [diff] [blame] | 384 | if (!shouldScheduleNavigation()) |
| 385 | return false; |
keith_miller@apple.com | bb2f61c | 2018-12-01 03:28:36 +0000 | [diff] [blame] | 386 | if (WTF::protocolIsJavaScript(url)) |
darin@apple.com | 47a20cb | 2014-04-27 16:06:27 +0000 | [diff] [blame] | 387 | return true; |
rniwa@webkit.org | f694bd6 | 2017-06-30 19:32:41 +0000 | [diff] [blame] | 388 | return NavigationDisabler::isNavigationAllowed(m_frame); |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 389 | } |
| 390 | |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 391 | void NavigationScheduler::scheduleRedirect(Document& initiatingDocument, double delay, const URL& url) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 392 | { |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 393 | if (!shouldScheduleNavigation(url)) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 394 | return; |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 395 | if (delay < 0 || delay > INT_MAX / 1000) |
| 396 | return; |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 397 | if (url.isEmpty()) |
| 398 | return; |
| 399 | |
commit-queue@webkit.org | 4cbfdfd | 2010-08-13 23:35:34 +0000 | [diff] [blame] | 400 | // We want a new back/forward list item if the refresh timeout is > 1 second. |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 401 | if (!m_redirect || delay <= m_redirect->delay()) { |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 402 | auto lockBackForwardList = delay <= 1 ? LockBackForwardList::Yes : LockBackForwardList::No; |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 403 | schedule(makeUnique<ScheduledRedirect>(initiatingDocument, delay, &m_frame.document()->securityOrigin(), url, LockHistory::Yes, lockBackForwardList)); |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 404 | } |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 405 | } |
| 406 | |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 407 | LockBackForwardList NavigationScheduler::mustLockBackForwardList(Frame& targetFrame) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 408 | { |
commit-queue@webkit.org | 2ca2f77 | 2010-08-17 23:40:00 +0000 | [diff] [blame] | 409 | // Non-user navigation before the page has finished firing onload should not create a new back/forward item. |
commit-queue@webkit.org | 4cbfdfd | 2010-08-13 23:35:34 +0000 | [diff] [blame] | 410 | // See https://webkit.org/b/42861 for the original motivation for this. |
weinig@apple.com | 2e10e10 | 2016-07-18 01:07:11 +0000 | [diff] [blame] | 411 | if (!UserGestureIndicator::processingUserGesture() && targetFrame.loader().documentLoader() && !targetFrame.loader().documentLoader()->wasOnloadDispatched()) |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 412 | return LockBackForwardList::Yes; |
commit-queue@webkit.org | 4cbfdfd | 2010-08-13 23:35:34 +0000 | [diff] [blame] | 413 | |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 414 | // Navigation of a subframe during loading of an ancestor frame does not create a new back/forward item. |
| 415 | // The definition of "during load" is any time before all handlers for the load event have been run. |
| 416 | // See https://bugs.webkit.org/show_bug.cgi?id=14957 for the original motivation for this. |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 417 | for (Frame* ancestor = targetFrame.tree().parent(); ancestor; ancestor = ancestor->tree().parent()) { |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 418 | Document* document = ancestor->document(); |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 419 | if (!ancestor->loader().isComplete() || (document && document->processingLoadEvent())) |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 420 | return LockBackForwardList::Yes; |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 421 | } |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 422 | return LockBackForwardList::No; |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 423 | } |
| 424 | |
cdumez@apple.com | e3df2df | 2019-05-02 22:24:27 +0000 | [diff] [blame] | 425 | void NavigationScheduler::scheduleLocationChange(Document& initiatingDocument, SecurityOrigin& securityOrigin, const URL& url, const String& referrer, LockHistory lockHistory, LockBackForwardList lockBackForwardList, CompletionHandler<void()>&& completionHandler) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 426 | { |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 427 | if (!shouldScheduleNavigation(url)) |
cdumez@apple.com | e3df2df | 2019-05-02 22:24:27 +0000 | [diff] [blame] | 428 | return completionHandler(); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 429 | |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 430 | if (lockBackForwardList == LockBackForwardList::No) |
| 431 | lockBackForwardList = mustLockBackForwardList(m_frame); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 432 | |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 433 | FrameLoader& loader = m_frame.loader(); |
eric@webkit.org | 818318b | 2011-06-16 23:15:10 +0000 | [diff] [blame] | 434 | |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 435 | // If the URL we're going to navigate to is the same as the current one, except for the |
| 436 | // fragment part, we don't need to schedule the location change. |
darin@apple.com | 610f27d | 2015-04-13 15:40:42 +0000 | [diff] [blame] | 437 | if (url.hasFragmentIdentifier() && equalIgnoringFragmentIdentifier(m_frame.document()->url(), url)) { |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 438 | ResourceRequest resourceRequest { m_frame.document()->completeURL(url), referrer, ResourceRequestCachePolicy::UseProtocolCachePolicy }; |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 439 | auto* frame = lexicalFrameFromCommonVM(); |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 440 | auto initiatedByMainFrame = frame && frame->isMainFrame() ? InitiatedByMainFrame::Yes : InitiatedByMainFrame::Unknown; |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 441 | |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 442 | FrameLoadRequest frameLoadRequest { initiatingDocument, securityOrigin, resourceRequest, "_self"_s, lockHistory, lockBackForwardList, MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, initiatingDocument.shouldOpenExternalURLsPolicyToPropagate(), initiatedByMainFrame }; |
dbates@webkit.org | 7f3a982 | 2017-06-22 19:45:10 +0000 | [diff] [blame] | 443 | loader.changeLocation(WTFMove(frameLoadRequest)); |
cdumez@apple.com | e3df2df | 2019-05-02 22:24:27 +0000 | [diff] [blame] | 444 | return completionHandler(); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | // Handle a location change of a page with no document as a special case. |
| 448 | // This may happen when a frame changes the location of another frame. |
akling@apple.com | 63e53cb | 2014-02-05 20:42:37 +0000 | [diff] [blame] | 449 | bool duringLoad = !loader.stateMachine().committedFirstRealDocumentLoad(); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 450 | |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 451 | schedule(makeUnique<ScheduledLocationChange>(initiatingDocument, &securityOrigin, url, referrer, lockHistory, lockBackForwardList, duringLoad, WTFMove(completionHandler))); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 452 | } |
| 453 | |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 454 | void NavigationScheduler::scheduleFormSubmission(Ref<FormSubmission>&& submission) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 455 | { |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 456 | ASSERT(m_frame.page()); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 457 | |
| 458 | // FIXME: Do we need special handling for form submissions where the URL is the same |
| 459 | // as the current one except for the fragment part? See scheduleLocationChange above. |
| 460 | |
| 461 | // Handle a location change of a page with no document as a special case. |
| 462 | // This may happen when a frame changes the location of another frame. |
akling@apple.com | 63e53cb | 2014-02-05 20:42:37 +0000 | [diff] [blame] | 463 | bool duringLoad = !m_frame.loader().stateMachine().committedFirstRealDocumentLoad(); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 464 | |
beidson@apple.com | 1117ef4 | 2009-12-12 01:34:17 +0000 | [diff] [blame] | 465 | // If this is a child frame and the form submission was triggered by a script, lock the back/forward list |
| 466 | // to match IE and Opera. |
| 467 | // See https://bugs.webkit.org/show_bug.cgi?id=32383 for the original motivation for this. |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 468 | LockBackForwardList lockBackForwardList = mustLockBackForwardList(m_frame); |
| 469 | if (lockBackForwardList == LockBackForwardList::No |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 470 | && (submission->state().formSubmissionTrigger() == SubmittedByJavaScript && m_frame.tree().parent() && !UserGestureIndicator::processingUserGesture())) { |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 471 | lockBackForwardList = LockBackForwardList::Yes; |
| 472 | } |
| 473 | |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 474 | schedule(makeUnique<ScheduledFormSubmission>(WTFMove(submission), lockBackForwardList, duringLoad)); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 475 | } |
| 476 | |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 477 | void NavigationScheduler::scheduleRefresh(Document& initiatingDocument) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 478 | { |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 479 | if (!shouldScheduleNavigation()) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 480 | return; |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 481 | const URL& url = m_frame.document()->url(); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 482 | if (url.isEmpty()) |
| 483 | return; |
| 484 | |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 485 | schedule(makeUnique<ScheduledRefresh>(initiatingDocument, &m_frame.document()->securityOrigin(), url, m_frame.loader().outgoingReferrer())); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 486 | } |
| 487 | |
abarth@webkit.org | 88b4e6b | 2010-10-04 22:09:57 +0000 | [diff] [blame] | 488 | void NavigationScheduler::scheduleHistoryNavigation(int steps) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 489 | { |
simon.fraser@apple.com | 7828786 | 2017-02-13 22:53:46 +0000 | [diff] [blame] | 490 | LOG(History, "NavigationScheduler %p scheduleHistoryNavigation(%d) - shouldSchedule %d", this, steps, shouldScheduleNavigation()); |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 491 | if (!shouldScheduleNavigation()) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 492 | return; |
| 493 | |
beidson@apple.com | aca909e | 2009-10-26 23:20:25 +0000 | [diff] [blame] | 494 | // Invalid history navigations (such as history.forward() during a new load) have the side effect of cancelling any scheduled |
| 495 | // redirects. We also avoid the possibility of cancelling the current load by avoiding the scheduled redirection altogether. |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 496 | BackForwardController& backForward = m_frame.page()->backForward(); |
achristensen@apple.com | 83efad7 | 2018-10-17 20:37:36 +0000 | [diff] [blame] | 497 | if ((steps > 0 && static_cast<unsigned>(steps) > backForward.forwardCount()) |
| 498 | || (steps < 0 && static_cast<unsigned>(-steps) > backForward.backCount())) { |
beidson@apple.com | bf1584a | 2010-01-22 04:22:02 +0000 | [diff] [blame] | 499 | cancel(); |
| 500 | return; |
| 501 | } |
inferno@chromium.org | 1930aab | 2010-09-17 16:36:53 +0000 | [diff] [blame] | 502 | |
beidson@apple.com | bf1584a | 2010-01-22 04:22:02 +0000 | [diff] [blame] | 503 | // In all other cases, schedule the history traversal to occur asynchronously. |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 504 | schedule(makeUnique<ScheduledHistoryNavigation>(steps)); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 505 | } |
| 506 | |
dbates@webkit.org | db7c48d | 2016-01-12 22:28:59 +0000 | [diff] [blame] | 507 | void NavigationScheduler::schedulePageBlock(Document& originDocument) |
| 508 | { |
| 509 | if (shouldScheduleNavigation()) |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 510 | schedule(makeUnique<ScheduledPageBlock>(originDocument)); |
dbates@webkit.org | db7c48d | 2016-01-12 22:28:59 +0000 | [diff] [blame] | 511 | } |
| 512 | |
andersca@apple.com | 574a745 | 2014-11-21 20:10:13 +0000 | [diff] [blame] | 513 | void NavigationScheduler::timerFired() |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 514 | { |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 515 | if (!m_frame.page()) |
eric@webkit.org | 3c52102 | 2009-10-29 00:22:14 +0000 | [diff] [blame] | 516 | return; |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 517 | if (m_frame.page()->defersLoading()) { |
commit-queue@webkit.org | daffe2f | 2013-01-24 05:42:33 +0000 | [diff] [blame] | 518 | InspectorInstrumentation::frameClearedScheduledNavigation(m_frame); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 519 | return; |
commit-queue@webkit.org | daffe2f | 2013-01-24 05:42:33 +0000 | [diff] [blame] | 520 | } |
| 521 | |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 522 | Ref<Frame> protect(m_frame); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 523 | |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 524 | std::unique_ptr<ScheduledNavigation> redirect = WTFMove(m_redirect); |
simon.fraser@apple.com | 7828786 | 2017-02-13 22:53:46 +0000 | [diff] [blame] | 525 | LOG(History, "NavigationScheduler %p timerFired - firing redirect %p", this, redirect.get()); |
| 526 | |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 527 | redirect->fire(m_frame); |
commit-queue@webkit.org | daffe2f | 2013-01-24 05:42:33 +0000 | [diff] [blame] | 528 | InspectorInstrumentation::frameClearedScheduledNavigation(m_frame); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 529 | } |
| 530 | |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 531 | void NavigationScheduler::schedule(std::unique_ptr<ScheduledNavigation> redirect) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 532 | { |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 533 | ASSERT(m_frame.page()); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 534 | |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 535 | Ref<Frame> protect(m_frame); |
inferno@chromium.org | 01ee2a2 | 2012-02-14 21:02:36 +0000 | [diff] [blame] | 536 | |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 537 | // If a redirect was scheduled during a load, then stop the current load. |
| 538 | // Otherwise when the current load transitions from a provisional to a |
| 539 | // committed state, pending redirects may be cancelled. |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 540 | if (redirect->wasDuringLoad()) { |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 541 | if (DocumentLoader* provisionalDocumentLoader = m_frame.loader().provisionalDocumentLoader()) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 542 | provisionalDocumentLoader->stopLoading(); |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 543 | m_frame.loader().stopLoading(UnloadEventPolicyUnloadAndPageHide); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | cancel(); |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 547 | m_redirect = WTFMove(redirect); |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 548 | |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 549 | if (!m_frame.loader().isComplete() && m_redirect->isLocationChange()) |
| 550 | m_frame.loader().completed(); |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 551 | |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 552 | if (!m_frame.page()) |
inferno@chromium.org | 01ee2a2 | 2012-02-14 21:02:36 +0000 | [diff] [blame] | 553 | return; |
| 554 | |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 555 | startTimer(); |
| 556 | } |
| 557 | |
abarth@webkit.org | 88b4e6b | 2010-10-04 22:09:57 +0000 | [diff] [blame] | 558 | void NavigationScheduler::startTimer() |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 559 | { |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 560 | if (!m_redirect) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 561 | return; |
| 562 | |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 563 | ASSERT(m_frame.page()); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 564 | if (m_timer.isActive()) |
| 565 | return; |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 566 | if (!m_redirect->shouldStartTimer(m_frame)) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 567 | return; |
| 568 | |
cdumez@apple.com | 7d7fe74a | 2017-04-10 08:02:21 +0000 | [diff] [blame] | 569 | Seconds delay = 1_s * m_redirect->delay(); |
dbates@webkit.org | dbb6952 | 2013-10-24 21:40:55 +0000 | [diff] [blame] | 570 | m_timer.startOneShot(delay); |
| 571 | InspectorInstrumentation::frameScheduledNavigation(m_frame, delay); |
andersca@apple.com | 8a45886 | 2014-01-11 00:38:16 +0000 | [diff] [blame] | 572 | m_redirect->didStartTimer(m_frame, m_timer); // m_redirect may be null on return (e.g. the client canceled the load) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 573 | } |
| 574 | |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 575 | void NavigationScheduler::cancel(NewLoadInProgress newLoadInProgress) |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 576 | { |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 577 | LOG(History, "NavigationScheduler %p cancel(newLoadInProgress=%d)", this, newLoadInProgress == NewLoadInProgress::Yes); |
simon.fraser@apple.com | 7828786 | 2017-02-13 22:53:46 +0000 | [diff] [blame] | 578 | |
commit-queue@webkit.org | daffe2f | 2013-01-24 05:42:33 +0000 | [diff] [blame] | 579 | if (m_timer.isActive()) |
| 580 | InspectorInstrumentation::frameClearedScheduledNavigation(m_frame); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 581 | m_timer.stop(); |
| 582 | |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 583 | if (auto redirect = WTFMove(m_redirect)) |
eric@webkit.org | 9b31e48 | 2010-03-31 23:22:23 +0000 | [diff] [blame] | 584 | redirect->didStopTimer(m_frame, newLoadInProgress); |
abarth@webkit.org | 450089a | 2009-10-02 08:03:35 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | } // namespace WebCore |