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