darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 1 | /* |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 2 | * Copyright (C) 2006-2018 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" |
bfulgham@apple.com | be0ac72 | 2019-05-20 00:48:59 +0000 | [diff] [blame] | 51 | #include "CustomHeaderFields.h" |
aroben@apple.com | 92cfa90 | 2008-04-16 19:19:00 +0000 | [diff] [blame] | 52 | #include "DOMWindow.h" |
mark.lam@apple.com | 45beb07 | 2012-12-12 23:04:20 +0000 | [diff] [blame] | 53 | #include "DatabaseManager.h" |
jer.noble@apple.com | 9e0f060 | 2014-11-22 05:27:16 +0000 | [diff] [blame] | 54 | #include "DiagnosticLoggingClient.h" |
eric.carlson@apple.com | 77b4a11 | 2014-10-30 19:04:29 +0000 | [diff] [blame] | 55 | #include "DiagnosticLoggingKeys.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 56 | #include "Document.h" |
darin | c111655 | 2006-10-30 20:05:39 +0000 | [diff] [blame] | 57 | #include "DocumentLoader.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 58 | #include "Editor.h" |
andersca | f623201 | 2006-11-15 00:36:50 +0000 | [diff] [blame] | 59 | #include "EditorClient.h" |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 60 | #include "Element.h" |
darin | f1bb004 | 2006-12-01 22:46:21 +0000 | [diff] [blame] | 61 | #include "Event.h" |
weinig@apple.com | 13d777f | 2013-04-16 21:54:22 +0000 | [diff] [blame] | 62 | #include "EventHandler.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 63 | #include "EventNames.h" |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 64 | #include "FloatRect.h" |
darin | c111655 | 2006-10-30 20:05:39 +0000 | [diff] [blame] | 65 | #include "FormState.h" |
dglazkov@chromium.org | 25a57e5 | 2010-06-20 21:00:35 +0000 | [diff] [blame] | 66 | #include "FormSubmission.h" |
cdumez@apple.com | c518f7e | 2018-04-03 18:01:41 +0000 | [diff] [blame] | 67 | #include "Frame.h" |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 68 | #include "FrameLoadRequest.h" |
| 69 | #include "FrameLoaderClient.h" |
diegohcg@webkit.org | 838e0a2 | 2010-09-04 14:48:30 +0000 | [diff] [blame] | 70 | #include "FrameNetworkingContext.h" |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 71 | #include "FrameTree.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 72 | #include "FrameView.h" |
akling@apple.com | af7f33b | 2016-02-06 17:00:30 +0000 | [diff] [blame] | 73 | #include "GCController.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 74 | #include "HTMLFormElement.h" |
commit-queue@webkit.org | e5739ca | 2012-11-15 19:39:50 +0000 | [diff] [blame] | 75 | #include "HTMLInputElement.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 76 | #include "HTMLNames.h" |
| 77 | #include "HTMLObjectElement.h" |
commit-queue@webkit.org | 26a3a09 | 2012-10-18 19:53:58 +0000 | [diff] [blame] | 78 | #include "HTMLParserIdioms.h" |
andersca@apple.com | a96cf71 | 2014-06-14 17:49:44 +0000 | [diff] [blame] | 79 | #include "HTTPHeaderNames.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 "SVGDocument.h" |
| 108 | #include "SVGLocatable.h" |
| 109 | #include "SVGNames.h" |
ossy@webkit.org | 66d8c0a | 2014-02-05 11:42:35 +0000 | [diff] [blame] | 110 | #include "SVGViewElement.h" |
| 111 | #include "SVGViewSpec.h" |
weinig@apple.com | 7909900 | 2008-11-21 05:51:28 +0000 | [diff] [blame] | 112 | #include "ScriptController.h" |
darin@chromium.org | 6b41247 | 2008-11-24 23:07:38 +0000 | [diff] [blame] | 113 | #include "ScriptSourceCode.h" |
vsevik@chromium.org | 53bb069 | 2012-01-18 20:59:10 +0000 | [diff] [blame] | 114 | #include "ScrollAnimator.h" |
weinig | e06430a | 2007-10-19 20:53:22 +0000 | [diff] [blame] | 115 | #include "SecurityOrigin.h" |
abarth@webkit.org | eea9066 | 2011-11-09 07:58:49 +0000 | [diff] [blame] | 116 | #include "SecurityPolicy.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 117 | #include "SegmentedString.h" |
yurys@chromium.org | 832b914 | 2010-08-05 12:36:31 +0000 | [diff] [blame] | 118 | #include "SerializedScriptValue.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 119 | #include "Settings.h" |
cdumez@apple.com | fdb8971 | 2018-06-11 20:52:31 +0000 | [diff] [blame] | 120 | #include "ShouldTreatAsContinuingLoad.h" |
rniwa@webkit.org | 77c6570 | 2019-08-13 05:18:11 +0000 | [diff] [blame] | 121 | #include "StyleTreeResolver.h" |
akling@apple.com | 7f81b1e | 2013-09-06 17:23:03 +0000 | [diff] [blame] | 122 | #include "SubframeLoader.h" |
dbates@webkit.org | 3c1f25a | 2018-02-07 18:56:02 +0000 | [diff] [blame] | 123 | #include "SubresourceLoader.h" |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 124 | #include "TextResourceDecoder.h" |
beidson@apple.com | e3ea01d | 2015-07-02 18:33:23 +0000 | [diff] [blame] | 125 | #include "UserContentController.h" |
commit-queue@webkit.org | 635dbdc | 2017-11-23 19:36:08 +0000 | [diff] [blame] | 126 | #include "UserGestureIndicator.h" |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 127 | #include "WindowFeatures.h" |
| 128 | #include "XMLDocumentParser.h" |
commit-queue@webkit.org | 1d99293 | 2018-09-11 17:14:07 +0000 | [diff] [blame] | 129 | #include <dom/ScriptDisallowedScope.h> |
achristensen@apple.com | ce5520e | 2017-09-25 22:33:19 +0000 | [diff] [blame] | 130 | #include <wtf/CompletionHandler.h> |
keith_miller@apple.com | bb2f61c | 2018-12-01 03:28:36 +0000 | [diff] [blame] | 131 | #include <wtf/URL.h> |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 132 | #include <wtf/Ref.h> |
beidson@apple.com | 1c9022b | 2018-03-21 00:05:58 +0000 | [diff] [blame] | 133 | #include <wtf/SetForScope.h> |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 134 | #include <wtf/StdLibExtras.h> |
simon.fraser@apple.com | 83325b9 | 2017-03-17 00:47:16 +0000 | [diff] [blame] | 135 | #include <wtf/SystemTracing.h> |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 136 | #include <wtf/text/CString.h> |
zimmermann@webkit.org | b5e11e6 | 2011-05-16 07:56:06 +0000 | [diff] [blame] | 137 | #include <wtf/text/WTFString.h> |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 138 | |
jcivelli@chromium.org | c2019dd | 2011-05-24 19:32:03 +0000 | [diff] [blame] | 139 | #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
jeremy@chromium.org | c4b86e3 | 2011-02-13 20:28:39 +0000 | [diff] [blame] | 140 | #include "Archive.h" |
jeremy@chromium.org | c4b86e3 | 2011-02-13 20:28:39 +0000 | [diff] [blame] | 141 | #endif |
| 142 | |
enrica@apple.com | 53b08e5 | 2016-01-19 22:58:59 +0000 | [diff] [blame] | 143 | #if ENABLE(DATA_DETECTION) |
| 144 | #include "DataDetection.h" |
| 145 | #endif |
| 146 | |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 147 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 148 | #include "DocumentType.h" |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 149 | #include "ResourceLoader.h" |
cdumez@apple.com | 0b0e88f | 2016-03-06 03:28:54 +0000 | [diff] [blame] | 150 | #include "RuntimeApplicationChecks.h" |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 151 | #endif |
loislo@chromium.org | 82b9dde | 2012-09-12 13:16:31 +0000 | [diff] [blame] | 152 | |
krollin@apple.com | d54b5d7 | 2016-09-12 18:59:32 +0000 | [diff] [blame] | 153 | #define RELEASE_LOG_IF_ALLOWED(fmt, ...) RELEASE_LOG_IF(isAlwaysOnLoggingAllowed(), Network, "%p - FrameLoader::" fmt, this, ##__VA_ARGS__) |
commit-queue@webkit.org | 6d63522 | 2016-03-08 06:44:59 +0000 | [diff] [blame] | 154 | |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 155 | namespace WebCore { |
| 156 | |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 157 | using namespace HTMLNames; |
oliver | b64e408 | 2007-10-12 13:13:51 +0000 | [diff] [blame] | 158 | using namespace SVGNames; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 159 | |
commit-queue@webkit.org | ff400aa | 2011-03-10 23:43:48 +0000 | [diff] [blame] | 160 | static const char defaultAcceptHeader[] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; |
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 | |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 213 | struct ForbidPromptsScope { |
| 214 | ForbidPromptsScope(Page* page) : m_page(page) |
| 215 | { |
| 216 | if (!m_page) |
| 217 | return; |
| 218 | m_page->forbidPrompts(); |
| 219 | } |
| 220 | |
| 221 | ~ForbidPromptsScope() |
| 222 | { |
| 223 | if (!m_page) |
| 224 | return; |
| 225 | m_page->allowPrompts(); |
| 226 | } |
| 227 | |
| 228 | Page* m_page; |
| 229 | }; |
| 230 | |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 231 | class FrameLoader::FrameProgressTracker { |
cdumez@apple.com | a738a88 | 2016-04-19 18:39:09 +0000 | [diff] [blame] | 232 | WTF_MAKE_FAST_ALLOCATED; |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 233 | public: |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 234 | explicit FrameProgressTracker(Frame& frame) |
| 235 | : m_frame(frame) |
| 236 | , m_inProgress(false) |
| 237 | { |
| 238 | } |
| 239 | |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 240 | ~FrameProgressTracker() |
| 241 | { |
jpfau@apple.com | 7907c6b | 2014-10-28 22:38:44 +0000 | [diff] [blame] | 242 | if (m_inProgress && m_frame.page()) |
andersca@apple.com | cd08879 | 2014-01-10 07:19:29 +0000 | [diff] [blame] | 243 | m_frame.page()->progress().progressCompleted(m_frame); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | void progressStarted() |
| 247 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 248 | ASSERT(m_frame.page()); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 249 | if (!m_inProgress) |
andersca@apple.com | cd08879 | 2014-01-10 07:19:29 +0000 | [diff] [blame] | 250 | m_frame.page()->progress().progressStarted(m_frame); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 251 | m_inProgress = true; |
| 252 | } |
| 253 | |
| 254 | void progressCompleted() |
| 255 | { |
| 256 | ASSERT(m_inProgress); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 257 | ASSERT(m_frame.page()); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 258 | m_inProgress = false; |
andersca@apple.com | cd08879 | 2014-01-10 07:19:29 +0000 | [diff] [blame] | 259 | m_frame.page()->progress().progressCompleted(m_frame); |
cdumez@apple.com | c2b1e2a | 2019-09-04 03:13:45 +0000 | [diff] [blame] | 260 | platformStrategies()->loaderStrategy()->pageLoadCompleted(*m_frame.page()); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | private: |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 264 | Frame& m_frame; |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 265 | bool m_inProgress; |
| 266 | }; |
| 267 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 268 | FrameLoader::FrameLoader(Frame& frame, FrameLoaderClient& client) |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 269 | : m_frame(frame) |
ggaren | 1b09a12 | 2006-11-29 06:11:14 +0000 | [diff] [blame] | 270 | , m_client(client) |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 271 | , m_policyChecker(makeUnique<PolicyChecker>(frame)) |
| 272 | , m_history(makeUnique<HistoryController>(frame)) |
akling@apple.com | 654fd9a | 2013-10-06 21:07:29 +0000 | [diff] [blame] | 273 | , m_notifier(frame) |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 274 | , m_subframeLoader(makeUnique<SubframeLoader>(frame)) |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 275 | , m_mixedContentChecker(frame) |
japhet@chromium.org | ce6c1ba | 2012-11-28 19:30:48 +0000 | [diff] [blame] | 276 | , m_state(FrameStateProvisional) |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 277 | , m_loadType(FrameLoadType::Standard) |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 278 | , m_quickRedirectComing(false) |
| 279 | , m_sentRedirectNotification(false) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 280 | , m_inStopAllLoaders(false) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 281 | , m_isExecutingJavaScriptFormAction(false) |
japhet@chromium.org | ce6c1ba | 2012-11-28 19:30:48 +0000 | [diff] [blame] | 282 | , m_didCallImplicitClose(true) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 283 | , m_wasUnloadEventEmitted(false) |
| 284 | , m_isComplete(false) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 285 | , m_needsClear(false) |
andersca@apple.com | 574a745 | 2014-11-21 20:10:13 +0000 | [diff] [blame] | 286 | , m_checkTimer(*this, &FrameLoader::checkTimerFired) |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 287 | , m_shouldCallCheckCompleted(false) |
| 288 | , m_shouldCallCheckLoadComplete(false) |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 289 | , m_opener(nullptr) |
beidson@apple.com | ac095c0 | 2009-08-18 01:37:56 +0000 | [diff] [blame] | 290 | , m_loadingFromCachedPage(false) |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 291 | , m_currentNavigationHasShownBeforeUnloadConfirmPanel(false) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 292 | , m_loadsSynchronously(false) |
abarth@webkit.org | f2c54c2 | 2010-04-11 06:57:13 +0000 | [diff] [blame] | 293 | , m_forcedSandboxFlags(SandboxNone) |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 294 | { |
| 295 | } |
| 296 | |
| 297 | FrameLoader::~FrameLoader() |
| 298 | { |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 299 | setOpener(nullptr); |
cdumez@apple.com | f6bbf48 | 2019-10-12 19:17:37 +0000 | [diff] [blame] | 300 | detachFromAllOpenedFrames(); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 301 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 302 | m_client.frameLoaderDestroyed(); |
diegohcg@webkit.org | 838e0a2 | 2010-09-04 14:48:30 +0000 | [diff] [blame] | 303 | |
| 304 | if (m_networkingContext) |
| 305 | m_networkingContext->invalidate(); |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 306 | } |
| 307 | |
cdumez@apple.com | f6bbf48 | 2019-10-12 19:17:37 +0000 | [diff] [blame] | 308 | void FrameLoader::detachFromAllOpenedFrames() |
| 309 | { |
| 310 | for (auto& frame : m_openedFrames) |
| 311 | frame->loader().m_opener = nullptr; |
| 312 | m_openedFrames.clear(); |
| 313 | } |
| 314 | |
mrowe@apple.com | 5d92f2a | 2008-09-30 21:04:35 +0000 | [diff] [blame] | 315 | void FrameLoader::init() |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 316 | { |
darin@apple.com | 7300681 | 2011-06-29 20:46:33 +0000 | [diff] [blame] | 317 | // This somewhat odd set of steps gives the frame an initial empty document. |
achristensen@apple.com | ceccd77 | 2018-10-02 20:24:42 +0000 | [diff] [blame] | 318 | setPolicyDocumentLoader(m_client.createDocumentLoader(ResourceRequest(URL({ }, emptyString())), SubstituteData()).ptr()); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 319 | setProvisionalDocumentLoader(m_policyDocumentLoader.get()); |
cdumez@apple.com | a0010ff | 2018-12-13 23:17:44 +0000 | [diff] [blame] | 320 | m_provisionalDocumentLoader->startLoadingMainResource(); |
jpfau@apple.com | ec9eb51 | 2014-07-10 01:13:45 +0000 | [diff] [blame] | 321 | |
| 322 | Ref<Frame> protect(m_frame); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 323 | m_frame.document()->cancelParsing(); |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 324 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocument); |
diegohcg@webkit.org | 838e0a2 | 2010-09-04 14:48:30 +0000 | [diff] [blame] | 325 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 326 | m_networkingContext = m_client.createNetworkingContext(); |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 327 | m_progressTracker = makeUnique<FrameProgressTracker>(m_frame); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 328 | } |
| 329 | |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 330 | void FrameLoader::initForSynthesizedDocument(const URL&) |
| 331 | { |
| 332 | // FIXME: We need to initialize the document URL to the specified URL. Currently the URL is empty and hence |
| 333 | // FrameLoader::checkCompleted() will overwrite the URL of the document to be activeDocumentLoader()->documentURL(). |
| 334 | |
achristensen@apple.com | ceccd77 | 2018-10-02 20:24:42 +0000 | [diff] [blame] | 335 | auto loader = m_client.createDocumentLoader(ResourceRequest(URL({ }, emptyString())), SubstituteData()); |
beidson@apple.com | 10a537f | 2015-07-09 22:30:42 +0000 | [diff] [blame] | 336 | loader->attachToFrame(m_frame); |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 337 | loader->setResponse(ResourceResponse(URL(), "text/html"_s, 0, String())); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 338 | loader->setCommitted(true); |
commit-queue@webkit.org | c7c21c9 | 2017-10-25 21:17:46 +0000 | [diff] [blame] | 339 | setDocumentLoader(loader.ptr()); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 340 | |
| 341 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocument); |
| 342 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocumentPostCommit); |
| 343 | m_stateMachine.advanceTo(FrameLoaderStateMachine::CommittedFirstRealLoad); |
| 344 | m_client.transitionToCommittedForNewPage(); |
| 345 | |
| 346 | m_didCallImplicitClose = true; |
| 347 | m_isComplete = true; |
| 348 | m_state = FrameStateComplete; |
| 349 | m_needsClear = true; |
| 350 | |
| 351 | m_networkingContext = m_client.createNetworkingContext(); |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 352 | m_progressTracker = makeUnique<FrameProgressTracker>(m_frame); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 353 | } |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 354 | |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 355 | void FrameLoader::setDefersLoading(bool defers) |
| 356 | { |
darin | 8207db4 | 2007-02-20 18:18:39 +0000 | [diff] [blame] | 357 | if (m_documentLoader) |
| 358 | m_documentLoader->setDefersLoading(defers); |
| 359 | if (m_provisionalDocumentLoader) |
| 360 | m_provisionalDocumentLoader->setDefersLoading(defers); |
| 361 | if (m_policyDocumentLoader) |
| 362 | m_policyDocumentLoader->setDefersLoading(defers); |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 363 | history().setDefersLoading(defers); |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 364 | |
| 365 | if (!defers) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 366 | m_frame.navigationScheduler().startTimer(); |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 367 | startCheckCompleteTimer(); |
| 368 | } |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 369 | } |
| 370 | |
rniwa@webkit.org | ba12a01 | 2019-02-03 22:48:22 +0000 | [diff] [blame] | 371 | void FrameLoader::checkContentPolicy(const ResourceResponse& response, PolicyCheckIdentifier identifier, ContentPolicyDecisionFunction&& function) |
achristensen@apple.com | b8c49be | 2017-08-23 21:10:09 +0000 | [diff] [blame] | 372 | { |
bfulgham@apple.com | 78e81d9 | 2018-06-25 21:29:50 +0000 | [diff] [blame] | 373 | if (!activeDocumentLoader()) { |
| 374 | // Load was cancelled |
rniwa@webkit.org | ba12a01 | 2019-02-03 22:48:22 +0000 | [diff] [blame] | 375 | function(PolicyAction::Ignore, identifier); |
bfulgham@apple.com | 78e81d9 | 2018-06-25 21:29:50 +0000 | [diff] [blame] | 376 | return; |
| 377 | } |
| 378 | |
rniwa@webkit.org | ba12a01 | 2019-02-03 22:48:22 +0000 | [diff] [blame] | 379 | // FIXME: Validate the policy check identifier. |
commit-queue@webkit.org | a4a9ce2 | 2019-04-10 22:56:35 +0000 | [diff] [blame] | 380 | client().dispatchDecidePolicyForResponse(response, activeDocumentLoader()->request(), identifier, activeDocumentLoader()->downloadAttribute(), WTFMove(function)); |
achristensen@apple.com | b8c49be | 2017-08-23 21:10:09 +0000 | [diff] [blame] | 381 | } |
| 382 | |
dbates@webkit.org | 7f3a982 | 2017-06-22 19:45:10 +0000 | [diff] [blame] | 383 | void FrameLoader::changeLocation(FrameLoadRequest&& request) |
mjs | d40bfee | 2007-07-09 06:29:48 +0000 | [diff] [blame] | 384 | { |
dbates@webkit.org | 7f3a982 | 2017-06-22 19:45:10 +0000 | [diff] [blame] | 385 | urlSelected(WTFMove(request), nullptr); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 386 | } |
| 387 | |
darin@apple.com | 0ce67df | 2019-06-17 01:48:13 +0000 | [diff] [blame] | 388 | void FrameLoader::urlSelected(const URL& url, const String& passedTarget, Event* triggeringEvent, LockHistory lockHistory, LockBackForwardList lockBackForwardList, ShouldSendReferrer shouldSendReferrer, 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] | 389 | { |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 390 | auto* frame = lexicalFrameFromCommonVM(); |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 391 | auto initiatedByMainFrame = frame && frame->isMainFrame() ? InitiatedByMainFrame::Yes : InitiatedByMainFrame::Unknown; |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 392 | |
cdumez@apple.com | 6eda1ab | 2018-12-20 20:23:18 +0000 | [diff] [blame] | 393 | NewFrameOpenerPolicy newFrameOpenerPolicy = openerPolicy.valueOr(shouldSendReferrer == NeverSendReferrer ? NewFrameOpenerPolicy::Suppress : NewFrameOpenerPolicy::Allow); |
wilander@apple.com | 6ffdf8f | 2019-02-06 22:02:15 +0000 | [diff] [blame] | 394 | urlSelected(FrameLoadRequest(*m_frame.document(), m_frame.document()->securityOrigin(), { url }, passedTarget, lockHistory, lockBackForwardList, shouldSendReferrer, AllowNavigationToInvalidURL::Yes, newFrameOpenerPolicy, shouldOpenExternalURLsPolicy, initiatedByMainFrame, DoNotReplaceDocumentIfJavaScriptURL, downloadAttribute, systemPreviewInfo), triggeringEvent, WTFMove(adClickAttribution)); |
bfulgham@apple.com | 8f83154 | 2016-03-31 15:35:41 +0000 | [diff] [blame] | 395 | } |
| 396 | |
wilander@apple.com | 6ffdf8f | 2019-02-06 22:02:15 +0000 | [diff] [blame] | 397 | void FrameLoader::urlSelected(FrameLoadRequest&& frameRequest, Event* triggeringEvent, Optional<AdClickAttribution>&& adClickAttribution) |
cjerdonek@webkit.org | 983777f | 2010-05-17 07:34:12 +0000 | [diff] [blame] | 398 | { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 399 | RELEASE_LOG_IF_ALLOWED("urlSelected: frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 400 | |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 401 | Ref<Frame> protect(m_frame); |
darin@apple.com | 1cf3d56 | 2010-12-07 16:23:03 +0000 | [diff] [blame] | 402 | |
cdumez@apple.com | 6cbf70a | 2019-10-11 20:26:15 +0000 | [diff] [blame] | 403 | if (m_frame.script().executeIfJavaScriptURL(frameRequest.resourceRequest().url(), frameRequest.shouldReplaceDocumentIfJavaScriptURL())) { |
| 404 | m_quickRedirectComing = false; |
weinig@apple.com | 6b00e24 | 2008-01-08 01:30:27 +0000 | [diff] [blame] | 405 | return; |
cdumez@apple.com | 6cbf70a | 2019-10-11 20:26:15 +0000 | [diff] [blame] | 406 | } |
weinig@apple.com | 6b00e24 | 2008-01-08 01:30:27 +0000 | [diff] [blame] | 407 | |
darin@apple.com | 1cf3d56 | 2010-12-07 16:23:03 +0000 | [diff] [blame] | 408 | if (frameRequest.frameName().isEmpty()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 409 | frameRequest.setFrameName(m_frame.document()->baseTarget()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 410 | |
darin@apple.com | 4cd1b24 | 2009-03-27 23:37:46 +0000 | [diff] [blame] | 411 | addHTTPOriginIfNeeded(frameRequest.resourceRequest(), outgoingOrigin()); |
bfulgham@apple.com | b30d7f8 | 2016-06-07 15:47:30 +0000 | [diff] [blame] | 412 | m_frame.document()->contentSecurityPolicy()->upgradeInsecureRequestIfNeeded(frameRequest.resourceRequest(), ContentSecurityPolicy::InsecureRequestType::Navigation); |
darin@apple.com | 4cd1b24 | 2009-03-27 23:37:46 +0000 | [diff] [blame] | 413 | |
wilander@apple.com | 6ffdf8f | 2019-02-06 22:02:15 +0000 | [diff] [blame] | 414 | loadFrameRequest(WTFMove(frameRequest), triggeringEvent, { }, WTFMove(adClickAttribution)); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 415 | } |
| 416 | |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 417 | void FrameLoader::submitForm(Ref<FormSubmission>&& submission) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 418 | { |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 419 | ASSERT(submission->method() == FormSubmission::Method::Post || submission->method() == FormSubmission::Method::Get); |
dglazkov@chromium.org | 25a57e5 | 2010-06-20 21:00:35 +0000 | [diff] [blame] | 420 | |
dglazkov@chromium.org | 996fc22 | 2010-06-21 16:36:40 +0000 | [diff] [blame] | 421 | // FIXME: Find a good spot for these. |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 422 | ASSERT(!submission->state().sourceDocument().frame() || submission->state().sourceDocument().frame() == &m_frame); |
dbates@webkit.org | 2990852 | 2017-01-07 07:14:03 +0000 | [diff] [blame] | 423 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 424 | if (!m_frame.page()) |
adele@apple.com | f3d6b89 | 2008-04-29 01:30:20 +0000 | [diff] [blame] | 425 | return; |
dbates@webkit.org | 2990852 | 2017-01-07 07:14:03 +0000 | [diff] [blame] | 426 | |
dglazkov@chromium.org | 996fc22 | 2010-06-21 16:36:40 +0000 | [diff] [blame] | 427 | if (submission->action().isEmpty()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 428 | return; |
| 429 | |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 430 | if (isDocumentSandboxed(m_frame, SandboxForms)) { |
mkwst@chromium.org | b10ebb43 | 2012-12-04 18:34:27 +0000 | [diff] [blame] | 431 | // 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] | 432 | 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] | 433 | return; |
mkwst@chromium.org | b10ebb43 | 2012-12-04 18:34:27 +0000 | [diff] [blame] | 434 | } |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 435 | |
keith_miller@apple.com | bb2f61c | 2018-12-01 03:28:36 +0000 | [diff] [blame] | 436 | if (WTF::protocolIsJavaScript(submission->action())) { |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 437 | if (!m_frame.document()->contentSecurityPolicy()->allowFormAction(URL(submission->action()))) |
commit-queue@webkit.org | 78e860e | 2012-08-16 12:42:09 +0000 | [diff] [blame] | 438 | return; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 439 | m_isExecutingJavaScriptFormAction = true; |
ap@apple.com | e6afcb6 | 2014-04-20 19:02:13 +0000 | [diff] [blame] | 440 | Ref<Frame> protect(m_frame); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 441 | m_frame.script().executeIfJavaScriptURL(submission->action(), DoNotReplaceDocumentIfJavaScriptURL); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 442 | m_isExecutingJavaScriptFormAction = false; |
| 443 | return; |
| 444 | } |
| 445 | |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 446 | Frame* targetFrame = findFrameForNavigation(submission->target(), &submission->state().sourceDocument()); |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 447 | if (!targetFrame) { |
commit-queue@webkit.org | 635dbdc | 2017-11-23 19:36:08 +0000 | [diff] [blame] | 448 | if (!DOMWindow::allowPopUp(m_frame) && !UserGestureIndicator::processingUserGesture()) |
abarth@webkit.org | c72185c | 2010-04-09 06:43:19 +0000 | [diff] [blame] | 449 | return; |
| 450 | |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 451 | // FIXME: targetFrame can be null for two distinct reasons: |
ap@apple.com | f8c414e | 2013-08-13 03:44:57 +0000 | [diff] [blame] | 452 | // 1. The frame was not found by name, so we should try opening a new window. |
| 453 | // 2. The frame was found, but navigating it was not allowed, e.g. by HTML5 sandbox or by origin checks. |
| 454 | // Continuing form submission makes no sense in the latter case. |
| 455 | // There is a repeat check after timer fires, so this is not a correctness issue. |
| 456 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 457 | targetFrame = &m_frame; |
dglazkov@chromium.org | 996fc22 | 2010-06-21 16:36:40 +0000 | [diff] [blame] | 458 | } else |
| 459 | submission->clearTarget(); |
| 460 | |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 461 | if (!targetFrame->page()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 462 | return; |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 463 | |
| 464 | // FIXME: We'd like to remove this altogether and fix the multiple form submission issue another way. |
| 465 | |
| 466 | // We do not want to submit more than one form from the same page, nor do we want to submit a single |
| 467 | // form more than once. This flag prevents these from happening; not sure how other browsers prevent this. |
ggaren@apple.com | 7a176e1 | 2015-11-12 01:48:27 +0000 | [diff] [blame] | 468 | // The flag is reset in each time we start dispatching a new mouse or key down event, and |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 469 | // also in setView since this part may get reused for a page from the back/forward cache. |
| 470 | // The form multi-submit logic here is only needed when we are submitting a form that affects this frame. |
| 471 | |
| 472 | // FIXME: Frame targeting is only one of the ways the submission could end up doing something other |
| 473 | // than replacing this frame's content, so this check is flawed. On the other hand, the check is hardly |
| 474 | // needed any more now that we reset m_submittedFormURL on each mouse or key down event. |
| 475 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 476 | if (m_frame.tree().isDescendantOf(targetFrame)) { |
commit-queue@webkit.org | 4396405 | 2012-08-13 19:30:15 +0000 | [diff] [blame] | 477 | if (m_submittedFormURL == submission->requestURL()) |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 478 | return; |
commit-queue@webkit.org | 4396405 | 2012-08-13 19:30:15 +0000 | [diff] [blame] | 479 | m_submittedFormURL = submission->requestURL(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 480 | } |
| 481 | |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 482 | submission->setReferrer(outgoingReferrer()); |
dglazkov@chromium.org | 996fc22 | 2010-06-21 16:36:40 +0000 | [diff] [blame] | 483 | submission->setOrigin(outgoingOrigin()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 484 | |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 485 | targetFrame->navigationScheduler().scheduleFormSubmission(WTFMove(submission)); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 486 | } |
| 487 | |
commit-queue@webkit.org | fc5833b | 2011-02-23 06:58:46 +0000 | [diff] [blame] | 488 | void FrameLoader::stopLoading(UnloadEventPolicy unloadEventPolicy) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 489 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 490 | if (m_frame.document() && m_frame.document()->parser()) |
| 491 | m_frame.document()->parser()->stopParsing(); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 492 | |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 493 | if (unloadEventPolicy != UnloadEventPolicyNone) |
ggaren@apple.com | 7a176e1 | 2015-11-12 01:48:27 +0000 | [diff] [blame] | 494 | dispatchUnloadEvents(unloadEventPolicy); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 495 | |
darin@apple.com | 4d9d718 | 2009-09-23 00:38:04 +0000 | [diff] [blame] | 496 | m_isComplete = true; // to avoid calling completed() in finishedParsing() |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 497 | m_didCallImplicitClose = true; // don't want that one either |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 498 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 499 | if (m_frame.document() && m_frame.document()->parsing()) { |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 500 | finishedParsing(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 501 | m_frame.document()->setParsing(false); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 502 | } |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 503 | |
darin@apple.com | 389af86 | 2016-11-14 03:22:31 +0000 | [diff] [blame] | 504 | if (auto* document = m_frame.document()) { |
mark.lam@apple.com | 45beb07 | 2012-12-12 23:04:20 +0000 | [diff] [blame] | 505 | // 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] | 506 | DatabaseManager::singleton().stopDatabases(*document, nullptr); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 507 | } |
| 508 | |
cdumez@apple.com | 2d8d608 | 2018-02-27 21:47:57 +0000 | [diff] [blame] | 509 | policyChecker().stopCheck(); |
| 510 | |
ap@apple.com | 3f0a0a1 | 2010-06-24 23:58:36 +0000 | [diff] [blame] | 511 | // 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] | 512 | m_frame.navigationScheduler().cancel(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | void FrameLoader::stop() |
| 516 | { |
| 517 | // http://bugs.webkit.org/show_bug.cgi?id=10854 |
| 518 | // 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] | 519 | Ref<Frame> protect(m_frame); |
abarth@webkit.org | fd91290 | 2011-06-10 21:16:20 +0000 | [diff] [blame] | 520 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 521 | if (DocumentParser* parser = m_frame.document()->parser()) { |
abarth@webkit.org | fd91290 | 2011-06-10 21:16:20 +0000 | [diff] [blame] | 522 | parser->stopParsing(); |
| 523 | parser->finish(); |
| 524 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 525 | } |
| 526 | |
ap@apple.com | e042b63 | 2013-05-17 20:04:43 +0000 | [diff] [blame] | 527 | void FrameLoader::willTransitionToCommitted() |
| 528 | { |
| 529 | // This function is called when a frame is still fully in place (not cached, not detached), but will be replaced. |
| 530 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 531 | if (m_frame.editor().hasComposition()) { |
ap@apple.com | e042b63 | 2013-05-17 20:04:43 +0000 | [diff] [blame] | 532 | // The text was already present in DOM, so it's better to confirm than to cancel the composition. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 533 | m_frame.editor().confirmComposition(); |
ap@apple.com | c985136 | 2014-12-11 17:23:34 +0000 | [diff] [blame] | 534 | if (EditorClient* editorClient = m_frame.editor().client()) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 535 | editorClient->respondToChangedSelection(&m_frame); |
ap@apple.com | c985136 | 2014-12-11 17:23:34 +0000 | [diff] [blame] | 536 | editorClient->discardedComposition(&m_frame); |
| 537 | } |
ap@apple.com | e042b63 | 2013-05-17 20:04:43 +0000 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 541 | bool FrameLoader::closeURL() |
| 542 | { |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 543 | history().saveDocumentState(); |
stavila@adobe.com | eb50d7c | 2014-12-17 10:14:32 +0000 | [diff] [blame] | 544 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 545 | Document* currentDocument = m_frame.document(); |
stavila@adobe.com | eb50d7c | 2014-12-17 10:14:32 +0000 | [diff] [blame] | 546 | UnloadEventPolicy unloadEventPolicy; |
| 547 | if (m_frame.page() && m_frame.page()->chrome().client().isSVGImageChromeClient()) { |
| 548 | // If this is the SVGDocument of an SVGImage, no need to dispatch events or recalcStyle. |
| 549 | unloadEventPolicy = UnloadEventPolicyNone; |
| 550 | } else { |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 551 | // Should only send the pagehide event here if the current document exists and has not been placed in the back/forward cache. |
| 552 | unloadEventPolicy = currentDocument && currentDocument->backForwardCacheState() == Document::NotInBackForwardCache ? UnloadEventPolicyUnloadAndPageHide : UnloadEventPolicyUnloadOnly; |
stavila@adobe.com | eb50d7c | 2014-12-17 10:14:32 +0000 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | stopLoading(unloadEventPolicy); |
beidson@apple.com | 212b784 | 2009-09-03 00:55:18 +0000 | [diff] [blame] | 556 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 557 | m_frame.editor().clearUndoRedoOperations(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 558 | return true; |
| 559 | } |
| 560 | |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 561 | bool FrameLoader::didOpenURL() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 562 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 563 | if (m_frame.navigationScheduler().redirectScheduledDuringLoad()) { |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 564 | // A redirect was scheduled before the document was created. |
| 565 | // This can happen when one frame changes another frame's location. |
| 566 | return false; |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 567 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 568 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 569 | m_frame.navigationScheduler().cancel(); |
| 570 | m_frame.editor().clearLastEditCommand(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 571 | |
| 572 | m_isComplete = false; |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 573 | m_didCallImplicitClose = false; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 574 | |
ap@webkit.org | fbfb0f9 | 2009-05-08 07:58:08 +0000 | [diff] [blame] | 575 | // If we are still in the process of initializing an empty document then |
| 576 | // its frame is not in a consistent state for rendering, so avoid setJSStatusBarText |
| 577 | // since it may cause clients to attempt to render the frame. |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 578 | if (!m_stateMachine.creatingInitialEmptyDocument()) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 579 | DOMWindow* window = m_frame.document()->domWindow(); |
abarth@webkit.org | 13fe1e2 | 2012-08-16 22:29:48 +0000 | [diff] [blame] | 580 | window->setStatus(String()); |
| 581 | window->setDefaultStatus(String()); |
ap@webkit.org | fbfb0f9 | 2009-05-08 07:58:08 +0000 | [diff] [blame] | 582 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 583 | |
| 584 | started(); |
| 585 | |
| 586 | return true; |
| 587 | } |
| 588 | |
ap@webkit.org | a0a1987 | 2008-02-05 09:34:18 +0000 | [diff] [blame] | 589 | void FrameLoader::didExplicitOpen() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 590 | { |
| 591 | m_isComplete = false; |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 592 | m_didCallImplicitClose = false; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 593 | |
andersca@apple.com | 1752dba | 2007-12-14 22:06:50 +0000 | [diff] [blame] | 594 | // Calling document.open counts as committing the first real document load. |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 595 | if (!m_stateMachine.committedFirstRealDocumentLoad()) |
| 596 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocumentPostCommit); |
cdumez@apple.com | 0af95e3 | 2019-04-16 23:07:35 +0000 | [diff] [blame] | 597 | |
| 598 | m_client.dispatchDidExplicitOpen(m_frame.document() ? m_frame.document()->url() : URL()); |
andersca@apple.com | 1752dba | 2007-12-14 22:06:50 +0000 | [diff] [blame] | 599 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 600 | // Prevent window.open(url) -- eg window.open("about:blank") -- from blowing away results |
| 601 | // from a subsequent window.document.open / window.document.write call. |
dbates@webkit.org | ef42d38 | 2010-01-25 19:20:06 +0000 | [diff] [blame] | 602 | // Canceling redirection here works for all cases because document.open |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 603 | // implicitly precedes document.write. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 604 | m_frame.navigationScheduler().cancel(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 605 | } |
| 606 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 607 | |
| 608 | void FrameLoader::cancelAndClear() |
| 609 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 610 | m_frame.navigationScheduler().cancel(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 611 | |
| 612 | if (!m_isComplete) |
| 613 | closeURL(); |
| 614 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 615 | clear(m_frame.document(), false); |
| 616 | m_frame.script().updatePlatformScriptObjects(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 617 | } |
| 618 | |
aestes@apple.com | 408782b | 2016-11-29 18:40:55 +0000 | [diff] [blame] | 619 | static inline bool shouldClearWindowName(const Frame& frame, const Document& newDocument) |
| 620 | { |
| 621 | if (!frame.isMainFrame()) |
| 622 | return false; |
| 623 | |
| 624 | if (frame.loader().opener()) |
| 625 | return false; |
| 626 | |
akling@apple.com | 6be0e97 | 2017-01-18 19:35:49 +0000 | [diff] [blame] | 627 | return !newDocument.securityOrigin().isSameOriginAs(frame.document()->securityOrigin()); |
aestes@apple.com | 408782b | 2016-11-29 18:40:55 +0000 | [diff] [blame] | 628 | } |
| 629 | |
beidson@apple.com | dc5cfa4 | 2019-07-01 20:29:20 +0000 | [diff] [blame] | 630 | 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] | 631 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 632 | m_frame.editor().clear(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 633 | |
beidson@apple.com | dc5cfa4 | 2019-07-01 20:29:20 +0000 | [diff] [blame] | 634 | bool neededClear = m_needsClear; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 635 | m_needsClear = false; |
beidson@apple.com | dc5cfa4 | 2019-07-01 20:29:20 +0000 | [diff] [blame] | 636 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 637 | if (neededClear && m_frame.document()->backForwardCacheState() != Document::InBackForwardCache) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 638 | m_frame.document()->cancelParsing(); |
| 639 | m_frame.document()->stopActiveDOMObjects(); |
timothy_horton@apple.com | 70d58d8 | 2014-07-26 18:45:04 +0000 | [diff] [blame] | 640 | bool hadLivingRenderTree = m_frame.document()->hasLivingRenderTree(); |
| 641 | m_frame.document()->prepareForDestruction(); |
| 642 | if (hadLivingRenderTree) |
simon.fraser@apple.com | 87cf166 | 2018-09-08 20:19:22 +0000 | [diff] [blame] | 643 | m_frame.document()->adjustFocusedNodeOnNodeRemoval(*m_frame.document()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 644 | } |
| 645 | |
beidson@apple.com | dc5cfa4 | 2019-07-01 20:29:20 +0000 | [diff] [blame] | 646 | if (handleDOMWindowCreation) |
| 647 | handleDOMWindowCreation(); |
| 648 | |
| 649 | if (!neededClear) |
| 650 | return; |
| 651 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 652 | // Do this after detaching the document so that the unload event works. |
thatcher | a1e24df | 2007-09-14 23:53:29 +0000 | [diff] [blame] | 653 | if (clearWindowProperties) { |
commit-queue@webkit.org | 8599a76 | 2016-11-01 21:42:51 +0000 | [diff] [blame] | 654 | InspectorInstrumentation::frameWindowDiscarded(m_frame, m_frame.document()->domWindow()); |
commit-queue@webkit.org | 8af5d21 | 2015-12-01 01:55:43 +0000 | [diff] [blame] | 655 | m_frame.document()->domWindow()->resetUnlessSuspendedForDocumentSuspension(); |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 656 | 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] | 657 | |
| 658 | if (shouldClearWindowName(m_frame, *newDocument)) |
utatane.tea@gmail.com | c4579a0 | 2017-07-07 04:42:04 +0000 | [diff] [blame] | 659 | m_frame.tree().setName(nullAtom()); |
weinig | f930763 | 2007-07-18 05:40:54 +0000 | [diff] [blame] | 660 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 661 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 662 | m_frame.selection().prepareForDestruction(); |
achristensen@apple.com | 09e70aa | 2017-04-27 16:42:13 +0000 | [diff] [blame] | 663 | m_frame.eventHandler().clear(); |
bfulgham@apple.com | 46bde7c | 2016-04-07 21:15:34 +0000 | [diff] [blame] | 664 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 665 | if (clearFrameView && m_frame.view()) |
| 666 | m_frame.view()->clear(); |
eric@webkit.org | 0683d94 | 2008-08-06 10:01:35 +0000 | [diff] [blame] | 667 | |
eric@webkit.org | 0683d94 | 2008-08-06 10:01:35 +0000 | [diff] [blame] | 668 | // Do not drop the document before the ScriptController and view are cleared |
| 669 | // as some destructors might still try to access the document. |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 670 | m_frame.setDocument(nullptr); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 671 | |
akling@apple.com | 7f81b1e | 2013-09-06 17:23:03 +0000 | [diff] [blame] | 672 | subframeLoader().clear(); |
eric@webkit.org | 0683d94 | 2008-08-06 10:01:35 +0000 | [diff] [blame] | 673 | |
bfulgham@apple.com | 472a034 | 2017-01-04 22:35:44 +0000 | [diff] [blame] | 674 | if (clearWindowProperties) |
cdumez@apple.com | 87a798a | 2018-04-19 04:02:30 +0000 | [diff] [blame] | 675 | m_frame.windowProxy().setDOMWindow(newDocument->domWindow()); |
bfulgham@apple.com | 472a034 | 2017-01-04 22:35:44 +0000 | [diff] [blame] | 676 | |
antti | 90500a3 | 2007-09-27 23:56:17 +0000 | [diff] [blame] | 677 | if (clearScriptObjects) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 678 | m_frame.script().clearScriptObjects(); |
eric@webkit.org | 0683d94 | 2008-08-06 10:01:35 +0000 | [diff] [blame] | 679 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 680 | m_frame.script().enableEval(); |
abarth@webkit.org | 9d220b6 | 2012-06-09 19:35:02 +0000 | [diff] [blame] | 681 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 682 | m_frame.navigationScheduler().clear(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 683 | |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 684 | m_checkTimer.stop(); |
| 685 | m_shouldCallCheckCompleted = false; |
| 686 | m_shouldCallCheckLoadComplete = false; |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 687 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 688 | if (m_stateMachine.isDisplayingInitialEmptyDocument() && m_stateMachine.committedFirstRealDocumentLoad()) |
| 689 | m_stateMachine.advanceTo(FrameLoaderStateMachine::CommittedFirstRealLoad); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | void FrameLoader::receivedFirstData() |
| 693 | { |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 694 | dispatchDidCommitLoad(WTF::nullopt); |
jcivelli@chromium.org | 4b94add | 2011-11-19 08:45:01 +0000 | [diff] [blame] | 695 | dispatchDidClearWindowObjectsInAllWorlds(); |
beidson@apple.com | 2a75a96 | 2012-04-24 18:12:55 +0000 | [diff] [blame] | 696 | dispatchGlobalObjectAvailableInAllWorlds(); |
jcivelli@chromium.org | 4b94add | 2011-11-19 08:45:01 +0000 | [diff] [blame] | 697 | |
darin | 8207db4 | 2007-02-20 18:18:39 +0000 | [diff] [blame] | 698 | if (!m_documentLoader) |
| 699 | return; |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 700 | |
dbates@webkit.org | 6602466 | 2018-02-03 04:53:47 +0000 | [diff] [blame] | 701 | auto& documentLoader = *m_documentLoader; |
| 702 | auto& title = documentLoader.title(); |
| 703 | if (!title.string.isNull()) |
| 704 | m_client.dispatchDidReceiveTitle(title); |
| 705 | |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 706 | ASSERT(m_frame.document()); |
| 707 | auto& document = *m_frame.document(); |
| 708 | |
dbates@webkit.org | 6602466 | 2018-02-03 04:53:47 +0000 | [diff] [blame] | 709 | 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] | 710 | |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 711 | double delay; |
darin@apple.com | 47a20cb | 2014-04-27 16:06:27 +0000 | [diff] [blame] | 712 | String urlString; |
cdumez@apple.com | 63b7fdd | 2019-09-12 04:32:29 +0000 | [diff] [blame] | 713 | if (!parseMetaHTTPEquivRefresh(documentLoader.response().httpHeaderField(HTTPHeaderName::Refresh), delay, urlString)) |
ap | e9991d5 | 2006-12-08 18:19:51 +0000 | [diff] [blame] | 714 | return; |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 715 | auto completedURL = urlString.isEmpty() ? document.url() : document.completeURL(urlString); |
keith_miller@apple.com | bb2f61c | 2018-12-01 03:28:36 +0000 | [diff] [blame] | 716 | if (!WTF::protocolIsJavaScript(completedURL)) |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 717 | m_frame.navigationScheduler().scheduleRedirect(document, delay, completedURL); |
ddkilzer@apple.com | 70f1539 | 2014-04-01 19:21:34 +0000 | [diff] [blame] | 718 | else { |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 719 | 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] | 720 | document.addConsoleMessage(MessageSource::Security, MessageLevel::Error, message); |
ddkilzer@apple.com | 70f1539 | 2014-04-01 19:21:34 +0000 | [diff] [blame] | 721 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 722 | } |
| 723 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 724 | void FrameLoader::setOutgoingReferrer(const URL& url) |
japhet@chromium.org | b254c9b | 2011-01-26 19:14:26 +0000 | [diff] [blame] | 725 | { |
levin@chromium.org | 1a2fef4 | 2011-03-01 02:10:28 +0000 | [diff] [blame] | 726 | m_outgoingReferrer = url.strippedForUseAsReferrer(); |
abarth@webkit.org | 412c54e | 2010-04-20 22:12:16 +0000 | [diff] [blame] | 727 | } |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 728 | |
dbates@webkit.org | 123b1af | 2019-09-23 21:56:43 +0000 | [diff] [blame] | 729 | void FrameLoader::didBeginDocument(bool dispatch) |
abarth@webkit.org | 412c54e | 2010-04-20 22:12:16 +0000 | [diff] [blame] | 730 | { |
| 731 | m_needsClear = true; |
| 732 | m_isComplete = false; |
| 733 | m_didCallImplicitClose = false; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 734 | m_frame.document()->setReadyState(Document::Loading); |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 735 | |
| 736 | if (m_pendingStateObject) { |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 737 | m_frame.document()->statePopped(*m_pendingStateObject); |
cdumez@apple.com | d839ea1 | 2015-07-04 19:42:18 +0000 | [diff] [blame] | 738 | m_pendingStateObject = nullptr; |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 739 | } |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 740 | |
andersca@apple.com | 6c6fb4b | 2009-08-12 22:03:02 +0000 | [diff] [blame] | 741 | if (dispatch) |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 742 | dispatchDidClearWindowObjectsInAllWorlds(); |
abarth@webkit.org | 412c54e | 2010-04-20 22:12:16 +0000 | [diff] [blame] | 743 | |
abarth@webkit.org | 622d9df | 2009-05-22 16:44:47 +0000 | [diff] [blame] | 744 | updateFirstPartyForCookies(); |
dbates@webkit.org | 123b1af | 2019-09-23 21:56:43 +0000 | [diff] [blame] | 745 | m_frame.document()->initContentSecurityPolicy(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 746 | |
akling@apple.com | 1c29edbc | 2013-08-23 23:19:21 +0000 | [diff] [blame] | 747 | const Settings& settings = m_frame.settings(); |
cdumez@apple.com | 0bb03ec | 2015-01-28 05:53:53 +0000 | [diff] [blame] | 748 | m_frame.document()->cachedResourceLoader().setImagesEnabled(settings.areImagesEnabled()); |
| 749 | m_frame.document()->cachedResourceLoader().setAutoLoadImages(settings.loadsImagesAutomatically()); |
aroben@apple.com | 3adf245 | 2008-02-07 23:19:31 +0000 | [diff] [blame] | 750 | |
collinj@webkit.org | 9c672f6 | 2008-09-19 04:15:14 +0000 | [diff] [blame] | 751 | if (m_documentLoader) { |
andersca@apple.com | 30391b4 | 2014-06-16 19:26:49 +0000 | [diff] [blame] | 752 | String dnsPrefetchControl = m_documentLoader->response().httpHeaderField(HTTPHeaderName::XDNSPrefetchControl); |
collinj@webkit.org | 9c672f6 | 2008-09-19 04:15:14 +0000 | [diff] [blame] | 753 | if (!dnsPrefetchControl.isEmpty()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 754 | m_frame.document()->parseDNSPrefetchControlHeader(dnsPrefetchControl); |
jochen@chromium.org | adec40f | 2011-02-09 17:03:38 +0000 | [diff] [blame] | 755 | |
dbates@webkit.org | 41f504e | 2018-05-07 17:52:34 +0000 | [diff] [blame] | 756 | 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] | 757 | |
cdumez@apple.com | 7c12c6c | 2018-05-30 21:30:21 +0000 | [diff] [blame] | 758 | String referrerPolicy = m_documentLoader->response().httpHeaderField(HTTPHeaderName::ReferrerPolicy); |
| 759 | if (!referrerPolicy.isNull()) |
| 760 | m_frame.document()->processReferrerPolicy(referrerPolicy, ReferrerPolicySource::HTTPHeader); |
| 761 | |
andersca@apple.com | 30391b4 | 2014-06-16 19:26:49 +0000 | [diff] [blame] | 762 | String headerContentLanguage = m_documentLoader->response().httpHeaderField(HTTPHeaderName::ContentLanguage); |
commit-queue@webkit.org | 26a3a09 | 2012-10-18 19:53:58 +0000 | [diff] [blame] | 763 | if (!headerContentLanguage.isEmpty()) { |
| 764 | size_t commaIndex = headerContentLanguage.find(','); |
| 765 | headerContentLanguage.truncate(commaIndex); // notFound == -1 == don't truncate |
darin@apple.com | 940b9ea | 2017-11-25 02:44:45 +0000 | [diff] [blame] | 766 | headerContentLanguage = stripLeadingAndTrailingHTMLSpaces(headerContentLanguage); |
commit-queue@webkit.org | 26a3a09 | 2012-10-18 19:53:58 +0000 | [diff] [blame] | 767 | if (!headerContentLanguage.isEmpty()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 768 | m_frame.document()->setContentLanguage(headerContentLanguage); |
commit-queue@webkit.org | 26a3a09 | 2012-10-18 19:53:58 +0000 | [diff] [blame] | 769 | } |
collinj@webkit.org | 9c672f6 | 2008-09-19 04:15:14 +0000 | [diff] [blame] | 770 | } |
| 771 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 772 | history().restoreDocumentState(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 773 | } |
| 774 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 775 | void FrameLoader::finishedParsing() |
| 776 | { |
simon.fraser@apple.com | 677f042 | 2017-12-02 17:55:24 +0000 | [diff] [blame] | 777 | LOG(Loading, "WebCoreLoading %s: Finished parsing", m_frame.tree().uniqueName().string().utf8().data()); |
| 778 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 779 | m_frame.injectUserScripts(InjectAtDocumentEnd); |
aestes@apple.com | e35644e | 2011-04-07 20:23:48 +0000 | [diff] [blame] | 780 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 781 | if (m_stateMachine.creatingInitialEmptyDocument()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 782 | return; |
| 783 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 784 | // This can be called from the Frame's destructor, in which case we shouldn't protect ourselves |
| 785 | // 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] | 786 | // 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] | 787 | RefPtr<Frame> protector = m_frame.view() ? &m_frame : 0; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 788 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 789 | m_client.dispatchDidFinishDocumentLoad(); |
darin@chromium.org | 1750e24 | 2008-12-08 18:13:25 +0000 | [diff] [blame] | 790 | |
cdumez@apple.com | 6d7c65e | 2015-09-02 17:07:57 +0000 | [diff] [blame] | 791 | scrollToFragmentWithParentBoundary(m_frame.document()->url()); |
| 792 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 793 | checkCompleted(); |
| 794 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 795 | if (!m_frame.view()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 796 | return; // We are being destroyed by something checkCompleted called. |
| 797 | |
| 798 | // Check if the scrollbars are really needed for the content. |
| 799 | // If not, remove them, relayout, and repaint. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 800 | m_frame.view()->restoreScrollbar(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 801 | } |
| 802 | |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 803 | void FrameLoader::loadDone(LoadCompletionType type) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 804 | { |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 805 | if (type == LoadCompletionType::Finish) |
| 806 | checkCompleted(); |
| 807 | else |
| 808 | scheduleCheckCompleted(); |
| 809 | } |
| 810 | |
| 811 | void FrameLoader::subresourceLoadDone(LoadCompletionType type) |
| 812 | { |
| 813 | if (type == LoadCompletionType::Finish) |
| 814 | checkLoadComplete(); |
| 815 | else |
| 816 | scheduleCheckLoadComplete(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 817 | } |
| 818 | |
darin@apple.com | 4d9d718 | 2009-09-23 00:38:04 +0000 | [diff] [blame] | 819 | bool FrameLoader::allChildrenAreComplete() const |
| 820 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 821 | 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] | 822 | if (!child->loader().m_isComplete) |
darin@apple.com | 4d9d718 | 2009-09-23 00:38:04 +0000 | [diff] [blame] | 823 | return false; |
| 824 | } |
| 825 | return true; |
| 826 | } |
| 827 | |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 828 | bool FrameLoader::allAncestorsAreComplete() const |
| 829 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 830 | for (Frame* ancestor = &m_frame; ancestor; ancestor = ancestor->tree().parent()) { |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 831 | if (!ancestor->loader().m_isComplete) |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 832 | return false; |
| 833 | } |
| 834 | return true; |
| 835 | } |
| 836 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 837 | void FrameLoader::checkCompleted() |
| 838 | { |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 839 | RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(ScriptDisallowedScope::InMainThread::isScriptAllowed()); |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 840 | m_shouldCallCheckCompleted = false; |
| 841 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 842 | // Have we completed before? |
| 843 | if (m_isComplete) |
| 844 | return; |
rniwa@webkit.org | fcdf9db | 2018-05-04 23:58:04 +0000 | [diff] [blame] | 845 | |
commit-queue@webkit.org | 4e024c5 | 2018-05-21 17:50:04 +0000 | [diff] [blame] | 846 | #if ENABLE(VIDEO) |
rniwa@webkit.org | fcdf9db | 2018-05-04 23:58:04 +0000 | [diff] [blame] | 847 | // FIXME: Remove this code once https://webkit.org/b/185284 is fixed. |
| 848 | if (HTMLMediaElement::isRunningDestructor()) { |
| 849 | ASSERT_NOT_REACHED(); |
| 850 | scheduleCheckCompleted(); |
| 851 | return; |
| 852 | } |
commit-queue@webkit.org | 4e024c5 | 2018-05-21 17:50:04 +0000 | [diff] [blame] | 853 | #endif |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 854 | |
antti@apple.com | 079cbf5 | 2017-05-05 18:39:30 +0000 | [diff] [blame] | 855 | // FIXME: It would be better if resource loads were kicked off after render tree update (or didn't complete synchronously). |
| 856 | // https://bugs.webkit.org/show_bug.cgi?id=171729 |
| 857 | if (m_frame.document()->inRenderTreeUpdate()) { |
| 858 | scheduleCheckCompleted(); |
| 859 | return; |
| 860 | } |
| 861 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 862 | // Are we still parsing? |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 863 | if (m_frame.document()->parsing()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 864 | return; |
| 865 | |
| 866 | // Still waiting for images/scripts? |
cdumez@apple.com | 0bb03ec | 2015-01-28 05:53:53 +0000 | [diff] [blame] | 867 | if (m_frame.document()->cachedResourceLoader().requestCount()) |
ap@webkit.org | f9b6eff | 2009-02-10 17:33:33 +0000 | [diff] [blame] | 868 | return; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 869 | |
eric.carlson@apple.com | 9c7fc72 | 2010-08-26 16:45:43 +0000 | [diff] [blame] | 870 | // Still waiting for elements that don't go through a FrameLoader? |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 871 | if (m_frame.document()->isDelayingLoadEvent()) |
eric.carlson@apple.com | 9c7fc72 | 2010-08-26 16:45:43 +0000 | [diff] [blame] | 872 | return; |
| 873 | |
antti@apple.com | 9f4e3b2 | 2017-02-19 12:12:07 +0000 | [diff] [blame] | 874 | auto* scriptableParser = m_frame.document()->scriptableDocumentParser(); |
| 875 | if (scriptableParser && scriptableParser->hasScriptsWaitingForStylesheets()) |
| 876 | return; |
| 877 | |
andreas.kling@nokia.com | 01f9244 | 2011-02-28 13:46:06 +0000 | [diff] [blame] | 878 | // Any frame that hasn't completed yet? |
| 879 | if (!allChildrenAreComplete()) |
| 880 | return; |
| 881 | |
darin@apple.com | c284300 | 2014-04-25 06:01:34 +0000 | [diff] [blame] | 882 | // Important not to protect earlier in this function, because earlier parts |
darin@apple.com | fe9effd | 2014-04-25 06:02:42 +0000 | [diff] [blame] | 883 | // 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] | 884 | // to ref an object while it's being destroyed. |
| 885 | Ref<Frame> protect(m_frame); |
| 886 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 887 | // OK, completed. |
| 888 | m_isComplete = true; |
cdumez@apple.com | d839ea1 | 2015-07-04 19:42:18 +0000 | [diff] [blame] | 889 | m_requestedHistoryItem = nullptr; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 890 | m_frame.document()->setReadyState(Document::Complete); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 891 | |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 892 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 893 | if (m_frame.document()->url().isEmpty()) { |
| 894 | // We need to update the document URL of a PDF document to be non-empty so that both back/forward history navigation |
| 895 | // between PDF pages and fragment navigation works. See <rdar://problem/9544769> for more details. |
| 896 | // FIXME: Is there a better place for this code, say DocumentLoader? Also, we should explicitly only update the URL |
| 897 | // of the document when it's a PDFDocument object instead of assuming that a Document object with an empty URL is a PDFDocument. |
| 898 | // FIXME: This code is incorrect for a synthesized document (which also has an empty URL). The URL for a synthesized |
| 899 | // document should be the URL specified to FrameLoader::initForSynthesizedDocument(). |
| 900 | m_frame.document()->setURL(activeDocumentLoader()->documentURL()); |
| 901 | } |
| 902 | #endif |
| 903 | |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 904 | checkCallImplicitClose(); // if we didn't do it before |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 905 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 906 | m_frame.navigationScheduler().startTimer(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 907 | |
| 908 | completed(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 909 | if (m_frame.page()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 910 | checkLoadComplete(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 911 | } |
| 912 | |
andersca@apple.com | 574a745 | 2014-11-21 20:10:13 +0000 | [diff] [blame] | 913 | void FrameLoader::checkTimerFired() |
weinig | c34c71c | 2007-03-09 16:05:37 +0000 | [diff] [blame] | 914 | { |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 915 | checkCompletenessNow(); |
| 916 | } |
| 917 | |
| 918 | void FrameLoader::checkCompletenessNow() |
| 919 | { |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 920 | Ref<Frame> protect(m_frame); |
commit-queue@webkit.org | 667ee8b | 2012-02-08 02:21:04 +0000 | [diff] [blame] | 921 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 922 | if (Page* page = m_frame.page()) { |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 923 | if (page->defersLoading()) |
| 924 | return; |
| 925 | } |
| 926 | if (m_shouldCallCheckCompleted) |
| 927 | checkCompleted(); |
| 928 | if (m_shouldCallCheckLoadComplete) |
| 929 | checkLoadComplete(); |
| 930 | } |
| 931 | |
| 932 | void FrameLoader::startCheckCompleteTimer() |
| 933 | { |
| 934 | if (!(m_shouldCallCheckCompleted || m_shouldCallCheckLoadComplete)) |
| 935 | return; |
| 936 | if (m_checkTimer.isActive()) |
| 937 | return; |
cdumez@apple.com | bc919b0 | 2017-04-09 14:49:14 +0000 | [diff] [blame] | 938 | m_checkTimer.startOneShot(0_s); |
weinig | c34c71c | 2007-03-09 16:05:37 +0000 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | void FrameLoader::scheduleCheckCompleted() |
| 942 | { |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 943 | m_shouldCallCheckCompleted = true; |
| 944 | startCheckCompleteTimer(); |
beidson | 398923b | 2007-07-31 20:29:02 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | void FrameLoader::scheduleCheckLoadComplete() |
| 948 | { |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 949 | m_shouldCallCheckLoadComplete = true; |
| 950 | startCheckCompleteTimer(); |
beidson | 398923b | 2007-07-31 20:29:02 +0000 | [diff] [blame] | 951 | } |
| 952 | |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 953 | void FrameLoader::checkCallImplicitClose() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 954 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 955 | if (m_didCallImplicitClose || m_frame.document()->parsing() || m_frame.document()->isDelayingLoadEvent()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 956 | return; |
| 957 | |
darin@apple.com | 4d9d718 | 2009-09-23 00:38:04 +0000 | [diff] [blame] | 958 | if (!allChildrenAreComplete()) |
| 959 | return; // still got a frame running -> too early |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 960 | |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 961 | m_didCallImplicitClose = true; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 962 | m_wasUnloadEventEmitted = false; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 963 | m_frame.document()->implicitClose(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 964 | } |
| 965 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 966 | void FrameLoader::loadURLIntoChildFrame(const URL& url, const String& referer, Frame* childFrame) |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 967 | { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 968 | RELEASE_LOG_IF_ALLOWED("loadURLIntoChildFrame: frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 969 | |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 970 | ASSERT(childFrame); |
darin@apple.com | a7e141f | 2009-03-06 17:22:07 +0000 | [diff] [blame] | 971 | |
jcivelli@chromium.org | c2019dd | 2011-05-24 19:32:03 +0000 | [diff] [blame] | 972 | #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 973 | if (auto activeLoader = activeDocumentLoader()) { |
| 974 | if (auto subframeArchive = activeLoader->popArchiveForSubframe(childFrame->tree().uniqueName(), url)) { |
| 975 | childFrame->loader().loadArchive(RefPtr<Archive> { subframeArchive }.releaseNonNull()); |
| 976 | return; |
| 977 | } |
mihaip@chromium.org | e5dbd37 | 2010-12-08 02:32:41 +0000 | [diff] [blame] | 978 | } |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 979 | #endif |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 980 | |
darin@apple.com | a7e141f | 2009-03-06 17:22:07 +0000 | [diff] [blame] | 981 | // 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] | 982 | // of this child frame with whatever was there at that point. |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 983 | auto* parentItem = history().currentItem(); |
| 984 | if (parentItem && parentItem->children().size() && isBackForwardLoadType(loadType()) && !m_frame.document()->loadEventFinished()) { |
| 985 | if (auto* childItem = parentItem->childItemWithTarget(childFrame->tree().uniqueName())) { |
ap@apple.com | 4d286a9 | 2013-08-19 23:41:18 +0000 | [diff] [blame] | 986 | childFrame->loader().m_requestedHistoryItem = childItem; |
cdumez@apple.com | 29f7c1e | 2019-03-13 20:32:48 +0000 | [diff] [blame] | 987 | childFrame->loader().loadDifferentDocumentItem(*childItem, nullptr, loadType(), MayAttemptCacheOnlyLoadForFormSubmissionItem, ShouldTreatAsContinuingLoad::No); |
mihaip@chromium.org | e5dbd37 | 2010-12-08 02:32:41 +0000 | [diff] [blame] | 988 | return; |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 992 | auto* lexicalFrame = lexicalFrameFromCommonVM(); |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 993 | auto initiatedByMainFrame = lexicalFrame && lexicalFrame->isMainFrame() ? InitiatedByMainFrame::Yes : InitiatedByMainFrame::Unknown; |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 994 | |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 995 | FrameLoadRequest frameLoadRequest { *m_frame.document(), m_frame.document()->securityOrigin(), { url }, "_self"_s, LockHistory::No, LockBackForwardList::Yes, ShouldSendReferrer::MaybeSendReferrer, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Suppress, ShouldOpenExternalURLsPolicy::ShouldNotAllow, initiatedByMainFrame }; |
wilander@apple.com | 6ffdf8f | 2019-02-06 22:02:15 +0000 | [diff] [blame] | 996 | childFrame->loader().loadURL(WTFMove(frameLoadRequest), referer, FrameLoadType::RedirectWithLockedBackForwardList, nullptr, { }, WTF::nullopt, [] { }); |
beidson@apple.com | 47ef96f | 2015-05-29 16:38:13 +0000 | [diff] [blame] | 997 | } |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 998 | |
jcivelli@chromium.org | c2019dd | 2011-05-24 19:32:03 +0000 | [diff] [blame] | 999 | #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 1000 | |
| 1001 | void FrameLoader::loadArchive(Ref<Archive>&& archive) |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 1002 | { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1003 | RELEASE_LOG_IF_ALLOWED("loadArchive: frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 1004 | |
japhet@chromium.org | ac5cd4b | 2012-04-12 19:27:28 +0000 | [diff] [blame] | 1005 | ArchiveResource* mainResource = archive->mainResource(); |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 1006 | ASSERT(mainResource); |
| 1007 | if (!mainResource) |
| 1008 | return; |
beidson@apple.com | ceb7cba | 2015-05-19 22:22:51 +0000 | [diff] [blame] | 1009 | |
jh718.park@samsung.com | 9f99af5 | 2016-03-15 00:22:45 +0000 | [diff] [blame] | 1010 | ResourceResponse response(URL(), mainResource->mimeType(), mainResource->data().size(), mainResource->textEncoding()); |
| 1011 | SubstituteData substituteData(&mainResource->data(), URL(), response, SubstituteData::SessionHistoryVisibility::Hidden); |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 1012 | |
| 1013 | ResourceRequest request(mainResource->url()); |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 1014 | |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 1015 | auto documentLoader = m_client.createDocumentLoader(request, substituteData); |
| 1016 | documentLoader->setArchive(WTFMove(archive)); |
achristensen@apple.com | 10e4a7b | 2018-11-28 21:14:43 +0000 | [diff] [blame] | 1017 | load(documentLoader.get()); |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 1018 | } |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 1019 | |
jcivelli@chromium.org | c2019dd | 2011-05-24 19:32:03 +0000 | [diff] [blame] | 1020 | #endif // ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 1021 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1022 | String FrameLoader::outgoingReferrer() const |
| 1023 | { |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 1024 | // See http://www.whatwg.org/specs/web-apps/current-work/#fetching-resources |
| 1025 | // for why we walk the parent chain for srcdoc documents. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1026 | Frame* frame = &m_frame; |
antti@apple.com | 1f5a246 | 2016-12-14 18:54:28 +0000 | [diff] [blame] | 1027 | while (frame && frame->document()->isSrcdocDocument()) { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1028 | frame = frame->tree().parent(); |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 1029 | // Srcdoc documents cannot be top-level documents, by definition, |
| 1030 | // because they need to be contained in iframes with the srcdoc. |
| 1031 | ASSERT(frame); |
| 1032 | } |
antti@apple.com | 1f5a246 | 2016-12-14 18:54:28 +0000 | [diff] [blame] | 1033 | if (!frame) |
| 1034 | return emptyString(); |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 1035 | return frame->loader().m_outgoingReferrer; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 1038 | String FrameLoader::outgoingOrigin() const |
| 1039 | { |
akling@apple.com | 6be0e97 | 2017-01-18 19:35:49 +0000 | [diff] [blame] | 1040 | return m_frame.document()->securityOrigin().toString(); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
dbates@webkit.org | 28db74a | 2016-04-15 22:23:44 +0000 | [diff] [blame] | 1043 | bool FrameLoader::checkIfFormActionAllowedByCSP(const URL& url, bool didReceiveRedirectResponse) const |
commit-queue@webkit.org | 78e860e | 2012-08-16 12:42:09 +0000 | [diff] [blame] | 1044 | { |
| 1045 | if (m_submittedFormURL.isEmpty()) |
| 1046 | return true; |
| 1047 | |
dbates@webkit.org | 28db74a | 2016-04-15 22:23:44 +0000 | [diff] [blame] | 1048 | auto redirectResponseReceived = didReceiveRedirectResponse ? ContentSecurityPolicy::RedirectResponseReceived::Yes : ContentSecurityPolicy::RedirectResponseReceived::No; |
commit-queue@webkit.org | 03af195 | 2016-09-22 08:28:37 +0000 | [diff] [blame] | 1049 | return m_frame.document()->contentSecurityPolicy()->allowFormAction(url, redirectResponseReceived); |
commit-queue@webkit.org | 78e860e | 2012-08-16 12:42:09 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1052 | Frame* FrameLoader::opener() |
| 1053 | { |
| 1054 | return m_opener; |
| 1055 | } |
| 1056 | |
| 1057 | void FrameLoader::setOpener(Frame* opener) |
| 1058 | { |
creis@chromium.org | 16d76c7 | 2012-12-04 17:39:26 +0000 | [diff] [blame] | 1059 | if (m_opener && !opener) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1060 | m_client.didDisownOpener(); |
creis@chromium.org | 16d76c7 | 2012-12-04 17:39:26 +0000 | [diff] [blame] | 1061 | |
rniwa@webkit.org | 2c6d4eb | 2017-07-01 21:26:31 +0000 | [diff] [blame] | 1062 | if (m_opener) { |
| 1063 | // When setOpener is called in ~FrameLoader, opener's m_frameLoader is already cleared. |
| 1064 | auto& openerFrameLoader = m_opener == &m_frame ? *this : m_opener->loader(); |
| 1065 | openerFrameLoader.m_openedFrames.remove(&m_frame); |
| 1066 | } |
cdumez@apple.com | 2e47236 | 2018-12-01 22:40:07 +0000 | [diff] [blame] | 1067 | if (opener) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1068 | opener->loader().m_openedFrames.add(&m_frame); |
cdumez@apple.com | 2e47236 | 2018-12-01 22:40:07 +0000 | [diff] [blame] | 1069 | if (auto* page = m_frame.page()) |
| 1070 | page->setOpenedByDOMWithOpener(); |
| 1071 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1072 | m_opener = opener; |
weinig | 343b6ff | 2007-08-07 03:08:53 +0000 | [diff] [blame] | 1073 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1074 | if (m_frame.document()) |
| 1075 | m_frame.document()->initSecurityContext(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
eric@webkit.org | 4ffb1fe | 2010-09-03 04:28:12 +0000 | [diff] [blame] | 1078 | // FIXME: This does not belong in FrameLoader! |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1079 | void FrameLoader::handleFallbackContent() |
| 1080 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1081 | HTMLFrameOwnerElement* owner = m_frame.ownerElement(); |
cdumez@apple.com | a9c60c9 | 2014-10-02 19:39:41 +0000 | [diff] [blame] | 1082 | if (!is<HTMLObjectElement>(owner)) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1083 | return; |
cdumez@apple.com | 72754ba | 2014-09-23 22:03:15 +0000 | [diff] [blame] | 1084 | downcast<HTMLObjectElement>(*owner).renderFallbackContent(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | void FrameLoader::provisionalLoadStarted() |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 1088 | { |
| 1089 | if (m_stateMachine.firstLayoutDone()) |
| 1090 | m_stateMachine.advanceTo(FrameLoaderStateMachine::CommittedFirstRealLoad); |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 1091 | m_frame.navigationScheduler().cancel(NewLoadInProgress::Yes); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1092 | m_client.provisionalLoadStarted(); |
cdumez@apple.com | ef2c015 | 2017-01-13 17:54:53 +0000 | [diff] [blame] | 1093 | |
| 1094 | if (m_frame.isMainFrame()) { |
sbarati@apple.com | ce7ec11 | 2018-04-17 15:57:32 +0000 | [diff] [blame] | 1095 | tracePoint(MainResourceLoadDidStartProvisional); |
simon.fraser@apple.com | 83325b9 | 2017-03-17 00:47:16 +0000 | [diff] [blame] | 1096 | |
cdumez@apple.com | ef2c015 | 2017-01-13 17:54:53 +0000 | [diff] [blame] | 1097 | if (auto* page = m_frame.page()) |
| 1098 | page->didStartProvisionalLoad(); |
| 1099 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1102 | void FrameLoader::resetMultipleFormSubmissionProtection() |
| 1103 | { |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1104 | m_submittedFormURL = URL(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
abarth@webkit.org | 622d9df | 2009-05-22 16:44:47 +0000 | [diff] [blame] | 1107 | void FrameLoader::updateFirstPartyForCookies() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1108 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1109 | if (m_frame.tree().parent()) |
| 1110 | setFirstPartyForCookies(m_frame.tree().parent()->document()->firstPartyForCookies()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1111 | else |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1112 | setFirstPartyForCookies(m_frame.document()->url()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1115 | void FrameLoader::setFirstPartyForCookies(const URL& url) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1116 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1117 | 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] | 1118 | frame->document()->setFirstPartyForCookies(url); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 1119 | |
cdumez@apple.com | 0b8674fb | 2019-03-13 19:53:41 +0000 | [diff] [blame] | 1120 | RegistrableDomain registrableDomain(url); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 1121 | 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] | 1122 | if (SecurityPolicy::shouldInheritSecurityOriginFromOwner(frame->document()->url()) || registrableDomain.matches(frame->document()->url())) |
dbates@webkit.org | 940f0b8 | 2018-07-24 16:27:25 +0000 | [diff] [blame] | 1123 | frame->document()->setSiteForCookies(url); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 1124 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
darin@apple.com | d69216d | 2008-03-11 00:45:47 +0000 | [diff] [blame] | 1127 | // 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] | 1128 | // 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] | 1129 | void FrameLoader::loadInSameDocument(const URL& url, SerializedScriptValue* stateObject, bool isNewNavigation) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1130 | { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1131 | RELEASE_LOG_IF_ALLOWED("loadInSameDocument: frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 1132 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1133 | // If we have a state object, we cannot also be a new navigation. |
| 1134 | ASSERT(!stateObject || (stateObject && !isNewNavigation)); |
| 1135 | |
| 1136 | // 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] | 1137 | URL oldURL = m_frame.document()->url(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1138 | m_frame.document()->setURL(url); |
jochen@chromium.org | 7495f96 | 2012-05-04 16:43:03 +0000 | [diff] [blame] | 1139 | setOutgoingReferrer(url); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1140 | documentLoader()->replaceRequestURLForSameDocumentNavigation(url); |
| 1141 | if (isNewNavigation && !shouldTreatURLAsSameAsCurrent(url) && !stateObject) { |
| 1142 | // NB: must happen after replaceRequestURLForSameDocumentNavigation(), since we add |
| 1143 | // based on the current request. Must also happen before we openURL and displace the |
| 1144 | // scroll position, since adding the BF item will save away scroll state. |
| 1145 | |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 1146 | // 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] | 1147 | // it was done, currItem is now set the that slow doc, and prevItem is whatever was |
| 1148 | // before it. Adding the b/f item will bump the slow doc down to prevItem, even |
| 1149 | // though its load is not yet done. I think this all works out OK, for one because |
| 1150 | // we have already saved away the scroll and doc state for the long slow load, |
| 1151 | // but it's not an obvious case. |
| 1152 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 1153 | history().updateBackForwardListForFragmentScroll(); |
beidson@apple.com | 8127cdc | 2009-08-07 15:35:19 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
japhet@chromium.org | b254c9b | 2011-01-26 19:14:26 +0000 | [diff] [blame] | 1156 | bool hashChange = equalIgnoringFragmentIdentifier(url, oldURL) && url.fragmentIdentifier() != oldURL.fragmentIdentifier(); |
beidson@apple.com | 43a414c | 2010-03-19 18:25:21 +0000 | [diff] [blame] | 1157 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 1158 | history().updateForSameDocumentNavigation(); |
britto@apple.com | 195cc0b | 2008-07-23 16:48:47 +0000 | [diff] [blame] | 1159 | |
| 1160 | // 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] | 1161 | if (hashChange) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1162 | m_frame.eventHandler().stopAutoscrollTimer(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1163 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1164 | // It's important to model this as a load that starts and immediately finishes. |
| 1165 | // Otherwise, the parent frame may think we never finished loading. |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1166 | started(); |
japhet@chromium.org | 48bb260 | 2010-03-04 23:01:45 +0000 | [diff] [blame] | 1167 | |
dbates@webkit.org | 86a1c67 | 2018-08-10 17:39:53 +0000 | [diff] [blame] | 1168 | if (auto* ownerElement = m_frame.ownerElement()) { |
| 1169 | auto* ownerRenderer = ownerElement->renderer(); |
| 1170 | auto* view = m_frame.view(); |
| 1171 | if (is<RenderWidget>(ownerRenderer) && view) |
| 1172 | downcast<RenderWidget>(*ownerRenderer).setWidget(view); |
| 1173 | } |
| 1174 | |
japhet@chromium.org | 48bb260 | 2010-03-04 23:01:45 +0000 | [diff] [blame] | 1175 | // We need to scroll to the fragment whether or not a hash change occurred, since |
| 1176 | // the user might have scrolled since the previous navigation. |
simon.fraser@apple.com | c79e486 | 2017-03-08 20:01:15 +0000 | [diff] [blame] | 1177 | scrollToFragmentWithParentBoundary(url, isNewNavigation); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1178 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1179 | m_isComplete = false; |
| 1180 | checkCompleted(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1181 | |
| 1182 | if (isNewNavigation) { |
| 1183 | // 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] | 1184 | // doing any loading. We need to make a pass on this now, since for fragment |
| 1185 | // 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] | 1186 | checkLoadComplete(); |
| 1187 | } |
| 1188 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1189 | m_client.dispatchDidNavigateWithinPage(); |
darin@chromium.org | fe27996 | 2010-03-16 17:26:59 +0000 | [diff] [blame] | 1190 | |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 1191 | m_frame.document()->statePopped(stateObject ? Ref<SerializedScriptValue> { *stateObject } : SerializedScriptValue::nullValue()); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1192 | m_client.dispatchDidPopStateWithinPage(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1193 | |
| 1194 | if (hashChange) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1195 | m_frame.document()->enqueueHashchangeEvent(oldURL, url); |
| 1196 | m_client.dispatchDidChangeLocationWithinPage(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | // FrameLoaderClient::didFinishLoad() tells the internal load delegate the load finished with no error |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1200 | m_client.didFinishLoad(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | bool FrameLoader::isComplete() const |
| 1204 | { |
| 1205 | return m_isComplete; |
| 1206 | } |
| 1207 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1208 | void FrameLoader::completed() |
| 1209 | { |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 1210 | Ref<Frame> protect(m_frame); |
beidson@apple.com | a566251 | 2009-10-27 00:19:33 +0000 | [diff] [blame] | 1211 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1212 | 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] | 1213 | descendant->navigationScheduler().startTimer(); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 1214 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1215 | if (Frame* parent = m_frame.tree().parent()) |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 1216 | parent->loader().checkCompleted(); |
beidson@apple.com | a566251 | 2009-10-27 00:19:33 +0000 | [diff] [blame] | 1217 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1218 | if (m_frame.view()) |
mmaxfield@apple.com | 6ebeece | 2014-12-09 21:03:54 +0000 | [diff] [blame] | 1219 | m_frame.view()->maintainScrollPositionAtAnchor(nullptr); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | void FrameLoader::started() |
| 1223 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1224 | for (Frame* frame = &m_frame; frame; frame = frame->tree().parent()) |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 1225 | frame->loader().m_isComplete = false; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 1228 | void FrameLoader::prepareForLoadStart() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1229 | { |
krollin@apple.com | d54b5d7 | 2016-09-12 18:59:32 +0000 | [diff] [blame] | 1230 | RELEASE_LOG_IF_ALLOWED("prepareForLoadStart: Starting frame load (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
commit-queue@webkit.org | 6d63522 | 2016-03-08 06:44:59 +0000 | [diff] [blame] | 1231 | |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 1232 | m_progressTracker->progressStarted(); |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 1233 | m_client.dispatchDidStartProvisionalLoad(); |
| 1234 | |
| 1235 | if (AXObjectCache::accessibilityEnabled()) { |
| 1236 | if (AXObjectCache* cache = m_frame.document()->existingAXObjectCache()) { |
| 1237 | AXObjectCache::AXLoadingEvent loadingEvent = loadType() == FrameLoadType::Reload ? AXObjectCache::AXLoadingReloaded : AXObjectCache::AXLoadingStarted; |
| 1238 | cache->frameLoadingEventNotification(&m_frame, loadingEvent); |
ossy@webkit.org | 451e9b0 | 2014-01-27 12:40:18 +0000 | [diff] [blame] | 1239 | } |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 1240 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | void FrameLoader::setupForReplace() |
| 1244 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1245 | m_client.revertToProvisionalState(m_documentLoader.get()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1246 | setState(FrameStateProvisional); |
| 1247 | m_provisionalDocumentLoader = m_documentLoader; |
cdumez@apple.com | d839ea1 | 2015-07-04 19:42:18 +0000 | [diff] [blame] | 1248 | m_documentLoader = nullptr; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1249 | detachChildren(); |
| 1250 | } |
| 1251 | |
wilander@apple.com | 6ffdf8f | 2019-02-06 22:02:15 +0000 | [diff] [blame] | 1252 | 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] | 1253 | { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1254 | RELEASE_LOG_IF_ALLOWED("loadFrameRequest: frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 1255 | |
inferno@chromium.org | 670ab75 | 2011-07-13 18:51:44 +0000 | [diff] [blame] | 1256 | // Protect frame from getting blown away inside dispatchBeforeLoadEvent in loadWithDocumentLoader. |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 1257 | auto protectFrame = makeRef(m_frame); |
inferno@chromium.org | 670ab75 | 2011-07-13 18:51:44 +0000 | [diff] [blame] | 1258 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1259 | URL url = request.resourceRequest().url(); |
antti@apple.com | c633dca | 2008-11-14 21:34:55 +0000 | [diff] [blame] | 1260 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1261 | ASSERT(m_frame.document()); |
dbates@webkit.org | 174ac71 | 2017-06-30 21:35:23 +0000 | [diff] [blame] | 1262 | if (!request.requesterSecurityOrigin().canDisplay(url)) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1263 | reportLocalLoadFailed(&m_frame, url.stringCenterEllipsizedToLength()); |
darin@apple.com | 1cf3d56 | 2010-12-07 16:23:03 +0000 | [diff] [blame] | 1264 | return; |
| 1265 | } |
| 1266 | |
darin | 5a1e60e | 2007-04-17 19:58:16 +0000 | [diff] [blame] | 1267 | String argsReferrer = request.resourceRequest().httpReferrer(); |
jochen@chromium.org | 4761ef5 | 2011-11-21 10:29:55 +0000 | [diff] [blame] | 1268 | if (argsReferrer.isEmpty()) |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 1269 | argsReferrer = outgoingReferrer(); |
antti@apple.com | c633dca | 2008-11-14 21:34:55 +0000 | [diff] [blame] | 1270 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1271 | String referrer = SecurityPolicy::generateReferrerHeader(m_frame.document()->referrerPolicy(), url, argsReferrer); |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 1272 | if (request.shouldSendReferrer() == NeverSendReferrer) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1273 | referrer = String(); |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 1274 | |
ggaren@apple.com | 78b4dc6 | 2009-01-30 23:09:43 +0000 | [diff] [blame] | 1275 | FrameLoadType loadType; |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 1276 | if (request.resourceRequest().cachePolicy() == ResourceRequestCachePolicy::ReloadIgnoringCacheData) |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1277 | loadType = FrameLoadType::Reload; |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 1278 | else if (request.lockBackForwardList() == LockBackForwardList::Yes) |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1279 | loadType = FrameLoadType::RedirectWithLockedBackForwardList; |
ggaren@apple.com | 78b4dc6 | 2009-01-30 23:09:43 +0000 | [diff] [blame] | 1280 | else |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1281 | loadType = FrameLoadType::Standard; |
ggaren@apple.com | 78b4dc6 | 2009-01-30 23:09:43 +0000 | [diff] [blame] | 1282 | |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 1283 | 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] | 1284 | // FIXME: It's possible this targetFrame will not be the same frame that was targeted by the actual |
| 1285 | // load if frame names have changed. |
| 1286 | Frame* sourceFrame = formState ? formState->sourceDocument().frame() : &m_frame; |
| 1287 | if (!sourceFrame) |
| 1288 | sourceFrame = &m_frame; |
| 1289 | Frame* targetFrame = sourceFrame->loader().findFrameForNavigation(frameName); |
| 1290 | if (targetFrame && targetFrame != sourceFrame) { |
| 1291 | if (Page* page = targetFrame->page()) |
| 1292 | page->chrome().focus(); |
| 1293 | } |
| 1294 | }; |
ggaren@apple.com | 78b4dc6 | 2009-01-30 23:09:43 +0000 | [diff] [blame] | 1295 | |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 1296 | if (request.resourceRequest().httpMethod() == "POST") |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 1297 | loadPostRequest(WTFMove(request), referrer, loadType, event, WTFMove(formState), WTFMove(completionHandler)); |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 1298 | else |
wilander@apple.com | 6ffdf8f | 2019-02-06 22:02:15 +0000 | [diff] [blame] | 1299 | loadURL(WTFMove(request), referrer, loadType, event, WTFMove(formState), WTFMove(adClickAttribution), WTFMove(completionHandler)); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1300 | } |
ddkilzer@apple.com | e6e7d42 | 2008-08-06 21:15:39 +0000 | [diff] [blame] | 1301 | |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 1302 | static ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicyToApply(Frame& currentFrame, InitiatedByMainFrame initiatedByMainFrame, ShouldOpenExternalURLsPolicy propagatedPolicy) |
mitz@apple.com | c99c715 | 2015-07-17 21:16:09 +0000 | [diff] [blame] | 1303 | { |
commit-queue@webkit.org | 635dbdc | 2017-11-23 19:36:08 +0000 | [diff] [blame] | 1304 | if (UserGestureIndicator::processingUserGesture()) |
mitz@apple.com | c99c715 | 2015-07-17 21:16:09 +0000 | [diff] [blame] | 1305 | return ShouldOpenExternalURLsPolicy::ShouldAllow; |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1306 | |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 1307 | if (initiatedByMainFrame == InitiatedByMainFrame::Yes) |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1308 | return propagatedPolicy; |
| 1309 | |
| 1310 | if (!currentFrame.isMainFrame()) |
| 1311 | return ShouldOpenExternalURLsPolicy::ShouldNotAllow; |
| 1312 | |
mitz@apple.com | c99c715 | 2015-07-17 21:16:09 +0000 | [diff] [blame] | 1313 | return propagatedPolicy; |
| 1314 | } |
| 1315 | |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1316 | static ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicyToApply(Frame& currentFrame, const FrameLoadRequest& frameLoadRequest) |
| 1317 | { |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 1318 | return shouldOpenExternalURLsPolicyToApply(currentFrame, frameLoadRequest.initiatedByMainFrame(), frameLoadRequest.shouldOpenExternalURLsPolicy()); |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 1321 | static void applyShouldOpenExternalURLsPolicyToNewDocumentLoader(Frame& frame, DocumentLoader& documentLoader, InitiatedByMainFrame initiatedByMainFrame, ShouldOpenExternalURLsPolicy propagatedPolicy) |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1322 | { |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 1323 | documentLoader.setShouldOpenExternalURLsPolicy(shouldOpenExternalURLsPolicyToApply(frame, initiatedByMainFrame, propagatedPolicy)); |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | static void applyShouldOpenExternalURLsPolicyToNewDocumentLoader(Frame& frame, DocumentLoader& documentLoader, const FrameLoadRequest& frameLoadRequest) |
| 1327 | { |
| 1328 | documentLoader.setShouldOpenExternalURLsPolicy(shouldOpenExternalURLsPolicyToApply(frame, frameLoadRequest)); |
| 1329 | } |
| 1330 | |
dbates@webkit.org | 872db61 | 2017-03-20 23:07:50 +0000 | [diff] [blame] | 1331 | bool FrameLoader::isNavigationAllowed() const |
| 1332 | { |
beidson@apple.com | b457130 | 2019-08-08 15:54:37 +0000 | [diff] [blame] | 1333 | 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] | 1334 | } |
| 1335 | |
pvollan@apple.com | 8f4bcd95 | 2018-02-01 04:18:38 +0000 | [diff] [blame] | 1336 | bool FrameLoader::isStopLoadingAllowed() const |
| 1337 | { |
| 1338 | return m_pageDismissalEventBeingDispatched == PageDismissalType::None; |
| 1339 | } |
| 1340 | |
wilander@apple.com | 6ffdf8f | 2019-02-06 22:02:15 +0000 | [diff] [blame] | 1341 | 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] | 1342 | { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1343 | RELEASE_LOG_IF_ALLOWED("loadURL: frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 1344 | |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 1345 | CompletionHandlerCallingScope completionHandlerCaller(WTFMove(completionHandler)); |
cdumez@apple.com | 8ace63b | 2018-06-29 22:56:29 +0000 | [diff] [blame] | 1346 | if (m_inStopAllLoaders || m_inClearProvisionalLoadForPolicyCheck) |
commit-queue@webkit.org | cd5cda2 | 2011-02-15 15:55:21 +0000 | [diff] [blame] | 1347 | return; |
| 1348 | |
jpfau@apple.com | 18da22e | 2014-06-19 00:20:25 +0000 | [diff] [blame] | 1349 | Ref<Frame> protect(m_frame); |
| 1350 | |
cdumez@apple.com | 3ed2674 | 2018-10-09 23:21:18 +0000 | [diff] [blame] | 1351 | // Anchor target is ignored when the download attribute is set since it will download the hyperlink rather than follow it. |
| 1352 | String effectiveFrameName = frameLoadRequest.downloadAttribute().isNull() ? frameLoadRequest.frameName() : String(); |
beidson@apple.com | bd66a78 | 2015-05-29 16:31:49 +0000 | [diff] [blame] | 1353 | AllowNavigationToInvalidURL allowNavigationToInvalidURL = frameLoadRequest.allowNavigationToInvalidURL(); |
| 1354 | NewFrameOpenerPolicy openerPolicy = frameLoadRequest.newFrameOpenerPolicy(); |
| 1355 | LockHistory lockHistory = frameLoadRequest.lockHistory(); |
andersca | 3513ce0 | 2007-05-17 08:38:44 +0000 | [diff] [blame] | 1356 | bool isFormSubmission = formState; |
beidson@apple.com | bd66a78 | 2015-05-29 16:31:49 +0000 | [diff] [blame] | 1357 | |
| 1358 | const URL& newURL = frameLoadRequest.resourceRequest().url(); |
weinig@apple.com | c500266 | 2007-12-12 07:26:19 +0000 | [diff] [blame] | 1359 | ResourceRequest request(newURL); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 1360 | if (!referrer.isEmpty()) { |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1361 | request.setHTTPReferrer(referrer); |
yusukesuzuki@slowstart.org | ae5a8bd | 2018-12-22 06:37:39 +0000 | [diff] [blame] | 1362 | auto referrerOrigin = SecurityOrigin::createFromString(referrer); |
abarth@webkit.org | 48cade3 | 2008-10-23 09:43:34 +0000 | [diff] [blame] | 1363 | addHTTPOriginIfNeeded(request, referrerOrigin->toString()); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 1364 | } |
akling@apple.com | 5298947 | 2013-09-16 20:09:25 +0000 | [diff] [blame] | 1365 | if (&m_frame.tree().top() != &m_frame) |
commit-queue@webkit.org | c4f892f | 2017-12-22 05:36:13 +0000 | [diff] [blame] | 1366 | request.setDomainForCachePartition(m_frame.tree().top().document()->domainForCachePartition()); |
antti@apple.com | cab5da4 | 2017-02-09 11:09:28 +0000 | [diff] [blame] | 1367 | |
jochen@chromium.org | dac140c | 2011-08-01 21:18:49 +0000 | [diff] [blame] | 1368 | addExtraFieldsToRequest(request, newLoadType, true); |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 1369 | if (isReload(newLoadType)) |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 1370 | request.setCachePolicy(ResourceRequestCachePolicy::ReloadIgnoringCacheData); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1371 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1372 | ASSERT(newLoadType != FrameLoadType::Same); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1373 | |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 1374 | // The search for a target frame is done earlier in the case of form submission. |
cdumez@apple.com | 3ed2674 | 2018-10-09 23:21:18 +0000 | [diff] [blame] | 1375 | Frame* targetFrame = isFormSubmission ? nullptr : findFrameForNavigation(effectiveFrameName); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1376 | if (targetFrame && targetFrame != &m_frame) { |
dbates@webkit.org | 7f3a982 | 2017-06-22 19:45:10 +0000 | [diff] [blame] | 1377 | frameLoadRequest.setFrameName("_self"); |
wilander@apple.com | 6ffdf8f | 2019-02-06 22:02:15 +0000 | [diff] [blame] | 1378 | targetFrame->loader().loadURL(WTFMove(frameLoadRequest), referrer, newLoadType, event, WTFMove(formState), WTFMove(adClickAttribution), completionHandlerCaller.release()); |
darin@apple.com | 19c05e9 | 2009-03-30 17:26:16 +0000 | [diff] [blame] | 1379 | return; |
| 1380 | } |
| 1381 | |
dbates@webkit.org | 872db61 | 2017-03-20 23:07:50 +0000 | [diff] [blame] | 1382 | if (!isNavigationAllowed()) |
eric@webkit.org | 6cae31a | 2009-09-26 02:35:15 +0000 | [diff] [blame] | 1383 | return; |
| 1384 | |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 1385 | NavigationAction action { frameLoadRequest.requester(), request, frameLoadRequest.initiatedByMainFrame(), newLoadType, isFormSubmission, event, frameLoadRequest.shouldOpenExternalURLsPolicy(), frameLoadRequest.downloadAttribute() }; |
cdumez@apple.com | 05911a3 | 2018-10-23 17:54:34 +0000 | [diff] [blame] | 1386 | action.setLockHistory(lockHistory); |
| 1387 | action.setLockBackForwardList(frameLoadRequest.lockBackForwardList()); |
wilander@apple.com | 6ffdf8f | 2019-02-06 22:02:15 +0000 | [diff] [blame] | 1388 | if (adClickAttribution && m_frame.isMainFrame()) |
| 1389 | action.setAdClickAttribution(WTFMove(*adClickAttribution)); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1390 | |
cdumez@apple.com | 3ed2674 | 2018-10-09 23:21:18 +0000 | [diff] [blame] | 1391 | if (!targetFrame && !effectiveFrameName.isEmpty()) { |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1392 | action = action.copyWithShouldOpenExternalURLsPolicy(shouldOpenExternalURLsPolicyToApply(m_frame, frameLoadRequest)); |
cdumez@apple.com | 3ed2674 | 2018-10-09 23:21:18 +0000 | [diff] [blame] | 1393 | 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, ShouldContinue shouldContinue) mutable { |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 1394 | continueLoadAfterNewWindowPolicy(request, formState.get(), frameName, action, shouldContinue, allowNavigationToInvalidURL, openerPolicy); |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 1395 | completionHandler(); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1396 | }); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1397 | return; |
| 1398 | } |
| 1399 | |
| 1400 | RefPtr<DocumentLoader> oldDocumentLoader = m_documentLoader; |
| 1401 | |
weinig@apple.com | c500266 | 2007-12-12 07:26:19 +0000 | [diff] [blame] | 1402 | bool sameURL = shouldTreatURLAsSameAsCurrent(newURL); |
yael.aharon@nokia.com | 79f6905 | 2010-12-30 19:31:00 +0000 | [diff] [blame] | 1403 | const String& httpMethod = request.httpMethod(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1404 | |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 1405 | // Make sure to do scroll to fragment processing even if the URL is |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1406 | // exactly the same so pages with '#' links and DHTML side effects |
| 1407 | // work properly. |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 1408 | if (shouldPerformFragmentNavigation(isFormSubmission, httpMethod, newLoadType, newURL)) { |
cdumez@apple.com | 91e03bd | 2018-09-17 17:15:07 +0000 | [diff] [blame] | 1409 | oldDocumentLoader->setTriggeringAction(WTFMove(action)); |
andersca@apple.com | 97ab6d9 | 2013-10-21 22:55:14 +0000 | [diff] [blame] | 1410 | oldDocumentLoader->setLastCheckedRequest(ResourceRequest()); |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1411 | policyChecker().stopCheck(); |
| 1412 | policyChecker().setLoadType(newLoadType); |
rniwa@webkit.org | ba12a01 | 2019-02-03 22:48:22 +0000 | [diff] [blame] | 1413 | RELEASE_ASSERT(!isBackForwardLoadType(newLoadType) || history().provisionalItem()); |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 1414 | policyChecker().checkNavigationPolicy(WTFMove(request), ResourceResponse { } /* redirectResponse */, oldDocumentLoader.get(), WTFMove(formState), [this, protectedFrame = makeRef(m_frame)] (const ResourceRequest& request, WeakPtr<FormState>&&, NavigationPolicyDecision navigationPolicyDecision) { |
| 1415 | continueFragmentScrollAfterNavigationPolicy(request, navigationPolicyDecision == NavigationPolicyDecision::ContinueLoad); |
cdumez@apple.com | 8221194 | 2018-04-17 18:13:49 +0000 | [diff] [blame] | 1416 | }, PolicyDecisionMode::Synchronous); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1417 | return; |
| 1418 | } |
| 1419 | |
dino@apple.com | b8e413d | 2018-05-08 20:12:24 +0000 | [diff] [blame] | 1420 | // 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] | 1421 | bool isRedirect = m_quickRedirectComing; |
dino@apple.com | 0bebb3a | 2018-05-22 23:56:01 +0000 | [diff] [blame] | 1422 | #if USE(SYSTEM_PREVIEW) |
| 1423 | bool isSystemPreview = frameLoadRequest.isSystemPreview(); |
dino@apple.com | 0bebb3a | 2018-05-22 23:56:01 +0000 | [diff] [blame] | 1424 | if (isSystemPreview) |
dino@apple.com | ddfbca8 | 2019-09-13 21:43:18 +0000 | [diff] [blame] | 1425 | request.setSystemPreviewInfo(frameLoadRequest.systemPreviewInfo()); |
dino@apple.com | 0bebb3a | 2018-05-22 23:56:01 +0000 | [diff] [blame] | 1426 | #endif |
commit-queue@webkit.org | a4a9ce2 | 2019-04-10 22:56:35 +0000 | [diff] [blame] | 1427 | loadWithNavigationAction(request, WTFMove(action), lockHistory, newLoadType, WTFMove(formState), allowNavigationToInvalidURL, frameLoadRequest.downloadAttribute(), [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] | 1428 | if (isRedirect) { |
| 1429 | m_quickRedirectComing = false; |
| 1430 | if (m_provisionalDocumentLoader) |
| 1431 | m_provisionalDocumentLoader->setIsClientRedirect(true); |
| 1432 | else if (m_policyDocumentLoader) |
| 1433 | m_policyDocumentLoader->setIsClientRedirect(true); |
| 1434 | } else if (sameURL && !isReload(newLoadType)) { |
| 1435 | // Example of this case are sites that reload the same URL with a different cookie |
| 1436 | // driving the generated content, or a master frame with links that drive a target |
| 1437 | // frame, where the user has clicked on the same link repeatedly. |
| 1438 | m_loadType = FrameLoadType::Same; |
| 1439 | } |
| 1440 | completionHandler(); |
| 1441 | }); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1442 | } |
| 1443 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1444 | SubstituteData FrameLoader::defaultSubstituteDataForURL(const URL& url) |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 1445 | { |
| 1446 | if (!shouldTreatURLAsSrcdocDocument(url)) |
| 1447 | return SubstituteData(); |
darin@apple.com | f9da7a7 | 2017-06-04 18:19:16 +0000 | [diff] [blame] | 1448 | auto& srcdoc = m_frame.ownerElement()->attributeWithoutSynchronization(srcdocAttr); |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 1449 | ASSERT(!srcdoc.isNull()); |
darin@apple.com | f9da7a7 | 2017-06-04 18:19:16 +0000 | [diff] [blame] | 1450 | CString encodedSrcdoc = srcdoc.string().utf8(); |
beidson@apple.com | ceb7cba | 2015-05-19 22:22:51 +0000 | [diff] [blame] | 1451 | |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 1452 | ResourceResponse response(URL(), "text/html"_s, encodedSrcdoc.length(), "UTF-8"_s); |
beidson@apple.com | ceb7cba | 2015-05-19 22:22:51 +0000 | [diff] [blame] | 1453 | 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] | 1454 | } |
| 1455 | |
dbates@webkit.org | 7f3a982 | 2017-06-22 19:45:10 +0000 | [diff] [blame] | 1456 | void FrameLoader::load(FrameLoadRequest&& request) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1457 | { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1458 | RELEASE_LOG_IF_ALLOWED("load (FrameLoadRequest): frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 1459 | |
cdumez@apple.com | 8ace63b | 2018-06-29 22:56:29 +0000 | [diff] [blame] | 1460 | if (m_inStopAllLoaders || m_inClearProvisionalLoadForPolicyCheck) |
andersca | 8567b3d | 2007-03-21 05:46:49 +0000 | [diff] [blame] | 1461 | return; |
simonjam@chromium.org | c98850b | 2012-11-28 01:07:36 +0000 | [diff] [blame] | 1462 | |
| 1463 | if (!request.frameName().isEmpty()) { |
| 1464 | Frame* frame = findFrameForNavigation(request.frameName()); |
| 1465 | if (frame) { |
| 1466 | request.setShouldCheckNewWindowPolicy(false); |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 1467 | if (&frame->loader() != this) { |
dbates@webkit.org | 7f3a982 | 2017-06-22 19:45:10 +0000 | [diff] [blame] | 1468 | frame->loader().load(WTFMove(request)); |
simonjam@chromium.org | c98850b | 2012-11-28 01:07:36 +0000 | [diff] [blame] | 1469 | return; |
| 1470 | } |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | if (request.shouldCheckNewWindowPolicy()) { |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 1475 | NavigationAction action { request.requester(), request.resourceRequest(), InitiatedByMainFrame::Unknown, NavigationType::Other, request.shouldOpenExternalURLsPolicy() }; |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 1476 | policyChecker().checkNewWindowPolicy(WTFMove(action), WTFMove(request.resourceRequest()), { }, request.frameName(), [this] (const ResourceRequest& request, WeakPtr<FormState>&& formState, const String& frameName, const NavigationAction& action, ShouldContinue shouldContinue) { |
| 1477 | continueLoadAfterNewWindowPolicy(request, formState.get(), frameName, action, shouldContinue, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Suppress); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1478 | }); |
| 1479 | |
simonjam@chromium.org | c98850b | 2012-11-28 01:07:36 +0000 | [diff] [blame] | 1480 | return; |
| 1481 | } |
| 1482 | |
| 1483 | if (!request.hasSubstituteData()) |
| 1484 | request.setSubstituteData(defaultSubstituteDataForURL(request.resourceRequest().url())); |
| 1485 | |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 1486 | Ref<DocumentLoader> loader = m_client.createDocumentLoader(request.resourceRequest(), request.substituteData()); |
jiewen_tan@apple.com | 32abaa6 | 2019-02-13 23:07:13 +0000 | [diff] [blame] | 1487 | loader->setAllowsWebArchiveForMainFrame(request.isRequestFromClientOrUserInput()); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 1488 | addSameSiteInfoToRequestIfNeeded(loader->request()); |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 1489 | applyShouldOpenExternalURLsPolicyToNewDocumentLoader(m_frame, loader, request); |
beidson@apple.com | d055853 | 2015-05-28 04:52:25 +0000 | [diff] [blame] | 1490 | |
cdumez@apple.com | 4353b6e | 2018-10-26 05:06:24 +0000 | [diff] [blame] | 1491 | if (request.shouldTreatAsContinuingLoad()) { |
cdumez@apple.com | 05911a3 | 2018-10-23 17:54:34 +0000 | [diff] [blame] | 1492 | loader->setClientRedirectSourceForHistory(request.clientRedirectSourceForHistory()); |
cdumez@apple.com | 4353b6e | 2018-10-26 05:06:24 +0000 | [diff] [blame] | 1493 | if (request.lockBackForwardList() == LockBackForwardList::Yes) { |
| 1494 | loader->setIsClientRedirect(true); |
| 1495 | m_loadType = FrameLoadType::RedirectWithLockedBackForwardList; |
| 1496 | } |
cdumez@apple.com | 05911a3 | 2018-10-23 17:54:34 +0000 | [diff] [blame] | 1497 | } |
| 1498 | |
cdumez@apple.com | 3aedc03 | 2019-01-31 02:23:55 +0000 | [diff] [blame] | 1499 | SetForScope<LoadContinuingState> continuingLoadGuard(m_currentLoadContinuingState, request.shouldTreatAsContinuingLoad() ? LoadContinuingState::ContinuingWithRequest : LoadContinuingState::NotContinuing); |
achristensen@apple.com | 10e4a7b | 2018-11-28 21:14:43 +0000 | [diff] [blame] | 1500 | load(loader.get()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
commit-queue@webkit.org | a4a9ce2 | 2019-04-10 22:56:35 +0000 | [diff] [blame] | 1503 | void FrameLoader::loadWithNavigationAction(const ResourceRequest& request, NavigationAction&& action, LockHistory lockHistory, FrameLoadType type, RefPtr<FormState>&& formState, AllowNavigationToInvalidURL allowNavigationToInvalidURL, const String& downloadAttribute, CompletionHandler<void()>&& completionHandler) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1504 | { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1505 | RELEASE_LOG_IF_ALLOWED("loadWithNavigationAction: frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 1506 | |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 1507 | Ref<DocumentLoader> loader = m_client.createDocumentLoader(request, defaultSubstituteDataForURL(request.url())); |
commit-queue@webkit.org | a4a9ce2 | 2019-04-10 22:56:35 +0000 | [diff] [blame] | 1508 | loader->setDownloadAttribute(downloadAttribute); |
dbates@webkit.org | 9692a07 | 2017-07-12 18:01:19 +0000 | [diff] [blame] | 1509 | applyShouldOpenExternalURLsPolicyToNewDocumentLoader(m_frame, loader, action.initiatedByMainFrame(), action.shouldOpenExternalURLsPolicy()); |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 1510 | |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 1511 | if (lockHistory == LockHistory::Yes && m_documentLoader) |
commit-queue@webkit.org | 63040d0 | 2011-03-26 00:30:40 +0000 | [diff] [blame] | 1512 | loader->setClientRedirectSourceForHistory(m_documentLoader->didCreateGlobalHistoryEntry() ? m_documentLoader->urlForHistory().string() : m_documentLoader->clientRedirectSourceForHistory()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1513 | |
cdumez@apple.com | 91e03bd | 2018-09-17 17:15:07 +0000 | [diff] [blame] | 1514 | loader->setTriggeringAction(WTFMove(action)); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1515 | if (m_documentLoader) |
| 1516 | loader->setOverrideEncoding(m_documentLoader->overrideEncoding()); |
| 1517 | |
achristensen@apple.com | 10e4a7b | 2018-11-28 21:14:43 +0000 | [diff] [blame] | 1518 | loadWithDocumentLoader(loader.ptr(), type, WTFMove(formState), allowNavigationToInvalidURL, ShouldTreatAsContinuingLoad::No, WTFMove(completionHandler)); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
achristensen@apple.com | 10e4a7b | 2018-11-28 21:14:43 +0000 | [diff] [blame] | 1521 | void FrameLoader::load(DocumentLoader& newDocumentLoader) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1522 | { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1523 | RELEASE_LOG_IF_ALLOWED("load (DocumentLoader): frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 1524 | |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1525 | ResourceRequest& r = newDocumentLoader.request(); |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 1526 | addExtraFieldsToMainResourceRequest(r); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1527 | FrameLoadType type; |
| 1528 | |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1529 | if (shouldTreatURLAsSameAsCurrent(newDocumentLoader.originalRequest().url())) { |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 1530 | r.setCachePolicy(ResourceRequestCachePolicy::ReloadIgnoringCacheData); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1531 | type = FrameLoadType::Same; |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1532 | } else if (shouldTreatURLAsSameAsCurrent(newDocumentLoader.unreachableURL()) && isReload(m_loadType)) |
commit-queue@webkit.org | fb4593b | 2018-04-18 17:50:15 +0000 | [diff] [blame] | 1533 | type = m_loadType; |
cdumez@apple.com | 3aedc03 | 2019-01-31 02:23:55 +0000 | [diff] [blame] | 1534 | 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] | 1535 | type = FrameLoadType::RedirectWithLockedBackForwardList; |
jpfau@apple.com | 6e5a605 | 2012-07-27 00:52:32 +0000 | [diff] [blame] | 1536 | else |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1537 | type = FrameLoadType::Standard; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1538 | |
| 1539 | if (m_documentLoader) |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1540 | newDocumentLoader.setOverrideEncoding(m_documentLoader->overrideEncoding()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1541 | |
| 1542 | // 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] | 1543 | // 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] | 1544 | // is appropriately maintained. |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1545 | // |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1546 | // 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] | 1547 | // shouldn't a more explicit type of reload be defined, that means roughly |
| 1548 | // "load without affecting history" ? |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 1549 | if (shouldReloadToHandleUnreachableURL(newDocumentLoader)) { |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1550 | // 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] | 1551 | // In this case we should save the document state now. Otherwise the state can be lost because load type is |
| 1552 | // changed and updateForBackForwardNavigation() will not be called when loading is committed. |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 1553 | history().saveDocumentAndScrollState(); |
commit-queue@webkit.org | 072ac24 | 2011-04-04 17:05:55 +0000 | [diff] [blame] | 1554 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1555 | ASSERT(type == FrameLoadType::Standard); |
| 1556 | type = FrameLoadType::Reload; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
achristensen@apple.com | 10e4a7b | 2018-11-28 21:14:43 +0000 | [diff] [blame] | 1559 | loadWithDocumentLoader(&newDocumentLoader, type, nullptr, AllowNavigationToInvalidURL::Yes, ShouldTreatAsContinuingLoad::No); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
achristensen@apple.com | 10e4a7b | 2018-11-28 21:14:43 +0000 | [diff] [blame] | 1562 | void FrameLoader::loadWithDocumentLoader(DocumentLoader* loader, FrameLoadType type, RefPtr<FormState>&& formState, AllowNavigationToInvalidURL allowNavigationToInvalidURL, ShouldTreatAsContinuingLoad, CompletionHandler<void()>&& completionHandler) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1563 | { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1564 | RELEASE_LOG_IF_ALLOWED("loadWithDocumentLoader: frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 1565 | |
inferno@chromium.org | 6e8e347 | 2010-10-26 13:29:04 +0000 | [diff] [blame] | 1566 | // Retain because dispatchBeforeLoadEvent may release the last reference to it. |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 1567 | Ref<Frame> protect(m_frame); |
inferno@chromium.org | 6e8e347 | 2010-10-26 13:29:04 +0000 | [diff] [blame] | 1568 | |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 1569 | CompletionHandlerCallingScope completionHandlerCaller(WTFMove(completionHandler)); |
| 1570 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1571 | ASSERT(m_client.hasWebView()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1572 | |
| 1573 | // Unfortunately the view must be non-nil, this is ultimately due |
| 1574 | // to parser requiring a FrameView. We should fix this dependency. |
| 1575 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1576 | ASSERT(m_frame.view()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1577 | |
dbates@webkit.org | 872db61 | 2017-03-20 23:07:50 +0000 | [diff] [blame] | 1578 | if (!isNavigationAllowed()) |
abarth@webkit.org | 89fa350 | 2009-09-21 02:30:12 +0000 | [diff] [blame] | 1579 | return; |
| 1580 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1581 | if (m_frame.document()) |
| 1582 | m_previousURL = m_frame.document()->url(); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 1583 | |
cdumez@apple.com | eb4832c | 2017-02-08 15:39:38 +0000 | [diff] [blame] | 1584 | const URL& newURL = loader->request().url(); |
| 1585 | |
jiewen_tan@apple.com | 1306fce | 2018-10-24 18:49:03 +0000 | [diff] [blame] | 1586 | // Only the first iframe navigation or the first iframe navigation after about:blank should be reported. |
| 1587 | // https://www.w3.org/TR/resource-timing-2/#resources-included-in-the-performanceresourcetiming-interface |
keith_miller@apple.com | bb2f61c | 2018-12-01 03:28:36 +0000 | [diff] [blame] | 1588 | if (m_shouldReportResourceTimingToParentFrame && !m_previousURL.isNull() && m_previousURL != WTF::blankURL()) |
jiewen_tan@apple.com | 1306fce | 2018-10-24 18:49:03 +0000 | [diff] [blame] | 1589 | m_shouldReportResourceTimingToParentFrame = false; |
| 1590 | |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1591 | // Log main frame navigation types. |
akling@apple.com | e6549f4 | 2016-12-01 16:15:27 +0000 | [diff] [blame] | 1592 | if (m_frame.isMainFrame()) { |
cdumez@apple.com | c518f7e | 2018-04-03 18:01:41 +0000 | [diff] [blame] | 1593 | if (auto* page = m_frame.page()) { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1594 | RELEASE_LOG_IF_ALLOWED("loadWithDocumentLoader: main frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
cdumez@apple.com | 563f1dc | 2017-04-29 03:55:35 +0000 | [diff] [blame] | 1595 | page->mainFrameLoadStarted(newURL, type); |
cdumez@apple.com | c518f7e | 2018-04-03 18:01:41 +0000 | [diff] [blame] | 1596 | page->performanceLogging().didReachPointOfInterest(PerformanceLogging::MainFrameLoadStarted); |
| 1597 | } |
akling@apple.com | e6549f4 | 2016-12-01 16:15:27 +0000 | [diff] [blame] | 1598 | } |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1599 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1600 | policyChecker().setLoadType(type); |
rniwa@webkit.org | ba12a01 | 2019-02-03 22:48:22 +0000 | [diff] [blame] | 1601 | RELEASE_ASSERT(!isBackForwardLoadType(type) || history().provisionalItem()); |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 1602 | bool isFormSubmission = formState; |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1603 | |
yael.aharon@nokia.com | 79f6905 | 2010-12-30 19:31:00 +0000 | [diff] [blame] | 1604 | const String& httpMethod = loader->request().httpMethod(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1605 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1606 | if (shouldPerformFragmentNavigation(isFormSubmission, httpMethod, policyChecker().loadType(), newURL)) { |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 1607 | RefPtr<DocumentLoader> oldDocumentLoader = m_documentLoader; |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 1608 | NavigationAction action { *m_frame.document(), loader->request(), InitiatedByMainFrame::Unknown, policyChecker().loadType(), isFormSubmission }; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1609 | |
cdumez@apple.com | 91e03bd | 2018-09-17 17:15:07 +0000 | [diff] [blame] | 1610 | oldDocumentLoader->setTriggeringAction(WTFMove(action)); |
andersca@apple.com | 97ab6d9 | 2013-10-21 22:55:14 +0000 | [diff] [blame] | 1611 | oldDocumentLoader->setLastCheckedRequest(ResourceRequest()); |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1612 | policyChecker().stopCheck(); |
rniwa@webkit.org | ba12a01 | 2019-02-03 22:48:22 +0000 | [diff] [blame] | 1613 | RELEASE_ASSERT(!isBackForwardLoadType(policyChecker().loadType()) || history().provisionalItem()); |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 1614 | policyChecker().checkNavigationPolicy(ResourceRequest(loader->request()), ResourceResponse { } /* redirectResponse */, oldDocumentLoader.get(), WTFMove(formState), [this, protectedFrame = makeRef(m_frame)] (const ResourceRequest& request, WeakPtr<FormState>&&, NavigationPolicyDecision navigationPolicyDecision) { |
| 1615 | continueFragmentScrollAfterNavigationPolicy(request, navigationPolicyDecision == NavigationPolicyDecision::ContinueLoad); |
cdumez@apple.com | 8221194 | 2018-04-17 18:13:49 +0000 | [diff] [blame] | 1616 | }, PolicyDecisionMode::Synchronous); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1617 | return; |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 1618 | } |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1619 | |
| 1620 | if (Frame* parent = m_frame.tree().parent()) |
| 1621 | loader->setOverrideEncoding(parent->loader().documentLoader()->overrideEncoding()); |
| 1622 | |
| 1623 | policyChecker().stopCheck(); |
| 1624 | setPolicyDocumentLoader(loader); |
| 1625 | if (loader->triggeringAction().isEmpty()) |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 1626 | 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] | 1627 | |
| 1628 | if (Element* ownerElement = m_frame.ownerElement()) { |
| 1629 | // We skip dispatching the beforeload event if we've already |
| 1630 | // committed a real document load because the event would leak |
| 1631 | // subsequent activity by the frame which the parent frame isn't |
| 1632 | // supposed to learn. For example, if the child frame navigated to |
| 1633 | // a new URL, the parent frame shouldn't learn the URL. |
| 1634 | if (!m_stateMachine.committedFirstRealDocumentLoad() |
| 1635 | && !ownerElement->dispatchBeforeLoadEvent(loader->request().url().string())) { |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 1636 | continueLoadAfterNavigationPolicy(loader->request(), formState.get(), NavigationPolicyDecision::IgnoreLoad, allowNavigationToInvalidURL); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1637 | return; |
| 1638 | } |
| 1639 | } |
| 1640 | |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 1641 | m_frame.navigationScheduler().cancel(NewLoadInProgress::Yes); |
cdumez@apple.com | 22fa18d | 2018-02-28 23:58:22 +0000 | [diff] [blame] | 1642 | |
cdumez@apple.com | 3aedc03 | 2019-01-31 02:23:55 +0000 | [diff] [blame] | 1643 | if (shouldTreatCurrentLoadAsContinuingLoad()) { |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 1644 | continueLoadAfterNavigationPolicy(loader->request(), formState.get(), NavigationPolicyDecision::ContinueLoad, allowNavigationToInvalidURL); |
beidson@apple.com | 1c9022b | 2018-03-21 00:05:58 +0000 | [diff] [blame] | 1645 | return; |
| 1646 | } |
| 1647 | |
rniwa@webkit.org | ba12a01 | 2019-02-03 22:48:22 +0000 | [diff] [blame] | 1648 | RELEASE_ASSERT(!isBackForwardLoadType(policyChecker().loadType()) || history().provisionalItem()); |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 1649 | 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 { |
| 1650 | continueLoadAfterNavigationPolicy(request, formState.get(), navigationPolicyDecision, allowNavigationToInvalidURL); |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 1651 | completionHandler(); |
achristensen@apple.com | 10e4a7b | 2018-11-28 21:14:43 +0000 | [diff] [blame] | 1652 | }, PolicyDecisionMode::Asynchronous); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
cdumez@apple.com | 2e68bb4 | 2018-03-19 22:30:57 +0000 | [diff] [blame] | 1655 | void FrameLoader::clearProvisionalLoadForPolicyCheck() |
| 1656 | { |
cdumez@apple.com | 8ace63b | 2018-06-29 22:56:29 +0000 | [diff] [blame] | 1657 | if (!m_policyDocumentLoader || !m_provisionalDocumentLoader || m_inClearProvisionalLoadForPolicyCheck) |
cdumez@apple.com | 2e68bb4 | 2018-03-19 22:30:57 +0000 | [diff] [blame] | 1658 | return; |
| 1659 | |
cdumez@apple.com | 8ace63b | 2018-06-29 22:56:29 +0000 | [diff] [blame] | 1660 | SetForScope<bool> change(m_inClearProvisionalLoadForPolicyCheck, true); |
cdumez@apple.com | 2e68bb4 | 2018-03-19 22:30:57 +0000 | [diff] [blame] | 1661 | m_provisionalDocumentLoader->stopLoading(); |
| 1662 | setProvisionalDocumentLoader(nullptr); |
| 1663 | } |
| 1664 | |
aroben@apple.com | 92cfa90 | 2008-04-16 19:19:00 +0000 | [diff] [blame] | 1665 | void FrameLoader::reportLocalLoadFailed(Frame* frame, const String& url) |
kmccullo | 23d362f | 2007-04-06 01:05:58 +0000 | [diff] [blame] | 1666 | { |
| 1667 | ASSERT(!url.isEmpty()); |
aroben@apple.com | 92cfa90 | 2008-04-16 19:19:00 +0000 | [diff] [blame] | 1668 | if (!frame) |
| 1669 | return; |
| 1670 | |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 1671 | 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] | 1672 | } |
| 1673 | |
bfulgham@apple.com | b4c7093 | 2016-01-06 22:07:51 +0000 | [diff] [blame] | 1674 | void FrameLoader::reportBlockedPortFailed(Frame* frame, const String& url) |
| 1675 | { |
| 1676 | ASSERT(!url.isEmpty()); |
| 1677 | if (!frame) |
| 1678 | return; |
| 1679 | |
| 1680 | frame->document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Not allowed to use restricted network port: " + url); |
| 1681 | } |
| 1682 | |
dbates@webkit.org | 3c1f25a | 2018-02-07 18:56:02 +0000 | [diff] [blame] | 1683 | void FrameLoader::reportAuthenticationChallengeBlocked(Frame* frame, const URL& url, const String& reason) |
| 1684 | { |
| 1685 | if (!frame) |
| 1686 | return; |
| 1687 | |
| 1688 | frame->document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, makeString("Blocked ", url.stringCenterEllipsizedToLength(), " from asking for credentials because ", reason, '.')); |
| 1689 | } |
| 1690 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1691 | const ResourceRequest& FrameLoader::initialRequest() const |
| 1692 | { |
andersca@apple.com | 48ffa33 | 2008-03-13 19:08:06 +0000 | [diff] [blame] | 1693 | return activeDocumentLoader()->originalRequest(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1694 | } |
| 1695 | |
drousso@apple.com | 21748ed | 2018-10-08 18:25:52 +0000 | [diff] [blame] | 1696 | bool FrameLoader::willLoadMediaElementURL(URL& url, Node& initiatorNode) |
weinig@apple.com | 6893525 | 2009-10-07 02:48:12 +0000 | [diff] [blame] | 1697 | { |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 1698 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1699 | // MobileStore depends on the iOS 4.0 era client delegate method because webView:resource:willSendRequest:redirectResponse:fromDataSource |
| 1700 | // 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] | 1701 | if (IOSApplication::isMobileStore()) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1702 | return m_client.shouldLoadMediaElementURL(url); |
| 1703 | #endif |
| 1704 | |
weinig@apple.com | 6893525 | 2009-10-07 02:48:12 +0000 | [diff] [blame] | 1705 | ResourceRequest request(url); |
drousso@apple.com | 21748ed | 2018-10-08 18:25:52 +0000 | [diff] [blame] | 1706 | request.setInspectorInitiatorNodeIdentifier(InspectorInstrumentation::identifierForNode(initiatorNode)); |
weinig@apple.com | 6893525 | 2009-10-07 02:48:12 +0000 | [diff] [blame] | 1707 | |
| 1708 | unsigned long identifier; |
| 1709 | ResourceError error; |
| 1710 | requestFromDelegate(request, identifier, error); |
antti@apple.com | 021dc01 | 2014-09-04 20:00:11 +0000 | [diff] [blame] | 1711 | 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] | 1712 | |
| 1713 | url = request.url(); |
| 1714 | |
| 1715 | return error.isNull(); |
| 1716 | } |
| 1717 | |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1718 | bool FrameLoader::shouldReloadToHandleUnreachableURL(DocumentLoader& docLoader) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1719 | { |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1720 | URL unreachableURL = docLoader.unreachableURL(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1721 | |
| 1722 | if (unreachableURL.isEmpty()) |
| 1723 | return false; |
| 1724 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1725 | if (!isBackForwardLoadType(policyChecker().loadType())) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1726 | return false; |
| 1727 | |
| 1728 | // We only treat unreachableURLs specially during the delegate callbacks |
| 1729 | // for provisional load errors and navigation policy decisions. The former |
| 1730 | // case handles well-formed URLs that can't be loaded, and the latter |
| 1731 | // case handles malformed URLs and unknown schemes. Loading alternate content |
| 1732 | // at other times behaves like a standard load. |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1733 | if (policyChecker().delegateIsDecidingNavigationPolicy() || policyChecker().delegateIsHandlingUnimplementablePolicy()) |
mitz@apple.com | 6699e27 | 2015-05-01 23:47:03 +0000 | [diff] [blame] | 1734 | return m_policyDocumentLoader && unreachableURL == m_policyDocumentLoader->request().url(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1735 | |
mitz@apple.com | 6699e27 | 2015-05-01 23:47:03 +0000 | [diff] [blame] | 1736 | return unreachableURL == m_provisionalLoadErrorBeingHandledURL; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
ggaren@apple.com | 3eaa7c0 | 2009-01-29 07:38:54 +0000 | [diff] [blame] | 1739 | void FrameLoader::reloadWithOverrideEncoding(const String& encoding) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1740 | { |
| 1741 | if (!m_documentLoader) |
| 1742 | return; |
| 1743 | |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1744 | RELEASE_LOG_IF_ALLOWED("reloadWithOverrideEncoding: frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 1745 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1746 | ResourceRequest request = m_documentLoader->request(); |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1747 | URL unreachableURL = m_documentLoader->unreachableURL(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1748 | if (!unreachableURL.isEmpty()) |
| 1749 | request.setURL(unreachableURL); |
| 1750 | |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 1751 | // FIXME: If the resource is a result of form submission and is not cached, the form will be silently resubmitted. |
| 1752 | // We should ask the user for confirmation in this case. |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 1753 | request.setCachePolicy(ResourceRequestCachePolicy::ReturnCacheDataElseLoad); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1754 | |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 1755 | Ref<DocumentLoader> loader = m_client.createDocumentLoader(request, defaultSubstituteDataForURL(request.url())); |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 1756 | applyShouldOpenExternalURLsPolicyToNewDocumentLoader(m_frame, loader, InitiatedByMainFrame::Unknown, m_documentLoader->shouldOpenExternalURLsPolicyToPropagate()); |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 1757 | |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 1758 | setPolicyDocumentLoader(loader.ptr()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1759 | |
| 1760 | loader->setOverrideEncoding(encoding); |
| 1761 | |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1762 | loadWithDocumentLoader(loader.ptr(), FrameLoadType::Reload, { }, AllowNavigationToInvalidURL::Yes, ShouldTreatAsContinuingLoad::No); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1763 | } |
| 1764 | |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 1765 | void FrameLoader::reload(OptionSet<ReloadOption> options) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1766 | { |
| 1767 | if (!m_documentLoader) |
| 1768 | return; |
| 1769 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1770 | // If a window is created by javascript, its main frame can have an empty but non-nil URL. |
| 1771 | // Reloading in this case will lose the current contents (see 4151001). |
darin@chromium.org | 4824685 | 2008-11-04 19:40:56 +0000 | [diff] [blame] | 1772 | if (m_documentLoader->request().url().isEmpty()) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1773 | return; |
| 1774 | |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1775 | RELEASE_LOG_IF_ALLOWED("reload: frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 1776 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1777 | // 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] | 1778 | ResourceRequest initialRequest = m_documentLoader->request(); |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1779 | URL unreachableURL = m_documentLoader->unreachableURL(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1780 | if (!unreachableURL.isEmpty()) |
darin@chromium.org | 4824685 | 2008-11-04 19:40:56 +0000 | [diff] [blame] | 1781 | initialRequest.setURL(unreachableURL); |
commit-queue@webkit.org | 2090e27 | 2012-06-28 16:05:43 +0000 | [diff] [blame] | 1782 | |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1783 | // Create a new document loader for the reload, this will become m_documentLoader eventually, |
| 1784 | // but first it has to be the "policy" document loader, and then the "provisional" document loader. |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 1785 | Ref<DocumentLoader> loader = m_client.createDocumentLoader(initialRequest, defaultSubstituteDataForURL(initialRequest.url())); |
jiewen_tan@apple.com | 32abaa6 | 2019-02-13 23:07:13 +0000 | [diff] [blame] | 1786 | loader->setAllowsWebArchiveForMainFrame(m_documentLoader->allowsWebArchiveForMainFrame()); |
dbates@webkit.org | dc3a7cf | 2017-07-12 17:12:07 +0000 | [diff] [blame] | 1787 | applyShouldOpenExternalURLsPolicyToNewDocumentLoader(m_frame, loader, InitiatedByMainFrame::Unknown, m_documentLoader->shouldOpenExternalURLsPolicyToPropagate()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1788 | |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 1789 | loader->setUserContentExtensionsEnabled(!options.contains(ReloadOption::DisableContentBlockers)); |
achristensen@apple.com | d40e0ba | 2015-10-14 20:03:14 +0000 | [diff] [blame] | 1790 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1791 | ResourceRequest& request = loader->request(); |
| 1792 | |
commit-queue@webkit.org | 4833ac5 | 2018-02-26 17:38:14 +0000 | [diff] [blame] | 1793 | // 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] | 1794 | request.setCachePolicy(ResourceRequestCachePolicy::ReloadIgnoringCacheData); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1795 | |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 1796 | addSameSiteInfoToRequestIfNeeded(request); |
| 1797 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1798 | // If we're about to re-post, set up action so the application can warn the user. |
| 1799 | if (request.httpMethod() == "POST") |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 1800 | loader->setTriggeringAction({ *m_frame.document(), request, InitiatedByMainFrame::Unknown, NavigationType::FormResubmitted }); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1801 | |
| 1802 | loader->setOverrideEncoding(m_documentLoader->overrideEncoding()); |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 1803 | |
| 1804 | auto frameLoadTypeForReloadOptions = [] (auto options) { |
antti@apple.com | eb7081d | 2018-05-09 07:05:46 +0000 | [diff] [blame] | 1805 | if (options & ReloadOption::FromOrigin) |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 1806 | return FrameLoadType::ReloadFromOrigin; |
antti@apple.com | eb7081d | 2018-05-09 07:05:46 +0000 | [diff] [blame] | 1807 | if (options & ReloadOption::ExpiredOnly) |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 1808 | return FrameLoadType::ReloadExpiredOnly; |
| 1809 | return FrameLoadType::Reload; |
| 1810 | }; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1811 | |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 1812 | loadWithDocumentLoader(loader.ptr(), frameLoadTypeForReloadOptions(options), { }, AllowNavigationToInvalidURL::Yes, ShouldTreatAsContinuingLoad::No); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1813 | } |
| 1814 | |
ajuma@chromium.org | edd7574 | 2019-09-11 14:52:18 +0000 | [diff] [blame] | 1815 | void FrameLoader::stopAllLoaders(ClearProvisionalItemPolicy clearProvisionalItemPolicy, StopLoadingPolicy stopLoadingPolicy) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1816 | { |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 1817 | if (m_frame.document() && m_frame.document()->backForwardCacheState() == Document::InBackForwardCache) |
cdumez@apple.com | a0010ff | 2018-12-13 23:17:44 +0000 | [diff] [blame] | 1818 | return; |
| 1819 | |
ajuma@chromium.org | edd7574 | 2019-09-11 14:52:18 +0000 | [diff] [blame] | 1820 | if (stopLoadingPolicy == StopLoadingPolicy::PreventDuringUnloadEvents && !isStopLoadingAllowed()) |
weinig@apple.com | f239bbf | 2009-04-09 18:30:32 +0000 | [diff] [blame] | 1821 | return; |
| 1822 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1823 | // If this method is called from within this method, infinite recursion can occur (3442218). Avoid this. |
| 1824 | if (m_inStopAllLoaders) |
| 1825 | return; |
pvollan@apple.com | 8f4bcd95 | 2018-02-01 04:18:38 +0000 | [diff] [blame] | 1826 | |
| 1827 | // This method might dispatch events. |
| 1828 | RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(ScriptDisallowedScope::InMainThread::isScriptAllowed()); |
| 1829 | |
inferno@chromium.org | bc05aa5 | 2012-08-06 16:30:40 +0000 | [diff] [blame] | 1830 | // Calling stopLoading() on the provisional document loader can blow away |
| 1831 | // the frame from underneath. |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 1832 | Ref<Frame> protect(m_frame); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1833 | |
| 1834 | m_inStopAllLoaders = true; |
| 1835 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1836 | policyChecker().stopCheck(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1837 | |
commit-queue@webkit.org | 987fd77 | 2011-01-21 18:26:42 +0000 | [diff] [blame] | 1838 | // If no new load is in progress, we should clear the provisional item from history |
| 1839 | // before we call stopLoading. |
| 1840 | if (clearProvisionalItemPolicy == ShouldClearProvisionalItem) |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 1841 | history().setProvisionalItem(nullptr); |
commit-queue@webkit.org | 987fd77 | 2011-01-21 18:26:42 +0000 | [diff] [blame] | 1842 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1843 | 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] | 1844 | child->loader().stopAllLoaders(clearProvisionalItemPolicy); |
darin | 7208e93 | 2007-02-13 17:52:53 +0000 | [diff] [blame] | 1845 | if (m_provisionalDocumentLoader) |
commit-queue@webkit.org | fc5833b | 2011-02-23 06:58:46 +0000 | [diff] [blame] | 1846 | m_provisionalDocumentLoader->stopLoading(); |
beidson@apple.com | 4642121 | 2008-08-25 21:48:56 +0000 | [diff] [blame] | 1847 | if (m_documentLoader) |
commit-queue@webkit.org | fc5833b | 2011-02-23 06:58:46 +0000 | [diff] [blame] | 1848 | m_documentLoader->stopLoading(); |
beidson@apple.com | 4642121 | 2008-08-25 21:48:56 +0000 | [diff] [blame] | 1849 | |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 1850 | setProvisionalDocumentLoader(nullptr); |
darin | 7208e93 | 2007-02-13 17:52:53 +0000 | [diff] [blame] | 1851 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1852 | m_inStopAllLoaders = false; |
| 1853 | } |
| 1854 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 1855 | void FrameLoader::stopForBackForwardCache() |
cdumez@apple.com | e16aaf0 | 2019-10-03 22:16:46 +0000 | [diff] [blame] | 1856 | { |
cdumez@apple.com | e16aaf0 | 2019-10-03 22:16:46 +0000 | [diff] [blame] | 1857 | // Stop provisional loads in subframes (The one in the main frame is about to be committed). |
| 1858 | if (!m_frame.isMainFrame()) { |
| 1859 | if (m_provisionalDocumentLoader) |
| 1860 | m_provisionalDocumentLoader->stopLoading(); |
| 1861 | setProvisionalDocumentLoader(nullptr); |
| 1862 | } |
| 1863 | |
| 1864 | // Stop current loads. |
| 1865 | if (m_documentLoader) |
| 1866 | m_documentLoader->stopLoading(); |
| 1867 | |
| 1868 | 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^] | 1869 | child->loader().stopForBackForwardCache(); |
cdumez@apple.com | 6cbf70a | 2019-10-11 20:26:15 +0000 | [diff] [blame] | 1870 | |
cdumez@apple.com | 7e7b879 | 2019-10-11 23:29:02 +0000 | [diff] [blame] | 1871 | // We cancel pending navigations & policy checks *after* cancelling loads because cancelling loads might end up |
| 1872 | // running script, which could schedule new navigations. |
cdumez@apple.com | 6cbf70a | 2019-10-11 20:26:15 +0000 | [diff] [blame] | 1873 | policyChecker().stopCheck(); |
| 1874 | m_frame.navigationScheduler().cancel(); |
cdumez@apple.com | e16aaf0 | 2019-10-03 22:16:46 +0000 | [diff] [blame] | 1875 | } |
| 1876 | |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 1877 | void FrameLoader::stopAllLoadersAndCheckCompleteness() |
| 1878 | { |
| 1879 | stopAllLoaders(); |
| 1880 | |
| 1881 | if (!m_checkTimer.isActive()) |
| 1882 | return; |
| 1883 | |
| 1884 | m_checkTimer.stop(); |
| 1885 | m_checkingLoadCompleteForDetachment = true; |
| 1886 | checkCompletenessNow(); |
| 1887 | m_checkingLoadCompleteForDetachment = false; |
| 1888 | } |
| 1889 | |
beidson | 398923b | 2007-07-31 20:29:02 +0000 | [diff] [blame] | 1890 | void FrameLoader::stopForUserCancel(bool deferCheckLoadComplete) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 1891 | { |
bfulgham@apple.com | 98845d9 | 2016-05-17 01:09:27 +0000 | [diff] [blame] | 1892 | // Calling stopAllLoaders can cause the frame to be deallocated, including the frame loader. |
| 1893 | Ref<Frame> protectedFrame(m_frame); |
| 1894 | |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 1895 | stopAllLoaders(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1896 | |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 1897 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1898 | // Lay out immediately when stopping to immediately clear the old page if we just committed this one |
| 1899 | // but haven't laid out/painted yet. |
| 1900 | // FIXME: Is this behavior specific to iOS? Or should we expose a setting to toggle this behavior? |
| 1901 | if (m_frame.view() && !m_frame.view()->didFirstLayout()) |
zalan@apple.com | 6116e6d | 2017-10-28 15:24:58 +0000 | [diff] [blame] | 1902 | m_frame.view()->layoutContext().layout(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1903 | #endif |
| 1904 | |
beidson | 398923b | 2007-07-31 20:29:02 +0000 | [diff] [blame] | 1905 | if (deferCheckLoadComplete) |
| 1906 | scheduleCheckLoadComplete(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1907 | else if (m_frame.page()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 1908 | checkLoadComplete(); |
| 1909 | } |
| 1910 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1911 | DocumentLoader* FrameLoader::activeDocumentLoader() const |
| 1912 | { |
| 1913 | if (m_state == FrameStateProvisional) |
| 1914 | return m_provisionalDocumentLoader.get(); |
| 1915 | return m_documentLoader.get(); |
| 1916 | } |
| 1917 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1918 | bool FrameLoader::isLoading() const |
| 1919 | { |
darin | 8207db4 | 2007-02-20 18:18:39 +0000 | [diff] [blame] | 1920 | DocumentLoader* docLoader = activeDocumentLoader(); |
| 1921 | if (!docLoader) |
| 1922 | return false; |
japhet@chromium.org | 4bcb80b | 2012-03-26 20:34:00 +0000 | [diff] [blame] | 1923 | return docLoader->isLoading(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1924 | } |
| 1925 | |
mjs | 7545bb5 | 2007-05-15 08:24:53 +0000 | [diff] [blame] | 1926 | bool FrameLoader::frameHasLoaded() const |
| 1927 | { |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 1928 | return m_stateMachine.committedFirstRealDocumentLoad() || (m_provisionalDocumentLoader && !m_stateMachine.creatingInitialEmptyDocument()); |
mjs | 7545bb5 | 2007-05-15 08:24:53 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1931 | void FrameLoader::setDocumentLoader(DocumentLoader* loader) |
| 1932 | { |
| 1933 | if (!loader && !m_documentLoader) |
| 1934 | return; |
cdumez@apple.com | a0010ff | 2018-12-13 23:17:44 +0000 | [diff] [blame] | 1935 | |
| 1936 | if (loader == m_documentLoader) |
| 1937 | return; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1938 | |
| 1939 | ASSERT(loader != m_documentLoader); |
| 1940 | ASSERT(!loader || loader->frameLoader() == this); |
| 1941 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1942 | m_client.prepareForDataSourceReplacement(); |
darin | c3d2605 | 2007-03-22 18:17:12 +0000 | [diff] [blame] | 1943 | detachChildren(); |
japhet@chromium.org | a9a58bb | 2012-09-01 01:09:02 +0000 | [diff] [blame] | 1944 | |
| 1945 | // detachChildren() can trigger this frame's unload event, and therefore |
| 1946 | // script can run and do just about anything. For example, an unload event that calls |
| 1947 | // document.write("") on its parent frame can lead to a recursive detachChildren() |
| 1948 | // invocation for this frame. In that case, we can end up at this point with a |
| 1949 | // loader that hasn't been deleted but has been detached from its frame. Such a |
| 1950 | // DocumentLoader has been sufficiently detached that we'll end up in an inconsistent |
| 1951 | // state if we try to use it. |
| 1952 | if (loader && !loader->frame()) |
| 1953 | return; |
| 1954 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1955 | if (m_documentLoader) |
| 1956 | m_documentLoader->detachFromFrame(); |
| 1957 | |
| 1958 | m_documentLoader = loader; |
| 1959 | } |
| 1960 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1961 | void FrameLoader::setPolicyDocumentLoader(DocumentLoader* loader) |
| 1962 | { |
| 1963 | if (m_policyDocumentLoader == loader) |
| 1964 | return; |
| 1965 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1966 | if (loader) |
beidson@apple.com | 10a537f | 2015-07-09 22:30:42 +0000 | [diff] [blame] | 1967 | loader->attachToFrame(m_frame); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1968 | if (m_policyDocumentLoader |
| 1969 | && m_policyDocumentLoader != m_provisionalDocumentLoader |
| 1970 | && m_policyDocumentLoader != m_documentLoader) |
| 1971 | m_policyDocumentLoader->detachFromFrame(); |
| 1972 | |
| 1973 | m_policyDocumentLoader = loader; |
| 1974 | } |
eric@webkit.org | 14774f4 | 2008-04-21 17:50:37 +0000 | [diff] [blame] | 1975 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1976 | void FrameLoader::setProvisionalDocumentLoader(DocumentLoader* loader) |
| 1977 | { |
| 1978 | ASSERT(!loader || !m_provisionalDocumentLoader); |
| 1979 | ASSERT(!loader || loader->frameLoader() == this); |
| 1980 | |
| 1981 | if (m_provisionalDocumentLoader && m_provisionalDocumentLoader != m_documentLoader) |
| 1982 | m_provisionalDocumentLoader->detachFromFrame(); |
| 1983 | |
| 1984 | m_provisionalDocumentLoader = loader; |
| 1985 | } |
| 1986 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1987 | void FrameLoader::setState(FrameState newState) |
akling@apple.com | e6549f4 | 2016-12-01 16:15:27 +0000 | [diff] [blame] | 1988 | { |
| 1989 | FrameState oldState = m_state; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1990 | m_state = newState; |
| 1991 | |
| 1992 | if (newState == FrameStateProvisional) |
| 1993 | provisionalLoadStarted(); |
| 1994 | else if (newState == FrameStateComplete) { |
| 1995 | frameLoadCompleted(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1996 | if (m_documentLoader) |
| 1997 | m_documentLoader->stopRecordingResponses(); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 1998 | if (m_frame.isMainFrame() && oldState != newState) { |
| 1999 | RELEASE_LOG_IF_ALLOWED("setState: main frame load completed (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
cdumez@apple.com | c518f7e | 2018-04-03 18:01:41 +0000 | [diff] [blame] | 2000 | m_frame.page()->performanceLogging().didReachPointOfInterest(PerformanceLogging::MainFrameLoadCompleted); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 2001 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2002 | } |
| 2003 | } |
| 2004 | |
| 2005 | void FrameLoader::clearProvisionalLoad() |
| 2006 | { |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 2007 | setProvisionalDocumentLoader(nullptr); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 2008 | m_progressTracker->progressCompleted(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2009 | setState(FrameStateComplete); |
| 2010 | } |
| 2011 | |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 2012 | void FrameLoader::commitProvisionalLoad() |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2013 | { |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2014 | RefPtr<DocumentLoader> pdl = m_provisionalDocumentLoader; |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 2015 | Ref<Frame> protect(m_frame); |
beidson@apple.com | 3a5e3b9 | 2009-01-27 08:05:59 +0000 | [diff] [blame] | 2016 | |
andersca@apple.com | e776c2f | 2014-01-18 01:47:19 +0000 | [diff] [blame] | 2017 | std::unique_ptr<CachedPage> cachedPage; |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 2018 | if (m_loadingFromCachedPage && history().provisionalItem()) |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 2019 | cachedPage = BackForwardCache::singleton().take(*history().provisionalItem(), m_frame.page()); |
akling@apple.com | 9663f4b | 2013-09-05 21:25:32 +0000 | [diff] [blame] | 2020 | |
cdumez@apple.com | 524b8aa | 2019-10-15 05:28:55 +0000 | [diff] [blame] | 2021 | 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] | 2022 | m_frame.document() ? m_frame.document()->url().stringCenterEllipsizedToLength().utf8().data() : "", |
beidson@apple.com | 69caeee | 2018-04-20 04:55:32 +0000 | [diff] [blame] | 2023 | pdl ? pdl->url().stringCenterEllipsizedToLength().utf8().data() : "<no provisional DocumentLoader>", cachedPage.get()); |
beidson@apple.com | 3a5e3b9 | 2009-01-27 08:05:59 +0000 | [diff] [blame] | 2024 | |
ap@apple.com | e042b63 | 2013-05-17 20:04:43 +0000 | [diff] [blame] | 2025 | willTransitionToCommitted(); |
| 2026 | |
cdumez@apple.com | a0010ff | 2018-12-13 23:17:44 +0000 | [diff] [blame] | 2027 | if (!m_frame.tree().parent() && history().currentItem() && history().currentItem() != history().provisionalItem()) { |
akling@apple.com | af7f33b | 2016-02-06 17:00:30 +0000 | [diff] [blame] | 2028 | // Check to see if we need to cache the page we are navigating away from into the back/forward cache. |
| 2029 | // 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^] | 2030 | BackForwardCache::singleton().addIfCacheable(*history().currentItem(), m_frame.page()); |
cdumez@apple.com | 8420ada | 2016-06-21 17:05:48 +0000 | [diff] [blame] | 2031 | |
carlosgc@webkit.org | 32a60dd | 2016-11-10 14:24:26 +0000 | [diff] [blame] | 2032 | WebCore::jettisonExpensiveObjectsOnTopLevelNavigation(); |
akling@apple.com | af7f33b | 2016-02-06 17:00:30 +0000 | [diff] [blame] | 2033 | } |
| 2034 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2035 | if (m_loadType != FrameLoadType::Replace) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2036 | closeOldDataSources(); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 2037 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 2038 | if (!cachedPage && !m_stateMachine.creatingInitialEmptyDocument()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2039 | m_client.makeRepresentation(pdl.get()); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 2040 | |
akling@apple.com | 9663f4b | 2013-09-05 21:25:32 +0000 | [diff] [blame] | 2041 | transitionToCommitted(cachedPage.get()); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 2042 | |
abarth@webkit.org | f12783f | 2012-10-03 19:34:30 +0000 | [diff] [blame] | 2043 | if (pdl && m_documentLoader) { |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 2044 | // 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] | 2045 | Ref<SecurityOrigin> securityOrigin(SecurityOrigin::create(pdl->request().url())); |
akling@apple.com | 5a7607f | 2015-01-21 22:33:49 +0000 | [diff] [blame] | 2046 | m_documentLoader->timing().setHasSameOriginAsPreviousDocument(securityOrigin.get().canRequest(m_previousURL)); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 2047 | } |
| 2048 | |
beidson | b72fe2e | 2007-05-03 21:35:24 +0000 | [diff] [blame] | 2049 | // 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] | 2050 | // status has changed, if there was a redirect. The frame load delegate may have saved some state about |
| 2051 | // the redirect in its -webView:willPerformClientRedirectToURL:delay:fireDate:forFrame:. Since we are |
| 2052 | // just about to commit a new page, there cannot possibly be a pending redirect at this point. |
| 2053 | if (m_sentRedirectNotification) |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 2054 | clientRedirectCancelledOrFinished(NewLoadInProgress::No); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2055 | |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 2056 | if (cachedPage && cachedPage->document()) { |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 2057 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2058 | // FIXME: CachedPage::restore() would dispatch viewport change notification. However UIKit expects load |
| 2059 | // commit to happen before any changes to viewport arguments and dealing with this there is difficult. |
| 2060 | m_frame.page()->chrome().setDispatchViewportDataDidChangeSuppressed(true); |
| 2061 | #endif |
dbates@webkit.org | cd75cb6 | 2017-03-15 22:44:59 +0000 | [diff] [blame] | 2062 | willRestoreFromCachedPage(); |
commit-queue@webkit.org | cbb6a49 | 2010-09-20 20:20:25 +0000 | [diff] [blame] | 2063 | |
carlosgc@webkit.org | 72eb796 | 2016-01-12 08:23:36 +0000 | [diff] [blame] | 2064 | // Start request for the main resource and dispatch didReceiveResponse before the load is committed for |
| 2065 | // consistency with all other loads. See https://bugs.webkit.org/show_bug.cgi?id=150927. |
| 2066 | ResourceError mainResouceError; |
| 2067 | unsigned long mainResourceIdentifier; |
| 2068 | ResourceRequest mainResourceRequest(cachedPage->documentLoader()->request()); |
| 2069 | requestFromDelegate(mainResourceRequest, mainResourceIdentifier, mainResouceError); |
| 2070 | notifier().dispatchDidReceiveResponse(cachedPage->documentLoader(), mainResourceIdentifier, cachedPage->documentLoader()->response()); |
| 2071 | |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 2072 | Optional<HasInsecureContent> hasInsecureContent = cachedPage->cachedMainFrame()->hasInsecureContent(); |
beidson@apple.com | 4322db0 | 2016-09-16 00:27:11 +0000 | [diff] [blame] | 2073 | |
cdumez@apple.com | 5c7c1f3 | 2019-01-16 20:40:02 +0000 | [diff] [blame] | 2074 | dispatchDidCommitLoad(hasInsecureContent); |
| 2075 | |
dbates@webkit.org | 1fecb92 | 2017-03-25 01:13:23 +0000 | [diff] [blame] | 2076 | // FIXME: This API should be turned around so that we ground CachedPage into the Page. |
| 2077 | cachedPage->restore(*m_frame.page()); |
commit-queue@webkit.org | 1686e5d | 2012-10-19 23:13:08 +0000 | [diff] [blame] | 2078 | |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 2079 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2080 | m_frame.page()->chrome().setDispatchViewportDataDidChangeSuppressed(false); |
| 2081 | m_frame.page()->chrome().dispatchViewportPropertiesDidChange(m_frame.page()->viewportArguments()); |
| 2082 | #endif |
wenson_hsieh@apple.com | 0c72417 | 2018-05-15 01:07:36 +0000 | [diff] [blame] | 2083 | m_frame.page()->chrome().dispatchDisabledAdaptationsDidChange(m_frame.page()->disabledAdaptations()); |
darin@apple.com | 961f2a5 | 2016-12-31 09:51:29 +0000 | [diff] [blame] | 2084 | |
| 2085 | auto& title = m_documentLoader->title(); |
| 2086 | if (!title.string.isNull()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2087 | m_client.dispatchDidReceiveTitle(title); |
commit-queue@webkit.org | cbb6a49 | 2010-09-20 20:20:25 +0000 | [diff] [blame] | 2088 | |
carlosgc@webkit.org | 72eb796 | 2016-01-12 08:23:36 +0000 | [diff] [blame] | 2089 | // Send remaining notifications for the main resource. |
| 2090 | notifier().sendRemainingDelegateMessages(m_documentLoader.get(), mainResourceIdentifier, mainResourceRequest, ResourceResponse(), |
| 2091 | nullptr, static_cast<int>(m_documentLoader->response().expectedContentLength()), 0, mainResouceError); |
| 2092 | |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 2093 | checkCompleted(); |
akling@apple.com | 9663f4b | 2013-09-05 21:25:32 +0000 | [diff] [blame] | 2094 | } else |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 2095 | didOpenURL(); |
beidson@apple.com | 3a5e3b9 | 2009-01-27 08:05:59 +0000 | [diff] [blame] | 2096 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2097 | 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] | 2098 | m_frame.document() ? m_frame.document()->url().stringCenterEllipsizedToLength().utf8().data() : ""); |
beidson@apple.com | 3a5e3b9 | 2009-01-27 08:05:59 +0000 | [diff] [blame] | 2099 | |
Hironori.Fujii@sony.com | 2253a9d | 2018-07-02 01:52:14 +0000 | [diff] [blame] | 2100 | if (m_loadType == FrameLoadType::Standard && m_documentLoader && m_documentLoader->isClientRedirect()) |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2101 | history().updateForClientRedirect(); |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2102 | |
beidson@apple.com | ac095c0 | 2009-08-18 01:37:56 +0000 | [diff] [blame] | 2103 | if (m_loadingFromCachedPage) { |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2104 | // 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] | 2105 | if (auto* page = m_frame.page()) |
| 2106 | page->chrome().didReceiveDocType(m_frame); |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 2107 | m_frame.document()->resume(ReasonForSuspension::BackForwardCache); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2108 | |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2109 | // Force a layout to update view size and thereby update scrollbars. |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 2110 | #if PLATFORM(IOS_FAMILY) |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 2111 | if (!m_client.forceLayoutOnRestoreFromBackForwardCache()) |
simon.fraser@apple.com | 72978b3 | 2014-03-09 18:14:07 +0000 | [diff] [blame] | 2112 | m_frame.view()->forceLayout(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2113 | #else |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2114 | m_frame.view()->forceLayout(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2115 | #endif |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2116 | |
carlosgc@webkit.org | 72eb796 | 2016-01-12 08:23:36 +0000 | [diff] [blame] | 2117 | // Main resource delegates were already sent, so we skip the first response here. |
| 2118 | for (unsigned i = 1; i < m_documentLoader->responses().size(); ++i) { |
| 2119 | const auto& response = m_documentLoader->responses()[i]; |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2120 | // FIXME: If the WebKit client changes or cancels the request, this is not respected. |
| 2121 | ResourceError error; |
| 2122 | unsigned long identifier; |
| 2123 | ResourceRequest request(response.url()); |
| 2124 | requestFromDelegate(request, identifier, error); |
| 2125 | // FIXME: If we get a resource with more than 2B bytes, this code won't do the right thing. |
| 2126 | // However, with today's computers and networking speeds, this won't happen in practice. |
| 2127 | // Could be an issue with a giant local file. |
akling@apple.com | 654fd9a | 2013-10-06 21:07:29 +0000 | [diff] [blame] | 2128 | 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] | 2129 | } |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2130 | |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2131 | // FIXME: Why only this frame and not parent frames? |
| 2132 | checkLoadCompleteForThisFrame(); |
| 2133 | } |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2134 | } |
| 2135 | |
akling@apple.com | 9663f4b | 2013-09-05 21:25:32 +0000 | [diff] [blame] | 2136 | void FrameLoader::transitionToCommitted(CachedPage* cachedPage) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2137 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2138 | ASSERT(m_client.hasWebView()); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2139 | ASSERT(m_state == FrameStateProvisional); |
| 2140 | |
| 2141 | if (m_state != FrameStateProvisional) |
| 2142 | return; |
| 2143 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2144 | if (FrameView* view = m_frame.view()) { |
bdakin@apple.com | 3fec69c | 2012-03-23 21:02:51 +0000 | [diff] [blame] | 2145 | if (ScrollAnimator* scrollAnimator = view->existingScrollAnimator()) |
bdakin@apple.com | 87235fc | 2012-03-23 20:36:31 +0000 | [diff] [blame] | 2146 | scrollAnimator->cancelAnimations(); |
| 2147 | } |
bdakin@apple.com | e0a38ad | 2011-03-15 18:30:41 +0000 | [diff] [blame] | 2148 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2149 | m_client.setCopiesOnScroll(); |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2150 | history().updateForCommit(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2151 | |
| 2152 | // The call to closeURL() invokes the unload event handler, which can execute arbitrary |
| 2153 | // JavaScript. If the script initiates a new load, we need to abandon the current load, |
| 2154 | // or the two will stomp each other. |
| 2155 | DocumentLoader* pdl = m_provisionalDocumentLoader.get(); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 2156 | if (m_documentLoader) |
| 2157 | closeURL(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2158 | if (pdl != m_provisionalDocumentLoader) |
| 2159 | return; |
| 2160 | |
beidson | 4a28913 | 2007-05-03 18:50:41 +0000 | [diff] [blame] | 2161 | if (m_documentLoader) |
| 2162 | m_documentLoader->stopLoadingSubresources(); |
| 2163 | if (m_documentLoader) |
| 2164 | m_documentLoader->stopLoadingPlugIns(); |
| 2165 | |
dbates@webkit.org | d77aa3f | 2017-05-03 16:58:04 +0000 | [diff] [blame] | 2166 | // Setting our document loader invokes the unload event handler of our child frames. |
| 2167 | // Script can do anything. If the script initiates a new load, we need to abandon the |
| 2168 | // current load or the two will stomp each other. |
beidson | 4a28913 | 2007-05-03 18:50:41 +0000 | [diff] [blame] | 2169 | setDocumentLoader(m_provisionalDocumentLoader.get()); |
dbates@webkit.org | d77aa3f | 2017-05-03 16:58:04 +0000 | [diff] [blame] | 2170 | if (pdl != m_provisionalDocumentLoader) |
| 2171 | return; |
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. |
| 2178 | DocumentLoader* dl = m_documentLoader.get(); |
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) { |
| 2199 | DocumentLoader* cachedDocumentLoader = cachedPage->documentLoader(); |
| 2200 | ASSERT(cachedDocumentLoader); |
beidson@apple.com | 10a537f | 2015-07-09 22:30:42 +0000 | [diff] [blame] | 2201 | cachedDocumentLoader->attachToFrame(m_frame); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2202 | m_client.transitionToCommittedFromCachedFrame(cachedPage->cachedMainFrame()); |
| 2203 | } else |
| 2204 | m_client.transitionToCommittedForNewPage(); |
| 2205 | } |
| 2206 | break; |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2207 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2208 | case FrameLoadType::Reload: |
| 2209 | case FrameLoadType::ReloadFromOrigin: |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2210 | case FrameLoadType::ReloadExpiredOnly: |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2211 | case FrameLoadType::Same: |
| 2212 | case FrameLoadType::Replace: |
| 2213 | history().updateForReload(); |
| 2214 | m_client.transitionToCommittedForNewPage(); |
| 2215 | break; |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2216 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2217 | case FrameLoadType::Standard: |
| 2218 | history().updateForStandardLoad(); |
| 2219 | if (m_frame.view()) |
| 2220 | m_frame.view()->setScrollbarsSuppressed(true); |
| 2221 | m_client.transitionToCommittedForNewPage(); |
| 2222 | break; |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2223 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2224 | case FrameLoadType::RedirectWithLockedBackForwardList: |
| 2225 | history().updateForRedirectWithLockedBackForwardList(); |
| 2226 | m_client.transitionToCommittedForNewPage(); |
| 2227 | break; |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2228 | } |
| 2229 | |
weinig@apple.com | ee87b2f | 2013-10-05 23:59:58 +0000 | [diff] [blame] | 2230 | m_documentLoader->writer().setMIMEType(dl->responseMIMEType()); |
weinig | 9288333 | 2007-02-20 01:05:27 +0000 | [diff] [blame] | 2231 | |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2232 | // Tell the client we've committed this URL. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2233 | ASSERT(m_frame.view()); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 2234 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 2235 | if (m_stateMachine.creatingInitialEmptyDocument()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 2236 | return; |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 2237 | |
| 2238 | if (!m_stateMachine.committedFirstRealDocumentLoad()) |
| 2239 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocumentPostCommit); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2240 | } |
| 2241 | |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 2242 | void FrameLoader::clientRedirectCancelledOrFinished(NewLoadInProgress newLoadInProgress) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2243 | { |
| 2244 | // Note that -webView:didCancelClientRedirectForFrame: is called on the frame load delegate even if |
| 2245 | // the redirect succeeded. We should either rename this API, or add a new method, like |
| 2246 | // -webView:didFinishClientRedirectForFrame: |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2247 | m_client.dispatchDidCancelClientRedirect(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2248 | |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 2249 | if (newLoadInProgress == NewLoadInProgress::No) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2250 | m_quickRedirectComing = false; |
| 2251 | |
| 2252 | m_sentRedirectNotification = false; |
| 2253 | } |
| 2254 | |
utatane.tea@gmail.com | eb3a809 | 2018-02-23 04:18:17 +0000 | [diff] [blame] | 2255 | void FrameLoader::clientRedirected(const URL& url, double seconds, WallTime fireDate, LockBackForwardList lockBackForwardList) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2256 | { |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 2257 | m_client.dispatchWillPerformClientRedirect(url, seconds, fireDate, lockBackForwardList); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2258 | |
| 2259 | // Remember that we sent a redirect notification to the frame load delegate so that when we commit |
| 2260 | // the next provisional load, we can send a corresponding -webView:didCancelClientRedirectForFrame: |
| 2261 | m_sentRedirectNotification = true; |
| 2262 | |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 2263 | // If a "quick" redirect comes in, we set a special mode so we treat the next |
| 2264 | // 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] | 2265 | // 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] | 2266 | // Loads triggered by JavaScript form submissions never count as quick redirects. |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 2267 | m_quickRedirectComing = (lockBackForwardList == LockBackForwardList::Yes || history().currentItemShouldBeReplaced()) && m_documentLoader && !m_isExecutingJavaScriptFormAction; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2268 | } |
| 2269 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2270 | bool FrameLoader::shouldReload(const URL& currentURL, const URL& destinationURL) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2271 | { |
| 2272 | // This function implements the rule: "Don't reload if navigating by fragment within |
| 2273 | // the same URL, but do reload if going to a new URL or to the same URL with no |
| 2274 | // fragment identifier at all." |
beidson@apple.com | ee49725 | 2009-08-10 16:35:00 +0000 | [diff] [blame] | 2275 | if (!destinationURL.hasFragmentIdentifier()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2276 | return true; |
beidson@apple.com | ee49725 | 2009-08-10 16:35:00 +0000 | [diff] [blame] | 2277 | return !equalIgnoringFragmentIdentifier(currentURL, destinationURL); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | void FrameLoader::closeOldDataSources() |
| 2281 | { |
| 2282 | // FIXME: Is it important for this traversal to be postorder instead of preorder? |
| 2283 | // If so, add helpers for postorder traversal, and use them. If not, then lets not |
| 2284 | // use a recursive algorithm here. |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2285 | 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] | 2286 | child->loader().closeOldDataSources(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2287 | |
| 2288 | if (m_documentLoader) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2289 | m_client.dispatchWillClose(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2290 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2291 | m_client.setMainFrameDocumentReady(false); // stop giving out the actual DOMDocument to observers |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
dbates@webkit.org | cd75cb6 | 2017-03-15 22:44:59 +0000 | [diff] [blame] | 2294 | void FrameLoader::willRestoreFromCachedPage() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2295 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2296 | ASSERT(!m_frame.tree().parent()); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2297 | ASSERT(m_frame.page()); |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 2298 | ASSERT(m_frame.isMainFrame()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2299 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2300 | m_frame.navigationScheduler().cancel(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2301 | |
| 2302 | // We still have to close the previous part page. |
| 2303 | closeURL(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2304 | |
| 2305 | // 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] | 2306 | if (m_frame.script().canExecuteScripts(NotAboutToExecuteScript)) { |
| 2307 | DOMWindow* window = m_frame.document()->domWindow(); |
abarth@webkit.org | 13fe1e2 | 2012-08-16 22:29:48 +0000 | [diff] [blame] | 2308 | window->setStatus(String()); |
| 2309 | window->setDefaultStatus(String()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2310 | } |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2311 | } |
| 2312 | |
beidson@apple.com | 913c7f8 | 2009-09-02 20:16:38 +0000 | [diff] [blame] | 2313 | void FrameLoader::open(CachedFrameBase& cachedFrame) |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2314 | { |
| 2315 | m_isComplete = false; |
| 2316 | |
| 2317 | // Don't re-emit the load event. |
| 2318 | m_didCallImplicitClose = true; |
| 2319 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2320 | URL url = cachedFrame.url(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2321 | |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 2322 | // FIXME: I suspect this block of code doesn't do anything. |
benjamin@webkit.org | f726d63 | 2012-03-04 03:26:27 +0000 | [diff] [blame] | 2323 | if (url.protocolIsInHTTPFamily() && !url.host().isEmpty() && url.path().isEmpty()) |
weinig@apple.com | c500266 | 2007-12-12 07:26:19 +0000 | [diff] [blame] | 2324 | url.setPath("/"); |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 2325 | |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 2326 | started(); |
rniwa@webkit.org | 77c6570 | 2019-08-13 05:18:11 +0000 | [diff] [blame] | 2327 | auto document = makeRef(*cachedFrame.document()); |
abarth@webkit.org | 23ea90a | 2012-08-14 19:47:59 +0000 | [diff] [blame] | 2328 | ASSERT(document->domWindow()); |
| 2329 | |
rniwa@webkit.org | 77c6570 | 2019-08-13 05:18:11 +0000 | [diff] [blame] | 2330 | clear(document.ptr(), true, true, cachedFrame.isMainFrame()); |
abarth@webkit.org | 23ea90a | 2012-08-14 19:47:59 +0000 | [diff] [blame] | 2331 | |
cdumez@apple.com | f0705d7 | 2019-07-01 21:55:03 +0000 | [diff] [blame] | 2332 | document->attachToCachedFrame(cachedFrame); |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 2333 | document->setBackForwardCacheState(Document::NotInBackForwardCache); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2334 | |
| 2335 | m_needsClear = true; |
| 2336 | m_isComplete = false; |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 2337 | m_didCallImplicitClose = false; |
Hironori.Fujii@sony.com | 27c57b4 | 2019-08-28 01:40:42 +0000 | [diff] [blame] | 2338 | setOutgoingReferrer(url); |
kmccullo | 6b1b5c2 | 2007-05-24 20:06:56 +0000 | [diff] [blame] | 2339 | |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2340 | FrameView* view = cachedFrame.view(); |
| 2341 | |
| 2342 | // When navigating to a CachedFrame its FrameView should never be null. If it is we'll crash in creative ways downstream. |
| 2343 | ASSERT(view); |
beidson@apple.com | 24f92a5 | 2009-09-03 00:07:51 +0000 | [diff] [blame] | 2344 | view->setWasScrolledByUser(false); |
adachan@apple.com | 95f492a | 2009-08-24 19:55:23 +0000 | [diff] [blame] | 2345 | |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 2346 | 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] | 2347 | m_frame.setView(view); |
cdumez@apple.com | 665ca3b | 2015-05-08 18:15:57 +0000 | [diff] [blame] | 2348 | |
| 2349 | // Use the previous ScrollView's frame rect. |
| 2350 | if (previousViewFrameRect) |
| 2351 | view->setFrameRect(previousViewFrameRect.value()); |
dbates@webkit.org | 7259cf3 | 2018-08-21 16:50:20 +0000 | [diff] [blame] | 2352 | |
rniwa@webkit.org | 77c6570 | 2019-08-13 05:18:11 +0000 | [diff] [blame] | 2353 | |
| 2354 | // Setting the document builds the render tree and runs post style resolution callbacks that can do anything, |
| 2355 | // including loading a child frame before its been re-attached to the frame tree as part of this restore. |
| 2356 | // For example, the HTML object element may load its content into a frame in a post style resolution callback. |
| 2357 | Style::PostResolutionCallbackDisabler disabler(document.get()); |
| 2358 | WidgetHierarchyUpdatesSuspensionScope suspendWidgetHierarchyUpdates; |
| 2359 | NavigationDisabler disableNavigation { &m_frame }; |
| 2360 | |
| 2361 | m_frame.setDocument(document.copyRef()); |
dbates@webkit.org | 7259cf3 | 2018-08-21 16:50:20 +0000 | [diff] [blame] | 2362 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 2363 | document->domWindow()->resumeFromBackForwardCache(); |
weinig@apple.com | 5367c41 | 2008-06-27 00:03:25 +0000 | [diff] [blame] | 2364 | |
abarth@webkit.org | 622d9df | 2009-05-22 16:44:47 +0000 | [diff] [blame] | 2365 | updateFirstPartyForCookies(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2366 | |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2367 | cachedFrame.restore(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2368 | } |
| 2369 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2370 | bool FrameLoader::isHostedByObjectElement() const |
| 2371 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2372 | HTMLFrameOwnerElement* owner = m_frame.ownerElement(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2373 | return owner && owner->hasTagName(objectTag); |
| 2374 | } |
| 2375 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2376 | bool FrameLoader::isReplacing() const |
| 2377 | { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2378 | return m_loadType == FrameLoadType::Replace; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | void FrameLoader::setReplacing() |
| 2382 | { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2383 | m_loadType = FrameLoadType::Replace; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2384 | } |
| 2385 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2386 | bool FrameLoader::subframeIsLoading() const |
| 2387 | { |
| 2388 | // 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] | 2389 | 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] | 2390 | FrameLoader& childLoader = child->loader(); |
| 2391 | DocumentLoader* documentLoader = childLoader.documentLoader(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2392 | if (documentLoader && documentLoader->isLoadingInAPISense()) |
| 2393 | return true; |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2394 | documentLoader = childLoader.provisionalDocumentLoader(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2395 | if (documentLoader && documentLoader->isLoadingInAPISense()) |
| 2396 | return true; |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2397 | documentLoader = childLoader.policyDocumentLoader(); |
mjs@apple.com | 17a175d | 2010-07-18 00:15:31 +0000 | [diff] [blame] | 2398 | if (documentLoader) |
| 2399 | return true; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2400 | } |
| 2401 | return false; |
| 2402 | } |
| 2403 | |
| 2404 | void FrameLoader::willChangeTitle(DocumentLoader* loader) |
| 2405 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2406 | m_client.willChangeTitle(loader); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | FrameLoadType FrameLoader::loadType() const |
| 2410 | { |
| 2411 | return m_loadType; |
| 2412 | } |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2413 | |
antti@apple.com | 2b38ed1 | 2017-04-26 18:22:27 +0000 | [diff] [blame] | 2414 | CachePolicy FrameLoader::subresourceCachePolicy(const URL& url) const |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2415 | { |
darin@apple.com | 30c194a | 2016-03-20 20:08:59 +0000 | [diff] [blame] | 2416 | if (Page* page = m_frame.page()) { |
cdumez@apple.com | a231c91 | 2019-10-16 18:24:25 +0000 | [diff] [blame] | 2417 | if (page->isResourceCachingDisabledByWebInspector()) |
darin@apple.com | 30c194a | 2016-03-20 20:08:59 +0000 | [diff] [blame] | 2418 | return CachePolicyReload; |
| 2419 | } |
darin@apple.com | 0fdefc3 | 2016-03-18 07:56:20 +0000 | [diff] [blame] | 2420 | |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2421 | if (m_isComplete) |
| 2422 | return CachePolicyVerify; |
ap@webkit.org | 86b1098 | 2009-05-18 15:30:10 +0000 | [diff] [blame] | 2423 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2424 | if (m_loadType == FrameLoadType::ReloadFromOrigin) |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2425 | return CachePolicyReload; |
ap@webkit.org | 86b1098 | 2009-05-18 15:30:10 +0000 | [diff] [blame] | 2426 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2427 | if (Frame* parentFrame = m_frame.tree().parent()) { |
antti@apple.com | 2b38ed1 | 2017-04-26 18:22:27 +0000 | [diff] [blame] | 2428 | CachePolicy parentCachePolicy = parentFrame->loader().subresourceCachePolicy(url); |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2429 | if (parentCachePolicy != CachePolicyVerify) |
| 2430 | return parentCachePolicy; |
| 2431 | } |
slewis@apple.com | ef236f4 | 2011-05-25 23:00:45 +0000 | [diff] [blame] | 2432 | |
cdumez@apple.com | 7449316 | 2014-12-08 18:42:12 +0000 | [diff] [blame] | 2433 | switch (m_loadType) { |
| 2434 | case FrameLoadType::Reload: |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2435 | return CachePolicyRevalidate; |
cdumez@apple.com | 7449316 | 2014-12-08 18:42:12 +0000 | [diff] [blame] | 2436 | case FrameLoadType::Back: |
| 2437 | case FrameLoadType::Forward: |
| 2438 | case FrameLoadType::IndexedBackForward: |
joepeck@webkit.org | 853e686 | 2010-11-18 17:59:53 +0000 | [diff] [blame] | 2439 | return CachePolicyHistoryBuffer; |
cdumez@apple.com | 7449316 | 2014-12-08 18:42:12 +0000 | [diff] [blame] | 2440 | case FrameLoadType::ReloadFromOrigin: |
| 2441 | ASSERT_NOT_REACHED(); // Already handled above. |
| 2442 | return CachePolicyReload; |
| 2443 | case FrameLoadType::RedirectWithLockedBackForwardList: |
| 2444 | case FrameLoadType::Replace: |
| 2445 | case FrameLoadType::Same: |
| 2446 | case FrameLoadType::Standard: |
antti@apple.com | 2b38ed1 | 2017-04-26 18:22:27 +0000 | [diff] [blame] | 2447 | return CachePolicyVerify; |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2448 | case FrameLoadType::ReloadExpiredOnly: |
antti@apple.com | 2b38ed1 | 2017-04-26 18:22:27 +0000 | [diff] [blame] | 2449 | // We know about expiration for HTTP and data. Do a normal reload otherwise. |
| 2450 | if (!url.protocolIsInHTTPFamily() && !url.protocolIsData()) |
| 2451 | return CachePolicyReload; |
cdumez@apple.com | 7449316 | 2014-12-08 18:42:12 +0000 | [diff] [blame] | 2452 | return CachePolicyVerify; |
| 2453 | } |
ossy@webkit.org | 41788ca | 2014-12-08 19:30:19 +0000 | [diff] [blame] | 2454 | |
| 2455 | RELEASE_ASSERT_NOT_REACHED(); |
| 2456 | return CachePolicyVerify; |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2457 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2458 | |
aestes@apple.com | 5a4908d | 2019-06-07 06:09:40 +0000 | [diff] [blame] | 2459 | void FrameLoader::dispatchDidFailProvisionalLoad(DocumentLoader& provisionalDocumentLoader, const ResourceError& error) |
| 2460 | { |
| 2461 | m_provisionalLoadErrorBeingHandledURL = provisionalDocumentLoader.url(); |
| 2462 | |
| 2463 | #if ENABLE(CONTENT_FILTERING) |
| 2464 | auto contentFilter = provisionalDocumentLoader.contentFilter(); |
| 2465 | auto contentFilterWillContinueLoading = false; |
| 2466 | #endif |
| 2467 | |
| 2468 | auto willContinueLoading = WillContinueLoading::No; |
| 2469 | if (history().provisionalItem()) |
| 2470 | willContinueLoading = WillContinueLoading::Yes; |
| 2471 | #if ENABLE(CONTENT_FILTERING) |
| 2472 | if (contentFilter && contentFilter->willHandleProvisionalLoadFailure(error)) { |
| 2473 | willContinueLoading = WillContinueLoading::Yes; |
| 2474 | contentFilterWillContinueLoading = true; |
| 2475 | } |
| 2476 | #endif |
| 2477 | |
| 2478 | m_client.dispatchDidFailProvisionalLoad(error, willContinueLoading); |
| 2479 | |
| 2480 | #if ENABLE(CONTENT_FILTERING) |
| 2481 | if (contentFilterWillContinueLoading) |
| 2482 | contentFilter->handleProvisionalLoadFailure(error); |
| 2483 | #endif |
| 2484 | |
| 2485 | m_provisionalLoadErrorBeingHandledURL = { }; |
| 2486 | } |
| 2487 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2488 | void FrameLoader::checkLoadCompleteForThisFrame() |
| 2489 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2490 | ASSERT(m_client.hasWebView()); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2491 | |
darin@apple.com | be4d3dd | 2017-07-30 21:44:01 +0000 | [diff] [blame] | 2492 | // FIXME: Should this check be done in checkLoadComplete instead of here? |
| 2493 | // FIXME: Why does this one check need to be repeated here, and not the many others from checkCompleted? |
| 2494 | if (m_frame.document()->isDelayingLoadEvent()) |
| 2495 | return; |
| 2496 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2497 | switch (m_state) { |
| 2498 | case FrameStateProvisional: { |
jiewen_tan@apple.com | 8c36f62 | 2016-04-01 21:40:20 +0000 | [diff] [blame] | 2499 | // FIXME: Prohibiting any provisional load failures from being sent to clients |
| 2500 | // while handling provisional load failures is too heavy. For example, the current |
| 2501 | // load will fail to cancel another ongoing load. That might prevent clients' page |
| 2502 | // load state being handled properly. |
mitz@apple.com | 6699e27 | 2015-05-01 23:47:03 +0000 | [diff] [blame] | 2503 | if (!m_provisionalLoadErrorBeingHandledURL.isEmpty()) |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2504 | return; |
| 2505 | |
| 2506 | RefPtr<DocumentLoader> pdl = m_provisionalDocumentLoader; |
| 2507 | if (!pdl) |
| 2508 | return; |
| 2509 | |
| 2510 | // If we've received any errors we may be stuck in the provisional state and actually complete. |
| 2511 | const ResourceError& error = pdl->mainDocumentError(); |
| 2512 | if (error.isNull()) |
| 2513 | return; |
| 2514 | |
| 2515 | // Check all children first. |
| 2516 | RefPtr<HistoryItem> item; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2517 | if (Page* page = m_frame.page()) |
commit-queue@webkit.org | 21a48d8 | 2011-01-09 01:27:19 +0000 | [diff] [blame] | 2518 | if (isBackForwardLoadType(loadType())) |
| 2519 | // 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] | 2520 | item = page->mainFrame().loader().history().currentItem(); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2521 | |
commit-queue@webkit.org | 987fd77 | 2011-01-21 18:26:42 +0000 | [diff] [blame] | 2522 | // 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] | 2523 | bool shouldReset = !history().provisionalItem(); |
ap@apple.com | 421e9a1 | 2011-03-24 00:50:45 +0000 | [diff] [blame] | 2524 | if (!pdl->isLoadingInAPISense() || pdl->isStopping()) { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 2525 | RELEASE_LOG_IF_ALLOWED("checkLoadCompleteForThisFrame: Failed provisional load (frame = %p, main = %d, isTimeout = %d, isCancellation = %d, errorCode = %d)", &m_frame, m_frame.isMainFrame(), error.isTimeout(), error.isCancellation(), error.errorCode()); |
cdumez@apple.com | 41883a9 | 2019-04-23 15:38:11 +0000 | [diff] [blame] | 2526 | |
aestes@apple.com | 5a4908d | 2019-06-07 06:09:40 +0000 | [diff] [blame] | 2527 | dispatchDidFailProvisionalLoad(*pdl, error); |
ap@apple.com | 09535d1 | 2011-03-24 00:48:30 +0000 | [diff] [blame] | 2528 | ASSERT(!pdl->isLoading()); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2529 | |
eric@webkit.org | b562c40 | 2010-01-13 01:29:35 +0000 | [diff] [blame] | 2530 | // If we're in the middle of loading multipart data, we need to restore the document loader. |
| 2531 | if (isReplacing() && !m_documentLoader.get()) |
eric@webkit.org | 9074725 | 2010-01-12 18:10:14 +0000 | [diff] [blame] | 2532 | setDocumentLoader(m_provisionalDocumentLoader.get()); |
| 2533 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2534 | // Finish resetting the load state, but only if another load hasn't been started by the |
| 2535 | // delegate callback. |
| 2536 | if (pdl == m_provisionalDocumentLoader) |
| 2537 | clearProvisionalLoad(); |
tonikitoo@webkit.org | e94ac9b | 2009-11-16 15:38:19 +0000 | [diff] [blame] | 2538 | else if (activeDocumentLoader()) { |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2539 | URL unreachableURL = activeDocumentLoader()->unreachableURL(); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2540 | if (!unreachableURL.isEmpty() && unreachableURL == pdl->request().url()) |
| 2541 | shouldReset = false; |
| 2542 | } |
| 2543 | } |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 2544 | if (shouldReset && item) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2545 | if (Page* page = m_frame.page()) { |
achristensen@apple.com | 3a889f1 | 2018-10-16 15:58:10 +0000 | [diff] [blame] | 2546 | page->backForward().setCurrentItem(*item); |
mitz@apple.com | bc84376 | 2008-12-08 21:18:11 +0000 | [diff] [blame] | 2547 | } |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2548 | return; |
| 2549 | } |
| 2550 | |
| 2551 | case FrameStateCommittedPage: { |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 2552 | if (!m_documentLoader) |
| 2553 | return; |
| 2554 | if (m_documentLoader->isLoadingInAPISense() && !m_documentLoader->isStopping() && !m_checkingLoadCompleteForDetachment) |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2555 | return; |
| 2556 | |
darin@apple.com | af8b1a9 | 2011-06-25 00:09:37 +0000 | [diff] [blame] | 2557 | setState(FrameStateComplete); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2558 | |
| 2559 | // FIXME: Is this subsequent work important if we already navigated away? |
| 2560 | // Maybe there are bugs because of that, or extra work we can skip because |
| 2561 | // the new page is ready. |
| 2562 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2563 | m_client.forceLayoutForNonHTML(); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2564 | |
| 2565 | // 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] | 2566 | if (m_frame.page()) { |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2567 | if (isBackForwardLoadType(m_loadType) || isReload(m_loadType)) |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2568 | history().restoreScrollPositionAndViewState(); |
darin@apple.com | e10e128 | 2010-10-30 00:44:33 +0000 | [diff] [blame] | 2569 | } |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2570 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 2571 | if (m_stateMachine.creatingInitialEmptyDocument() || !m_stateMachine.committedFirstRealDocumentLoad()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 2572 | return; |
| 2573 | |
timothy_horton@apple.com | 346f8d7 | 2013-08-01 00:06:51 +0000 | [diff] [blame] | 2574 | m_progressTracker->progressCompleted(); |
eric.carlson@apple.com | 77b4a11 | 2014-10-30 19:04:29 +0000 | [diff] [blame] | 2575 | Page* page = m_frame.page(); |
| 2576 | if (page) { |
simon.fraser@apple.com | 83325b9 | 2017-03-17 00:47:16 +0000 | [diff] [blame] | 2577 | if (m_frame.isMainFrame()) { |
sbarati@apple.com | ce7ec11 | 2018-04-17 15:57:32 +0000 | [diff] [blame] | 2578 | tracePoint(MainResourceLoadDidEnd); |
cdumez@apple.com | ef2c015 | 2017-01-13 17:54:53 +0000 | [diff] [blame] | 2579 | page->didFinishLoad(); |
simon.fraser@apple.com | 83325b9 | 2017-03-17 00:47:16 +0000 | [diff] [blame] | 2580 | } |
andersca@apple.com | 7c0a3fc | 2012-05-01 22:22:25 +0000 | [diff] [blame] | 2581 | } |
| 2582 | |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 2583 | const ResourceError& error = m_documentLoader->mainDocumentError(); |
mario@webkit.org | 685258f | 2011-12-06 00:10:55 +0000 | [diff] [blame] | 2584 | |
| 2585 | AXObjectCache::AXLoadingEvent loadingEvent; |
| 2586 | if (!error.isNull()) { |
krollin@apple.com | d54b5d7 | 2016-09-12 18:59:32 +0000 | [diff] [blame] | 2587 | RELEASE_LOG_IF_ALLOWED("checkLoadCompleteForThisFrame: Finished frame load with error (frame = %p, main = %d, isTimeout = %d, isCancellation = %d, errorCode = %d)", &m_frame, m_frame.isMainFrame(), error.isTimeout(), error.isCancellation(), error.errorCode()); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2588 | m_client.dispatchDidFailLoad(error); |
mario@webkit.org | 685258f | 2011-12-06 00:10:55 +0000 | [diff] [blame] | 2589 | loadingEvent = AXObjectCache::AXLoadingFailed; |
| 2590 | } else { |
krollin@apple.com | 5c91c4e | 2016-09-20 20:03:45 +0000 | [diff] [blame] | 2591 | RELEASE_LOG_IF_ALLOWED("checkLoadCompleteForThisFrame: Finished frame load (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
enrica@apple.com | 53b08e5 | 2016-01-19 22:58:59 +0000 | [diff] [blame] | 2592 | #if ENABLE(DATA_DETECTION) |
rniwa@webkit.org | 2f150e7 | 2016-06-14 07:35:53 +0000 | [diff] [blame] | 2593 | auto* document = m_frame.document(); |
| 2594 | if (m_frame.settings().dataDetectorTypes() != DataDetectorTypeNone && document) { |
| 2595 | if (auto* documentElement = document->documentElement()) { |
| 2596 | RefPtr<Range> documentRange = makeRange(firstPositionInNode(documentElement), lastPositionInNode(documentElement)); |
timothy_horton@apple.com | 688a910 | 2016-07-07 03:03:42 +0000 | [diff] [blame] | 2597 | m_frame.setDataDetectionResults(DataDetection::detectContentInRange(documentRange, m_frame.settings().dataDetectorTypes(), m_client.dataDetectionContext())); |
rniwa@webkit.org | 2f150e7 | 2016-06-14 07:35:53 +0000 | [diff] [blame] | 2598 | if (m_frame.isMainFrame()) |
| 2599 | m_client.dispatchDidFinishDataDetection(m_frame.dataDetectionResults()); |
| 2600 | } |
enrica@apple.com | 53b08e5 | 2016-01-19 22:58:59 +0000 | [diff] [blame] | 2601 | } |
| 2602 | #endif |
enrica@apple.com | 4c36ad5 | 2016-01-23 00:24:02 +0000 | [diff] [blame] | 2603 | m_client.dispatchDidFinishLoad(); |
| 2604 | loadingEvent = AXObjectCache::AXLoadingFinished; |
mario@webkit.org | 685258f | 2011-12-06 00:10:55 +0000 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | // Notify accessibility. |
rniwa@webkit.org | 2f150e7 | 2016-06-14 07:35:53 +0000 | [diff] [blame] | 2608 | if (auto* document = m_frame.document()) { |
| 2609 | if (AXObjectCache* cache = document->existingAXObjectCache()) |
| 2610 | cache->frameLoadingEventNotification(&m_frame, loadingEvent); |
| 2611 | } |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2612 | |
beidson@apple.com | 4aecb3d | 2015-07-09 04:47:09 +0000 | [diff] [blame] | 2613 | // The above calls to dispatchDidFinishLoad() might have detached the Frame |
| 2614 | // from its Page and also might have caused Page to be deleted. |
| 2615 | // Don't assume 'page' is still available to use. |
| 2616 | if (m_frame.isMainFrame() && m_frame.page()) { |
| 2617 | ASSERT(&m_frame.page()->mainFrame() == &m_frame); |
cdumez@apple.com | 10d0f25 | 2016-04-23 21:33:49 +0000 | [diff] [blame] | 2618 | 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] | 2619 | } |
eric.carlson@apple.com | 77b4a11 | 2014-10-30 19:04:29 +0000 | [diff] [blame] | 2620 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2621 | return; |
| 2622 | } |
| 2623 | |
| 2624 | case FrameStateComplete: |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2625 | m_loadType = FrameLoadType::Standard; |
beidson@apple.com | d141827 | 2009-01-30 17:30:47 +0000 | [diff] [blame] | 2626 | frameLoadCompleted(); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2627 | return; |
| 2628 | } |
| 2629 | |
| 2630 | ASSERT_NOT_REACHED(); |
| 2631 | } |
andersca | 5d5f802 | 2007-02-28 00:38:00 +0000 | [diff] [blame] | 2632 | |
ap@apple.com | 456d465 | 2011-11-30 12:13:31 +0000 | [diff] [blame] | 2633 | void FrameLoader::setOriginalURLForDownloadRequest(ResourceRequest& request) |
| 2634 | { |
jiewen_tan@apple.com | 8283620 | 2016-03-31 20:39:24 +0000 | [diff] [blame] | 2635 | // FIXME: Rename firstPartyForCookies back to mainDocumentURL. It was a mistake to think that it was only used for cookies. |
| 2636 | // 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] | 2637 | URL originalURL; |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2638 | auto* initiator = m_frame.document(); |
| 2639 | if (initiator) { |
| 2640 | originalURL = initiator->firstPartyForCookies(); |
jiewen_tan@apple.com | 65b3816 | 2016-12-22 00:04:11 +0000 | [diff] [blame] | 2641 | // If there is no main document URL, it means that this document is newly opened and just for download purpose. |
| 2642 | // 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] | 2643 | if (originalURL.isEmpty() && opener() && opener()->document()) { |
jiewen_tan@apple.com | 65b3816 | 2016-12-22 00:04:11 +0000 | [diff] [blame] | 2644 | originalURL = opener()->document()->firstPartyForCookies(); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2645 | initiator = opener()->document(); |
| 2646 | } |
jiewen_tan@apple.com | 65b3816 | 2016-12-22 00:04:11 +0000 | [diff] [blame] | 2647 | } |
jiewen_tan@apple.com | 8283620 | 2016-03-31 20:39:24 +0000 | [diff] [blame] | 2648 | // If the originalURL is the same as the requested URL, we are processing a download |
| 2649 | // initiated directly without a page and do not need to specify the originalURL. |
| 2650 | if (originalURL == request.url()) |
| 2651 | request.setFirstPartyForCookies(URL()); |
| 2652 | else |
| 2653 | request.setFirstPartyForCookies(originalURL); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2654 | addSameSiteInfoToRequestIfNeeded(request, initiator); |
ap@apple.com | 456d465 | 2011-11-30 12:13:31 +0000 | [diff] [blame] | 2655 | } |
| 2656 | |
antti@apple.com | 8e03f74 | 2018-11-09 19:47:15 +0000 | [diff] [blame] | 2657 | void FrameLoader::didReachLayoutMilestone(OptionSet<LayoutMilestone> milestones) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2658 | { |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 2659 | ASSERT(m_frame.isMainFrame()); |
bdakin@apple.com | 7ce7e1b | 2013-08-12 21:37:06 +0000 | [diff] [blame] | 2660 | |
simon.fraser@apple.com | 625ae9e | 2016-08-19 18:10:23 +0000 | [diff] [blame] | 2661 | m_client.dispatchDidReachLayoutMilestone(milestones); |
bdakin@apple.com | 3ab3737 | 2012-02-01 21:52:41 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
bdakin@apple.com | e98caf1 | 2012-09-25 23:08:03 +0000 | [diff] [blame] | 2664 | void FrameLoader::didFirstLayout() |
| 2665 | { |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 2666 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2667 | // Only send layout-related delegate callbacks synchronously for the main frame to |
| 2668 | // avoid reentering layout for the main frame while delivering a layout-related delegate |
| 2669 | // callback for a subframe. |
| 2670 | if (&m_frame != &m_frame.page()->mainFrame()) |
| 2671 | return; |
| 2672 | #endif |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2673 | if (m_frame.page() && isBackForwardLoadType(m_loadType)) |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2674 | history().restoreScrollPositionAndViewState(); |
bdakin@apple.com | e98caf1 | 2012-09-25 23:08:03 +0000 | [diff] [blame] | 2675 | |
| 2676 | if (m_stateMachine.committedFirstRealDocumentLoad() && !m_stateMachine.isDisplayingInitialEmptyDocument() && !m_stateMachine.firstLayoutDone()) |
| 2677 | m_stateMachine.advanceTo(FrameLoaderStateMachine::FirstLayoutDone); |
| 2678 | } |
| 2679 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2680 | void FrameLoader::frameLoadCompleted() |
| 2681 | { |
beidson@apple.com | d141827 | 2009-01-30 17:30:47 +0000 | [diff] [blame] | 2682 | // Note: Can be called multiple times. |
| 2683 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2684 | m_client.frameLoadCompleted(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2685 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2686 | history().updateForFrameLoadCompleted(); |
beidson@apple.com | d141827 | 2009-01-30 17:30:47 +0000 | [diff] [blame] | 2687 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2688 | // After a canceled provisional load, firstLayoutDone is false. |
| 2689 | // Reset it to true if we're displaying a page. |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 2690 | if (m_documentLoader && m_stateMachine.committedFirstRealDocumentLoad() && !m_stateMachine.isDisplayingInitialEmptyDocument() && !m_stateMachine.firstLayoutDone()) |
| 2691 | m_stateMachine.advanceTo(FrameLoaderStateMachine::FirstLayoutDone); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2692 | } |
| 2693 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2694 | void FrameLoader::detachChildren() |
| 2695 | { |
cdumez@apple.com | 8b478c6 | 2016-01-23 01:04:59 +0000 | [diff] [blame] | 2696 | // detachChildren() will fire the unload event in each subframe and the |
| 2697 | // HTML specification states that the parent document's ignore-opens-during-unload counter while |
| 2698 | // this event is being fired in its subframes: |
| 2699 | // https://html.spec.whatwg.org/multipage/browsers.html#unload-a-document |
| 2700 | IgnoreOpensDuringUnloadCountIncrementer ignoreOpensDuringUnloadCountIncrementer(m_frame.document()); |
| 2701 | |
cdumez@apple.com | f0705d7 | 2019-07-01 21:55:03 +0000 | [diff] [blame] | 2702 | // detachChildren() will fire the unload event in each subframe and the |
| 2703 | // HTML specification states that navigations should be prevented during the prompt to unload algorithm: |
| 2704 | // https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate |
| 2705 | std::unique_ptr<NavigationDisabler> navigationDisabler; |
| 2706 | if (m_frame.isMainFrame()) |
ysuzuki@apple.com | 1d8e24d | 2019-08-19 06:59:40 +0000 | [diff] [blame] | 2707 | navigationDisabler = makeUnique<NavigationDisabler>(&m_frame); |
cdumez@apple.com | f0705d7 | 2019-07-01 21:55:03 +0000 | [diff] [blame] | 2708 | |
cdumez@apple.com | 6857a01 | 2017-03-02 23:43:09 +0000 | [diff] [blame] | 2709 | // Any subframe inserted by unload event handlers executed in the loop below will not get unloaded |
| 2710 | // because we create a copy of the subframes list before looping. Therefore, it would be unsafe to |
| 2711 | // allow loading of subframes at this point. |
| 2712 | SubframeLoadingDisabler subframeLoadingDisabler(m_frame.document()); |
| 2713 | |
akling@apple.com | 72c1c36 | 2013-09-06 01:34:05 +0000 | [diff] [blame] | 2714 | Vector<Ref<Frame>, 16> childrenToDetach; |
| 2715 | childrenToDetach.reserveInitialCapacity(m_frame.tree().childCount()); |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2716 | 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] | 2717 | childrenToDetach.uncheckedAppend(*child); |
commit-queue@webkit.org | acddfad | 2015-09-30 05:53:51 +0000 | [diff] [blame] | 2718 | for (auto& child : childrenToDetach) |
| 2719 | child->loader().detachFromParent(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2720 | } |
| 2721 | |
darin@apple.com | 9ace801 | 2017-01-23 06:24:18 +0000 | [diff] [blame] | 2722 | void FrameLoader::closeAndRemoveChild(Frame& child) |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2723 | { |
darin@apple.com | 9ace801 | 2017-01-23 06:24:18 +0000 | [diff] [blame] | 2724 | child.tree().detachFromParent(); |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2725 | |
darin@apple.com | 9ace801 | 2017-01-23 06:24:18 +0000 | [diff] [blame] | 2726 | child.setView(nullptr); |
| 2727 | if (child.ownerElement() && child.page()) |
| 2728 | child.page()->decrementSubframeCount(); |
| 2729 | child.willDetachPage(); |
| 2730 | child.detachFromPage(); |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2731 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2732 | m_frame.tree().removeChild(child); |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2733 | } |
| 2734 | |
darin@apple.com | af8b1a9 | 2011-06-25 00:09:37 +0000 | [diff] [blame] | 2735 | // Called every time a resource is completely loaded or an error is received. |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2736 | void FrameLoader::checkLoadComplete() |
| 2737 | { |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 2738 | m_shouldCallCheckLoadComplete = false; |
| 2739 | |
akling@apple.com | 72c1c36 | 2013-09-06 01:34:05 +0000 | [diff] [blame] | 2740 | if (!m_frame.page()) |
| 2741 | return; |
| 2742 | |
darin@apple.com | 355b152 | 2017-08-15 18:13:57 +0000 | [diff] [blame] | 2743 | ASSERT(m_client.hasWebView()); |
| 2744 | |
andersca | a315d57 | 2007-03-13 01:09:53 +0000 | [diff] [blame] | 2745 | // FIXME: Always traversing the entire frame tree is a bit inefficient, but |
| 2746 | // 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] | 2747 | Vector<Ref<Frame>, 16> frames; |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 2748 | for (Frame* frame = &m_frame.mainFrame(); frame; frame = frame->tree().traverseNext()) |
akling@apple.com | 72c1c36 | 2013-09-06 01:34:05 +0000 | [diff] [blame] | 2749 | frames.append(*frame); |
| 2750 | |
| 2751 | // To process children before their parents, iterate the vector backwards. |
jiewen_tan@apple.com | be26fa3 | 2015-12-01 00:33:47 +0000 | [diff] [blame] | 2752 | for (auto frame = frames.rbegin(); frame != frames.rend(); ++frame) { |
| 2753 | if ((*frame)->page()) |
| 2754 | (*frame)->loader().checkLoadCompleteForThisFrame(); |
| 2755 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | int FrameLoader::numPendingOrLoadingRequests(bool recurse) const |
| 2759 | { |
| 2760 | if (!recurse) |
cdumez@apple.com | 0bb03ec | 2015-01-28 05:53:53 +0000 | [diff] [blame] | 2761 | return m_frame.document()->cachedResourceLoader().requestCount(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2762 | |
| 2763 | int count = 0; |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2764 | 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] | 2765 | count += frame->document()->cachedResourceLoader().requestCount(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2766 | return count; |
| 2767 | } |
| 2768 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2769 | String FrameLoader::userAgent(const URL& url) const |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2770 | { |
drousso@apple.com | c9a88bd | 2019-01-26 22:32:38 +0000 | [diff] [blame] | 2771 | String userAgent; |
| 2772 | |
| 2773 | if (auto* documentLoader = m_frame.mainFrame().loader().activeDocumentLoader()) |
| 2774 | userAgent = documentLoader->customUserAgent(); |
| 2775 | |
| 2776 | InspectorInstrumentation::applyUserAgentOverride(m_frame, userAgent); |
| 2777 | |
| 2778 | if (!userAgent.isEmpty()) |
| 2779 | return userAgent; |
cdumez@apple.com | 96b28c8 | 2018-12-10 21:26:39 +0000 | [diff] [blame] | 2780 | |
seokju@webkit.org | cb8504d | 2014-01-09 17:19:34 +0000 | [diff] [blame] | 2781 | return m_client.userAgent(url); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2782 | } |
rniwa@webkit.org | 1547091 | 2019-01-26 06:50:58 +0000 | [diff] [blame] | 2783 | |
| 2784 | String FrameLoader::userAgentForJavaScript(const URL& url) const |
| 2785 | { |
drousso@apple.com | c9a88bd | 2019-01-26 22:32:38 +0000 | [diff] [blame] | 2786 | String userAgent; |
| 2787 | |
rniwa@webkit.org | 1547091 | 2019-01-26 06:50:58 +0000 | [diff] [blame] | 2788 | if (auto* documentLoader = m_frame.mainFrame().loader().activeDocumentLoader()) { |
rniwa@webkit.org | af0b1ae | 2019-01-29 07:15:00 +0000 | [diff] [blame] | 2789 | if (m_frame.settings().needsSiteSpecificQuirks()) |
| 2790 | userAgent = documentLoader->customJavaScriptUserAgentAsSiteSpecificQuirks(); |
drousso@apple.com | c9a88bd | 2019-01-26 22:32:38 +0000 | [diff] [blame] | 2791 | if (userAgent.isEmpty()) |
| 2792 | userAgent = documentLoader->customUserAgent(); |
rniwa@webkit.org | 1547091 | 2019-01-26 06:50:58 +0000 | [diff] [blame] | 2793 | } |
| 2794 | |
drousso@apple.com | c9a88bd | 2019-01-26 22:32:38 +0000 | [diff] [blame] | 2795 | InspectorInstrumentation::applyUserAgentOverride(m_frame, userAgent); |
| 2796 | |
| 2797 | if (!userAgent.isEmpty()) |
| 2798 | return userAgent; |
| 2799 | |
rniwa@webkit.org | 1547091 | 2019-01-26 06:50:58 +0000 | [diff] [blame] | 2800 | return m_client.userAgent(url); |
| 2801 | } |
megan_gardner@apple.com | de788db | 2018-12-19 20:21:31 +0000 | [diff] [blame] | 2802 | |
| 2803 | String FrameLoader::navigatorPlatform() const |
| 2804 | { |
| 2805 | if (auto* documentLoader = m_frame.mainFrame().loader().activeDocumentLoader()) { |
| 2806 | auto& customNavigatorPlatform = documentLoader->customNavigatorPlatform(); |
| 2807 | if (!customNavigatorPlatform.isEmpty()) |
| 2808 | return customNavigatorPlatform; |
| 2809 | } |
| 2810 | return String(); |
| 2811 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2812 | |
ggaren@apple.com | 7a176e1 | 2015-11-12 01:48:27 +0000 | [diff] [blame] | 2813 | void FrameLoader::dispatchOnloadEvents() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2814 | { |
ggaren@apple.com | 7a176e1 | 2015-11-12 01:48:27 +0000 | [diff] [blame] | 2815 | m_client.dispatchDidDispatchOnloadEvents(); |
japhet@chromium.org | 92a952b | 2010-07-12 18:14:17 +0000 | [diff] [blame] | 2816 | |
darin@apple.com | af8b1a9 | 2011-06-25 00:09:37 +0000 | [diff] [blame] | 2817 | if (documentLoader()) |
ggaren@apple.com | 7a176e1 | 2015-11-12 01:48:27 +0000 | [diff] [blame] | 2818 | documentLoader()->dispatchOnloadEvents(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | void FrameLoader::frameDetached() |
| 2822 | { |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 2823 | // 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] | 2824 | Ref<Frame> protectedFrame(m_frame); |
| 2825 | |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 2826 | if (m_checkTimer.isActive()) { |
| 2827 | m_checkTimer.stop(); |
| 2828 | checkCompletenessNow(); |
| 2829 | } |
| 2830 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 2831 | if (m_frame.document()->backForwardCacheState() != Document::InBackForwardCache) { |
rniwa@webkit.org | 1a1b520 | 2018-06-01 22:30:02 +0000 | [diff] [blame] | 2832 | stopAllLoadersAndCheckCompleteness(); |
dbates@webkit.org | 6d862de | 2017-02-11 02:53:53 +0000 | [diff] [blame] | 2833 | m_frame.document()->stopActiveDOMObjects(); |
| 2834 | } |
| 2835 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2836 | detachFromParent(); |
| 2837 | } |
| 2838 | |
ggaren | c04b2c5 | 2006-11-30 21:06:14 +0000 | [diff] [blame] | 2839 | void FrameLoader::detachFromParent() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2840 | { |
dbates@webkit.org | 6d862de | 2017-02-11 02:53:53 +0000 | [diff] [blame] | 2841 | // 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] | 2842 | Ref<Frame> protect(m_frame); |
ggaren | c04b2c5 | 2006-11-30 21:06:14 +0000 | [diff] [blame] | 2843 | |
ggaren | acf2874 | 2006-12-27 07:38:18 +0000 | [diff] [blame] | 2844 | closeURL(); |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2845 | history().saveScrollPositionAndViewStateToItem(history().currentItem()); |
ggaren | c04b2c5 | 2006-11-30 21:06:14 +0000 | [diff] [blame] | 2846 | detachChildren(); |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 2847 | if (m_frame.document()->backForwardCacheState() != Document::InBackForwardCache) { |
| 2848 | // 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] | 2849 | // because detachedChildren() will trigger the unload event handlers of any child frames, and those event |
| 2850 | // handlers might start a new subresource load in this frame. |
ajuma@chromium.org | edd7574 | 2019-09-11 14:52:18 +0000 | [diff] [blame] | 2851 | stopAllLoaders(ShouldClearProvisionalItem, StopLoadingPolicy::AlwaysStopLoading); |
dbates@webkit.org | 6d862de | 2017-02-11 02:53:53 +0000 | [diff] [blame] | 2852 | } |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 2853 | |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 2854 | InspectorInstrumentation::frameDetachedFromParent(m_frame); |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 2855 | |
beidson@apple.com | 24f92a5 | 2009-09-03 00:07:51 +0000 | [diff] [blame] | 2856 | detachViewsAndDocumentLoader(); |
| 2857 | |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 2858 | m_progressTracker = nullptr; |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 2859 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2860 | if (Frame* parent = m_frame.tree().parent()) { |
darin@apple.com | 9ace801 | 2017-01-23 06:24:18 +0000 | [diff] [blame] | 2861 | parent->loader().closeAndRemoveChild(m_frame); |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2862 | parent->loader().scheduleCheckCompleted(); |
darin@apple.com | be4d3dd | 2017-07-30 21:44:01 +0000 | [diff] [blame] | 2863 | parent->loader().scheduleCheckLoadComplete(); |
weinig | c34c71c | 2007-03-09 16:05:37 +0000 | [diff] [blame] | 2864 | } else { |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 2865 | m_frame.setView(nullptr); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2866 | m_frame.willDetachPage(); |
| 2867 | m_frame.detachFromPage(); |
ddkilzer | 3adeb2f | 2006-12-28 23:33:37 +0000 | [diff] [blame] | 2868 | } |
ggaren | c04b2c5 | 2006-11-30 21:06:14 +0000 | [diff] [blame] | 2869 | } |
beidson@apple.com | 24f92a5 | 2009-09-03 00:07:51 +0000 | [diff] [blame] | 2870 | |
| 2871 | void FrameLoader::detachViewsAndDocumentLoader() |
| 2872 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2873 | m_client.detachedFromParent2(); |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 2874 | setDocumentLoader(nullptr); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2875 | m_client.detachedFromParent3(); |
beidson@apple.com | 24f92a5 | 2009-09-03 00:07:51 +0000 | [diff] [blame] | 2876 | } |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2877 | |
| 2878 | void FrameLoader::addExtraFieldsToSubresourceRequest(ResourceRequest& request) |
| 2879 | { |
jochen@chromium.org | dac140c | 2011-08-01 21:18:49 +0000 | [diff] [blame] | 2880 | addExtraFieldsToRequest(request, m_loadType, false); |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2881 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2882 | |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2883 | void FrameLoader::addExtraFieldsToMainResourceRequest(ResourceRequest& request) |
| 2884 | { |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 2885 | // FIXME: Using m_loadType seems wrong for some callers. |
| 2886 | // If we are only preparing to load the main resource, that is previous load's load type! |
jochen@chromium.org | dac140c | 2011-08-01 21:18:49 +0000 | [diff] [blame] | 2887 | addExtraFieldsToRequest(request, m_loadType, true); |
bfulgham@apple.com | b30d7f8 | 2016-06-07 15:47:30 +0000 | [diff] [blame] | 2888 | |
| 2889 | // Upgrade-Insecure-Requests should only be added to main resource requests |
| 2890 | addHTTPUpgradeInsecureRequestsIfNeeded(request); |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2891 | } |
| 2892 | |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2893 | ResourceRequestCachePolicy FrameLoader::defaultRequestCachingPolicy(const ResourceRequest& request, FrameLoadType loadType, bool isMainResource) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2894 | { |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2895 | if (m_overrideCachePolicyForTesting) |
| 2896 | return m_overrideCachePolicyForTesting.value(); |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2897 | |
| 2898 | if (isMainResource) { |
| 2899 | if (isReload(loadType) || request.isConditional()) |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2900 | return ResourceRequestCachePolicy::ReloadIgnoringCacheData; |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2901 | |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2902 | return ResourceRequestCachePolicy::UseProtocolCachePolicy; |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | if (request.isConditional()) |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2906 | return ResourceRequestCachePolicy::ReloadIgnoringCacheData; |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2907 | |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2908 | if (documentLoader()->isLoadingInAPISense()) { |
| 2909 | // If we inherit cache policy from a main resource, we use the DocumentLoader's |
| 2910 | // original request cache policy for two reasons: |
| 2911 | // 1. For POST requests, we mutate the cache policy for the main resource, |
| 2912 | // but we do not want this to apply to subresources |
| 2913 | // 2. Delegates that modify the cache policy using willSendRequest: should |
| 2914 | // not affect any other resources. Such changes need to be done |
| 2915 | // per request. |
| 2916 | ResourceRequestCachePolicy mainDocumentOriginalCachePolicy = documentLoader()->originalRequest().cachePolicy(); |
| 2917 | // 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. |
| 2918 | // 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] | 2919 | return (mainDocumentOriginalCachePolicy == ResourceRequestCachePolicy::ReturnCacheDataDontLoad) ? ResourceRequestCachePolicy::ReturnCacheDataElseLoad : mainDocumentOriginalCachePolicy; |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 2920 | } |
| 2921 | |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2922 | return ResourceRequestCachePolicy::UseProtocolCachePolicy; |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | void FrameLoader::addExtraFieldsToRequest(ResourceRequest& request, FrameLoadType loadType, bool isMainResource) |
| 2926 | { |
cdumez@apple.com | 3aedc03 | 2019-01-31 02:23:55 +0000 | [diff] [blame] | 2927 | // If the request came from a previous process due to process-swap-on-navigation then we should not modify the request. |
| 2928 | if (m_currentLoadContinuingState == LoadContinuingState::ContinuingWithRequest) |
cdumez@apple.com | fdb8971 | 2018-06-11 20:52:31 +0000 | [diff] [blame] | 2929 | return; |
| 2930 | |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2931 | // Don't set the cookie policy URL if it's already been set. |
| 2932 | // But make sure to set it on all requests regardless of protocol, as it has significance beyond the cookie policy (<rdar://problem/6616664>). |
dbates@webkit.org | 2dc5b0d | 2019-02-21 23:54:40 +0000 | [diff] [blame] | 2933 | bool isMainFrameMainResource = isMainResource && m_frame.isMainFrame(); |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2934 | if (request.firstPartyForCookies().isEmpty()) { |
dbates@webkit.org | 2dc5b0d | 2019-02-21 23:54:40 +0000 | [diff] [blame] | 2935 | if (isMainFrameMainResource) |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2936 | request.setFirstPartyForCookies(request.url()); |
| 2937 | else if (Document* document = m_frame.document()) |
| 2938 | request.setFirstPartyForCookies(document->firstPartyForCookies()); |
| 2939 | } |
| 2940 | |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2941 | if (request.isSameSiteUnspecified()) { |
| 2942 | auto* initiator = m_frame.document(); |
| 2943 | if (isMainResource) { |
| 2944 | auto* ownerFrame = m_frame.tree().parent(); |
dbates@webkit.org | 1e85855 | 2018-06-30 02:11:01 +0000 | [diff] [blame] | 2945 | if (!ownerFrame && m_stateMachine.isDisplayingInitialEmptyDocument()) |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2946 | ownerFrame = m_opener; |
| 2947 | if (ownerFrame) |
| 2948 | initiator = ownerFrame->document(); |
| 2949 | ASSERT(ownerFrame || m_frame.isMainFrame()); |
| 2950 | } |
| 2951 | addSameSiteInfoToRequestIfNeeded(request, initiator); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2952 | } |
dbates@webkit.org | 2dc5b0d | 2019-02-21 23:54:40 +0000 | [diff] [blame] | 2953 | request.setIsTopSite(isMainFrameMainResource); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 2954 | |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2955 | Page* page = frame().page(); |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2956 | bool hasSpecificCachePolicy = request.cachePolicy() != ResourceRequestCachePolicy::UseProtocolCachePolicy; |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2957 | |
cdumez@apple.com | a231c91 | 2019-10-16 18:24:25 +0000 | [diff] [blame] | 2958 | if (page && page->isResourceCachingDisabledByWebInspector()) { |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2959 | request.setCachePolicy(ResourceRequestCachePolicy::ReloadIgnoringCacheData); |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2960 | loadType = FrameLoadType::ReloadFromOrigin; |
| 2961 | } else if (!hasSpecificCachePolicy) |
| 2962 | request.setCachePolicy(defaultRequestCachingPolicy(request, loadType, isMainResource)); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 2963 | |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2964 | // The remaining modifications are only necessary for HTTP and HTTPS. |
| 2965 | if (!request.url().isEmpty() && !request.url().protocolIsInHTTPFamily()) |
| 2966 | return; |
antti@apple.com | 7c97e2c | 2015-03-19 05:21:40 +0000 | [diff] [blame] | 2967 | |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 2968 | if (!hasSpecificCachePolicy && request.cachePolicy() == ResourceRequestCachePolicy::ReloadIgnoringCacheData) { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2969 | if (loadType == FrameLoadType::Reload) |
andersca@apple.com | a96cf71 | 2014-06-14 17:49:44 +0000 | [diff] [blame] | 2970 | request.setHTTPHeaderField(HTTPHeaderName::CacheControl, "max-age=0"); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2971 | else if (loadType == FrameLoadType::ReloadFromOrigin) { |
andersca@apple.com | a96cf71 | 2014-06-14 17:49:44 +0000 | [diff] [blame] | 2972 | request.setHTTPHeaderField(HTTPHeaderName::CacheControl, "no-cache"); |
| 2973 | request.setHTTPHeaderField(HTTPHeaderName::Pragma, "no-cache"); |
japhet@chromium.org | 1e31314 | 2010-08-31 22:53:31 +0000 | [diff] [blame] | 2974 | } |
| 2975 | } |
darin@apple.com | 0fdefc3 | 2016-03-18 07:56:20 +0000 | [diff] [blame] | 2976 | |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2977 | if (m_overrideResourceLoadPriorityForTesting) |
| 2978 | request.setPriority(m_overrideResourceLoadPriorityForTesting.value()); |
| 2979 | |
Ms2ger@igalia.com | c33b77c | 2017-11-10 16:41:03 +0000 | [diff] [blame] | 2980 | applyUserAgentIfNeeded(request); |
commit-queue@webkit.org | 79f5a00 | 2016-10-11 10:53:22 +0000 | [diff] [blame] | 2981 | |
| 2982 | if (isMainResource) |
staikos@webkit.org | 159f11f | 2009-05-18 23:48:30 +0000 | [diff] [blame] | 2983 | request.setHTTPAccept(defaultAcceptHeader); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 2984 | |
| 2985 | // Make sure we send the Origin header. |
| 2986 | addHTTPOriginIfNeeded(request, String()); |
ap@webkit.org | 113cb8c | 2008-12-05 14:43:53 +0000 | [diff] [blame] | 2987 | |
ap@apple.com | 9454f7c | 2013-06-20 20:06:02 +0000 | [diff] [blame] | 2988 | // Only set fallback array if it's still empty (later attempts may be incorrect, see bug 117818). |
| 2989 | if (request.responseContentDispositionEncodingFallbackArray().isEmpty()) { |
| 2990 | // 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] | 2991 | 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] | 2992 | } |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 2993 | } |
| 2994 | |
tony@chromium.org | c1443b7 | 2011-06-24 22:05:16 +0000 | [diff] [blame] | 2995 | void FrameLoader::addHTTPOriginIfNeeded(ResourceRequest& request, const String& origin) |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 2996 | { |
| 2997 | if (!request.httpOrigin().isEmpty()) |
| 2998 | return; // Request already has an Origin header. |
| 2999 | |
| 3000 | // Don't send an Origin header for GET or HEAD to avoid privacy issues. |
| 3001 | // For example, if an intranet page has a hyperlink to an external web |
| 3002 | // site, we don't want to include the Origin of the request because it |
| 3003 | // will leak the internal host name. Similar privacy concerns have lead |
| 3004 | // to the widespread suppression of the Referer header at the network |
| 3005 | // layer. |
| 3006 | if (request.httpMethod() == "GET" || request.httpMethod() == "HEAD") |
| 3007 | return; |
| 3008 | |
| 3009 | // For non-GET and non-HEAD methods, always send an Origin header so the |
| 3010 | // server knows we support this feature. |
| 3011 | |
| 3012 | if (origin.isEmpty()) { |
| 3013 | // If we don't know what origin header to attach, we attach the value |
| 3014 | // for an empty origin. |
abarth@webkit.org | 29f0c1a | 2011-11-05 01:32:07 +0000 | [diff] [blame] | 3015 | request.setHTTPOrigin(SecurityOrigin::createUnique()->toString()); |
tony@chromium.org | c1443b7 | 2011-06-24 22:05:16 +0000 | [diff] [blame] | 3016 | return; |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 3017 | } |
| 3018 | |
| 3019 | request.setHTTPOrigin(origin); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3020 | } |
| 3021 | |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 3022 | // 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>. |
| 3023 | // The algorithm is ammended to treat URLs that inherit their security origin from their owner (e.g. about:blank) |
| 3024 | // as same-site. This matches the behavior of Chrome and Firefox. |
| 3025 | void FrameLoader::addSameSiteInfoToRequestIfNeeded(ResourceRequest& request, const Document* initiator) |
| 3026 | { |
| 3027 | if (!request.isSameSiteUnspecified()) |
| 3028 | return; |
| 3029 | if (!initiator) { |
| 3030 | request.setIsSameSite(true); |
| 3031 | return; |
| 3032 | } |
| 3033 | if (SecurityPolicy::shouldInheritSecurityOriginFromOwner(request.url())) { |
| 3034 | request.setIsSameSite(true); |
| 3035 | return; |
| 3036 | } |
cdumez@apple.com | 0b8674fb | 2019-03-13 19:53:41 +0000 | [diff] [blame] | 3037 | request.setIsSameSite(areRegistrableDomainsEqual(initiator->siteForCookies(), request.url())); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 3038 | } |
| 3039 | |
bfulgham@apple.com | b30d7f8 | 2016-06-07 15:47:30 +0000 | [diff] [blame] | 3040 | void FrameLoader::addHTTPUpgradeInsecureRequestsIfNeeded(ResourceRequest& request) |
| 3041 | { |
| 3042 | if (request.url().protocolIs("https")) { |
| 3043 | // FIXME: Identify HSTS cases and avoid adding the header. <https://bugs.webkit.org/show_bug.cgi?id=157885> |
| 3044 | return; |
| 3045 | } |
| 3046 | |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 3047 | request.setHTTPHeaderField(HTTPHeaderName::UpgradeInsecureRequests, "1"_s); |
bfulgham@apple.com | b30d7f8 | 2016-06-07 15:47:30 +0000 | [diff] [blame] | 3048 | } |
| 3049 | |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 3050 | 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] | 3051 | { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3052 | RELEASE_LOG_IF_ALLOWED("loadPostRequest: frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 3053 | |
beidson@apple.com | bd66a78 | 2015-05-29 16:31:49 +0000 | [diff] [blame] | 3054 | String frameName = request.frameName(); |
| 3055 | LockHistory lockHistory = request.lockHistory(); |
| 3056 | AllowNavigationToInvalidURL allowNavigationToInvalidURL = request.allowNavigationToInvalidURL(); |
| 3057 | NewFrameOpenerPolicy openerPolicy = request.newFrameOpenerPolicy(); |
| 3058 | |
| 3059 | const ResourceRequest& inRequest = request.resourceRequest(); |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3060 | const URL& url = inRequest.url(); |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 3061 | const String& contentType = inRequest.httpContentType(); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 3062 | String origin = inRequest.httpOrigin(); |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 3063 | |
| 3064 | ResourceRequest workingResourceRequest(url); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3065 | |
| 3066 | if (!referrer.isEmpty()) |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 3067 | workingResourceRequest.setHTTPReferrer(referrer); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 3068 | workingResourceRequest.setHTTPOrigin(origin); |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 3069 | workingResourceRequest.setHTTPMethod("POST"); |
youenn.fablet@crf.canon.fr | 11cc655 | 2016-01-22 14:51:16 +0000 | [diff] [blame] | 3070 | workingResourceRequest.setHTTPBody(inRequest.httpBody()); |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 3071 | workingResourceRequest.setHTTPContentType(contentType); |
jochen@chromium.org | dac140c | 2011-08-01 21:18:49 +0000 | [diff] [blame] | 3072 | addExtraFieldsToRequest(workingResourceRequest, loadType, true); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3073 | |
bfulgham@apple.com | b30d7f8 | 2016-06-07 15:47:30 +0000 | [diff] [blame] | 3074 | if (Document* document = m_frame.document()) |
| 3075 | document->contentSecurityPolicy()->upgradeInsecureRequestIfNeeded(workingResourceRequest, ContentSecurityPolicy::InsecureRequestType::Load); |
| 3076 | |
dbates@webkit.org | 9692a07 | 2017-07-12 18:01:19 +0000 | [diff] [blame] | 3077 | NavigationAction action { request.requester(), workingResourceRequest, request.initiatedByMainFrame(), loadType, true, event, request.shouldOpenExternalURLsPolicy(), request.downloadAttribute() }; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3078 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3079 | if (!frameName.isEmpty()) { |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 3080 | // 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] | 3081 | if (auto* targetFrame = formState ? nullptr : findFrameForNavigation(frameName)) { |
commit-queue@webkit.org | a4a9ce2 | 2019-04-10 22:56:35 +0000 | [diff] [blame] | 3082 | targetFrame->loader().loadWithNavigationAction(workingResourceRequest, WTFMove(action), lockHistory, loadType, WTFMove(formState), allowNavigationToInvalidURL, { }, WTFMove(completionHandler)); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 3083 | return; |
darin@chromium.org | 1e25ab7 | 2012-04-02 20:14:07 +0000 | [diff] [blame] | 3084 | } |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 3085 | |
achristensen@apple.com | b075c90 | 2018-07-27 22:29:58 +0000 | [diff] [blame] | 3086 | 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, ShouldContinue shouldContinue) mutable { |
bfulgham@apple.com | 657c5c7 | 2018-05-24 05:23:00 +0000 | [diff] [blame] | 3087 | continueLoadAfterNewWindowPolicy(request, formState.get(), frameName, action, shouldContinue, allowNavigationToInvalidURL, openerPolicy); |
cdumez@apple.com | b76757c | 2018-03-06 22:01:27 +0000 | [diff] [blame] | 3088 | completionHandler(); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 3089 | }); |
| 3090 | return; |
| 3091 | } |
| 3092 | |
| 3093 | // must grab this now, since this load may stop the previous load and clear this flag |
| 3094 | bool isRedirect = m_quickRedirectComing; |
commit-queue@webkit.org | a4a9ce2 | 2019-04-10 22:56:35 +0000 | [diff] [blame] | 3095 | loadWithNavigationAction(workingResourceRequest, WTFMove(action), lockHistory, 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] | 3096 | if (isRedirect) { |
| 3097 | m_quickRedirectComing = false; |
| 3098 | if (m_provisionalDocumentLoader) |
| 3099 | m_provisionalDocumentLoader->setIsClientRedirect(true); |
| 3100 | else if (m_policyDocumentLoader) |
| 3101 | m_policyDocumentLoader->setIsClientRedirect(true); |
| 3102 | } |
| 3103 | completionHandler(); |
| 3104 | }); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3105 | } |
| 3106 | |
youenn@apple.com | b9709cc | 2018-04-16 21:50:26 +0000 | [diff] [blame] | 3107 | 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] | 3108 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3109 | ASSERT(m_frame.document()); |
| 3110 | String referrer = SecurityPolicy::generateReferrerHeader(m_frame.document()->referrerPolicy(), request.url(), outgoingReferrer()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3111 | |
| 3112 | ResourceRequest initialRequest = request; |
| 3113 | initialRequest.setTimeoutInterval(10); |
| 3114 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3115 | if (!referrer.isEmpty()) |
| 3116 | initialRequest.setHTTPReferrer(referrer); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 3117 | addHTTPOriginIfNeeded(initialRequest, outgoingOrigin()); |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 3118 | |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 3119 | initialRequest.setFirstPartyForCookies(m_frame.mainFrame().loader().documentLoader()->request().url()); |
japhet@chromium.org | 92a952b | 2010-07-12 18:14:17 +0000 | [diff] [blame] | 3120 | |
| 3121 | addExtraFieldsToSubresourceRequest(initialRequest); |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 3122 | |
andersca | ec429f5 | 2007-01-13 01:44:24 +0000 | [diff] [blame] | 3123 | unsigned long identifier = 0; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3124 | ResourceRequest newRequest(initialRequest); |
| 3125 | requestFromDelegate(newRequest, identifier, error); |
| 3126 | |
beidson@apple.com | e3ea01d | 2015-07-02 18:33:23 +0000 | [diff] [blame] | 3127 | #if ENABLE(CONTENT_EXTENSIONS) |
| 3128 | if (error.isNull()) { |
commit-queue@webkit.org | 8090ccb | 2015-10-06 08:18:08 +0000 | [diff] [blame] | 3129 | if (auto* page = m_frame.page()) { |
commit-queue@webkit.org | 3d33984 | 2016-08-04 18:07:45 +0000 | [diff] [blame] | 3130 | if (m_documentLoader) { |
achristensen@apple.com | b80d342 | 2019-04-26 17:03:15 +0000 | [diff] [blame] | 3131 | 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] | 3132 | bool blockedLoad = results.summary.blockedLoad; |
| 3133 | ContentExtensions::applyResultsToRequest(WTFMove(results), page, newRequest); |
| 3134 | if (blockedLoad) { |
commit-queue@webkit.org | 3d33984 | 2016-08-04 18:07:45 +0000 | [diff] [blame] | 3135 | newRequest = { }; |
| 3136 | error = ResourceError(errorDomainWebKitInternal, 0, initialRequest.url(), emptyString()); |
| 3137 | response = { }; |
| 3138 | data = nullptr; |
| 3139 | } |
beidson@apple.com | e3ea01d | 2015-07-02 18:33:23 +0000 | [diff] [blame] | 3140 | } |
| 3141 | } |
beidson@apple.com | e3ea01d | 2015-07-02 18:33:23 +0000 | [diff] [blame] | 3142 | } |
| 3143 | #endif |
| 3144 | |
bfulgham@apple.com | b30d7f8 | 2016-06-07 15:47:30 +0000 | [diff] [blame] | 3145 | m_frame.document()->contentSecurityPolicy()->upgradeInsecureRequestIfNeeded(newRequest, ContentSecurityPolicy::InsecureRequestType::Load); |
| 3146 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3147 | if (error.isNull()) { |
| 3148 | ASSERT(!newRequest.isNull()); |
youenn.fablet@crf.canon.fr | 0aef67f | 2015-04-29 08:18:10 +0000 | [diff] [blame] | 3149 | |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 3150 | if (!documentLoader()->applicationCacheHost().maybeLoadSynchronously(newRequest, error, response, data)) { |
youenn.fablet@crf.canon.fr | 0aef67f | 2015-04-29 08:18:10 +0000 | [diff] [blame] | 3151 | Vector<char> buffer; |
youenn@apple.com | b9709cc | 2018-04-16 21:50:26 +0000 | [diff] [blame] | 3152 | 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] | 3153 | data = SharedBuffer::create(WTFMove(buffer)); |
darin@apple.com | c04189e | 2017-01-18 05:17:17 +0000 | [diff] [blame] | 3154 | documentLoader()->applicationCacheHost().maybeLoadFallbackSynchronously(newRequest, error, response, data); |
cdumez@apple.com | 7708545 | 2017-06-30 18:18:19 +0000 | [diff] [blame] | 3155 | ResourceLoadObserver::shared().logSubresourceLoading(&m_frame, newRequest, response); |
ap@webkit.org | fb96f8a | 2009-01-02 09:25:02 +0000 | [diff] [blame] | 3156 | } |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3157 | } |
youenn.fablet@crf.canon.fr | 0aef67f | 2015-04-29 08:18:10 +0000 | [diff] [blame] | 3158 | 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] | 3159 | return identifier; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3160 | } |
| 3161 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3162 | const ResourceRequest& FrameLoader::originalRequest() const |
| 3163 | { |
| 3164 | return activeDocumentLoader()->originalRequestCopy(); |
| 3165 | } |
| 3166 | |
japhet@chromium.org | 7f7bee4 | 2012-03-29 23:17:09 +0000 | [diff] [blame] | 3167 | void FrameLoader::receivedMainResourceError(const ResourceError& error) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3168 | { |
| 3169 | // Retain because the stop may release the last reference to it. |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 3170 | Ref<Frame> protect(m_frame); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3171 | |
| 3172 | RefPtr<DocumentLoader> loader = activeDocumentLoader(); |
japhet@chromium.org | 7f7bee4 | 2012-03-29 23:17:09 +0000 | [diff] [blame] | 3173 | // FIXME: Don't want to do this if an entirely new load is going, so should check |
| 3174 | // that both data sources on the frame are either this or nil. |
| 3175 | stop(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3176 | if (m_client.shouldFallBack(error)) |
japhet@chromium.org | 7f7bee4 | 2012-03-29 23:17:09 +0000 | [diff] [blame] | 3177 | handleFallbackContent(); |
abarth@webkit.org | 1c893f4 | 2009-10-10 02:27:21 +0000 | [diff] [blame] | 3178 | |
lars | 8bf288d | 2007-10-04 08:45:12 +0000 | [diff] [blame] | 3179 | if (m_state == FrameStateProvisional && m_provisionalDocumentLoader) { |
darin@apple.com | 4cd1b24 | 2009-03-27 23:37:46 +0000 | [diff] [blame] | 3180 | if (m_submittedFormURL == m_provisionalDocumentLoader->originalRequestCopy().url()) |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3181 | m_submittedFormURL = URL(); |
antti | ac25cb4 | 2007-03-02 07:59:15 +0000 | [diff] [blame] | 3182 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 3183 | // 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] | 3184 | // transitioned to the new page (before WebFrameState == commit). The goal here is to restore any state |
| 3185 | // 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] | 3186 | history().invalidateCurrentItemCachedPage(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3187 | |
| 3188 | // Call clientRedirectCancelledOrFinished here so that the frame load delegate is notified that the redirect's |
| 3189 | // status has changed, if there was a redirect. The frame load delegate may have saved some state about |
| 3190 | // the redirect in its -webView:willPerformClientRedirectToURL:delay:fireDate:forFrame:. Since we are definitely |
| 3191 | // not going to use this provisional resource, as it was cancelled, notify the frame load delegate that the redirect |
| 3192 | // has ended. |
| 3193 | if (m_sentRedirectNotification) |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 3194 | clientRedirectCancelledOrFinished(NewLoadInProgress::No); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3195 | } |
abarth@webkit.org | 1c893f4 | 2009-10-10 02:27:21 +0000 | [diff] [blame] | 3196 | |
japhet@chromium.org | 7f7bee4 | 2012-03-29 23:17:09 +0000 | [diff] [blame] | 3197 | checkCompleted(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3198 | if (m_frame.page()) |
japhet@chromium.org | 7f7bee4 | 2012-03-29 23:17:09 +0000 | [diff] [blame] | 3199 | checkLoadComplete(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3200 | } |
| 3201 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3202 | void FrameLoader::continueFragmentScrollAfterNavigationPolicy(const ResourceRequest& request, bool shouldContinue) |
| 3203 | { |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3204 | m_quickRedirectComing = false; |
darin | 4e5519d | 2007-01-22 02:46:06 +0000 | [diff] [blame] | 3205 | |
| 3206 | if (!shouldContinue) |
| 3207 | return; |
| 3208 | |
bfulgham@apple.com | 98845d9 | 2016-05-17 01:09:27 +0000 | [diff] [blame] | 3209 | // Calling stopLoading() on the provisional document loader can cause the underlying |
| 3210 | // frame to be deallocated. |
| 3211 | Ref<Frame> protectedFrame(m_frame); |
| 3212 | |
mihaip@chromium.org | d5123ba | 2011-09-16 02:16:46 +0000 | [diff] [blame] | 3213 | // If we have a provisional request for a different document, a fragment scroll should cancel it. |
| 3214 | if (m_provisionalDocumentLoader && !equalIgnoringFragmentIdentifier(m_provisionalDocumentLoader->request().url(), request.url())) { |
| 3215 | m_provisionalDocumentLoader->stopLoading(); |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 3216 | setProvisionalDocumentLoader(nullptr); |
mihaip@chromium.org | d5123ba | 2011-09-16 02:16:46 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3219 | bool isRedirect = m_quickRedirectComing || policyChecker().loadType() == FrameLoadType::RedirectWithLockedBackForwardList; |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3220 | loadInSameDocument(request.url(), 0, !isRedirect); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3221 | } |
| 3222 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3223 | 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] | 3224 | { |
yael.aharon@nokia.com | 79f6905 | 2010-12-30 19:31:00 +0000 | [diff] [blame] | 3225 | // 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] | 3226 | // currently displaying a frameset, or if the URL does not have a fragment. |
| 3227 | // These rules were originally based on what KHTML was doing in KHTMLPart::openURL. |
| 3228 | |
| 3229 | // FIXME: What about load types other than Standard and Reload? |
| 3230 | |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 3231 | return (!isFormSubmission || equalLettersIgnoringASCIICase(httpMethod, "get")) |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 3232 | && !isReload(loadType) |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3233 | && loadType != FrameLoadType::Same |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 3234 | && m_frame.document()->backForwardCacheState() != Document::InBackForwardCache |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3235 | && !shouldReload(m_frame.document()->url(), url) |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 3236 | // We don't want to just scroll if a link from within a |
| 3237 | // frameset is trying to reload the frameset into _top. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3238 | && !m_frame.document()->isFrameSet(); |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 3239 | } |
| 3240 | |
simon.fraser@apple.com | c79e486 | 2017-03-08 20:01:15 +0000 | [diff] [blame] | 3241 | static bool itemAllowsScrollRestoration(HistoryItem* historyItem) |
| 3242 | { |
simon.fraser@apple.com | 804555f | 2017-11-29 20:41:47 +0000 | [diff] [blame] | 3243 | return !historyItem || historyItem->shouldRestoreScrollPosition(); |
simon.fraser@apple.com | c79e486 | 2017-03-08 20:01:15 +0000 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | static bool isSameDocumentReload(bool isNewNavigation, FrameLoadType loadType) |
| 3247 | { |
| 3248 | return !isNewNavigation && !isBackForwardLoadType(loadType); |
| 3249 | } |
| 3250 | |
| 3251 | void FrameLoader::scrollToFragmentWithParentBoundary(const URL& url, bool isNewNavigation) |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 3252 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3253 | FrameView* view = m_frame.view(); |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 3254 | if (!view) |
| 3255 | return; |
| 3256 | |
simon.fraser@apple.com | c79e486 | 2017-03-08 20:01:15 +0000 | [diff] [blame] | 3257 | if (isSameDocumentReload(isNewNavigation, m_loadType) || itemAllowsScrollRestoration(history().currentItem())) |
| 3258 | view->scrollToFragment(url); |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 3259 | } |
| 3260 | |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 3261 | bool FrameLoader::shouldClose() |
| 3262 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3263 | Page* page = m_frame.page(); |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 3264 | if (!page) |
| 3265 | return true; |
| 3266 | if (!page->chrome().canRunBeforeUnloadConfirmPanel()) |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 3267 | return true; |
| 3268 | |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 3269 | // 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] | 3270 | Vector<Ref<Frame>, 16> targetFrames; |
| 3271 | targetFrames.append(m_frame); |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3272 | 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] | 3273 | targetFrames.append(*child); |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 3274 | |
| 3275 | bool shouldClose = false; |
| 3276 | { |
rniwa@webkit.org | f694bd6 | 2017-06-30 19:32:41 +0000 | [diff] [blame] | 3277 | NavigationDisabler navigationDisabler(&m_frame); |
cdumez@apple.com | e4df29d | 2018-09-26 19:29:54 +0000 | [diff] [blame] | 3278 | IgnoreOpensDuringUnloadCountIncrementer ignoreOpensDuringUnloadCountIncrementer(m_frame.document()); |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 3279 | size_t i; |
| 3280 | |
| 3281 | for (i = 0; i < targetFrames.size(); i++) { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3282 | if (!targetFrames[i]->tree().isDescendantOf(&m_frame)) |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 3283 | continue; |
ggaren@apple.com | 7a176e1 | 2015-11-12 01:48:27 +0000 | [diff] [blame] | 3284 | if (!targetFrames[i]->loader().dispatchBeforeUnloadEvent(page->chrome(), this)) |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 3285 | break; |
| 3286 | } |
| 3287 | |
| 3288 | if (i == targetFrames.size()) |
| 3289 | shouldClose = true; |
| 3290 | } |
| 3291 | |
aestes@apple.com | c7f1761 | 2011-08-12 19:56:56 +0000 | [diff] [blame] | 3292 | if (!shouldClose) |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3293 | m_submittedFormURL = URL(); |
aestes@apple.com | c7f1761 | 2011-08-12 19:56:56 +0000 | [diff] [blame] | 3294 | |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3295 | m_currentNavigationHasShownBeforeUnloadConfirmPanel = false; |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 3296 | return shouldClose; |
| 3297 | } |
| 3298 | |
ggaren@apple.com | 7a176e1 | 2015-11-12 01:48:27 +0000 | [diff] [blame] | 3299 | void FrameLoader::dispatchUnloadEvents(UnloadEventPolicy unloadEventPolicy) |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3300 | { |
| 3301 | if (!m_frame.document()) |
| 3302 | return; |
| 3303 | |
ajuma@chromium.org | edd7574 | 2019-09-11 14:52:18 +0000 | [diff] [blame] | 3304 | if (m_pageDismissalEventBeingDispatched != PageDismissalType::None) |
| 3305 | return; |
| 3306 | |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3307 | // We store the frame's page in a local variable because the frame might get detached inside dispatchEvent. |
| 3308 | ForbidPromptsScope forbidPrompts(m_frame.page()); |
cdumez@apple.com | 8b478c6 | 2016-01-23 01:04:59 +0000 | [diff] [blame] | 3309 | IgnoreOpensDuringUnloadCountIncrementer ignoreOpensDuringUnloadCountIncrementer(m_frame.document()); |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3310 | |
| 3311 | if (m_didCallImplicitClose && !m_wasUnloadEventEmitted) { |
| 3312 | auto* currentFocusedElement = m_frame.document()->focusedElement(); |
| 3313 | if (is<HTMLInputElement>(currentFocusedElement)) |
| 3314 | downcast<HTMLInputElement>(*currentFocusedElement).endEditing(); |
| 3315 | if (m_pageDismissalEventBeingDispatched == PageDismissalType::None) { |
| 3316 | if (unloadEventPolicy == UnloadEventPolicyUnloadAndPageHide) { |
| 3317 | m_pageDismissalEventBeingDispatched = PageDismissalType::PageHide; |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 3318 | 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] | 3319 | } |
| 3320 | |
| 3321 | // FIXME: update Page Visibility state here. |
| 3322 | // https://bugs.webkit.org/show_bug.cgi?id=116770 |
| 3323 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 3324 | if (m_frame.document()->backForwardCacheState() == Document::NotInBackForwardCache) { |
rniwa@webkit.org | 6c40374 | 2018-08-17 21:24:40 +0000 | [diff] [blame] | 3325 | 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] | 3326 | // The DocumentLoader (and thus its LoadTiming) might get destroyed |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3327 | // while dispatching the event, so protect it to prevent writing the end |
| 3328 | // time into freed memory. |
| 3329 | RefPtr<DocumentLoader> documentLoader = m_provisionalDocumentLoader; |
| 3330 | m_pageDismissalEventBeingDispatched = PageDismissalType::Unload; |
commit-queue@webkit.org | 3eeac49 | 2016-08-12 22:53:27 +0000 | [diff] [blame] | 3331 | if (documentLoader && documentLoader->timing().startTime() && !documentLoader->timing().unloadEventStart() && !documentLoader->timing().unloadEventEnd()) { |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3332 | auto& timing = documentLoader->timing(); |
| 3333 | timing.markUnloadEventStart(); |
| 3334 | m_frame.document()->domWindow()->dispatchEvent(unloadEvent, m_frame.document()); |
| 3335 | timing.markUnloadEventEnd(); |
| 3336 | } else |
| 3337 | m_frame.document()->domWindow()->dispatchEvent(unloadEvent, m_frame.document()); |
| 3338 | } |
| 3339 | } |
| 3340 | m_pageDismissalEventBeingDispatched = PageDismissalType::None; |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3341 | m_wasUnloadEventEmitted = true; |
| 3342 | } |
| 3343 | |
| 3344 | // Dispatching the unload event could have made m_frame.document() null. |
| 3345 | if (!m_frame.document()) |
| 3346 | return; |
| 3347 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 3348 | if (m_frame.document()->backForwardCacheState() != Document::NotInBackForwardCache) |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3349 | return; |
| 3350 | |
| 3351 | // Don't remove event listeners from a transitional empty document (see bug 28716 for more information). |
| 3352 | bool keepEventListeners = m_stateMachine.isDisplayingInitialEmptyDocument() && m_provisionalDocumentLoader |
| 3353 | && m_frame.document()->isSecureTransitionTo(m_provisionalDocumentLoader->url()); |
| 3354 | |
| 3355 | if (!keepEventListeners) |
| 3356 | m_frame.document()->removeAllEventListeners(); |
| 3357 | } |
| 3358 | |
cdumez@apple.com | 6473cc4 | 2017-03-22 21:14:23 +0000 | [diff] [blame] | 3359 | static bool shouldAskForNavigationConfirmation(Document& document, const BeforeUnloadEvent& event) |
cdumez@apple.com | 6004546 | 2017-02-20 06:36:04 +0000 | [diff] [blame] | 3360 | { |
fred.wang@free.fr | d6e8274 | 2017-08-25 17:28:53 +0000 | [diff] [blame] | 3361 | // Confirmation dialog should not be displayed when the allow-modals flag is not set. |
| 3362 | if (document.isSandboxed(SandboxModals)) |
| 3363 | return false; |
| 3364 | |
cdumez@apple.com | 72d8e4b | 2017-04-17 00:56:47 +0000 | [diff] [blame] | 3365 | bool userDidInteractWithPage = document.topDocument().userDidInteractWithPage(); |
cdumez@apple.com | 6004546 | 2017-02-20 06:36:04 +0000 | [diff] [blame] | 3366 | // Web pages can request we ask for confirmation before navigating by: |
| 3367 | // - Cancelling the BeforeUnloadEvent (modern way) |
| 3368 | // - Setting the returnValue attribute on the BeforeUnloadEvent to a non-empty string. |
| 3369 | // - Returning a non-empty string from the event handler, which is then set as returnValue |
| 3370 | // attribute on the BeforeUnloadEvent. |
cdumez@apple.com | 6473cc4 | 2017-03-22 21:14:23 +0000 | [diff] [blame] | 3371 | return userDidInteractWithPage && (event.defaultPrevented() || !event.returnValue().isEmpty()); |
cdumez@apple.com | 6004546 | 2017-02-20 06:36:04 +0000 | [diff] [blame] | 3372 | } |
| 3373 | |
ggaren@apple.com | 7a176e1 | 2015-11-12 01:48:27 +0000 | [diff] [blame] | 3374 | bool FrameLoader::dispatchBeforeUnloadEvent(Chrome& chrome, FrameLoader* frameLoaderBeingNavigated) |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 3375 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3376 | DOMWindow* domWindow = m_frame.document()->domWindow(); |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 3377 | if (!domWindow) |
| 3378 | return true; |
| 3379 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3380 | RefPtr<Document> document = m_frame.document(); |
cdumez@apple.com | f978083 | 2015-01-27 00:26:21 +0000 | [diff] [blame] | 3381 | if (!document->bodyOrFrameset()) |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 3382 | return true; |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3383 | |
cdumez@apple.com | 32216e4 | 2015-11-12 07:28:57 +0000 | [diff] [blame] | 3384 | Ref<BeforeUnloadEvent> beforeUnloadEvent = BeforeUnloadEvent::create(); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3385 | |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3386 | { |
ajuma@chromium.org | edd7574 | 2019-09-11 14:52:18 +0000 | [diff] [blame] | 3387 | SetForScope<PageDismissalType> change(m_pageDismissalEventBeingDispatched, PageDismissalType::BeforeUnload); |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3388 | ForbidPromptsScope forbidPrompts(m_frame.page()); |
cdumez@apple.com | 32216e4 | 2015-11-12 07:28:57 +0000 | [diff] [blame] | 3389 | domWindow->dispatchEvent(beforeUnloadEvent, domWindow->document()); |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame] | 3390 | } |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3391 | |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 3392 | if (!beforeUnloadEvent->defaultPrevented()) |
akling@apple.com | e8090dd | 2016-08-31 16:32:44 +0000 | [diff] [blame] | 3393 | document->defaultEventHandler(beforeUnloadEvent.get()); |
cdumez@apple.com | 6004546 | 2017-02-20 06:36:04 +0000 | [diff] [blame] | 3394 | |
cdumez@apple.com | 6473cc4 | 2017-03-22 21:14:23 +0000 | [diff] [blame] | 3395 | if (!shouldAskForNavigationConfirmation(*document, beforeUnloadEvent)) |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 3396 | return true; |
| 3397 | |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3398 | // If the navigating FrameLoader has already shown a beforeunload confirmation panel for the current navigation attempt, |
| 3399 | // this frame is not allowed to cause another one to be shown. |
| 3400 | if (frameLoaderBeingNavigated->m_currentNavigationHasShownBeforeUnloadConfirmPanel) { |
utatane.tea@gmail.com | 8407763 | 2018-06-23 08:39:34 +0000 | [diff] [blame] | 3401 | 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] | 3402 | return true; |
| 3403 | } |
| 3404 | |
| 3405 | // We should only display the beforeunload dialog for an iframe if its SecurityOrigin matches all |
| 3406 | // ancestor frame SecurityOrigins up through the navigating FrameLoader. |
| 3407 | if (frameLoaderBeingNavigated != this) { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3408 | Frame* parentFrame = m_frame.tree().parent(); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3409 | while (parentFrame) { |
| 3410 | Document* parentDocument = parentFrame->document(); |
| 3411 | if (!parentDocument) |
| 3412 | return true; |
akling@apple.com | 6be0e97 | 2017-01-18 19:35:49 +0000 | [diff] [blame] | 3413 | 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] | 3414 | 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] | 3415 | return true; |
| 3416 | } |
| 3417 | |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 3418 | if (&parentFrame->loader() == frameLoaderBeingNavigated) |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3419 | break; |
| 3420 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3421 | parentFrame = parentFrame->tree().parent(); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | // The navigatingFrameLoader should always be in our ancestory. |
| 3425 | ASSERT(parentFrame); |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 3426 | ASSERT(&parentFrame->loader() == frameLoaderBeingNavigated); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 3427 | } |
| 3428 | |
| 3429 | frameLoaderBeingNavigated->m_currentNavigationHasShownBeforeUnloadConfirmPanel = true; |
| 3430 | |
ch.dumez@sisa.samsung.com | 231386f | 2013-09-09 18:40:04 +0000 | [diff] [blame] | 3431 | String text = document->displayStringModifiedByEncoding(beforeUnloadEvent->returnValue()); |
darin@apple.com | 9ace801 | 2017-01-23 06:24:18 +0000 | [diff] [blame] | 3432 | return chrome.runBeforeUnloadConfirmPanel(text, m_frame); |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 3433 | } |
| 3434 | |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 3435 | void FrameLoader::continueLoadAfterNavigationPolicy(const ResourceRequest& request, FormState* formState, NavigationPolicyDecision navigationPolicyDecision, AllowNavigationToInvalidURL allowNavigationToInvalidURL) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3436 | { |
| 3437 | // If we loaded an alternate page to replace an unreachableURL, we'll get in here with a |
| 3438 | // nil policyDataSource because loading the alternate page will have passed |
| 3439 | // through this method already, nested; otherwise, policyDataSource should still be set. |
| 3440 | ASSERT(m_policyDocumentLoader || !m_provisionalDocumentLoader->unreachableURL().isEmpty()); |
| 3441 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3442 | bool isTargetItem = history().provisionalItem() ? history().provisionalItem()->isTargetItem() : false; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3443 | |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 3444 | bool urlIsDisallowed = allowNavigationToInvalidURL == AllowNavigationToInvalidURL::No && !request.url().isValid(); |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 3445 | bool canContinue = navigationPolicyDecision == NavigationPolicyDecision::ContinueLoad && shouldClose() && !urlIsDisallowed; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3446 | |
| 3447 | if (!canContinue) { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3448 | RELEASE_LOG_IF_ALLOWED("continueLoadAfterNavigationPolicy: can't continue loading frame due to the following reasons (" |
| 3449 | "frame = %p, " |
| 3450 | "main = %d, " |
| 3451 | "allowNavigationToInvalidURL = %d, " |
| 3452 | "requestURLIsValid = %d, " |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 3453 | "navigationPolicyDecision = %d)", |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3454 | &m_frame, |
| 3455 | m_frame.isMainFrame(), |
| 3456 | static_cast<int>(allowNavigationToInvalidURL), |
| 3457 | request.url().isValid(), |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 3458 | static_cast<int>(navigationPolicyDecision)); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3459 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3460 | // If we were waiting for a quick redirect, but the policy delegate decided to ignore it, then we |
| 3461 | // need to report that the client redirect was cancelled. |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 3462 | // FIXME: The client should be told about ignored non-quick redirects, too. |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3463 | if (m_quickRedirectComing) |
achristensen@apple.com | 6fddc91 | 2018-10-18 21:16:52 +0000 | [diff] [blame] | 3464 | clientRedirectCancelledOrFinished(NewLoadInProgress::No); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3465 | |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 3466 | if (navigationPolicyDecision == NavigationPolicyDecision::StopAllLoads) { |
| 3467 | stopAllLoaders(); |
| 3468 | m_checkTimer.stop(); |
| 3469 | } |
| 3470 | |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 3471 | setPolicyDocumentLoader(nullptr); |
cdumez@apple.com | d653185 | 2018-03-06 03:13:32 +0000 | [diff] [blame] | 3472 | checkCompleted(); |
cdumez@apple.com | 2e66584 | 2019-02-01 22:52:58 +0000 | [diff] [blame] | 3473 | |
| 3474 | if (navigationPolicyDecision != NavigationPolicyDecision::StopAllLoads) |
| 3475 | checkLoadComplete(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3476 | |
| 3477 | // 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] | 3478 | // 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] | 3479 | // 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] | 3480 | if ((isTargetItem || m_frame.isMainFrame()) && isBackForwardLoadType(policyChecker().loadType())) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3481 | if (Page* page = m_frame.page()) { |
achristensen@apple.com | ebfea93 | 2018-10-15 21:45:55 +0000 | [diff] [blame] | 3482 | if (HistoryItem* resetItem = m_frame.mainFrame().loader().history().currentItem()) |
achristensen@apple.com | 3a889f1 | 2018-10-16 15:58:10 +0000 | [diff] [blame] | 3483 | page->backForward().setCurrentItem(*resetItem); |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 3484 | } |
andersca@apple.com | b85d674 | 2011-03-04 03:21:07 +0000 | [diff] [blame] | 3485 | } |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3486 | return; |
| 3487 | } |
| 3488 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 3489 | FrameLoadType type = policyChecker().loadType(); |
commit-queue@webkit.org | 987fd77 | 2011-01-21 18:26:42 +0000 | [diff] [blame] | 3490 | // 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] | 3491 | stopAllLoaders(ShouldNotClearProvisionalItem); |
beidson@apple.com | c90a442 | 2008-10-09 20:43:24 +0000 | [diff] [blame] | 3492 | |
| 3493 | // <rdar://problem/6250856> - In certain circumstances on pages with multiple frames, stopAllLoaders() |
| 3494 | // 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] | 3495 | if (!m_frame.page()) { |
| 3496 | RELEASE_LOG_IF_ALLOWED("continueLoadAfterNavigationPolicy: can't continue loading frame because it became defunct (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
beidson@apple.com | c90a442 | 2008-10-09 20:43:24 +0000 | [diff] [blame] | 3497 | return; |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3498 | } |
timothy@apple.com | 8f20734 | 2009-04-11 05:31:05 +0000 | [diff] [blame] | 3499 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3500 | setProvisionalDocumentLoader(m_policyDocumentLoader.get()); |
| 3501 | m_loadType = type; |
| 3502 | setState(FrameStateProvisional); |
| 3503 | |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 3504 | setPolicyDocumentLoader(nullptr); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3505 | |
cdumez@apple.com | 2574377 | 2015-08-17 22:57:27 +0000 | [diff] [blame] | 3506 | if (isBackForwardLoadType(type)) { |
cdumez@apple.com | 10d0f25 | 2016-04-23 21:33:49 +0000 | [diff] [blame] | 3507 | auto& diagnosticLoggingClient = m_frame.page()->diagnosticLoggingClient(); |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 3508 | if (history().provisionalItem() && history().provisionalItem()->isInBackForwardCache()) { |
| 3509 | diagnosticLoggingClient.logDiagnosticMessageWithResult(DiagnosticLoggingKeys::backForwardCacheKey(), DiagnosticLoggingKeys::retrievalKey(), DiagnosticLoggingResultPass, ShouldSample::Yes); |
cdumez@apple.com | 2574377 | 2015-08-17 22:57:27 +0000 | [diff] [blame] | 3510 | loadProvisionalItemFromCachedPage(); |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3511 | RELEASE_LOG_IF_ALLOWED("continueLoadAfterNavigationPolicy: can't continue loading frame because it will be loaded from cache (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
cdumez@apple.com | 2574377 | 2015-08-17 22:57:27 +0000 | [diff] [blame] | 3512 | return; |
| 3513 | } |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 3514 | diagnosticLoggingClient.logDiagnosticMessageWithResult(DiagnosticLoggingKeys::backForwardCacheKey(), DiagnosticLoggingKeys::retrievalKey(), DiagnosticLoggingResultFail, ShouldSample::Yes); |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 3515 | } |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3516 | |
cdumez@apple.com | a0010ff | 2018-12-13 23:17:44 +0000 | [diff] [blame] | 3517 | CompletionHandler<void()> completionHandler = [this, protectedFrame = makeRef(m_frame)] () mutable { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3518 | if (!m_provisionalDocumentLoader) { |
| 3519 | RELEASE_LOG_IF_ALLOWED("continueLoadAfterNavigationPolicy completionHandler: Frame load canceled #1 (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
achristensen@apple.com | b2d9e11 | 2017-09-25 19:18:50 +0000 | [diff] [blame] | 3520 | return; |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3521 | } |
achristensen@apple.com | b2d9e11 | 2017-09-25 19:18:50 +0000 | [diff] [blame] | 3522 | |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 3523 | prepareForLoadStart(); |
beidson@apple.com | 0262233 | 2018-04-13 18:04:22 +0000 | [diff] [blame] | 3524 | |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 3525 | // The load might be cancelled inside of prepareForLoadStart(), nulling out the m_provisionalDocumentLoader, |
| 3526 | // so we need to null check it again. |
| 3527 | if (!m_provisionalDocumentLoader) { |
| 3528 | RELEASE_LOG_IF_ALLOWED("prepareForLoadStart completionHandler: Frame load canceled #2 (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 3529 | return; |
| 3530 | } |
| 3531 | |
| 3532 | DocumentLoader* activeDocLoader = activeDocumentLoader(); |
| 3533 | if (activeDocLoader && activeDocLoader->isLoadingMainResource()) { |
| 3534 | RELEASE_LOG_IF_ALLOWED("prepareForLoadStart completionHandler: Main frame already being loaded (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 3535 | return; |
| 3536 | } |
| 3537 | |
| 3538 | m_loadingFromCachedPage = false; |
beidson@apple.com | 0262233 | 2018-04-13 18:04:22 +0000 | [diff] [blame] | 3539 | |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 3540 | m_provisionalDocumentLoader->startLoadingMainResource(); |
achristensen@apple.com | b2d9e11 | 2017-09-25 19:18:50 +0000 | [diff] [blame] | 3541 | }; |
| 3542 | |
andersca@apple.com | 61e3332 | 2013-10-05 04:52:04 +0000 | [diff] [blame] | 3543 | if (!formState) { |
achristensen@apple.com | b2d9e11 | 2017-09-25 19:18:50 +0000 | [diff] [blame] | 3544 | completionHandler(); |
andersca@apple.com | 61e3332 | 2013-10-05 04:52:04 +0000 | [diff] [blame] | 3545 | return; |
| 3546 | } |
| 3547 | |
achristensen@apple.com | b2d9e11 | 2017-09-25 19:18:50 +0000 | [diff] [blame] | 3548 | m_client.dispatchWillSubmitForm(*formState, WTFMove(completionHandler)); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3549 | } |
| 3550 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3551 | void FrameLoader::continueLoadAfterNewWindowPolicy(const ResourceRequest& request, |
beidson@apple.com | e9d460a | 2018-04-10 00:31:02 +0000 | [diff] [blame] | 3552 | FormState* formState, const String& frameName, const NavigationAction& action, ShouldContinue shouldContinue, AllowNavigationToInvalidURL allowNavigationToInvalidURL, NewFrameOpenerPolicy openerPolicy) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3553 | { |
beidson@apple.com | e9d460a | 2018-04-10 00:31:02 +0000 | [diff] [blame] | 3554 | if (shouldContinue != ShouldContinue::Yes) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3555 | return; |
| 3556 | |
akling@apple.com | 55cde01 | 2013-10-05 00:35:12 +0000 | [diff] [blame] | 3557 | Ref<Frame> frame(m_frame); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3558 | RefPtr<Frame> mainFrame = m_client.dispatchCreatePage(action); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3559 | if (!mainFrame) |
| 3560 | return; |
| 3561 | |
commit-queue@webkit.org | 04df842 | 2017-06-09 17:59:18 +0000 | [diff] [blame] | 3562 | SandboxFlags sandboxFlags = frame->loader().effectiveSandboxFlags(); |
| 3563 | if (sandboxFlags & SandboxPropagatesToAuxiliaryBrowsingContexts) |
| 3564 | mainFrame->loader().forceSandboxFlags(sandboxFlags); |
wilander@apple.com | 2d7ea24 | 2016-08-08 21:43:36 +0000 | [diff] [blame] | 3565 | |
cdumez@apple.com | eec032f | 2017-04-05 13:36:47 +0000 | [diff] [blame] | 3566 | if (!equalIgnoringASCIICase(frameName, "_blank")) |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3567 | mainFrame->tree().setName(frameName); |
kmccullo | 1f90121 | 2007-05-16 20:57:47 +0000 | [diff] [blame] | 3568 | |
eric@webkit.org | 5aee676 | 2009-10-06 18:20:33 +0000 | [diff] [blame] | 3569 | mainFrame->page()->setOpenedByDOM(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3570 | mainFrame->loader().m_client.dispatchShow(); |
ap@apple.com | a383f25 | 2015-02-14 18:16:00 +0000 | [diff] [blame] | 3571 | if (openerPolicy == NewFrameOpenerPolicy::Allow) { |
cdumez@apple.com | 7814173 | 2014-11-04 23:00:48 +0000 | [diff] [blame] | 3572 | mainFrame->loader().setOpener(frame.ptr()); |
jochen@chromium.org | 235ee97 | 2012-05-09 22:13:12 +0000 | [diff] [blame] | 3573 | mainFrame->document()->setReferrerPolicy(frame->document()->referrerPolicy()); |
| 3574 | } |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 3575 | |
cdumez@apple.com | 548d7bb | 2018-10-09 18:25:29 +0000 | [diff] [blame] | 3576 | NavigationAction newAction { *frame->document(), request, InitiatedByMainFrame::Unknown, NavigationType::Other, action.shouldOpenExternalURLsPolicy(), nullptr, action.downloadAttribute() }; |
cdumez@apple.com | 91e03bd | 2018-09-17 17:15:07 +0000 | [diff] [blame] | 3577 | mainFrame->loader().loadWithNavigationAction(request, WTFMove(newAction), LockHistory::No, FrameLoadType::Standard, formState, allowNavigationToInvalidURL); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3578 | } |
| 3579 | |
andersca | ec429f5 | 2007-01-13 01:44:24 +0000 | [diff] [blame] | 3580 | void FrameLoader::requestFromDelegate(ResourceRequest& request, unsigned long& identifier, ResourceError& error) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3581 | { |
| 3582 | ASSERT(!request.isNull()); |
| 3583 | |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 3584 | identifier = 0; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3585 | if (Page* page = m_frame.page()) { |
akling@apple.com | eb67e0a | 2013-08-19 08:24:08 +0000 | [diff] [blame] | 3586 | identifier = page->progress().createUniqueIdentifier(); |
akling@apple.com | 654fd9a | 2013-10-06 21:07:29 +0000 | [diff] [blame] | 3587 | notifier().assignIdentifierToInitialRequest(identifier, m_documentLoader.get(), request); |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 3588 | } |
andersca | ec429f5 | 2007-01-13 01:44:24 +0000 | [diff] [blame] | 3589 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3590 | ResourceRequest newRequest(request); |
akling@apple.com | 654fd9a | 2013-10-06 21:07:29 +0000 | [diff] [blame] | 3591 | notifier().dispatchWillSendRequest(m_documentLoader.get(), identifier, newRequest, ResourceResponse()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3592 | |
| 3593 | if (newRequest.isNull()) |
weinig@apple.com | 87a569c | 2008-05-18 01:21:20 +0000 | [diff] [blame] | 3594 | error = cancelledError(request); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3595 | else |
| 3596 | error = ResourceError(); |
| 3597 | |
| 3598 | request = newRequest; |
| 3599 | } |
| 3600 | |
cdumez@apple.com | d038ecf | 2017-08-15 21:15:09 +0000 | [diff] [blame] | 3601 | void FrameLoader::loadedResourceFromMemoryCache(CachedResource& resource, ResourceRequest& newRequest, ResourceError& error) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3602 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3603 | Page* page = m_frame.page(); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3604 | if (!page) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3605 | return; |
| 3606 | |
cdumez@apple.com | d038ecf | 2017-08-15 21:15:09 +0000 | [diff] [blame] | 3607 | if (!resource.shouldSendResourceLoadCallbacks() || m_documentLoader->haveToldClientAboutLoad(resource.url())) |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3608 | return; |
| 3609 | |
japhet@chromium.org | 3e31718 | 2013-01-29 20:06:19 +0000 | [diff] [blame] | 3610 | // 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] | 3611 | if (resource.type() == CachedResource::Type::MainResource) |
japhet@chromium.org | 3e31718 | 2013-01-29 20:06:19 +0000 | [diff] [blame] | 3612 | return; |
| 3613 | |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3614 | if (!page->areMemoryCacheClientCallsEnabled()) { |
cdumez@apple.com | d038ecf | 2017-08-15 21:15:09 +0000 | [diff] [blame] | 3615 | InspectorInstrumentation::didLoadResourceFromMemoryCache(*page, m_documentLoader.get(), &resource); |
| 3616 | m_documentLoader->recordMemoryCacheLoadForFutureClientNotification(resource.resourceRequest()); |
| 3617 | m_documentLoader->didTellClientAboutLoad(resource.url()); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3618 | return; |
| 3619 | } |
| 3620 | |
cdumez@apple.com | d038ecf | 2017-08-15 21:15:09 +0000 | [diff] [blame] | 3621 | if (m_client.dispatchDidLoadResourceFromMemoryCache(m_documentLoader.get(), newRequest, resource.response(), resource.encodedSize())) { |
| 3622 | InspectorInstrumentation::didLoadResourceFromMemoryCache(*page, m_documentLoader.get(), &resource); |
| 3623 | m_documentLoader->didTellClientAboutLoad(resource.url()); |
timothy@apple.com | 8f85dce | 2008-01-08 23:51:28 +0000 | [diff] [blame] | 3624 | return; |
| 3625 | } |
| 3626 | |
andersca | ec429f5 | 2007-01-13 01:44:24 +0000 | [diff] [blame] | 3627 | unsigned long identifier; |
aestes@apple.com | 0c8e191 | 2013-04-06 03:09:25 +0000 | [diff] [blame] | 3628 | requestFromDelegate(newRequest, identifier, error); |
joepeck@webkit.org | e7d264d | 2017-03-09 03:35:13 +0000 | [diff] [blame] | 3629 | |
cdumez@apple.com | d038ecf | 2017-08-15 21:15:09 +0000 | [diff] [blame] | 3630 | ResourceResponse response = resource.response(); |
joepeck@webkit.org | e7d264d | 2017-03-09 03:35:13 +0000 | [diff] [blame] | 3631 | response.setSource(ResourceResponse::Source::MemoryCache); |
cdumez@apple.com | d038ecf | 2017-08-15 21:15:09 +0000 | [diff] [blame] | 3632 | notifier().sendRemainingDelegateMessages(m_documentLoader.get(), identifier, newRequest, response, 0, resource.encodedSize(), 0, error); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3633 | } |
| 3634 | |
Ms2ger@igalia.com | c33b77c | 2017-11-10 16:41:03 +0000 | [diff] [blame] | 3635 | void FrameLoader::applyUserAgentIfNeeded(ResourceRequest& request) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3636 | { |
Ms2ger@igalia.com | c33b77c | 2017-11-10 16:41:03 +0000 | [diff] [blame] | 3637 | if (!request.hasHTTPHeaderField(HTTPHeaderName::UserAgent)) { |
| 3638 | String userAgent = this->userAgent(request.url()); |
| 3639 | ASSERT(!userAgent.isNull()); |
| 3640 | request.setHTTPUserAgent(userAgent); |
| 3641 | } |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3642 | } |
| 3643 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3644 | 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] | 3645 | { |
akling@apple.com | 5298947 | 2013-09-16 20:09:25 +0000 | [diff] [blame] | 3646 | Frame& topFrame = m_frame.tree().top(); |
| 3647 | if (&m_frame == &topFrame) |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 3648 | return false; |
| 3649 | |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3650 | XFrameOptionsDisposition disposition = parseXFrameOptionsHeader(content); |
| 3651 | |
| 3652 | switch (disposition) { |
| 3653 | case XFrameOptionsSameOrigin: { |
yusukesuzuki@slowstart.org | ae5a8bd | 2018-12-22 06:37:39 +0000 | [diff] [blame] | 3654 | auto origin = SecurityOrigin::create(url); |
akling@apple.com | 5298947 | 2013-09-16 20:09:25 +0000 | [diff] [blame] | 3655 | if (!origin->isSameSchemeHostPort(topFrame.document()->securityOrigin())) |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 3656 | return true; |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3657 | 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] | 3658 | if (!origin->isSameSchemeHostPort(frame->document()->securityOrigin())) |
dbates@webkit.org | 250656a | 2018-05-12 04:11:16 +0000 | [diff] [blame] | 3659 | return true; |
mkwst@chromium.org | f9d8fa0 | 2013-03-19 21:12:24 +0000 | [diff] [blame] | 3660 | } |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3661 | return false; |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 3662 | } |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3663 | case XFrameOptionsDeny: |
| 3664 | return true; |
| 3665 | case XFrameOptionsAllowAll: |
| 3666 | return false; |
| 3667 | case XFrameOptionsConflict: |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 3668 | 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] | 3669 | return true; |
| 3670 | case XFrameOptionsInvalid: |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 3671 | 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] | 3672 | return false; |
psolanki@apple.com | e2dc3b9 | 2014-02-20 18:23:24 +0000 | [diff] [blame] | 3673 | case XFrameOptionsNone: |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3674 | return false; |
| 3675 | } |
psolanki@apple.com | e2dc3b9 | 2014-02-20 18:23:24 +0000 | [diff] [blame] | 3676 | ASSERT_NOT_REACHED(); |
| 3677 | return false; |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 3678 | } |
| 3679 | |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 3680 | void FrameLoader::loadProvisionalItemFromCachedPage() |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3681 | { |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 3682 | DocumentLoader* provisionalLoader = provisionalDocumentLoader(); |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 3683 | 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] | 3684 | |
achristensen@apple.com | c41ad69 | 2019-01-31 21:23:44 +0000 | [diff] [blame] | 3685 | prepareForLoadStart(); |
| 3686 | |
| 3687 | m_loadingFromCachedPage = true; |
| 3688 | |
| 3689 | // Should have timing data from previous time(s) the page was shown. |
| 3690 | ASSERT(provisionalLoader->timing().startTime()); |
| 3691 | provisionalLoader->resetTiming(); |
| 3692 | provisionalLoader->timing().markStartTime(); |
| 3693 | |
| 3694 | provisionalLoader->setCommitted(true); |
| 3695 | commitProvisionalLoad(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3696 | } |
| 3697 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3698 | bool FrameLoader::shouldTreatURLAsSameAsCurrent(const URL& url) const |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3699 | { |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3700 | if (!history().currentItem()) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3701 | return false; |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3702 | return url == history().currentItem()->url() || url == history().currentItem()->originalURL(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3703 | } |
| 3704 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3705 | bool FrameLoader::shouldTreatURLAsSrcdocDocument(const URL& url) const |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 3706 | { |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 3707 | if (!equalLettersIgnoringASCIICase(url.string(), "about:srcdoc")) |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 3708 | return false; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3709 | HTMLFrameOwnerElement* ownerElement = m_frame.ownerElement(); |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 3710 | if (!ownerElement) |
| 3711 | return false; |
| 3712 | if (!ownerElement->hasTagName(iframeTag)) |
| 3713 | return false; |
rniwa@webkit.org | bda54a0 | 2016-07-18 00:39:37 +0000 | [diff] [blame] | 3714 | return ownerElement->hasAttributeWithoutSynchronization(srcdocAttr); |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 3715 | } |
| 3716 | |
darin@apple.com | 0ce67df | 2019-06-17 01:48:13 +0000 | [diff] [blame] | 3717 | Frame* FrameLoader::findFrameForNavigation(const AtomString& name, Document* activeDocument) |
weinig@apple.com | 7742780 | 2008-01-11 00:23:13 +0000 | [diff] [blame] | 3718 | { |
ap@apple.com | f8c414e | 2013-08-13 03:44:57 +0000 | [diff] [blame] | 3719 | // FIXME: Eventually all callers should supply the actual activeDocument so we can call canNavigate with the right document. |
| 3720 | if (!activeDocument) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3721 | activeDocument = m_frame.document(); |
ap@apple.com | f8c414e | 2013-08-13 03:44:57 +0000 | [diff] [blame] | 3722 | |
cdumez@apple.com | 6cb3eff | 2018-10-15 15:34:39 +0000 | [diff] [blame] | 3723 | auto* frame = m_frame.tree().find(name, activeDocument->frame() ? *activeDocument->frame() : m_frame); |
| 3724 | |
ap@apple.com | f8c414e | 2013-08-13 03:44:57 +0000 | [diff] [blame] | 3725 | if (!activeDocument->canNavigate(frame)) |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3726 | return nullptr; |
abarth@webkit.org | b46fdef | 2012-04-13 00:42:37 +0000 | [diff] [blame] | 3727 | |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 3728 | return frame; |
weinig@apple.com | 7742780 | 2008-01-11 00:23:13 +0000 | [diff] [blame] | 3729 | } |
| 3730 | |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3731 | void FrameLoader::loadSameDocumentItem(HistoryItem& item) |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3732 | { |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3733 | ASSERT(item.documentSequenceNumber() == history().currentItem()->documentSequenceNumber()); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3734 | |
aestes@apple.com | 8303b34 | 2016-02-19 09:29:44 +0000 | [diff] [blame] | 3735 | Ref<Frame> protect(m_frame); |
| 3736 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3737 | // Save user view state to the current history item here since we don't do a normal load. |
| 3738 | // FIXME: Does form state need to be saved here too? |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3739 | history().saveScrollPositionAndViewStateToItem(history().currentItem()); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3740 | if (FrameView* view = m_frame.view()) |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3741 | view->setWasScrolledByUser(false); |
| 3742 | |
achristensen@apple.com | 3a889f1 | 2018-10-16 15:58:10 +0000 | [diff] [blame] | 3743 | history().setCurrentItem(item); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3744 | |
| 3745 | // 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] | 3746 | loadInSameDocument(item.url(), item.stateObject(), false); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3747 | |
| 3748 | // 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] | 3749 | history().restoreScrollPositionAndViewState(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3750 | } |
| 3751 | |
abarth@webkit.org | 1c893f4 | 2009-10-10 02:27:21 +0000 | [diff] [blame] | 3752 | // FIXME: This function should really be split into a couple pieces, some of |
| 3753 | // which should be methods of HistoryController and some of which should be |
| 3754 | // methods of FrameLoader. |
cdumez@apple.com | 29f7c1e | 2019-03-13 20:32:48 +0000 | [diff] [blame] | 3755 | void FrameLoader::loadDifferentDocumentItem(HistoryItem& item, HistoryItem* fromItem, FrameLoadType loadType, FormSubmissionCacheLoadPolicy cacheLoadPolicy, ShouldTreatAsContinuingLoad shouldTreatAsContinuingLoad) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3756 | { |
krollin@apple.com | e1810b6 | 2018-12-20 19:23:20 +0000 | [diff] [blame] | 3757 | RELEASE_LOG_IF_ALLOWED("loadDifferentDocumentItem: frame load started (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame()); |
| 3758 | |
bfulgham@apple.com | d0c0fc8 | 2019-05-17 16:03:36 +0000 | [diff] [blame] | 3759 | Ref<Frame> protectedFrame(m_frame); |
| 3760 | |
jiewen_tan@apple.com | 71ef00e | 2018-12-04 23:01:29 +0000 | [diff] [blame] | 3761 | // History items should not be reported to the parent. |
| 3762 | m_shouldReportResourceTimingToParentFrame = false; |
| 3763 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3764 | // 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] | 3765 | history().setProvisionalItem(&item); |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 3766 | |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 3767 | auto initiatedByMainFrame = InitiatedByMainFrame::Unknown; |
| 3768 | |
cdumez@apple.com | 3aedc03 | 2019-01-31 02:23:55 +0000 | [diff] [blame] | 3769 | 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] | 3770 | |
cdumez@apple.com | 9265dfe | 2019-10-17 01:44:16 +0000 | [diff] [blame^] | 3771 | if (CachedPage* cachedPage = BackForwardCache::singleton().get(item, m_frame.page())) { |
mitz@apple.com | 4a60442 | 2014-11-13 23:22:50 +0000 | [diff] [blame] | 3772 | auto documentLoader = cachedPage->documentLoader(); |
cdumez@apple.com | 6478e4d | 2015-06-14 04:53:14 +0000 | [diff] [blame] | 3773 | m_client.updateCachedDocumentLoader(*documentLoader); |
beidson@apple.com | 07c00cf | 2018-05-11 16:12:11 +0000 | [diff] [blame] | 3774 | |
| 3775 | auto action = NavigationAction { *m_frame.document(), documentLoader->request(), initiatedByMainFrame, loadType, false }; |
| 3776 | action.setTargetBackForwardItem(item); |
cdumez@apple.com | 29f7c1e | 2019-03-13 20:32:48 +0000 | [diff] [blame] | 3777 | action.setSourceBackForwardItem(fromItem); |
beidson@apple.com | 07c00cf | 2018-05-11 16:12:11 +0000 | [diff] [blame] | 3778 | documentLoader->setTriggeringAction(WTFMove(action)); |
| 3779 | |
mitz@apple.com | 4a60442 | 2014-11-13 23:22:50 +0000 | [diff] [blame] | 3780 | documentLoader->setLastCheckedRequest(ResourceRequest()); |
achristensen@apple.com | 22b9ddf | 2018-08-17 23:24:37 +0000 | [diff] [blame] | 3781 | loadWithDocumentLoader(documentLoader, loadType, { }, AllowNavigationToInvalidURL::Yes, shouldTreatAsContinuingLoad); |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 3782 | return; |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3783 | } |
adele@apple.com | f3d6b89 | 2008-04-29 01:30:20 +0000 | [diff] [blame] | 3784 | |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3785 | URL itemURL = item.url(); |
| 3786 | URL itemOriginalURL = item.originalURL(); |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3787 | URL currentURL; |
beidson | 0c34599 | 2007-02-13 08:59:33 +0000 | [diff] [blame] | 3788 | if (documentLoader()) |
weinig@apple.com | c500266 | 2007-12-12 07:26:19 +0000 | [diff] [blame] | 3789 | currentURL = documentLoader()->url(); |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3790 | RefPtr<FormData> formData = item.formData(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3791 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3792 | ResourceRequest request(itemURL); |
| 3793 | |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3794 | if (!item.referrer().isNull()) |
| 3795 | request.setHTTPReferrer(item.referrer()); |
dbates@webkit.org | ae34b60 | 2015-08-05 16:05:55 +0000 | [diff] [blame] | 3796 | |
dbates@webkit.org | 9692a07 | 2017-07-12 18:01:19 +0000 | [diff] [blame] | 3797 | ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLsPolicyToApply(m_frame, initiatedByMainFrame, item.shouldOpenExternalURLsPolicy()); |
dbates@webkit.org | ae34b60 | 2015-08-05 16:05:55 +0000 | [diff] [blame] | 3798 | bool isFormSubmission = false; |
| 3799 | Event* event = nullptr; |
| 3800 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3801 | // If this was a repost that failed the page cache, we might try to repost the form. |
| 3802 | NavigationAction action; |
| 3803 | if (formData) { |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3804 | request.setHTTPMethod("POST"); |
youenn.fablet@crf.canon.fr | 11cc655 | 2016-01-22 14:51:16 +0000 | [diff] [blame] | 3805 | request.setHTTPBody(WTFMove(formData)); |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3806 | request.setHTTPContentType(item.formContentType()); |
yusukesuzuki@slowstart.org | ae5a8bd | 2018-12-22 06:37:39 +0000 | [diff] [blame] | 3807 | auto securityOrigin = SecurityOrigin::createFromString(item.referrer()); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3808 | addHTTPOriginIfNeeded(request, securityOrigin->toString()); |
bfulgham@apple.com | b30d7f8 | 2016-06-07 15:47:30 +0000 | [diff] [blame] | 3809 | addHTTPUpgradeInsecureRequestsIfNeeded(request); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3810 | |
| 3811 | // Make sure to add extra fields to the request after the Origin header is added for the FormData case. |
| 3812 | // See https://bugs.webkit.org/show_bug.cgi?id=22194 for more discussion. |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3813 | addExtraFieldsToRequest(request, loadType, true); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3814 | |
| 3815 | // FIXME: Slight hack to test if the NSURL cache contains the page we're going to. |
| 3816 | // We want to know this before talking to the policy delegate, since it affects whether |
| 3817 | // we show the DoYouReallyWantToRepost nag. |
| 3818 | // |
| 3819 | // This trick has a small bug (3123893) where we might find a cache hit, but then |
| 3820 | // have the item vanish when we try to use it in the ensuing nav. This should be |
| 3821 | // extremely rare, but in that case the user will get an error on the navigation. |
| 3822 | |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3823 | if (cacheLoadPolicy == MayAttemptCacheOnlyLoadForFormSubmissionItem) { |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 3824 | request.setCachePolicy(ResourceRequestCachePolicy::ReturnCacheDataDontLoad); |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 3825 | action = { *m_frame.document(), request, initiatedByMainFrame, loadType, isFormSubmission, event, shouldOpenExternalURLsPolicy }; |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3826 | } else { |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 3827 | request.setCachePolicy(ResourceRequestCachePolicy::ReturnCacheDataElseLoad); |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 3828 | action = { *m_frame.document(), request, initiatedByMainFrame, NavigationType::FormResubmitted, shouldOpenExternalURLsPolicy, event }; |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3829 | } |
| 3830 | } else { |
| 3831 | switch (loadType) { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3832 | case FrameLoadType::Reload: |
commit-queue@webkit.org | ea87ad8 | 2018-01-11 00:45:49 +0000 | [diff] [blame] | 3833 | case FrameLoadType::ReloadFromOrigin: |
commit-queue@webkit.org | 4833ac5 | 2018-02-26 17:38:14 +0000 | [diff] [blame] | 3834 | case FrameLoadType::ReloadExpiredOnly: |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 3835 | request.setCachePolicy(ResourceRequestCachePolicy::ReloadIgnoringCacheData); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3836 | break; |
| 3837 | case FrameLoadType::Back: |
| 3838 | case FrameLoadType::Forward: |
carlosgc@webkit.org | 2af15b7 | 2016-02-27 07:44:07 +0000 | [diff] [blame] | 3839 | case FrameLoadType::IndexedBackForward: { |
cdumez@apple.com | 3e885d4 | 2016-03-15 20:01:39 +0000 | [diff] [blame] | 3840 | #if PLATFORM(COCOA) |
carlosgc@webkit.org | 2af15b7 | 2016-02-27 07:44:07 +0000 | [diff] [blame] | 3841 | bool allowStaleData = true; |
| 3842 | #else |
| 3843 | bool allowStaleData = !item.wasRestoredFromSession(); |
| 3844 | #endif |
| 3845 | if (allowStaleData) |
simon.fraser@apple.com | 90e9625 | 2018-07-09 23:54:18 +0000 | [diff] [blame] | 3846 | request.setCachePolicy(ResourceRequestCachePolicy::ReturnCacheDataElseLoad); |
carlosgc@webkit.org | 2af15b7 | 2016-02-27 07:44:07 +0000 | [diff] [blame] | 3847 | item.setWasRestoredFromSession(false); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3848 | break; |
carlosgc@webkit.org | 2af15b7 | 2016-02-27 07:44:07 +0000 | [diff] [blame] | 3849 | } |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3850 | case FrameLoadType::Standard: |
| 3851 | case FrameLoadType::RedirectWithLockedBackForwardList: |
| 3852 | break; |
| 3853 | case FrameLoadType::Same: |
antti@apple.com | 5d0c540 | 2017-03-17 19:52:49 +0000 | [diff] [blame] | 3854 | case FrameLoadType::Replace: |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3855 | ASSERT_NOT_REACHED(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3856 | } |
| 3857 | |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3858 | addExtraFieldsToRequest(request, loadType, true); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3859 | |
jochen@chromium.org | 056b7fa | 2011-10-18 04:47:05 +0000 | [diff] [blame] | 3860 | ResourceRequest requestForOriginalURL(request); |
| 3861 | requestForOriginalURL.setURL(itemOriginalURL); |
dbates@webkit.org | 9692a07 | 2017-07-12 18:01:19 +0000 | [diff] [blame] | 3862 | action = { *m_frame.document(), requestForOriginalURL, initiatedByMainFrame, loadType, isFormSubmission, event, shouldOpenExternalURLsPolicy }; |
jochen@chromium.org | 056b7fa | 2011-10-18 04:47:05 +0000 | [diff] [blame] | 3863 | } |
| 3864 | |
beidson@apple.com | 07c00cf | 2018-05-11 16:12:11 +0000 | [diff] [blame] | 3865 | action.setTargetBackForwardItem(item); |
cdumez@apple.com | 29f7c1e | 2019-03-13 20:32:48 +0000 | [diff] [blame] | 3866 | action.setSourceBackForwardItem(fromItem); |
beidson@apple.com | 07c00cf | 2018-05-11 16:12:11 +0000 | [diff] [blame] | 3867 | |
cdumez@apple.com | 91e03bd | 2018-09-17 17:15:07 +0000 | [diff] [blame] | 3868 | loadWithNavigationAction(request, WTFMove(action), LockHistory::No, loadType, { }, AllowNavigationToInvalidURL::Yes); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | // Loads content into this frame, as specified by history item |
cdumez@apple.com | 29f7c1e | 2019-03-13 20:32:48 +0000 | [diff] [blame] | 3872 | void FrameLoader::loadItem(HistoryItem& item, HistoryItem* fromItem, FrameLoadType loadType, ShouldTreatAsContinuingLoad shouldTreatAsContinuingLoad) |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3873 | { |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3874 | m_requestedHistoryItem = &item; |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3875 | HistoryItem* currentItem = history().currentItem(); |
cdumez@apple.com | fea5cb9 | 2015-02-02 00:49:36 +0000 | [diff] [blame] | 3876 | bool sameDocumentNavigation = currentItem && item.shouldDoSameDocumentNavigationTo(*currentItem); |
darin@chromium.org | e71dd0f | 2009-04-17 20:31:17 +0000 | [diff] [blame] | 3877 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3878 | if (sameDocumentNavigation) |
mihaip@chromium.org | e5dbd37 | 2010-12-08 02:32:41 +0000 | [diff] [blame] | 3879 | loadSameDocumentItem(item); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3880 | else |
cdumez@apple.com | 29f7c1e | 2019-03-13 20:32:48 +0000 | [diff] [blame] | 3881 | loadDifferentDocumentItem(item, fromItem, loadType, MayAttemptCacheOnlyLoadForFormSubmissionItem, shouldTreatAsContinuingLoad); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3882 | } |
| 3883 | |
| 3884 | void FrameLoader::retryAfterFailedCacheOnlyMainResourceLoad() |
| 3885 | { |
| 3886 | ASSERT(m_state == FrameStateProvisional); |
| 3887 | ASSERT(!m_loadingFromCachedPage); |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3888 | ASSERT(history().provisionalItem()); |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3889 | ASSERT(history().provisionalItem()->formData()); |
| 3890 | ASSERT(history().provisionalItem() == m_requestedHistoryItem.get()); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3891 | |
| 3892 | FrameLoadType loadType = m_loadType; |
achristensen@apple.com | d924576 | 2019-07-09 18:55:43 +0000 | [diff] [blame] | 3893 | HistoryItem* item = history().provisionalItem(); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3894 | |
| 3895 | stopAllLoaders(ShouldNotClearProvisionalItem); |
achristensen@apple.com | d924576 | 2019-07-09 18:55:43 +0000 | [diff] [blame] | 3896 | if (item) |
| 3897 | loadDifferentDocumentItem(*item, history().currentItem(), loadType, MayNotAttemptCacheOnlyLoadForFormSubmissionItem, ShouldTreatAsContinuingLoad::No); |
| 3898 | else { |
| 3899 | ASSERT_NOT_REACHED(); |
| 3900 | RELEASE_LOG_ERROR(ResourceLoading, "Retrying load after failed cache-only main resource load failed because there is no provisional history item."); |
| 3901 | } |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3902 | } |
| 3903 | |
andersca | c8ee246 | 2007-01-05 22:26:32 +0000 | [diff] [blame] | 3904 | ResourceError FrameLoader::cancelledError(const ResourceRequest& request) const |
| 3905 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3906 | ResourceError error = m_client.cancelledError(request); |
youenn.fablet@crf.canon.fr | 156f9bb | 2016-06-09 06:55:26 +0000 | [diff] [blame] | 3907 | error.setType(ResourceError::Type::Cancellation); |
weinig@apple.com | 87a569c | 2008-05-18 01:21:20 +0000 | [diff] [blame] | 3908 | return error; |
andersca | c8ee246 | 2007-01-05 22:26:32 +0000 | [diff] [blame] | 3909 | } |
| 3910 | |
commit-queue@webkit.org | 8090ccb | 2015-10-06 08:18:08 +0000 | [diff] [blame] | 3911 | ResourceError FrameLoader::blockedByContentBlockerError(const ResourceRequest& request) const |
| 3912 | { |
| 3913 | return m_client.blockedByContentBlockerError(request); |
| 3914 | } |
| 3915 | |
bfulgham@apple.com | b4c7093 | 2016-01-06 22:07:51 +0000 | [diff] [blame] | 3916 | ResourceError FrameLoader::blockedError(const ResourceRequest& request) const |
| 3917 | { |
| 3918 | ResourceError error = m_client.blockedError(request); |
youenn.fablet@crf.canon.fr | 156f9bb | 2016-06-09 06:55:26 +0000 | [diff] [blame] | 3919 | error.setType(ResourceError::Type::Cancellation); |
bfulgham@apple.com | b4c7093 | 2016-01-06 22:07:51 +0000 | [diff] [blame] | 3920 | return error; |
| 3921 | } |
| 3922 | |
aestes@apple.com | 176a9aa | 2016-07-08 20:14:34 +0000 | [diff] [blame] | 3923 | #if ENABLE(CONTENT_FILTERING) |
| 3924 | ResourceError FrameLoader::blockedByContentFilterError(const ResourceRequest& request) const |
| 3925 | { |
| 3926 | ResourceError error = m_client.blockedByContentFilterError(request); |
| 3927 | error.setType(ResourceError::Type::General); |
| 3928 | return error; |
| 3929 | } |
| 3930 | #endif |
| 3931 | |
ap@apple.com | 1e847592 | 2018-10-18 21:38:50 +0000 | [diff] [blame] | 3932 | #if PLATFORM(IOS_FAMILY) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 3933 | RetainPtr<CFDictionaryRef> FrameLoader::connectionProperties(ResourceLoader* loader) |
| 3934 | { |
| 3935 | return m_client.connectionProperties(loader->documentLoader(), loader->identifier()); |
| 3936 | } |
| 3937 | #endif |
| 3938 | |
dbates@webkit.org | 0fefad7 | 2017-10-19 18:46:22 +0000 | [diff] [blame] | 3939 | ReferrerPolicy FrameLoader::effectiveReferrerPolicy() const |
| 3940 | { |
| 3941 | if (auto* parentFrame = m_frame.tree().parent()) |
| 3942 | return parentFrame->document()->referrerPolicy(); |
| 3943 | if (m_opener) |
| 3944 | return m_opener->document()->referrerPolicy(); |
| 3945 | return ReferrerPolicy::NoReferrerWhenDowngrade; |
| 3946 | } |
| 3947 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 3948 | String FrameLoader::referrer() const |
| 3949 | { |
cdumez@apple.com | 327d6c6 | 2016-07-16 04:51:45 +0000 | [diff] [blame] | 3950 | return m_documentLoader ? m_documentLoader->request().httpReferrer() : emptyString(); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 3951 | } |
| 3952 | |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3953 | void FrameLoader::dispatchDidClearWindowObjectsInAllWorlds() |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3954 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3955 | if (!m_frame.script().canExecuteScripts(NotAboutToExecuteScript)) |
thatcher | 10840e5 | 2007-09-22 00:49:09 +0000 | [diff] [blame] | 3956 | return; |
| 3957 | |
weinig@apple.com | 8f71603 | 2013-10-02 17:03:09 +0000 | [diff] [blame] | 3958 | Vector<Ref<DOMWrapperWorld>> worlds; |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3959 | ScriptController::getAllWorlds(worlds); |
cdumez@apple.com | 2f66120 | 2014-11-04 07:22:18 +0000 | [diff] [blame] | 3960 | for (auto& world : worlds) |
| 3961 | dispatchDidClearWindowObjectInWorld(world); |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3962 | } |
| 3963 | |
weinig@apple.com | 8f71603 | 2013-10-02 17:03:09 +0000 | [diff] [blame] | 3964 | void FrameLoader::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld& world) |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3965 | { |
cdumez@apple.com | 87a798a | 2018-04-19 04:02:30 +0000 | [diff] [blame] | 3966 | if (!m_frame.script().canExecuteScripts(NotAboutToExecuteScript) || !m_frame.windowProxy().existingJSWindowProxy(world)) |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3967 | return; |
| 3968 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3969 | m_client.dispatchDidClearWindowObjectInWorld(world); |
timothy@apple.com | efb8ac1 | 2008-07-24 02:48:36 +0000 | [diff] [blame] | 3970 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3971 | if (Page* page = m_frame.page()) |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 3972 | page->inspectorController().didClearWindowObjectInWorld(m_frame, world); |
loislo@chromium.org | e971cb5 | 2011-02-08 17:32:44 +0000 | [diff] [blame] | 3973 | |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 3974 | InspectorInstrumentation::didClearWindowObjectInWorld(m_frame, world); |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3975 | } |
| 3976 | |
beidson@apple.com | 2a75a96 | 2012-04-24 18:12:55 +0000 | [diff] [blame] | 3977 | void FrameLoader::dispatchGlobalObjectAvailableInAllWorlds() |
| 3978 | { |
weinig@apple.com | 8f71603 | 2013-10-02 17:03:09 +0000 | [diff] [blame] | 3979 | Vector<Ref<DOMWrapperWorld>> worlds; |
beidson@apple.com | 2a75a96 | 2012-04-24 18:12:55 +0000 | [diff] [blame] | 3980 | ScriptController::getAllWorlds(worlds); |
cdumez@apple.com | 2f66120 | 2014-11-04 07:22:18 +0000 | [diff] [blame] | 3981 | for (auto& world : worlds) |
| 3982 | m_client.dispatchGlobalObjectAvailable(world); |
beidson@apple.com | 2a75a96 | 2012-04-24 18:12:55 +0000 | [diff] [blame] | 3983 | } |
| 3984 | |
abarth@webkit.org | 8b45d86 | 2011-11-05 21:55:59 +0000 | [diff] [blame] | 3985 | SandboxFlags FrameLoader::effectiveSandboxFlags() const |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3986 | { |
abarth@webkit.org | f2c54c2 | 2010-04-11 06:57:13 +0000 | [diff] [blame] | 3987 | SandboxFlags flags = m_forcedSandboxFlags; |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3988 | if (Frame* parentFrame = m_frame.tree().parent()) |
abarth@webkit.org | 8b45d86 | 2011-11-05 21:55:59 +0000 | [diff] [blame] | 3989 | flags |= parentFrame->document()->sandboxFlags(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3990 | if (HTMLFrameOwnerElement* ownerElement = m_frame.ownerElement()) |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3991 | flags |= ownerElement->sandboxFlags(); |
abarth@webkit.org | 8b45d86 | 2011-11-05 21:55:59 +0000 | [diff] [blame] | 3992 | return flags; |
abarth@webkit.org | f5267a4 | 2010-01-10 08:14:05 +0000 | [diff] [blame] | 3993 | } |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3994 | |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3995 | void FrameLoader::didChangeTitle(DocumentLoader* loader) |
| 3996 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3997 | m_client.didChangeTitle(loader); |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3998 | |
darin@apple.com | 719d29c | 2009-07-24 00:09:17 +0000 | [diff] [blame] | 3999 | if (loader == m_documentLoader) { |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 4000 | // Must update the entries in the back-forward list too. |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 4001 | history().setCurrentItemTitle(loader->title()); |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 4002 | // This must go through the WebFrame because it has the right notion of the current b/f item. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 4003 | m_client.setTitle(loader->title(), loader->urlForHistory()); |
| 4004 | m_client.setMainFrameDocumentReady(true); // update observers with new DOMDocument |
| 4005 | m_client.dispatchDidReceiveTitle(loader->title()); |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 4006 | } |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 4007 | |
| 4008 | #if ENABLE(REMOTE_INSPECTOR) |
| 4009 | if (m_frame.isMainFrame()) |
| 4010 | m_frame.page()->remoteInspectorInformationDidChange(); |
| 4011 | #endif |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 4012 | } |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 4013 | |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 4014 | void FrameLoader::dispatchDidCommitLoad(Optional<HasInsecureContent> initialHasInsecureContent) |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 4015 | { |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 4016 | if (m_stateMachine.creatingInitialEmptyDocument()) |
darin@apple.com | 87134f2 | 2007-12-05 22:58:41 +0000 | [diff] [blame] | 4017 | return; |
| 4018 | |
beidson@apple.com | 4322db0 | 2016-09-16 00:27:11 +0000 | [diff] [blame] | 4019 | m_client.dispatchDidCommitLoad(initialHasInsecureContent); |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 4020 | |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 4021 | if (m_frame.isMainFrame()) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 4022 | m_frame.page()->resetSeenPlugins(); |
| 4023 | m_frame.page()->resetSeenMediaEngines(); |
jer.noble@apple.com | 2d0a60a | 2012-10-18 18:12:57 +0000 | [diff] [blame] | 4024 | } |
jer.noble@apple.com | 381b467 | 2012-07-28 00:41:18 +0000 | [diff] [blame] | 4025 | |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 4026 | InspectorInstrumentation::didCommitLoad(m_frame, m_documentLoader.get()); |
commit-queue@webkit.org | 42b4787 | 2013-02-19 19:19:02 +0000 | [diff] [blame] | 4027 | |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 4028 | #if ENABLE(REMOTE_INSPECTOR) |
akling@apple.com | fbea406 | 2014-02-27 20:24:03 +0000 | [diff] [blame] | 4029 | if (m_frame.isMainFrame()) |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 4030 | m_frame.page()->remoteInspectorInformationDidChange(); |
| 4031 | #endif |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 4032 | } |
| 4033 | |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 4034 | void FrameLoader::tellClientAboutPastMemoryCacheLoads() |
| 4035 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 4036 | ASSERT(m_frame.page()); |
| 4037 | ASSERT(m_frame.page()->areMemoryCacheClientCallsEnabled()); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 4038 | |
| 4039 | if (!m_documentLoader) |
| 4040 | return; |
| 4041 | |
jpfau@apple.com | 97c6a7f | 2013-02-26 00:49:17 +0000 | [diff] [blame] | 4042 | Vector<ResourceRequest> pastLoads; |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 4043 | m_documentLoader->takeMemoryCacheLoadsForClientNotification(pastLoads); |
| 4044 | |
commit-queue@webkit.org | acddfad | 2015-09-30 05:53:51 +0000 | [diff] [blame] | 4045 | for (auto& pastLoad : pastLoads) { |
| 4046 | CachedResource* resource = MemoryCache::singleton().resourceForRequest(pastLoad, m_frame.page()->sessionID()); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 4047 | |
| 4048 | // FIXME: These loads, loaded from cache, but now gone from the cache by the time |
| 4049 | // Page::setMemoryCacheClientCallsEnabled(true) is called, will not be seen by the client. |
| 4050 | // Consider if there's some efficient way of remembering enough to deliver this client call. |
| 4051 | // We have the URL, but not the rest of the response or the length. |
| 4052 | if (!resource) |
| 4053 | continue; |
| 4054 | |
| 4055 | ResourceRequest request(resource->url()); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 4056 | m_client.dispatchDidLoadResourceFromMemoryCache(m_documentLoader.get(), request, resource->response(), resource->encodedSize()); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 4057 | } |
| 4058 | } |
| 4059 | |
diegohcg@webkit.org | 838e0a2 | 2010-09-04 14:48:30 +0000 | [diff] [blame] | 4060 | NetworkingContext* FrameLoader::networkingContext() const |
| 4061 | { |
| 4062 | return m_networkingContext.get(); |
| 4063 | } |
| 4064 | |
antti@apple.com | a6775c1 | 2013-04-05 21:19:56 +0000 | [diff] [blame] | 4065 | void FrameLoader::loadProgressingStatusChanged() |
| 4066 | { |
antti@apple.com | 08536d1 | 2014-06-27 21:58:06 +0000 | [diff] [blame] | 4067 | if (auto* view = m_frame.mainFrame().view()) |
| 4068 | view->loadProgressingStatusChanged(); |
antti@apple.com | a6775c1 | 2013-04-05 21:19:56 +0000 | [diff] [blame] | 4069 | } |
| 4070 | |
timothy_horton@apple.com | 88756d6 | 2013-05-30 06:24:36 +0000 | [diff] [blame] | 4071 | void FrameLoader::forcePageTransitionIfNeeded() |
| 4072 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 4073 | m_client.forcePageTransitionIfNeeded(); |
timothy_horton@apple.com | 88756d6 | 2013-05-30 06:24:36 +0000 | [diff] [blame] | 4074 | } |
| 4075 | |
antti@apple.com | 1229ead | 2015-03-30 21:09:14 +0000 | [diff] [blame] | 4076 | void FrameLoader::clearTestingOverrides() |
| 4077 | { |
cdumez@apple.com | 8b7a022 | 2018-12-20 04:41:11 +0000 | [diff] [blame] | 4078 | m_overrideCachePolicyForTesting = WTF::nullopt; |
| 4079 | m_overrideResourceLoadPriorityForTesting = WTF::nullopt; |
antti@apple.com | 2c4a2a2 | 2015-08-14 14:08:59 +0000 | [diff] [blame] | 4080 | m_isStrictRawResourceValidationPolicyDisabledForTesting = false; |
antti@apple.com | 1229ead | 2015-03-30 21:09:14 +0000 | [diff] [blame] | 4081 | } |
| 4082 | |
commit-queue@webkit.org | 6d63522 | 2016-03-08 06:44:59 +0000 | [diff] [blame] | 4083 | bool FrameLoader::isAlwaysOnLoggingAllowed() const |
| 4084 | { |
| 4085 | return frame().isAlwaysOnLoggingAllowed(); |
| 4086 | } |
| 4087 | |
darin@apple.com | 90a0f15 | 2009-02-01 00:55:03 +0000 | [diff] [blame] | 4088 | bool FrameLoaderClient::hasHTMLView() const |
| 4089 | { |
| 4090 | return true; |
| 4091 | } |
| 4092 | |
dbates@webkit.org | 7f3a982 | 2017-06-22 19:45:10 +0000 | [diff] [blame] | 4093 | 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] | 4094 | { |
| 4095 | ASSERT(!features.dialog || request.frameName().isEmpty()); |
| 4096 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4097 | created = false; |
| 4098 | |
dbates@webkit.org | de972cd | 2018-01-24 22:11:19 +0000 | [diff] [blame] | 4099 | // FIXME: Provide line number information with respect to the opener's document. |
keith_miller@apple.com | bb2f61c | 2018-12-01 03:28:36 +0000 | [diff] [blame] | 4100 | if (WTF::protocolIsJavaScript(request.resourceRequest().url()) && !openerFrame.document()->contentSecurityPolicy()->allowJavaScriptURLs(openerFrame.document()->url(), { })) |
dbates@webkit.org | de972cd | 2018-01-24 22:11:19 +0000 | [diff] [blame] | 4101 | return nullptr; |
| 4102 | |
cdumez@apple.com | eec032f | 2017-04-05 13:36:47 +0000 | [diff] [blame] | 4103 | if (!request.frameName().isEmpty() && !equalIgnoringASCIICase(request.frameName(), "_blank")) { |
cdumez@apple.com | 468ca18 | 2015-05-15 05:07:22 +0000 | [diff] [blame] | 4104 | if (RefPtr<Frame> frame = lookupFrame.loader().findFrameForNavigation(request.frameName(), openerFrame.document())) { |
cdumez@apple.com | eec032f | 2017-04-05 13:36:47 +0000 | [diff] [blame] | 4105 | if (!equalIgnoringASCIICase(request.frameName(), "_self")) { |
jochen@chromium.org | b2c684a | 2013-05-11 19:09:01 +0000 | [diff] [blame] | 4106 | if (Page* page = frame->page()) |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4107 | page->chrome().focus(); |
jochen@chromium.org | b2c684a | 2013-05-11 19:09:01 +0000 | [diff] [blame] | 4108 | } |
aestes@apple.com | 2038dcb | 2015-12-28 16:26:24 +0000 | [diff] [blame] | 4109 | return frame; |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4110 | } |
| 4111 | } |
| 4112 | |
| 4113 | // Sandboxed frames cannot open new auxiliary browsing contexts. |
mkwst@chromium.org | b10ebb43 | 2012-12-04 18:34:27 +0000 | [diff] [blame] | 4114 | if (isDocumentSandboxed(openerFrame, SandboxPopups)) { |
| 4115 | // 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] | 4116 | 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] | 4117 | return nullptr; |
mkwst@chromium.org | b10ebb43 | 2012-12-04 18:34:27 +0000 | [diff] [blame] | 4118 | } |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4119 | |
| 4120 | // FIXME: Setting the referrer should be the caller's responsibility. |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 4121 | 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] | 4122 | if (!referrer.isEmpty()) |
dbates@webkit.org | 7f3a982 | 2017-06-22 19:45:10 +0000 | [diff] [blame] | 4123 | request.resourceRequest().setHTTPReferrer(referrer); |
| 4124 | FrameLoader::addHTTPOriginIfNeeded(request.resourceRequest(), openerFrame.loader().outgoingOrigin()); |
| 4125 | FrameLoader::addHTTPUpgradeInsecureRequestsIfNeeded(request.resourceRequest()); |
dbates@webkit.org | 8c917f2 | 2018-04-24 07:36:59 +0000 | [diff] [blame] | 4126 | FrameLoader::addSameSiteInfoToRequestIfNeeded(request.resourceRequest(), openerFrame.document()); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4127 | |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 4128 | Page* oldPage = openerFrame.page(); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4129 | if (!oldPage) |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4130 | return nullptr; |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4131 | |
beidson@apple.com | 7034ec7 | 2017-07-06 00:01:53 +0000 | [diff] [blame] | 4132 | ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLsPolicyToApply(openerFrame, request); |
dbates@webkit.org | c49c95d | 2017-07-12 17:25:37 +0000 | [diff] [blame] | 4133 | NavigationAction action { request.requester(), request.resourceRequest(), request.initiatedByMainFrame(), NavigationType::Other, shouldOpenExternalURLsPolicy }; |
dbates@webkit.org | 7f3a982 | 2017-06-22 19:45:10 +0000 | [diff] [blame] | 4134 | Page* page = oldPage->chrome().createWindow(openerFrame, request, features, action); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4135 | if (!page) |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4136 | return nullptr; |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4137 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4138 | RefPtr<Frame> frame = &page->mainFrame(); |
| 4139 | |
commit-queue@webkit.org | 04df842 | 2017-06-09 17:59:18 +0000 | [diff] [blame] | 4140 | if (isDocumentSandboxed(openerFrame, SandboxPropagatesToAuxiliaryBrowsingContexts)) |
| 4141 | frame->loader().forceSandboxFlags(openerFrame.document()->sandboxFlags()); |
abarth@webkit.org | 7155e25 | 2011-11-04 18:14:58 +0000 | [diff] [blame] | 4142 | |
cdumez@apple.com | eec032f | 2017-04-05 13:36:47 +0000 | [diff] [blame] | 4143 | if (!equalIgnoringASCIICase(request.frameName(), "_blank")) |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4144 | frame->tree().setName(request.frameName()); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4145 | |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4146 | page->chrome().setToolbarsVisible(features.toolBarVisible || features.locationBarVisible); |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4147 | |
| 4148 | if (!frame->page()) |
| 4149 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4150 | page->chrome().setStatusbarVisible(features.statusBarVisible); |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4151 | |
| 4152 | if (!frame->page()) |
| 4153 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4154 | page->chrome().setScrollbarsVisible(features.scrollbarsVisible); |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4155 | |
| 4156 | if (!frame->page()) |
| 4157 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4158 | page->chrome().setMenubarVisible(features.menuBarVisible); |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4159 | |
| 4160 | if (!frame->page()) |
| 4161 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4162 | page->chrome().setResizable(features.resizable); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4163 | |
| 4164 | // '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] | 4165 | // specify the size of the viewport. We can only resize the window, so adjust |
| 4166 | // for the difference between the window size and the viewport size. |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4167 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4168 | // 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] | 4169 | #if !PLATFORM(IOS_FAMILY) |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4170 | FloatSize viewportSize = page->chrome().pageRect().size(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 4171 | FloatRect windowRect = page->chrome().windowRect(); |
andersca@apple.com | c1242ad | 2015-08-13 17:37:27 +0000 | [diff] [blame] | 4172 | if (features.x) |
| 4173 | windowRect.setX(*features.x); |
| 4174 | if (features.y) |
| 4175 | windowRect.setY(*features.y); |
ap@apple.com | 8d15a82 | 2013-08-09 23:25:11 +0000 | [diff] [blame] | 4176 | // Zero width and height mean using default size, not minumum one. |
andersca@apple.com | c1242ad | 2015-08-13 17:37:27 +0000 | [diff] [blame] | 4177 | if (features.width && *features.width) |
| 4178 | windowRect.setWidth(*features.width + (windowRect.width() - viewportSize.width())); |
| 4179 | if (features.height && *features.height) |
| 4180 | windowRect.setHeight(*features.height + (windowRect.height() - viewportSize.height())); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4181 | |
kenneth@webkit.org | dc092f7 | 2012-11-14 11:05:20 +0000 | [diff] [blame] | 4182 | // 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] | 4183 | FloatRect newWindowRect = DOMWindow::adjustWindowRect(*page, windowRect); |
kenneth@webkit.org | dc092f7 | 2012-11-14 11:05:20 +0000 | [diff] [blame] | 4184 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4185 | if (!frame->page()) |
| 4186 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4187 | page->chrome().setWindowRect(newWindowRect); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 4188 | #else |
| 4189 | // On iOS, width and height refer to the viewport dimensions. |
| 4190 | ViewportArguments arguments; |
| 4191 | // Zero width and height mean using default size, not minimum one. |
andersca@apple.com | c1242ad | 2015-08-13 17:37:27 +0000 | [diff] [blame] | 4192 | if (features.width && *features.width) |
| 4193 | arguments.width = *features.width; |
| 4194 | if (features.height && *features.height) |
| 4195 | arguments.height = *features.height; |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4196 | frame->setViewportArguments(arguments); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 4197 | #endif |
| 4198 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 4199 | if (!frame->page()) |
| 4200 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 4201 | page->chrome().show(); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4202 | |
| 4203 | created = true; |
aestes@apple.com | 2038dcb | 2015-12-28 16:26:24 +0000 | [diff] [blame] | 4204 | return frame; |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 4205 | } |
| 4206 | |
timothy_horton@apple.com | 57a2221 | 2017-10-19 20:43:41 +0000 | [diff] [blame] | 4207 | bool FrameLoader::shouldSuppressTextInputFromEditing() const |
aestes@apple.com | 54c9cf5 | 2016-12-16 23:10:56 +0000 | [diff] [blame] | 4208 | { |
timothy_horton@apple.com | 57a2221 | 2017-10-19 20:43:41 +0000 | [diff] [blame] | 4209 | return m_frame.settings().shouldSuppressTextInputFromEditingDuringProvisionalNavigation() && m_state == FrameStateProvisional; |
aestes@apple.com | 54c9cf5 | 2016-12-16 23:10:56 +0000 | [diff] [blame] | 4210 | } |
| 4211 | |
ggaren | 58e230c | 2006-11-12 04:53:17 +0000 | [diff] [blame] | 4212 | } // namespace WebCore |