darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 1 | /* |
bfulgham@apple.com | 2187dd5 | 2020-06-10 23:11:41 +0000 | [diff] [blame] | 2 | * Copyright (C) 2006-2020 Apple Inc. All rights reserved. |
hausmann@webkit.org | f696447 | 2008-09-29 12:47:08 +0000 | [diff] [blame] | 3 | * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
staikos@webkit.org | 159f11f | 2009-05-18 23:48:30 +0000 | [diff] [blame] | 4 | * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
staikos@webkit.org | c769212 | 2009-10-28 18:12:34 +0000 | [diff] [blame] | 5 | * Copyright (C) 2008 Alp Toker <alp@atoker.com> |
| 6 | * Copyright (C) Research In Motion Limited 2009. All rights reserved. |
commit-queue@webkit.org | ff400aa | 2011-03-10 23:43:48 +0000 | [diff] [blame] | 7 | * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> |
commit-queue@webkit.org | 343b8a6 | 2011-09-21 01:49:03 +0000 | [diff] [blame] | 8 | * Copyright (C) 2011 Google Inc. All rights reserved. |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions |
| 12 | * are met: |
| 13 | * |
| 14 | * 1. Redistributions of source code must retain the above copyright |
joepeck@webkit.org | 6d6a47c | 2014-03-06 19:33:51 +0000 | [diff] [blame] | 15 | * notice, this list of conditions and the following disclaimer. |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 16 | * 2. Redistributions in binary form must reproduce the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer in the |
joepeck@webkit.org | 6d6a47c | 2014-03-06 19:33:51 +0000 | [diff] [blame] | 18 | * documentation and/or other materials provided with the distribution. |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 19 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 20 | * its contributors may be used to endorse or promote products derived |
joepeck@webkit.org | 6d6a47c | 2014-03-06 19:33:51 +0000 | [diff] [blame] | 21 | * from this software without specific prior written permission. |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 24 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 25 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 26 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 27 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 28 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 30 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | */ |
| 34 | |
darin | c111655 | 2006-10-30 20:05:39 +0000 | [diff] [blame] | 35 | #include "config.h" |
| 36 | #include "FrameLoader.h" |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 37 | |
mario@webkit.org | 685258f | 2011-12-06 00:10:55 +0000 | [diff] [blame] | 38 | #include "AXObjectCache.h" |
darin@chromium.org | df43753 | 2009-08-05 00:18:28 +0000 | [diff] [blame] | 39 | #include "ApplicationCacheHost.h" |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 40 | #include "BackForwardCache.h" |
darin@apple.com | e10e128 | 2010-10-30 00:44:33 +0000 | [diff] [blame] | 41 | #include "BackForwardController.h" |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 42 | #include "BeforeUnloadEvent.h" |
beidson | 448a6e7 | 2007-04-10 23:55:56 +0000 | [diff] [blame] | 43 | #include "CachedPage.h" |
darin@apple.com | e10e128 | 2010-10-30 00:44:33 +0000 | [diff] [blame] | 44 | #include "CachedResourceLoader.h" |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 45 | #include "Chrome.h" |
commit-queue@webkit.org | 52b6833 | 2011-06-07 16:20:07 +0000 | [diff] [blame] | 46 | #include "ChromeClient.h" |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 47 | #include "CommonVM.h" |
aestes@apple.com | 176a9aa | 2016-07-08 20:14:34 +0000 | [diff] [blame] | 48 | #include "ContentFilter.h" |
achristensen@apple.com | d3edc2a | 2019-03-21 20:23:46 +0000 | [diff] [blame] | 49 | #include "ContentRuleListResults.h" |
abarth@webkit.org | f921dee | 2011-03-26 11:59:34 +0000 | [diff] [blame] | 50 | #include "ContentSecurityPolicy.h" |
aroben@apple.com | 92cfa90 | 2008-04-16 19:19:00 +0000 | [diff] [blame] | 51 | #include "DOMWindow.h" |
mark.lam@apple.com | 45beb07 | 2012-12-12 23:04:20 +0000 | [diff] [blame] | 52 | #include "DatabaseManager.h" |
jer.noble@apple.com | 9e0f060 | 2014-11-22 05:27:16 +0000 | [diff] [blame] | 53 | #include "DiagnosticLoggingClient.h" |
eric.carlson@apple.com | 77b4a11 | 2014-10-30 19:04:29 +0000 | [diff] [blame] | 54 | #include "DiagnosticLoggingKeys.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 55 | #include "Document.h" |
darin | c111655 | 2006-10-30 20:05:39 +0000 | [diff] [blame] | 56 | #include "DocumentLoader.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 57 | #include "Editor.h" |
andersca | f623201 | 2006-11-15 00:36:50 +0000 | [diff] [blame] | 58 | #include "EditorClient.h" |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 59 | #include "Element.h" |
darin | f1bb004 | 2006-12-01 22:46:21 +0000 | [diff] [blame] | 60 | #include "Event.h" |
weinig@apple.com | 13d777f | 2013-04-16 21:54:22 +0000 | [diff] [blame] | 61 | #include "EventHandler.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 62 | #include "EventNames.h" |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 63 | #include "FloatRect.h" |
darin | c111655 | 2006-10-30 20:05:39 +0000 | [diff] [blame] | 64 | #include "FormState.h" |
dglazkov@chromium.org | 25a57e5 | 2010-06-20 21:00:35 +0000 | [diff] [blame] | 65 | #include "FormSubmission.h" |
cdumez@apple.com | c518f7e | 2018-04-03 18:01:41 +0000 | [diff] [blame] | 66 | #include "Frame.h" |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 67 | #include "FrameLoadRequest.h" |
| 68 | #include "FrameLoaderClient.h" |
diegohcg@webkit.org | 838e0a2 | 2010-09-04 14:48:30 +0000 | [diff] [blame] | 69 | #include "FrameNetworkingContext.h" |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 70 | #include "FrameTree.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 71 | #include "FrameView.h" |
akling@apple.com | af7f33b | 2016-02-06 17:00:30 +0000 | [diff] [blame] | 72 | #include "GCController.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 73 | #include "HTMLFormElement.h" |
commit-queue@webkit.org | e5739ca | 2012-11-15 19:39:50 +0000 | [diff] [blame] | 74 | #include "HTMLInputElement.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 75 | #include "HTMLNames.h" |
| 76 | #include "HTMLObjectElement.h" |
commit-queue@webkit.org | 26a3a09 | 2012-10-18 19:53:58 +0000 | [diff] [blame] | 77 | #include "HTMLParserIdioms.h" |
andersca@apple.com | a96cf71 | 2014-06-14 17:49:44 +0000 | [diff] [blame] | 78 | #include "HTTPHeaderNames.h" |
commit-queue@webkit.org | f1fbce6 | 2020-01-01 11:25:53 +0000 | [diff] [blame] | 79 | #include "HTTPHeaderValues.h" |
ap | e9991d5 | 2006-12-08 18:19:51 +0000 | [diff] [blame] | 80 | #include "HTTPParsers.h" |
andersca@apple.com | 9b9d83b | 2013-04-10 19:11:20 +0000 | [diff] [blame] | 81 | #include "HistoryController.h" |
weinig | 62f94be | 2007-07-18 20:37:20 +0000 | [diff] [blame] | 82 | #include "HistoryItem.h" |
cdumez@apple.com | 8b478c6 | 2016-01-23 01:04:59 +0000 | [diff] [blame] | 83 | #include "IgnoreOpensDuringUnloadCountIncrementer.h" |
commit-queue@webkit.org | 4c49a66 | 2011-01-02 22:27:10 +0000 | [diff] [blame] | 84 | #include "InspectorController.h" |
yurys@chromium.org | 389a624 | 2011-01-12 13:06:42 +0000 | [diff] [blame] | 85 | #include "InspectorInstrumentation.h" |
yoav@yoav.ws | 1c12d5c | 2017-01-19 07:13:54 +0000 | [diff] [blame] | 86 | #include "LinkLoader.h" |
commit-queue@webkit.org | 3eeac49 | 2016-08-12 22:53:27 +0000 | [diff] [blame] | 87 | #include "LoadTiming.h" |
beidson@apple.com | 0c140b4 | 2013-01-17 00:45:30 +0000 | [diff] [blame] | 88 | #include "LoaderStrategy.h" |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 89 | #include "Logging.h" |
weinig@apple.com | 13d777f | 2013-04-16 21:54:22 +0000 | [diff] [blame] | 90 | #include "MemoryCache.h" |
carlosgc@webkit.org | 32a60dd | 2016-11-10 14:24:26 +0000 | [diff] [blame] | 91 | #include "MemoryRelease.h" |
rniwa@webkit.org | f694bd6 | 2017-06-30 19:32:41 +0000 | [diff] [blame] | 92 | #include "NavigationDisabler.h" |
rniwa@webkit.org | 2c6d4eb | 2017-07-01 21:26:31 +0000 | [diff] [blame] | 93 | #include "NavigationScheduler.h" |
drousso@apple.com | 21748ed | 2018-10-08 18:25:52 +0000 | [diff] [blame] | 94 | #include "Node.h" |
achristensen@apple.com | e594567 | 2016-06-13 21:58:53 +0000 | [diff] [blame] | 95 | #include "Page.h" |
ggaren@apple.com | 521f64b | 2009-09-24 05:53:23 +0000 | [diff] [blame] | 96 | #include "PageTransitionEvent.h" |
akling@apple.com | e6549f4 | 2016-12-01 16:15:27 +0000 | [diff] [blame] | 97 | #include "PerformanceLogging.h" |
beidson@apple.com | 0c140b4 | 2013-01-17 00:45:30 +0000 | [diff] [blame] | 98 | #include "PlatformStrategies.h" |
hausmann@webkit.org | 9999bb8 | 2008-03-10 11:52:27 +0000 | [diff] [blame] | 99 | #include "PluginData.h" |
andersca@apple.com | 641fef9 | 2009-01-06 22:57:25 +0000 | [diff] [blame] | 100 | #include "PluginDocument.h" |
abarth@webkit.org | 401a379 | 2013-03-03 10:12:59 +0000 | [diff] [blame] | 101 | #include "PolicyChecker.h" |
andersca | 2b2c5ce | 2007-01-15 21:55:00 +0000 | [diff] [blame] | 102 | #include "ProgressTracker.h" |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 103 | #include "ResourceHandle.h" |
beidson@apple.com | e3ea01d | 2015-07-02 18:33:23 +0000 | [diff] [blame] | 104 | #include "ResourceLoadInfo.h" |
wilander@apple.com | 63f925f | 2016-10-06 17:40:12 +0000 | [diff] [blame] | 105 | #include "ResourceLoadObserver.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 106 | #include "ResourceRequest.h" |
ossy@webkit.org | 66d8c0a | 2014-02-05 11:42:35 +0000 | [diff] [blame] | 107 | #include "SVGLocatable.h" |
| 108 | #include "SVGNames.h" |
ossy@webkit.org | 66d8c0a | 2014-02-05 11:42:35 +0000 | [diff] [blame] | 109 | #include "SVGViewElement.h" |
| 110 | #include "SVGViewSpec.h" |
weinig@apple.com | 7909900 | 2008-11-21 05:51:28 +0000 | [diff] [blame] | 111 | #include "ScriptController.h" |
darin@chromium.org | 6b41247 | 2008-11-24 23:07:38 +0000 | [diff] [blame] | 112 | #include "ScriptSourceCode.h" |
vsevik@chromium.org | 53bb069 | 2012-01-18 20:59:10 +0000 | [diff] [blame] | 113 | #include "ScrollAnimator.h" |
weinig | e06430a | 2007-10-19 20:53:22 +0000 | [diff] [blame] | 114 | #include "SecurityOrigin.h" |
abarth@webkit.org | eea9066 | 2011-11-09 07:58:49 +0000 | [diff] [blame] | 115 | #include "SecurityPolicy.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 116 | #include "SegmentedString.h" |
yurys@chromium.org | 832b914 | 2010-08-05 12:36:31 +0000 | [diff] [blame] | 117 | #include "SerializedScriptValue.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 118 | #include "Settings.h" |
cdumez@apple.com | fdb8971 | 2018-06-11 20:52:31 +0000 | [diff] [blame] | 119 | #include "ShouldTreatAsContinuingLoad.h" |
rniwa@webkit.org | 77c6570 | 2019-08-13 05:18:11 +0000 | [diff] [blame] | 120 | #include "StyleTreeResolver.h" |
akling@apple.com | 7f81b1e | 2013-09-06 17:23:03 +0000 | [diff] [blame] | 121 | #include "SubframeLoader.h" |
dbates@webkit.org | 3c1f25a | 2018-02-07 18:56:02 +0000 | [diff] [blame] | 122 | #include "SubresourceLoader.h" |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 123 | #include "TextResourceDecoder.h" |
beidson@apple.com | e3ea01d | 2015-07-02 18:33:23 +0000 | [diff] [blame] | 124 | #include "UserContentController.h" |
commit-queue@webkit.org | 635dbdc | 2017-11-23 19:36:08 +0000 | [diff] [blame] | 125 | #include "UserGestureIndicator.h" |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 126 | #include "WindowFeatures.h" |
| 127 | #include "XMLDocumentParser.h" |
commit-queue@webkit.org | 1d99293 | 2018-09-11 17:14:07 +0000 | [diff] [blame] | 128 | #include <dom/ScriptDisallowedScope.h> |
achristensen@apple.com | ce5520e | 2017-09-25 22:33:19 +0000 | [diff] [blame] | 129 | #include <wtf/CompletionHandler.h> |
keith_miller@apple.com | bb2f61c | 2018-12-01 03:28:36 +0000 | [diff] [blame] | 130 | #include <wtf/URL.h> |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 131 | #include <wtf/Ref.h> |
beidson@apple.com | 1c9022b | 2018-03-21 00:05:58 +0000 | [diff] [blame] | 132 | #include <wtf/SetForScope.h> |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 133 | #include <wtf/StdLibExtras.h> |
simon.fraser@apple.com | 83325b9 | 2017-03-17 00:47:16 +0000 | [diff] [blame] | 134 | #include <wtf/SystemTracing.h> |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 135 | #include <wtf/text/CString.h> |
zimmermann@webkit.org | b5e11e6 | 2011-05-16 07:56:06 +0000 | [diff] [blame] | 136 | #include <wtf/text/WTFString.h> |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 137 | |
jcivelli@chromium.org | c2019dd | 2011-05-24 19:32:03 +0000 | [diff] [blame] | 138 | #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
jeremy@chromium.org | c4b86e3 | 2011-02-13 20:28:39 +0000 | [diff] [blame] | 139 | #include "Archive.h" |
jeremy@chromium.org | c4b86e3 | 2011-02-13 20:28:39 +0000 | [diff] [blame] | 140 | #endif |
| 141 | |
enrica@apple.com | 53b08e5 | 2016-01-19 22:58:59 +0000 | [diff] [blame] | 142 | #if ENABLE(DATA_DETECTION) |
| 143 | #include "DataDetection.h" |
| 144 | #endif |
| 145 | |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 146 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 147 | #include "DocumentType.h" |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 148 | #include "ResourceLoader.h" |
cdumez@apple.com | 0b0e88f | 2016-03-06 03:28:54 +0000 | [diff] [blame] | 149 | #include "RuntimeApplicationChecks.h" |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 150 | #endif |
loislo@chromium.org | 82b9dde | 2012-09-12 13:16:31 +0000 | [diff] [blame] | 151 | |
krollin@apple.com | f26b56e | 2020-02-28 19:43:33 +0000 | [diff] [blame] | 152 | #define PAGE_ID ((pageID().valueOr(PageIdentifier())).toUInt64()) |
| 153 | #define FRAME_ID ((frameID().valueOr(FrameIdentifier())).toUInt64()) |
| 154 | #define FRAMELOADER_RELEASE_LOG_IF_ALLOWED(channel, fmt, ...) RELEASE_LOG_IF(isAlwaysOnLoggingAllowed(), channel, "%p - [pageID=%" PRIu64 ", frameID=%" PRIu64 ", main=%d] FrameLoader::" fmt, this, PAGE_ID, FRAME_ID, m_frame.isMainFrame(), ##__VA_ARGS__) |
| 155 | #define FRAMELOADER_RELEASE_LOG_ERROR_IF_ALLOWED(channel, fmt, ...) RELEASE_LOG_IF(isAlwaysOnLoggingAllowed(), channel, "%p - [pageID=%" PRIu64 ", frameID=%" PRIu64 ", main=%d] FrameLoader::" fmt, this, PAGE_ID, FRAME_ID, m_frame.isMainFrame(), ##__VA_ARGS__) |
commit-queue@webkit.org | 6d63522 | 2016-03-08 06:44:59 +0000 | [diff] [blame] | 156 | |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 157 | namespace WebCore { |
| 158 | |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 159 | using namespace HTMLNames; |
oliver | b64e408 | 2007-10-12 13:13:51 +0000 | [diff] [blame] | 160 | using namespace SVGNames; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 161 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 162 | bool isBackForwardLoadType(FrameLoadType type) |
| 163 | { |
| 164 | switch (type) { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 165 | case FrameLoadType::Standard: |
| 166 | case FrameLoadType::Reload: |
| 167 | case FrameLoadType::ReloadFromOrigin: |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 168 | case FrameLoadType::ReloadExpiredOnly: |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 169 | case FrameLoadType::Same: |
| 170 | case FrameLoadType::RedirectWithLockedBackForwardList: |
| 171 | case FrameLoadType::Replace: |
| 172 | return false; |
| 173 | case FrameLoadType::Back: |
| 174 | case FrameLoadType::Forward: |
| 175 | case FrameLoadType::IndexedBackForward: |
| 176 | return true; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 177 | } |
| 178 | ASSERT_NOT_REACHED(); |
| 179 | return false; |
| 180 | } |
| 181 | |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 182 | bool isReload(FrameLoadType type) |
| 183 | { |
| 184 | switch (type) { |
| 185 | case FrameLoadType::Reload: |
| 186 | case FrameLoadType::ReloadFromOrigin: |
| 187 | case FrameLoadType::ReloadExpiredOnly: |
| 188 | return true; |
| 189 | case FrameLoadType::Standard: |
| 190 | case FrameLoadType::Same: |
| 191 | case FrameLoadType::RedirectWithLockedBackForwardList: |
| 192 | case FrameLoadType::Replace: |
| 193 | case FrameLoadType::Back: |
| 194 | case FrameLoadType::Forward: |
| 195 | case FrameLoadType::IndexedBackForward: |
| 196 | return false; |
| 197 | } |
| 198 | ASSERT_NOT_REACHED(); |
| 199 | return false; |
| 200 | } |
| 201 | |
cjerdonek@webkit.org | 75d1069 | 2010-05-18 16:18:31 +0000 | [diff] [blame] | 202 | // This is not in the FrameLoader class to emphasize that it does not depend on |
| 203 | // private FrameLoader data, and to avoid increasing the number of public functions |
| 204 | // with access to private data. Since only this .cpp file needs it, making it |
| 205 | // non-member lets us exclude it from the header file, thus keeping FrameLoader.h's |
| 206 | // API simpler. |
| 207 | // |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 208 | static bool isDocumentSandboxed(Frame& frame, SandboxFlags mask) |
cjerdonek@webkit.org | 75d1069 | 2010-05-18 16:18:31 +0000 | [diff] [blame] | 209 | { |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 210 | return frame.document() && frame.document()->isSandboxed(mask); |
cjerdonek@webkit.org | 75d1069 | 2010-05-18 16:18:31 +0000 | [diff] [blame] | 211 | } |
| 212 | |
cdumez@apple.com | fc8fdf3 | 2019-12-06 21:05:12 +0000 | [diff] [blame] | 213 | class PageLevelForbidScope { |
| 214 | protected: |
| 215 | explicit PageLevelForbidScope(Page* page) |
| 216 | : m_page(makeWeakPtr(page)) |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 217 | { |
cdumez@apple.com | fc8fdf3 | 2019-12-06 21:05:12 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | ~PageLevelForbidScope() = default; |
| 221 | |
| 222 | WeakPtr<Page> m_page; |
| 223 | }; |
| 224 | |
| 225 | struct ForbidPromptsScope : public PageLevelForbidScope { |
| 226 | explicit ForbidPromptsScope(Page* page) |
| 227 | : PageLevelForbidScope(page) |
| 228 | { |
| 229 | if (m_page) |
| 230 | m_page->forbidPrompts(); |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | ~ForbidPromptsScope() |
| 234 | { |
cdumez@apple.com | fc8fdf3 | 2019-12-06 21:05:12 +0000 | [diff] [blame] | 235 | if (m_page) |
| 236 | m_page->allowPrompts(); |
| 237 | } |
| 238 | }; |
| 239 | |
| 240 | struct ForbidSynchronousLoadsScope : public PageLevelForbidScope { |
| 241 | explicit ForbidSynchronousLoadsScope(Page* page) |
| 242 | : PageLevelForbidScope(page) |
| 243 | { |
| 244 | if (m_page) |
| 245 | m_page->forbidSynchronousLoads(); |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 246 | } |
| 247 | |
cdumez@apple.com | fc8fdf3 | 2019-12-06 21:05:12 +0000 | [diff] [blame] | 248 | ~ForbidSynchronousLoadsScope() |
| 249 | { |
| 250 | if (m_page) |
| 251 | m_page->allowSynchronousLoads(); |
| 252 | } |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 253 | }; |
| 254 | |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 255 | class FrameLoader::FrameProgressTracker { |
cdumez@apple.com | a738a88 | 2016-04-19 18:39:09 +0000 | [diff] [blame] | 256 | WTF_MAKE_FAST_ALLOCATED; |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 257 | public: |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 258 | explicit FrameProgressTracker(Frame& frame) |
| 259 | : m_frame(frame) |
| 260 | , m_inProgress(false) |
| 261 | { |
| 262 | } |
| 263 | |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 264 | ~FrameProgressTracker() |
| 265 | { |
jpfau@apple.com | 7907c6b | 2014-10-28 22:38:44 +0000 | [diff] [blame] | 266 | if (m_inProgress && m_frame.page()) |
andersca@apple.com | cd08879 | 2014-01-10 07:19:29 +0000 | [diff] [blame] | 267 | m_frame.page()->progress().progressCompleted(m_frame); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | void progressStarted() |
| 271 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 272 | ASSERT(m_frame.page()); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 273 | if (!m_inProgress) |
andersca@apple.com | cd08879 | 2014-01-10 07:19:29 +0000 | [diff] [blame] | 274 | m_frame.page()->progress().progressStarted(m_frame); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 275 | m_inProgress = true; |
| 276 | } |
| 277 | |
| 278 | void progressCompleted() |
| 279 | { |
| 280 | ASSERT(m_inProgress); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 281 | ASSERT(m_frame.page()); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 282 | m_inProgress = false; |
andersca@apple.com | cd08879 | 2014-01-10 07:19:29 +0000 | [diff] [blame] | 283 | m_frame.page()->progress().progressCompleted(m_frame); |
cdumez@apple.com | c2b1e2a | 2019-09-04 03:13:45 +0000 | [diff] [blame] | 284 | platformStrategies()->loaderStrategy()->pageLoadCompleted(*m_frame.page()); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | private: |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 288 | Frame& m_frame; |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 289 | bool m_inProgress; |
| 290 | }; |
| 291 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 292 | FrameLoader::FrameLoader(Frame& frame, UniqueRef<FrameLoaderClient>&& client) |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 293 | : m_frame(frame) |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 294 | , m_client(WTFMove(client)) |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 295 | , m_policyChecker(makeUnique<PolicyChecker>(frame)) |
| 296 | , m_history(makeUnique<HistoryController>(frame)) |
akling@apple.com | 654fd9a | 2013-10-06 21:07:29 +0000 | [diff] [blame] | 297 | , m_notifier(frame) |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 298 | , m_subframeLoader(makeUnique<SubframeLoader>(frame)) |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 299 | , m_mixedContentChecker(frame) |
japhet@chromium.org | ce6c1ba | 2012-11-28 19:30:48 +0000 | [diff] [blame] | 300 | , m_state(FrameStateProvisional) |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 301 | , m_loadType(FrameLoadType::Standard) |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 302 | , m_quickRedirectComing(false) |
| 303 | , m_sentRedirectNotification(false) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 304 | , m_inStopAllLoaders(false) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 305 | , m_isExecutingJavaScriptFormAction(false) |
japhet@chromium.org | ce6c1ba | 2012-11-28 19:30:48 +0000 | [diff] [blame] | 306 | , m_didCallImplicitClose(true) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 307 | , m_wasUnloadEventEmitted(false) |
| 308 | , m_isComplete(false) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 309 | , m_needsClear(false) |
andersca@apple.com | 574a745 | 2014-11-21 20:10:13 +0000 | [diff] [blame] | 310 | , m_checkTimer(*this, &FrameLoader::checkTimerFired) |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 311 | , m_shouldCallCheckCompleted(false) |
| 312 | , m_shouldCallCheckLoadComplete(false) |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 313 | , m_opener(nullptr) |
beidson@apple.com | ac095c0 | 2009-08-18 01:37:56 +0000 | [diff] [blame] | 314 | , m_loadingFromCachedPage(false) |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 315 | , m_currentNavigationHasShownBeforeUnloadConfirmPanel(false) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 316 | , m_loadsSynchronously(false) |
abarth@webkit.org | f2c54c2 | 2010-04-11 06:57:13 +0000 | [diff] [blame] | 317 | , m_forcedSandboxFlags(SandboxNone) |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 318 | { |
| 319 | } |
| 320 | |
| 321 | FrameLoader::~FrameLoader() |
| 322 | { |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 323 | setOpener(nullptr); |
cdumez@apple.com | f6bbf48 | 2019-10-12 19:17:37 +0000 | [diff] [blame] | 324 | detachFromAllOpenedFrames(); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 325 | |
diegohcg@webkit.org | 838e0a2 | 2010-09-04 14:48:30 +0000 | [diff] [blame] | 326 | if (m_networkingContext) |
| 327 | m_networkingContext->invalidate(); |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 328 | } |
| 329 | |
cdumez@apple.com | f6bbf48 | 2019-10-12 19:17:37 +0000 | [diff] [blame] | 330 | void FrameLoader::detachFromAllOpenedFrames() |
| 331 | { |
| 332 | for (auto& frame : m_openedFrames) |
achristensen@apple.com | 2ace43d | 2020-11-05 16:54:48 +0000 | [diff] [blame] | 333 | frame.loader().m_opener = nullptr; |
cdumez@apple.com | f6bbf48 | 2019-10-12 19:17:37 +0000 | [diff] [blame] | 334 | m_openedFrames.clear(); |
| 335 | } |
| 336 | |
mrowe@apple.com | 5d92f2a | 2008-09-30 21:04:35 +0000 | [diff] [blame] | 337 | void FrameLoader::init() |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 338 | { |
darin@apple.com | 7300681 | 2011-06-29 20:46:33 +0000 | [diff] [blame] | 339 | // This somewhat odd set of steps gives the frame an initial empty document. |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 340 | setPolicyDocumentLoader(m_client->createDocumentLoader(ResourceRequest(URL({ }, emptyString())), SubstituteData()).ptr()); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 341 | setProvisionalDocumentLoader(m_policyDocumentLoader.get()); |
cdumez@apple.com | a0010ff | 2018-12-13 23:17:44 +0000 | [diff] [blame] | 342 | m_provisionalDocumentLoader->startLoadingMainResource(); |
jpfau@apple.com | ec9eb51 | 2014-07-10 01:13:45 +0000 | [diff] [blame] | 343 | |
| 344 | Ref<Frame> protect(m_frame); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 345 | m_frame.document()->cancelParsing(); |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 346 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocument); |
diegohcg@webkit.org | 838e0a2 | 2010-09-04 14:48:30 +0000 | [diff] [blame] | 347 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 348 | m_networkingContext = m_client->createNetworkingContext(); |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 349 | m_progressTracker = makeUnique<FrameProgressTracker>(m_frame); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 350 | } |
| 351 | |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 352 | void FrameLoader::initForSynthesizedDocument(const URL&) |
| 353 | { |
| 354 | // FIXME: We need to initialize the document URL to the specified URL. Currently the URL is empty and hence |
| 355 | // FrameLoader::checkCompleted() will overwrite the URL of the document to be activeDocumentLoader()->documentURL(). |
| 356 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 357 | auto loader = m_client->createDocumentLoader(ResourceRequest(URL({ }, emptyString())), SubstituteData()); |
beidson@apple.com | 10a537f | 2015-07-09 22:30:42 +0000 | [diff] [blame] | 358 | loader->attachToFrame(m_frame); |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 359 | loader->setResponse(ResourceResponse(URL(), "text/html"_s, 0, String())); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 360 | loader->setCommitted(true); |
commit-queue@webkit.org | c7c21c9 | 2017-10-25 21:17:46 +0000 | [diff] [blame] | 361 | setDocumentLoader(loader.ptr()); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 362 | |
| 363 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocument); |
| 364 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocumentPostCommit); |
| 365 | m_stateMachine.advanceTo(FrameLoaderStateMachine::CommittedFirstRealLoad); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 366 | m_client->transitionToCommittedForNewPage(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 367 | |
| 368 | m_didCallImplicitClose = true; |
| 369 | m_isComplete = true; |
| 370 | m_state = FrameStateComplete; |
| 371 | m_needsClear = true; |
| 372 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 373 | m_networkingContext = m_client->createNetworkingContext(); |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 374 | m_progressTracker = makeUnique<FrameProgressTracker>(m_frame); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 375 | } |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 376 | |
krollin@apple.com | f26b56e | 2020-02-28 19:43:33 +0000 | [diff] [blame] | 377 | Optional<PageIdentifier> FrameLoader::pageID() const |
| 378 | { |
| 379 | return client().pageID(); |
| 380 | } |
| 381 | |
| 382 | Optional<FrameIdentifier> FrameLoader::frameID() const |
| 383 | { |
| 384 | return client().frameID(); |
| 385 | } |
| 386 | |
achristensen@apple.com | 2ace43d | 2020-11-05 16:54:48 +0000 | [diff] [blame] | 387 | Frame* FrameLoader::opener() |
| 388 | { |
achristensen@apple.com | d1bf54a | 2020-11-05 17:19:40 +0000 | [diff] [blame] | 389 | return m_opener.get(); |
achristensen@apple.com | 2ace43d | 2020-11-05 16:54:48 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | const Frame* FrameLoader::opener() const |
| 393 | { |
achristensen@apple.com | d1bf54a | 2020-11-05 17:19:40 +0000 | [diff] [blame] | 394 | return m_opener.get(); |
achristensen@apple.com | 2ace43d | 2020-11-05 16:54:48 +0000 | [diff] [blame] | 395 | } |
| 396 | |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 397 | void FrameLoader::setDefersLoading(bool defers) |
| 398 | { |
darin | 8207db4 | 2007-02-20 18:18:39 +0000 | [diff] [blame] | 399 | if (m_documentLoader) |
| 400 | m_documentLoader->setDefersLoading(defers); |
| 401 | if (m_provisionalDocumentLoader) |
| 402 | m_provisionalDocumentLoader->setDefersLoading(defers); |
| 403 | if (m_policyDocumentLoader) |
| 404 | m_policyDocumentLoader->setDefersLoading(defers); |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 405 | history().setDefersLoading(defers); |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 406 | |
| 407 | if (!defers) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 408 | m_frame.navigationScheduler().startTimer(); |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 409 | startCheckCompleteTimer(); |
| 410 | } |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 411 | } |
| 412 | |
rniwa@webkit.org | ba12a01 | 2019-02-03 22:48:22 +0000 | [diff] [blame] | 413 | void FrameLoader::checkContentPolicy(const ResourceResponse& response, PolicyCheckIdentifier identifier, ContentPolicyDecisionFunction&& function) |
achristensen@apple.com | b8c49be | 2017-08-23 21:10:09 +0000 | [diff] [blame] | 414 | { |
bfulgham@apple.com | 78e81d9 | 2018-06-25 21:29:50 +0000 | [diff] [blame] | 415 | if (!activeDocumentLoader()) { |
| 416 | // Load was cancelled |
rniwa@webkit.org | ba12a01 | 2019-02-03 22:48:22 +0000 | [diff] [blame] | 417 | function(PolicyAction::Ignore, identifier); |
bfulgham@apple.com | 78e81d9 | 2018-06-25 21:29:50 +0000 | [diff] [blame] | 418 | return; |
| 419 | } |
| 420 | |
rniwa@webkit.org | ba12a01 | 2019-02-03 22:48:22 +0000 | [diff] [blame] | 421 | // FIXME: Validate the policy check identifier. |
commit-queue@webkit.org | a4a9ce2 | 2019-04-10 22:56:35 +0000 | [diff] [blame] | 422 | client().dispatchDecidePolicyForResponse(response, activeDocumentLoader()->request(), identifier, activeDocumentLoader()->downloadAttribute(), WTFMove(function)); |
achristensen@apple.com | b8c49be | 2017-08-23 21:10:09 +0000 | [diff] [blame] | 423 | } |
| 424 | |
commit-queue@webkit.org | f271985 | 2020-11-11 04:55:57 +0000 | [diff] [blame^] | 425 | void FrameLoader::changeLocation(const URL& url, const String& passedTarget, Event* triggeringEvent, LockHistory lockHistory, LockBackForwardList lockBackForwardList, const ReferrerPolicy& referrerPolicy, ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy, Optional<NewFrameOpenerPolicy> openerPolicy, const AtomString& downloadAttribute, const SystemPreviewInfo& systemPreviewInfo, Optional<AdClickAttribution>&& adClickAttribution) |
bfulgham@apple.com | 8f83154 | 2016-03-31 15:35:41 +0000 | [diff] [blame] | 426 | { |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 427 | auto* frame = lexicalFrameFromCommonVM(); |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 428 | auto initiatedByMainFrame = frame && frame->isMainFrame() ? InitiatedByMainFrame::Yes : InitiatedByMainFrame::Unknown; |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 429 | |
commit-queue@webkit.org | 8383b5f | 2020-03-02 11:36:00 +0000 | [diff] [blame] | 430 | NewFrameOpenerPolicy newFrameOpenerPolicy = openerPolicy.valueOr(referrerPolicy == ReferrerPolicy::NoReferrer ? NewFrameOpenerPolicy::Suppress : NewFrameOpenerPolicy::Allow); |
commit-queue@webkit.org | 1b6bd84 | 2020-04-18 17:04:07 +0000 | [diff] [blame] | 431 | FrameLoadRequest frameLoadRequest(*m_frame.document(), m_frame.document()->securityOrigin(), { url }, passedTarget, initiatedByMainFrame, downloadAttribute, systemPreviewInfo); |
| 432 | frameLoadRequest.setLockHistory(lockHistory); |
| 433 | frameLoadRequest.setLockBackForwardList(lockBackForwardList); |
| 434 | frameLoadRequest.setNewFrameOpenerPolicy(newFrameOpenerPolicy); |
| 435 | frameLoadRequest.setReferrerPolicy(referrerPolicy); |
| 436 | frameLoadRequest.setShouldOpenExternalURLsPolicy(shouldOpenExternalURLsPolicy); |
| 437 | frameLoadRequest.disableShouldReplaceDocumentIfJavaScriptURL(); |
commit-queue@webkit.org | f271985 | 2020-11-11 04:55:57 +0000 | [diff] [blame^] | 438 | changeLocation(WTFMove(frameLoadRequest), triggeringEvent, WTFMove(adClickAttribution)); |
bfulgham@apple.com | 8f83154 | 2016-03-31 15:35:41 +0000 | [diff] [blame] | 439 | } |
| 440 | |
commit-queue@webkit.org | f271985 | 2020-11-11 04:55:57 +0000 | [diff] [blame^] | 441 | void FrameLoader::changeLocation(FrameLoadRequest&& frameRequest, Event* triggeringEvent, Optional<AdClickAttribution>&& adClickAttribution) |
cjerdonek@webkit.org | 983777f | 2010-05-17 07:34:12 +0000 | [diff] [blame] | 442 | { |
commit-queue@webkit.org | 7a3c552 | 2020-03-09 15:10:01 +0000 | [diff] [blame] | 443 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "changeLocation: frame load started"); |
commit-queue@webkit.org | 8a13ad3 | 2020-03-16 08:11:26 +0000 | [diff] [blame] | 444 | ASSERT(frameRequest.resourceRequest().httpMethod() == "GET"); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 445 | |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 446 | Ref<Frame> protect(m_frame); |
darin@apple.com | 1cf3d56 | 2010-12-07 16:23:03 +0000 | [diff] [blame] | 447 | |
commit-queue@webkit.org | 13f8490 | 2020-06-14 06:34:43 +0000 | [diff] [blame] | 448 | if (frameRequest.resourceRequest().url().protocolIsJavaScript()) { |
| 449 | m_frame.script().executeJavaScriptURL(frameRequest.resourceRequest().url(), &frameRequest.requester().securityOrigin(), frameRequest.shouldReplaceDocumentIfJavaScriptURL()); |
cdumez@apple.com | 6cbf70a | 2019-10-11 20:26:15 +0000 | [diff] [blame] | 450 | m_quickRedirectComing = false; |
weinig@apple.com | 6b00e24 | 2008-01-08 01:30:27 +0000 | [diff] [blame] | 451 | return; |
cdumez@apple.com | 6cbf70a | 2019-10-11 20:26:15 +0000 | [diff] [blame] | 452 | } |
weinig@apple.com | 6b00e24 | 2008-01-08 01:30:27 +0000 | [diff] [blame] | 453 | |
darin@apple.com | 1cf3d56 | 2010-12-07 16:23:03 +0000 | [diff] [blame] | 454 | if (frameRequest.frameName().isEmpty()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 455 | frameRequest.setFrameName(m_frame.document()->baseTarget()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 456 | |
bfulgham@apple.com | b30d7f8 | 2016-06-07 15:47:30 +0000 | [diff] [blame] | 457 | m_frame.document()->contentSecurityPolicy()->upgradeInsecureRequestIfNeeded(frameRequest.resourceRequest(), ContentSecurityPolicy::InsecureRequestType::Navigation); |
darin@apple.com | 4cd1b24 | 2009-03-27 23:37:46 +0000 | [diff] [blame] | 458 | |
commit-queue@webkit.org | f271985 | 2020-11-11 04:55:57 +0000 | [diff] [blame^] | 459 | loadFrameRequest(WTFMove(frameRequest), triggeringEvent, { }, WTFMove(adClickAttribution)); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 460 | } |
| 461 | |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 462 | void FrameLoader::submitForm(Ref<FormSubmission>&& submission) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 463 | { |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 464 | ASSERT(submission->method() == FormSubmission::Method::Post || submission->method() == FormSubmission::Method::Get); |
dglazkov@chromium.org | 25a57e5 | 2010-06-20 21:00:35 +0000 | [diff] [blame] | 465 | |
dglazkov@chromium.org | 996fc22 | 2010-06-21 16:36:40 +0000 | [diff] [blame] | 466 | // FIXME: Find a good spot for these. |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 467 | ASSERT(!submission->state().sourceDocument().frame() || submission->state().sourceDocument().frame() == &m_frame); |
dbates@webkit.org | 2990852 | 2017-01-07 07:14:03 +0000 | [diff] [blame] | 468 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 469 | if (!m_frame.page()) |
adele@apple.com | f3d6b89 | 2008-04-29 01:30:20 +0000 | [diff] [blame] | 470 | return; |
dbates@webkit.org | 2990852 | 2017-01-07 07:14:03 +0000 | [diff] [blame] | 471 | |
dglazkov@chromium.org | 996fc22 | 2010-06-21 16:36:40 +0000 | [diff] [blame] | 472 | if (submission->action().isEmpty()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 473 | return; |
| 474 | |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 475 | if (isDocumentSandboxed(m_frame, SandboxForms)) { |
mkwst@chromium.org | b10ebb43 | 2012-12-04 18:34:27 +0000 | [diff] [blame] | 476 | // FIXME: This message should be moved off the console once a solution to https://bugs.webkit.org/show_bug.cgi?id=103274 exists. |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 477 | m_frame.document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Blocked form submission to '" + submission->action().stringCenterEllipsizedToLength() + "' because the form's frame is sandboxed and the 'allow-forms' permission is not set."); |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 478 | return; |
mkwst@chromium.org | b10ebb43 | 2012-12-04 18:34:27 +0000 | [diff] [blame] | 479 | } |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 480 | |
bfulgham@apple.com | 2187dd5 | 2020-06-10 23:11:41 +0000 | [diff] [blame] | 481 | URL formAction = submission->action(); |
| 482 | if (!m_frame.document()->contentSecurityPolicy()->allowFormAction(formAction)) |
| 483 | return; |
| 484 | |
| 485 | if (formAction.protocolIsJavaScript()) { |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 486 | m_isExecutingJavaScriptFormAction = true; |
ap@apple.com | e6afcb6 | 2014-04-20 19:02:13 +0000 | [diff] [blame] | 487 | Ref<Frame> protect(m_frame); |
commit-queue@webkit.org | 13f8490 | 2020-06-14 06:34:43 +0000 | [diff] [blame] | 488 | m_frame.script().executeJavaScriptURL(submission->action(), nullptr, DoNotReplaceDocumentIfJavaScriptURL); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 489 | m_isExecutingJavaScriptFormAction = false; |
| 490 | return; |
| 491 | } |
| 492 | |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 493 | Frame* targetFrame = findFrameForNavigation(submission->target(), &submission->state().sourceDocument()); |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 494 | if (!targetFrame) { |
commit-queue@webkit.org | 635dbdc | 2017-11-23 19:36:08 +0000 | [diff] [blame] | 495 | if (!DOMWindow::allowPopUp(m_frame) && !UserGestureIndicator::processingUserGesture()) |
abarth@webkit.org | c72185c | 2010-04-09 06:43:19 +0000 | [diff] [blame] | 496 | return; |
| 497 | |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 498 | // FIXME: targetFrame can be null for two distinct reasons: |
ap@apple.com | f8c414e | 2013-08-13 03:44:57 +0000 | [diff] [blame] | 499 | // 1. The frame was not found by name, so we should try opening a new window. |
| 500 | // 2. The frame was found, but navigating it was not allowed, e.g. by HTML5 sandbox or by origin checks. |
| 501 | // Continuing form submission makes no sense in the latter case. |
| 502 | // There is a repeat check after timer fires, so this is not a correctness issue. |
| 503 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 504 | targetFrame = &m_frame; |
dglazkov@chromium.org | 996fc22 | 2010-06-21 16:36:40 +0000 | [diff] [blame] | 505 | } else |
| 506 | submission->clearTarget(); |
| 507 | |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 508 | if (!targetFrame->page()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 509 | return; |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 510 | |
cdumez@apple.com | ede5bd3 | 2019-12-20 00:28:57 +0000 | [diff] [blame] | 511 | if (m_frame.tree().isDescendantOf(targetFrame)) |
commit-queue@webkit.org | 4396405 | 2012-08-13 19:30:15 +0000 | [diff] [blame] | 512 | m_submittedFormURL = submission->requestURL(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 513 | |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 514 | submission->setReferrer(outgoingReferrer()); |
commit-queue@webkit.org | 138b414 | 2020-03-10 11:27:15 +0000 | [diff] [blame] | 515 | submission->setOrigin(SecurityPolicy::generateOriginHeader(m_frame.document()->referrerPolicy(), submission->requestURL(), m_frame.document()->securityOrigin())); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 516 | |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 517 | targetFrame->navigationScheduler().scheduleFormSubmission(WTFMove(submission)); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 518 | } |
| 519 | |
commit-queue@webkit.org | fc5833b | 2011-02-23 06:58:46 +0000 | [diff] [blame] | 520 | void FrameLoader::stopLoading(UnloadEventPolicy unloadEventPolicy) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 521 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 522 | if (m_frame.document() && m_frame.document()->parser()) |
| 523 | m_frame.document()->parser()->stopParsing(); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 524 | |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 525 | if (unloadEventPolicy != UnloadEventPolicyNone) |
ggaren@apple.com | 7a176e1 | 2015-11-12 01:48:27 +0000 | [diff] [blame] | 526 | dispatchUnloadEvents(unloadEventPolicy); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 527 | |
darin@apple.com | 4d9d718 | 2009-09-23 00:38:04 +0000 | [diff] [blame] | 528 | m_isComplete = true; // to avoid calling completed() in finishedParsing() |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 529 | m_didCallImplicitClose = true; // don't want that one either |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 530 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 531 | if (m_frame.document() && m_frame.document()->parsing()) { |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 532 | finishedParsing(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 533 | m_frame.document()->setParsing(false); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 534 | } |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 535 | |
darin@apple.com | 389af86 | 2016-11-14 03:22:31 +0000 | [diff] [blame] | 536 | if (auto* document = m_frame.document()) { |
mark.lam@apple.com | 45beb07 | 2012-12-12 23:04:20 +0000 | [diff] [blame] | 537 | // FIXME: Should the DatabaseManager watch for something like ActiveDOMObject::stop() rather than being special-cased here? |
darin@apple.com | 389af86 | 2016-11-14 03:22:31 +0000 | [diff] [blame] | 538 | DatabaseManager::singleton().stopDatabases(*document, nullptr); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 539 | } |
| 540 | |
cdumez@apple.com | 2d8d608 | 2018-02-27 21:47:57 +0000 | [diff] [blame] | 541 | policyChecker().stopCheck(); |
| 542 | |
ap@apple.com | 3f0a0a1 | 2010-06-24 23:58:36 +0000 | [diff] [blame] | 543 | // FIXME: This will cancel redirection timer, which really needs to be restarted when restoring the frame from b/f cache. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 544 | m_frame.navigationScheduler().cancel(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | void FrameLoader::stop() |
| 548 | { |
| 549 | // http://bugs.webkit.org/show_bug.cgi?id=10854 |
| 550 | // The frame's last ref may be removed and it will be deleted by checkCompleted(). |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 551 | Ref<Frame> protect(m_frame); |
abarth@webkit.org | fd91290 | 2011-06-10 21:16:20 +0000 | [diff] [blame] | 552 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 553 | if (DocumentParser* parser = m_frame.document()->parser()) { |
abarth@webkit.org | fd91290 | 2011-06-10 21:16:20 +0000 | [diff] [blame] | 554 | parser->stopParsing(); |
| 555 | parser->finish(); |
| 556 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 557 | } |
| 558 | |
commit-queue@webkit.org | 8772f67 | 2020-04-13 08:24:39 +0000 | [diff] [blame] | 559 | void FrameLoader::closeURL() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 560 | { |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 561 | history().saveDocumentState(); |
stavila@adobe.com | eb50d7c | 2014-12-17 10:14:32 +0000 | [diff] [blame] | 562 | |
shihchieh_lee@apple.com | 501b37c | 2020-04-28 16:36:38 +0000 | [diff] [blame] | 563 | RefPtr<Document> currentDocument = m_frame.document(); |
stavila@adobe.com | eb50d7c | 2014-12-17 10:14:32 +0000 | [diff] [blame] | 564 | UnloadEventPolicy unloadEventPolicy; |
| 565 | if (m_frame.page() && m_frame.page()->chrome().client().isSVGImageChromeClient()) { |
| 566 | // If this is the SVGDocument of an SVGImage, no need to dispatch events or recalcStyle. |
| 567 | unloadEventPolicy = UnloadEventPolicyNone; |
| 568 | } else { |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 569 | // Should only send the pagehide event here if the current document exists and has not been placed in the back/forward cache. |
| 570 | unloadEventPolicy = currentDocument && currentDocument->backForwardCacheState() == Document::NotInBackForwardCache ? UnloadEventPolicyUnloadAndPageHide : UnloadEventPolicyUnloadOnly; |
stavila@adobe.com | eb50d7c | 2014-12-17 10:14:32 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | stopLoading(unloadEventPolicy); |
beidson@apple.com | 212b784 | 2009-09-03 00:55:18 +0000 | [diff] [blame] | 574 | |
shihchieh_lee@apple.com | 501b37c | 2020-04-28 16:36:38 +0000 | [diff] [blame] | 575 | if (currentDocument) |
| 576 | currentDocument->editor().clearUndoRedoOperations(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 577 | } |
| 578 | |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 579 | bool FrameLoader::didOpenURL() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 580 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 581 | if (m_frame.navigationScheduler().redirectScheduledDuringLoad()) { |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 582 | // A redirect was scheduled before the document was created. |
| 583 | // This can happen when one frame changes another frame's location. |
| 584 | return false; |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 585 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 586 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 587 | m_frame.navigationScheduler().cancel(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 588 | |
| 589 | m_isComplete = false; |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 590 | m_didCallImplicitClose = false; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 591 | |
ap@webkit.org | fbfb0f9 | 2009-05-08 07:58:08 +0000 | [diff] [blame] | 592 | // If we are still in the process of initializing an empty document then |
| 593 | // its frame is not in a consistent state for rendering, so avoid setJSStatusBarText |
| 594 | // since it may cause clients to attempt to render the frame. |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 595 | if (!m_stateMachine.creatingInitialEmptyDocument()) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 596 | DOMWindow* window = m_frame.document()->domWindow(); |
abarth@webkit.org | 13fe1e2 | 2012-08-16 22:29:48 +0000 | [diff] [blame] | 597 | window->setStatus(String()); |
| 598 | window->setDefaultStatus(String()); |
ap@webkit.org | fbfb0f9 | 2009-05-08 07:58:08 +0000 | [diff] [blame] | 599 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 600 | |
| 601 | started(); |
| 602 | |
| 603 | return true; |
| 604 | } |
| 605 | |
ap@webkit.org | a0a1987 | 2008-02-05 09:34:18 +0000 | [diff] [blame] | 606 | void FrameLoader::didExplicitOpen() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 607 | { |
| 608 | m_isComplete = false; |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 609 | m_didCallImplicitClose = false; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 610 | |
andersca@apple.com | 1752dba | 2007-12-14 22:06:50 +0000 | [diff] [blame] | 611 | // Calling document.open counts as committing the first real document load. |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 612 | if (!m_stateMachine.committedFirstRealDocumentLoad()) |
| 613 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocumentPostCommit); |
cdumez@apple.com | 0af95e3 | 2019-04-16 23:07:35 +0000 | [diff] [blame] | 614 | |
cdumez@apple.com | c59c42d | 2019-10-30 18:36:22 +0000 | [diff] [blame] | 615 | if (auto* document = m_frame.document()) |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 616 | m_client->dispatchDidExplicitOpen(document->url(), document->contentType()); |
andersca@apple.com | 1752dba | 2007-12-14 22:06:50 +0000 | [diff] [blame] | 617 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 618 | // Prevent window.open(url) -- eg window.open("about:blank") -- from blowing away results |
| 619 | // from a subsequent window.document.open / window.document.write call. |
dbates@webkit.org | ef42d38 | 2010-01-25 19:20:06 +0000 | [diff] [blame] | 620 | // Canceling redirection here works for all cases because document.open |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 621 | // implicitly precedes document.write. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 622 | m_frame.navigationScheduler().cancel(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 623 | } |
| 624 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 625 | |
| 626 | void FrameLoader::cancelAndClear() |
| 627 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 628 | m_frame.navigationScheduler().cancel(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 629 | |
| 630 | if (!m_isComplete) |
| 631 | closeURL(); |
| 632 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 633 | clear(m_frame.document(), false); |
| 634 | m_frame.script().updatePlatformScriptObjects(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 635 | } |
| 636 | |
aestes@apple.com | 408782b | 2016-11-29 18:40:55 +0000 | [diff] [blame] | 637 | static inline bool shouldClearWindowName(const Frame& frame, const Document& newDocument) |
| 638 | { |
| 639 | if (!frame.isMainFrame()) |
| 640 | return false; |
| 641 | |
| 642 | if (frame.loader().opener()) |
| 643 | return false; |
| 644 | |
akling@apple.com | 6be0e97 | 2017-01-18 19:35:49 +0000 | [diff] [blame] | 645 | return !newDocument.securityOrigin().isSameOriginAs(frame.document()->securityOrigin()); |
aestes@apple.com | 408782b | 2016-11-29 18:40:55 +0000 | [diff] [blame] | 646 | } |
| 647 | |
beidson@apple.com | dc5cfa4 | 2019-07-01 20:29:20 +0000 | [diff] [blame] | 648 | void FrameLoader::clear(Document* newDocument, bool clearWindowProperties, bool clearScriptObjects, bool clearFrameView, WTF::Function<void()>&& handleDOMWindowCreation) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 649 | { |
beidson@apple.com | dc5cfa4 | 2019-07-01 20:29:20 +0000 | [diff] [blame] | 650 | bool neededClear = m_needsClear; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 651 | m_needsClear = false; |
beidson@apple.com | dc5cfa4 | 2019-07-01 20:29:20 +0000 | [diff] [blame] | 652 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 653 | if (neededClear && m_frame.document()->backForwardCacheState() != Document::InBackForwardCache) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 654 | m_frame.document()->cancelParsing(); |
| 655 | m_frame.document()->stopActiveDOMObjects(); |
timothy_horton@apple.com | 70d58d8 | 2014-07-26 18:45:04 +0000 | [diff] [blame] | 656 | bool hadLivingRenderTree = m_frame.document()->hasLivingRenderTree(); |
shihchieh_lee@apple.com | 501b37c | 2020-04-28 16:36:38 +0000 | [diff] [blame] | 657 | m_frame.document()->willBeRemovedFromFrame(); |
timothy_horton@apple.com | 70d58d8 | 2014-07-26 18:45:04 +0000 | [diff] [blame] | 658 | if (hadLivingRenderTree) |
simon.fraser@apple.com | 87cf166 | 2018-09-08 20:19:22 +0000 | [diff] [blame] | 659 | m_frame.document()->adjustFocusedNodeOnNodeRemoval(*m_frame.document()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 660 | } |
| 661 | |
beidson@apple.com | dc5cfa4 | 2019-07-01 20:29:20 +0000 | [diff] [blame] | 662 | if (handleDOMWindowCreation) |
| 663 | handleDOMWindowCreation(); |
| 664 | |
| 665 | if (!neededClear) |
| 666 | return; |
| 667 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 668 | // Do this after detaching the document so that the unload event works. |
thatcher | a1e24df | 2007-09-14 23:53:29 +0000 | [diff] [blame] | 669 | if (clearWindowProperties) { |
commit-queue@webkit.org | 8599a76 | 2016-11-01 21:42:51 +0000 | [diff] [blame] | 670 | InspectorInstrumentation::frameWindowDiscarded(m_frame, m_frame.document()->domWindow()); |
commit-queue@webkit.org | 8af5d21 | 2015-12-01 01:55:43 +0000 | [diff] [blame] | 671 | m_frame.document()->domWindow()->resetUnlessSuspendedForDocumentSuspension(); |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 672 | m_frame.windowProxy().clearJSWindowProxiesNotMatchingDOMWindow(newDocument->domWindow(), m_frame.document()->backForwardCacheState() == Document::AboutToEnterBackForwardCache); |
aestes@apple.com | 408782b | 2016-11-29 18:40:55 +0000 | [diff] [blame] | 673 | |
| 674 | if (shouldClearWindowName(m_frame, *newDocument)) |
utatane.tea@gmail.com | c4579a0 | 2017-07-07 04:42:04 +0000 | [diff] [blame] | 675 | m_frame.tree().setName(nullAtom()); |
weinig | f930763 | 2007-07-18 05:40:54 +0000 | [diff] [blame] | 676 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 677 | |
achristensen@apple.com | 09e70aa | 2017-04-27 16:42:13 +0000 | [diff] [blame] | 678 | m_frame.eventHandler().clear(); |
bfulgham@apple.com | 46bde7c | 2016-04-07 21:15:34 +0000 | [diff] [blame] | 679 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 680 | if (clearFrameView && m_frame.view()) |
| 681 | m_frame.view()->clear(); |
eric@webkit.org | 0683d94 | 2008-08-06 10:01:35 +0000 | [diff] [blame] | 682 | |
eric@webkit.org | 0683d94 | 2008-08-06 10:01:35 +0000 | [diff] [blame] | 683 | // Do not drop the document before the ScriptController and view are cleared |
| 684 | // as some destructors might still try to access the document. |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 685 | m_frame.setDocument(nullptr); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 686 | |
akling@apple.com | 7f81b1e | 2013-09-06 17:23:03 +0000 | [diff] [blame] | 687 | subframeLoader().clear(); |
eric@webkit.org | 0683d94 | 2008-08-06 10:01:35 +0000 | [diff] [blame] | 688 | |
bfulgham@apple.com | 472a034 | 2017-01-04 22:35:44 +0000 | [diff] [blame] | 689 | if (clearWindowProperties) |
cdumez@apple.com | 87a798a | 2018-04-19 04:02:30 +0000 | [diff] [blame] | 690 | m_frame.windowProxy().setDOMWindow(newDocument->domWindow()); |
bfulgham@apple.com | 472a034 | 2017-01-04 22:35:44 +0000 | [diff] [blame] | 691 | |
antti | 90500a3 | 2007-09-27 23:56:17 +0000 | [diff] [blame] | 692 | if (clearScriptObjects) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 693 | m_frame.script().clearScriptObjects(); |
eric@webkit.org | 0683d94 | 2008-08-06 10:01:35 +0000 | [diff] [blame] | 694 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 695 | m_frame.script().enableEval(); |
abarth@webkit.org | 9d220b6 | 2012-06-09 19:35:02 +0000 | [diff] [blame] | 696 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 697 | m_frame.navigationScheduler().clear(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 698 | |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 699 | m_checkTimer.stop(); |
| 700 | m_shouldCallCheckCompleted = false; |
| 701 | m_shouldCallCheckLoadComplete = false; |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 702 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 703 | if (m_stateMachine.isDisplayingInitialEmptyDocument() && m_stateMachine.committedFirstRealDocumentLoad()) |
| 704 | m_stateMachine.advanceTo(FrameLoaderStateMachine::CommittedFirstRealLoad); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | void FrameLoader::receivedFirstData() |
| 708 | { |
commit-queue@webkit.org | c7d4087 | 2020-03-31 19:56:26 +0000 | [diff] [blame] | 709 | auto protectedFrame = makeRef(m_frame); |
| 710 | |
achristensen@apple.com | e0301a3 | 2020-02-07 23:30:29 +0000 | [diff] [blame] | 711 | dispatchDidCommitLoad(WTF::nullopt, WTF::nullopt); |
jcivelli@chromium.org | 4b94add | 2011-11-19 08:45:01 +0000 | [diff] [blame] | 712 | dispatchDidClearWindowObjectsInAllWorlds(); |
beidson@apple.com | 2a75a96 | 2012-04-24 18:12:55 +0000 | [diff] [blame] | 713 | dispatchGlobalObjectAvailableInAllWorlds(); |
jcivelli@chromium.org | 4b94add | 2011-11-19 08:45:01 +0000 | [diff] [blame] | 714 | |
darin | 8207db4 | 2007-02-20 18:18:39 +0000 | [diff] [blame] | 715 | if (!m_documentLoader) |
| 716 | return; |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 717 | |
dbates@webkit.org | 6602466 | 2018-02-03 04:53:47 +0000 | [diff] [blame] | 718 | auto& documentLoader = *m_documentLoader; |
| 719 | auto& title = documentLoader.title(); |
| 720 | if (!title.string.isNull()) |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 721 | m_client->dispatchDidReceiveTitle(title); |
dbates@webkit.org | 6602466 | 2018-02-03 04:53:47 +0000 | [diff] [blame] | 722 | |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 723 | ASSERT(m_frame.document()); |
| 724 | auto& document = *m_frame.document(); |
| 725 | |
dbates@webkit.org | 6602466 | 2018-02-03 04:53:47 +0000 | [diff] [blame] | 726 | LinkLoader::loadLinksFromHeader(documentLoader.response().httpHeaderField(HTTPHeaderName::Link), document.url(), document, LinkLoader::MediaAttributeCheck::MediaAttributeEmpty); |
yoav@yoav.ws | 1c12d5c | 2017-01-19 07:13:54 +0000 | [diff] [blame] | 727 | |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 728 | double delay; |
darin@apple.com | 47a20cb | 2014-04-27 16:06:27 +0000 | [diff] [blame] | 729 | String urlString; |
cdumez@apple.com | 63b7fdd | 2019-09-12 04:32:29 +0000 | [diff] [blame] | 730 | if (!parseMetaHTTPEquivRefresh(documentLoader.response().httpHeaderField(HTTPHeaderName::Refresh), delay, urlString)) |
ap | e9991d5 | 2006-12-08 18:19:51 +0000 | [diff] [blame] | 731 | return; |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 732 | auto completedURL = urlString.isEmpty() ? document.url() : document.completeURL(urlString); |
commit-queue@webkit.org | 39359f0 | 2020-04-25 21:28:45 +0000 | [diff] [blame] | 733 | if (!completedURL.protocolIsJavaScript()) |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 734 | m_frame.navigationScheduler().scheduleRedirect(document, delay, completedURL); |
ddkilzer@apple.com | 70f1539 | 2014-04-01 19:21:34 +0000 | [diff] [blame] | 735 | else { |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 736 | auto message = "Refused to refresh " + document.url().stringCenterEllipsizedToLength() + " to a javascript: URL"; |
dbates@webkit.org | 6602466 | 2018-02-03 04:53:47 +0000 | [diff] [blame] | 737 | document.addConsoleMessage(MessageSource::Security, MessageLevel::Error, message); |
ddkilzer@apple.com | 70f1539 | 2014-04-01 19:21:34 +0000 | [diff] [blame] | 738 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 739 | } |
| 740 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 741 | void FrameLoader::setOutgoingReferrer(const URL& url) |
japhet@chromium.org | b254c9b | 2011-01-26 19:14:26 +0000 | [diff] [blame] | 742 | { |
levin@chromium.org | 1a2fef4 | 2011-03-01 02:10:28 +0000 | [diff] [blame] | 743 | m_outgoingReferrer = url.strippedForUseAsReferrer(); |
abarth@webkit.org | 412c54e | 2010-04-20 22:12:16 +0000 | [diff] [blame] | 744 | } |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 745 | |
dbates@webkit.org | 123b1af | 2019-09-23 21:56:43 +0000 | [diff] [blame] | 746 | void FrameLoader::didBeginDocument(bool dispatch) |
abarth@webkit.org | 412c54e | 2010-04-20 22:12:16 +0000 | [diff] [blame] | 747 | { |
| 748 | m_needsClear = true; |
| 749 | m_isComplete = false; |
| 750 | m_didCallImplicitClose = false; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 751 | m_frame.document()->setReadyState(Document::Loading); |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 752 | |
| 753 | if (m_pendingStateObject) { |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 754 | m_frame.document()->statePopped(*m_pendingStateObject); |
cdumez@apple.com | d839ea1 | 2015-07-04 19:42:18 +0000 | [diff] [blame] | 755 | m_pendingStateObject = nullptr; |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 756 | } |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 757 | |
andersca@apple.com | 6c6fb4b | 2009-08-12 22:03:02 +0000 | [diff] [blame] | 758 | if (dispatch) |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 759 | dispatchDidClearWindowObjectsInAllWorlds(); |
abarth@webkit.org | 412c54e | 2010-04-20 22:12:16 +0000 | [diff] [blame] | 760 | |
abarth@webkit.org | 622d9df | 2009-05-22 16:44:47 +0000 | [diff] [blame] | 761 | updateFirstPartyForCookies(); |
dbates@webkit.org | 123b1af | 2019-09-23 21:56:43 +0000 | [diff] [blame] | 762 | m_frame.document()->initContentSecurityPolicy(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 763 | |
akling@apple.com | 1c29edbc | 2013-08-23 23:19:21 +0000 | [diff] [blame] | 764 | const Settings& settings = m_frame.settings(); |
cdumez@apple.com | 0bb03ec | 2015-01-28 05:53:53 +0000 | [diff] [blame] | 765 | m_frame.document()->cachedResourceLoader().setImagesEnabled(settings.areImagesEnabled()); |
| 766 | m_frame.document()->cachedResourceLoader().setAutoLoadImages(settings.loadsImagesAutomatically()); |
aroben@apple.com | 3adf245 | 2008-02-07 23:19:31 +0000 | [diff] [blame] | 767 | |
collinj@webkit.org | 9c672f6 | 2008-09-19 04:15:14 +0000 | [diff] [blame] | 768 | if (m_documentLoader) { |
andersca@apple.com | 30391b4 | 2014-06-16 19:26:49 +0000 | [diff] [blame] | 769 | String dnsPrefetchControl = m_documentLoader->response().httpHeaderField(HTTPHeaderName::XDNSPrefetchControl); |
collinj@webkit.org | 9c672f6 | 2008-09-19 04:15:14 +0000 | [diff] [blame] | 770 | if (!dnsPrefetchControl.isEmpty()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 771 | m_frame.document()->parseDNSPrefetchControlHeader(dnsPrefetchControl); |
jochen@chromium.org | adec40f | 2011-02-09 17:03:38 +0000 | [diff] [blame] | 772 | |
dbates@webkit.org | 41f504e | 2018-05-07 17:52:34 +0000 | [diff] [blame] | 773 | m_frame.document()->contentSecurityPolicy()->didReceiveHeaders(ContentSecurityPolicyResponseHeaders(m_documentLoader->response()), referrer(), ContentSecurityPolicy::ReportParsingErrors::No); |
commit-queue@webkit.org | 26a3a09 | 2012-10-18 19:53:58 +0000 | [diff] [blame] | 774 | |
cdumez@apple.com | 7c12c6c | 2018-05-30 21:30:21 +0000 | [diff] [blame] | 775 | String referrerPolicy = m_documentLoader->response().httpHeaderField(HTTPHeaderName::ReferrerPolicy); |
| 776 | if (!referrerPolicy.isNull()) |
| 777 | m_frame.document()->processReferrerPolicy(referrerPolicy, ReferrerPolicySource::HTTPHeader); |
| 778 | |
andersca@apple.com | 30391b4 | 2014-06-16 19:26:49 +0000 | [diff] [blame] | 779 | String headerContentLanguage = m_documentLoader->response().httpHeaderField(HTTPHeaderName::ContentLanguage); |
commit-queue@webkit.org | 26a3a09 | 2012-10-18 19:53:58 +0000 | [diff] [blame] | 780 | if (!headerContentLanguage.isEmpty()) { |
| 781 | size_t commaIndex = headerContentLanguage.find(','); |
| 782 | headerContentLanguage.truncate(commaIndex); // notFound == -1 == don't truncate |
darin@apple.com | 940b9ea | 2017-11-25 02:44:45 +0000 | [diff] [blame] | 783 | headerContentLanguage = stripLeadingAndTrailingHTMLSpaces(headerContentLanguage); |
commit-queue@webkit.org | 26a3a09 | 2012-10-18 19:53:58 +0000 | [diff] [blame] | 784 | if (!headerContentLanguage.isEmpty()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 785 | m_frame.document()->setContentLanguage(headerContentLanguage); |
commit-queue@webkit.org | 26a3a09 | 2012-10-18 19:53:58 +0000 | [diff] [blame] | 786 | } |
collinj@webkit.org | 9c672f6 | 2008-09-19 04:15:14 +0000 | [diff] [blame] | 787 | } |
| 788 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 789 | history().restoreDocumentState(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 790 | } |
| 791 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 792 | void FrameLoader::finishedParsing() |
| 793 | { |
simon.fraser@apple.com | 677f042 | 2017-12-02 17:55:24 +0000 | [diff] [blame] | 794 | LOG(Loading, "WebCoreLoading %s: Finished parsing", m_frame.tree().uniqueName().string().utf8().data()); |
| 795 | |
commit-queue@webkit.org | 11fed0a | 2020-04-04 00:44:31 +0000 | [diff] [blame] | 796 | m_frame.injectUserScripts(UserScriptInjectionTime::DocumentEnd); |
aestes@apple.com | e35644e | 2011-04-07 20:23:48 +0000 | [diff] [blame] | 797 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 798 | if (m_stateMachine.creatingInitialEmptyDocument()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 799 | return; |
| 800 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 801 | // This can be called from the Frame's destructor, in which case we shouldn't protect ourselves |
| 802 | // because doing so will cause us to re-enter the destructor when protector goes out of scope. |
beidson@apple.com | f7eea40 | 2008-07-10 04:51:10 +0000 | [diff] [blame] | 803 | // Null-checking the FrameView indicates whether or not we're in the destructor. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 804 | RefPtr<Frame> protector = m_frame.view() ? &m_frame : 0; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 805 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 806 | m_client->dispatchDidFinishDocumentLoad(); |
darin@chromium.org | 1750e24 | 2008-12-08 18:13:25 +0000 | [diff] [blame] | 807 | |
cdumez@apple.com | 6d7c65e | 2015-09-02 17:07:57 +0000 | [diff] [blame] | 808 | scrollToFragmentWithParentBoundary(m_frame.document()->url()); |
| 809 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 810 | checkCompleted(); |
| 811 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 812 | if (!m_frame.view()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 813 | return; // We are being destroyed by something checkCompleted called. |
| 814 | |
| 815 | // Check if the scrollbars are really needed for the content. |
| 816 | // If not, remove them, relayout, and repaint. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 817 | m_frame.view()->restoreScrollbar(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 818 | } |
| 819 | |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 820 | void FrameLoader::loadDone(LoadCompletionType type) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 821 | { |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 822 | if (type == LoadCompletionType::Finish) |
| 823 | checkCompleted(); |
| 824 | else |
| 825 | scheduleCheckCompleted(); |
| 826 | } |
| 827 | |
| 828 | void FrameLoader::subresourceLoadDone(LoadCompletionType type) |
| 829 | { |
| 830 | if (type == LoadCompletionType::Finish) |
| 831 | checkLoadComplete(); |
| 832 | else |
| 833 | scheduleCheckLoadComplete(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 834 | } |
| 835 | |
commit-queue@webkit.org | 87bc913 | 2020-09-12 08:35:27 +0000 | [diff] [blame] | 836 | bool FrameLoader::preventsParentFromBeingComplete(const Frame& frame) const |
| 837 | { |
| 838 | return !frame.loader().m_isComplete && (!frame.ownerElement() || !frame.ownerElement()->isLazyLoadObserverActive()); |
| 839 | } |
| 840 | |
darin@apple.com | 4d9d718 | 2009-09-23 00:38:04 +0000 | [diff] [blame] | 841 | bool FrameLoader::allChildrenAreComplete() const |
| 842 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 843 | for (Frame* child = m_frame.tree().firstChild(); child; child = child->tree().nextSibling()) { |
commit-queue@webkit.org | 87bc913 | 2020-09-12 08:35:27 +0000 | [diff] [blame] | 844 | if (preventsParentFromBeingComplete(*child)) |
darin@apple.com | 4d9d718 | 2009-09-23 00:38:04 +0000 | [diff] [blame] | 845 | return false; |
| 846 | } |
| 847 | return true; |
| 848 | } |
| 849 | |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 850 | bool FrameLoader::allAncestorsAreComplete() const |
| 851 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 852 | for (Frame* ancestor = &m_frame; ancestor; ancestor = ancestor->tree().parent()) { |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 853 | if (!ancestor->loader().m_isComplete) |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 854 | return false; |
| 855 | } |
| 856 | return true; |
| 857 | } |
| 858 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 859 | void FrameLoader::checkCompleted() |
| 860 | { |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 861 | RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(ScriptDisallowedScope::InMainThread::isScriptAllowed()); |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 862 | m_shouldCallCheckCompleted = false; |
| 863 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 864 | // Have we completed before? |
| 865 | if (m_isComplete) |
| 866 | return; |
| 867 | |
antti@apple.com | 079cbf5 | 2017-05-05 18:39:30 +0000 | [diff] [blame] | 868 | // FIXME: It would be better if resource loads were kicked off after render tree update (or didn't complete synchronously). |
| 869 | // https://bugs.webkit.org/show_bug.cgi?id=171729 |
| 870 | if (m_frame.document()->inRenderTreeUpdate()) { |
| 871 | scheduleCheckCompleted(); |
| 872 | return; |
| 873 | } |
| 874 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 875 | // Are we still parsing? |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 876 | if (m_frame.document()->parsing()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 877 | return; |
| 878 | |
| 879 | // Still waiting for images/scripts? |
cdumez@apple.com | 0bb03ec | 2015-01-28 05:53:53 +0000 | [diff] [blame] | 880 | if (m_frame.document()->cachedResourceLoader().requestCount()) |
ap@webkit.org | f9b6eff | 2009-02-10 17:33:33 +0000 | [diff] [blame] | 881 | return; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 882 | |
eric.carlson@apple.com | 9c7fc72 | 2010-08-26 16:45:43 +0000 | [diff] [blame] | 883 | // Still waiting for elements that don't go through a FrameLoader? |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 884 | if (m_frame.document()->isDelayingLoadEvent()) |
eric.carlson@apple.com | 9c7fc72 | 2010-08-26 16:45:43 +0000 | [diff] [blame] | 885 | return; |
| 886 | |
antti@apple.com | 9f4e3b2 | 2017-02-19 12:12:07 +0000 | [diff] [blame] | 887 | auto* scriptableParser = m_frame.document()->scriptableDocumentParser(); |
| 888 | if (scriptableParser && scriptableParser->hasScriptsWaitingForStylesheets()) |
| 889 | return; |
| 890 | |
andreas.kling@nokia.com | 01f9244 | 2011-02-28 13:46:06 +0000 | [diff] [blame] | 891 | // Any frame that hasn't completed yet? |
| 892 | if (!allChildrenAreComplete()) |
| 893 | return; |
| 894 | |
darin@apple.com | c284300 | 2014-04-25 06:01:34 +0000 | [diff] [blame] | 895 | // Important not to protect earlier in this function, because earlier parts |
darin@apple.com | fe9effd | 2014-04-25 06:02:42 +0000 | [diff] [blame] | 896 | // of this function can be called in the frame's destructor, and it's not legal |
darin@apple.com | c284300 | 2014-04-25 06:01:34 +0000 | [diff] [blame] | 897 | // to ref an object while it's being destroyed. |
| 898 | Ref<Frame> protect(m_frame); |
| 899 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 900 | // OK, completed. |
| 901 | m_isComplete = true; |
cdumez@apple.com | d839ea1 | 2015-07-04 19:42:18 +0000 | [diff] [blame] | 902 | m_requestedHistoryItem = nullptr; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 903 | m_frame.document()->setReadyState(Document::Complete); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 904 | |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 905 | checkCallImplicitClose(); // if we didn't do it before |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 906 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 907 | m_frame.navigationScheduler().startTimer(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 908 | |
| 909 | completed(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 910 | if (m_frame.page()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 911 | checkLoadComplete(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 912 | } |
| 913 | |
andersca@apple.com | 574a745 | 2014-11-21 20:10:13 +0000 | [diff] [blame] | 914 | void FrameLoader::checkTimerFired() |
weinig | c34c71c | 2007-03-09 16:05:37 +0000 | [diff] [blame] | 915 | { |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 916 | checkCompletenessNow(); |
| 917 | } |
| 918 | |
| 919 | void FrameLoader::checkCompletenessNow() |
| 920 | { |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 921 | Ref<Frame> protect(m_frame); |
commit-queue@webkit.org | 667ee8b | 2012-02-08 02:21:04 +0000 | [diff] [blame] | 922 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 923 | if (Page* page = m_frame.page()) { |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 924 | if (page->defersLoading()) |
| 925 | return; |
| 926 | } |
| 927 | if (m_shouldCallCheckCompleted) |
| 928 | checkCompleted(); |
| 929 | if (m_shouldCallCheckLoadComplete) |
| 930 | checkLoadComplete(); |
| 931 | } |
| 932 | |
| 933 | void FrameLoader::startCheckCompleteTimer() |
| 934 | { |
| 935 | if (!(m_shouldCallCheckCompleted || m_shouldCallCheckLoadComplete)) |
| 936 | return; |
| 937 | if (m_checkTimer.isActive()) |
| 938 | return; |
cdumez@apple.com | bc919b0 | 2017-04-09 14:49:14 +0000 | [diff] [blame] | 939 | m_checkTimer.startOneShot(0_s); |
weinig | c34c71c | 2007-03-09 16:05:37 +0000 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | void FrameLoader::scheduleCheckCompleted() |
| 943 | { |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 944 | m_shouldCallCheckCompleted = true; |
| 945 | startCheckCompleteTimer(); |
beidson | 398923b | 2007-07-31 20:29:02 +0000 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | void FrameLoader::scheduleCheckLoadComplete() |
| 949 | { |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 950 | m_shouldCallCheckLoadComplete = true; |
| 951 | startCheckCompleteTimer(); |
beidson | 398923b | 2007-07-31 20:29:02 +0000 | [diff] [blame] | 952 | } |
| 953 | |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 954 | void FrameLoader::checkCallImplicitClose() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 955 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 956 | if (m_didCallImplicitClose || m_frame.document()->parsing() || m_frame.document()->isDelayingLoadEvent()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 957 | return; |
| 958 | |
darin@apple.com | 4d9d718 | 2009-09-23 00:38:04 +0000 | [diff] [blame] | 959 | if (!allChildrenAreComplete()) |
| 960 | return; // still got a frame running -> too early |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 961 | |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 962 | m_didCallImplicitClose = true; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 963 | m_wasUnloadEventEmitted = false; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 964 | m_frame.document()->implicitClose(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 965 | } |
| 966 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 967 | void FrameLoader::loadURLIntoChildFrame(const URL& url, const String& referer, Frame* childFrame) |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 968 | { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 969 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "loadURLIntoChildFrame: frame load started"); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 970 | |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 971 | ASSERT(childFrame); |
darin@apple.com | a7e141f | 2009-03-06 17:22:07 +0000 | [diff] [blame] | 972 | |
jcivelli@chromium.org | c2019dd | 2011-05-24 19:32:03 +0000 | [diff] [blame] | 973 | #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 974 | if (auto activeLoader = activeDocumentLoader()) { |
| 975 | if (auto subframeArchive = activeLoader->popArchiveForSubframe(childFrame->tree().uniqueName(), url)) { |
| 976 | childFrame->loader().loadArchive(RefPtr<Archive> { subframeArchive }.releaseNonNull()); |
| 977 | return; |
| 978 | } |
mihaip@chromium.org | e5dbd37 | 2010-12-08 02:32:41 +0000 | [diff] [blame] | 979 | } |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 980 | #endif |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 981 | |
darin@apple.com | a7e141f | 2009-03-06 17:22:07 +0000 | [diff] [blame] | 982 | // If we're moving in the back/forward list, we might want to replace the content |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 983 | // of this child frame with whatever was there at that point. |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 984 | auto* parentItem = history().currentItem(); |
| 985 | if (parentItem && parentItem->children().size() && isBackForwardLoadType(loadType()) && !m_frame.document()->loadEventFinished()) { |
| 986 | if (auto* childItem = parentItem->childItemWithTarget(childFrame->tree().uniqueName())) { |
ap@apple.com | 4d286a9 | 2013-08-19 23:41:18 +0000 | [diff] [blame] | 987 | childFrame->loader().m_requestedHistoryItem = childItem; |
cdumez@apple.com | 29f7c1e | 2019-03-13 20:32:48 +0000 | [diff] [blame] | 988 | childFrame->loader().loadDifferentDocumentItem(*childItem, nullptr, loadType(), MayAttemptCacheOnlyLoadForFormSubmissionItem, ShouldTreatAsContinuingLoad::No); |
mihaip@chromium.org | e5dbd37 | 2010-12-08 02:32:41 +0000 | [diff] [blame] | 989 | return; |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 993 | auto* lexicalFrame = lexicalFrameFromCommonVM(); |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 994 | auto initiatedByMainFrame = lexicalFrame && lexicalFrame->isMainFrame() ? InitiatedByMainFrame::Yes : InitiatedByMainFrame::Unknown; |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 995 | |
commit-queue@webkit.org | 1b6bd84 | 2020-04-18 17:04:07 +0000 | [diff] [blame] | 996 | FrameLoadRequest frameLoadRequest { *m_frame.document(), m_frame.document()->securityOrigin(), { url }, "_self"_s, initiatedByMainFrame }; |
| 997 | frameLoadRequest.setNewFrameOpenerPolicy(NewFrameOpenerPolicy::Suppress); |
| 998 | frameLoadRequest.setLockBackForwardList(LockBackForwardList::Yes); |
wilander@apple.com | 6ffdf8f | 2019-02-06 22:02:15 +0000 | [diff] [blame] | 999 | childFrame->loader().loadURL(WTFMove(frameLoadRequest), referer, FrameLoadType::RedirectWithLockedBackForwardList, nullptr, { }, WTF::nullopt, [] { }); |
beidson@apple.com | 47ef96f | 2015-05-29 16:38:13 +0000 | [diff] [blame] | 1000 | } |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 1001 | |
jcivelli@chromium.org | c2019dd | 2011-05-24 19:32:03 +0000 | [diff] [blame] | 1002 | #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 1003 | |
| 1004 | void FrameLoader::loadArchive(Ref<Archive>&& archive) |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 1005 | { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1006 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "loadArchive: frame load started"); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1007 | |
japhet@chromium.org | ac5cd4b | 2012-04-12 19:27:28 +0000 | [diff] [blame] | 1008 | ArchiveResource* mainResource = archive->mainResource(); |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 1009 | ASSERT(mainResource); |
| 1010 | if (!mainResource) |
| 1011 | return; |
beidson@apple.com | ceb7cba | 2015-05-19 22:22:51 +0000 | [diff] [blame] | 1012 | |
jh718.park@samsung.com | 9f99af5 | 2016-03-15 00:22:45 +0000 | [diff] [blame] | 1013 | ResourceResponse response(URL(), mainResource->mimeType(), mainResource->data().size(), mainResource->textEncoding()); |
| 1014 | SubstituteData substituteData(&mainResource->data(), URL(), response, SubstituteData::SessionHistoryVisibility::Hidden); |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 1015 | |
| 1016 | ResourceRequest request(mainResource->url()); |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 1017 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1018 | auto documentLoader = m_client->createDocumentLoader(request, substituteData); |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 1019 | documentLoader->setArchive(WTFMove(archive)); |
achristensen@apple.com | 10e4a7b | 2018-11-28 21:14:43 +0000 | [diff] [blame] | 1020 | load(documentLoader.get()); |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 1021 | } |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 1022 | |
jcivelli@chromium.org | c2019dd | 2011-05-24 19:32:03 +0000 | [diff] [blame] | 1023 | #endif // ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 1024 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1025 | String FrameLoader::outgoingReferrer() const |
| 1026 | { |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 1027 | // See http://www.whatwg.org/specs/web-apps/current-work/#fetching-resources |
| 1028 | // for why we walk the parent chain for srcdoc documents. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1029 | Frame* frame = &m_frame; |
antti@apple.com | 1f5a246 | 2016-12-14 18:54:28 +0000 | [diff] [blame] | 1030 | while (frame && frame->document()->isSrcdocDocument()) { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1031 | frame = frame->tree().parent(); |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 1032 | // Srcdoc documents cannot be top-level documents, by definition, |
| 1033 | // because they need to be contained in iframes with the srcdoc. |
| 1034 | ASSERT(frame); |
| 1035 | } |
antti@apple.com | 1f5a246 | 2016-12-14 18:54:28 +0000 | [diff] [blame] | 1036 | if (!frame) |
| 1037 | return emptyString(); |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 1038 | return frame->loader().m_outgoingReferrer; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
cdumez@apple.com | 1f985b8 | 2020-05-01 23:07:38 +0000 | [diff] [blame] | 1041 | String FrameLoader::outgoingOrigin() const |
| 1042 | { |
| 1043 | return m_frame.document()->securityOrigin().toString(); |
| 1044 | } |
| 1045 | |
dbates@webkit.org | 28db74a | 2016-04-15 22:23:44 +0000 | [diff] [blame] | 1046 | bool FrameLoader::checkIfFormActionAllowedByCSP(const URL& url, bool didReceiveRedirectResponse) const |
commit-queue@webkit.org | 78e860e | 2012-08-16 12:42:09 +0000 | [diff] [blame] | 1047 | { |
| 1048 | if (m_submittedFormURL.isEmpty()) |
| 1049 | return true; |
| 1050 | |
dbates@webkit.org | 28db74a | 2016-04-15 22:23:44 +0000 | [diff] [blame] | 1051 | auto redirectResponseReceived = didReceiveRedirectResponse ? ContentSecurityPolicy::RedirectResponseReceived::Yes : ContentSecurityPolicy::RedirectResponseReceived::No; |
commit-queue@webkit.org | 03af195 | 2016-09-22 08:28:37 +0000 | [diff] [blame] | 1052 | return m_frame.document()->contentSecurityPolicy()->allowFormAction(url, redirectResponseReceived); |
commit-queue@webkit.org | 78e860e | 2012-08-16 12:42:09 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1055 | void FrameLoader::setOpener(Frame* opener) |
| 1056 | { |
creis@chromium.org | 16d76c7 | 2012-12-04 17:39:26 +0000 | [diff] [blame] | 1057 | if (m_opener && !opener) |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1058 | m_client->didDisownOpener(); |
creis@chromium.org | 16d76c7 | 2012-12-04 17:39:26 +0000 | [diff] [blame] | 1059 | |
rniwa@webkit.org | 2c6d4eb | 2017-07-01 21:26:31 +0000 | [diff] [blame] | 1060 | if (m_opener) { |
| 1061 | // When setOpener is called in ~FrameLoader, opener's m_frameLoader is already cleared. |
| 1062 | auto& openerFrameLoader = m_opener == &m_frame ? *this : m_opener->loader(); |
achristensen@apple.com | 2ace43d | 2020-11-05 16:54:48 +0000 | [diff] [blame] | 1063 | openerFrameLoader.m_openedFrames.remove(m_frame); |
rniwa@webkit.org | 2c6d4eb | 2017-07-01 21:26:31 +0000 | [diff] [blame] | 1064 | } |
cdumez@apple.com | 2e47236 | 2018-12-01 22:40:07 +0000 | [diff] [blame] | 1065 | if (opener) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1066 | opener->loader().m_openedFrames.add(&m_frame); |
cdumez@apple.com | 2e47236 | 2018-12-01 22:40:07 +0000 | [diff] [blame] | 1067 | if (auto* page = m_frame.page()) |
| 1068 | page->setOpenedByDOMWithOpener(); |
| 1069 | } |
achristensen@apple.com | 2ace43d | 2020-11-05 16:54:48 +0000 | [diff] [blame] | 1070 | m_opener = makeWeakPtr(opener); |
weinig | 343b6ff | 2007-08-07 03:08:53 +0000 | [diff] [blame] | 1071 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1072 | if (m_frame.document()) |
| 1073 | m_frame.document()->initSecurityContext(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1074 | } |
| 1075 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1076 | void FrameLoader::provisionalLoadStarted() |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 1077 | { |
| 1078 | if (m_stateMachine.firstLayoutDone()) |
| 1079 | m_stateMachine.advanceTo(FrameLoaderStateMachine::CommittedFirstRealLoad); |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 1080 | m_frame.navigationScheduler().cancel(NewLoadInProgress::Yes); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1081 | m_client->provisionalLoadStarted(); |
cdumez@apple.com | ef2c015 | 2017-01-13 17:54:53 +0000 | [diff] [blame] | 1082 | |
| 1083 | if (m_frame.isMainFrame()) { |
sbarati@apple.com | ce7ec11 | 2018-04-17 15:57:32 +0000 | [diff] [blame] | 1084 | tracePoint(MainResourceLoadDidStartProvisional); |
simon.fraser@apple.com | 83325b9 | 2017-03-17 00:47:16 +0000 | [diff] [blame] | 1085 | |
cdumez@apple.com | ef2c015 | 2017-01-13 17:54:53 +0000 | [diff] [blame] | 1086 | if (auto* page = m_frame.page()) |
| 1087 | page->didStartProvisionalLoad(); |
| 1088 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1091 | void FrameLoader::resetMultipleFormSubmissionProtection() |
| 1092 | { |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1093 | m_submittedFormURL = URL(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
abarth@webkit.org | 622d9df | 2009-05-22 16:44:47 +0000 | [diff] [blame] | 1096 | void FrameLoader::updateFirstPartyForCookies() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1097 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1098 | if (m_frame.tree().parent()) |
| 1099 | setFirstPartyForCookies(m_frame.tree().parent()->document()->firstPartyForCookies()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1100 | else |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1101 | setFirstPartyForCookies(m_frame.document()->url()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1104 | void FrameLoader::setFirstPartyForCookies(const URL& url) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1105 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1106 | for (Frame* frame = &m_frame; frame; frame = frame->tree().traverseNext(&m_frame)) |
darin@apple.com | af8b1a9 | 2011-06-25 00:09:37 +0000 | [diff] [blame] | 1107 | frame->document()->setFirstPartyForCookies(url); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 1108 | |
cdumez@apple.com | 0b8674fb | 2019-03-13 19:53:41 +0000 | [diff] [blame] | 1109 | RegistrableDomain registrableDomain(url); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 1110 | for (Frame* frame = &m_frame; frame; frame = frame->tree().traverseNext(&m_frame)) { |
cdumez@apple.com | 0b8674fb | 2019-03-13 19:53:41 +0000 | [diff] [blame] | 1111 | if (SecurityPolicy::shouldInheritSecurityOriginFromOwner(frame->document()->url()) || registrableDomain.matches(frame->document()->url())) |
dbates@webkit.org | 940f0b8 | 2018-07-24 16:27:25 +0000 | [diff] [blame] | 1112 | frame->document()->setSiteForCookies(url); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 1113 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
darin@apple.com | d69216d | 2008-03-11 00:45:47 +0000 | [diff] [blame] | 1116 | // This does the same kind of work that didOpenURL does, except it relies on the fact |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1117 | // that a higher level already checked that the URLs match and the scrolling is the right thing to do. |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 1118 | void FrameLoader::loadInSameDocument(const URL& url, SerializedScriptValue* stateObject, bool isNewNavigation) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1119 | { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1120 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "loadInSameDocument: frame load started"); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1121 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1122 | // If we have a state object, we cannot also be a new navigation. |
| 1123 | ASSERT(!stateObject || (stateObject && !isNewNavigation)); |
| 1124 | |
| 1125 | // Update the data source's request with the new URL to fake the URL change |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1126 | URL oldURL = m_frame.document()->url(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1127 | m_frame.document()->setURL(url); |
jochen@chromium.org | 7495f96 | 2012-05-04 16:43:03 +0000 | [diff] [blame] | 1128 | setOutgoingReferrer(url); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1129 | documentLoader()->replaceRequestURLForSameDocumentNavigation(url); |
| 1130 | if (isNewNavigation && !shouldTreatURLAsSameAsCurrent(url) && !stateObject) { |
| 1131 | // NB: must happen after replaceRequestURLForSameDocumentNavigation(), since we add |
| 1132 | // based on the current request. Must also happen before we openURL and displace the |
| 1133 | // scroll position, since adding the BF item will save away scroll state. |
| 1134 | |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 1135 | // NB2: If we were loading a long, slow doc, and the user fragment navigated before |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1136 | // it was done, currItem is now set the that slow doc, and prevItem is whatever was |
| 1137 | // before it. Adding the b/f item will bump the slow doc down to prevItem, even |
| 1138 | // though its load is not yet done. I think this all works out OK, for one because |
| 1139 | // we have already saved away the scroll and doc state for the long slow load, |
| 1140 | // but it's not an obvious case. |
| 1141 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 1142 | history().updateBackForwardListForFragmentScroll(); |
beidson@apple.com | 8127cdc | 2009-08-07 15:35:19 +0000 | [diff] [blame] | 1143 | } |
darin@apple.com | 1e231d5 | 2020-04-25 18:01:55 +0000 | [diff] [blame] | 1144 | |
| 1145 | bool hashChange = equalIgnoringFragmentIdentifier(url, oldURL) && !equalRespectingNullity(url.fragmentIdentifier(), oldURL.fragmentIdentifier()); |
| 1146 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 1147 | history().updateForSameDocumentNavigation(); |
britto@apple.com | 195cc0b | 2008-07-23 16:48:47 +0000 | [diff] [blame] | 1148 | |
| 1149 | // If we were in the autoscroll/panScroll mode we want to stop it before following the link to the anchor |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1150 | if (hashChange) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1151 | m_frame.eventHandler().stopAutoscrollTimer(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1152 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1153 | // It's important to model this as a load that starts and immediately finishes. |
| 1154 | // Otherwise, the parent frame may think we never finished loading. |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1155 | started(); |
japhet@chromium.org | 48bb260 | 2010-03-04 23:01:45 +0000 | [diff] [blame] | 1156 | |
dbates@webkit.org | 86a1c67 | 2018-08-10 17:39:53 +0000 | [diff] [blame] | 1157 | if (auto* ownerElement = m_frame.ownerElement()) { |
| 1158 | auto* ownerRenderer = ownerElement->renderer(); |
| 1159 | auto* view = m_frame.view(); |
| 1160 | if (is<RenderWidget>(ownerRenderer) && view) |
| 1161 | downcast<RenderWidget>(*ownerRenderer).setWidget(view); |
| 1162 | } |
| 1163 | |
japhet@chromium.org | 48bb260 | 2010-03-04 23:01:45 +0000 | [diff] [blame] | 1164 | // We need to scroll to the fragment whether or not a hash change occurred, since |
| 1165 | // the user might have scrolled since the previous navigation. |
simon.fraser@apple.com | c79e486 | 2017-03-08 20:01:15 +0000 | [diff] [blame] | 1166 | scrollToFragmentWithParentBoundary(url, isNewNavigation); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1167 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1168 | m_isComplete = false; |
| 1169 | checkCompleted(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1170 | |
| 1171 | if (isNewNavigation) { |
| 1172 | // This will clear previousItem from the rest of the frame tree that didn't |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 1173 | // doing any loading. We need to make a pass on this now, since for fragment |
| 1174 | // navigation we'll not go through a real load and reach Completed state. |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1175 | checkLoadComplete(); |
| 1176 | } |
| 1177 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1178 | m_client->dispatchDidNavigateWithinPage(); |
darin@chromium.org | fe27996 | 2010-03-16 17:26:59 +0000 | [diff] [blame] | 1179 | |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 1180 | m_frame.document()->statePopped(stateObject ? Ref<SerializedScriptValue> { *stateObject } : SerializedScriptValue::nullValue()); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1181 | m_client->dispatchDidPopStateWithinPage(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1182 | |
| 1183 | if (hashChange) { |
commit-queue@webkit.org | 39359f0 | 2020-04-25 21:28:45 +0000 | [diff] [blame] | 1184 | m_frame.document()->enqueueHashchangeEvent(oldURL.string(), url.string()); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1185 | m_client->dispatchDidChangeLocationWithinPage(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | // FrameLoaderClient::didFinishLoad() tells the internal load delegate the load finished with no error |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1189 | m_client->didFinishLoad(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | bool FrameLoader::isComplete() const |
| 1193 | { |
| 1194 | return m_isComplete; |
| 1195 | } |
| 1196 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1197 | void FrameLoader::completed() |
| 1198 | { |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 1199 | Ref<Frame> protect(m_frame); |
beidson@apple.com | a566251 | 2009-10-27 00:19:33 +0000 | [diff] [blame] | 1200 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1201 | for (Frame* descendant = m_frame.tree().traverseNext(&m_frame); descendant; descendant = descendant->tree().traverseNext(&m_frame)) |
akling@apple.com | 9ce995f | 2013-08-21 20:54:20 +0000 | [diff] [blame] | 1202 | descendant->navigationScheduler().startTimer(); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 1203 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1204 | if (Frame* parent = m_frame.tree().parent()) |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 1205 | parent->loader().checkCompleted(); |
beidson@apple.com | a566251 | 2009-10-27 00:19:33 +0000 | [diff] [blame] | 1206 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1207 | if (m_frame.view()) |
mmaxfield@apple.com | 6ebeece | 2014-12-09 21:03:54 +0000 | [diff] [blame] | 1208 | m_frame.view()->maintainScrollPositionAtAnchor(nullptr); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | void FrameLoader::started() |
| 1212 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1213 | for (Frame* frame = &m_frame; frame; frame = frame->tree().parent()) |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 1214 | frame->loader().m_isComplete = false; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1215 | } |
| 1216 | |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 1217 | void FrameLoader::prepareForLoadStart() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1218 | { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1219 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "prepareForLoadStart: Starting frame load"); |
commit-queue@webkit.org | 6d63522 | 2016-03-08 06:44:59 +0000 | [diff] [blame] | 1220 | |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 1221 | m_progressTracker->progressStarted(); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1222 | m_client->dispatchDidStartProvisionalLoad(); |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 1223 | |
| 1224 | if (AXObjectCache::accessibilityEnabled()) { |
| 1225 | if (AXObjectCache* cache = m_frame.document()->existingAXObjectCache()) { |
| 1226 | AXObjectCache::AXLoadingEvent loadingEvent = loadType() == FrameLoadType::Reload ? AXObjectCache::AXLoadingReloaded : AXObjectCache::AXLoadingStarted; |
| 1227 | cache->frameLoadingEventNotification(&m_frame, loadingEvent); |
ossy@webkit.org | 451e9b0 | 2014-01-27 12:40:18 +0000 | [diff] [blame] | 1228 | } |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 1229 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | void FrameLoader::setupForReplace() |
| 1233 | { |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1234 | m_client->revertToProvisionalState(m_documentLoader.get()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1235 | setState(FrameStateProvisional); |
| 1236 | m_provisionalDocumentLoader = m_documentLoader; |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1237 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "setupForReplace: Setting provisional document loader (m_provisionalDocumentLoader=%p)", m_provisionalDocumentLoader.get()); |
cdumez@apple.com | d839ea1 | 2015-07-04 19:42:18 +0000 | [diff] [blame] | 1238 | m_documentLoader = nullptr; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1239 | detachChildren(); |
| 1240 | } |
| 1241 | |
commit-queue@webkit.org | f271985 | 2020-11-11 04:55:57 +0000 | [diff] [blame^] | 1242 | void FrameLoader::loadFrameRequest(FrameLoadRequest&& request, Event* event, RefPtr<FormState>&& formState, Optional<AdClickAttribution>&& adClickAttribution) |
dbates@webkit.org | 2990852 | 2017-01-07 07:14:03 +0000 | [diff] [blame] | 1243 | { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1244 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "loadFrameRequest: frame load started"); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1245 | |
inferno@chromium.org | 670ab75 | 2011-07-13 18:51:44 +0000 | [diff] [blame] | 1246 | // Protect frame from getting blown away inside dispatchBeforeLoadEvent in loadWithDocumentLoader. |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 1247 | auto protectFrame = makeRef(m_frame); |
inferno@chromium.org | 670ab75 | 2011-07-13 18:51:44 +0000 | [diff] [blame] | 1248 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1249 | URL url = request.resourceRequest().url(); |
antti@apple.com | c633dca | 2008-11-14 21:34:55 +0000 | [diff] [blame] | 1250 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1251 | ASSERT(m_frame.document()); |
dbates@webkit.org | 174ac71 | 2017-06-30 21:35:23 +0000 | [diff] [blame] | 1252 | if (!request.requesterSecurityOrigin().canDisplay(url)) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1253 | reportLocalLoadFailed(&m_frame, url.stringCenterEllipsizedToLength()); |
darin@apple.com | 1cf3d56 | 2010-12-07 16:23:03 +0000 | [diff] [blame] | 1254 | return; |
| 1255 | } |
| 1256 | |
darin | 5a1e60e | 2007-04-17 19:58:16 +0000 | [diff] [blame] | 1257 | String argsReferrer = request.resourceRequest().httpReferrer(); |
jochen@chromium.org | 4761ef5 | 2011-11-21 10:29:55 +0000 | [diff] [blame] | 1258 | if (argsReferrer.isEmpty()) |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 1259 | argsReferrer = outgoingReferrer(); |
antti@apple.com | c633dca | 2008-11-14 21:34:55 +0000 | [diff] [blame] | 1260 | |
commit-queue@webkit.org | 8383b5f | 2020-03-02 11:36:00 +0000 | [diff] [blame] | 1261 | ReferrerPolicy referrerPolicy = request.referrerPolicy(); |
| 1262 | if (referrerPolicy == ReferrerPolicy::EmptyString) |
| 1263 | referrerPolicy = m_frame.document()->referrerPolicy(); |
| 1264 | String referrer = SecurityPolicy::generateReferrerHeader(referrerPolicy, url, argsReferrer); |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 1265 | |
ggaren@apple.com | 78b4dc6 | 2009-01-30 23:09:43 +0000 | [diff] [blame] | 1266 | FrameLoadType loadType; |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 1267 | if (request.resourceRequest().cachePolicy() == ResourceRequestCachePolicy::ReloadIgnoringCacheData) |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1268 | loadType = FrameLoadType::Reload; |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 1269 | else if (request.lockBackForwardList() == LockBackForwardList::Yes) |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1270 | loadType = FrameLoadType::RedirectWithLockedBackForwardList; |
ggaren@apple.com | 78b4dc6 | 2009-01-30 23:09:43 +0000 | [diff] [blame] | 1271 | else |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1272 | loadType = FrameLoadType::Standard; |
ggaren@apple.com | 78b4dc6 | 2009-01-30 23:09:43 +0000 | [diff] [blame] | 1273 | |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 1274 | auto completionHandler = [this, protectedFrame = makeRef(m_frame), formState = makeWeakPtr(formState.get()), frameName = request.frameName()] { |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 1275 | // FIXME: It's possible this targetFrame will not be the same frame that was targeted by the actual |
| 1276 | // load if frame names have changed. |
| 1277 | Frame* sourceFrame = formState ? formState->sourceDocument().frame() : &m_frame; |
| 1278 | if (!sourceFrame) |
| 1279 | sourceFrame = &m_frame; |
| 1280 | Frame* targetFrame = sourceFrame->loader().findFrameForNavigation(frameName); |
| 1281 | if (targetFrame && targetFrame != sourceFrame) { |
| 1282 | if (Page* page = targetFrame->page()) |
| 1283 | page->chrome().focus(); |
| 1284 | } |
| 1285 | }; |
ggaren@apple.com | 78b4dc6 | 2009-01-30 23:09:43 +0000 | [diff] [blame] | 1286 | |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 1287 | if (request.resourceRequest().httpMethod() == "POST") |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 1288 | loadPostRequest(WTFMove(request), referrer, loadType, event, WTFMove(formState), WTFMove(completionHandler)); |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 1289 | else |
commit-queue@webkit.org | f271985 | 2020-11-11 04:55:57 +0000 | [diff] [blame^] | 1290 | loadURL(WTFMove(request), referrer, loadType, event, WTFMove(formState), WTFMove(adClickAttribution), WTFMove(completionHandler)); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1291 | } |
ddkilzer@apple.com | e6e7d42 | 2008-08-06 21:15:39 +0000 | [diff] [blame] | 1292 | |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 1293 | static ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicyToApply(Frame& currentFrame, InitiatedByMainFrame initiatedByMainFrame, ShouldOpenExternalURLsPolicy propagatedPolicy) |
mitz@apple.com | c99c715 | 2015-07-17 21:16:09 +0000 | [diff] [blame] | 1294 | { |
commit-queue@webkit.org | 635dbdc | 2017-11-23 19:36:08 +0000 | [diff] [blame] | 1295 | if (UserGestureIndicator::processingUserGesture()) |
mitz@apple.com | c99c715 | 2015-07-17 21:16:09 +0000 | [diff] [blame] | 1296 | return ShouldOpenExternalURLsPolicy::ShouldAllow; |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1297 | |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 1298 | if (initiatedByMainFrame == InitiatedByMainFrame::Yes) |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1299 | return propagatedPolicy; |
| 1300 | |
| 1301 | if (!currentFrame.isMainFrame()) |
| 1302 | return ShouldOpenExternalURLsPolicy::ShouldNotAllow; |
| 1303 | |
mitz@apple.com | c99c715 | 2015-07-17 21:16:09 +0000 | [diff] [blame] | 1304 | return propagatedPolicy; |
| 1305 | } |
| 1306 | |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1307 | static ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicyToApply(Frame& currentFrame, const FrameLoadRequest& frameLoadRequest) |
| 1308 | { |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 1309 | return shouldOpenExternalURLsPolicyToApply(currentFrame, frameLoadRequest.initiatedByMainFrame(), frameLoadRequest.shouldOpenExternalURLsPolicy()); |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 1312 | static void applyShouldOpenExternalURLsPolicyToNewDocumentLoader(Frame& frame, DocumentLoader& documentLoader, InitiatedByMainFrame initiatedByMainFrame, ShouldOpenExternalURLsPolicy propagatedPolicy) |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1313 | { |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 1314 | documentLoader.setShouldOpenExternalURLsPolicy(shouldOpenExternalURLsPolicyToApply(frame, initiatedByMainFrame, propagatedPolicy)); |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | static void applyShouldOpenExternalURLsPolicyToNewDocumentLoader(Frame& frame, DocumentLoader& documentLoader, const FrameLoadRequest& frameLoadRequest) |
| 1318 | { |
| 1319 | documentLoader.setShouldOpenExternalURLsPolicy(shouldOpenExternalURLsPolicyToApply(frame, frameLoadRequest)); |
| 1320 | } |
| 1321 | |
dbates@webkit.org | 872db61 | 2017-03-20 23:07:50 +0000 | [diff] [blame] | 1322 | bool FrameLoader::isNavigationAllowed() const |
| 1323 | { |
beidson@apple.com | b457130 | 2019-08-08 15:54:37 +0000 | [diff] [blame] | 1324 | return m_pageDismissalEventBeingDispatched == PageDismissalType::None && !m_frame.script().willReplaceWithResultOfExecutingJavascriptURL() && NavigationDisabler::isNavigationAllowed(m_frame); |
dbates@webkit.org | 872db61 | 2017-03-20 23:07:50 +0000 | [diff] [blame] | 1325 | } |
| 1326 | |
pvollan@apple.com | 8f4bcd95 | 2018-02-01 04:18:38 +0000 | [diff] [blame] | 1327 | bool FrameLoader::isStopLoadingAllowed() const |
| 1328 | { |
| 1329 | return m_pageDismissalEventBeingDispatched == PageDismissalType::None; |
| 1330 | } |
| 1331 | |
commit-queue@webkit.org | f271985 | 2020-11-11 04:55:57 +0000 | [diff] [blame^] | 1332 | void FrameLoader::loadURL(FrameLoadRequest&& frameLoadRequest, const String& referrer, FrameLoadType newLoadType, Event* event, RefPtr<FormState>&& formState, Optional<AdClickAttribution>&& adClickAttribution, CompletionHandler<void()>&& completionHandler) |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1333 | { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1334 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "loadURL: frame load started"); |
commit-queue@webkit.org | 8a13ad3 | 2020-03-16 08:11:26 +0000 | [diff] [blame] | 1335 | ASSERT(frameLoadRequest.resourceRequest().httpMethod() == "GET"); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1336 | |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 1337 | CompletionHandlerCallingScope completionHandlerCaller(WTFMove(completionHandler)); |
cdumez@apple.com | 8ace63b | 2018-06-29 22:56:29 +0000 | [diff] [blame] | 1338 | if (m_inStopAllLoaders || m_inClearProvisionalLoadForPolicyCheck) |
commit-queue@webkit.org | cd5cda2 | 2011-02-15 15:55:21 +0000 | [diff] [blame] | 1339 | return; |
| 1340 | |
jpfau@apple.com | 18da22e | 2014-06-19 00:20:25 +0000 | [diff] [blame] | 1341 | Ref<Frame> protect(m_frame); |
| 1342 | |
cdumez@apple.com | 3ed2674 | 2018-10-09 23:21:18 +0000 | [diff] [blame] | 1343 | // Anchor target is ignored when the download attribute is set since it will download the hyperlink rather than follow it. |
| 1344 | String effectiveFrameName = frameLoadRequest.downloadAttribute().isNull() ? frameLoadRequest.frameName() : String(); |
andersca | 3513ce0 | 2007-05-17 08:38:44 +0000 | [diff] [blame] | 1345 | bool isFormSubmission = formState; |
beidson@apple.com | bd66a78 | 2015-05-29 16:31:49 +0000 | [diff] [blame] | 1346 | |
commit-queue@webkit.org | a622774 | 2020-04-21 10:31:08 +0000 | [diff] [blame] | 1347 | // The search for a target frame is done earlier in the case of form submission. |
| 1348 | auto targetFrame = isFormSubmission ? nullptr : makeRefPtr(findFrameForNavigation(effectiveFrameName)); |
| 1349 | if (targetFrame && targetFrame != &m_frame) { |
| 1350 | frameLoadRequest.setFrameName("_self"); |
commit-queue@webkit.org | f271985 | 2020-11-11 04:55:57 +0000 | [diff] [blame^] | 1351 | targetFrame->loader().loadURL(WTFMove(frameLoadRequest), referrer, newLoadType, event, WTFMove(formState), WTFMove(adClickAttribution), completionHandlerCaller.release()); |
commit-queue@webkit.org | a622774 | 2020-04-21 10:31:08 +0000 | [diff] [blame] | 1352 | return; |
| 1353 | } |
| 1354 | |
beidson@apple.com | bd66a78 | 2015-05-29 16:31:49 +0000 | [diff] [blame] | 1355 | const URL& newURL = frameLoadRequest.resourceRequest().url(); |
weinig@apple.com | c500266 | 2007-12-12 07:26:19 +0000 | [diff] [blame] | 1356 | ResourceRequest request(newURL); |
commit-queue@webkit.org | 3480786 | 2020-03-29 17:34:16 +0000 | [diff] [blame] | 1357 | if (!referrer.isEmpty()) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1358 | request.setHTTPReferrer(referrer); |
commit-queue@webkit.org | 3480786 | 2020-03-29 17:34:16 +0000 | [diff] [blame] | 1359 | |
commit-queue@webkit.org | 627a2de | 2020-04-13 08:04:39 +0000 | [diff] [blame] | 1360 | addExtraFieldsToRequest(request, IsMainResource::Yes, newLoadType); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1361 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1362 | ASSERT(newLoadType != FrameLoadType::Same); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1363 | |
dbates@webkit.org | 872db61 | 2017-03-20 23:07:50 +0000 | [diff] [blame] | 1364 | if (!isNavigationAllowed()) |
eric@webkit.org | 6cae31a | 2009-09-26 02:35:15 +0000 | [diff] [blame] | 1365 | return; |
| 1366 | |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 1367 | NavigationAction action { frameLoadRequest.requester(), request, frameLoadRequest.initiatedByMainFrame(), newLoadType, isFormSubmission, event, frameLoadRequest.shouldOpenExternalURLsPolicy(), frameLoadRequest.downloadAttribute() }; |
commit-queue@webkit.org | a622774 | 2020-04-21 10:31:08 +0000 | [diff] [blame] | 1368 | action.setLockHistory(frameLoadRequest.lockHistory()); |
cdumez@apple.com | 05911a3 | 2018-10-23 17:54:34 +0000 | [diff] [blame] | 1369 | action.setLockBackForwardList(frameLoadRequest.lockBackForwardList()); |
commit-queue@webkit.org | f271985 | 2020-11-11 04:55:57 +0000 | [diff] [blame^] | 1370 | if (adClickAttribution && m_frame.isMainFrame()) |
| 1371 | action.setAdClickAttribution(WTFMove(*adClickAttribution)); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1372 | |
commit-queue@webkit.org | a622774 | 2020-04-21 10:31:08 +0000 | [diff] [blame] | 1373 | NewFrameOpenerPolicy openerPolicy = frameLoadRequest.newFrameOpenerPolicy(); |
| 1374 | AllowNavigationToInvalidURL allowNavigationToInvalidURL = frameLoadRequest.allowNavigationToInvalidURL(); |
cdumez@apple.com | 3ed2674 | 2018-10-09 23:21:18 +0000 | [diff] [blame] | 1375 | if (!targetFrame && !effectiveFrameName.isEmpty()) { |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1376 | action = action.copyWithShouldOpenExternalURLsPolicy(shouldOpenExternalURLsPolicyToApply(m_frame, frameLoadRequest)); |
commit-queue@webkit.org | 57af63c | 2020-04-29 10:23:01 +0000 | [diff] [blame] | 1377 | policyChecker().checkNewWindowPolicy(WTFMove(action), WTFMove(request), WTFMove(formState), effectiveFrameName, [this, allowNavigationToInvalidURL, openerPolicy, completionHandler = completionHandlerCaller.release()] (const ResourceRequest& request, WeakPtr<FormState>&& formState, const String& frameName, const NavigationAction& action, ShouldContinuePolicyCheck shouldContinue) mutable { |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 1378 | continueLoadAfterNewWindowPolicy(request, formState.get(), frameName, action, shouldContinue, allowNavigationToInvalidURL, openerPolicy); |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 1379 | completionHandler(); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1380 | }); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1381 | return; |
| 1382 | } |
| 1383 | |
| 1384 | RefPtr<DocumentLoader> oldDocumentLoader = m_documentLoader; |
| 1385 | |
weinig@apple.com | c500266 | 2007-12-12 07:26:19 +0000 | [diff] [blame] | 1386 | bool sameURL = shouldTreatURLAsSameAsCurrent(newURL); |
yael.aharon@nokia.com | 79f6905 | 2010-12-30 19:31:00 +0000 | [diff] [blame] | 1387 | const String& httpMethod = request.httpMethod(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1388 | |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 1389 | // Make sure to do scroll to fragment processing even if the URL is |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1390 | // exactly the same so pages with '#' links and DHTML side effects |
| 1391 | // work properly. |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 1392 | if (shouldPerformFragmentNavigation(isFormSubmission, httpMethod, newLoadType, newURL)) { |
cdumez@apple.com | 91e03bd | 2018-09-17 17:15:07 +0000 | [diff] [blame] | 1393 | oldDocumentLoader->setTriggeringAction(WTFMove(action)); |
andersca@apple.com | 97ab6d9 | 2013-10-21 22:55:14 +0000 | [diff] [blame] | 1394 | oldDocumentLoader->setLastCheckedRequest(ResourceRequest()); |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1395 | policyChecker().stopCheck(); |
| 1396 | policyChecker().setLoadType(newLoadType); |
rniwa@webkit.org | ba12a01 | 2019-02-03 22:48:22 +0000 | [diff] [blame] | 1397 | RELEASE_ASSERT(!isBackForwardLoadType(newLoadType) || history().provisionalItem()); |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 1398 | policyChecker().checkNavigationPolicy(WTFMove(request), ResourceResponse { } /* redirectResponse */, oldDocumentLoader.get(), WTFMove(formState), [this, protectedFrame = makeRef(m_frame)] (const ResourceRequest& request, WeakPtr<FormState>&&, NavigationPolicyDecision navigationPolicyDecision) { |
| 1399 | continueFragmentScrollAfterNavigationPolicy(request, navigationPolicyDecision == NavigationPolicyDecision::ContinueLoad); |
cdumez@apple.com | 8221194 | 2018-04-17 18:13:49 +0000 | [diff] [blame] | 1400 | }, PolicyDecisionMode::Synchronous); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1401 | return; |
| 1402 | } |
| 1403 | |
dino@apple.com | b8e413d | 2018-05-08 20:12:24 +0000 | [diff] [blame] | 1404 | // Must grab this now, since this load may stop the previous load and clear this flag. |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1405 | bool isRedirect = m_quickRedirectComing; |
dino@apple.com | 0bebb3a | 2018-05-22 23:56:01 +0000 | [diff] [blame] | 1406 | #if USE(SYSTEM_PREVIEW) |
| 1407 | bool isSystemPreview = frameLoadRequest.isSystemPreview(); |
dino@apple.com | 0bebb3a | 2018-05-22 23:56:01 +0000 | [diff] [blame] | 1408 | if (isSystemPreview) |
dino@apple.com | ddfbca8 | 2019-09-13 21:43:18 +0000 | [diff] [blame] | 1409 | request.setSystemPreviewInfo(frameLoadRequest.systemPreviewInfo()); |
dino@apple.com | 0bebb3a | 2018-05-22 23:56:01 +0000 | [diff] [blame] | 1410 | #endif |
commit-queue@webkit.org | bed33c6 | 2020-04-28 20:41:35 +0000 | [diff] [blame] | 1411 | loadWithNavigationAction(request, WTFMove(action), newLoadType, WTFMove(formState), allowNavigationToInvalidURL, [this, isRedirect, sameURL, newLoadType, protectedFrame = makeRef(m_frame), completionHandler = completionHandlerCaller.release()] () mutable { |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 1412 | if (isRedirect) { |
| 1413 | m_quickRedirectComing = false; |
| 1414 | if (m_provisionalDocumentLoader) |
| 1415 | m_provisionalDocumentLoader->setIsClientRedirect(true); |
| 1416 | else if (m_policyDocumentLoader) |
| 1417 | m_policyDocumentLoader->setIsClientRedirect(true); |
| 1418 | } else if (sameURL && !isReload(newLoadType)) { |
| 1419 | // Example of this case are sites that reload the same URL with a different cookie |
| 1420 | // driving the generated content, or a master frame with links that drive a target |
| 1421 | // frame, where the user has clicked on the same link repeatedly. |
| 1422 | m_loadType = FrameLoadType::Same; |
| 1423 | } |
| 1424 | completionHandler(); |
| 1425 | }); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1428 | SubstituteData FrameLoader::defaultSubstituteDataForURL(const URL& url) |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 1429 | { |
| 1430 | if (!shouldTreatURLAsSrcdocDocument(url)) |
| 1431 | return SubstituteData(); |
darin@apple.com | f9da7a7 | 2017-06-04 18:19:16 +0000 | [diff] [blame] | 1432 | auto& srcdoc = m_frame.ownerElement()->attributeWithoutSynchronization(srcdocAttr); |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 1433 | ASSERT(!srcdoc.isNull()); |
darin@apple.com | f9da7a7 | 2017-06-04 18:19:16 +0000 | [diff] [blame] | 1434 | CString encodedSrcdoc = srcdoc.string().utf8(); |
beidson@apple.com | ceb7cba | 2015-05-19 22:22:51 +0000 | [diff] [blame] | 1435 | |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 1436 | ResourceResponse response(URL(), "text/html"_s, encodedSrcdoc.length(), "UTF-8"_s); |
beidson@apple.com | ceb7cba | 2015-05-19 22:22:51 +0000 | [diff] [blame] | 1437 | return SubstituteData(SharedBuffer::create(encodedSrcdoc.data(), encodedSrcdoc.length()), URL(), response, SubstituteData::SessionHistoryVisibility::Hidden); |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
dbates@webkit.org | 7f3a982 | 2017-06-22 19:45:10 +0000 | [diff] [blame] | 1440 | void FrameLoader::load(FrameLoadRequest&& request) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1441 | { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1442 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "load (FrameLoadRequest): frame load started"); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1443 | |
cdumez@apple.com | 8ace63b | 2018-06-29 22:56:29 +0000 | [diff] [blame] | 1444 | if (m_inStopAllLoaders || m_inClearProvisionalLoadForPolicyCheck) |
andersca | 8567b3d | 2007-03-21 05:46:49 +0000 | [diff] [blame] | 1445 | return; |
simonjam@chromium.org | c98850b | 2012-11-28 01:07:36 +0000 | [diff] [blame] | 1446 | |
| 1447 | if (!request.frameName().isEmpty()) { |
| 1448 | Frame* frame = findFrameForNavigation(request.frameName()); |
| 1449 | if (frame) { |
| 1450 | request.setShouldCheckNewWindowPolicy(false); |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 1451 | if (&frame->loader() != this) { |
dbates@webkit.org | 7f3a982 | 2017-06-22 19:45:10 +0000 | [diff] [blame] | 1452 | frame->loader().load(WTFMove(request)); |
simonjam@chromium.org | c98850b | 2012-11-28 01:07:36 +0000 | [diff] [blame] | 1453 | return; |
| 1454 | } |
| 1455 | } |
| 1456 | } |
| 1457 | |
| 1458 | if (request.shouldCheckNewWindowPolicy()) { |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 1459 | NavigationAction action { request.requester(), request.resourceRequest(), InitiatedByMainFrame::Unknown, NavigationType::Other, request.shouldOpenExternalURLsPolicy() }; |
commit-queue@webkit.org | 57af63c | 2020-04-29 10:23:01 +0000 | [diff] [blame] | 1460 | policyChecker().checkNewWindowPolicy(WTFMove(action), WTFMove(request.resourceRequest()), { }, request.frameName(), [this] (const ResourceRequest& request, WeakPtr<FormState>&& formState, const String& frameName, const NavigationAction& action, ShouldContinuePolicyCheck shouldContinue) { |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 1461 | continueLoadAfterNewWindowPolicy(request, formState.get(), frameName, action, shouldContinue, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Suppress); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1462 | }); |
| 1463 | |
simonjam@chromium.org | c98850b | 2012-11-28 01:07:36 +0000 | [diff] [blame] | 1464 | return; |
| 1465 | } |
| 1466 | |
| 1467 | if (!request.hasSubstituteData()) |
| 1468 | request.setSubstituteData(defaultSubstituteDataForURL(request.resourceRequest().url())); |
| 1469 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1470 | Ref<DocumentLoader> loader = m_client->createDocumentLoader(request.resourceRequest(), request.substituteData()); |
jiewen_tan@apple.com | 32abaa6 | 2019-02-13 23:07:13 +0000 | [diff] [blame] | 1471 | loader->setAllowsWebArchiveForMainFrame(request.isRequestFromClientOrUserInput()); |
bfulgham@apple.com | 2eaf0ac | 2020-02-06 17:32:18 +0000 | [diff] [blame] | 1472 | loader->setAllowsDataURLsForMainFrame(request.isRequestFromClientOrUserInput()); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 1473 | addSameSiteInfoToRequestIfNeeded(loader->request()); |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1474 | applyShouldOpenExternalURLsPolicyToNewDocumentLoader(m_frame, loader, request); |
beidson@apple.com | d055853 | 2015-05-28 04:52:25 +0000 | [diff] [blame] | 1475 | |
cdumez@apple.com | 4353b6e | 2018-10-26 05:06:24 +0000 | [diff] [blame] | 1476 | if (request.shouldTreatAsContinuingLoad()) { |
cdumez@apple.com | 05911a3 | 2018-10-23 17:54:34 +0000 | [diff] [blame] | 1477 | loader->setClientRedirectSourceForHistory(request.clientRedirectSourceForHistory()); |
cdumez@apple.com | 4353b6e | 2018-10-26 05:06:24 +0000 | [diff] [blame] | 1478 | if (request.lockBackForwardList() == LockBackForwardList::Yes) { |
| 1479 | loader->setIsClientRedirect(true); |
| 1480 | m_loadType = FrameLoadType::RedirectWithLockedBackForwardList; |
| 1481 | } |
cdumez@apple.com | 05911a3 | 2018-10-23 17:54:34 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
cdumez@apple.com | 3aedc03 | 2019-01-31 02:23:55 +0000 | [diff] [blame] | 1484 | SetForScope<LoadContinuingState> continuingLoadGuard(m_currentLoadContinuingState, request.shouldTreatAsContinuingLoad() ? LoadContinuingState::ContinuingWithRequest : LoadContinuingState::NotContinuing); |
achristensen@apple.com | 10e4a7b | 2018-11-28 21:14:43 +0000 | [diff] [blame] | 1485 | load(loader.get()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1486 | } |
| 1487 | |
commit-queue@webkit.org | bed33c6 | 2020-04-28 20:41:35 +0000 | [diff] [blame] | 1488 | void FrameLoader::loadWithNavigationAction(const ResourceRequest& request, NavigationAction&& action, FrameLoadType type, RefPtr<FormState>&& formState, AllowNavigationToInvalidURL allowNavigationToInvalidURL, CompletionHandler<void()>&& completionHandler) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1489 | { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1490 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "loadWithNavigationAction: frame load started"); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1491 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1492 | Ref<DocumentLoader> loader = m_client->createDocumentLoader(request, defaultSubstituteDataForURL(request.url())); |
dbates@webkit.org | 9692a07 | 2017-07-12 18:01:19 +0000 | [diff] [blame] | 1493 | applyShouldOpenExternalURLsPolicyToNewDocumentLoader(m_frame, loader, action.initiatedByMainFrame(), action.shouldOpenExternalURLsPolicy()); |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 1494 | |
commit-queue@webkit.org | 4a7ad28 | 2020-04-05 05:09:42 +0000 | [diff] [blame] | 1495 | if (action.lockHistory() == LockHistory::Yes && m_documentLoader) |
commit-queue@webkit.org | 63040d0 | 2011-03-26 00:30:40 +0000 | [diff] [blame] | 1496 | loader->setClientRedirectSourceForHistory(m_documentLoader->didCreateGlobalHistoryEntry() ? m_documentLoader->urlForHistory().string() : m_documentLoader->clientRedirectSourceForHistory()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1497 | |
cdumez@apple.com | 91e03bd | 2018-09-17 17:15:07 +0000 | [diff] [blame] | 1498 | loader->setTriggeringAction(WTFMove(action)); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1499 | if (m_documentLoader) |
| 1500 | loader->setOverrideEncoding(m_documentLoader->overrideEncoding()); |
| 1501 | |
commit-queue@webkit.org | 372c264 | 2020-04-03 16:53:48 +0000 | [diff] [blame] | 1502 | loadWithDocumentLoader(loader.ptr(), type, WTFMove(formState), allowNavigationToInvalidURL, WTFMove(completionHandler)); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
achristensen@apple.com | 10e4a7b | 2018-11-28 21:14:43 +0000 | [diff] [blame] | 1505 | void FrameLoader::load(DocumentLoader& newDocumentLoader) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1506 | { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1507 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "load (DocumentLoader): frame load started"); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1508 | |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1509 | ResourceRequest& r = newDocumentLoader.request(); |
commit-queue@webkit.org | 53c0a6b | 2020-04-02 07:43:14 +0000 | [diff] [blame] | 1510 | // FIXME: Using m_loadType seems wrong here. |
| 1511 | // If we are only preparing to load the main resource, that is previous load's load type! |
commit-queue@webkit.org | 627a2de | 2020-04-13 08:04:39 +0000 | [diff] [blame] | 1512 | addExtraFieldsToRequest(r, IsMainResource::Yes, m_loadType); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1513 | FrameLoadType type; |
| 1514 | |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1515 | if (shouldTreatURLAsSameAsCurrent(newDocumentLoader.originalRequest().url())) { |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 1516 | r.setCachePolicy(ResourceRequestCachePolicy::ReloadIgnoringCacheData); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1517 | type = FrameLoadType::Same; |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1518 | } else if (shouldTreatURLAsSameAsCurrent(newDocumentLoader.unreachableURL()) && isReload(m_loadType)) |
commit-queue@webkit.org | fb4593b | 2018-04-18 17:50:15 +0000 | [diff] [blame] | 1519 | type = m_loadType; |
cdumez@apple.com | 3aedc03 | 2019-01-31 02:23:55 +0000 | [diff] [blame] | 1520 | else if (m_loadType == FrameLoadType::RedirectWithLockedBackForwardList && ((!newDocumentLoader.unreachableURL().isEmpty() && newDocumentLoader.substituteData().isValid()) || shouldTreatCurrentLoadAsContinuingLoad())) |
aestes@apple.com | 176a9aa | 2016-07-08 20:14:34 +0000 | [diff] [blame] | 1521 | type = FrameLoadType::RedirectWithLockedBackForwardList; |
jpfau@apple.com | 6e5a605 | 2012-07-27 00:52:32 +0000 | [diff] [blame] | 1522 | else |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1523 | type = FrameLoadType::Standard; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1524 | |
| 1525 | if (m_documentLoader) |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1526 | newDocumentLoader.setOverrideEncoding(m_documentLoader->overrideEncoding()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1527 | |
| 1528 | // When we loading alternate content for an unreachable URL that we're |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1529 | // visiting in the history list, we treat it as a reload so the history list |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1530 | // is appropriately maintained. |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1531 | // |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1532 | // FIXME: This seems like a dangerous overloading of the meaning of "FrameLoadType::Reload" ... |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1533 | // shouldn't a more explicit type of reload be defined, that means roughly |
| 1534 | // "load without affecting history" ? |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 1535 | if (shouldReloadToHandleUnreachableURL(newDocumentLoader)) { |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1536 | // shouldReloadToHandleUnreachableURL returns true only when the original load type is back-forward. |
commit-queue@webkit.org | 072ac24 | 2011-04-04 17:05:55 +0000 | [diff] [blame] | 1537 | // In this case we should save the document state now. Otherwise the state can be lost because load type is |
| 1538 | // changed and updateForBackForwardNavigation() will not be called when loading is committed. |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 1539 | history().saveDocumentAndScrollState(); |
commit-queue@webkit.org | 072ac24 | 2011-04-04 17:05:55 +0000 | [diff] [blame] | 1540 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1541 | ASSERT(type == FrameLoadType::Standard); |
| 1542 | type = FrameLoadType::Reload; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
commit-queue@webkit.org | 372c264 | 2020-04-03 16:53:48 +0000 | [diff] [blame] | 1545 | loadWithDocumentLoader(&newDocumentLoader, type, nullptr, AllowNavigationToInvalidURL::Yes); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
commit-queue@webkit.org | 372c264 | 2020-04-03 16:53:48 +0000 | [diff] [blame] | 1548 | void FrameLoader::loadWithDocumentLoader(DocumentLoader* loader, FrameLoadType type, RefPtr<FormState>&& formState, AllowNavigationToInvalidURL allowNavigationToInvalidURL, CompletionHandler<void()>&& completionHandler) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1549 | { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1550 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "loadWithDocumentLoader: frame load started"); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1551 | |
inferno@chromium.org | 6e8e347 | 2010-10-26 13:29:04 +0000 | [diff] [blame] | 1552 | // Retain because dispatchBeforeLoadEvent may release the last reference to it. |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 1553 | Ref<Frame> protect(m_frame); |
inferno@chromium.org | 6e8e347 | 2010-10-26 13:29:04 +0000 | [diff] [blame] | 1554 | |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 1555 | CompletionHandlerCallingScope completionHandlerCaller(WTFMove(completionHandler)); |
| 1556 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1557 | ASSERT(m_client->hasWebView()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1558 | |
| 1559 | // Unfortunately the view must be non-nil, this is ultimately due |
| 1560 | // to parser requiring a FrameView. We should fix this dependency. |
| 1561 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1562 | ASSERT(m_frame.view()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1563 | |
dbates@webkit.org | 872db61 | 2017-03-20 23:07:50 +0000 | [diff] [blame] | 1564 | if (!isNavigationAllowed()) |
abarth@webkit.org | 89fa350 | 2009-09-21 02:30:12 +0000 | [diff] [blame] | 1565 | return; |
| 1566 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1567 | if (m_frame.document()) |
| 1568 | m_previousURL = m_frame.document()->url(); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 1569 | |
cdumez@apple.com | eb4832c | 2017-02-08 15:39:38 +0000 | [diff] [blame] | 1570 | const URL& newURL = loader->request().url(); |
| 1571 | |
jiewen_tan@apple.com | 1306fce | 2018-10-24 18:49:03 +0000 | [diff] [blame] | 1572 | // Only the first iframe navigation or the first iframe navigation after about:blank should be reported. |
| 1573 | // https://www.w3.org/TR/resource-timing-2/#resources-included-in-the-performanceresourcetiming-interface |
youenn@apple.com | 55cf9a2 | 2020-03-23 19:46:57 +0000 | [diff] [blame] | 1574 | if (m_shouldReportResourceTimingToParentFrame && !m_previousURL.isNull() && m_previousURL != aboutBlankURL()) |
jiewen_tan@apple.com | 1306fce | 2018-10-24 18:49:03 +0000 | [diff] [blame] | 1575 | m_shouldReportResourceTimingToParentFrame = false; |
| 1576 | |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1577 | // Log main frame navigation types. |
akling@apple.com | e6549f4 | 2016-12-01 16:15:27 +0000 | [diff] [blame] | 1578 | if (m_frame.isMainFrame()) { |
cdumez@apple.com | c518f7e | 2018-04-03 18:01:41 +0000 | [diff] [blame] | 1579 | if (auto* page = m_frame.page()) { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1580 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "loadWithDocumentLoader: main frame load started"); |
cdumez@apple.com | 563f1dc | 2017-04-29 03:55:35 +0000 | [diff] [blame] | 1581 | page->mainFrameLoadStarted(newURL, type); |
cdumez@apple.com | c518f7e | 2018-04-03 18:01:41 +0000 | [diff] [blame] | 1582 | page->performanceLogging().didReachPointOfInterest(PerformanceLogging::MainFrameLoadStarted); |
| 1583 | } |
akling@apple.com | e6549f4 | 2016-12-01 16:15:27 +0000 | [diff] [blame] | 1584 | } |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1585 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1586 | policyChecker().setLoadType(type); |
rniwa@webkit.org | ba12a01 | 2019-02-03 22:48:22 +0000 | [diff] [blame] | 1587 | RELEASE_ASSERT(!isBackForwardLoadType(type) || history().provisionalItem()); |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 1588 | bool isFormSubmission = formState; |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1589 | |
yael.aharon@nokia.com | 79f6905 | 2010-12-30 19:31:00 +0000 | [diff] [blame] | 1590 | const String& httpMethod = loader->request().httpMethod(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1591 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1592 | if (shouldPerformFragmentNavigation(isFormSubmission, httpMethod, policyChecker().loadType(), newURL)) { |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 1593 | RefPtr<DocumentLoader> oldDocumentLoader = m_documentLoader; |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 1594 | NavigationAction action { *m_frame.document(), loader->request(), InitiatedByMainFrame::Unknown, policyChecker().loadType(), isFormSubmission }; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1595 | |
cdumez@apple.com | 91e03bd | 2018-09-17 17:15:07 +0000 | [diff] [blame] | 1596 | oldDocumentLoader->setTriggeringAction(WTFMove(action)); |
andersca@apple.com | 97ab6d9 | 2013-10-21 22:55:14 +0000 | [diff] [blame] | 1597 | oldDocumentLoader->setLastCheckedRequest(ResourceRequest()); |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1598 | policyChecker().stopCheck(); |
rniwa@webkit.org | ba12a01 | 2019-02-03 22:48:22 +0000 | [diff] [blame] | 1599 | RELEASE_ASSERT(!isBackForwardLoadType(policyChecker().loadType()) || history().provisionalItem()); |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 1600 | policyChecker().checkNavigationPolicy(ResourceRequest(loader->request()), ResourceResponse { } /* redirectResponse */, oldDocumentLoader.get(), WTFMove(formState), [this, protectedFrame = makeRef(m_frame)] (const ResourceRequest& request, WeakPtr<FormState>&&, NavigationPolicyDecision navigationPolicyDecision) { |
| 1601 | continueFragmentScrollAfterNavigationPolicy(request, navigationPolicyDecision == NavigationPolicyDecision::ContinueLoad); |
cdumez@apple.com | 8221194 | 2018-04-17 18:13:49 +0000 | [diff] [blame] | 1602 | }, PolicyDecisionMode::Synchronous); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1603 | return; |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 1604 | } |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1605 | |
| 1606 | if (Frame* parent = m_frame.tree().parent()) |
| 1607 | loader->setOverrideEncoding(parent->loader().documentLoader()->overrideEncoding()); |
| 1608 | |
| 1609 | policyChecker().stopCheck(); |
| 1610 | setPolicyDocumentLoader(loader); |
| 1611 | if (loader->triggeringAction().isEmpty()) |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 1612 | loader->setTriggeringAction({ *m_frame.document(), loader->request(), InitiatedByMainFrame::Unknown, policyChecker().loadType(), isFormSubmission }); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1613 | |
| 1614 | if (Element* ownerElement = m_frame.ownerElement()) { |
| 1615 | // We skip dispatching the beforeload event if we've already |
| 1616 | // committed a real document load because the event would leak |
| 1617 | // subsequent activity by the frame which the parent frame isn't |
| 1618 | // supposed to learn. For example, if the child frame navigated to |
| 1619 | // a new URL, the parent frame shouldn't learn the URL. |
| 1620 | if (!m_stateMachine.committedFirstRealDocumentLoad() |
| 1621 | && !ownerElement->dispatchBeforeLoadEvent(loader->request().url().string())) { |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 1622 | continueLoadAfterNavigationPolicy(loader->request(), formState.get(), NavigationPolicyDecision::IgnoreLoad, allowNavigationToInvalidURL); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1623 | return; |
| 1624 | } |
| 1625 | } |
| 1626 | |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 1627 | m_frame.navigationScheduler().cancel(NewLoadInProgress::Yes); |
cdumez@apple.com | 22fa18d | 2018-02-28 23:58:22 +0000 | [diff] [blame] | 1628 | |
cdumez@apple.com | 3aedc03 | 2019-01-31 02:23:55 +0000 | [diff] [blame] | 1629 | if (shouldTreatCurrentLoadAsContinuingLoad()) { |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 1630 | continueLoadAfterNavigationPolicy(loader->request(), formState.get(), NavigationPolicyDecision::ContinueLoad, allowNavigationToInvalidURL); |
beidson@apple.com | 1c9022b | 2018-03-21 00:05:58 +0000 | [diff] [blame] | 1631 | return; |
| 1632 | } |
| 1633 | |
rniwa@webkit.org | ba12a01 | 2019-02-03 22:48:22 +0000 | [diff] [blame] | 1634 | RELEASE_ASSERT(!isBackForwardLoadType(policyChecker().loadType()) || history().provisionalItem()); |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 1635 | policyChecker().checkNavigationPolicy(ResourceRequest(loader->request()), ResourceResponse { } /* redirectResponse */, loader, WTFMove(formState), [this, protectedFrame = makeRef(m_frame), allowNavigationToInvalidURL, completionHandler = completionHandlerCaller.release()] (const ResourceRequest& request, WeakPtr<FormState>&& formState, NavigationPolicyDecision navigationPolicyDecision) mutable { |
| 1636 | continueLoadAfterNavigationPolicy(request, formState.get(), navigationPolicyDecision, allowNavigationToInvalidURL); |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 1637 | completionHandler(); |
achristensen@apple.com | 10e4a7b | 2018-11-28 21:14:43 +0000 | [diff] [blame] | 1638 | }, PolicyDecisionMode::Asynchronous); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
cdumez@apple.com | 2e68bb4 | 2018-03-19 22:30:57 +0000 | [diff] [blame] | 1641 | void FrameLoader::clearProvisionalLoadForPolicyCheck() |
| 1642 | { |
cdumez@apple.com | 8ace63b | 2018-06-29 22:56:29 +0000 | [diff] [blame] | 1643 | if (!m_policyDocumentLoader || !m_provisionalDocumentLoader || m_inClearProvisionalLoadForPolicyCheck) |
cdumez@apple.com | 2e68bb4 | 2018-03-19 22:30:57 +0000 | [diff] [blame] | 1644 | return; |
| 1645 | |
cdumez@apple.com | 8ace63b | 2018-06-29 22:56:29 +0000 | [diff] [blame] | 1646 | SetForScope<bool> change(m_inClearProvisionalLoadForPolicyCheck, true); |
cdumez@apple.com | 2e68bb4 | 2018-03-19 22:30:57 +0000 | [diff] [blame] | 1647 | m_provisionalDocumentLoader->stopLoading(); |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1648 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "clearProvisionalLoadForPolicyCheck: Clearing provisional document loader (m_provisionalDocumentLoader=%p)", m_provisionalDocumentLoader.get()); |
cdumez@apple.com | 2e68bb4 | 2018-03-19 22:30:57 +0000 | [diff] [blame] | 1649 | setProvisionalDocumentLoader(nullptr); |
| 1650 | } |
| 1651 | |
achristensen@apple.com | 2ace43d | 2020-11-05 16:54:48 +0000 | [diff] [blame] | 1652 | bool FrameLoader::hasOpenedFrames() const |
| 1653 | { |
| 1654 | return !m_openedFrames.computesEmpty(); |
| 1655 | } |
| 1656 | |
aroben@apple.com | 92cfa90 | 2008-04-16 19:19:00 +0000 | [diff] [blame] | 1657 | void FrameLoader::reportLocalLoadFailed(Frame* frame, const String& url) |
kmccullo | 23d362f | 2007-04-06 01:05:58 +0000 | [diff] [blame] | 1658 | { |
| 1659 | ASSERT(!url.isEmpty()); |
aroben@apple.com | 92cfa90 | 2008-04-16 19:19:00 +0000 | [diff] [blame] | 1660 | if (!frame) |
| 1661 | return; |
| 1662 | |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 1663 | frame->document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Not allowed to load local resource: " + url); |
kmccullo | 23d362f | 2007-04-06 01:05:58 +0000 | [diff] [blame] | 1664 | } |
| 1665 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1666 | const ResourceRequest& FrameLoader::initialRequest() const |
| 1667 | { |
andersca@apple.com | 48ffa33 | 2008-03-13 19:08:06 +0000 | [diff] [blame] | 1668 | return activeDocumentLoader()->originalRequest(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
drousso@apple.com | 21748ed | 2018-10-08 18:25:52 +0000 | [diff] [blame] | 1671 | bool FrameLoader::willLoadMediaElementURL(URL& url, Node& initiatorNode) |
weinig@apple.com | 6893525 | 2009-10-07 02:48:12 +0000 | [diff] [blame] | 1672 | { |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 1673 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1674 | // MobileStore depends on the iOS 4.0 era client delegate method because webView:resource:willSendRequest:redirectResponse:fromDataSource |
| 1675 | // doesn't let them tell when a load request is coming from a media element. See <rdar://problem/8266916> for more details. |
cdumez@apple.com | 0b0e88f | 2016-03-06 03:28:54 +0000 | [diff] [blame] | 1676 | if (IOSApplication::isMobileStore()) |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1677 | return m_client->shouldLoadMediaElementURL(url); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1678 | #endif |
| 1679 | |
weinig@apple.com | 6893525 | 2009-10-07 02:48:12 +0000 | [diff] [blame] | 1680 | ResourceRequest request(url); |
drousso@apple.com | 21748ed | 2018-10-08 18:25:52 +0000 | [diff] [blame] | 1681 | request.setInspectorInitiatorNodeIdentifier(InspectorInstrumentation::identifierForNode(initiatorNode)); |
weinig@apple.com | 6893525 | 2009-10-07 02:48:12 +0000 | [diff] [blame] | 1682 | |
| 1683 | unsigned long identifier; |
| 1684 | ResourceError error; |
| 1685 | requestFromDelegate(request, identifier, error); |
antti@apple.com | 021dc01 | 2014-09-04 20:00:11 +0000 | [diff] [blame] | 1686 | notifier().sendRemainingDelegateMessages(m_documentLoader.get(), identifier, request, ResourceResponse(url, String(), -1, String()), 0, -1, -1, error); |
weinig@apple.com | 6893525 | 2009-10-07 02:48:12 +0000 | [diff] [blame] | 1687 | |
| 1688 | url = request.url(); |
| 1689 | |
| 1690 | return error.isNull(); |
| 1691 | } |
| 1692 | |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1693 | bool FrameLoader::shouldReloadToHandleUnreachableURL(DocumentLoader& docLoader) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1694 | { |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1695 | URL unreachableURL = docLoader.unreachableURL(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1696 | |
| 1697 | if (unreachableURL.isEmpty()) |
| 1698 | return false; |
| 1699 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1700 | if (!isBackForwardLoadType(policyChecker().loadType())) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1701 | return false; |
| 1702 | |
| 1703 | // We only treat unreachableURLs specially during the delegate callbacks |
| 1704 | // for provisional load errors and navigation policy decisions. The former |
| 1705 | // case handles well-formed URLs that can't be loaded, and the latter |
| 1706 | // case handles malformed URLs and unknown schemes. Loading alternate content |
| 1707 | // at other times behaves like a standard load. |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1708 | if (policyChecker().delegateIsDecidingNavigationPolicy() || policyChecker().delegateIsHandlingUnimplementablePolicy()) |
mitz@apple.com | 6699e27 | 2015-05-01 23:47:03 +0000 | [diff] [blame] | 1709 | return m_policyDocumentLoader && unreachableURL == m_policyDocumentLoader->request().url(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1710 | |
mitz@apple.com | 6699e27 | 2015-05-01 23:47:03 +0000 | [diff] [blame] | 1711 | return unreachableURL == m_provisionalLoadErrorBeingHandledURL; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
ggaren@apple.com | 3eaa7c0 | 2009-01-29 07:38:54 +0000 | [diff] [blame] | 1714 | void FrameLoader::reloadWithOverrideEncoding(const String& encoding) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1715 | { |
| 1716 | if (!m_documentLoader) |
| 1717 | return; |
| 1718 | |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1719 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "reloadWithOverrideEncoding: frame load started"); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1720 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1721 | ResourceRequest request = m_documentLoader->request(); |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1722 | URL unreachableURL = m_documentLoader->unreachableURL(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1723 | if (!unreachableURL.isEmpty()) |
| 1724 | request.setURL(unreachableURL); |
| 1725 | |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 1726 | // FIXME: If the resource is a result of form submission and is not cached, the form will be silently resubmitted. |
| 1727 | // We should ask the user for confirmation in this case. |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 1728 | request.setCachePolicy(ResourceRequestCachePolicy::ReturnCacheDataElseLoad); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1729 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1730 | Ref<DocumentLoader> loader = m_client->createDocumentLoader(request, defaultSubstituteDataForURL(request.url())); |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 1731 | applyShouldOpenExternalURLsPolicyToNewDocumentLoader(m_frame, loader, InitiatedByMainFrame::Unknown, m_documentLoader->shouldOpenExternalURLsPolicyToPropagate()); |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 1732 | |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 1733 | setPolicyDocumentLoader(loader.ptr()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1734 | |
| 1735 | loader->setOverrideEncoding(encoding); |
| 1736 | |
commit-queue@webkit.org | 372c264 | 2020-04-03 16:53:48 +0000 | [diff] [blame] | 1737 | loadWithDocumentLoader(loader.ptr(), FrameLoadType::Reload, { }, AllowNavigationToInvalidURL::Yes); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1738 | } |
| 1739 | |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 1740 | void FrameLoader::reload(OptionSet<ReloadOption> options) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1741 | { |
| 1742 | if (!m_documentLoader) |
| 1743 | return; |
| 1744 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1745 | // If a window is created by javascript, its main frame can have an empty but non-nil URL. |
| 1746 | // Reloading in this case will lose the current contents (see 4151001). |
darin@chromium.org | 4824685 | 2008-11-04 19:40:56 +0000 | [diff] [blame] | 1747 | if (m_documentLoader->request().url().isEmpty()) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1748 | return; |
| 1749 | |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1750 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "reload: frame load started"); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1751 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1752 | // Replace error-page URL with the URL we were trying to reach. |
commit-queue@webkit.org | 2090e27 | 2012-06-28 16:05:43 +0000 | [diff] [blame] | 1753 | ResourceRequest initialRequest = m_documentLoader->request(); |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1754 | URL unreachableURL = m_documentLoader->unreachableURL(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1755 | if (!unreachableURL.isEmpty()) |
darin@chromium.org | 4824685 | 2008-11-04 19:40:56 +0000 | [diff] [blame] | 1756 | initialRequest.setURL(unreachableURL); |
commit-queue@webkit.org | 2090e27 | 2012-06-28 16:05:43 +0000 | [diff] [blame] | 1757 | |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1758 | // Create a new document loader for the reload, this will become m_documentLoader eventually, |
| 1759 | // but first it has to be the "policy" document loader, and then the "provisional" document loader. |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1760 | Ref<DocumentLoader> loader = m_client->createDocumentLoader(initialRequest, defaultSubstituteDataForURL(initialRequest.url())); |
jiewen_tan@apple.com | 32abaa6 | 2019-02-13 23:07:13 +0000 | [diff] [blame] | 1761 | loader->setAllowsWebArchiveForMainFrame(m_documentLoader->allowsWebArchiveForMainFrame()); |
bfulgham@apple.com | 2eaf0ac | 2020-02-06 17:32:18 +0000 | [diff] [blame] | 1762 | loader->setAllowsDataURLsForMainFrame(m_documentLoader->allowsDataURLsForMainFrame()); |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 1763 | applyShouldOpenExternalURLsPolicyToNewDocumentLoader(m_frame, loader, InitiatedByMainFrame::Unknown, m_documentLoader->shouldOpenExternalURLsPolicyToPropagate()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1764 | |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 1765 | loader->setUserContentExtensionsEnabled(!options.contains(ReloadOption::DisableContentBlockers)); |
achristensen@apple.com | d40e0ba | 2015-10-14 20:03:14 +0000 | [diff] [blame] | 1766 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1767 | ResourceRequest& request = loader->request(); |
| 1768 | |
commit-queue@webkit.org | 4833ac5 | 2018-02-26 17:38:14 +0000 | [diff] [blame] | 1769 | // FIXME: We don't have a mechanism to revalidate the main resource without reloading at the moment. |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 1770 | request.setCachePolicy(ResourceRequestCachePolicy::ReloadIgnoringCacheData); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1771 | |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 1772 | addSameSiteInfoToRequestIfNeeded(request); |
| 1773 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1774 | // If we're about to re-post, set up action so the application can warn the user. |
| 1775 | if (request.httpMethod() == "POST") |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 1776 | loader->setTriggeringAction({ *m_frame.document(), request, InitiatedByMainFrame::Unknown, NavigationType::FormResubmitted }); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1777 | |
| 1778 | loader->setOverrideEncoding(m_documentLoader->overrideEncoding()); |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 1779 | |
| 1780 | auto frameLoadTypeForReloadOptions = [] (auto options) { |
antti@apple.com | eb7081d | 2018-05-09 07:05:46 +0000 | [diff] [blame] | 1781 | if (options & ReloadOption::FromOrigin) |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 1782 | return FrameLoadType::ReloadFromOrigin; |
antti@apple.com | eb7081d | 2018-05-09 07:05:46 +0000 | [diff] [blame] | 1783 | if (options & ReloadOption::ExpiredOnly) |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 1784 | return FrameLoadType::ReloadExpiredOnly; |
| 1785 | return FrameLoadType::Reload; |
| 1786 | }; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1787 | |
commit-queue@webkit.org | 372c264 | 2020-04-03 16:53:48 +0000 | [diff] [blame] | 1788 | loadWithDocumentLoader(loader.ptr(), frameLoadTypeForReloadOptions(options), { }, AllowNavigationToInvalidURL::Yes); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1789 | } |
| 1790 | |
ajuma@chromium.org | edd7574 | 2019-09-11 14:52:18 +0000 | [diff] [blame] | 1791 | void FrameLoader::stopAllLoaders(ClearProvisionalItemPolicy clearProvisionalItemPolicy, StopLoadingPolicy stopLoadingPolicy) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1792 | { |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 1793 | if (m_frame.document() && m_frame.document()->backForwardCacheState() == Document::InBackForwardCache) |
cdumez@apple.com | a0010ff | 2018-12-13 23:17:44 +0000 | [diff] [blame] | 1794 | return; |
| 1795 | |
ajuma@chromium.org | edd7574 | 2019-09-11 14:52:18 +0000 | [diff] [blame] | 1796 | if (stopLoadingPolicy == StopLoadingPolicy::PreventDuringUnloadEvents && !isStopLoadingAllowed()) |
weinig@apple.com | f239bbf | 2009-04-09 18:30:32 +0000 | [diff] [blame] | 1797 | return; |
| 1798 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1799 | // If this method is called from within this method, infinite recursion can occur (3442218). Avoid this. |
| 1800 | if (m_inStopAllLoaders) |
| 1801 | return; |
pvollan@apple.com | 8f4bcd95 | 2018-02-01 04:18:38 +0000 | [diff] [blame] | 1802 | |
| 1803 | // This method might dispatch events. |
| 1804 | RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(ScriptDisallowedScope::InMainThread::isScriptAllowed()); |
| 1805 | |
inferno@chromium.org | bc05aa5 | 2012-08-06 16:30:40 +0000 | [diff] [blame] | 1806 | // Calling stopLoading() on the provisional document loader can blow away |
| 1807 | // the frame from underneath. |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 1808 | Ref<Frame> protect(m_frame); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1809 | |
| 1810 | m_inStopAllLoaders = true; |
| 1811 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1812 | policyChecker().stopCheck(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1813 | |
commit-queue@webkit.org | 987fd77 | 2011-01-21 18:26:42 +0000 | [diff] [blame] | 1814 | // If no new load is in progress, we should clear the provisional item from history |
| 1815 | // before we call stopLoading. |
| 1816 | if (clearProvisionalItemPolicy == ShouldClearProvisionalItem) |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 1817 | history().setProvisionalItem(nullptr); |
commit-queue@webkit.org | 987fd77 | 2011-01-21 18:26:42 +0000 | [diff] [blame] | 1818 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1819 | for (RefPtr<Frame> child = m_frame.tree().firstChild(); child; child = child->tree().nextSibling()) |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 1820 | child->loader().stopAllLoaders(clearProvisionalItemPolicy); |
darin | 7208e93 | 2007-02-13 17:52:53 +0000 | [diff] [blame] | 1821 | if (m_provisionalDocumentLoader) |
commit-queue@webkit.org | fc5833b | 2011-02-23 06:58:46 +0000 | [diff] [blame] | 1822 | m_provisionalDocumentLoader->stopLoading(); |
beidson@apple.com | 4642121 | 2008-08-25 21:48:56 +0000 | [diff] [blame] | 1823 | if (m_documentLoader) |
commit-queue@webkit.org | fc5833b | 2011-02-23 06:58:46 +0000 | [diff] [blame] | 1824 | m_documentLoader->stopLoading(); |
commit-queue@webkit.org | 424bc41 | 2020-02-24 15:50:39 +0000 | [diff] [blame] | 1825 | if (m_frame.page() && !m_frame.page()->chrome().client().isSVGImageChromeClient()) |
| 1826 | platformStrategies()->loaderStrategy()->browsingContextRemoved(frame()); |
beidson@apple.com | 4642121 | 2008-08-25 21:48:56 +0000 | [diff] [blame] | 1827 | |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1828 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "stopAllLoaders: Clearing provisional document loader (m_provisionalDocumentLoader=%p)", m_provisionalDocumentLoader.get()); |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 1829 | setProvisionalDocumentLoader(nullptr); |
darin | 7208e93 | 2007-02-13 17:52:53 +0000 | [diff] [blame] | 1830 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1831 | m_inStopAllLoaders = false; |
| 1832 | } |
| 1833 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 1834 | void FrameLoader::stopForBackForwardCache() |
cdumez@apple.com | e16aaf0 | 2019-10-03 22:16:46 +0000 | [diff] [blame] | 1835 | { |
cdumez@apple.com | e16aaf0 | 2019-10-03 22:16:46 +0000 | [diff] [blame] | 1836 | // Stop provisional loads in subframes (The one in the main frame is about to be committed). |
| 1837 | if (!m_frame.isMainFrame()) { |
| 1838 | if (m_provisionalDocumentLoader) |
| 1839 | m_provisionalDocumentLoader->stopLoading(); |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1840 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "stopForBackForwardCache: Clearing provisional document loader (m_provisionalDocumentLoader=%p)", m_provisionalDocumentLoader.get()); |
cdumez@apple.com | e16aaf0 | 2019-10-03 22:16:46 +0000 | [diff] [blame] | 1841 | setProvisionalDocumentLoader(nullptr); |
| 1842 | } |
| 1843 | |
| 1844 | // Stop current loads. |
| 1845 | if (m_documentLoader) |
| 1846 | m_documentLoader->stopLoading(); |
| 1847 | |
| 1848 | for (RefPtr<Frame> child = m_frame.tree().firstChild(); child; child = child->tree().nextSibling()) |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 1849 | child->loader().stopForBackForwardCache(); |
cdumez@apple.com | 6cbf70a | 2019-10-11 20:26:15 +0000 | [diff] [blame] | 1850 | |
cdumez@apple.com | 7e7b879 | 2019-10-11 23:29:02 +0000 | [diff] [blame] | 1851 | // We cancel pending navigations & policy checks *after* cancelling loads because cancelling loads might end up |
| 1852 | // running script, which could schedule new navigations. |
cdumez@apple.com | 6cbf70a | 2019-10-11 20:26:15 +0000 | [diff] [blame] | 1853 | policyChecker().stopCheck(); |
| 1854 | m_frame.navigationScheduler().cancel(); |
cdumez@apple.com | e16aaf0 | 2019-10-03 22:16:46 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 1857 | void FrameLoader::stopAllLoadersAndCheckCompleteness() |
| 1858 | { |
| 1859 | stopAllLoaders(); |
| 1860 | |
| 1861 | if (!m_checkTimer.isActive()) |
| 1862 | return; |
| 1863 | |
| 1864 | m_checkTimer.stop(); |
| 1865 | m_checkingLoadCompleteForDetachment = true; |
| 1866 | checkCompletenessNow(); |
| 1867 | m_checkingLoadCompleteForDetachment = false; |
| 1868 | } |
| 1869 | |
beidson | 398923b | 2007-07-31 20:29:02 +0000 | [diff] [blame] | 1870 | void FrameLoader::stopForUserCancel(bool deferCheckLoadComplete) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 1871 | { |
bfulgham@apple.com | 98845d9 | 2016-05-17 01:09:27 +0000 | [diff] [blame] | 1872 | // Calling stopAllLoaders can cause the frame to be deallocated, including the frame loader. |
| 1873 | Ref<Frame> protectedFrame(m_frame); |
| 1874 | |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 1875 | stopAllLoaders(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1876 | |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 1877 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1878 | // Lay out immediately when stopping to immediately clear the old page if we just committed this one |
| 1879 | // but haven't laid out/painted yet. |
| 1880 | // FIXME: Is this behavior specific to iOS? Or should we expose a setting to toggle this behavior? |
| 1881 | if (m_frame.view() && !m_frame.view()->didFirstLayout()) |
zalan@apple.com | 6116e6d | 2017-10-28 15:24:58 +0000 | [diff] [blame] | 1882 | m_frame.view()->layoutContext().layout(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1883 | #endif |
| 1884 | |
beidson | 398923b | 2007-07-31 20:29:02 +0000 | [diff] [blame] | 1885 | if (deferCheckLoadComplete) |
| 1886 | scheduleCheckLoadComplete(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1887 | else if (m_frame.page()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 1888 | checkLoadComplete(); |
| 1889 | } |
| 1890 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1891 | DocumentLoader* FrameLoader::activeDocumentLoader() const |
| 1892 | { |
| 1893 | if (m_state == FrameStateProvisional) |
| 1894 | return m_provisionalDocumentLoader.get(); |
| 1895 | return m_documentLoader.get(); |
| 1896 | } |
| 1897 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1898 | bool FrameLoader::isLoading() const |
| 1899 | { |
darin | 8207db4 | 2007-02-20 18:18:39 +0000 | [diff] [blame] | 1900 | DocumentLoader* docLoader = activeDocumentLoader(); |
| 1901 | if (!docLoader) |
| 1902 | return false; |
japhet@chromium.org | 4bcb80b | 2012-03-26 20:34:00 +0000 | [diff] [blame] | 1903 | return docLoader->isLoading(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1904 | } |
| 1905 | |
mjs | 7545bb5 | 2007-05-15 08:24:53 +0000 | [diff] [blame] | 1906 | bool FrameLoader::frameHasLoaded() const |
| 1907 | { |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 1908 | return m_stateMachine.committedFirstRealDocumentLoad() || (m_provisionalDocumentLoader && !m_stateMachine.creatingInitialEmptyDocument()); |
mjs | 7545bb5 | 2007-05-15 08:24:53 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1911 | void FrameLoader::setDocumentLoader(DocumentLoader* loader) |
| 1912 | { |
| 1913 | if (!loader && !m_documentLoader) |
| 1914 | return; |
cdumez@apple.com | a0010ff | 2018-12-13 23:17:44 +0000 | [diff] [blame] | 1915 | |
| 1916 | if (loader == m_documentLoader) |
| 1917 | return; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1918 | |
| 1919 | ASSERT(loader != m_documentLoader); |
| 1920 | ASSERT(!loader || loader->frameLoader() == this); |
| 1921 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 1922 | m_client->prepareForDataSourceReplacement(); |
darin | c3d2605 | 2007-03-22 18:17:12 +0000 | [diff] [blame] | 1923 | detachChildren(); |
japhet@chromium.org | a9a58bb | 2012-09-01 01:09:02 +0000 | [diff] [blame] | 1924 | |
| 1925 | // detachChildren() can trigger this frame's unload event, and therefore |
| 1926 | // script can run and do just about anything. For example, an unload event that calls |
| 1927 | // document.write("") on its parent frame can lead to a recursive detachChildren() |
| 1928 | // invocation for this frame. In that case, we can end up at this point with a |
| 1929 | // loader that hasn't been deleted but has been detached from its frame. Such a |
| 1930 | // DocumentLoader has been sufficiently detached that we'll end up in an inconsistent |
| 1931 | // state if we try to use it. |
| 1932 | if (loader && !loader->frame()) |
| 1933 | return; |
| 1934 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1935 | if (m_documentLoader) |
| 1936 | m_documentLoader->detachFromFrame(); |
| 1937 | |
| 1938 | m_documentLoader = loader; |
| 1939 | } |
| 1940 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1941 | void FrameLoader::setPolicyDocumentLoader(DocumentLoader* loader) |
| 1942 | { |
| 1943 | if (m_policyDocumentLoader == loader) |
| 1944 | return; |
| 1945 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1946 | if (loader) |
beidson@apple.com | 10a537f | 2015-07-09 22:30:42 +0000 | [diff] [blame] | 1947 | loader->attachToFrame(m_frame); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1948 | if (m_policyDocumentLoader |
| 1949 | && m_policyDocumentLoader != m_provisionalDocumentLoader |
| 1950 | && m_policyDocumentLoader != m_documentLoader) |
| 1951 | m_policyDocumentLoader->detachFromFrame(); |
| 1952 | |
| 1953 | m_policyDocumentLoader = loader; |
| 1954 | } |
eric@webkit.org | 14774f4 | 2008-04-21 17:50:37 +0000 | [diff] [blame] | 1955 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1956 | void FrameLoader::setProvisionalDocumentLoader(DocumentLoader* loader) |
| 1957 | { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1958 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "setProvisionalDocumentLoader: Setting provisional document loader (m_provisionalDocumentLoader=%p)", loader); |
| 1959 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1960 | ASSERT(!loader || !m_provisionalDocumentLoader); |
| 1961 | ASSERT(!loader || loader->frameLoader() == this); |
| 1962 | |
| 1963 | if (m_provisionalDocumentLoader && m_provisionalDocumentLoader != m_documentLoader) |
| 1964 | m_provisionalDocumentLoader->detachFromFrame(); |
| 1965 | |
| 1966 | m_provisionalDocumentLoader = loader; |
| 1967 | } |
| 1968 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1969 | void FrameLoader::setState(FrameState newState) |
akling@apple.com | e6549f4 | 2016-12-01 16:15:27 +0000 | [diff] [blame] | 1970 | { |
| 1971 | FrameState oldState = m_state; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1972 | m_state = newState; |
| 1973 | |
| 1974 | if (newState == FrameStateProvisional) |
| 1975 | provisionalLoadStarted(); |
| 1976 | else if (newState == FrameStateComplete) { |
| 1977 | frameLoadCompleted(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1978 | if (m_documentLoader) |
| 1979 | m_documentLoader->stopRecordingResponses(); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1980 | if (m_frame.isMainFrame() && oldState != newState) { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1981 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "setState: main frame load completed"); |
cdumez@apple.com | c518f7e | 2018-04-03 18:01:41 +0000 | [diff] [blame] | 1982 | m_frame.page()->performanceLogging().didReachPointOfInterest(PerformanceLogging::MainFrameLoadCompleted); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1983 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | void FrameLoader::clearProvisionalLoad() |
| 1988 | { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 1989 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "clearProvisionalLoad: Clearing provisional document loader (m_provisionalDocumentLoader=%p)", m_provisionalDocumentLoader.get()); |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 1990 | setProvisionalDocumentLoader(nullptr); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 1991 | m_progressTracker->progressCompleted(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1992 | setState(FrameStateComplete); |
| 1993 | } |
| 1994 | |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 1995 | void FrameLoader::commitProvisionalLoad() |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1996 | { |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1997 | RefPtr<DocumentLoader> pdl = m_provisionalDocumentLoader; |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 1998 | Ref<Frame> protect(m_frame); |
beidson@apple.com | 3a5e3b9 | 2009-01-27 08:05:59 +0000 | [diff] [blame] | 1999 | |
andersca@apple.com | e776c2f | 2014-01-18 01:47:19 +0000 | [diff] [blame] | 2000 | std::unique_ptr<CachedPage> cachedPage; |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 2001 | if (m_loadingFromCachedPage && history().provisionalItem()) |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 2002 | cachedPage = BackForwardCache::singleton().take(*history().provisionalItem(), m_frame.page()); |
akling@apple.com | 9663f4b | 2013-09-05 21:25:32 +0000 | [diff] [blame] | 2003 | |
cdumez@apple.com | 524b8aa | 2019-10-15 05:28:55 +0000 | [diff] [blame] | 2004 | LOG(BackForwardCache, "WebCoreLoading %s: About to commit provisional load from previous URL '%s' to new URL '%s' with cached page %p", m_frame.tree().uniqueName().string().utf8().data(), |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2005 | m_frame.document() ? m_frame.document()->url().stringCenterEllipsizedToLength().utf8().data() : "", |
beidson@apple.com | 69caeee | 2018-04-20 04:55:32 +0000 | [diff] [blame] | 2006 | pdl ? pdl->url().stringCenterEllipsizedToLength().utf8().data() : "<no provisional DocumentLoader>", cachedPage.get()); |
beidson@apple.com | 3a5e3b9 | 2009-01-27 08:05:59 +0000 | [diff] [blame] | 2007 | |
wenson_hsieh@apple.com | 2851e66 | 2020-08-10 02:18:44 +0000 | [diff] [blame] | 2008 | if (auto document = makeRefPtr(m_frame.document())) { |
| 2009 | // In the case where we're restoring from a cached page, our document will not |
| 2010 | // be connected to its frame yet, so the following call with be a no-op. We will |
| 2011 | // attempt to confirm any active composition once again in this scenario after we |
| 2012 | // finish restoring from the cached page. |
| 2013 | document->editor().confirmCompositionAndNotifyClient(); |
| 2014 | } |
ap@apple.com | e042b63 | 2013-05-17 20:04:43 +0000 | [diff] [blame] | 2015 | |
cdumez@apple.com | a0010ff | 2018-12-13 23:17:44 +0000 | [diff] [blame] | 2016 | if (!m_frame.tree().parent() && history().currentItem() && history().currentItem() != history().provisionalItem()) { |
akling@apple.com | af7f33b | 2016-02-06 17:00:30 +0000 | [diff] [blame] | 2017 | // Check to see if we need to cache the page we are navigating away from into the back/forward cache. |
| 2018 | // We are doing this here because we know for sure that a new page is about to be loaded. |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 2019 | BackForwardCache::singleton().addIfCacheable(*history().currentItem(), m_frame.page()); |
cdumez@apple.com | 8420ada | 2016-06-21 17:05:48 +0000 | [diff] [blame] | 2020 | |
carlosgc@webkit.org | 32a60dd | 2016-11-10 14:24:26 +0000 | [diff] [blame] | 2021 | WebCore::jettisonExpensiveObjectsOnTopLevelNavigation(); |
akling@apple.com | af7f33b | 2016-02-06 17:00:30 +0000 | [diff] [blame] | 2022 | } |
| 2023 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2024 | if (m_loadType != FrameLoadType::Replace) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2025 | closeOldDataSources(); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 2026 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 2027 | if (!cachedPage && !m_stateMachine.creatingInitialEmptyDocument()) |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2028 | m_client->makeRepresentation(pdl.get()); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 2029 | |
akling@apple.com | 9663f4b | 2013-09-05 21:25:32 +0000 | [diff] [blame] | 2030 | transitionToCommitted(cachedPage.get()); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 2031 | |
abarth@webkit.org | f12783f | 2012-10-03 19:34:30 +0000 | [diff] [blame] | 2032 | if (pdl && m_documentLoader) { |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 2033 | // Check if the destination page is allowed to access the previous page's timing information. |
akling@apple.com | 6eea45d | 2014-12-17 01:48:38 +0000 | [diff] [blame] | 2034 | Ref<SecurityOrigin> securityOrigin(SecurityOrigin::create(pdl->request().url())); |
akling@apple.com | 5a7607f | 2015-01-21 22:33:49 +0000 | [diff] [blame] | 2035 | m_documentLoader->timing().setHasSameOriginAsPreviousDocument(securityOrigin.get().canRequest(m_previousURL)); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 2036 | } |
| 2037 | |
beidson | b72fe2e | 2007-05-03 21:35:24 +0000 | [diff] [blame] | 2038 | // Call clientRedirectCancelledOrFinished() here so that the frame load delegate is notified that the redirect's |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2039 | // status has changed, if there was a redirect. The frame load delegate may have saved some state about |
| 2040 | // the redirect in its -webView:willPerformClientRedirectToURL:delay:fireDate:forFrame:. Since we are |
| 2041 | // just about to commit a new page, there cannot possibly be a pending redirect at this point. |
| 2042 | if (m_sentRedirectNotification) |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 2043 | clientRedirectCancelledOrFinished(NewLoadInProgress::No); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2044 | |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 2045 | if (cachedPage && cachedPage->document()) { |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 2046 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2047 | // FIXME: CachedPage::restore() would dispatch viewport change notification. However UIKit expects load |
| 2048 | // commit to happen before any changes to viewport arguments and dealing with this there is difficult. |
| 2049 | m_frame.page()->chrome().setDispatchViewportDataDidChangeSuppressed(true); |
| 2050 | #endif |
dbates@webkit.org | cd75cb6 | 2017-03-15 22:44:59 +0000 | [diff] [blame] | 2051 | willRestoreFromCachedPage(); |
commit-queue@webkit.org | cbb6a49 | 2010-09-20 20:20:25 +0000 | [diff] [blame] | 2052 | |
carlosgc@webkit.org | 72eb796 | 2016-01-12 08:23:36 +0000 | [diff] [blame] | 2053 | // Start request for the main resource and dispatch didReceiveResponse before the load is committed for |
| 2054 | // consistency with all other loads. See https://bugs.webkit.org/show_bug.cgi?id=150927. |
| 2055 | ResourceError mainResouceError; |
| 2056 | unsigned long mainResourceIdentifier; |
| 2057 | ResourceRequest mainResourceRequest(cachedPage->documentLoader()->request()); |
| 2058 | requestFromDelegate(mainResourceRequest, mainResourceIdentifier, mainResouceError); |
| 2059 | notifier().dispatchDidReceiveResponse(cachedPage->documentLoader(), mainResourceIdentifier, cachedPage->documentLoader()->response()); |
| 2060 | |
commit-queue@webkit.org | 511a949 | 2020-03-12 18:28:40 +0000 | [diff] [blame] | 2061 | auto hasInsecureContent = cachedPage->cachedMainFrame()->hasInsecureContent(); |
commit-queue@webkit.org | fbfef68 | 2020-03-14 02:10:54 +0000 | [diff] [blame] | 2062 | auto usedLegacyTLS = cachedPage->cachedMainFrame()->usedLegacyTLS(); |
beidson@apple.com | 4322db0 | 2016-09-16 00:27:11 +0000 | [diff] [blame] | 2063 | |
achristensen@apple.com | e0301a3 | 2020-02-07 23:30:29 +0000 | [diff] [blame] | 2064 | dispatchDidCommitLoad(hasInsecureContent, usedLegacyTLS); |
cdumez@apple.com | 5c7c1f3 | 2019-01-16 20:40:02 +0000 | [diff] [blame] | 2065 | |
dbates@webkit.org | 1fecb92 | 2017-03-25 01:13:23 +0000 | [diff] [blame] | 2066 | // FIXME: This API should be turned around so that we ground CachedPage into the Page. |
| 2067 | cachedPage->restore(*m_frame.page()); |
commit-queue@webkit.org | 1686e5d | 2012-10-19 23:13:08 +0000 | [diff] [blame] | 2068 | |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 2069 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2070 | m_frame.page()->chrome().setDispatchViewportDataDidChangeSuppressed(false); |
| 2071 | m_frame.page()->chrome().dispatchViewportPropertiesDidChange(m_frame.page()->viewportArguments()); |
| 2072 | #endif |
wenson_hsieh@apple.com | 0c72417 | 2018-05-15 01:07:36 +0000 | [diff] [blame] | 2073 | m_frame.page()->chrome().dispatchDisabledAdaptationsDidChange(m_frame.page()->disabledAdaptations()); |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 2074 | |
| 2075 | auto& title = m_documentLoader->title(); |
| 2076 | if (!title.string.isNull()) |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2077 | m_client->dispatchDidReceiveTitle(title); |
commit-queue@webkit.org | cbb6a49 | 2010-09-20 20:20:25 +0000 | [diff] [blame] | 2078 | |
carlosgc@webkit.org | 72eb796 | 2016-01-12 08:23:36 +0000 | [diff] [blame] | 2079 | // Send remaining notifications for the main resource. |
| 2080 | notifier().sendRemainingDelegateMessages(m_documentLoader.get(), mainResourceIdentifier, mainResourceRequest, ResourceResponse(), |
| 2081 | nullptr, static_cast<int>(m_documentLoader->response().expectedContentLength()), 0, mainResouceError); |
| 2082 | |
cdumez@apple.com | 81d062f | 2020-06-29 16:32:33 +0000 | [diff] [blame] | 2083 | Vector<Ref<Frame>> targetFrames; |
| 2084 | targetFrames.append(m_frame); |
| 2085 | for (auto* child = m_frame.tree().firstChild(); child; child = child->tree().traverseNext(&m_frame)) |
| 2086 | targetFrames.append(*child); |
| 2087 | |
| 2088 | for (auto& frame : targetFrames) |
| 2089 | frame->loader().checkCompleted(); |
akling@apple.com | 9663f4b | 2013-09-05 21:25:32 +0000 | [diff] [blame] | 2090 | } else |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 2091 | didOpenURL(); |
beidson@apple.com | 3a5e3b9 | 2009-01-27 08:05:59 +0000 | [diff] [blame] | 2092 | |
wenson_hsieh@apple.com | 2851e66 | 2020-08-10 02:18:44 +0000 | [diff] [blame] | 2093 | if (auto document = makeRefPtr(m_frame.document())) |
| 2094 | document->editor().confirmCompositionAndNotifyClient(); |
| 2095 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2096 | LOG(Loading, "WebCoreLoading %s: Finished committing provisional load to URL %s", m_frame.tree().uniqueName().string().utf8().data(), |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2097 | m_frame.document() ? m_frame.document()->url().stringCenterEllipsizedToLength().utf8().data() : ""); |
beidson@apple.com | 3a5e3b9 | 2009-01-27 08:05:59 +0000 | [diff] [blame] | 2098 | |
Hironori.Fujii@sony.com | 2253a9d | 2018-07-02 01:52:14 +0000 | [diff] [blame] | 2099 | if (m_loadType == FrameLoadType::Standard && m_documentLoader && m_documentLoader->isClientRedirect()) |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2100 | history().updateForClientRedirect(); |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2101 | |
beidson@apple.com | ac095c0 | 2009-08-18 01:37:56 +0000 | [diff] [blame] | 2102 | if (m_loadingFromCachedPage) { |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2103 | // Note, didReceiveDocType is expected to be called for cached pages. See <rdar://problem/5906758> for more details. |
darin@apple.com | 9ace801 | 2017-01-23 06:24:18 +0000 | [diff] [blame] | 2104 | if (auto* page = m_frame.page()) |
| 2105 | page->chrome().didReceiveDocType(m_frame); |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 2106 | m_frame.document()->resume(ReasonForSuspension::BackForwardCache); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2107 | |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2108 | // Force a layout to update view size and thereby update scrollbars. |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 2109 | #if PLATFORM(IOS_FAMILY) |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2110 | if (!m_client->forceLayoutOnRestoreFromBackForwardCache()) |
simon.fraser@apple.com | 72978b3 | 2014-03-09 18:14:07 +0000 | [diff] [blame] | 2111 | m_frame.view()->forceLayout(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2112 | #else |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2113 | m_frame.view()->forceLayout(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2114 | #endif |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2115 | |
carlosgc@webkit.org | 72eb796 | 2016-01-12 08:23:36 +0000 | [diff] [blame] | 2116 | // Main resource delegates were already sent, so we skip the first response here. |
| 2117 | for (unsigned i = 1; i < m_documentLoader->responses().size(); ++i) { |
| 2118 | const auto& response = m_documentLoader->responses()[i]; |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2119 | // FIXME: If the WebKit client changes or cancels the request, this is not respected. |
| 2120 | ResourceError error; |
| 2121 | unsigned long identifier; |
| 2122 | ResourceRequest request(response.url()); |
| 2123 | requestFromDelegate(request, identifier, error); |
| 2124 | // FIXME: If we get a resource with more than 2B bytes, this code won't do the right thing. |
| 2125 | // However, with today's computers and networking speeds, this won't happen in practice. |
| 2126 | // Could be an issue with a giant local file. |
akling@apple.com | 654fd9a | 2013-10-06 21:07:29 +0000 | [diff] [blame] | 2127 | notifier().sendRemainingDelegateMessages(m_documentLoader.get(), identifier, request, response, 0, static_cast<int>(response.expectedContentLength()), 0, error); |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2128 | } |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2129 | |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2130 | // FIXME: Why only this frame and not parent frames? |
| 2131 | checkLoadCompleteForThisFrame(); |
| 2132 | } |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2133 | } |
| 2134 | |
akling@apple.com | 9663f4b | 2013-09-05 21:25:32 +0000 | [diff] [blame] | 2135 | void FrameLoader::transitionToCommitted(CachedPage* cachedPage) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2136 | { |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2137 | ASSERT(m_client->hasWebView()); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2138 | ASSERT(m_state == FrameStateProvisional); |
| 2139 | |
| 2140 | if (m_state != FrameStateProvisional) |
| 2141 | return; |
| 2142 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2143 | if (FrameView* view = m_frame.view()) { |
bdakin@apple.com | 3fec69c | 2012-03-23 21:02:51 +0000 | [diff] [blame] | 2144 | if (ScrollAnimator* scrollAnimator = view->existingScrollAnimator()) |
bdakin@apple.com | 87235fc | 2012-03-23 20:36:31 +0000 | [diff] [blame] | 2145 | scrollAnimator->cancelAnimations(); |
| 2146 | } |
bdakin@apple.com | e0a38ad | 2011-03-15 18:30:41 +0000 | [diff] [blame] | 2147 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2148 | m_client->setCopiesOnScroll(); |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2149 | history().updateForCommit(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2150 | |
| 2151 | // The call to closeURL() invokes the unload event handler, which can execute arbitrary |
| 2152 | // JavaScript. If the script initiates a new load, we need to abandon the current load, |
| 2153 | // or the two will stomp each other. |
darin@apple.com | 325c5bdc | 2020-05-07 18:55:50 +0000 | [diff] [blame] | 2154 | auto originalProvisionalDocumentLoader = m_provisionalDocumentLoader; |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 2155 | if (m_documentLoader) |
| 2156 | closeURL(); |
darin@apple.com | 325c5bdc | 2020-05-07 18:55:50 +0000 | [diff] [blame] | 2157 | if (originalProvisionalDocumentLoader != m_provisionalDocumentLoader) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2158 | return; |
| 2159 | |
beidson | 4a28913 | 2007-05-03 18:50:41 +0000 | [diff] [blame] | 2160 | if (m_documentLoader) |
| 2161 | m_documentLoader->stopLoadingSubresources(); |
| 2162 | if (m_documentLoader) |
| 2163 | m_documentLoader->stopLoadingPlugIns(); |
| 2164 | |
dbates@webkit.org | d77aa3f | 2017-05-03 16:58:04 +0000 | [diff] [blame] | 2165 | // Setting our document loader invokes the unload event handler of our child frames. |
| 2166 | // Script can do anything. If the script initiates a new load, we need to abandon the |
| 2167 | // current load or the two will stomp each other. |
beidson | 4a28913 | 2007-05-03 18:50:41 +0000 | [diff] [blame] | 2168 | setDocumentLoader(m_provisionalDocumentLoader.get()); |
darin@apple.com | 325c5bdc | 2020-05-07 18:55:50 +0000 | [diff] [blame] | 2169 | if (originalProvisionalDocumentLoader != m_provisionalDocumentLoader) |
dbates@webkit.org | d77aa3f | 2017-05-03 16:58:04 +0000 | [diff] [blame] | 2170 | return; |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 2171 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "transitionToCommitted: Clearing provisional document loader (m_provisionalDocumentLoader=%p)", m_provisionalDocumentLoader.get()); |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 2172 | setProvisionalDocumentLoader(nullptr); |
japhet@chromium.org | a9a58bb | 2012-09-01 01:09:02 +0000 | [diff] [blame] | 2173 | |
dbates@webkit.org | ec90788 | 2017-05-05 04:04:35 +0000 | [diff] [blame] | 2174 | // Nothing else can interrupt this commit - set the Provisional->Committed transition in stone |
commit-queue@webkit.org | 1af3b43 | 2011-08-05 07:00:47 +0000 | [diff] [blame] | 2175 | setState(FrameStateCommittedPage); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2176 | |
| 2177 | // Handle adding the URL to the back/forward list. |
darin@apple.com | 325c5bdc | 2020-05-07 18:55:50 +0000 | [diff] [blame] | 2178 | auto documentLoader = m_documentLoader; |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2179 | |
| 2180 | switch (m_loadType) { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2181 | case FrameLoadType::Forward: |
| 2182 | case FrameLoadType::Back: |
| 2183 | case FrameLoadType::IndexedBackForward: |
| 2184 | if (m_frame.page()) { |
| 2185 | // If the first load within a frame is a navigation within a back/forward list that was attached |
| 2186 | // without any of the items being loaded then we need to update the history in a similar manner as |
| 2187 | // for a standard load with the exception of updating the back/forward list (<rdar://problem/8091103>). |
| 2188 | if (!m_stateMachine.committedFirstRealDocumentLoad() && m_frame.isMainFrame()) |
| 2189 | history().updateForStandardLoad(HistoryController::UpdateAllExceptBackForwardList); |
mrowe@apple.com | 04fa487 | 2010-06-16 02:23:45 +0000 | [diff] [blame] | 2190 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2191 | history().updateForBackForwardNavigation(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2192 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2193 | // For cached pages, CachedFrame::restore will take care of firing the popstate event with the history item's state object |
| 2194 | if (history().currentItem() && !cachedPage) |
| 2195 | m_pendingStateObject = history().currentItem()->stateObject(); |
mrowe@apple.com | 04fa487 | 2010-06-16 02:23:45 +0000 | [diff] [blame] | 2196 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2197 | // Create a document view for this document, or used the cached view. |
| 2198 | if (cachedPage) { |
darin@apple.com | 325c5bdc | 2020-05-07 18:55:50 +0000 | [diff] [blame] | 2199 | ASSERT(cachedPage->documentLoader()); |
| 2200 | cachedPage->documentLoader()->attachToFrame(m_frame); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2201 | m_client->transitionToCommittedFromCachedFrame(cachedPage->cachedMainFrame()); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2202 | } else |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2203 | m_client->transitionToCommittedForNewPage(); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2204 | } |
| 2205 | break; |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2206 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2207 | case FrameLoadType::Reload: |
| 2208 | case FrameLoadType::ReloadFromOrigin: |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2209 | case FrameLoadType::ReloadExpiredOnly: |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2210 | case FrameLoadType::Same: |
| 2211 | case FrameLoadType::Replace: |
| 2212 | history().updateForReload(); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2213 | m_client->transitionToCommittedForNewPage(); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2214 | break; |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2215 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2216 | case FrameLoadType::Standard: |
| 2217 | history().updateForStandardLoad(); |
| 2218 | if (m_frame.view()) |
| 2219 | m_frame.view()->setScrollbarsSuppressed(true); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2220 | m_client->transitionToCommittedForNewPage(); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2221 | break; |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2222 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2223 | case FrameLoadType::RedirectWithLockedBackForwardList: |
| 2224 | history().updateForRedirectWithLockedBackForwardList(); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2225 | m_client->transitionToCommittedForNewPage(); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2226 | break; |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2227 | } |
| 2228 | |
darin@apple.com | 325c5bdc | 2020-05-07 18:55:50 +0000 | [diff] [blame] | 2229 | if (documentLoader) |
| 2230 | documentLoader->writer().setMIMEType(documentLoader->responseMIMEType()); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 2231 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 2232 | if (m_stateMachine.creatingInitialEmptyDocument()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 2233 | return; |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 2234 | |
| 2235 | if (!m_stateMachine.committedFirstRealDocumentLoad()) |
| 2236 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocumentPostCommit); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2237 | } |
| 2238 | |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 2239 | void FrameLoader::clientRedirectCancelledOrFinished(NewLoadInProgress newLoadInProgress) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2240 | { |
| 2241 | // Note that -webView:didCancelClientRedirectForFrame: is called on the frame load delegate even if |
| 2242 | // the redirect succeeded. We should either rename this API, or add a new method, like |
| 2243 | // -webView:didFinishClientRedirectForFrame: |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2244 | m_client->dispatchDidCancelClientRedirect(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2245 | |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 2246 | if (newLoadInProgress == NewLoadInProgress::No) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2247 | m_quickRedirectComing = false; |
| 2248 | |
| 2249 | m_sentRedirectNotification = false; |
| 2250 | } |
| 2251 | |
utatane.tea@gmail.com | eb3a809 | 2018-02-23 04:18:17 +0000 | [diff] [blame] | 2252 | void FrameLoader::clientRedirected(const URL& url, double seconds, WallTime fireDate, LockBackForwardList lockBackForwardList) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2253 | { |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2254 | m_client->dispatchWillPerformClientRedirect(url, seconds, fireDate, lockBackForwardList); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2255 | |
| 2256 | // Remember that we sent a redirect notification to the frame load delegate so that when we commit |
| 2257 | // the next provisional load, we can send a corresponding -webView:didCancelClientRedirectForFrame: |
| 2258 | m_sentRedirectNotification = true; |
| 2259 | |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 2260 | // If a "quick" redirect comes in, we set a special mode so we treat the next |
| 2261 | // load as part of the original navigation. If we don't have a document loader, we have |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2262 | // no "original" load on which to base a redirect, so we treat the redirect as a normal load. |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 2263 | // Loads triggered by JavaScript form submissions never count as quick redirects. |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 2264 | m_quickRedirectComing = (lockBackForwardList == LockBackForwardList::Yes || history().currentItemShouldBeReplaced()) && m_documentLoader && !m_isExecutingJavaScriptFormAction; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2265 | } |
| 2266 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2267 | bool FrameLoader::shouldReload(const URL& currentURL, const URL& destinationURL) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2268 | { |
| 2269 | // This function implements the rule: "Don't reload if navigating by fragment within |
| 2270 | // the same URL, but do reload if going to a new URL or to the same URL with no |
| 2271 | // fragment identifier at all." |
beidson@apple.com | ee49725 | 2009-08-10 16:35:00 +0000 | [diff] [blame] | 2272 | if (!destinationURL.hasFragmentIdentifier()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2273 | return true; |
beidson@apple.com | ee49725 | 2009-08-10 16:35:00 +0000 | [diff] [blame] | 2274 | return !equalIgnoringFragmentIdentifier(currentURL, destinationURL); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | void FrameLoader::closeOldDataSources() |
| 2278 | { |
| 2279 | // FIXME: Is it important for this traversal to be postorder instead of preorder? |
| 2280 | // If so, add helpers for postorder traversal, and use them. If not, then lets not |
| 2281 | // use a recursive algorithm here. |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2282 | for (Frame* child = m_frame.tree().firstChild(); child; child = child->tree().nextSibling()) |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2283 | child->loader().closeOldDataSources(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2284 | |
| 2285 | if (m_documentLoader) |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2286 | m_client->dispatchWillClose(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2287 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2288 | m_client->setMainFrameDocumentReady(false); // stop giving out the actual DOMDocument to observers |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2289 | } |
| 2290 | |
dbates@webkit.org | cd75cb6 | 2017-03-15 22:44:59 +0000 | [diff] [blame] | 2291 | void FrameLoader::willRestoreFromCachedPage() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2292 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2293 | ASSERT(!m_frame.tree().parent()); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2294 | ASSERT(m_frame.page()); |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 2295 | ASSERT(m_frame.isMainFrame()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2296 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2297 | m_frame.navigationScheduler().cancel(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2298 | |
| 2299 | // We still have to close the previous part page. |
| 2300 | closeURL(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2301 | |
| 2302 | // Delete old status bar messages (if it _was_ activated on last URL). |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2303 | if (m_frame.script().canExecuteScripts(NotAboutToExecuteScript)) { |
| 2304 | DOMWindow* window = m_frame.document()->domWindow(); |
abarth@webkit.org | 13fe1e2 | 2012-08-16 22:29:48 +0000 | [diff] [blame] | 2305 | window->setStatus(String()); |
| 2306 | window->setDefaultStatus(String()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2307 | } |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2308 | } |
| 2309 | |
beidson@apple.com | 913c7f8 | 2009-09-02 20:16:38 +0000 | [diff] [blame] | 2310 | void FrameLoader::open(CachedFrameBase& cachedFrame) |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2311 | { |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2312 | // Don't re-emit the load event. |
| 2313 | m_didCallImplicitClose = true; |
| 2314 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2315 | URL url = cachedFrame.url(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2316 | |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 2317 | // FIXME: I suspect this block of code doesn't do anything. |
benjamin@webkit.org | f726d63 | 2012-03-04 03:26:27 +0000 | [diff] [blame] | 2318 | if (url.protocolIsInHTTPFamily() && !url.host().isEmpty() && url.path().isEmpty()) |
weinig@apple.com | c500266 | 2007-12-12 07:26:19 +0000 | [diff] [blame] | 2319 | url.setPath("/"); |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 2320 | |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 2321 | started(); |
rniwa@webkit.org | 77c6570 | 2019-08-13 05:18:11 +0000 | [diff] [blame] | 2322 | auto document = makeRef(*cachedFrame.document()); |
abarth@webkit.org | 23ea90a | 2012-08-14 19:47:59 +0000 | [diff] [blame] | 2323 | ASSERT(document->domWindow()); |
| 2324 | |
rniwa@webkit.org | 77c6570 | 2019-08-13 05:18:11 +0000 | [diff] [blame] | 2325 | clear(document.ptr(), true, true, cachedFrame.isMainFrame()); |
abarth@webkit.org | 23ea90a | 2012-08-14 19:47:59 +0000 | [diff] [blame] | 2326 | |
cdumez@apple.com | f0705d7 | 2019-07-01 21:55:03 +0000 | [diff] [blame] | 2327 | document->attachToCachedFrame(cachedFrame); |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 2328 | document->setBackForwardCacheState(Document::NotInBackForwardCache); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2329 | |
| 2330 | m_needsClear = true; |
| 2331 | m_isComplete = false; |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 2332 | m_didCallImplicitClose = false; |
Hironori.Fujii@sony.com | 27c57b4 | 2019-08-28 01:40:42 +0000 | [diff] [blame] | 2333 | setOutgoingReferrer(url); |
kmccullo | 6b1b5c2 | 2007-05-24 20:06:56 +0000 | [diff] [blame] | 2334 | |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2335 | FrameView* view = cachedFrame.view(); |
| 2336 | |
| 2337 | // When navigating to a CachedFrame its FrameView should never be null. If it is we'll crash in creative ways downstream. |
| 2338 | ASSERT(view); |
beidson@apple.com | 24f92a5 | 2009-09-03 00:07:51 +0000 | [diff] [blame] | 2339 | view->setWasScrolledByUser(false); |
adachan@apple.com | 95f492a | 2009-08-24 19:55:23 +0000 | [diff] [blame] | 2340 | |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 2341 | Optional<IntRect> previousViewFrameRect = m_frame.view() ? m_frame.view()->frameRect() : Optional<IntRect>(WTF::nullopt); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2342 | m_frame.setView(view); |
cdumez@apple.com | 665ca3b | 2015-05-08 18:15:57 +0000 | [diff] [blame] | 2343 | |
| 2344 | // Use the previous ScrollView's frame rect. |
| 2345 | if (previousViewFrameRect) |
| 2346 | view->setFrameRect(previousViewFrameRect.value()); |
dbates@webkit.org | 7259cf3 | 2018-08-21 16:50:20 +0000 | [diff] [blame] | 2347 | |
rniwa@webkit.org | 77c6570 | 2019-08-13 05:18:11 +0000 | [diff] [blame] | 2348 | |
| 2349 | // Setting the document builds the render tree and runs post style resolution callbacks that can do anything, |
| 2350 | // including loading a child frame before its been re-attached to the frame tree as part of this restore. |
| 2351 | // For example, the HTML object element may load its content into a frame in a post style resolution callback. |
| 2352 | Style::PostResolutionCallbackDisabler disabler(document.get()); |
| 2353 | WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates; |
| 2354 | NavigationDisabler disableNavigation { &m_frame }; |
| 2355 | |
| 2356 | m_frame.setDocument(document.copyRef()); |
dbates@webkit.org | 7259cf3 | 2018-08-21 16:50:20 +0000 | [diff] [blame] | 2357 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 2358 | document->domWindow()->resumeFromBackForwardCache(); |
weinig@apple.com | 5367c41 | 2008-06-27 00:03:25 +0000 | [diff] [blame] | 2359 | |
abarth@webkit.org | 622d9df | 2009-05-22 16:44:47 +0000 | [diff] [blame] | 2360 | updateFirstPartyForCookies(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2361 | |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2362 | cachedFrame.restore(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2363 | } |
| 2364 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2365 | bool FrameLoader::isReplacing() const |
| 2366 | { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2367 | return m_loadType == FrameLoadType::Replace; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | void FrameLoader::setReplacing() |
| 2371 | { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2372 | m_loadType = FrameLoadType::Replace; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2373 | } |
| 2374 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2375 | bool FrameLoader::subframeIsLoading() const |
| 2376 | { |
| 2377 | // It's most likely that the last added frame is the last to load so we walk backwards. |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2378 | for (Frame* child = m_frame.tree().lastChild(); child; child = child->tree().previousSibling()) { |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2379 | FrameLoader& childLoader = child->loader(); |
| 2380 | DocumentLoader* documentLoader = childLoader.documentLoader(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2381 | if (documentLoader && documentLoader->isLoadingInAPISense()) |
| 2382 | return true; |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2383 | documentLoader = childLoader.provisionalDocumentLoader(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2384 | if (documentLoader && documentLoader->isLoadingInAPISense()) |
| 2385 | return true; |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2386 | documentLoader = childLoader.policyDocumentLoader(); |
mjs@apple.com | 17a175d | 2010-07-18 00:15:31 +0000 | [diff] [blame] | 2387 | if (documentLoader) |
| 2388 | return true; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2389 | } |
| 2390 | return false; |
| 2391 | } |
| 2392 | |
| 2393 | void FrameLoader::willChangeTitle(DocumentLoader* loader) |
| 2394 | { |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2395 | m_client->willChangeTitle(loader); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | FrameLoadType FrameLoader::loadType() const |
| 2399 | { |
| 2400 | return m_loadType; |
| 2401 | } |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2402 | |
antti@apple.com | 2b38ed1 | 2017-04-26 18:22:27 +0000 | [diff] [blame] | 2403 | CachePolicy FrameLoader::subresourceCachePolicy(const URL& url) const |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2404 | { |
darin@apple.com | 30c194a | 2016-03-20 20:08:59 +0000 | [diff] [blame] | 2405 | if (Page* page = m_frame.page()) { |
cdumez@apple.com | a231c91 | 2019-10-16 18:24:25 +0000 | [diff] [blame] | 2406 | if (page->isResourceCachingDisabledByWebInspector()) |
darin@apple.com | 30c194a | 2016-03-20 20:08:59 +0000 | [diff] [blame] | 2407 | return CachePolicyReload; |
| 2408 | } |
darin@apple.com | 0fdefc3 | 2016-03-18 07:56:20 +0000 | [diff] [blame] | 2409 | |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2410 | if (m_isComplete) |
| 2411 | return CachePolicyVerify; |
ap@webkit.org | 86b1098 | 2009-05-18 15:30:10 +0000 | [diff] [blame] | 2412 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2413 | if (m_loadType == FrameLoadType::ReloadFromOrigin) |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2414 | return CachePolicyReload; |
ap@webkit.org | 86b1098 | 2009-05-18 15:30:10 +0000 | [diff] [blame] | 2415 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2416 | if (Frame* parentFrame = m_frame.tree().parent()) { |
antti@apple.com | 2b38ed1 | 2017-04-26 18:22:27 +0000 | [diff] [blame] | 2417 | CachePolicy parentCachePolicy = parentFrame->loader().subresourceCachePolicy(url); |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2418 | if (parentCachePolicy != CachePolicyVerify) |
| 2419 | return parentCachePolicy; |
| 2420 | } |
slewis@apple.com | ef236f4 | 2011-05-25 23:00:45 +0000 | [diff] [blame] | 2421 | |
cdumez@apple.com | 7449316 | 2014-12-08 18:42:12 +0000 | [diff] [blame] | 2422 | switch (m_loadType) { |
| 2423 | case FrameLoadType::Reload: |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2424 | return CachePolicyRevalidate; |
cdumez@apple.com | 7449316 | 2014-12-08 18:42:12 +0000 | [diff] [blame] | 2425 | case FrameLoadType::Back: |
| 2426 | case FrameLoadType::Forward: |
| 2427 | case FrameLoadType::IndexedBackForward: |
joepeck@webkit.org | 853e686 | 2010-11-18 17:59:53 +0000 | [diff] [blame] | 2428 | return CachePolicyHistoryBuffer; |
cdumez@apple.com | 7449316 | 2014-12-08 18:42:12 +0000 | [diff] [blame] | 2429 | case FrameLoadType::ReloadFromOrigin: |
| 2430 | ASSERT_NOT_REACHED(); // Already handled above. |
| 2431 | return CachePolicyReload; |
| 2432 | case FrameLoadType::RedirectWithLockedBackForwardList: |
| 2433 | case FrameLoadType::Replace: |
| 2434 | case FrameLoadType::Same: |
| 2435 | case FrameLoadType::Standard: |
antti@apple.com | 2b38ed1 | 2017-04-26 18:22:27 +0000 | [diff] [blame] | 2436 | return CachePolicyVerify; |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2437 | case FrameLoadType::ReloadExpiredOnly: |
antti@apple.com | 2b38ed1 | 2017-04-26 18:22:27 +0000 | [diff] [blame] | 2438 | // We know about expiration for HTTP and data. Do a normal reload otherwise. |
| 2439 | if (!url.protocolIsInHTTPFamily() && !url.protocolIsData()) |
| 2440 | return CachePolicyReload; |
cdumez@apple.com | 7449316 | 2014-12-08 18:42:12 +0000 | [diff] [blame] | 2441 | return CachePolicyVerify; |
| 2442 | } |
ossy@webkit.org | 41788ca | 2014-12-08 19:30:19 +0000 | [diff] [blame] | 2443 | |
| 2444 | RELEASE_ASSERT_NOT_REACHED(); |
| 2445 | return CachePolicyVerify; |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2446 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2447 | |
aestes@apple.com | 5a4908d | 2019-06-07 06:09:40 +0000 | [diff] [blame] | 2448 | void FrameLoader::dispatchDidFailProvisionalLoad(DocumentLoader& provisionalDocumentLoader, const ResourceError& error) |
| 2449 | { |
| 2450 | m_provisionalLoadErrorBeingHandledURL = provisionalDocumentLoader.url(); |
| 2451 | |
| 2452 | #if ENABLE(CONTENT_FILTERING) |
| 2453 | auto contentFilter = provisionalDocumentLoader.contentFilter(); |
| 2454 | auto contentFilterWillContinueLoading = false; |
| 2455 | #endif |
| 2456 | |
| 2457 | auto willContinueLoading = WillContinueLoading::No; |
| 2458 | if (history().provisionalItem()) |
| 2459 | willContinueLoading = WillContinueLoading::Yes; |
| 2460 | #if ENABLE(CONTENT_FILTERING) |
| 2461 | if (contentFilter && contentFilter->willHandleProvisionalLoadFailure(error)) { |
| 2462 | willContinueLoading = WillContinueLoading::Yes; |
| 2463 | contentFilterWillContinueLoading = true; |
| 2464 | } |
| 2465 | #endif |
| 2466 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2467 | m_client->dispatchDidFailProvisionalLoad(error, willContinueLoading); |
aestes@apple.com | 5a4908d | 2019-06-07 06:09:40 +0000 | [diff] [blame] | 2468 | |
| 2469 | #if ENABLE(CONTENT_FILTERING) |
| 2470 | if (contentFilterWillContinueLoading) |
| 2471 | contentFilter->handleProvisionalLoadFailure(error); |
| 2472 | #endif |
| 2473 | |
| 2474 | m_provisionalLoadErrorBeingHandledURL = { }; |
| 2475 | } |
| 2476 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2477 | void FrameLoader::checkLoadCompleteForThisFrame() |
| 2478 | { |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2479 | ASSERT(m_client->hasWebView()); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2480 | |
darin@apple.com | be4d3dd | 2017-07-30 21:44:01 +0000 | [diff] [blame] | 2481 | // FIXME: Should this check be done in checkLoadComplete instead of here? |
| 2482 | // FIXME: Why does this one check need to be repeated here, and not the many others from checkCompleted? |
| 2483 | if (m_frame.document()->isDelayingLoadEvent()) |
| 2484 | return; |
| 2485 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2486 | switch (m_state) { |
| 2487 | case FrameStateProvisional: { |
jiewen_tan@apple.com | 8c36f62 | 2016-04-01 21:40:20 +0000 | [diff] [blame] | 2488 | // FIXME: Prohibiting any provisional load failures from being sent to clients |
| 2489 | // while handling provisional load failures is too heavy. For example, the current |
| 2490 | // load will fail to cancel another ongoing load. That might prevent clients' page |
| 2491 | // load state being handled properly. |
mitz@apple.com | 6699e27 | 2015-05-01 23:47:03 +0000 | [diff] [blame] | 2492 | if (!m_provisionalLoadErrorBeingHandledURL.isEmpty()) |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2493 | return; |
| 2494 | |
| 2495 | RefPtr<DocumentLoader> pdl = m_provisionalDocumentLoader; |
| 2496 | if (!pdl) |
| 2497 | return; |
| 2498 | |
| 2499 | // If we've received any errors we may be stuck in the provisional state and actually complete. |
| 2500 | const ResourceError& error = pdl->mainDocumentError(); |
| 2501 | if (error.isNull()) |
| 2502 | return; |
| 2503 | |
| 2504 | // Check all children first. |
| 2505 | RefPtr<HistoryItem> item; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2506 | if (Page* page = m_frame.page()) |
commit-queue@webkit.org | 21a48d8 | 2011-01-09 01:27:19 +0000 | [diff] [blame] | 2507 | if (isBackForwardLoadType(loadType())) |
| 2508 | // Reset the back forward list to the last committed history item at the top level. |
akling@apple.com | 095b544 | 2013-08-27 02:47:37 +0000 | [diff] [blame] | 2509 | item = page->mainFrame().loader().history().currentItem(); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2510 | |
commit-queue@webkit.org | 987fd77 | 2011-01-21 18:26:42 +0000 | [diff] [blame] | 2511 | // Only reset if we aren't already going to a new provisional item. |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2512 | bool shouldReset = !history().provisionalItem(); |
ap@apple.com | 421e9a1 | 2011-03-24 00:50:45 +0000 | [diff] [blame] | 2513 | if (!pdl->isLoadingInAPISense() || pdl->isStopping()) { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 2514 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "checkLoadCompleteForThisFrame: Failed provisional load (isTimeout = %d, isCancellation = %d, errorCode = %d)", error.isTimeout(), error.isCancellation(), error.errorCode()); |
cdumez@apple.com | 41883a9 | 2019-04-23 15:38:11 +0000 | [diff] [blame] | 2515 | |
aestes@apple.com | 5a4908d | 2019-06-07 06:09:40 +0000 | [diff] [blame] | 2516 | dispatchDidFailProvisionalLoad(*pdl, error); |
ap@apple.com | 09535d1 | 2011-03-24 00:48:30 +0000 | [diff] [blame] | 2517 | ASSERT(!pdl->isLoading()); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2518 | |
eric@webkit.org | b562c40 | 2010-01-13 01:29:35 +0000 | [diff] [blame] | 2519 | // If we're in the middle of loading multipart data, we need to restore the document loader. |
| 2520 | if (isReplacing() && !m_documentLoader.get()) |
eric@webkit.org | 9074725 | 2010-01-12 18:10:14 +0000 | [diff] [blame] | 2521 | setDocumentLoader(m_provisionalDocumentLoader.get()); |
| 2522 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2523 | // Finish resetting the load state, but only if another load hasn't been started by the |
| 2524 | // delegate callback. |
| 2525 | if (pdl == m_provisionalDocumentLoader) |
| 2526 | clearProvisionalLoad(); |
tonikitoo@webkit.org | e94ac9b | 2009-11-16 15:38:19 +0000 | [diff] [blame] | 2527 | else if (activeDocumentLoader()) { |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2528 | URL unreachableURL = activeDocumentLoader()->unreachableURL(); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2529 | if (!unreachableURL.isEmpty() && unreachableURL == pdl->request().url()) |
| 2530 | shouldReset = false; |
| 2531 | } |
| 2532 | } |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 2533 | if (shouldReset && item) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2534 | if (Page* page = m_frame.page()) { |
achristensen@apple.com | 3a889f1 | 2018-10-16 15:58:10 +0000 | [diff] [blame] | 2535 | page->backForward().setCurrentItem(*item); |
mitz@apple.com | bc84376 | 2008-12-08 21:18:11 +0000 | [diff] [blame] | 2536 | } |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2537 | return; |
| 2538 | } |
| 2539 | |
| 2540 | case FrameStateCommittedPage: { |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 2541 | if (!m_documentLoader) |
| 2542 | return; |
| 2543 | if (m_documentLoader->isLoadingInAPISense() && !m_documentLoader->isStopping() && !m_checkingLoadCompleteForDetachment) |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2544 | return; |
| 2545 | |
darin@apple.com | af8b1a9 | 2011-06-25 00:09:37 +0000 | [diff] [blame] | 2546 | setState(FrameStateComplete); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2547 | |
| 2548 | // FIXME: Is this subsequent work important if we already navigated away? |
| 2549 | // Maybe there are bugs because of that, or extra work we can skip because |
| 2550 | // the new page is ready. |
| 2551 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2552 | m_client->forceLayoutForNonHTML(); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2553 | |
| 2554 | // If the user had a scroll point, scroll to it, overriding the anchor point if any. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2555 | if (m_frame.page()) { |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2556 | if (isBackForwardLoadType(m_loadType) || isReload(m_loadType)) |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2557 | history().restoreScrollPositionAndViewState(); |
darin@apple.com | e10e128 | 2010-10-30 00:44:33 +0000 | [diff] [blame] | 2558 | } |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2559 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 2560 | if (m_stateMachine.creatingInitialEmptyDocument() || !m_stateMachine.committedFirstRealDocumentLoad()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 2561 | return; |
| 2562 | |
timothy_horton@apple.com | 346f8d7 | 2013-08-01 00:06:51 +0000 | [diff] [blame] | 2563 | m_progressTracker->progressCompleted(); |
eric.carlson@apple.com | 77b4a11 | 2014-10-30 19:04:29 +0000 | [diff] [blame] | 2564 | Page* page = m_frame.page(); |
| 2565 | if (page) { |
simon.fraser@apple.com | 83325b9 | 2017-03-17 00:47:16 +0000 | [diff] [blame] | 2566 | if (m_frame.isMainFrame()) { |
sbarati@apple.com | ce7ec11 | 2018-04-17 15:57:32 +0000 | [diff] [blame] | 2567 | tracePoint(MainResourceLoadDidEnd); |
cdumez@apple.com | ef2c015 | 2017-01-13 17:54:53 +0000 | [diff] [blame] | 2568 | page->didFinishLoad(); |
simon.fraser@apple.com | 83325b9 | 2017-03-17 00:47:16 +0000 | [diff] [blame] | 2569 | } |
andersca@apple.com | 7c0a3fc | 2012-05-01 22:22:25 +0000 | [diff] [blame] | 2570 | } |
| 2571 | |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 2572 | const ResourceError& error = m_documentLoader->mainDocumentError(); |
mario@webkit.org | 685258f | 2011-12-06 00:10:55 +0000 | [diff] [blame] | 2573 | |
| 2574 | AXObjectCache::AXLoadingEvent loadingEvent; |
| 2575 | if (!error.isNull()) { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 2576 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "checkLoadCompleteForThisFrame: Finished frame load with error (isTimeout = %d, isCancellation = %d, errorCode = %d)", error.isTimeout(), error.isCancellation(), error.errorCode()); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2577 | m_client->dispatchDidFailLoad(error); |
mario@webkit.org | 685258f | 2011-12-06 00:10:55 +0000 | [diff] [blame] | 2578 | loadingEvent = AXObjectCache::AXLoadingFailed; |
| 2579 | } else { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 2580 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "checkLoadCompleteForThisFrame: Finished frame load"); |
enrica@apple.com | 53b08e5 | 2016-01-19 22:58:59 +0000 | [diff] [blame] | 2581 | #if ENABLE(DATA_DETECTION) |
darin@apple.com | e729ead | 2020-04-27 15:05:00 +0000 | [diff] [blame] | 2582 | auto document = m_frame.document(); |
| 2583 | auto types = m_frame.settings().dataDetectorTypes(); |
| 2584 | if (document && static_cast<uint32_t>(types)) { |
| 2585 | m_frame.setDataDetectionResults(DataDetection::detectContentInRange(makeRangeSelectingNodeContents(*document), types, m_client->dataDetectionContext())); |
| 2586 | if (m_frame.isMainFrame()) |
| 2587 | m_client->dispatchDidFinishDataDetection(m_frame.dataDetectionResults()); |
enrica@apple.com | 53b08e5 | 2016-01-19 22:58:59 +0000 | [diff] [blame] | 2588 | } |
| 2589 | #endif |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2590 | m_client->dispatchDidFinishLoad(); |
enrica@apple.com | 4c36ad5 | 2016-01-23 00:24:02 +0000 | [diff] [blame] | 2591 | loadingEvent = AXObjectCache::AXLoadingFinished; |
mario@webkit.org | 685258f | 2011-12-06 00:10:55 +0000 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | // Notify accessibility. |
rniwa@webkit.org | 2f150e7 | 2016-06-14 07:35:53 +0000 | [diff] [blame] | 2595 | if (auto* document = m_frame.document()) { |
| 2596 | if (AXObjectCache* cache = document->existingAXObjectCache()) |
| 2597 | cache->frameLoadingEventNotification(&m_frame, loadingEvent); |
| 2598 | } |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2599 | |
beidson@apple.com | 4aecb3d | 2015-07-09 04:47:09 +0000 | [diff] [blame] | 2600 | // The above calls to dispatchDidFinishLoad() might have detached the Frame |
| 2601 | // from its Page and also might have caused Page to be deleted. |
| 2602 | // Don't assume 'page' is still available to use. |
| 2603 | if (m_frame.isMainFrame() && m_frame.page()) { |
| 2604 | ASSERT(&m_frame.page()->mainFrame() == &m_frame); |
cdumez@apple.com | 10d0f25 | 2016-04-23 21:33:49 +0000 | [diff] [blame] | 2605 | m_frame.page()->diagnosticLoggingClient().logDiagnosticMessageWithResult(DiagnosticLoggingKeys::pageLoadedKey(), emptyString(), error.isNull() ? DiagnosticLoggingResultPass : DiagnosticLoggingResultFail, ShouldSample::Yes); |
beidson@apple.com | 4aecb3d | 2015-07-09 04:47:09 +0000 | [diff] [blame] | 2606 | } |
eric.carlson@apple.com | 77b4a11 | 2014-10-30 19:04:29 +0000 | [diff] [blame] | 2607 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2608 | return; |
| 2609 | } |
| 2610 | |
| 2611 | case FrameStateComplete: |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2612 | m_loadType = FrameLoadType::Standard; |
beidson@apple.com | d141827 | 2009-01-30 17:30:47 +0000 | [diff] [blame] | 2613 | frameLoadCompleted(); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2614 | return; |
| 2615 | } |
| 2616 | |
| 2617 | ASSERT_NOT_REACHED(); |
| 2618 | } |
andersca | 5d5f802 | 2007-02-28 00:38:00 +0000 | [diff] [blame] | 2619 | |
ap@apple.com | 456d465 | 2011-11-30 12:13:31 +0000 | [diff] [blame] | 2620 | void FrameLoader::setOriginalURLForDownloadRequest(ResourceRequest& request) |
| 2621 | { |
jiewen_tan@apple.com | 8283620 | 2016-03-31 20:39:24 +0000 | [diff] [blame] | 2622 | // FIXME: Rename firstPartyForCookies back to mainDocumentURL. It was a mistake to think that it was only used for cookies. |
| 2623 | // The originalURL is defined as the URL of the page where the download was initiated. |
jiewen_tan@apple.com | 65b3816 | 2016-12-22 00:04:11 +0000 | [diff] [blame] | 2624 | URL originalURL; |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2625 | auto* initiator = m_frame.document(); |
| 2626 | if (initiator) { |
| 2627 | originalURL = initiator->firstPartyForCookies(); |
jiewen_tan@apple.com | 65b3816 | 2016-12-22 00:04:11 +0000 | [diff] [blame] | 2628 | // If there is no main document URL, it means that this document is newly opened and just for download purpose. |
| 2629 | // In this case, we need to set the originalURL to this document's opener's main document URL. |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2630 | if (originalURL.isEmpty() && opener() && opener()->document()) { |
jiewen_tan@apple.com | 65b3816 | 2016-12-22 00:04:11 +0000 | [diff] [blame] | 2631 | originalURL = opener()->document()->firstPartyForCookies(); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2632 | initiator = opener()->document(); |
| 2633 | } |
jiewen_tan@apple.com | 65b3816 | 2016-12-22 00:04:11 +0000 | [diff] [blame] | 2634 | } |
jiewen_tan@apple.com | 8283620 | 2016-03-31 20:39:24 +0000 | [diff] [blame] | 2635 | // If the originalURL is the same as the requested URL, we are processing a download |
| 2636 | // initiated directly without a page and do not need to specify the originalURL. |
| 2637 | if (originalURL == request.url()) |
| 2638 | request.setFirstPartyForCookies(URL()); |
| 2639 | else |
| 2640 | request.setFirstPartyForCookies(originalURL); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2641 | addSameSiteInfoToRequestIfNeeded(request, initiator); |
ap@apple.com | 456d465 | 2011-11-30 12:13:31 +0000 | [diff] [blame] | 2642 | } |
| 2643 | |
antti@apple.com | 8e03f74 | 2018-11-09 19:47:15 +0000 | [diff] [blame] | 2644 | void FrameLoader::didReachLayoutMilestone(OptionSet<LayoutMilestone> milestones) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2645 | { |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 2646 | ASSERT(m_frame.isMainFrame()); |
bdakin@apple.com | 7ce7e1b | 2013-08-12 21:37:06 +0000 | [diff] [blame] | 2647 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2648 | m_client->dispatchDidReachLayoutMilestone(milestones); |
bdakin@apple.com | 3ab3737 | 2012-02-01 21:52:41 +0000 | [diff] [blame] | 2649 | } |
| 2650 | |
bdakin@apple.com | e98caf1 | 2012-09-25 23:08:03 +0000 | [diff] [blame] | 2651 | void FrameLoader::didFirstLayout() |
| 2652 | { |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 2653 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2654 | // Only send layout-related delegate callbacks synchronously for the main frame to |
| 2655 | // avoid reentering layout for the main frame while delivering a layout-related delegate |
| 2656 | // callback for a subframe. |
| 2657 | if (&m_frame != &m_frame.page()->mainFrame()) |
| 2658 | return; |
| 2659 | #endif |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2660 | if (m_frame.page() && isBackForwardLoadType(m_loadType)) |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2661 | history().restoreScrollPositionAndViewState(); |
bdakin@apple.com | e98caf1 | 2012-09-25 23:08:03 +0000 | [diff] [blame] | 2662 | |
| 2663 | if (m_stateMachine.committedFirstRealDocumentLoad() && !m_stateMachine.isDisplayingInitialEmptyDocument() && !m_stateMachine.firstLayoutDone()) |
| 2664 | m_stateMachine.advanceTo(FrameLoaderStateMachine::FirstLayoutDone); |
| 2665 | } |
| 2666 | |
zalan@apple.com | fc7ad74 | 2020-03-04 14:53:01 +0000 | [diff] [blame] | 2667 | void FrameLoader::didReachVisuallyNonEmptyState() |
| 2668 | { |
| 2669 | ASSERT(m_frame.isMainFrame()); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2670 | m_client->dispatchDidReachVisuallyNonEmptyState(); |
zalan@apple.com | fc7ad74 | 2020-03-04 14:53:01 +0000 | [diff] [blame] | 2671 | } |
| 2672 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2673 | void FrameLoader::frameLoadCompleted() |
| 2674 | { |
beidson@apple.com | d141827 | 2009-01-30 17:30:47 +0000 | [diff] [blame] | 2675 | // Note: Can be called multiple times. |
| 2676 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2677 | m_client->frameLoadCompleted(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2678 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2679 | history().updateForFrameLoadCompleted(); |
beidson@apple.com | d141827 | 2009-01-30 17:30:47 +0000 | [diff] [blame] | 2680 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2681 | // After a canceled provisional load, firstLayoutDone is false. |
| 2682 | // Reset it to true if we're displaying a page. |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 2683 | if (m_documentLoader && m_stateMachine.committedFirstRealDocumentLoad() && !m_stateMachine.isDisplayingInitialEmptyDocument() && !m_stateMachine.firstLayoutDone()) |
| 2684 | m_stateMachine.advanceTo(FrameLoaderStateMachine::FirstLayoutDone); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2685 | } |
| 2686 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2687 | void FrameLoader::detachChildren() |
| 2688 | { |
cdumez@apple.com | 8b478c6 | 2016-01-23 01:04:59 +0000 | [diff] [blame] | 2689 | // detachChildren() will fire the unload event in each subframe and the |
| 2690 | // HTML specification states that the parent document's ignore-opens-during-unload counter while |
| 2691 | // this event is being fired in its subframes: |
| 2692 | // https://html.spec.whatwg.org/multipage/browsers.html#unload-a-document |
| 2693 | IgnoreOpensDuringUnloadCountIncrementer ignoreOpensDuringUnloadCountIncrementer(m_frame.document()); |
| 2694 | |
cdumez@apple.com | f0705d7 | 2019-07-01 21:55:03 +0000 | [diff] [blame] | 2695 | // detachChildren() will fire the unload event in each subframe and the |
| 2696 | // HTML specification states that navigations should be prevented during the prompt to unload algorithm: |
| 2697 | // https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate |
| 2698 | std::unique_ptr<NavigationDisabler> navigationDisabler; |
| 2699 | if (m_frame.isMainFrame()) |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 2700 | navigationDisabler = makeUnique<NavigationDisabler>(&m_frame); |
cdumez@apple.com | f0705d7 | 2019-07-01 21:55:03 +0000 | [diff] [blame] | 2701 | |
cdumez@apple.com | 6857a01 | 2017-03-02 23:43:09 +0000 | [diff] [blame] | 2702 | // Any subframe inserted by unload event handlers executed in the loop below will not get unloaded |
| 2703 | // because we create a copy of the subframes list before looping. Therefore, it would be unsafe to |
| 2704 | // allow loading of subframes at this point. |
| 2705 | SubframeLoadingDisabler subframeLoadingDisabler(m_frame.document()); |
| 2706 | |
akling@apple.com | 72c1c36 | 2013-09-06 01:34:05 +0000 | [diff] [blame] | 2707 | Vector<Ref<Frame>, 16> childrenToDetach; |
| 2708 | childrenToDetach.reserveInitialCapacity(m_frame.tree().childCount()); |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2709 | for (Frame* child = m_frame.tree().lastChild(); child; child = child->tree().previousSibling()) |
akling@apple.com | 72c1c36 | 2013-09-06 01:34:05 +0000 | [diff] [blame] | 2710 | childrenToDetach.uncheckedAppend(*child); |
commit-queue@webkit.org | acddfad | 2015-09-30 05:53:51 +0000 | [diff] [blame] | 2711 | for (auto& child : childrenToDetach) |
| 2712 | child->loader().detachFromParent(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2713 | } |
| 2714 | |
darin@apple.com | 9ace801 | 2017-01-23 06:24:18 +0000 | [diff] [blame] | 2715 | void FrameLoader::closeAndRemoveChild(Frame& child) |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2716 | { |
darin@apple.com | 9ace801 | 2017-01-23 06:24:18 +0000 | [diff] [blame] | 2717 | child.tree().detachFromParent(); |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2718 | |
darin@apple.com | 9ace801 | 2017-01-23 06:24:18 +0000 | [diff] [blame] | 2719 | child.setView(nullptr); |
darin@apple.com | 9ace801 | 2017-01-23 06:24:18 +0000 | [diff] [blame] | 2720 | child.willDetachPage(); |
| 2721 | child.detachFromPage(); |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2722 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2723 | m_frame.tree().removeChild(child); |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2724 | } |
| 2725 | |
darin@apple.com | af8b1a9 | 2011-06-25 00:09:37 +0000 | [diff] [blame] | 2726 | // Called every time a resource is completely loaded or an error is received. |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2727 | void FrameLoader::checkLoadComplete() |
| 2728 | { |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 2729 | m_shouldCallCheckLoadComplete = false; |
| 2730 | |
akling@apple.com | 72c1c36 | 2013-09-06 01:34:05 +0000 | [diff] [blame] | 2731 | if (!m_frame.page()) |
| 2732 | return; |
| 2733 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2734 | ASSERT(m_client->hasWebView()); |
darin@apple.com | 355b152 | 2017-08-15 18:13:57 +0000 | [diff] [blame] | 2735 | |
andersca | a315d57 | 2007-03-13 01:09:53 +0000 | [diff] [blame] | 2736 | // FIXME: Always traversing the entire frame tree is a bit inefficient, but |
| 2737 | // is currently needed in order to null out the previous history item for all frames. |
akling@apple.com | 72c1c36 | 2013-09-06 01:34:05 +0000 | [diff] [blame] | 2738 | Vector<Ref<Frame>, 16> frames; |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 2739 | for (Frame* frame = &m_frame.mainFrame(); frame; frame = frame->tree().traverseNext()) |
akling@apple.com | 72c1c36 | 2013-09-06 01:34:05 +0000 | [diff] [blame] | 2740 | frames.append(*frame); |
| 2741 | |
| 2742 | // To process children before their parents, iterate the vector backwards. |
jiewen_tan@apple.com | be26fa3 | 2015-12-01 00:33:47 +0000 | [diff] [blame] | 2743 | for (auto frame = frames.rbegin(); frame != frames.rend(); ++frame) { |
| 2744 | if ((*frame)->page()) |
| 2745 | (*frame)->loader().checkLoadCompleteForThisFrame(); |
| 2746 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | int FrameLoader::numPendingOrLoadingRequests(bool recurse) const |
| 2750 | { |
| 2751 | if (!recurse) |
cdumez@apple.com | 0bb03ec | 2015-01-28 05:53:53 +0000 | [diff] [blame] | 2752 | return m_frame.document()->cachedResourceLoader().requestCount(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2753 | |
| 2754 | int count = 0; |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2755 | for (Frame* frame = &m_frame; frame; frame = frame->tree().traverseNext(&m_frame)) |
cdumez@apple.com | 0bb03ec | 2015-01-28 05:53:53 +0000 | [diff] [blame] | 2756 | count += frame->document()->cachedResourceLoader().requestCount(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2757 | return count; |
| 2758 | } |
| 2759 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2760 | String FrameLoader::userAgent(const URL& url) const |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2761 | { |
drousso@apple.com | c9a88bd | 2019-01-26 22:32:38 +0000 | [diff] [blame] | 2762 | String userAgent; |
| 2763 | |
rniwa@webkit.org | 1547091 | 2019-01-26 06:50:58 +0000 | [diff] [blame] | 2764 | if (auto* documentLoader = m_frame.mainFrame().loader().activeDocumentLoader()) { |
rniwa@webkit.org | af0b1ae | 2019-01-29 07:15:00 +0000 | [diff] [blame] | 2765 | if (m_frame.settings().needsSiteSpecificQuirks()) |
rniwa@webkit.org | 75b8f3e | 2019-12-04 04:28:10 +0000 | [diff] [blame] | 2766 | userAgent = documentLoader->customUserAgentAsSiteSpecificQuirks(); |
drousso@apple.com | c9a88bd | 2019-01-26 22:32:38 +0000 | [diff] [blame] | 2767 | if (userAgent.isEmpty()) |
| 2768 | userAgent = documentLoader->customUserAgent(); |
rniwa@webkit.org | 1547091 | 2019-01-26 06:50:58 +0000 | [diff] [blame] | 2769 | } |
| 2770 | |
drousso@apple.com | c9a88bd | 2019-01-26 22:32:38 +0000 | [diff] [blame] | 2771 | InspectorInstrumentation::applyUserAgentOverride(m_frame, userAgent); |
| 2772 | |
| 2773 | if (!userAgent.isEmpty()) |
| 2774 | return userAgent; |
| 2775 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2776 | return m_client->userAgent(url); |
rniwa@webkit.org | 1547091 | 2019-01-26 06:50:58 +0000 | [diff] [blame] | 2777 | } |
rniwa@webkit.org | 75b8f3e | 2019-12-04 04:28:10 +0000 | [diff] [blame] | 2778 | |
megan_gardner@apple.com | de788db | 2018-12-19 20:21:31 +0000 | [diff] [blame] | 2779 | String FrameLoader::navigatorPlatform() const |
| 2780 | { |
| 2781 | if (auto* documentLoader = m_frame.mainFrame().loader().activeDocumentLoader()) { |
| 2782 | auto& customNavigatorPlatform = documentLoader->customNavigatorPlatform(); |
| 2783 | if (!customNavigatorPlatform.isEmpty()) |
| 2784 | return customNavigatorPlatform; |
| 2785 | } |
| 2786 | return String(); |
| 2787 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2788 | |
ggaren@apple.com | 7a176e1 | 2015-11-12 01:48:27 +0000 | [diff] [blame] | 2789 | void FrameLoader::dispatchOnloadEvents() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2790 | { |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2791 | m_client->dispatchDidDispatchOnloadEvents(); |
japhet@chromium.org | 92a952b | 2010-07-12 18:14:17 +0000 | [diff] [blame] | 2792 | |
darin@apple.com | af8b1a9 | 2011-06-25 00:09:37 +0000 | [diff] [blame] | 2793 | if (documentLoader()) |
ggaren@apple.com | 7a176e1 | 2015-11-12 01:48:27 +0000 | [diff] [blame] | 2794 | documentLoader()->dispatchOnloadEvents(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | void FrameLoader::frameDetached() |
| 2798 | { |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 2799 | // Calling stopAllLoadersAndCheckCompleteness() can cause the frame to be deallocated, including the frame loader. |
bfulgham@apple.com | 98845d9 | 2016-05-17 01:09:27 +0000 | [diff] [blame] | 2800 | Ref<Frame> protectedFrame(m_frame); |
| 2801 | |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 2802 | if (m_checkTimer.isActive()) { |
| 2803 | m_checkTimer.stop(); |
| 2804 | checkCompletenessNow(); |
| 2805 | } |
| 2806 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 2807 | if (m_frame.document()->backForwardCacheState() != Document::InBackForwardCache) { |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 2808 | stopAllLoadersAndCheckCompleteness(); |
dbates@webkit.org | 6d862de | 2017-02-11 02:53:53 +0000 | [diff] [blame] | 2809 | m_frame.document()->stopActiveDOMObjects(); |
| 2810 | } |
| 2811 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2812 | detachFromParent(); |
| 2813 | } |
| 2814 | |
ggaren | c04b2c5 | 2006-11-30 21:06:14 +0000 | [diff] [blame] | 2815 | void FrameLoader::detachFromParent() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2816 | { |
dbates@webkit.org | 6d862de | 2017-02-11 02:53:53 +0000 | [diff] [blame] | 2817 | // Calling stopAllLoaders() can cause the frame to be deallocated, including the frame loader. |
akling@apple.com | a34e522 | 2013-09-10 03:44:05 +0000 | [diff] [blame] | 2818 | Ref<Frame> protect(m_frame); |
ggaren | c04b2c5 | 2006-11-30 21:06:14 +0000 | [diff] [blame] | 2819 | |
ggaren | acf2874 | 2006-12-27 07:38:18 +0000 | [diff] [blame] | 2820 | closeURL(); |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2821 | history().saveScrollPositionAndViewStateToItem(history().currentItem()); |
ggaren | c04b2c5 | 2006-11-30 21:06:14 +0000 | [diff] [blame] | 2822 | detachChildren(); |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 2823 | if (m_frame.document()->backForwardCacheState() != Document::InBackForwardCache) { |
| 2824 | // stopAllLoaders() needs to be called after detachChildren() if the document is not in the back/forward cache, |
dbates@webkit.org | 6d862de | 2017-02-11 02:53:53 +0000 | [diff] [blame] | 2825 | // because detachedChildren() will trigger the unload event handlers of any child frames, and those event |
| 2826 | // handlers might start a new subresource load in this frame. |
ajuma@chromium.org | edd7574 | 2019-09-11 14:52:18 +0000 | [diff] [blame] | 2827 | stopAllLoaders(ShouldClearProvisionalItem, StopLoadingPolicy::AlwaysStopLoading); |
dbates@webkit.org | 6d862de | 2017-02-11 02:53:53 +0000 | [diff] [blame] | 2828 | } |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 2829 | |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 2830 | InspectorInstrumentation::frameDetachedFromParent(m_frame); |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 2831 | |
beidson@apple.com | 24f92a5 | 2009-09-03 00:07:51 +0000 | [diff] [blame] | 2832 | detachViewsAndDocumentLoader(); |
| 2833 | |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 2834 | m_progressTracker = nullptr; |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 2835 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2836 | if (Frame* parent = m_frame.tree().parent()) { |
darin@apple.com | 9ace801 | 2017-01-23 06:24:18 +0000 | [diff] [blame] | 2837 | parent->loader().closeAndRemoveChild(m_frame); |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2838 | parent->loader().scheduleCheckCompleted(); |
darin@apple.com | be4d3dd | 2017-07-30 21:44:01 +0000 | [diff] [blame] | 2839 | parent->loader().scheduleCheckLoadComplete(); |
weinig | c34c71c | 2007-03-09 16:05:37 +0000 | [diff] [blame] | 2840 | } else { |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 2841 | m_frame.setView(nullptr); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2842 | m_frame.willDetachPage(); |
| 2843 | m_frame.detachFromPage(); |
ddkilzer | 3adeb2f | 2006-12-28 23:33:37 +0000 | [diff] [blame] | 2844 | } |
ggaren | c04b2c5 | 2006-11-30 21:06:14 +0000 | [diff] [blame] | 2845 | } |
beidson@apple.com | 24f92a5 | 2009-09-03 00:07:51 +0000 | [diff] [blame] | 2846 | |
| 2847 | void FrameLoader::detachViewsAndDocumentLoader() |
| 2848 | { |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2849 | m_client->detachedFromParent2(); |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 2850 | setDocumentLoader(nullptr); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 2851 | m_client->detachedFromParent3(); |
beidson@apple.com | 24f92a5 | 2009-09-03 00:07:51 +0000 | [diff] [blame] | 2852 | } |
commit-queue@webkit.org | 53c0a6b | 2020-04-02 07:43:14 +0000 | [diff] [blame] | 2853 | |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2854 | ResourceRequestCachePolicy FrameLoader::defaultRequestCachingPolicy(const ResourceRequest& request, FrameLoadType loadType, bool isMainResource) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2855 | { |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2856 | if (m_overrideCachePolicyForTesting) |
| 2857 | return m_overrideCachePolicyForTesting.value(); |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2858 | |
| 2859 | if (isMainResource) { |
| 2860 | if (isReload(loadType) || request.isConditional()) |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2861 | return ResourceRequestCachePolicy::ReloadIgnoringCacheData; |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2862 | |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2863 | return ResourceRequestCachePolicy::UseProtocolCachePolicy; |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | if (request.isConditional()) |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2867 | return ResourceRequestCachePolicy::ReloadIgnoringCacheData; |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2868 | |
beidson@apple.com | 33772ac | 2020-08-15 00:35:42 +0000 | [diff] [blame] | 2869 | auto* documentLoader = this->documentLoader(); |
| 2870 | if (documentLoader && documentLoader->isLoadingInAPISense()) { |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2871 | // If we inherit cache policy from a main resource, we use the DocumentLoader's |
| 2872 | // original request cache policy for two reasons: |
| 2873 | // 1. For POST requests, we mutate the cache policy for the main resource, |
| 2874 | // but we do not want this to apply to subresources |
| 2875 | // 2. Delegates that modify the cache policy using willSendRequest: should |
| 2876 | // not affect any other resources. Such changes need to be done |
| 2877 | // per request. |
beidson@apple.com | 33772ac | 2020-08-15 00:35:42 +0000 | [diff] [blame] | 2878 | ResourceRequestCachePolicy mainDocumentOriginalCachePolicy = documentLoader->originalRequest().cachePolicy(); |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2879 | // Back-forward navigations try to load main resource from cache only to avoid re-submitting form data, and start over (with a warning dialog) if that fails. |
| 2880 | // This policy is set on initial request too, but should not be inherited. |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2881 | return (mainDocumentOriginalCachePolicy == ResourceRequestCachePolicy::ReturnCacheDataDontLoad) ? ResourceRequestCachePolicy::ReturnCacheDataElseLoad : mainDocumentOriginalCachePolicy; |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2882 | } |
| 2883 | |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2884 | return ResourceRequestCachePolicy::UseProtocolCachePolicy; |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2885 | } |
| 2886 | |
commit-queue@webkit.org | 627a2de | 2020-04-13 08:04:39 +0000 | [diff] [blame] | 2887 | void FrameLoader::addExtraFieldsToRequest(ResourceRequest& request, IsMainResource mainResource, FrameLoadType loadType) |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2888 | { |
cdumez@apple.com | 3aedc03 | 2019-01-31 02:23:55 +0000 | [diff] [blame] | 2889 | // If the request came from a previous process due to process-swap-on-navigation then we should not modify the request. |
| 2890 | if (m_currentLoadContinuingState == LoadContinuingState::ContinuingWithRequest) |
cdumez@apple.com | fdb8971 | 2018-06-11 20:52:31 +0000 | [diff] [blame] | 2891 | return; |
| 2892 | |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2893 | // Don't set the cookie policy URL if it's already been set. |
| 2894 | // But make sure to set it on all requests regardless of protocol, as it has significance beyond the cookie policy (<rdar://problem/6616664>). |
commit-queue@webkit.org | 627a2de | 2020-04-13 08:04:39 +0000 | [diff] [blame] | 2895 | bool isMainResource = mainResource == IsMainResource::Yes; |
dbates@webkit.org | 2dc5b0d | 2019-02-21 23:54:40 +0000 | [diff] [blame] | 2896 | bool isMainFrameMainResource = isMainResource && m_frame.isMainFrame(); |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2897 | if (request.firstPartyForCookies().isEmpty()) { |
dbates@webkit.org | 2dc5b0d | 2019-02-21 23:54:40 +0000 | [diff] [blame] | 2898 | if (isMainFrameMainResource) |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2899 | request.setFirstPartyForCookies(request.url()); |
| 2900 | else if (Document* document = m_frame.document()) |
| 2901 | request.setFirstPartyForCookies(document->firstPartyForCookies()); |
| 2902 | } |
| 2903 | |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2904 | if (request.isSameSiteUnspecified()) { |
| 2905 | auto* initiator = m_frame.document(); |
| 2906 | if (isMainResource) { |
| 2907 | auto* ownerFrame = m_frame.tree().parent(); |
dbates@webkit.org | 1e85855 | 2018-06-30 02:11:01 +0000 | [diff] [blame] | 2908 | if (!ownerFrame && m_stateMachine.isDisplayingInitialEmptyDocument()) |
achristensen@apple.com | 2ace43d | 2020-11-05 16:54:48 +0000 | [diff] [blame] | 2909 | ownerFrame = m_opener.get(); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2910 | if (ownerFrame) |
| 2911 | initiator = ownerFrame->document(); |
| 2912 | ASSERT(ownerFrame || m_frame.isMainFrame()); |
| 2913 | } |
| 2914 | addSameSiteInfoToRequestIfNeeded(request, initiator); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2915 | } |
dbates@webkit.org | 2dc5b0d | 2019-02-21 23:54:40 +0000 | [diff] [blame] | 2916 | request.setIsTopSite(isMainFrameMainResource); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2917 | |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2918 | Page* page = frame().page(); |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2919 | bool hasSpecificCachePolicy = request.cachePolicy() != ResourceRequestCachePolicy::UseProtocolCachePolicy; |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2920 | |
cdumez@apple.com | a231c91 | 2019-10-16 18:24:25 +0000 | [diff] [blame] | 2921 | if (page && page->isResourceCachingDisabledByWebInspector()) { |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2922 | request.setCachePolicy(ResourceRequestCachePolicy::ReloadIgnoringCacheData); |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2923 | loadType = FrameLoadType::ReloadFromOrigin; |
| 2924 | } else if (!hasSpecificCachePolicy) |
| 2925 | request.setCachePolicy(defaultRequestCachingPolicy(request, loadType, isMainResource)); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 2926 | |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2927 | // The remaining modifications are only necessary for HTTP and HTTPS. |
| 2928 | if (!request.url().isEmpty() && !request.url().protocolIsInHTTPFamily()) |
| 2929 | return; |
antti@apple.com | 7c97e2c | 2015-03-19 05:21:40 +0000 | [diff] [blame] | 2930 | |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2931 | if (!hasSpecificCachePolicy && request.cachePolicy() == ResourceRequestCachePolicy::ReloadIgnoringCacheData) { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2932 | if (loadType == FrameLoadType::Reload) |
commit-queue@webkit.org | f1fbce6 | 2020-01-01 11:25:53 +0000 | [diff] [blame] | 2933 | request.setHTTPHeaderField(HTTPHeaderName::CacheControl, HTTPHeaderValues::maxAge0()); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2934 | else if (loadType == FrameLoadType::ReloadFromOrigin) { |
commit-queue@webkit.org | f1fbce6 | 2020-01-01 11:25:53 +0000 | [diff] [blame] | 2935 | request.setHTTPHeaderField(HTTPHeaderName::CacheControl, HTTPHeaderValues::noCache()); |
| 2936 | request.setHTTPHeaderField(HTTPHeaderName::Pragma, HTTPHeaderValues::noCache()); |
japhet@chromium.org | 1e31314 | 2010-08-31 22:53:31 +0000 | [diff] [blame] | 2937 | } |
| 2938 | } |
darin@apple.com | 0fdefc3 | 2016-03-18 07:56:20 +0000 | [diff] [blame] | 2939 | |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2940 | if (m_overrideResourceLoadPriorityForTesting) |
| 2941 | request.setPriority(m_overrideResourceLoadPriorityForTesting.value()); |
| 2942 | |
cdumez@apple.com | 1f985b8 | 2020-05-01 23:07:38 +0000 | [diff] [blame] | 2943 | // Make sure we send the Origin header. |
| 2944 | addHTTPOriginIfNeeded(request, String()); |
| 2945 | |
commit-queue@webkit.org | 77e2405 | 2020-06-26 01:03:22 +0000 | [diff] [blame] | 2946 | applyUserAgentIfNeeded(request); |
| 2947 | |
| 2948 | if (isMainResource) |
| 2949 | request.setHTTPHeaderField(HTTPHeaderName::Accept, CachedResourceRequest::acceptHeaderValueFromType(CachedResource::Type::MainResource)); |
| 2950 | |
ap@apple.com | 9454f7c | 2013-06-20 20:06:02 +0000 | [diff] [blame] | 2951 | // Only set fallback array if it's still empty (later attempts may be incorrect, see bug 117818). |
| 2952 | if (request.responseContentDispositionEncodingFallbackArray().isEmpty()) { |
| 2953 | // Always try UTF-8. If that fails, try frame encoding (if any) and then the default. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2954 | request.setResponseContentDispositionEncodingFallbackArray("UTF-8", m_frame.document()->encoding(), m_frame.settings().defaultTextEncodingName()); |
ap@apple.com | 9454f7c | 2013-06-20 20:06:02 +0000 | [diff] [blame] | 2955 | } |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 2956 | } |
| 2957 | |
cdumez@apple.com | 1f985b8 | 2020-05-01 23:07:38 +0000 | [diff] [blame] | 2958 | void FrameLoader::addHTTPOriginIfNeeded(ResourceRequest& request, const String& origin) |
| 2959 | { |
| 2960 | if (!request.httpOrigin().isEmpty()) |
| 2961 | return; // Request already has an Origin header. |
| 2962 | |
| 2963 | // Don't send an Origin header for GET or HEAD to avoid privacy issues. |
| 2964 | // For example, if an intranet page has a hyperlink to an external web |
| 2965 | // site, we don't want to include the Origin of the request because it |
| 2966 | // will leak the internal host name. Similar privacy concerns have lead |
| 2967 | // to the widespread suppression of the Referer header at the network |
| 2968 | // layer. |
| 2969 | if (request.httpMethod() == "GET" || request.httpMethod() == "HEAD") |
| 2970 | return; |
| 2971 | |
| 2972 | // FIXME: take referrer-policy into account. |
| 2973 | // https://bugs.webkit.org/show_bug.cgi?id=209066 |
| 2974 | |
| 2975 | // For non-GET and non-HEAD methods, always send an Origin header so the |
| 2976 | // server knows we support this feature. |
| 2977 | |
| 2978 | if (origin.isEmpty()) { |
| 2979 | // If we don't know what origin header to attach, we attach the value |
| 2980 | // for an empty origin. |
| 2981 | request.setHTTPOrigin(SecurityOrigin::createUnique()->toString()); |
| 2982 | return; |
| 2983 | } |
| 2984 | |
| 2985 | request.setHTTPOrigin(origin); |
| 2986 | } |
| 2987 | |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2988 | // Implements the "'Same-site' and 'cross-site' Requests" algorithm from <https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00#section-2.1>. |
| 2989 | // The algorithm is ammended to treat URLs that inherit their security origin from their owner (e.g. about:blank) |
| 2990 | // as same-site. This matches the behavior of Chrome and Firefox. |
| 2991 | void FrameLoader::addSameSiteInfoToRequestIfNeeded(ResourceRequest& request, const Document* initiator) |
| 2992 | { |
| 2993 | if (!request.isSameSiteUnspecified()) |
| 2994 | return; |
| 2995 | if (!initiator) { |
| 2996 | request.setIsSameSite(true); |
| 2997 | return; |
| 2998 | } |
| 2999 | if (SecurityPolicy::shouldInheritSecurityOriginFromOwner(request.url())) { |
| 3000 | request.setIsSameSite(true); |
| 3001 | return; |
| 3002 | } |
cdumez@apple.com | 0b8674fb | 2019-03-13 19:53:41 +0000 | [diff] [blame] | 3003 | request.setIsSameSite(areRegistrableDomainsEqual(initiator->siteForCookies(), request.url())); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 3004 | } |
| 3005 | |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 3006 | void FrameLoader::loadPostRequest(FrameLoadRequest&& request, const String& referrer, FrameLoadType loadType, Event* event, RefPtr<FormState>&& formState, CompletionHandler<void()>&& completionHandler) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3007 | { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 3008 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "loadPostRequest: frame load started"); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3009 | |
beidson@apple.com | bd66a78 | 2015-05-29 16:31:49 +0000 | [diff] [blame] | 3010 | String frameName = request.frameName(); |
| 3011 | LockHistory lockHistory = request.lockHistory(); |
| 3012 | AllowNavigationToInvalidURL allowNavigationToInvalidURL = request.allowNavigationToInvalidURL(); |
| 3013 | NewFrameOpenerPolicy openerPolicy = request.newFrameOpenerPolicy(); |
| 3014 | |
| 3015 | const ResourceRequest& inRequest = request.resourceRequest(); |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3016 | const URL& url = inRequest.url(); |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 3017 | const String& contentType = inRequest.httpContentType(); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 3018 | String origin = inRequest.httpOrigin(); |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 3019 | |
| 3020 | ResourceRequest workingResourceRequest(url); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3021 | |
| 3022 | if (!referrer.isEmpty()) |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 3023 | workingResourceRequest.setHTTPReferrer(referrer); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 3024 | workingResourceRequest.setHTTPOrigin(origin); |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 3025 | workingResourceRequest.setHTTPMethod("POST"); |
youenn.fablet@crf.canon.fr | 11cc655 | 2016-01-22 14:51:16 +0000 | [diff] [blame] | 3026 | workingResourceRequest.setHTTPBody(inRequest.httpBody()); |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 3027 | workingResourceRequest.setHTTPContentType(contentType); |
commit-queue@webkit.org | 627a2de | 2020-04-13 08:04:39 +0000 | [diff] [blame] | 3028 | addExtraFieldsToRequest(workingResourceRequest, IsMainResource::Yes, loadType); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3029 | |
bfulgham@apple.com | b30d7f8 | 2016-06-07 15:47:30 +0000 | [diff] [blame] | 3030 | if (Document* document = m_frame.document()) |
| 3031 | document->contentSecurityPolicy()->upgradeInsecureRequestIfNeeded(workingResourceRequest, ContentSecurityPolicy::InsecureRequestType::Load); |
| 3032 | |
commit-queue@webkit.org | bed33c6 | 2020-04-28 20:41:35 +0000 | [diff] [blame] | 3033 | NavigationAction action { request.requester(), workingResourceRequest, request.initiatedByMainFrame(), loadType, true, event, request.shouldOpenExternalURLsPolicy(), { } }; |
commit-queue@webkit.org | 4a7ad28 | 2020-04-05 05:09:42 +0000 | [diff] [blame] | 3034 | action.setLockHistory(lockHistory); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3035 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3036 | if (!frameName.isEmpty()) { |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 3037 | // The search for a target frame is done earlier in the case of form submission. |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 3038 | if (auto* targetFrame = formState ? nullptr : findFrameForNavigation(frameName)) { |
commit-queue@webkit.org | bed33c6 | 2020-04-28 20:41:35 +0000 | [diff] [blame] | 3039 | targetFrame->loader().loadWithNavigationAction(workingResourceRequest, WTFMove(action), loadType, WTFMove(formState), allowNavigationToInvalidURL, WTFMove(completionHandler)); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 3040 | return; |
darin@chromium.org | 1e25ab7 | 2012-04-02 20:14:07 +0000 | [diff] [blame] | 3041 | } |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 3042 | |
commit-queue@webkit.org | 57af63c | 2020-04-29 10:23:01 +0000 | [diff] [blame] | 3043 | policyChecker().checkNewWindowPolicy(WTFMove(action), WTFMove(workingResourceRequest), WTFMove(formState), frameName, [this, allowNavigationToInvalidURL, openerPolicy, completionHandler = WTFMove(completionHandler)] (const ResourceRequest& request, WeakPtr<FormState>&& formState, const String& frameName, const NavigationAction& action, ShouldContinuePolicyCheck shouldContinue) mutable { |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 3044 | continueLoadAfterNewWindowPolicy(request, formState.get(), frameName, action, shouldContinue, allowNavigationToInvalidURL, openerPolicy); |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 3045 | completionHandler(); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 3046 | }); |
| 3047 | return; |
| 3048 | } |
| 3049 | |
| 3050 | // must grab this now, since this load may stop the previous load and clear this flag |
| 3051 | bool isRedirect = m_quickRedirectComing; |
commit-queue@webkit.org | bed33c6 | 2020-04-28 20:41:35 +0000 | [diff] [blame] | 3052 | loadWithNavigationAction(workingResourceRequest, WTFMove(action), loadType, WTFMove(formState), allowNavigationToInvalidURL, [this, isRedirect, protectedFrame = makeRef(m_frame), completionHandler = WTFMove(completionHandler)] () mutable { |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 3053 | if (isRedirect) { |
| 3054 | m_quickRedirectComing = false; |
| 3055 | if (m_provisionalDocumentLoader) |
| 3056 | m_provisionalDocumentLoader->setIsClientRedirect(true); |
| 3057 | else if (m_policyDocumentLoader) |
| 3058 | m_policyDocumentLoader->setIsClientRedirect(true); |
| 3059 | } |
| 3060 | completionHandler(); |
| 3061 | }); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3062 | } |
| 3063 | |
youenn@apple.com | b9709cc | 2018-04-16 21:50:26 +0000 | [diff] [blame] | 3064 | unsigned long FrameLoader::loadResourceSynchronously(const ResourceRequest& request, ClientCredentialPolicy clientCredentialPolicy, const FetchOptions& options, const HTTPHeaderMap& originalRequestHeaders, ResourceError& error, ResourceResponse& response, RefPtr<SharedBuffer>& data) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3065 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3066 | ASSERT(m_frame.document()); |
| 3067 | String referrer = SecurityPolicy::generateReferrerHeader(m_frame.document()->referrerPolicy(), request.url(), outgoingReferrer()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3068 | |
| 3069 | ResourceRequest initialRequest = request; |
| 3070 | initialRequest.setTimeoutInterval(10); |
| 3071 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3072 | if (!referrer.isEmpty()) |
| 3073 | initialRequest.setHTTPReferrer(referrer); |
cdumez@apple.com | 1f985b8 | 2020-05-01 23:07:38 +0000 | [diff] [blame] | 3074 | addHTTPOriginIfNeeded(initialRequest, outgoingOrigin()); |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 3075 | |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 3076 | initialRequest.setFirstPartyForCookies(m_frame.mainFrame().loader().documentLoader()->request().url()); |
japhet@chromium.org | 92a952b | 2010-07-12 18:14:17 +0000 | [diff] [blame] | 3077 | |
commit-queue@webkit.org | 627a2de | 2020-04-13 08:04:39 +0000 | [diff] [blame] | 3078 | addExtraFieldsToRequest(initialRequest, IsMainResource::No); |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 3079 | |
commit-queue@webkit.org | 84a7209 | 2020-04-23 20:37:54 +0000 | [diff] [blame] | 3080 | applyUserAgentIfNeeded(initialRequest); |
| 3081 | |
andersca | ec429f5 | 2007-01-13 01:44:24 +0000 | [diff] [blame] | 3082 | unsigned long identifier = 0; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3083 | ResourceRequest newRequest(initialRequest); |
| 3084 | requestFromDelegate(newRequest, identifier, error); |
| 3085 | |
beidson@apple.com | e3ea01d | 2015-07-02 18:33:23 +0000 | [diff] [blame] | 3086 | #if ENABLE(CONTENT_EXTENSIONS) |
| 3087 | if (error.isNull()) { |
commit-queue@webkit.org | 8090ccb | 2015-10-06 08:18:08 +0000 | [diff] [blame] | 3088 | if (auto* page = m_frame.page()) { |
commit-queue@webkit.org | 3d33984 | 2016-08-04 18:07:45 +0000 | [diff] [blame] | 3089 | if (m_documentLoader) { |
achristensen@apple.com | b80d342 | 2019-04-26 17:03:15 +0000 | [diff] [blame] | 3090 | auto results = page->userContentProvider().processContentRuleListsForLoad(newRequest.url(), ContentExtensions::ResourceType::Raw, *m_documentLoader); |
achristensen@apple.com | d3edc2a | 2019-03-21 20:23:46 +0000 | [diff] [blame] | 3091 | bool blockedLoad = results.summary.blockedLoad; |
| 3092 | ContentExtensions::applyResultsToRequest(WTFMove(results), page, newRequest); |
| 3093 | if (blockedLoad) { |
commit-queue@webkit.org | 3d33984 | 2016-08-04 18:07:45 +0000 | [diff] [blame] | 3094 | newRequest = { }; |
| 3095 | error = ResourceError(errorDomainWebKitInternal, 0, initialRequest.url(), emptyString()); |
| 3096 | response = { }; |
| 3097 | data = nullptr; |
| 3098 | } |
beidson@apple.com | e3ea01d | 2015-07-02 18:33:23 +0000 | [diff] [blame] | 3099 | } |
| 3100 | } |
beidson@apple.com | e3ea01d | 2015-07-02 18:33:23 +0000 | [diff] [blame] | 3101 | } |
| 3102 | #endif |
| 3103 | |
bfulgham@apple.com | b30d7f8 | 2016-06-07 15:47:30 +0000 | [diff] [blame] | 3104 | m_frame.document()->contentSecurityPolicy()->upgradeInsecureRequestIfNeeded(newRequest, ContentSecurityPolicy::InsecureRequestType::Load); |
| 3105 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3106 | if (error.isNull()) { |
| 3107 | ASSERT(!newRequest.isNull()); |
youenn.fablet@crf.canon.fr | 0aef67f | 2015-04-29 08:18:10 +0000 | [diff] [blame] | 3108 | |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 3109 | if (!documentLoader()->applicationCacheHost().maybeLoadSynchronously(newRequest, error, response, data)) { |
youenn.fablet@crf.canon.fr | 0aef67f | 2015-04-29 08:18:10 +0000 | [diff] [blame] | 3110 | Vector<char> buffer; |
youenn@apple.com | b9709cc | 2018-04-16 21:50:26 +0000 | [diff] [blame] | 3111 | platformStrategies()->loaderStrategy()->loadResourceSynchronously(*this, identifier, newRequest, clientCredentialPolicy, options, originalRequestHeaders, error, response, buffer); |
commit-queue@webkit.org | 08f38b9 | 2017-04-12 09:25:04 +0000 | [diff] [blame] | 3112 | data = SharedBuffer::create(WTFMove(buffer)); |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 3113 | documentLoader()->applicationCacheHost().maybeLoadFallbackSynchronously(newRequest, error, response, data); |
wilander@apple.com | a4d606a | 2019-11-19 20:35:21 +0000 | [diff] [blame] | 3114 | ResourceLoadObserver::shared().logSubresourceLoading(&m_frame, newRequest, response, |
| 3115 | (isScriptLikeDestination(options.destination) ? ResourceLoadObserver::FetchDestinationIsScriptLike::Yes : ResourceLoadObserver::FetchDestinationIsScriptLike::No)); |
ap@webkit.org | fb96f8a | 2009-01-02 09:25:02 +0000 | [diff] [blame] | 3116 | } |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3117 | } |
youenn.fablet@crf.canon.fr | 0aef67f | 2015-04-29 08:18:10 +0000 | [diff] [blame] | 3118 | notifier().sendRemainingDelegateMessages(m_documentLoader.get(), identifier, request, response, data ? data->data() : nullptr, data ? data->size() : 0, -1, error); |
kmccullough@apple.com | 2a4950c | 2008-03-28 23:28:56 +0000 | [diff] [blame] | 3119 | return identifier; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3120 | } |
| 3121 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3122 | const ResourceRequest& FrameLoader::originalRequest() const |
| 3123 | { |
| 3124 | return activeDocumentLoader()->originalRequestCopy(); |
| 3125 | } |
| 3126 | |
japhet@chromium.org | 7f7bee4 | 2012-03-29 23:17:09 +0000 | [diff] [blame] | 3127 | void FrameLoader::receivedMainResourceError(const ResourceError& error) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3128 | { |
| 3129 | // Retain because the stop may release the last reference to it. |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 3130 | Ref<Frame> protect(m_frame); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3131 | |
| 3132 | RefPtr<DocumentLoader> loader = activeDocumentLoader(); |
japhet@chromium.org | 7f7bee4 | 2012-03-29 23:17:09 +0000 | [diff] [blame] | 3133 | // FIXME: Don't want to do this if an entirely new load is going, so should check |
| 3134 | // that both data sources on the frame are either this or nil. |
| 3135 | stop(); |
commit-queue@webkit.org | 15deb6e | 2020-06-08 09:04:33 +0000 | [diff] [blame] | 3136 | if (m_client->shouldFallBack(error)) { |
| 3137 | HTMLFrameOwnerElement* owner = m_frame.ownerElement(); |
| 3138 | if (is<HTMLObjectElement>(owner)) |
| 3139 | downcast<HTMLObjectElement>(*owner).renderFallbackContent(); |
| 3140 | } |
abarth@webkit.org | 1c893f4 | 2009-10-10 02:27:21 +0000 | [diff] [blame] | 3141 | |
lars | 8bf288d | 2007-10-04 08:45:12 +0000 | [diff] [blame] | 3142 | if (m_state == FrameStateProvisional && m_provisionalDocumentLoader) { |
darin@apple.com | 4cd1b24 | 2009-03-27 23:37:46 +0000 | [diff] [blame] | 3143 | if (m_submittedFormURL == m_provisionalDocumentLoader->originalRequestCopy().url()) |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3144 | m_submittedFormURL = URL(); |
antti | ac25cb4 | 2007-03-02 07:59:15 +0000 | [diff] [blame] | 3145 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 3146 | // We might have made a back/forward cache item, but now we're bailing out due to an error before we ever |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3147 | // transitioned to the new page (before WebFrameState == commit). The goal here is to restore any state |
| 3148 | // so that the existing view (that wenever got far enough to replace) can continue being used. |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3149 | history().invalidateCurrentItemCachedPage(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3150 | |
| 3151 | // Call clientRedirectCancelledOrFinished here so that the frame load delegate is notified that the redirect's |
| 3152 | // status has changed, if there was a redirect. The frame load delegate may have saved some state about |
| 3153 | // the redirect in its -webView:willPerformClientRedirectToURL:delay:fireDate:forFrame:. Since we are definitely |
| 3154 | // not going to use this provisional resource, as it was cancelled, notify the frame load delegate that the redirect |
| 3155 | // has ended. |
| 3156 | if (m_sentRedirectNotification) |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 3157 | clientRedirectCancelledOrFinished(NewLoadInProgress::No); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3158 | } |
abarth@webkit.org | 1c893f4 | 2009-10-10 02:27:21 +0000 | [diff] [blame] | 3159 | |
japhet@chromium.org | 7f7bee4 | 2012-03-29 23:17:09 +0000 | [diff] [blame] | 3160 | checkCompleted(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3161 | if (m_frame.page()) |
japhet@chromium.org | 7f7bee4 | 2012-03-29 23:17:09 +0000 | [diff] [blame] | 3162 | checkLoadComplete(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3163 | } |
| 3164 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3165 | void FrameLoader::continueFragmentScrollAfterNavigationPolicy(const ResourceRequest& request, bool shouldContinue) |
| 3166 | { |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3167 | m_quickRedirectComing = false; |
darin | 4e5519d | 2007-01-22 02:46:06 +0000 | [diff] [blame] | 3168 | |
| 3169 | if (!shouldContinue) |
| 3170 | return; |
| 3171 | |
bfulgham@apple.com | 98845d9 | 2016-05-17 01:09:27 +0000 | [diff] [blame] | 3172 | // Calling stopLoading() on the provisional document loader can cause the underlying |
| 3173 | // frame to be deallocated. |
| 3174 | Ref<Frame> protectedFrame(m_frame); |
| 3175 | |
mihaip@chromium.org | d5123ba | 2011-09-16 02:16:46 +0000 | [diff] [blame] | 3176 | // If we have a provisional request for a different document, a fragment scroll should cancel it. |
| 3177 | if (m_provisionalDocumentLoader && !equalIgnoringFragmentIdentifier(m_provisionalDocumentLoader->request().url(), request.url())) { |
| 3178 | m_provisionalDocumentLoader->stopLoading(); |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 3179 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "continueFragmentScrollAfterNavigationPolicy: Clearing provisional document loader (m_provisionalDocumentLoader=%p)", m_provisionalDocumentLoader.get()); |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 3180 | setProvisionalDocumentLoader(nullptr); |
mihaip@chromium.org | d5123ba | 2011-09-16 02:16:46 +0000 | [diff] [blame] | 3181 | } |
| 3182 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3183 | bool isRedirect = m_quickRedirectComing || policyChecker().loadType() == FrameLoadType::RedirectWithLockedBackForwardList; |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3184 | loadInSameDocument(request.url(), 0, !isRedirect); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3185 | } |
| 3186 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3187 | bool FrameLoader::shouldPerformFragmentNavigation(bool isFormSubmission, const String& httpMethod, FrameLoadType loadType, const URL& url) |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 3188 | { |
yael.aharon@nokia.com | 79f6905 | 2010-12-30 19:31:00 +0000 | [diff] [blame] | 3189 | // We don't do this if we are submitting a form with method other than "GET", explicitly reloading, |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 3190 | // currently displaying a frameset, or if the URL does not have a fragment. |
| 3191 | // These rules were originally based on what KHTML was doing in KHTMLPart::openURL. |
| 3192 | |
| 3193 | // FIXME: What about load types other than Standard and Reload? |
| 3194 | |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 3195 | return (!isFormSubmission || equalLettersIgnoringASCIICase(httpMethod, "get")) |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 3196 | && !isReload(loadType) |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3197 | && loadType != FrameLoadType::Same |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 3198 | && m_frame.document()->backForwardCacheState() != Document::InBackForwardCache |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3199 | && !shouldReload(m_frame.document()->url(), url) |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 3200 | // We don't want to just scroll if a link from within a |
| 3201 | // frameset is trying to reload the frameset into _top. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3202 | && !m_frame.document()->isFrameSet(); |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 3203 | } |
| 3204 | |
simon.fraser@apple.com | c79e486 | 2017-03-08 20:01:15 +0000 | [diff] [blame] | 3205 | static bool itemAllowsScrollRestoration(HistoryItem* historyItem) |
| 3206 | { |
simon.fraser@apple.com | 804555f | 2017-11-29 20:41:47 +0000 | [diff] [blame] | 3207 | return !historyItem || historyItem->shouldRestoreScrollPosition(); |
simon.fraser@apple.com | c79e486 | 2017-03-08 20:01:15 +0000 | [diff] [blame] | 3208 | } |
| 3209 | |
| 3210 | static bool isSameDocumentReload(bool isNewNavigation, FrameLoadType loadType) |
| 3211 | { |
| 3212 | return !isNewNavigation && !isBackForwardLoadType(loadType); |
| 3213 | } |
| 3214 | |
| 3215 | void FrameLoader::scrollToFragmentWithParentBoundary(const URL& url, bool isNewNavigation) |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 3216 | { |
rniwa@webkit.org | 892a376 | 2019-11-22 05:09:36 +0000 | [diff] [blame] | 3217 | auto view = makeRefPtr(m_frame.view()); |
| 3218 | auto document = makeRefPtr(m_frame.document()); |
| 3219 | if (!view || !document) |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 3220 | return; |
| 3221 | |
rniwa@webkit.org | 892a376 | 2019-11-22 05:09:36 +0000 | [diff] [blame] | 3222 | if (isSameDocumentReload(isNewNavigation, m_loadType) || itemAllowsScrollRestoration(history().currentItem())) { |
| 3223 | // https://html.spec.whatwg.org/multipage/browsing-the-web.html#try-to-scroll-to-the-fragment |
| 3224 | if (!document->haveStylesheetsLoaded()) |
| 3225 | document->setGotoAnchorNeededAfterStylesheetsLoad(true); |
| 3226 | else |
| 3227 | view->scrollToFragment(url); |
| 3228 | } |
| 3229 | |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 3230 | } |
| 3231 | |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 3232 | bool FrameLoader::shouldClose() |
| 3233 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3234 | Page* page = m_frame.page(); |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 3235 | if (!page) |
| 3236 | return true; |
| 3237 | if (!page->chrome().canRunBeforeUnloadConfirmPanel()) |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 3238 | return true; |
| 3239 | |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 3240 | // Store all references to each subframe in advance since beforeunload's event handler may modify frame |
akling@apple.com | 72c1c36 | 2013-09-06 01:34:05 +0000 | [diff] [blame] | 3241 | Vector<Ref<Frame>, 16> targetFrames; |
| 3242 | targetFrames.append(m_frame); |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3243 | for (Frame* child = m_frame.tree().firstChild(); child; child = child->tree().traverseNext(&m_frame)) |
akling@apple.com | 72c1c36 | 2013-09-06 01:34:05 +0000 | [diff] [blame] | 3244 | targetFrames.append(*child); |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 3245 | |
| 3246 | bool shouldClose = false; |
| 3247 | { |
rniwa@webkit.org | f694bd6 | 2017-06-30 19:32:41 +0000 | [diff] [blame] | 3248 | NavigationDisabler navigationDisabler(&m_frame); |
cdumez@apple.com | e4df29d | 2018-09-26 19:29:54 +0000 | [diff] [blame] | 3249 | IgnoreOpensDuringUnloadCountIncrementer ignoreOpensDuringUnloadCountIncrementer(m_frame.document()); |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 3250 | size_t i; |
| 3251 | |
| 3252 | for (i = 0; i < targetFrames.size(); i++) { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3253 | if (!targetFrames[i]->tree().isDescendantOf(&m_frame)) |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 3254 | continue; |
ggaren@apple.com | 7a176e1 | 2015-11-12 01:48:27 +0000 | [diff] [blame] | 3255 | if (!targetFrames[i]->loader().dispatchBeforeUnloadEvent(page->chrome(), this)) |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 3256 | break; |
| 3257 | } |
| 3258 | |
| 3259 | if (i == targetFrames.size()) |
| 3260 | shouldClose = true; |
| 3261 | } |
| 3262 | |
aestes@apple.com | c7f1761 | 2011-08-12 19:56:56 +0000 | [diff] [blame] | 3263 | if (!shouldClose) |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3264 | m_submittedFormURL = URL(); |
aestes@apple.com | c7f1761 | 2011-08-12 19:56:56 +0000 | [diff] [blame] | 3265 | |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3266 | m_currentNavigationHasShownBeforeUnloadConfirmPanel = false; |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 3267 | return shouldClose; |
| 3268 | } |
| 3269 | |
ggaren@apple.com | 7a176e1 | 2015-11-12 01:48:27 +0000 | [diff] [blame] | 3270 | void FrameLoader::dispatchUnloadEvents(UnloadEventPolicy unloadEventPolicy) |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3271 | { |
| 3272 | if (!m_frame.document()) |
| 3273 | return; |
| 3274 | |
ajuma@chromium.org | edd7574 | 2019-09-11 14:52:18 +0000 | [diff] [blame] | 3275 | if (m_pageDismissalEventBeingDispatched != PageDismissalType::None) |
| 3276 | return; |
| 3277 | |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3278 | // We store the frame's page in a local variable because the frame might get detached inside dispatchEvent. |
| 3279 | ForbidPromptsScope forbidPrompts(m_frame.page()); |
cdumez@apple.com | fc8fdf3 | 2019-12-06 21:05:12 +0000 | [diff] [blame] | 3280 | ForbidSynchronousLoadsScope forbidSynchronousLoads(m_frame.page()); |
cdumez@apple.com | 8b478c6 | 2016-01-23 01:04:59 +0000 | [diff] [blame] | 3281 | IgnoreOpensDuringUnloadCountIncrementer ignoreOpensDuringUnloadCountIncrementer(m_frame.document()); |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3282 | |
| 3283 | if (m_didCallImplicitClose && !m_wasUnloadEventEmitted) { |
| 3284 | auto* currentFocusedElement = m_frame.document()->focusedElement(); |
| 3285 | if (is<HTMLInputElement>(currentFocusedElement)) |
| 3286 | downcast<HTMLInputElement>(*currentFocusedElement).endEditing(); |
| 3287 | if (m_pageDismissalEventBeingDispatched == PageDismissalType::None) { |
| 3288 | if (unloadEventPolicy == UnloadEventPolicyUnloadAndPageHide) { |
| 3289 | m_pageDismissalEventBeingDispatched = PageDismissalType::PageHide; |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 3290 | m_frame.document()->domWindow()->dispatchEvent(PageTransitionEvent::create(eventNames().pagehideEvent, m_frame.document()->backForwardCacheState() == Document::AboutToEnterBackForwardCache), m_frame.document()); |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3291 | } |
| 3292 | |
cdumez@apple.com | 19a0fdc | 2020-09-26 00:50:00 +0000 | [diff] [blame] | 3293 | // This takes care of firing the visibilitychange event and making sure the document is reported as hidden. |
| 3294 | m_frame.document()->setVisibilityHiddenDueToDismissal(true); |
cdumez@apple.com | 3bd17f7 | 2020-09-25 21:29:46 +0000 | [diff] [blame] | 3295 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 3296 | if (m_frame.document()->backForwardCacheState() == Document::NotInBackForwardCache) { |
rniwa@webkit.org | 6c40374 | 2018-08-17 21:24:40 +0000 | [diff] [blame] | 3297 | Ref<Event> unloadEvent(Event::create(eventNames().unloadEvent, Event::CanBubble::No, Event::IsCancelable::No)); |
commit-queue@webkit.org | 3eeac49 | 2016-08-12 22:53:27 +0000 | [diff] [blame] | 3298 | // The DocumentLoader (and thus its LoadTiming) might get destroyed |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3299 | // while dispatching the event, so protect it to prevent writing the end |
| 3300 | // time into freed memory. |
| 3301 | RefPtr<DocumentLoader> documentLoader = m_provisionalDocumentLoader; |
| 3302 | m_pageDismissalEventBeingDispatched = PageDismissalType::Unload; |
commit-queue@webkit.org | 3eeac49 | 2016-08-12 22:53:27 +0000 | [diff] [blame] | 3303 | if (documentLoader && documentLoader->timing().startTime() && !documentLoader->timing().unloadEventStart() && !documentLoader->timing().unloadEventEnd()) { |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3304 | auto& timing = documentLoader->timing(); |
| 3305 | timing.markUnloadEventStart(); |
| 3306 | m_frame.document()->domWindow()->dispatchEvent(unloadEvent, m_frame.document()); |
| 3307 | timing.markUnloadEventEnd(); |
| 3308 | } else |
| 3309 | m_frame.document()->domWindow()->dispatchEvent(unloadEvent, m_frame.document()); |
| 3310 | } |
| 3311 | } |
| 3312 | m_pageDismissalEventBeingDispatched = PageDismissalType::None; |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3313 | m_wasUnloadEventEmitted = true; |
| 3314 | } |
| 3315 | |
| 3316 | // Dispatching the unload event could have made m_frame.document() null. |
| 3317 | if (!m_frame.document()) |
| 3318 | return; |
| 3319 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 3320 | if (m_frame.document()->backForwardCacheState() != Document::NotInBackForwardCache) |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3321 | return; |
| 3322 | |
| 3323 | // Don't remove event listeners from a transitional empty document (see bug 28716 for more information). |
| 3324 | bool keepEventListeners = m_stateMachine.isDisplayingInitialEmptyDocument() && m_provisionalDocumentLoader |
| 3325 | && m_frame.document()->isSecureTransitionTo(m_provisionalDocumentLoader->url()); |
| 3326 | |
| 3327 | if (!keepEventListeners) |
| 3328 | m_frame.document()->removeAllEventListeners(); |
| 3329 | } |
| 3330 | |
cdumez@apple.com | 6473cc4 | 2017-03-22 21:14:23 +0000 | [diff] [blame] | 3331 | static bool shouldAskForNavigationConfirmation(Document& document, const BeforeUnloadEvent& event) |
cdumez@apple.com | 6004546 | 2017-02-20 06:36:04 +0000 | [diff] [blame] | 3332 | { |
fred.wang@free.fr | d6e8274 | 2017-08-25 17:28:53 +0000 | [diff] [blame] | 3333 | // Confirmation dialog should not be displayed when the allow-modals flag is not set. |
| 3334 | if (document.isSandboxed(SandboxModals)) |
| 3335 | return false; |
| 3336 | |
cdumez@apple.com | 72d8e4b | 2017-04-17 00:56:47 +0000 | [diff] [blame] | 3337 | bool userDidInteractWithPage = document.topDocument().userDidInteractWithPage(); |
cdumez@apple.com | 6004546 | 2017-02-20 06:36:04 +0000 | [diff] [blame] | 3338 | // Web pages can request we ask for confirmation before navigating by: |
| 3339 | // - Cancelling the BeforeUnloadEvent (modern way) |
| 3340 | // - Setting the returnValue attribute on the BeforeUnloadEvent to a non-empty string. |
| 3341 | // - Returning a non-empty string from the event handler, which is then set as returnValue |
| 3342 | // attribute on the BeforeUnloadEvent. |
cdumez@apple.com | 6473cc4 | 2017-03-22 21:14:23 +0000 | [diff] [blame] | 3343 | return userDidInteractWithPage && (event.defaultPrevented() || !event.returnValue().isEmpty()); |
cdumez@apple.com | 6004546 | 2017-02-20 06:36:04 +0000 | [diff] [blame] | 3344 | } |
| 3345 | |
ggaren@apple.com | 7a176e1 | 2015-11-12 01:48:27 +0000 | [diff] [blame] | 3346 | bool FrameLoader::dispatchBeforeUnloadEvent(Chrome& chrome, FrameLoader* frameLoaderBeingNavigated) |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 3347 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3348 | DOMWindow* domWindow = m_frame.document()->domWindow(); |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 3349 | if (!domWindow) |
| 3350 | return true; |
| 3351 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3352 | RefPtr<Document> document = m_frame.document(); |
cdumez@apple.com | f978083 | 2015-01-27 00:26:21 +0000 | [diff] [blame] | 3353 | if (!document->bodyOrFrameset()) |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 3354 | return true; |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3355 | |
cdumez@apple.com | 32216e4 | 2015-11-12 07:28:57 +0000 | [diff] [blame] | 3356 | Ref<BeforeUnloadEvent> beforeUnloadEvent = BeforeUnloadEvent::create(); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3357 | |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3358 | { |
ajuma@chromium.org | edd7574 | 2019-09-11 14:52:18 +0000 | [diff] [blame] | 3359 | SetForScope<PageDismissalType> change(m_pageDismissalEventBeingDispatched, PageDismissalType::BeforeUnload); |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3360 | ForbidPromptsScope forbidPrompts(m_frame.page()); |
cdumez@apple.com | fc8fdf3 | 2019-12-06 21:05:12 +0000 | [diff] [blame] | 3361 | ForbidSynchronousLoadsScope forbidSynchronousLoads(m_frame.page()); |
cdumez@apple.com | 32216e4 | 2015-11-12 07:28:57 +0000 | [diff] [blame] | 3362 | domWindow->dispatchEvent(beforeUnloadEvent, domWindow->document()); |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3363 | } |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3364 | |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 3365 | if (!beforeUnloadEvent->defaultPrevented()) |
akling@apple.com | e8090dd | 2016-08-31 16:32:44 +0000 | [diff] [blame] | 3366 | document->defaultEventHandler(beforeUnloadEvent.get()); |
cdumez@apple.com | 6004546 | 2017-02-20 06:36:04 +0000 | [diff] [blame] | 3367 | |
cdumez@apple.com | 6473cc4 | 2017-03-22 21:14:23 +0000 | [diff] [blame] | 3368 | if (!shouldAskForNavigationConfirmation(*document, beforeUnloadEvent)) |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 3369 | return true; |
| 3370 | |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3371 | // If the navigating FrameLoader has already shown a beforeunload confirmation panel for the current navigation attempt, |
| 3372 | // this frame is not allowed to cause another one to be shown. |
| 3373 | if (frameLoaderBeingNavigated->m_currentNavigationHasShownBeforeUnloadConfirmPanel) { |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 3374 | document->addConsoleMessage(MessageSource::JS, MessageLevel::Error, "Blocked attempt to show multiple beforeunload confirmation dialogs for the same navigation."_s); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3375 | return true; |
| 3376 | } |
| 3377 | |
| 3378 | // We should only display the beforeunload dialog for an iframe if its SecurityOrigin matches all |
| 3379 | // ancestor frame SecurityOrigins up through the navigating FrameLoader. |
| 3380 | if (frameLoaderBeingNavigated != this) { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3381 | Frame* parentFrame = m_frame.tree().parent(); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3382 | while (parentFrame) { |
| 3383 | Document* parentDocument = parentFrame->document(); |
| 3384 | if (!parentDocument) |
| 3385 | return true; |
akling@apple.com | 6be0e97 | 2017-01-18 19:35:49 +0000 | [diff] [blame] | 3386 | if (!m_frame.document() || !m_frame.document()->securityOrigin().canAccess(parentDocument->securityOrigin())) { |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 3387 | document->addConsoleMessage(MessageSource::JS, MessageLevel::Error, "Blocked attempt to show beforeunload confirmation dialog on behalf of a frame with different security origin. Protocols, domains, and ports must match."_s); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3388 | return true; |
| 3389 | } |
| 3390 | |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 3391 | if (&parentFrame->loader() == frameLoaderBeingNavigated) |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3392 | break; |
| 3393 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3394 | parentFrame = parentFrame->tree().parent(); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | // The navigatingFrameLoader should always be in our ancestory. |
| 3398 | ASSERT(parentFrame); |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 3399 | ASSERT(&parentFrame->loader() == frameLoaderBeingNavigated); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | frameLoaderBeingNavigated->m_currentNavigationHasShownBeforeUnloadConfirmPanel = true; |
| 3403 | |
ch.dumez@sisa.samsung.com | 231386f | 2013-09-09 18:40:04 +0000 | [diff] [blame] | 3404 | String text = document->displayStringModifiedByEncoding(beforeUnloadEvent->returnValue()); |
darin@apple.com | 9ace801 | 2017-01-23 06:24:18 +0000 | [diff] [blame] | 3405 | return chrome.runBeforeUnloadConfirmPanel(text, m_frame); |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 3406 | } |
| 3407 | |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 3408 | void FrameLoader::continueLoadAfterNavigationPolicy(const ResourceRequest& request, FormState* formState, NavigationPolicyDecision navigationPolicyDecision, AllowNavigationToInvalidURL allowNavigationToInvalidURL) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3409 | { |
| 3410 | // If we loaded an alternate page to replace an unreachableURL, we'll get in here with a |
| 3411 | // nil policyDataSource because loading the alternate page will have passed |
| 3412 | // through this method already, nested; otherwise, policyDataSource should still be set. |
| 3413 | ASSERT(m_policyDocumentLoader || !m_provisionalDocumentLoader->unreachableURL().isEmpty()); |
| 3414 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3415 | bool isTargetItem = history().provisionalItem() ? history().provisionalItem()->isTargetItem() : false; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3416 | |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 3417 | bool urlIsDisallowed = allowNavigationToInvalidURL == AllowNavigationToInvalidURL::No && !request.url().isValid(); |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 3418 | bool canContinue = navigationPolicyDecision == NavigationPolicyDecision::ContinueLoad && shouldClose() && !urlIsDisallowed; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3419 | |
| 3420 | if (!canContinue) { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 3421 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "continueLoadAfterNavigationPolicy: can't continue loading frame due to the following reasons (" |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3422 | "allowNavigationToInvalidURL = %d, " |
| 3423 | "requestURLIsValid = %d, " |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 3424 | "navigationPolicyDecision = %d)", |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3425 | static_cast<int>(allowNavigationToInvalidURL), |
| 3426 | request.url().isValid(), |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 3427 | static_cast<int>(navigationPolicyDecision)); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3428 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3429 | // If we were waiting for a quick redirect, but the policy delegate decided to ignore it, then we |
| 3430 | // need to report that the client redirect was cancelled. |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 3431 | // FIXME: The client should be told about ignored non-quick redirects, too. |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3432 | if (m_quickRedirectComing) |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 3433 | clientRedirectCancelledOrFinished(NewLoadInProgress::No); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3434 | |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 3435 | if (navigationPolicyDecision == NavigationPolicyDecision::StopAllLoads) { |
| 3436 | stopAllLoaders(); |
| 3437 | m_checkTimer.stop(); |
| 3438 | } |
| 3439 | |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 3440 | setPolicyDocumentLoader(nullptr); |
cdumez@apple.com | d653185 | 2018-03-06 03:13:32 +0000 | [diff] [blame] | 3441 | checkCompleted(); |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 3442 | |
| 3443 | if (navigationPolicyDecision != NavigationPolicyDecision::StopAllLoads) |
| 3444 | checkLoadComplete(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3445 | |
| 3446 | // If the navigation request came from the back/forward menu, and we punt on it, we have the |
simon.fraser@apple.com | c79e486 | 2017-03-08 20:01:15 +0000 | [diff] [blame] | 3447 | // problem that we have optimistically moved the b/f cursor already, so move it back. For sanity, |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3448 | // we only do this when punting a navigation for the target frame or top-level frame. |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 3449 | if ((isTargetItem || m_frame.isMainFrame()) && isBackForwardLoadType(policyChecker().loadType())) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3450 | if (Page* page = m_frame.page()) { |
achristensen@apple.com | ebfea93 | 2018-10-15 21:45:55 +0000 | [diff] [blame] | 3451 | if (HistoryItem* resetItem = m_frame.mainFrame().loader().history().currentItem()) |
achristensen@apple.com | 3a889f1 | 2018-10-16 15:58:10 +0000 | [diff] [blame] | 3452 | page->backForward().setCurrentItem(*resetItem); |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 3453 | } |
andersca@apple.com | b85d674 | 2011-03-04 03:21:07 +0000 | [diff] [blame] | 3454 | } |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3455 | return; |
| 3456 | } |
| 3457 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 3458 | FrameLoadType type = policyChecker().loadType(); |
commit-queue@webkit.org | 987fd77 | 2011-01-21 18:26:42 +0000 | [diff] [blame] | 3459 | // A new navigation is in progress, so don't clear the history's provisional item. |
commit-queue@webkit.org | fc5833b | 2011-02-23 06:58:46 +0000 | [diff] [blame] | 3460 | stopAllLoaders(ShouldNotClearProvisionalItem); |
beidson@apple.com | c90a442 | 2008-10-09 20:43:24 +0000 | [diff] [blame] | 3461 | |
| 3462 | // <rdar://problem/6250856> - In certain circumstances on pages with multiple frames, stopAllLoaders() |
| 3463 | // might detach the current FrameLoader, in which case we should bail on this newly defunct load. |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3464 | if (!m_frame.page()) { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 3465 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "continueLoadAfterNavigationPolicy: can't continue loading frame because it became defunct"); |
beidson@apple.com | c90a442 | 2008-10-09 20:43:24 +0000 | [diff] [blame] | 3466 | return; |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3467 | } |
timothy@apple.com | 8f20734 | 2009-04-11 05:31:05 +0000 | [diff] [blame] | 3468 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3469 | setProvisionalDocumentLoader(m_policyDocumentLoader.get()); |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 3470 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "continueLoadAfterNavigationPolicy: Setting provisional document loader (m_provisionalDocumentLoader=%p)", m_provisionalDocumentLoader.get()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3471 | m_loadType = type; |
| 3472 | setState(FrameStateProvisional); |
| 3473 | |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 3474 | setPolicyDocumentLoader(nullptr); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3475 | |
cdumez@apple.com | 2574377 | 2015-08-17 22:57:27 +0000 | [diff] [blame] | 3476 | if (isBackForwardLoadType(type)) { |
cdumez@apple.com | 10d0f25 | 2016-04-23 21:33:49 +0000 | [diff] [blame] | 3477 | auto& diagnosticLoggingClient = m_frame.page()->diagnosticLoggingClient(); |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 3478 | if (history().provisionalItem() && history().provisionalItem()->isInBackForwardCache()) { |
| 3479 | diagnosticLoggingClient.logDiagnosticMessageWithResult(DiagnosticLoggingKeys::backForwardCacheKey(), DiagnosticLoggingKeys::retrievalKey(), DiagnosticLoggingResultPass, ShouldSample::Yes); |
cdumez@apple.com | 2574377 | 2015-08-17 22:57:27 +0000 | [diff] [blame] | 3480 | loadProvisionalItemFromCachedPage(); |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 3481 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "continueLoadAfterNavigationPolicy: can't continue loading frame because it will be loaded from cache"); |
cdumez@apple.com | 2574377 | 2015-08-17 22:57:27 +0000 | [diff] [blame] | 3482 | return; |
| 3483 | } |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 3484 | diagnosticLoggingClient.logDiagnosticMessageWithResult(DiagnosticLoggingKeys::backForwardCacheKey(), DiagnosticLoggingKeys::retrievalKey(), DiagnosticLoggingResultFail, ShouldSample::Yes); |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 3485 | } |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3486 | |
cdumez@apple.com | a0010ff | 2018-12-13 23:17:44 +0000 | [diff] [blame] | 3487 | CompletionHandler<void()> completionHandler = [this, protectedFrame = makeRef(m_frame)] () mutable { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3488 | if (!m_provisionalDocumentLoader) { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 3489 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "continueLoadAfterNavigationPolicy (completionHandler): Frame load canceled - no provisional document loader before prepareForLoadStart"); |
achristensen@apple.com | b2d9e11 | 2017-09-25 19:18:50 +0000 | [diff] [blame] | 3490 | return; |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3491 | } |
achristensen@apple.com | b2d9e11 | 2017-09-25 19:18:50 +0000 | [diff] [blame] | 3492 | |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 3493 | prepareForLoadStart(); |
beidson@apple.com | 0262233 | 2018-04-13 18:04:22 +0000 | [diff] [blame] | 3494 | |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 3495 | // The load might be cancelled inside of prepareForLoadStart(), nulling out the m_provisionalDocumentLoader, |
| 3496 | // so we need to null check it again. |
| 3497 | if (!m_provisionalDocumentLoader) { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 3498 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "continueLoadAfterNavigationPolicy (completionHandler): Frame load canceled - no provisional document loader after prepareForLoadStart"); |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 3499 | return; |
| 3500 | } |
| 3501 | |
| 3502 | DocumentLoader* activeDocLoader = activeDocumentLoader(); |
| 3503 | if (activeDocLoader && activeDocLoader->isLoadingMainResource()) { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 3504 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "continueLoadAfterNavigationPolicy (completionHandler): Main frame already being loaded"); |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 3505 | return; |
| 3506 | } |
| 3507 | |
| 3508 | m_loadingFromCachedPage = false; |
beidson@apple.com | 0262233 | 2018-04-13 18:04:22 +0000 | [diff] [blame] | 3509 | |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 3510 | m_provisionalDocumentLoader->startLoadingMainResource(); |
achristensen@apple.com | b2d9e11 | 2017-09-25 19:18:50 +0000 | [diff] [blame] | 3511 | }; |
| 3512 | |
andersca@apple.com | 61e3332 | 2013-10-05 04:52:04 +0000 | [diff] [blame] | 3513 | if (!formState) { |
achristensen@apple.com | b2d9e11 | 2017-09-25 19:18:50 +0000 | [diff] [blame] | 3514 | completionHandler(); |
andersca@apple.com | 61e3332 | 2013-10-05 04:52:04 +0000 | [diff] [blame] | 3515 | return; |
| 3516 | } |
| 3517 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3518 | m_client->dispatchWillSubmitForm(*formState, WTFMove(completionHandler)); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3519 | } |
| 3520 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3521 | void FrameLoader::continueLoadAfterNewWindowPolicy(const ResourceRequest& request, |
commit-queue@webkit.org | 57af63c | 2020-04-29 10:23:01 +0000 | [diff] [blame] | 3522 | FormState* formState, const String& frameName, const NavigationAction& action, ShouldContinuePolicyCheck shouldContinue, AllowNavigationToInvalidURL allowNavigationToInvalidURL, NewFrameOpenerPolicy openerPolicy) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3523 | { |
commit-queue@webkit.org | 57af63c | 2020-04-29 10:23:01 +0000 | [diff] [blame] | 3524 | if (shouldContinue != ShouldContinuePolicyCheck::Yes) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3525 | return; |
| 3526 | |
akling@apple.com | 55cde01 | 2013-10-05 00:35:12 +0000 | [diff] [blame] | 3527 | Ref<Frame> frame(m_frame); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3528 | RefPtr<Frame> mainFrame = m_client->dispatchCreatePage(action); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3529 | if (!mainFrame) |
| 3530 | return; |
| 3531 | |
commit-queue@webkit.org | 04df842 | 2017-06-09 17:59:18 +0000 | [diff] [blame] | 3532 | SandboxFlags sandboxFlags = frame->loader().effectiveSandboxFlags(); |
| 3533 | if (sandboxFlags & SandboxPropagatesToAuxiliaryBrowsingContexts) |
| 3534 | mainFrame->loader().forceSandboxFlags(sandboxFlags); |
wilander@apple.com | 2d7ea24 | 2016-08-08 21:43:36 +0000 | [diff] [blame] | 3535 | |
cdumez@apple.com | eec032f | 2017-04-05 13:36:47 +0000 | [diff] [blame] | 3536 | if (!equalIgnoringASCIICase(frameName, "_blank")) |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3537 | mainFrame->tree().setName(frameName); |
kmccullo | 1f90121 | 2007-05-16 20:57:47 +0000 | [diff] [blame] | 3538 | |
eric@webkit.org | 5aee676 | 2009-10-06 18:20:33 +0000 | [diff] [blame] | 3539 | mainFrame->page()->setOpenedByDOM(); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3540 | mainFrame->loader().m_client->dispatchShow(); |
ap@apple.com | a383f25 | 2015-02-14 18:16:00 +0000 | [diff] [blame] | 3541 | if (openerPolicy == NewFrameOpenerPolicy::Allow) { |
cdumez@apple.com | 7814173 | 2014-11-04 23:00:48 +0000 | [diff] [blame] | 3542 | mainFrame->loader().setOpener(frame.ptr()); |
jochen@chromium.org | 235ee97 | 2012-05-09 22:13:12 +0000 | [diff] [blame] | 3543 | mainFrame->document()->setReferrerPolicy(frame->document()->referrerPolicy()); |
| 3544 | } |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 3545 | |
cdumez@apple.com | 548d7bb | 2018-10-09 18:25:29 +0000 | [diff] [blame] | 3546 | NavigationAction newAction { *frame->document(), request, InitiatedByMainFrame::Unknown, NavigationType::Other, action.shouldOpenExternalURLsPolicy(), nullptr, action.downloadAttribute() }; |
commit-queue@webkit.org | 4a7ad28 | 2020-04-05 05:09:42 +0000 | [diff] [blame] | 3547 | mainFrame->loader().loadWithNavigationAction(request, WTFMove(newAction), FrameLoadType::Standard, formState, allowNavigationToInvalidURL); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3548 | } |
| 3549 | |
andersca | ec429f5 | 2007-01-13 01:44:24 +0000 | [diff] [blame] | 3550 | void FrameLoader::requestFromDelegate(ResourceRequest& request, unsigned long& identifier, ResourceError& error) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3551 | { |
| 3552 | ASSERT(!request.isNull()); |
| 3553 | |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 3554 | identifier = 0; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3555 | if (Page* page = m_frame.page()) { |
akling@apple.com | eb67e0a | 2013-08-19 08:24:08 +0000 | [diff] [blame] | 3556 | identifier = page->progress().createUniqueIdentifier(); |
akling@apple.com | 654fd9a | 2013-10-06 21:07:29 +0000 | [diff] [blame] | 3557 | notifier().assignIdentifierToInitialRequest(identifier, m_documentLoader.get(), request); |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 3558 | } |
andersca | ec429f5 | 2007-01-13 01:44:24 +0000 | [diff] [blame] | 3559 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3560 | ResourceRequest newRequest(request); |
akling@apple.com | 654fd9a | 2013-10-06 21:07:29 +0000 | [diff] [blame] | 3561 | notifier().dispatchWillSendRequest(m_documentLoader.get(), identifier, newRequest, ResourceResponse()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3562 | |
| 3563 | if (newRequest.isNull()) |
weinig@apple.com | 87a569c | 2008-05-18 01:21:20 +0000 | [diff] [blame] | 3564 | error = cancelledError(request); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3565 | else |
| 3566 | error = ResourceError(); |
| 3567 | |
| 3568 | request = newRequest; |
| 3569 | } |
| 3570 | |
cdumez@apple.com | d038ecf | 2017-08-15 21:15:09 +0000 | [diff] [blame] | 3571 | void FrameLoader::loadedResourceFromMemoryCache(CachedResource& resource, ResourceRequest& newRequest, ResourceError& error) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3572 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3573 | Page* page = m_frame.page(); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3574 | if (!page) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3575 | return; |
| 3576 | |
commit-queue@webkit.org | 39359f0 | 2020-04-25 21:28:45 +0000 | [diff] [blame] | 3577 | if (!resource.shouldSendResourceLoadCallbacks() || m_documentLoader->haveToldClientAboutLoad(resource.url().string())) |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3578 | return; |
| 3579 | |
japhet@chromium.org | 3e31718 | 2013-01-29 20:06:19 +0000 | [diff] [blame] | 3580 | // Main resource delegate messages are synthesized in MainResourceLoader, so we must not send them here. |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 3581 | if (resource.type() == CachedResource::Type::MainResource) |
japhet@chromium.org | 3e31718 | 2013-01-29 20:06:19 +0000 | [diff] [blame] | 3582 | return; |
| 3583 | |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3584 | if (!page->areMemoryCacheClientCallsEnabled()) { |
cdumez@apple.com | d038ecf | 2017-08-15 21:15:09 +0000 | [diff] [blame] | 3585 | InspectorInstrumentation::didLoadResourceFromMemoryCache(*page, m_documentLoader.get(), &resource); |
| 3586 | m_documentLoader->recordMemoryCacheLoadForFutureClientNotification(resource.resourceRequest()); |
commit-queue@webkit.org | 39359f0 | 2020-04-25 21:28:45 +0000 | [diff] [blame] | 3587 | m_documentLoader->didTellClientAboutLoad(resource.url().string()); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3588 | return; |
| 3589 | } |
| 3590 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3591 | if (m_client->dispatchDidLoadResourceFromMemoryCache(m_documentLoader.get(), newRequest, resource.response(), resource.encodedSize())) { |
cdumez@apple.com | d038ecf | 2017-08-15 21:15:09 +0000 | [diff] [blame] | 3592 | InspectorInstrumentation::didLoadResourceFromMemoryCache(*page, m_documentLoader.get(), &resource); |
commit-queue@webkit.org | 39359f0 | 2020-04-25 21:28:45 +0000 | [diff] [blame] | 3593 | m_documentLoader->didTellClientAboutLoad(resource.url().string()); |
timothy@apple.com | 8f85dce | 2008-01-08 23:51:28 +0000 | [diff] [blame] | 3594 | return; |
| 3595 | } |
| 3596 | |
andersca | ec429f5 | 2007-01-13 01:44:24 +0000 | [diff] [blame] | 3597 | unsigned long identifier; |
aestes@apple.com | 0c8e191 | 2013-04-06 03:09:25 +0000 | [diff] [blame] | 3598 | requestFromDelegate(newRequest, identifier, error); |
joepeck@webkit.org | e7d264d | 2017-03-09 03:35:13 +0000 | [diff] [blame] | 3599 | |
cdumez@apple.com | d038ecf | 2017-08-15 21:15:09 +0000 | [diff] [blame] | 3600 | ResourceResponse response = resource.response(); |
joepeck@webkit.org | e7d264d | 2017-03-09 03:35:13 +0000 | [diff] [blame] | 3601 | response.setSource(ResourceResponse::Source::MemoryCache); |
cdumez@apple.com | d038ecf | 2017-08-15 21:15:09 +0000 | [diff] [blame] | 3602 | notifier().sendRemainingDelegateMessages(m_documentLoader.get(), identifier, newRequest, response, 0, resource.encodedSize(), 0, error); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3603 | } |
| 3604 | |
Ms2ger@igalia.com | c33b77c | 2017-11-10 16:41:03 +0000 | [diff] [blame] | 3605 | void FrameLoader::applyUserAgentIfNeeded(ResourceRequest& request) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3606 | { |
Ms2ger@igalia.com | c33b77c | 2017-11-10 16:41:03 +0000 | [diff] [blame] | 3607 | if (!request.hasHTTPHeaderField(HTTPHeaderName::UserAgent)) { |
| 3608 | String userAgent = this->userAgent(request.url()); |
| 3609 | ASSERT(!userAgent.isNull()); |
| 3610 | request.setHTTPUserAgent(userAgent); |
| 3611 | } |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3612 | } |
| 3613 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3614 | bool FrameLoader::shouldInterruptLoadForXFrameOptions(const String& content, const URL& url, unsigned long requestIdentifier) |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 3615 | { |
akling@apple.com | 5298947 | 2013-09-16 20:09:25 +0000 | [diff] [blame] | 3616 | Frame& topFrame = m_frame.tree().top(); |
| 3617 | if (&m_frame == &topFrame) |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 3618 | return false; |
| 3619 | |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3620 | XFrameOptionsDisposition disposition = parseXFrameOptionsHeader(content); |
| 3621 | |
| 3622 | switch (disposition) { |
commit-queue@webkit.org | 27facab | 2020-07-18 10:33:54 +0000 | [diff] [blame] | 3623 | case XFrameOptionsDisposition::SameOrigin: { |
yusukesuzuki@slowstart.org | ae5a8bd | 2018-12-22 06:37:39 +0000 | [diff] [blame] | 3624 | auto origin = SecurityOrigin::create(url); |
akling@apple.com | 5298947 | 2013-09-16 20:09:25 +0000 | [diff] [blame] | 3625 | if (!origin->isSameSchemeHostPort(topFrame.document()->securityOrigin())) |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 3626 | return true; |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3627 | for (Frame* frame = m_frame.tree().parent(); frame; frame = frame->tree().parent()) { |
akling@apple.com | fbea406 | 2014-02-27 20:24:03 +0000 | [diff] [blame] | 3628 | if (!origin->isSameSchemeHostPort(frame->document()->securityOrigin())) |
dbates@webkit.org | 250656a | 2018-05-12 04:11:16 +0000 | [diff] [blame] | 3629 | return true; |
mkwst@chromium.org | f9d8fa0 | 2013-03-19 21:12:24 +0000 | [diff] [blame] | 3630 | } |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3631 | return false; |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 3632 | } |
commit-queue@webkit.org | 27facab | 2020-07-18 10:33:54 +0000 | [diff] [blame] | 3633 | case XFrameOptionsDisposition::Deny: |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3634 | return true; |
commit-queue@webkit.org | 27facab | 2020-07-18 10:33:54 +0000 | [diff] [blame] | 3635 | case XFrameOptionsDisposition::AllowAll: |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3636 | return false; |
commit-queue@webkit.org | 27facab | 2020-07-18 10:33:54 +0000 | [diff] [blame] | 3637 | case XFrameOptionsDisposition::Conflict: |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 3638 | m_frame.document()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, "Multiple 'X-Frame-Options' headers with conflicting values ('" + content + "') encountered when loading '" + url.stringCenterEllipsizedToLength() + "'. Falling back to 'DENY'.", requestIdentifier); |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3639 | return true; |
commit-queue@webkit.org | 27facab | 2020-07-18 10:33:54 +0000 | [diff] [blame] | 3640 | case XFrameOptionsDisposition::Invalid: |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 3641 | m_frame.document()->addConsoleMessage(MessageSource::JS, MessageLevel::Error, "Invalid 'X-Frame-Options' header encountered when loading '" + url.stringCenterEllipsizedToLength() + "': '" + content + "' is not a recognized directive. The header will be ignored.", requestIdentifier); |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3642 | return false; |
commit-queue@webkit.org | 27facab | 2020-07-18 10:33:54 +0000 | [diff] [blame] | 3643 | case XFrameOptionsDisposition::None: |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3644 | return false; |
| 3645 | } |
psolanki@apple.com | e2dc3b9 | 2014-02-20 18:23:24 +0000 | [diff] [blame] | 3646 | ASSERT_NOT_REACHED(); |
| 3647 | return false; |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 3648 | } |
| 3649 | |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 3650 | void FrameLoader::loadProvisionalItemFromCachedPage() |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3651 | { |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 3652 | DocumentLoader* provisionalLoader = provisionalDocumentLoader(); |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 3653 | LOG(BackForwardCache, "FrameLoader::loadProvisionalItemFromCachedPage Loading provisional DocumentLoader %p with URL '%s' from CachedPage", provisionalDocumentLoader(), provisionalDocumentLoader()->url().stringCenterEllipsizedToLength().utf8().data()); |
beidson@apple.com | ac095c0 | 2009-08-18 01:37:56 +0000 | [diff] [blame] | 3654 | |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 3655 | prepareForLoadStart(); |
| 3656 | |
| 3657 | m_loadingFromCachedPage = true; |
| 3658 | |
| 3659 | // Should have timing data from previous time(s) the page was shown. |
| 3660 | ASSERT(provisionalLoader->timing().startTime()); |
| 3661 | provisionalLoader->resetTiming(); |
| 3662 | provisionalLoader->timing().markStartTime(); |
| 3663 | |
| 3664 | provisionalLoader->setCommitted(true); |
| 3665 | commitProvisionalLoad(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3666 | } |
| 3667 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3668 | bool FrameLoader::shouldTreatURLAsSameAsCurrent(const URL& url) const |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3669 | { |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3670 | if (!history().currentItem()) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3671 | return false; |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3672 | return url == history().currentItem()->url() || url == history().currentItem()->originalURL(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3675 | bool FrameLoader::shouldTreatURLAsSrcdocDocument(const URL& url) const |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 3676 | { |
youenn@apple.com | 1779d58 | 2020-03-20 17:40:44 +0000 | [diff] [blame] | 3677 | if (!url.isAboutSrcDoc()) |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 3678 | return false; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3679 | HTMLFrameOwnerElement* ownerElement = m_frame.ownerElement(); |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 3680 | if (!ownerElement) |
| 3681 | return false; |
| 3682 | if (!ownerElement->hasTagName(iframeTag)) |
| 3683 | return false; |
rniwa@webkit.org | bda54a0 | 2016-07-18 00:39:37 +0000 | [diff] [blame] | 3684 | return ownerElement->hasAttributeWithoutSynchronization(srcdocAttr); |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 3685 | } |
| 3686 | |
darin@apple.com | 0ce67df | 2019-06-17 01:48:13 +0000 | [diff] [blame] | 3687 | Frame* FrameLoader::findFrameForNavigation(const AtomString& name, Document* activeDocument) |
weinig@apple.com | 7742780 | 2008-01-11 00:23:13 +0000 | [diff] [blame] | 3688 | { |
ap@apple.com | f8c414e | 2013-08-13 03:44:57 +0000 | [diff] [blame] | 3689 | // FIXME: Eventually all callers should supply the actual activeDocument so we can call canNavigate with the right document. |
| 3690 | if (!activeDocument) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3691 | activeDocument = m_frame.document(); |
ap@apple.com | f8c414e | 2013-08-13 03:44:57 +0000 | [diff] [blame] | 3692 | |
cdumez@apple.com | 6cb3eff | 2018-10-15 15:34:39 +0000 | [diff] [blame] | 3693 | auto* frame = m_frame.tree().find(name, activeDocument->frame() ? *activeDocument->frame() : m_frame); |
| 3694 | |
ap@apple.com | f8c414e | 2013-08-13 03:44:57 +0000 | [diff] [blame] | 3695 | if (!activeDocument->canNavigate(frame)) |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3696 | return nullptr; |
abarth@webkit.org | b46fdef | 2012-04-13 00:42:37 +0000 | [diff] [blame] | 3697 | |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 3698 | return frame; |
weinig@apple.com | 7742780 | 2008-01-11 00:23:13 +0000 | [diff] [blame] | 3699 | } |
| 3700 | |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3701 | void FrameLoader::loadSameDocumentItem(HistoryItem& item) |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3702 | { |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3703 | ASSERT(item.documentSequenceNumber() == history().currentItem()->documentSequenceNumber()); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3704 | |
aestes@apple.com | 8303b34 | 2016-02-19 09:29:44 +0000 | [diff] [blame] | 3705 | Ref<Frame> protect(m_frame); |
| 3706 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3707 | // Save user view state to the current history item here since we don't do a normal load. |
| 3708 | // FIXME: Does form state need to be saved here too? |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3709 | history().saveScrollPositionAndViewStateToItem(history().currentItem()); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3710 | if (FrameView* view = m_frame.view()) |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3711 | view->setWasScrolledByUser(false); |
| 3712 | |
achristensen@apple.com | 3a889f1 | 2018-10-16 15:58:10 +0000 | [diff] [blame] | 3713 | history().setCurrentItem(item); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3714 | |
| 3715 | // loadInSameDocument() actually changes the URL and notifies load delegates of a "fake" load |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3716 | loadInSameDocument(item.url(), item.stateObject(), false); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3717 | |
| 3718 | // Restore user view state from the current history item here since we don't do a normal load. |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3719 | history().restoreScrollPositionAndViewState(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3720 | } |
| 3721 | |
abarth@webkit.org | 1c893f4 | 2009-10-10 02:27:21 +0000 | [diff] [blame] | 3722 | // FIXME: This function should really be split into a couple pieces, some of |
| 3723 | // which should be methods of HistoryController and some of which should be |
| 3724 | // methods of FrameLoader. |
cdumez@apple.com | 29f7c1e | 2019-03-13 20:32:48 +0000 | [diff] [blame] | 3725 | void FrameLoader::loadDifferentDocumentItem(HistoryItem& item, HistoryItem* fromItem, FrameLoadType loadType, FormSubmissionCacheLoadPolicy cacheLoadPolicy, ShouldTreatAsContinuingLoad shouldTreatAsContinuingLoad) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3726 | { |
krollin@apple.com | bdeaed7 | 2020-01-08 01:31:20 +0000 | [diff] [blame] | 3727 | FRAMELOADER_RELEASE_LOG_IF_ALLOWED(ResourceLoading, "loadDifferentDocumentItem: frame load started"); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3728 | |
bfulgham@apple.com | d0c0fc8 | 2019-05-17 16:03:36 +0000 | [diff] [blame] | 3729 | Ref<Frame> protectedFrame(m_frame); |
| 3730 | |
jiewen_tan@apple.com | 71ef00e | 2018-12-04 23:01:29 +0000 | [diff] [blame] | 3731 | // History items should not be reported to the parent. |
| 3732 | m_shouldReportResourceTimingToParentFrame = false; |
| 3733 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3734 | // Remember this item so we can traverse any child items as child frames load |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3735 | history().setProvisionalItem(&item); |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 3736 | |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 3737 | auto initiatedByMainFrame = InitiatedByMainFrame::Unknown; |
| 3738 | |
cdumez@apple.com | 3aedc03 | 2019-01-31 02:23:55 +0000 | [diff] [blame] | 3739 | SetForScope<LoadContinuingState> continuingLoadGuard(m_currentLoadContinuingState, shouldTreatAsContinuingLoad == ShouldTreatAsContinuingLoad::Yes ? LoadContinuingState::ContinuingWithHistoryItem : LoadContinuingState::NotContinuing); |
beidson@apple.com | 69caeee | 2018-04-20 04:55:32 +0000 | [diff] [blame] | 3740 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame] | 3741 | if (CachedPage* cachedPage = BackForwardCache::singleton().get(item, m_frame.page())) { |
mitz@apple.com | 4a60442 | 2014-11-13 23:22:50 +0000 | [diff] [blame] | 3742 | auto documentLoader = cachedPage->documentLoader(); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3743 | m_client->updateCachedDocumentLoader(*documentLoader); |
beidson@apple.com | 07c00cf | 2018-05-11 16:12:11 +0000 | [diff] [blame] | 3744 | |
| 3745 | auto action = NavigationAction { *m_frame.document(), documentLoader->request(), initiatedByMainFrame, loadType, false }; |
| 3746 | action.setTargetBackForwardItem(item); |
cdumez@apple.com | 29f7c1e | 2019-03-13 20:32:48 +0000 | [diff] [blame] | 3747 | action.setSourceBackForwardItem(fromItem); |
beidson@apple.com | 07c00cf | 2018-05-11 16:12:11 +0000 | [diff] [blame] | 3748 | documentLoader->setTriggeringAction(WTFMove(action)); |
| 3749 | |
mitz@apple.com | 4a60442 | 2014-11-13 23:22:50 +0000 | [diff] [blame] | 3750 | documentLoader->setLastCheckedRequest(ResourceRequest()); |
commit-queue@webkit.org | 372c264 | 2020-04-03 16:53:48 +0000 | [diff] [blame] | 3751 | loadWithDocumentLoader(documentLoader, loadType, { }, AllowNavigationToInvalidURL::Yes); |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 3752 | return; |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3753 | } |
adele@apple.com | f3d6b89 | 2008-04-29 01:30:20 +0000 | [diff] [blame] | 3754 | |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3755 | URL itemURL = item.url(); |
| 3756 | URL itemOriginalURL = item.originalURL(); |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3757 | URL currentURL; |
beidson | 0c34599 | 2007-02-13 08:59:33 +0000 | [diff] [blame] | 3758 | if (documentLoader()) |
weinig@apple.com | c500266 | 2007-12-12 07:26:19 +0000 | [diff] [blame] | 3759 | currentURL = documentLoader()->url(); |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3760 | RefPtr<FormData> formData = item.formData(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3761 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3762 | ResourceRequest request(itemURL); |
| 3763 | |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3764 | if (!item.referrer().isNull()) |
| 3765 | request.setHTTPReferrer(item.referrer()); |
dbates@webkit.org | ae34b60 | 2015-08-05 16:05:55 +0000 | [diff] [blame] | 3766 | |
dbates@webkit.org | 9692a07 | 2017-07-12 18:01:19 +0000 | [diff] [blame] | 3767 | ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLsPolicyToApply(m_frame, initiatedByMainFrame, item.shouldOpenExternalURLsPolicy()); |
dbates@webkit.org | ae34b60 | 2015-08-05 16:05:55 +0000 | [diff] [blame] | 3768 | bool isFormSubmission = false; |
| 3769 | Event* event = nullptr; |
| 3770 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3771 | // If this was a repost that failed the page cache, we might try to repost the form. |
| 3772 | NavigationAction action; |
| 3773 | if (formData) { |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3774 | request.setHTTPMethod("POST"); |
youenn.fablet@crf.canon.fr | 11cc655 | 2016-01-22 14:51:16 +0000 | [diff] [blame] | 3775 | request.setHTTPBody(WTFMove(formData)); |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3776 | request.setHTTPContentType(item.formContentType()); |
cdumez@apple.com | 1f985b8 | 2020-05-01 23:07:38 +0000 | [diff] [blame] | 3777 | auto securityOrigin = SecurityOrigin::createFromString(item.referrer()); |
| 3778 | addHTTPOriginIfNeeded(request, securityOrigin->toString()); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3779 | |
commit-queue@webkit.org | 627a2de | 2020-04-13 08:04:39 +0000 | [diff] [blame] | 3780 | addExtraFieldsToRequest(request, IsMainResource::Yes, loadType); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3781 | |
| 3782 | // FIXME: Slight hack to test if the NSURL cache contains the page we're going to. |
| 3783 | // We want to know this before talking to the policy delegate, since it affects whether |
| 3784 | // we show the DoYouReallyWantToRepost nag. |
| 3785 | // |
| 3786 | // This trick has a small bug (3123893) where we might find a cache hit, but then |
| 3787 | // have the item vanish when we try to use it in the ensuing nav. This should be |
| 3788 | // extremely rare, but in that case the user will get an error on the navigation. |
| 3789 | |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3790 | if (cacheLoadPolicy == MayAttemptCacheOnlyLoadForFormSubmissionItem) { |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 3791 | request.setCachePolicy(ResourceRequestCachePolicy::ReturnCacheDataDontLoad); |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 3792 | action = { *m_frame.document(), request, initiatedByMainFrame, loadType, isFormSubmission, event, shouldOpenExternalURLsPolicy }; |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3793 | } else { |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 3794 | request.setCachePolicy(ResourceRequestCachePolicy::ReturnCacheDataElseLoad); |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 3795 | action = { *m_frame.document(), request, initiatedByMainFrame, NavigationType::FormResubmitted, shouldOpenExternalURLsPolicy, event }; |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3796 | } |
| 3797 | } else { |
| 3798 | switch (loadType) { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3799 | case FrameLoadType::Reload: |
commit-queue@webkit.org | ea87ad8 | 2018-01-11 00:45:49 +0000 | [diff] [blame] | 3800 | case FrameLoadType::ReloadFromOrigin: |
commit-queue@webkit.org | 4833ac5 | 2018-02-26 17:38:14 +0000 | [diff] [blame] | 3801 | case FrameLoadType::ReloadExpiredOnly: |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 3802 | request.setCachePolicy(ResourceRequestCachePolicy::ReloadIgnoringCacheData); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3803 | break; |
| 3804 | case FrameLoadType::Back: |
| 3805 | case FrameLoadType::Forward: |
carlosgc@webkit.org | 2af15b7 | 2016-02-27 07:44:07 +0000 | [diff] [blame] | 3806 | case FrameLoadType::IndexedBackForward: { |
cdumez@apple.com | 3e885d4 | 2016-03-15 20:01:39 +0000 | [diff] [blame] | 3807 | #if PLATFORM(COCOA) |
carlosgc@webkit.org | 2af15b7 | 2016-02-27 07:44:07 +0000 | [diff] [blame] | 3808 | bool allowStaleData = true; |
| 3809 | #else |
| 3810 | bool allowStaleData = !item.wasRestoredFromSession(); |
| 3811 | #endif |
| 3812 | if (allowStaleData) |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 3813 | request.setCachePolicy(ResourceRequestCachePolicy::ReturnCacheDataElseLoad); |
carlosgc@webkit.org | 2af15b7 | 2016-02-27 07:44:07 +0000 | [diff] [blame] | 3814 | item.setWasRestoredFromSession(false); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3815 | break; |
carlosgc@webkit.org | 2af15b7 | 2016-02-27 07:44:07 +0000 | [diff] [blame] | 3816 | } |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3817 | case FrameLoadType::Standard: |
| 3818 | case FrameLoadType::RedirectWithLockedBackForwardList: |
| 3819 | break; |
| 3820 | case FrameLoadType::Same: |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 3821 | case FrameLoadType::Replace: |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3822 | ASSERT_NOT_REACHED(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3823 | } |
| 3824 | |
commit-queue@webkit.org | 627a2de | 2020-04-13 08:04:39 +0000 | [diff] [blame] | 3825 | addExtraFieldsToRequest(request, IsMainResource::Yes, loadType); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3826 | |
jochen@chromium.org | 056b7fa | 2011-10-18 04:47:05 +0000 | [diff] [blame] | 3827 | ResourceRequest requestForOriginalURL(request); |
| 3828 | requestForOriginalURL.setURL(itemOriginalURL); |
dbates@webkit.org | 9692a07 | 2017-07-12 18:01:19 +0000 | [diff] [blame] | 3829 | action = { *m_frame.document(), requestForOriginalURL, initiatedByMainFrame, loadType, isFormSubmission, event, shouldOpenExternalURLsPolicy }; |
jochen@chromium.org | 056b7fa | 2011-10-18 04:47:05 +0000 | [diff] [blame] | 3830 | } |
| 3831 | |
beidson@apple.com | 07c00cf | 2018-05-11 16:12:11 +0000 | [diff] [blame] | 3832 | action.setTargetBackForwardItem(item); |
cdumez@apple.com | 29f7c1e | 2019-03-13 20:32:48 +0000 | [diff] [blame] | 3833 | action.setSourceBackForwardItem(fromItem); |
beidson@apple.com | 07c00cf | 2018-05-11 16:12:11 +0000 | [diff] [blame] | 3834 | |
commit-queue@webkit.org | 4a7ad28 | 2020-04-05 05:09:42 +0000 | [diff] [blame] | 3835 | loadWithNavigationAction(request, WTFMove(action), loadType, { }, AllowNavigationToInvalidURL::Yes); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | // Loads content into this frame, as specified by history item |
cdumez@apple.com | 29f7c1e | 2019-03-13 20:32:48 +0000 | [diff] [blame] | 3839 | void FrameLoader::loadItem(HistoryItem& item, HistoryItem* fromItem, FrameLoadType loadType, ShouldTreatAsContinuingLoad shouldTreatAsContinuingLoad) |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3840 | { |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3841 | m_requestedHistoryItem = &item; |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3842 | HistoryItem* currentItem = history().currentItem(); |
cdumez@apple.com | fea5cb9 | 2015-02-02 00:49:36 +0000 | [diff] [blame] | 3843 | bool sameDocumentNavigation = currentItem && item.shouldDoSameDocumentNavigationTo(*currentItem); |
darin@chromium.org | e71dd0f | 2009-04-17 20:31:17 +0000 | [diff] [blame] | 3844 | |
cdumez@apple.com | 4c2d228 | 2020-10-29 21:35:14 +0000 | [diff] [blame] | 3845 | // If we're continuing this history navigation in a new process, then doing a same document navigation never makes sense. |
| 3846 | ASSERT(!sameDocumentNavigation || shouldTreatAsContinuingLoad == ShouldTreatAsContinuingLoad::No); |
| 3847 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3848 | if (sameDocumentNavigation) |
mihaip@chromium.org | e5dbd37 | 2010-12-08 02:32:41 +0000 | [diff] [blame] | 3849 | loadSameDocumentItem(item); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3850 | else |
cdumez@apple.com | 29f7c1e | 2019-03-13 20:32:48 +0000 | [diff] [blame] | 3851 | loadDifferentDocumentItem(item, fromItem, loadType, MayAttemptCacheOnlyLoadForFormSubmissionItem, shouldTreatAsContinuingLoad); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3852 | } |
| 3853 | |
| 3854 | void FrameLoader::retryAfterFailedCacheOnlyMainResourceLoad() |
| 3855 | { |
| 3856 | ASSERT(m_state == FrameStateProvisional); |
| 3857 | ASSERT(!m_loadingFromCachedPage); |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3858 | ASSERT(history().provisionalItem()); |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3859 | ASSERT(history().provisionalItem()->formData()); |
| 3860 | ASSERT(history().provisionalItem() == m_requestedHistoryItem.get()); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3861 | |
| 3862 | FrameLoadType loadType = m_loadType; |
achristensen@apple.com | d924576 | 2019-07-09 18:55:43 +0000 | [diff] [blame] | 3863 | HistoryItem* item = history().provisionalItem(); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3864 | |
| 3865 | stopAllLoaders(ShouldNotClearProvisionalItem); |
achristensen@apple.com | d924576 | 2019-07-09 18:55:43 +0000 | [diff] [blame] | 3866 | if (item) |
| 3867 | loadDifferentDocumentItem(*item, history().currentItem(), loadType, MayNotAttemptCacheOnlyLoadForFormSubmissionItem, ShouldTreatAsContinuingLoad::No); |
| 3868 | else { |
| 3869 | ASSERT_NOT_REACHED(); |
krollin@apple.com | f26b56e | 2020-02-28 19:43:33 +0000 | [diff] [blame] | 3870 | FRAMELOADER_RELEASE_LOG_ERROR_IF_ALLOWED(ResourceLoading, "retryAfterFailedCacheOnlyMainResourceLoad: Retrying load after failed cache-only main resource load failed because there is no provisional history item."); |
achristensen@apple.com | d924576 | 2019-07-09 18:55:43 +0000 | [diff] [blame] | 3871 | } |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3872 | } |
| 3873 | |
andersca | c8ee246 | 2007-01-05 22:26:32 +0000 | [diff] [blame] | 3874 | ResourceError FrameLoader::cancelledError(const ResourceRequest& request) const |
| 3875 | { |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3876 | ResourceError error = m_client->cancelledError(request); |
youenn.fablet@crf.canon.fr | 156f9bb | 2016-06-09 06:55:26 +0000 | [diff] [blame] | 3877 | error.setType(ResourceError::Type::Cancellation); |
weinig@apple.com | 87a569c | 2008-05-18 01:21:20 +0000 | [diff] [blame] | 3878 | return error; |
andersca | c8ee246 | 2007-01-05 22:26:32 +0000 | [diff] [blame] | 3879 | } |
| 3880 | |
commit-queue@webkit.org | 8090ccb | 2015-10-06 08:18:08 +0000 | [diff] [blame] | 3881 | ResourceError FrameLoader::blockedByContentBlockerError(const ResourceRequest& request) const |
| 3882 | { |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3883 | return m_client->blockedByContentBlockerError(request); |
commit-queue@webkit.org | 8090ccb | 2015-10-06 08:18:08 +0000 | [diff] [blame] | 3884 | } |
| 3885 | |
bfulgham@apple.com | b4c7093 | 2016-01-06 22:07:51 +0000 | [diff] [blame] | 3886 | ResourceError FrameLoader::blockedError(const ResourceRequest& request) const |
| 3887 | { |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3888 | ResourceError error = m_client->blockedError(request); |
youenn.fablet@crf.canon.fr | 156f9bb | 2016-06-09 06:55:26 +0000 | [diff] [blame] | 3889 | error.setType(ResourceError::Type::Cancellation); |
bfulgham@apple.com | b4c7093 | 2016-01-06 22:07:51 +0000 | [diff] [blame] | 3890 | return error; |
| 3891 | } |
| 3892 | |
aestes@apple.com | 176a9aa | 2016-07-08 20:14:34 +0000 | [diff] [blame] | 3893 | #if ENABLE(CONTENT_FILTERING) |
| 3894 | ResourceError FrameLoader::blockedByContentFilterError(const ResourceRequest& request) const |
| 3895 | { |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3896 | ResourceError error = m_client->blockedByContentFilterError(request); |
aestes@apple.com | 176a9aa | 2016-07-08 20:14:34 +0000 | [diff] [blame] | 3897 | error.setType(ResourceError::Type::General); |
| 3898 | return error; |
| 3899 | } |
| 3900 | #endif |
| 3901 | |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 3902 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 3903 | RetainPtr<CFDictionaryRef> FrameLoader::connectionProperties(ResourceLoader* loader) |
| 3904 | { |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3905 | return m_client->connectionProperties(loader->documentLoader(), loader->identifier()); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 3906 | } |
| 3907 | #endif |
| 3908 | |
dbates@webkit.org | 0fefad7 | 2017-10-19 18:46:22 +0000 | [diff] [blame] | 3909 | ReferrerPolicy FrameLoader::effectiveReferrerPolicy() const |
| 3910 | { |
| 3911 | if (auto* parentFrame = m_frame.tree().parent()) |
| 3912 | return parentFrame->document()->referrerPolicy(); |
| 3913 | if (m_opener) |
| 3914 | return m_opener->document()->referrerPolicy(); |
| 3915 | return ReferrerPolicy::NoReferrerWhenDowngrade; |
| 3916 | } |
| 3917 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 3918 | String FrameLoader::referrer() const |
| 3919 | { |
cdumez@apple.com | 327d6c6 | 2016-07-16 04:51:45 +0000 | [diff] [blame] | 3920 | return m_documentLoader ? m_documentLoader->request().httpReferrer() : emptyString(); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 3921 | } |
| 3922 | |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3923 | void FrameLoader::dispatchDidClearWindowObjectsInAllWorlds() |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3924 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3925 | if (!m_frame.script().canExecuteScripts(NotAboutToExecuteScript)) |
thatcher | 10840e5 | 2007-09-22 00:49:09 +0000 | [diff] [blame] | 3926 | return; |
| 3927 | |
weinig@apple.com | 8f71603 | 2013-10-02 17:03:09 +0000 | [diff] [blame] | 3928 | Vector<Ref<DOMWrapperWorld>> worlds; |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3929 | ScriptController::getAllWorlds(worlds); |
cdumez@apple.com | 2f66120 | 2014-11-04 07:22:18 +0000 | [diff] [blame] | 3930 | for (auto& world : worlds) |
| 3931 | dispatchDidClearWindowObjectInWorld(world); |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3932 | } |
| 3933 | |
weinig@apple.com | 8f71603 | 2013-10-02 17:03:09 +0000 | [diff] [blame] | 3934 | void FrameLoader::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld& world) |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3935 | { |
cdumez@apple.com | 87a798a | 2018-04-19 04:02:30 +0000 | [diff] [blame] | 3936 | if (!m_frame.script().canExecuteScripts(NotAboutToExecuteScript) || !m_frame.windowProxy().existingJSWindowProxy(world)) |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3937 | return; |
| 3938 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3939 | m_client->dispatchDidClearWindowObjectInWorld(world); |
timothy@apple.com | efb8ac1 | 2008-07-24 02:48:36 +0000 | [diff] [blame] | 3940 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3941 | if (Page* page = m_frame.page()) |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 3942 | page->inspectorController().didClearWindowObjectInWorld(m_frame, world); |
loislo@chromium.org | e971cb5 | 2011-02-08 17:32:44 +0000 | [diff] [blame] | 3943 | |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 3944 | InspectorInstrumentation::didClearWindowObjectInWorld(m_frame, world); |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3945 | } |
| 3946 | |
beidson@apple.com | 2a75a96 | 2012-04-24 18:12:55 +0000 | [diff] [blame] | 3947 | void FrameLoader::dispatchGlobalObjectAvailableInAllWorlds() |
| 3948 | { |
weinig@apple.com | 8f71603 | 2013-10-02 17:03:09 +0000 | [diff] [blame] | 3949 | Vector<Ref<DOMWrapperWorld>> worlds; |
beidson@apple.com | 2a75a96 | 2012-04-24 18:12:55 +0000 | [diff] [blame] | 3950 | ScriptController::getAllWorlds(worlds); |
cdumez@apple.com | 2f66120 | 2014-11-04 07:22:18 +0000 | [diff] [blame] | 3951 | for (auto& world : worlds) |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3952 | m_client->dispatchGlobalObjectAvailable(world); |
beidson@apple.com | 2a75a96 | 2012-04-24 18:12:55 +0000 | [diff] [blame] | 3953 | } |
| 3954 | |
abarth@webkit.org | 8b45d86 | 2011-11-05 21:55:59 +0000 | [diff] [blame] | 3955 | SandboxFlags FrameLoader::effectiveSandboxFlags() const |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3956 | { |
abarth@webkit.org | f2c54c2 | 2010-04-11 06:57:13 +0000 | [diff] [blame] | 3957 | SandboxFlags flags = m_forcedSandboxFlags; |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3958 | if (Frame* parentFrame = m_frame.tree().parent()) |
abarth@webkit.org | 8b45d86 | 2011-11-05 21:55:59 +0000 | [diff] [blame] | 3959 | flags |= parentFrame->document()->sandboxFlags(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3960 | if (HTMLFrameOwnerElement* ownerElement = m_frame.ownerElement()) |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3961 | flags |= ownerElement->sandboxFlags(); |
abarth@webkit.org | 8b45d86 | 2011-11-05 21:55:59 +0000 | [diff] [blame] | 3962 | return flags; |
abarth@webkit.org | f5267a4 | 2010-01-10 08:14:05 +0000 | [diff] [blame] | 3963 | } |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3964 | |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3965 | void FrameLoader::didChangeTitle(DocumentLoader* loader) |
| 3966 | { |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3967 | m_client->didChangeTitle(loader); |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3968 | |
darin@apple.com | 719d29c | 2009-07-24 00:09:17 +0000 | [diff] [blame] | 3969 | if (loader == m_documentLoader) { |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3970 | // Must update the entries in the back-forward list too. |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3971 | history().setCurrentItemTitle(loader->title()); |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3972 | // This must go through the WebFrame because it has the right notion of the current b/f item. |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3973 | m_client->setTitle(loader->title(), loader->urlForHistory()); |
| 3974 | m_client->setMainFrameDocumentReady(true); // update observers with new DOMDocument |
| 3975 | m_client->dispatchDidReceiveTitle(loader->title()); |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3976 | } |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 3977 | |
| 3978 | #if ENABLE(REMOTE_INSPECTOR) |
| 3979 | if (m_frame.isMainFrame()) |
| 3980 | m_frame.page()->remoteInspectorInformationDidChange(); |
| 3981 | #endif |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3982 | } |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 3983 | |
achristensen@apple.com | e0301a3 | 2020-02-07 23:30:29 +0000 | [diff] [blame] | 3984 | void FrameLoader::dispatchDidCommitLoad(Optional<HasInsecureContent> initialHasInsecureContent, Optional<UsedLegacyTLS> initialUsedLegacyTLS) |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 3985 | { |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 3986 | if (m_stateMachine.creatingInitialEmptyDocument()) |
darin@apple.com | 87134f2 | 2007-12-05 22:58:41 +0000 | [diff] [blame] | 3987 | return; |
| 3988 | |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 3989 | m_client->dispatchDidCommitLoad(initialHasInsecureContent, initialUsedLegacyTLS); |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 3990 | |
simon.fraser@apple.com | 54d7757 | 2020-08-04 05:57:39 +0000 | [diff] [blame] | 3991 | if (m_frame.isMainFrame()) |
| 3992 | m_frame.page()->didCommitLoad(); |
jer.noble@apple.com | 381b467 | 2012-07-28 00:41:18 +0000 | [diff] [blame] | 3993 | |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 3994 | InspectorInstrumentation::didCommitLoad(m_frame, m_documentLoader.get()); |
commit-queue@webkit.org | 42b4787 | 2013-02-19 19:19:02 +0000 | [diff] [blame] | 3995 | |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 3996 | #if ENABLE(REMOTE_INSPECTOR) |
akling@apple.com | fbea406 | 2014-02-27 20:24:03 +0000 | [diff] [blame] | 3997 | if (m_frame.isMainFrame()) |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 3998 | m_frame.page()->remoteInspectorInformationDidChange(); |
| 3999 | #endif |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 4000 | } |
| 4001 | |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 4002 | void FrameLoader::tellClientAboutPastMemoryCacheLoads() |
| 4003 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 4004 | ASSERT(m_frame.page()); |
| 4005 | ASSERT(m_frame.page()->areMemoryCacheClientCallsEnabled()); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 4006 | |
| 4007 | if (!m_documentLoader) |
| 4008 | return; |
| 4009 | |
jpfau@apple.com | 97c6a7f | 2013-02-26 00:49:17 +0000 | [diff] [blame] | 4010 | Vector<ResourceRequest> pastLoads; |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 4011 | m_documentLoader->takeMemoryCacheLoadsForClientNotification(pastLoads); |
| 4012 | |
commit-queue@webkit.org | acddfad | 2015-09-30 05:53:51 +0000 | [diff] [blame] | 4013 | for (auto& pastLoad : pastLoads) { |
| 4014 | CachedResource* resource = MemoryCache::singleton().resourceForRequest(pastLoad, m_frame.page()->sessionID()); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 4015 | |
| 4016 | // FIXME: These loads, loaded from cache, but now gone from the cache by the time |
| 4017 | // Page::setMemoryCacheClientCallsEnabled(true) is called, will not be seen by the client. |
| 4018 | // Consider if there's some efficient way of remembering enough to deliver this client call. |
| 4019 | // We have the URL, but not the rest of the response or the length. |
| 4020 | if (!resource) |
| 4021 | continue; |
| 4022 | |
| 4023 | ResourceRequest request(resource->url()); |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 4024 | m_client->dispatchDidLoadResourceFromMemoryCache(m_documentLoader.get(), request, resource->response(), resource->encodedSize()); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 4025 | } |
| 4026 | } |
| 4027 | |
diegohcg@webkit.org | 838e0a2 | 2010-09-04 14:48:30 +0000 | [diff] [blame] | 4028 | NetworkingContext* FrameLoader::networkingContext() const |
| 4029 | { |
| 4030 | return m_networkingContext.get(); |
| 4031 | } |
| 4032 | |
antti@apple.com | a6775c1 | 2013-04-05 21:19:56 +0000 | [diff] [blame] | 4033 | void FrameLoader::loadProgressingStatusChanged() |
| 4034 | { |
antti@apple.com | 08536d1 | 2014-06-27 21:58:06 +0000 | [diff] [blame] | 4035 | if (auto* view = m_frame.mainFrame().view()) |
| 4036 | view->loadProgressingStatusChanged(); |
antti@apple.com | a6775c1 | 2013-04-05 21:19:56 +0000 | [diff] [blame] | 4037 | } |
| 4038 | |
zalan@apple.com | fc7ad74 | 2020-03-04 14:53:01 +0000 | [diff] [blame] | 4039 | void FrameLoader::completePageTransitionIfNeeded() |
timothy_horton@apple.com | 88756d6 | 2013-05-30 06:24:36 +0000 | [diff] [blame] | 4040 | { |
youenn@apple.com | ee96d0f | 2020-03-18 13:59:23 +0000 | [diff] [blame] | 4041 | m_client->completePageTransitionIfNeeded(); |
timothy_horton@apple.com | 88756d6 | 2013-05-30 06:24:36 +0000 | [diff] [blame] | 4042 | } |
| 4043 | |
antti@apple.com | 1229ead | 2015-03-30 21:09:14 +0000 | [diff] [blame] | 4044 | void FrameLoader::clearTestingOverrides() |
| 4045 | { |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 4046 | m_overrideCachePolicyForTesting = WTF::nullopt; |
| 4047 | m_overrideResourceLoadPriorityForTesting = WTF::nullopt; |
antti@apple.com | 2c4a2a2 | 2015-08-14 14:08:59 +0000 | [diff] [blame] | 4048 | m_isStrictRawResourceValidationPolicyDisabledForTesting = false; |
antti@apple.com | 1229ead | 2015-03-30 21:09:14 +0000 | [diff] [blame] | 4049 | } |
| 4050 | |
commit-queue@webkit.org | 6d63522 | 2016-03-08 06:44:59 +0000 | [diff] [blame] | 4051 | bool FrameLoader::isAlwaysOnLoggingAllowed() const |
| 4052 | { |
| 4053 | return frame().isAlwaysOnLoggingAllowed(); |
| 4054 | } |
| 4055 | |
darin@apple.com | 90a0f15 | 2009-02-01 00:55:03 +0000 | [diff] [blame] | 4056 | bool FrameLoaderClient::hasHTMLView() const |
| 4057 | { |
| 4058 | return true; |
| 4059 | } |
| 4060 | |
dbates@webkit.org | 7f3a982 | 2017-06-22 19:45:10 +0000 | [diff] [blame] | 4061 | RefPtr<Frame> createWindow(Frame& openerFrame, Frame& lookupFrame, FrameLoadRequest&& request, const WindowFeatures& features, bool& created) |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4062 | { |
| 4063 | ASSERT(!features.dialog || request.frameName().isEmpty()); |
commit-queue@webkit.org | 8a13ad3 | 2020-03-16 08:11:26 +0000 | [diff] [blame] | 4064 | ASSERT(request.resourceRequest().httpMethod() == "GET"); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4065 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4066 | created = false; |
| 4067 | |
dbates@webkit.org | de972cd | 2018-01-24 22:11:19 +0000 | [diff] [blame] | 4068 | // FIXME: Provide line number information with respect to the opener's document. |
commit-queue@webkit.org | 39359f0 | 2020-04-25 21:28:45 +0000 | [diff] [blame] | 4069 | if (request.resourceRequest().url().protocolIsJavaScript() && !openerFrame.document()->contentSecurityPolicy()->allowJavaScriptURLs(openerFrame.document()->url().string(), { })) |
dbates@webkit.org | de972cd | 2018-01-24 22:11:19 +0000 | [diff] [blame] | 4070 | return nullptr; |
| 4071 | |
cdumez@apple.com | eec032f | 2017-04-05 13:36:47 +0000 | [diff] [blame] | 4072 | if (!request.frameName().isEmpty() && !equalIgnoringASCIICase(request.frameName(), "_blank")) { |
cdumez@apple.com | 468ca18 | 2015-05-15 05:07:22 +0000 | [diff] [blame] | 4073 | if (RefPtr<Frame> frame = lookupFrame.loader().findFrameForNavigation(request.frameName(), openerFrame.document())) { |
cdumez@apple.com | eec032f | 2017-04-05 13:36:47 +0000 | [diff] [blame] | 4074 | if (!equalIgnoringASCIICase(request.frameName(), "_self")) { |
jochen@chromium.org | b2c684a | 2013-05-11 19:09:01 +0000 | [diff] [blame] | 4075 | if (Page* page = frame->page()) |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4076 | page->chrome().focus(); |
jochen@chromium.org | b2c684a | 2013-05-11 19:09:01 +0000 | [diff] [blame] | 4077 | } |
aestes@apple.com | 2038dcb | 2015-12-28 16:26:24 +0000 | [diff] [blame] | 4078 | return frame; |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4079 | } |
| 4080 | } |
| 4081 | |
| 4082 | // Sandboxed frames cannot open new auxiliary browsing contexts. |
mkwst@chromium.org | b10ebb43 | 2012-12-04 18:34:27 +0000 | [diff] [blame] | 4083 | if (isDocumentSandboxed(openerFrame, SandboxPopups)) { |
| 4084 | // FIXME: This message should be moved off the console once a solution to https://bugs.webkit.org/show_bug.cgi?id=103274 exists. |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 4085 | openerFrame.document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Blocked opening '" + request.resourceRequest().url().stringCenterEllipsizedToLength() + "' in a new window because the request was made in a sandboxed frame whose 'allow-popups' permission is not set."); |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4086 | return nullptr; |
mkwst@chromium.org | b10ebb43 | 2012-12-04 18:34:27 +0000 | [diff] [blame] | 4087 | } |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4088 | |
| 4089 | // FIXME: Setting the referrer should be the caller's responsibility. |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 4090 | String referrer = SecurityPolicy::generateReferrerHeader(openerFrame.document()->referrerPolicy(), request.resourceRequest().url(), openerFrame.loader().outgoingReferrer()); |
jochen@chromium.org | c881e40 | 2013-02-28 21:45:58 +0000 | [diff] [blame] | 4091 | if (!referrer.isEmpty()) |
dbates@webkit.org | 7f3a982 | 2017-06-22 19:45:10 +0000 | [diff] [blame] | 4092 | request.resourceRequest().setHTTPReferrer(referrer); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 4093 | FrameLoader::addSameSiteInfoToRequestIfNeeded(request.resourceRequest(), openerFrame.document()); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4094 | |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 4095 | Page* oldPage = openerFrame.page(); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4096 | if (!oldPage) |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4097 | return nullptr; |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4098 | |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 4099 | ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLsPolicyToApply(openerFrame, request); |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 4100 | NavigationAction action { request.requester(), request.resourceRequest(), request.initiatedByMainFrame(), NavigationType::Other, shouldOpenExternalURLsPolicy }; |
commit-queue@webkit.org | ba63760 | 2020-03-16 07:20:28 +0000 | [diff] [blame] | 4101 | Page* page = oldPage->chrome().createWindow(openerFrame, features, action); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4102 | if (!page) |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4103 | return nullptr; |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4104 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4105 | RefPtr<Frame> frame = &page->mainFrame(); |
| 4106 | |
commit-queue@webkit.org | 04df842 | 2017-06-09 17:59:18 +0000 | [diff] [blame] | 4107 | if (isDocumentSandboxed(openerFrame, SandboxPropagatesToAuxiliaryBrowsingContexts)) |
| 4108 | frame->loader().forceSandboxFlags(openerFrame.document()->sandboxFlags()); |
abarth@webkit.org | 7155e25 | 2011-11-04 18:14:58 +0000 | [diff] [blame] | 4109 | |
cdumez@apple.com | eec032f | 2017-04-05 13:36:47 +0000 | [diff] [blame] | 4110 | if (!equalIgnoringASCIICase(request.frameName(), "_blank")) |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4111 | frame->tree().setName(request.frameName()); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4112 | |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4113 | page->chrome().setToolbarsVisible(features.toolBarVisible || features.locationBarVisible); |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4114 | |
| 4115 | if (!frame->page()) |
| 4116 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4117 | page->chrome().setStatusbarVisible(features.statusBarVisible); |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4118 | |
| 4119 | if (!frame->page()) |
| 4120 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4121 | page->chrome().setScrollbarsVisible(features.scrollbarsVisible); |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4122 | |
| 4123 | if (!frame->page()) |
| 4124 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4125 | page->chrome().setMenubarVisible(features.menuBarVisible); |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4126 | |
| 4127 | if (!frame->page()) |
| 4128 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4129 | page->chrome().setResizable(features.resizable); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4130 | |
| 4131 | // 'x' and 'y' specify the location of the window, while 'width' and 'height' |
kenneth@webkit.org | dc092f7 | 2012-11-14 11:05:20 +0000 | [diff] [blame] | 4132 | // specify the size of the viewport. We can only resize the window, so adjust |
| 4133 | // for the difference between the window size and the viewport size. |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4134 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4135 | // FIXME: We should reconcile the initialization of viewport arguments between iOS and non-IOS. |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 4136 | #if !PLATFORM(IOS_FAMILY) |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4137 | FloatSize viewportSize = page->chrome().pageRect().size(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 4138 | FloatRect windowRect = page->chrome().windowRect(); |
andersca@apple.com | c1242ad | 2015-08-13 17:37:27 +0000 | [diff] [blame] | 4139 | if (features.x) |
| 4140 | windowRect.setX(*features.x); |
| 4141 | if (features.y) |
| 4142 | windowRect.setY(*features.y); |
clopez@igalia.com | 6251d34 | 2020-04-16 11:22:51 +0000 | [diff] [blame] | 4143 | // Zero width and height mean using default size, not minimum one. |
andersca@apple.com | c1242ad | 2015-08-13 17:37:27 +0000 | [diff] [blame] | 4144 | if (features.width && *features.width) |
| 4145 | windowRect.setWidth(*features.width + (windowRect.width() - viewportSize.width())); |
| 4146 | if (features.height && *features.height) |
| 4147 | windowRect.setHeight(*features.height + (windowRect.height() - viewportSize.height())); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4148 | |
clopez@igalia.com | 6251d34 | 2020-04-16 11:22:51 +0000 | [diff] [blame] | 4149 | #if PLATFORM(GTK) |
| 4150 | FloatRect oldWindowRect = oldPage->chrome().windowRect(); |
| 4151 | // Use the size of the previous window if there is no default size. |
| 4152 | if (!windowRect.width()) |
| 4153 | windowRect.setWidth(oldWindowRect.width()); |
| 4154 | if (!windowRect.height()) |
| 4155 | windowRect.setHeight(oldWindowRect.height()); |
| 4156 | #endif |
| 4157 | |
kenneth@webkit.org | dc092f7 | 2012-11-14 11:05:20 +0000 | [diff] [blame] | 4158 | // Ensure non-NaN values, minimum size as well as being within valid screen area. |
darin@apple.com | 9ace801 | 2017-01-23 06:24:18 +0000 | [diff] [blame] | 4159 | FloatRect newWindowRect = DOMWindow::adjustWindowRect(*page, windowRect); |
kenneth@webkit.org | dc092f7 | 2012-11-14 11:05:20 +0000 | [diff] [blame] | 4160 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4161 | if (!frame->page()) |
| 4162 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4163 | page->chrome().setWindowRect(newWindowRect); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 4164 | #else |
| 4165 | // On iOS, width and height refer to the viewport dimensions. |
| 4166 | ViewportArguments arguments; |
| 4167 | // Zero width and height mean using default size, not minimum one. |
andersca@apple.com | c1242ad | 2015-08-13 17:37:27 +0000 | [diff] [blame] | 4168 | if (features.width && *features.width) |
| 4169 | arguments.width = *features.width; |
| 4170 | if (features.height && *features.height) |
| 4171 | arguments.height = *features.height; |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4172 | frame->setViewportArguments(arguments); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 4173 | #endif |
| 4174 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4175 | if (!frame->page()) |
| 4176 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4177 | page->chrome().show(); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4178 | |
| 4179 | created = true; |
aestes@apple.com | 2038dcb | 2015-12-28 16:26:24 +0000 | [diff] [blame] | 4180 | return frame; |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4181 | } |
| 4182 | |
timothy_horton@apple.com | 57a2221 | 2017-10-19 20:43:41 +0000 | [diff] [blame] | 4183 | bool FrameLoader::shouldSuppressTextInputFromEditing() const |
aestes@apple.com | 54c9cf5 | 2016-12-16 23:10:56 +0000 | [diff] [blame] | 4184 | { |
timothy_horton@apple.com | 57a2221 | 2017-10-19 20:43:41 +0000 | [diff] [blame] | 4185 | return m_frame.settings().shouldSuppressTextInputFromEditingDuringProvisionalNavigation() && m_state == FrameStateProvisional; |
aestes@apple.com | 54c9cf5 | 2016-12-16 23:10:56 +0000 | [diff] [blame] | 4186 | } |
| 4187 | |
commit-queue@webkit.org | 9529858 | 2020-04-17 07:52:00 +0000 | [diff] [blame] | 4188 | bool FrameLoader::arePluginsEnabled() |
| 4189 | { |
| 4190 | return m_frame.settings().arePluginsEnabled(); |
| 4191 | } |
| 4192 | |
ggaren | 58e230c | 2006-11-12 04:53:17 +0000 | [diff] [blame] | 4193 | } // namespace WebCore |
krollin@apple.com | f26b56e | 2020-02-28 19:43:33 +0000 | [diff] [blame] | 4194 | |
| 4195 | #undef PAGE_ID |
| 4196 | #undef FRAME_ID |