darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 1 | /* |
aestes@apple.com | 5e14373 | 2011-03-25 23:07:43 +0000 | [diff] [blame] | 2 | * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 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" |
darin@apple.com | e10e128 | 2010-10-30 00:44:33 +0000 | [diff] [blame] | 40 | #include "BackForwardController.h" |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 41 | #include "BeforeUnloadEvent.h" |
beidson | 448a6e7 | 2007-04-10 23:55:56 +0000 | [diff] [blame] | 42 | #include "CachedPage.h" |
darin@apple.com | e10e128 | 2010-10-30 00:44:33 +0000 | [diff] [blame] | 43 | #include "CachedResourceLoader.h" |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 44 | #include "Chrome.h" |
commit-queue@webkit.org | 52b6833 | 2011-06-07 16:20:07 +0000 | [diff] [blame] | 45 | #include "ChromeClient.h" |
abarth@webkit.org | f921dee | 2011-03-26 11:59:34 +0000 | [diff] [blame] | 46 | #include "ContentSecurityPolicy.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 47 | #include "DOMImplementation.h" |
aroben@apple.com | 92cfa90 | 2008-04-16 19:19:00 +0000 | [diff] [blame] | 48 | #include "DOMWindow.h" |
mark.lam@apple.com | 45beb07 | 2012-12-12 23:04:20 +0000 | [diff] [blame] | 49 | #include "DatabaseManager.h" |
jer.noble@apple.com | 9e0f060 | 2014-11-22 05:27:16 +0000 | [diff] [blame] | 50 | #include "DiagnosticLoggingClient.h" |
eric.carlson@apple.com | 77b4a11 | 2014-10-30 19:04:29 +0000 | [diff] [blame] | 51 | #include "DiagnosticLoggingKeys.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 52 | #include "Document.h" |
tonyg@chromium.org | 064638a | 2010-07-26 17:03:35 +0000 | [diff] [blame] | 53 | #include "DocumentLoadTiming.h" |
darin | c111655 | 2006-10-30 20:05:39 +0000 | [diff] [blame] | 54 | #include "DocumentLoader.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 55 | #include "Editor.h" |
andersca | f623201 | 2006-11-15 00:36:50 +0000 | [diff] [blame] | 56 | #include "EditorClient.h" |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 57 | #include "Element.h" |
darin | f1bb004 | 2006-12-01 22:46:21 +0000 | [diff] [blame] | 58 | #include "Event.h" |
weinig@apple.com | 13d777f | 2013-04-16 21:54:22 +0000 | [diff] [blame] | 59 | #include "EventHandler.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 60 | #include "EventNames.h" |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 61 | #include "FloatRect.h" |
darin | c111655 | 2006-10-30 20:05:39 +0000 | [diff] [blame] | 62 | #include "FormState.h" |
dglazkov@chromium.org | 25a57e5 | 2010-06-20 21:00:35 +0000 | [diff] [blame] | 63 | #include "FormSubmission.h" |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 64 | #include "FrameLoadRequest.h" |
| 65 | #include "FrameLoaderClient.h" |
diegohcg@webkit.org | 838e0a2 | 2010-09-04 14:48:30 +0000 | [diff] [blame] | 66 | #include "FrameNetworkingContext.h" |
ggaren | 52fd107 | 2006-11-06 23:56:59 +0000 | [diff] [blame] | 67 | #include "FrameTree.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 68 | #include "FrameView.h" |
japhet@chromium.org | 3ded963 | 2009-10-19 21:15:06 +0000 | [diff] [blame] | 69 | #include "HTMLAnchorElement.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 70 | #include "HTMLFormElement.h" |
commit-queue@webkit.org | e5739ca | 2012-11-15 19:39:50 +0000 | [diff] [blame] | 71 | #include "HTMLInputElement.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 72 | #include "HTMLNames.h" |
| 73 | #include "HTMLObjectElement.h" |
commit-queue@webkit.org | 26a3a09 | 2012-10-18 19:53:58 +0000 | [diff] [blame] | 74 | #include "HTMLParserIdioms.h" |
andersca@apple.com | a96cf71 | 2014-06-14 17:49:44 +0000 | [diff] [blame] | 75 | #include "HTTPHeaderNames.h" |
ap | e9991d5 | 2006-12-08 18:19:51 +0000 | [diff] [blame] | 76 | #include "HTTPParsers.h" |
andersca@apple.com | 9b9d83b | 2013-04-10 19:11:20 +0000 | [diff] [blame] | 77 | #include "HistoryController.h" |
weinig | 62f94be | 2007-07-18 20:37:20 +0000 | [diff] [blame] | 78 | #include "HistoryItem.h" |
andersca@apple.com | 9b9d83b | 2013-04-10 19:11:20 +0000 | [diff] [blame] | 79 | #include "IconController.h" |
commit-queue@webkit.org | 4c49a66 | 2011-01-02 22:27:10 +0000 | [diff] [blame] | 80 | #include "InspectorController.h" |
yurys@chromium.org | 389a624 | 2011-01-12 13:06:42 +0000 | [diff] [blame] | 81 | #include "InspectorInstrumentation.h" |
beidson@apple.com | 0c140b4 | 2013-01-17 00:45:30 +0000 | [diff] [blame] | 82 | #include "LoaderStrategy.h" |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 83 | #include "Logging.h" |
weinig | 62f94be | 2007-07-18 20:37:20 +0000 | [diff] [blame] | 84 | #include "MIMETypeRegistry.h" |
darin@apple.com | ade301a | 2013-09-27 15:09:01 +0000 | [diff] [blame] | 85 | #include "MainFrame.h" |
weinig@apple.com | 13d777f | 2013-04-16 21:54:22 +0000 | [diff] [blame] | 86 | #include "MemoryCache.h" |
ggaren | 2e94123 | 2007-05-26 00:28:27 +0000 | [diff] [blame] | 87 | #include "PageCache.h" |
barraclough@apple.com | 58899e0 | 2014-02-12 21:56:32 +0000 | [diff] [blame] | 88 | #include "PageThrottler.h" |
ggaren@apple.com | 521f64b | 2009-09-24 05:53:23 +0000 | [diff] [blame] | 89 | #include "PageTransitionEvent.h" |
beidson@apple.com | 0c140b4 | 2013-01-17 00:45:30 +0000 | [diff] [blame] | 90 | #include "PlatformStrategies.h" |
hausmann@webkit.org | 9999bb8 | 2008-03-10 11:52:27 +0000 | [diff] [blame] | 91 | #include "PluginData.h" |
andersca@apple.com | 641fef9 | 2009-01-06 22:57:25 +0000 | [diff] [blame] | 92 | #include "PluginDocument.h" |
abarth@webkit.org | 401a379 | 2013-03-03 10:12:59 +0000 | [diff] [blame] | 93 | #include "PolicyChecker.h" |
andersca | 2b2c5ce | 2007-01-15 21:55:00 +0000 | [diff] [blame] | 94 | #include "ProgressTracker.h" |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 95 | #include "ResourceHandle.h" |
beidson@apple.com | e3ea01d | 2015-07-02 18:33:23 +0000 | [diff] [blame] | 96 | #include "ResourceLoadInfo.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 97 | #include "ResourceRequest.h" |
ossy@webkit.org | 66d8c0a | 2014-02-05 11:42:35 +0000 | [diff] [blame] | 98 | #include "SVGDocument.h" |
| 99 | #include "SVGLocatable.h" |
| 100 | #include "SVGNames.h" |
| 101 | #include "SVGPreserveAspectRatio.h" |
ossy@webkit.org | 66d8c0a | 2014-02-05 11:42:35 +0000 | [diff] [blame] | 102 | #include "SVGViewElement.h" |
| 103 | #include "SVGViewSpec.h" |
beidson@apple.com | c7fe45f | 2010-07-21 23:19:55 +0000 | [diff] [blame] | 104 | #include "SchemeRegistry.h" |
weinig@apple.com | 7909900 | 2008-11-21 05:51:28 +0000 | [diff] [blame] | 105 | #include "ScriptController.h" |
darin@chromium.org | 6b41247 | 2008-11-24 23:07:38 +0000 | [diff] [blame] | 106 | #include "ScriptSourceCode.h" |
vsevik@chromium.org | 53bb069 | 2012-01-18 20:59:10 +0000 | [diff] [blame] | 107 | #include "ScrollAnimator.h" |
weinig | e06430a | 2007-10-19 20:53:22 +0000 | [diff] [blame] | 108 | #include "SecurityOrigin.h" |
abarth@webkit.org | eea9066 | 2011-11-09 07:58:49 +0000 | [diff] [blame] | 109 | #include "SecurityPolicy.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 110 | #include "SegmentedString.h" |
yurys@chromium.org | 832b914 | 2010-08-05 12:36:31 +0000 | [diff] [blame] | 111 | #include "SerializedScriptValue.h" |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 112 | #include "Settings.h" |
akling@apple.com | 7f81b1e | 2013-09-06 17:23:03 +0000 | [diff] [blame] | 113 | #include "SubframeLoader.h" |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 114 | #include "TextResourceDecoder.h" |
beidson@apple.com | e3ea01d | 2015-07-02 18:33:23 +0000 | [diff] [blame] | 115 | #include "UserContentController.h" |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 116 | #include "WindowFeatures.h" |
| 117 | #include "XMLDocumentParser.h" |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 118 | #include <wtf/CurrentTime.h> |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 119 | #include <wtf/Ref.h> |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 120 | #include <wtf/StdLibExtras.h> |
| 121 | #include <wtf/text/CString.h> |
zimmermann@webkit.org | b5e11e6 | 2011-05-16 07:56:06 +0000 | [diff] [blame] | 122 | #include <wtf/text/WTFString.h> |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 123 | |
jcivelli@chromium.org | c2019dd | 2011-05-24 19:32:03 +0000 | [diff] [blame] | 124 | #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
jeremy@chromium.org | c4b86e3 | 2011-02-13 20:28:39 +0000 | [diff] [blame] | 125 | #include "Archive.h" |
jeremy@chromium.org | c4b86e3 | 2011-02-13 20:28:39 +0000 | [diff] [blame] | 126 | #endif |
| 127 | |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 128 | #if PLATFORM(IOS) |
| 129 | #include "DocumentType.h" |
| 130 | #include "MemoryPressureHandler.h" |
| 131 | #include "ResourceLoader.h" |
| 132 | #include "RuntimeApplicationChecksIOS.h" |
| 133 | #include "SystemMemory.h" |
| 134 | #include "WKContentObservation.h" |
| 135 | #endif |
loislo@chromium.org | 82b9dde | 2012-09-12 13:16:31 +0000 | [diff] [blame] | 136 | |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 137 | namespace WebCore { |
| 138 | |
darin@apple.com | 1b75e77 | 2010-06-15 22:20:34 +0000 | [diff] [blame] | 139 | using namespace HTMLNames; |
oliver | b64e408 | 2007-10-12 13:13:51 +0000 | [diff] [blame] | 140 | using namespace SVGNames; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 141 | |
commit-queue@webkit.org | ff400aa | 2011-03-10 23:43:48 +0000 | [diff] [blame] | 142 | 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] | 143 | |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 144 | #if PLATFORM(IOS) |
| 145 | const int memoryLevelThresholdToPrunePageCache = 20; |
| 146 | #endif |
| 147 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 148 | bool isBackForwardLoadType(FrameLoadType type) |
| 149 | { |
| 150 | switch (type) { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 151 | case FrameLoadType::Standard: |
| 152 | case FrameLoadType::Reload: |
| 153 | case FrameLoadType::ReloadFromOrigin: |
| 154 | case FrameLoadType::Same: |
| 155 | case FrameLoadType::RedirectWithLockedBackForwardList: |
| 156 | case FrameLoadType::Replace: |
| 157 | return false; |
| 158 | case FrameLoadType::Back: |
| 159 | case FrameLoadType::Forward: |
| 160 | case FrameLoadType::IndexedBackForward: |
| 161 | return true; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 162 | } |
| 163 | ASSERT_NOT_REACHED(); |
| 164 | return false; |
| 165 | } |
| 166 | |
cjerdonek@webkit.org | 75d1069 | 2010-05-18 16:18:31 +0000 | [diff] [blame] | 167 | // This is not in the FrameLoader class to emphasize that it does not depend on |
| 168 | // private FrameLoader data, and to avoid increasing the number of public functions |
| 169 | // with access to private data. Since only this .cpp file needs it, making it |
| 170 | // non-member lets us exclude it from the header file, thus keeping FrameLoader.h's |
| 171 | // API simpler. |
| 172 | // |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 173 | static bool isDocumentSandboxed(Frame& frame, SandboxFlags mask) |
cjerdonek@webkit.org | 75d1069 | 2010-05-18 16:18:31 +0000 | [diff] [blame] | 174 | { |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 175 | return frame.document() && frame.document()->isSandboxed(mask); |
cjerdonek@webkit.org | 75d1069 | 2010-05-18 16:18:31 +0000 | [diff] [blame] | 176 | } |
| 177 | |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame^] | 178 | struct ForbidPromptsScope { |
| 179 | ForbidPromptsScope(Page* page) : m_page(page) |
| 180 | { |
| 181 | if (!m_page) |
| 182 | return; |
| 183 | m_page->forbidPrompts(); |
| 184 | } |
| 185 | |
| 186 | ~ForbidPromptsScope() |
| 187 | { |
| 188 | if (!m_page) |
| 189 | return; |
| 190 | m_page->allowPrompts(); |
| 191 | } |
| 192 | |
| 193 | Page* m_page; |
| 194 | }; |
| 195 | |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 196 | class FrameLoader::FrameProgressTracker { |
| 197 | public: |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 198 | explicit FrameProgressTracker(Frame& frame) |
| 199 | : m_frame(frame) |
| 200 | , m_inProgress(false) |
| 201 | { |
| 202 | } |
| 203 | |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 204 | ~FrameProgressTracker() |
| 205 | { |
jpfau@apple.com | 7907c6b | 2014-10-28 22:38:44 +0000 | [diff] [blame] | 206 | if (m_inProgress && m_frame.page()) |
andersca@apple.com | cd08879 | 2014-01-10 07:19:29 +0000 | [diff] [blame] | 207 | m_frame.page()->progress().progressCompleted(m_frame); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | void progressStarted() |
| 211 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 212 | ASSERT(m_frame.page()); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 213 | if (!m_inProgress) |
andersca@apple.com | cd08879 | 2014-01-10 07:19:29 +0000 | [diff] [blame] | 214 | m_frame.page()->progress().progressStarted(m_frame); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 215 | m_inProgress = true; |
| 216 | } |
| 217 | |
| 218 | void progressCompleted() |
| 219 | { |
| 220 | ASSERT(m_inProgress); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 221 | ASSERT(m_frame.page()); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 222 | m_inProgress = false; |
andersca@apple.com | cd08879 | 2014-01-10 07:19:29 +0000 | [diff] [blame] | 223 | m_frame.page()->progress().progressCompleted(m_frame); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | private: |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 227 | Frame& m_frame; |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 228 | bool m_inProgress; |
| 229 | }; |
| 230 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 231 | FrameLoader::FrameLoader(Frame& frame, FrameLoaderClient& client) |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 232 | : m_frame(frame) |
ggaren | 1b09a12 | 2006-11-29 06:11:14 +0000 | [diff] [blame] | 233 | , m_client(client) |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 234 | , m_policyChecker(std::make_unique<PolicyChecker>(frame)) |
| 235 | , m_history(std::make_unique<HistoryController>(frame)) |
akling@apple.com | 654fd9a | 2013-10-06 21:07:29 +0000 | [diff] [blame] | 236 | , m_notifier(frame) |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 237 | , m_subframeLoader(std::make_unique<SubframeLoader>(frame)) |
| 238 | , m_icon(std::make_unique<IconController>(frame)) |
| 239 | , m_mixedContentChecker(frame) |
japhet@chromium.org | ce6c1ba | 2012-11-28 19:30:48 +0000 | [diff] [blame] | 240 | , m_state(FrameStateProvisional) |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 241 | , m_loadType(FrameLoadType::Standard) |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 242 | , m_quickRedirectComing(false) |
| 243 | , m_sentRedirectNotification(false) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 244 | , m_inStopAllLoaders(false) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 245 | , m_isExecutingJavaScriptFormAction(false) |
japhet@chromium.org | ce6c1ba | 2012-11-28 19:30:48 +0000 | [diff] [blame] | 246 | , m_didCallImplicitClose(true) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 247 | , m_wasUnloadEventEmitted(false) |
| 248 | , m_isComplete(false) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 249 | , m_needsClear(false) |
andersca@apple.com | 574a745 | 2014-11-21 20:10:13 +0000 | [diff] [blame] | 250 | , m_checkTimer(*this, &FrameLoader::checkTimerFired) |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 251 | , m_shouldCallCheckCompleted(false) |
| 252 | , m_shouldCallCheckLoadComplete(false) |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 253 | , m_opener(nullptr) |
beidson@apple.com | ac095c0 | 2009-08-18 01:37:56 +0000 | [diff] [blame] | 254 | , m_loadingFromCachedPage(false) |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 255 | , m_currentNavigationHasShownBeforeUnloadConfirmPanel(false) |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 256 | , m_loadsSynchronously(false) |
abarth@webkit.org | f2c54c2 | 2010-04-11 06:57:13 +0000 | [diff] [blame] | 257 | , m_forcedSandboxFlags(SandboxNone) |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 258 | { |
| 259 | } |
| 260 | |
| 261 | FrameLoader::~FrameLoader() |
| 262 | { |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 263 | setOpener(nullptr); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 264 | |
commit-queue@webkit.org | acddfad | 2015-09-30 05:53:51 +0000 | [diff] [blame] | 265 | for (auto& frame : m_openedFrames) |
| 266 | frame->loader().m_opener = nullptr; |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 267 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 268 | m_client.frameLoaderDestroyed(); |
diegohcg@webkit.org | 838e0a2 | 2010-09-04 14:48:30 +0000 | [diff] [blame] | 269 | |
| 270 | if (m_networkingContext) |
| 271 | m_networkingContext->invalidate(); |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 272 | } |
| 273 | |
mrowe@apple.com | 5d92f2a | 2008-09-30 21:04:35 +0000 | [diff] [blame] | 274 | void FrameLoader::init() |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 275 | { |
darin@apple.com | 7300681 | 2011-06-29 20:46:33 +0000 | [diff] [blame] | 276 | // This somewhat odd set of steps gives the frame an initial empty document. |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 277 | setPolicyDocumentLoader(m_client.createDocumentLoader(ResourceRequest(URL(ParsedURLString, emptyString())), SubstituteData()).ptr()); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 278 | setProvisionalDocumentLoader(m_policyDocumentLoader.get()); |
japhet@chromium.org | ce6c1ba | 2012-11-28 19:30:48 +0000 | [diff] [blame] | 279 | m_provisionalDocumentLoader->startLoadingMainResource(); |
jpfau@apple.com | ec9eb51 | 2014-07-10 01:13:45 +0000 | [diff] [blame] | 280 | |
| 281 | Ref<Frame> protect(m_frame); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 282 | m_frame.document()->cancelParsing(); |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 283 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocument); |
diegohcg@webkit.org | 838e0a2 | 2010-09-04 14:48:30 +0000 | [diff] [blame] | 284 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 285 | m_networkingContext = m_client.createNetworkingContext(); |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 286 | m_progressTracker = std::make_unique<FrameProgressTracker>(m_frame); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 287 | } |
| 288 | |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 289 | #if PLATFORM(IOS) |
| 290 | void FrameLoader::initForSynthesizedDocument(const URL&) |
| 291 | { |
| 292 | // FIXME: We need to initialize the document URL to the specified URL. Currently the URL is empty and hence |
| 293 | // FrameLoader::checkCompleted() will overwrite the URL of the document to be activeDocumentLoader()->documentURL(). |
| 294 | |
| 295 | RefPtr<DocumentLoader> loader = m_client.createDocumentLoader(ResourceRequest(URL(ParsedURLString, emptyString())), SubstituteData()); |
beidson@apple.com | 10a537f | 2015-07-09 22:30:42 +0000 | [diff] [blame] | 296 | loader->attachToFrame(m_frame); |
antti@apple.com | 7a96ae8 | 2014-09-04 20:59:43 +0000 | [diff] [blame] | 297 | loader->setResponse(ResourceResponse(URL(), ASCIILiteral("text/html"), 0, String())); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 298 | loader->setCommitted(true); |
| 299 | setDocumentLoader(loader.get()); |
| 300 | |
| 301 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocument); |
| 302 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocumentPostCommit); |
| 303 | m_stateMachine.advanceTo(FrameLoaderStateMachine::CommittedFirstRealLoad); |
| 304 | m_client.transitionToCommittedForNewPage(); |
| 305 | |
| 306 | m_didCallImplicitClose = true; |
| 307 | m_isComplete = true; |
| 308 | m_state = FrameStateComplete; |
| 309 | m_needsClear = true; |
| 310 | |
| 311 | m_networkingContext = m_client.createNetworkingContext(); |
aestes@apple.com | 52fb679 | 2014-03-01 05:14:42 +0000 | [diff] [blame] | 312 | m_progressTracker = std::make_unique<FrameProgressTracker>(m_frame); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 313 | } |
| 314 | #endif |
| 315 | |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 316 | void FrameLoader::setDefersLoading(bool defers) |
| 317 | { |
darin | 8207db4 | 2007-02-20 18:18:39 +0000 | [diff] [blame] | 318 | if (m_documentLoader) |
| 319 | m_documentLoader->setDefersLoading(defers); |
| 320 | if (m_provisionalDocumentLoader) |
| 321 | m_provisionalDocumentLoader->setDefersLoading(defers); |
| 322 | if (m_policyDocumentLoader) |
| 323 | m_policyDocumentLoader->setDefersLoading(defers); |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 324 | history().setDefersLoading(defers); |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 325 | |
| 326 | if (!defers) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 327 | m_frame.navigationScheduler().startTimer(); |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 328 | startCheckCompleteTimer(); |
| 329 | } |
darin | fa7a4e3 | 2006-10-30 00:37:02 +0000 | [diff] [blame] | 330 | } |
| 331 | |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 332 | void FrameLoader::changeLocation(const FrameLoadRequest& request) |
mjs | d40bfee | 2007-07-09 06:29:48 +0000 | [diff] [blame] | 333 | { |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 334 | urlSelected(request, nullptr); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 335 | } |
| 336 | |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 337 | void FrameLoader::urlSelected(const URL& url, const String& passedTarget, Event* triggeringEvent, LockHistory lockHistory, LockBackForwardList lockBackForwardList, ShouldSendReferrer shouldSendReferrer, ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 338 | { |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 339 | NewFrameOpenerPolicy newFrameOpenerPolicy = shouldSendReferrer == NeverSendReferrer ? NewFrameOpenerPolicy::Suppress : NewFrameOpenerPolicy::Allow; |
| 340 | |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 341 | urlSelected(FrameLoadRequest(m_frame.document()->securityOrigin(), ResourceRequest(url), passedTarget, lockHistory, lockBackForwardList, shouldSendReferrer, AllowNavigationToInvalidURL::Yes, newFrameOpenerPolicy, DoNotReplaceDocumentIfJavaScriptURL, shouldOpenExternalURLsPolicy), triggeringEvent); |
cjerdonek@webkit.org | 983777f | 2010-05-17 07:34:12 +0000 | [diff] [blame] | 342 | } |
| 343 | |
beidson@apple.com | dab0572 | 2015-05-31 05:53:06 +0000 | [diff] [blame] | 344 | void FrameLoader::urlSelected(const FrameLoadRequest& passedRequest, Event* triggeringEvent) |
cjerdonek@webkit.org | 983777f | 2010-05-17 07:34:12 +0000 | [diff] [blame] | 345 | { |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 346 | Ref<Frame> protect(m_frame); |
darin@apple.com | 1cf3d56 | 2010-12-07 16:23:03 +0000 | [diff] [blame] | 347 | FrameLoadRequest frameRequest(passedRequest); |
| 348 | |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 349 | if (m_frame.script().executeIfJavaScriptURL(frameRequest.resourceRequest().url(), frameRequest.shouldReplaceDocumentIfJavaScriptURL())) |
weinig@apple.com | 6b00e24 | 2008-01-08 01:30:27 +0000 | [diff] [blame] | 350 | return; |
| 351 | |
darin@apple.com | 1cf3d56 | 2010-12-07 16:23:03 +0000 | [diff] [blame] | 352 | if (frameRequest.frameName().isEmpty()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 353 | frameRequest.setFrameName(m_frame.document()->baseTarget()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 354 | |
darin@apple.com | 4cd1b24 | 2009-03-27 23:37:46 +0000 | [diff] [blame] | 355 | addHTTPOriginIfNeeded(frameRequest.resourceRequest(), outgoingOrigin()); |
| 356 | |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 357 | loadFrameRequest(frameRequest, triggeringEvent, nullptr); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 358 | } |
| 359 | |
dglazkov@chromium.org | 25a57e5 | 2010-06-20 21:00:35 +0000 | [diff] [blame] | 360 | void FrameLoader::submitForm(PassRefPtr<FormSubmission> submission) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 361 | { |
dglazkov@chromium.org | 996fc22 | 2010-06-21 16:36:40 +0000 | [diff] [blame] | 362 | ASSERT(submission->method() == FormSubmission::PostMethod || submission->method() == FormSubmission::GetMethod); |
dglazkov@chromium.org | 25a57e5 | 2010-06-20 21:00:35 +0000 | [diff] [blame] | 363 | |
dglazkov@chromium.org | 996fc22 | 2010-06-21 16:36:40 +0000 | [diff] [blame] | 364 | // FIXME: Find a good spot for these. |
| 365 | ASSERT(submission->data()); |
| 366 | ASSERT(submission->state()); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 367 | ASSERT(!submission->state()->sourceDocument()->frame() || submission->state()->sourceDocument()->frame() == &m_frame); |
beidson | 2b28322 | 2006-11-14 03:54:33 +0000 | [diff] [blame] | 368 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 369 | if (!m_frame.page()) |
adele@apple.com | f3d6b89 | 2008-04-29 01:30:20 +0000 | [diff] [blame] | 370 | return; |
| 371 | |
dglazkov@chromium.org | 996fc22 | 2010-06-21 16:36:40 +0000 | [diff] [blame] | 372 | if (submission->action().isEmpty()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 373 | return; |
| 374 | |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 375 | if (isDocumentSandboxed(m_frame, SandboxForms)) { |
mkwst@chromium.org | b10ebb43 | 2012-12-04 18:34:27 +0000 | [diff] [blame] | 376 | // 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] | 377 | 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] | 378 | return; |
mkwst@chromium.org | b10ebb43 | 2012-12-04 18:34:27 +0000 | [diff] [blame] | 379 | } |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 380 | |
dglazkov@chromium.org | 996fc22 | 2010-06-21 16:36:40 +0000 | [diff] [blame] | 381 | if (protocolIsJavaScript(submission->action())) { |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 382 | if (!m_frame.document()->contentSecurityPolicy()->allowFormAction(URL(submission->action()))) |
commit-queue@webkit.org | 78e860e | 2012-08-16 12:42:09 +0000 | [diff] [blame] | 383 | return; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 384 | m_isExecutingJavaScriptFormAction = true; |
ap@apple.com | e6afcb6 | 2014-04-20 19:02:13 +0000 | [diff] [blame] | 385 | Ref<Frame> protect(m_frame); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 386 | m_frame.script().executeIfJavaScriptURL(submission->action(), DoNotReplaceDocumentIfJavaScriptURL); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 387 | m_isExecutingJavaScriptFormAction = false; |
| 388 | return; |
| 389 | } |
| 390 | |
abarth@webkit.org | 5d82cdb | 2012-04-13 07:53:46 +0000 | [diff] [blame] | 391 | Frame* targetFrame = findFrameForNavigation(submission->target(), submission->state()->sourceDocument()); |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 392 | if (!targetFrame) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 393 | if (!DOMWindow::allowPopUp(&m_frame) && !ScriptController::processingUserGesture()) |
abarth@webkit.org | c72185c | 2010-04-09 06:43:19 +0000 | [diff] [blame] | 394 | return; |
| 395 | |
ap@apple.com | f8c414e | 2013-08-13 03:44:57 +0000 | [diff] [blame] | 396 | // FIXME: targetFrame can be 0 for two distinct reasons: |
| 397 | // 1. The frame was not found by name, so we should try opening a new window. |
| 398 | // 2. The frame was found, but navigating it was not allowed, e.g. by HTML5 sandbox or by origin checks. |
| 399 | // Continuing form submission makes no sense in the latter case. |
| 400 | // There is a repeat check after timer fires, so this is not a correctness issue. |
| 401 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 402 | targetFrame = &m_frame; |
dglazkov@chromium.org | 996fc22 | 2010-06-21 16:36:40 +0000 | [diff] [blame] | 403 | } else |
| 404 | submission->clearTarget(); |
| 405 | |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 406 | if (!targetFrame->page()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 407 | return; |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 408 | |
| 409 | // FIXME: We'd like to remove this altogether and fix the multiple form submission issue another way. |
| 410 | |
| 411 | // We do not want to submit more than one form from the same page, nor do we want to submit a single |
| 412 | // form more than once. This flag prevents these from happening; not sure how other browsers prevent this. |
| 413 | // The flag is reset in each time we start handle a new mouse or key down event, and |
| 414 | // also in setView since this part may get reused for a page from the back/forward cache. |
| 415 | // The form multi-submit logic here is only needed when we are submitting a form that affects this frame. |
| 416 | |
| 417 | // FIXME: Frame targeting is only one of the ways the submission could end up doing something other |
| 418 | // than replacing this frame's content, so this check is flawed. On the other hand, the check is hardly |
| 419 | // needed any more now that we reset m_submittedFormURL on each mouse or key down event. |
| 420 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 421 | if (m_frame.tree().isDescendantOf(targetFrame)) { |
commit-queue@webkit.org | 4396405 | 2012-08-13 19:30:15 +0000 | [diff] [blame] | 422 | if (m_submittedFormURL == submission->requestURL()) |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 423 | return; |
commit-queue@webkit.org | 4396405 | 2012-08-13 19:30:15 +0000 | [diff] [blame] | 424 | m_submittedFormURL = submission->requestURL(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 425 | } |
| 426 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 427 | submission->data()->generateFiles(m_frame.document()); |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 428 | submission->setReferrer(outgoingReferrer()); |
dglazkov@chromium.org | 996fc22 | 2010-06-21 16:36:40 +0000 | [diff] [blame] | 429 | submission->setOrigin(outgoingOrigin()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 430 | |
akling@apple.com | 9ce995f | 2013-08-21 20:54:20 +0000 | [diff] [blame] | 431 | targetFrame->navigationScheduler().scheduleFormSubmission(submission); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 432 | } |
| 433 | |
commit-queue@webkit.org | fc5833b | 2011-02-23 06:58:46 +0000 | [diff] [blame] | 434 | void FrameLoader::stopLoading(UnloadEventPolicy unloadEventPolicy) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 435 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 436 | if (m_frame.document() && m_frame.document()->parser()) |
| 437 | m_frame.document()->parser()->stopParsing(); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 438 | |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame^] | 439 | if (unloadEventPolicy != UnloadEventPolicyNone) |
| 440 | handleUnloadEvents(unloadEventPolicy); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 441 | |
darin@apple.com | 4d9d718 | 2009-09-23 00:38:04 +0000 | [diff] [blame] | 442 | m_isComplete = true; // to avoid calling completed() in finishedParsing() |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 443 | m_didCallImplicitClose = true; // don't want that one either |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 444 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 445 | if (m_frame.document() && m_frame.document()->parsing()) { |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 446 | finishedParsing(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 447 | m_frame.document()->setParsing(false); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 448 | } |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 449 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 450 | if (Document* doc = m_frame.document()) { |
tonyg@chromium.org | d299d8a7 | 2010-09-06 18:32:48 +0000 | [diff] [blame] | 451 | // FIXME: HTML5 doesn't tell us to set the state to complete when aborting, but we do anyway to match legacy behavior. |
| 452 | // http://www.w3.org/Bugs/Public/show_bug.cgi?id=10537 |
| 453 | doc->setReadyState(Document::Complete); |
| 454 | |
mark.lam@apple.com | 45beb07 | 2012-12-12 23:04:20 +0000 | [diff] [blame] | 455 | // FIXME: Should the DatabaseManager watch for something like ActiveDOMObject::stop() rather than being special-cased here? |
cdumez@apple.com | 0fb69f0 | 2015-02-26 23:22:17 +0000 | [diff] [blame] | 456 | DatabaseManager::singleton().stopDatabases(doc, 0); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 457 | } |
| 458 | |
ap@apple.com | 3f0a0a1 | 2010-06-24 23:58:36 +0000 | [diff] [blame] | 459 | // 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] | 460 | m_frame.navigationScheduler().cancel(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | void FrameLoader::stop() |
| 464 | { |
| 465 | // http://bugs.webkit.org/show_bug.cgi?id=10854 |
| 466 | // 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] | 467 | Ref<Frame> protect(m_frame); |
abarth@webkit.org | fd91290 | 2011-06-10 21:16:20 +0000 | [diff] [blame] | 468 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 469 | if (DocumentParser* parser = m_frame.document()->parser()) { |
abarth@webkit.org | fd91290 | 2011-06-10 21:16:20 +0000 | [diff] [blame] | 470 | parser->stopParsing(); |
| 471 | parser->finish(); |
| 472 | } |
abarth@webkit.org | 4e00997 | 2011-06-13 20:36:03 +0000 | [diff] [blame] | 473 | |
akling@apple.com | f721911 | 2013-09-08 10:54:53 +0000 | [diff] [blame] | 474 | icon().stopLoader(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 475 | } |
| 476 | |
ap@apple.com | e042b63 | 2013-05-17 20:04:43 +0000 | [diff] [blame] | 477 | void FrameLoader::willTransitionToCommitted() |
| 478 | { |
| 479 | // This function is called when a frame is still fully in place (not cached, not detached), but will be replaced. |
| 480 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 481 | if (m_frame.editor().hasComposition()) { |
ap@apple.com | e042b63 | 2013-05-17 20:04:43 +0000 | [diff] [blame] | 482 | // 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] | 483 | m_frame.editor().confirmComposition(); |
ap@apple.com | c985136 | 2014-12-11 17:23:34 +0000 | [diff] [blame] | 484 | if (EditorClient* editorClient = m_frame.editor().client()) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 485 | editorClient->respondToChangedSelection(&m_frame); |
ap@apple.com | c985136 | 2014-12-11 17:23:34 +0000 | [diff] [blame] | 486 | editorClient->discardedComposition(&m_frame); |
| 487 | } |
ap@apple.com | e042b63 | 2013-05-17 20:04:43 +0000 | [diff] [blame] | 488 | } |
| 489 | } |
| 490 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 491 | bool FrameLoader::closeURL() |
| 492 | { |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 493 | history().saveDocumentState(); |
stavila@adobe.com | eb50d7c | 2014-12-17 10:14:32 +0000 | [diff] [blame] | 494 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 495 | Document* currentDocument = m_frame.document(); |
stavila@adobe.com | eb50d7c | 2014-12-17 10:14:32 +0000 | [diff] [blame] | 496 | UnloadEventPolicy unloadEventPolicy; |
| 497 | if (m_frame.page() && m_frame.page()->chrome().client().isSVGImageChromeClient()) { |
| 498 | // If this is the SVGDocument of an SVGImage, no need to dispatch events or recalcStyle. |
| 499 | unloadEventPolicy = UnloadEventPolicyNone; |
| 500 | } else { |
| 501 | // Should only send the pagehide event here if the current document exists and has not been placed in the page cache. |
| 502 | unloadEventPolicy = currentDocument && !currentDocument->inPageCache() ? UnloadEventPolicyUnloadAndPageHide : UnloadEventPolicyUnloadOnly; |
| 503 | } |
| 504 | |
| 505 | stopLoading(unloadEventPolicy); |
beidson@apple.com | 212b784 | 2009-09-03 00:55:18 +0000 | [diff] [blame] | 506 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 507 | m_frame.editor().clearUndoRedoOperations(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 508 | return true; |
| 509 | } |
| 510 | |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 511 | bool FrameLoader::didOpenURL() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 512 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 513 | if (m_frame.navigationScheduler().redirectScheduledDuringLoad()) { |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 514 | // A redirect was scheduled before the document was created. |
| 515 | // This can happen when one frame changes another frame's location. |
| 516 | return false; |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 517 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 518 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 519 | m_frame.navigationScheduler().cancel(); |
| 520 | m_frame.editor().clearLastEditCommand(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 521 | |
| 522 | m_isComplete = false; |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 523 | m_didCallImplicitClose = false; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 524 | |
ap@webkit.org | fbfb0f9 | 2009-05-08 07:58:08 +0000 | [diff] [blame] | 525 | // If we are still in the process of initializing an empty document then |
| 526 | // its frame is not in a consistent state for rendering, so avoid setJSStatusBarText |
| 527 | // since it may cause clients to attempt to render the frame. |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 528 | if (!m_stateMachine.creatingInitialEmptyDocument()) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 529 | DOMWindow* window = m_frame.document()->domWindow(); |
abarth@webkit.org | 13fe1e2 | 2012-08-16 22:29:48 +0000 | [diff] [blame] | 530 | window->setStatus(String()); |
| 531 | window->setDefaultStatus(String()); |
ap@webkit.org | fbfb0f9 | 2009-05-08 07:58:08 +0000 | [diff] [blame] | 532 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 533 | |
| 534 | started(); |
| 535 | |
| 536 | return true; |
| 537 | } |
| 538 | |
ap@webkit.org | a0a1987 | 2008-02-05 09:34:18 +0000 | [diff] [blame] | 539 | void FrameLoader::didExplicitOpen() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 540 | { |
| 541 | m_isComplete = false; |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 542 | m_didCallImplicitClose = false; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 543 | |
andersca@apple.com | 1752dba | 2007-12-14 22:06:50 +0000 | [diff] [blame] | 544 | // Calling document.open counts as committing the first real document load. |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 545 | if (!m_stateMachine.committedFirstRealDocumentLoad()) |
| 546 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocumentPostCommit); |
andersca@apple.com | 1752dba | 2007-12-14 22:06:50 +0000 | [diff] [blame] | 547 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 548 | // Prevent window.open(url) -- eg window.open("about:blank") -- from blowing away results |
| 549 | // from a subsequent window.document.open / window.document.write call. |
dbates@webkit.org | ef42d38 | 2010-01-25 19:20:06 +0000 | [diff] [blame] | 550 | // Canceling redirection here works for all cases because document.open |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 551 | // implicitly precedes document.write. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 552 | m_frame.navigationScheduler().cancel(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 553 | } |
| 554 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 555 | |
| 556 | void FrameLoader::cancelAndClear() |
| 557 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 558 | m_frame.navigationScheduler().cancel(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 559 | |
| 560 | if (!m_isComplete) |
| 561 | closeURL(); |
| 562 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 563 | clear(m_frame.document(), false); |
| 564 | m_frame.script().updatePlatformScriptObjects(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 565 | } |
| 566 | |
abarth@webkit.org | 23ea90a | 2012-08-14 19:47:59 +0000 | [diff] [blame] | 567 | void FrameLoader::clear(Document* newDocument, bool clearWindowProperties, bool clearScriptObjects, bool clearFrameView) |
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.editor().clear(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 570 | |
| 571 | if (!m_needsClear) |
| 572 | return; |
| 573 | m_needsClear = false; |
lars | b632676 | 2007-01-11 12:34:26 +0000 | [diff] [blame] | 574 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 575 | if (!m_frame.document()->inPageCache()) { |
| 576 | m_frame.document()->cancelParsing(); |
| 577 | m_frame.document()->stopActiveDOMObjects(); |
timothy_horton@apple.com | 70d58d8 | 2014-07-26 18:45:04 +0000 | [diff] [blame] | 578 | bool hadLivingRenderTree = m_frame.document()->hasLivingRenderTree(); |
| 579 | m_frame.document()->prepareForDestruction(); |
| 580 | if (hadLivingRenderTree) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 581 | m_frame.document()->removeFocusedNodeOfSubtree(m_frame.document()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | // Do this after detaching the document so that the unload event works. |
thatcher | a1e24df | 2007-09-14 23:53:29 +0000 | [diff] [blame] | 585 | if (clearWindowProperties) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 586 | InspectorInstrumentation::frameWindowDiscarded(&m_frame, m_frame.document()->domWindow()); |
| 587 | m_frame.document()->domWindow()->resetUnlessSuspendedForPageCache(); |
| 588 | m_frame.script().clearWindowShell(newDocument->domWindow(), m_frame.document()->inPageCache()); |
weinig | f930763 | 2007-07-18 05:40:54 +0000 | [diff] [blame] | 589 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 590 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 591 | m_frame.selection().prepareForDestruction(); |
| 592 | m_frame.eventHandler().clear(); |
| 593 | if (clearFrameView && m_frame.view()) |
| 594 | m_frame.view()->clear(); |
eric@webkit.org | 0683d94 | 2008-08-06 10:01:35 +0000 | [diff] [blame] | 595 | |
eric@webkit.org | 0683d94 | 2008-08-06 10:01:35 +0000 | [diff] [blame] | 596 | // Do not drop the document before the ScriptController and view are cleared |
| 597 | // as some destructors might still try to access the document. |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 598 | m_frame.setDocument(nullptr); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 599 | |
akling@apple.com | 7f81b1e | 2013-09-06 17:23:03 +0000 | [diff] [blame] | 600 | subframeLoader().clear(); |
eric@webkit.org | 0683d94 | 2008-08-06 10:01:35 +0000 | [diff] [blame] | 601 | |
antti | 90500a3 | 2007-09-27 23:56:17 +0000 | [diff] [blame] | 602 | if (clearScriptObjects) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 603 | m_frame.script().clearScriptObjects(); |
eric@webkit.org | 0683d94 | 2008-08-06 10:01:35 +0000 | [diff] [blame] | 604 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 605 | m_frame.script().enableEval(); |
abarth@webkit.org | 9d220b6 | 2012-06-09 19:35:02 +0000 | [diff] [blame] | 606 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 607 | m_frame.navigationScheduler().clear(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 608 | |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 609 | m_checkTimer.stop(); |
| 610 | m_shouldCallCheckCompleted = false; |
| 611 | m_shouldCallCheckLoadComplete = false; |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 612 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 613 | if (m_stateMachine.isDisplayingInitialEmptyDocument() && m_stateMachine.committedFirstRealDocumentLoad()) |
| 614 | m_stateMachine.advanceTo(FrameLoaderStateMachine::CommittedFirstRealLoad); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | void FrameLoader::receivedFirstData() |
| 618 | { |
jcivelli@chromium.org | 4b94add | 2011-11-19 08:45:01 +0000 | [diff] [blame] | 619 | dispatchDidCommitLoad(); |
| 620 | dispatchDidClearWindowObjectsInAllWorlds(); |
beidson@apple.com | 2a75a96 | 2012-04-24 18:12:55 +0000 | [diff] [blame] | 621 | dispatchGlobalObjectAvailableInAllWorlds(); |
jcivelli@chromium.org | 4b94add | 2011-11-19 08:45:01 +0000 | [diff] [blame] | 622 | |
pkasting@chromium.org | c733b94 | 2009-05-05 19:19:23 +0000 | [diff] [blame] | 623 | if (m_documentLoader) { |
evan@chromium.org | c3532e9 | 2011-03-31 15:17:13 +0000 | [diff] [blame] | 624 | StringWithDirection ptitle = m_documentLoader->title(); |
pkasting@chromium.org | c733b94 | 2009-05-05 19:19:23 +0000 | [diff] [blame] | 625 | // If we have a title let the WebView know about it. |
| 626 | if (!ptitle.isNull()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 627 | m_client.dispatchDidReceiveTitle(ptitle); |
pkasting@chromium.org | c733b94 | 2009-05-05 19:19:23 +0000 | [diff] [blame] | 628 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 629 | |
darin | 8207db4 | 2007-02-20 18:18:39 +0000 | [diff] [blame] | 630 | if (!m_documentLoader) |
| 631 | return; |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 632 | |
| 633 | double delay; |
darin@apple.com | 47a20cb | 2014-04-27 16:06:27 +0000 | [diff] [blame] | 634 | String urlString; |
andersca@apple.com | 30391b4 | 2014-06-16 19:26:49 +0000 | [diff] [blame] | 635 | if (!parseHTTPRefresh(m_documentLoader->response().httpHeaderField(HTTPHeaderName::Refresh), false, delay, urlString)) |
ap | e9991d5 | 2006-12-08 18:19:51 +0000 | [diff] [blame] | 636 | return; |
darin@apple.com | 47a20cb | 2014-04-27 16:06:27 +0000 | [diff] [blame] | 637 | URL completedURL; |
| 638 | if (urlString.isEmpty()) |
| 639 | completedURL = m_frame.document()->url(); |
ap | e9991d5 | 2006-12-08 18:19:51 +0000 | [diff] [blame] | 640 | else |
darin@apple.com | 47a20cb | 2014-04-27 16:06:27 +0000 | [diff] [blame] | 641 | completedURL = m_frame.document()->completeURL(urlString); |
darin | ebefc17 | 2006-11-08 09:48:44 +0000 | [diff] [blame] | 642 | |
darin@apple.com | 47a20cb | 2014-04-27 16:06:27 +0000 | [diff] [blame] | 643 | if (!protocolIsJavaScript(completedURL)) |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 644 | m_frame.navigationScheduler().scheduleRedirect(m_frame.document(), delay, completedURL); |
ddkilzer@apple.com | 70f1539 | 2014-04-01 19:21:34 +0000 | [diff] [blame] | 645 | else { |
| 646 | String message = "Refused to refresh " + m_frame.document()->url().stringCenterEllipsizedToLength() + " to a javascript: URL"; |
| 647 | m_frame.document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, message); |
| 648 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 649 | } |
| 650 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 651 | void FrameLoader::setOutgoingReferrer(const URL& url) |
japhet@chromium.org | b254c9b | 2011-01-26 19:14:26 +0000 | [diff] [blame] | 652 | { |
levin@chromium.org | 1a2fef4 | 2011-03-01 02:10:28 +0000 | [diff] [blame] | 653 | m_outgoingReferrer = url.strippedForUseAsReferrer(); |
abarth@webkit.org | 412c54e | 2010-04-20 22:12:16 +0000 | [diff] [blame] | 654 | } |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 655 | |
abarth@webkit.org | 412c54e | 2010-04-20 22:12:16 +0000 | [diff] [blame] | 656 | void FrameLoader::didBeginDocument(bool dispatch) |
| 657 | { |
| 658 | m_needsClear = true; |
| 659 | m_isComplete = false; |
| 660 | m_didCallImplicitClose = false; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 661 | m_frame.document()->setReadyState(Document::Loading); |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 662 | |
| 663 | if (m_pendingStateObject) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 664 | m_frame.document()->statePopped(m_pendingStateObject.get()); |
cdumez@apple.com | d839ea1 | 2015-07-04 19:42:18 +0000 | [diff] [blame] | 665 | m_pendingStateObject = nullptr; |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 666 | } |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 667 | |
andersca@apple.com | 6c6fb4b | 2009-08-12 22:03:02 +0000 | [diff] [blame] | 668 | if (dispatch) |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 669 | dispatchDidClearWindowObjectsInAllWorlds(); |
abarth@webkit.org | 412c54e | 2010-04-20 22:12:16 +0000 | [diff] [blame] | 670 | |
abarth@webkit.org | 622d9df | 2009-05-22 16:44:47 +0000 | [diff] [blame] | 671 | updateFirstPartyForCookies(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 672 | m_frame.document()->initContentSecurityPolicy(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 673 | |
akling@apple.com | 1c29edbc | 2013-08-23 23:19:21 +0000 | [diff] [blame] | 674 | const Settings& settings = m_frame.settings(); |
cdumez@apple.com | 0bb03ec | 2015-01-28 05:53:53 +0000 | [diff] [blame] | 675 | m_frame.document()->cachedResourceLoader().setImagesEnabled(settings.areImagesEnabled()); |
| 676 | m_frame.document()->cachedResourceLoader().setAutoLoadImages(settings.loadsImagesAutomatically()); |
aroben@apple.com | 3adf245 | 2008-02-07 23:19:31 +0000 | [diff] [blame] | 677 | |
collinj@webkit.org | 9c672f6 | 2008-09-19 04:15:14 +0000 | [diff] [blame] | 678 | if (m_documentLoader) { |
andersca@apple.com | 30391b4 | 2014-06-16 19:26:49 +0000 | [diff] [blame] | 679 | String dnsPrefetchControl = m_documentLoader->response().httpHeaderField(HTTPHeaderName::XDNSPrefetchControl); |
collinj@webkit.org | 9c672f6 | 2008-09-19 04:15:14 +0000 | [diff] [blame] | 680 | if (!dnsPrefetchControl.isEmpty()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 681 | m_frame.document()->parseDNSPrefetchControlHeader(dnsPrefetchControl); |
jochen@chromium.org | adec40f | 2011-02-09 17:03:38 +0000 | [diff] [blame] | 682 | |
andersca@apple.com | 30391b4 | 2014-06-16 19:26:49 +0000 | [diff] [blame] | 683 | String policyValue = m_documentLoader->response().httpHeaderField(HTTPHeaderName::ContentSecurityPolicy); |
mkwst@chromium.org | a9bf73d | 2012-10-31 23:41:27 +0000 | [diff] [blame] | 684 | if (!policyValue.isEmpty()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 685 | m_frame.document()->contentSecurityPolicy()->didReceiveHeader(policyValue, ContentSecurityPolicy::Enforce); |
abarth@webkit.org | bd0c775 | 2011-05-07 02:13:06 +0000 | [diff] [blame] | 686 | |
andersca@apple.com | 30391b4 | 2014-06-16 19:26:49 +0000 | [diff] [blame] | 687 | policyValue = m_documentLoader->response().httpHeaderField(HTTPHeaderName::ContentSecurityPolicyReportOnly); |
mkwst@chromium.org | a9bf73d | 2012-10-31 23:41:27 +0000 | [diff] [blame] | 688 | if (!policyValue.isEmpty()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 689 | m_frame.document()->contentSecurityPolicy()->didReceiveHeader(policyValue, ContentSecurityPolicy::Report); |
mkwst@chromium.org | a9bf73d | 2012-10-31 23:41:27 +0000 | [diff] [blame] | 690 | |
andersca@apple.com | 30391b4 | 2014-06-16 19:26:49 +0000 | [diff] [blame] | 691 | policyValue = m_documentLoader->response().httpHeaderField(HTTPHeaderName::XWebKitCSP); |
mkwst@chromium.org | a9bf73d | 2012-10-31 23:41:27 +0000 | [diff] [blame] | 692 | if (!policyValue.isEmpty()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 693 | m_frame.document()->contentSecurityPolicy()->didReceiveHeader(policyValue, ContentSecurityPolicy::PrefixedEnforce); |
mkwst@chromium.org | a9bf73d | 2012-10-31 23:41:27 +0000 | [diff] [blame] | 694 | |
andersca@apple.com | 30391b4 | 2014-06-16 19:26:49 +0000 | [diff] [blame] | 695 | policyValue = m_documentLoader->response().httpHeaderField(HTTPHeaderName::XWebKitCSPReportOnly); |
mkwst@chromium.org | a9bf73d | 2012-10-31 23:41:27 +0000 | [diff] [blame] | 696 | if (!policyValue.isEmpty()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 697 | m_frame.document()->contentSecurityPolicy()->didReceiveHeader(policyValue, ContentSecurityPolicy::PrefixedReport); |
commit-queue@webkit.org | 26a3a09 | 2012-10-18 19:53:58 +0000 | [diff] [blame] | 698 | |
andersca@apple.com | 30391b4 | 2014-06-16 19:26:49 +0000 | [diff] [blame] | 699 | String headerContentLanguage = m_documentLoader->response().httpHeaderField(HTTPHeaderName::ContentLanguage); |
commit-queue@webkit.org | 26a3a09 | 2012-10-18 19:53:58 +0000 | [diff] [blame] | 700 | if (!headerContentLanguage.isEmpty()) { |
| 701 | size_t commaIndex = headerContentLanguage.find(','); |
| 702 | headerContentLanguage.truncate(commaIndex); // notFound == -1 == don't truncate |
| 703 | headerContentLanguage = headerContentLanguage.stripWhiteSpace(isHTMLSpace); |
| 704 | if (!headerContentLanguage.isEmpty()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 705 | m_frame.document()->setContentLanguage(headerContentLanguage); |
commit-queue@webkit.org | 26a3a09 | 2012-10-18 19:53:58 +0000 | [diff] [blame] | 706 | } |
collinj@webkit.org | 9c672f6 | 2008-09-19 04:15:14 +0000 | [diff] [blame] | 707 | } |
| 708 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 709 | history().restoreDocumentState(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 710 | } |
| 711 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 712 | void FrameLoader::finishedParsing() |
| 713 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 714 | m_frame.injectUserScripts(InjectAtDocumentEnd); |
aestes@apple.com | e35644e | 2011-04-07 20:23:48 +0000 | [diff] [blame] | 715 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 716 | if (m_stateMachine.creatingInitialEmptyDocument()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 717 | return; |
| 718 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 719 | // This can be called from the Frame's destructor, in which case we shouldn't protect ourselves |
| 720 | // 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] | 721 | // 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] | 722 | RefPtr<Frame> protector = m_frame.view() ? &m_frame : 0; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 723 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 724 | m_client.dispatchDidFinishDocumentLoad(); |
darin@chromium.org | 1750e24 | 2008-12-08 18:13:25 +0000 | [diff] [blame] | 725 | |
cdumez@apple.com | 6d7c65e | 2015-09-02 17:07:57 +0000 | [diff] [blame] | 726 | scrollToFragmentWithParentBoundary(m_frame.document()->url()); |
| 727 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 728 | checkCompleted(); |
| 729 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 730 | if (!m_frame.view()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 731 | return; // We are being destroyed by something checkCompleted called. |
| 732 | |
| 733 | // Check if the scrollbars are really needed for the content. |
| 734 | // If not, remove them, relayout, and repaint. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 735 | m_frame.view()->restoreScrollbar(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | void FrameLoader::loadDone() |
| 739 | { |
ap@webkit.org | f9b6eff | 2009-02-10 17:33:33 +0000 | [diff] [blame] | 740 | checkCompleted(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 741 | } |
| 742 | |
darin@apple.com | 4d9d718 | 2009-09-23 00:38:04 +0000 | [diff] [blame] | 743 | bool FrameLoader::allChildrenAreComplete() const |
| 744 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 745 | 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] | 746 | if (!child->loader().m_isComplete) |
darin@apple.com | 4d9d718 | 2009-09-23 00:38:04 +0000 | [diff] [blame] | 747 | return false; |
| 748 | } |
| 749 | return true; |
| 750 | } |
| 751 | |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 752 | bool FrameLoader::allAncestorsAreComplete() const |
| 753 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 754 | for (Frame* ancestor = &m_frame; ancestor; ancestor = ancestor->tree().parent()) { |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 755 | if (!ancestor->loader().m_isComplete) |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 756 | return false; |
| 757 | } |
| 758 | return true; |
| 759 | } |
| 760 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 761 | void FrameLoader::checkCompleted() |
| 762 | { |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 763 | m_shouldCallCheckCompleted = false; |
| 764 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 765 | // Have we completed before? |
| 766 | if (m_isComplete) |
| 767 | return; |
| 768 | |
| 769 | // Are we still parsing? |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 770 | if (m_frame.document()->parsing()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 771 | return; |
| 772 | |
| 773 | // Still waiting for images/scripts? |
cdumez@apple.com | 0bb03ec | 2015-01-28 05:53:53 +0000 | [diff] [blame] | 774 | if (m_frame.document()->cachedResourceLoader().requestCount()) |
ap@webkit.org | f9b6eff | 2009-02-10 17:33:33 +0000 | [diff] [blame] | 775 | return; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 776 | |
eric.carlson@apple.com | 9c7fc72 | 2010-08-26 16:45:43 +0000 | [diff] [blame] | 777 | // Still waiting for elements that don't go through a FrameLoader? |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 778 | if (m_frame.document()->isDelayingLoadEvent()) |
eric.carlson@apple.com | 9c7fc72 | 2010-08-26 16:45:43 +0000 | [diff] [blame] | 779 | return; |
| 780 | |
andreas.kling@nokia.com | 01f9244 | 2011-02-28 13:46:06 +0000 | [diff] [blame] | 781 | // Any frame that hasn't completed yet? |
| 782 | if (!allChildrenAreComplete()) |
| 783 | return; |
| 784 | |
darin@apple.com | c284300 | 2014-04-25 06:01:34 +0000 | [diff] [blame] | 785 | // Important not to protect earlier in this function, because earlier parts |
darin@apple.com | fe9effd | 2014-04-25 06:02:42 +0000 | [diff] [blame] | 786 | // 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] | 787 | // to ref an object while it's being destroyed. |
| 788 | Ref<Frame> protect(m_frame); |
| 789 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 790 | // OK, completed. |
| 791 | m_isComplete = true; |
cdumez@apple.com | d839ea1 | 2015-07-04 19:42:18 +0000 | [diff] [blame] | 792 | m_requestedHistoryItem = nullptr; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 793 | m_frame.document()->setReadyState(Document::Complete); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 794 | |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 795 | #if PLATFORM(IOS) |
| 796 | if (m_frame.document()->url().isEmpty()) { |
| 797 | // We need to update the document URL of a PDF document to be non-empty so that both back/forward history navigation |
| 798 | // between PDF pages and fragment navigation works. See <rdar://problem/9544769> for more details. |
| 799 | // FIXME: Is there a better place for this code, say DocumentLoader? Also, we should explicitly only update the URL |
| 800 | // of the document when it's a PDFDocument object instead of assuming that a Document object with an empty URL is a PDFDocument. |
| 801 | // FIXME: This code is incorrect for a synthesized document (which also has an empty URL). The URL for a synthesized |
| 802 | // document should be the URL specified to FrameLoader::initForSynthesizedDocument(). |
| 803 | m_frame.document()->setURL(activeDocumentLoader()->documentURL()); |
| 804 | } |
| 805 | #endif |
| 806 | |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 807 | checkCallImplicitClose(); // if we didn't do it before |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 808 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 809 | m_frame.navigationScheduler().startTimer(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 810 | |
| 811 | completed(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 812 | if (m_frame.page()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 813 | checkLoadComplete(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 814 | } |
| 815 | |
andersca@apple.com | 574a745 | 2014-11-21 20:10:13 +0000 | [diff] [blame] | 816 | void FrameLoader::checkTimerFired() |
weinig | c34c71c | 2007-03-09 16:05:37 +0000 | [diff] [blame] | 817 | { |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 818 | Ref<Frame> protect(m_frame); |
commit-queue@webkit.org | 667ee8b | 2012-02-08 02:21:04 +0000 | [diff] [blame] | 819 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 820 | if (Page* page = m_frame.page()) { |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 821 | if (page->defersLoading()) |
| 822 | return; |
| 823 | } |
| 824 | if (m_shouldCallCheckCompleted) |
| 825 | checkCompleted(); |
| 826 | if (m_shouldCallCheckLoadComplete) |
| 827 | checkLoadComplete(); |
| 828 | } |
| 829 | |
| 830 | void FrameLoader::startCheckCompleteTimer() |
| 831 | { |
| 832 | if (!(m_shouldCallCheckCompleted || m_shouldCallCheckLoadComplete)) |
| 833 | return; |
| 834 | if (m_checkTimer.isActive()) |
| 835 | return; |
| 836 | m_checkTimer.startOneShot(0); |
weinig | c34c71c | 2007-03-09 16:05:37 +0000 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | void FrameLoader::scheduleCheckCompleted() |
| 840 | { |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 841 | m_shouldCallCheckCompleted = true; |
| 842 | startCheckCompleteTimer(); |
beidson | 398923b | 2007-07-31 20:29:02 +0000 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | void FrameLoader::scheduleCheckLoadComplete() |
| 846 | { |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 847 | m_shouldCallCheckLoadComplete = true; |
| 848 | startCheckCompleteTimer(); |
beidson | 398923b | 2007-07-31 20:29:02 +0000 | [diff] [blame] | 849 | } |
| 850 | |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 851 | void FrameLoader::checkCallImplicitClose() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 852 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 853 | if (m_didCallImplicitClose || m_frame.document()->parsing() || m_frame.document()->isDelayingLoadEvent()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 854 | return; |
| 855 | |
darin@apple.com | 4d9d718 | 2009-09-23 00:38:04 +0000 | [diff] [blame] | 856 | if (!allChildrenAreComplete()) |
| 857 | return; // still got a frame running -> too early |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 858 | |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 859 | m_didCallImplicitClose = true; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 860 | m_wasUnloadEventEmitted = false; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 861 | m_frame.document()->implicitClose(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 862 | } |
| 863 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 864 | void FrameLoader::loadURLIntoChildFrame(const URL& url, const String& referer, Frame* childFrame) |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 865 | { |
| 866 | ASSERT(childFrame); |
darin@apple.com | a7e141f | 2009-03-06 17:22:07 +0000 | [diff] [blame] | 867 | |
jcivelli@chromium.org | c2019dd | 2011-05-24 19:32:03 +0000 | [diff] [blame] | 868 | #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 869 | RefPtr<Archive> subframeArchive = activeDocumentLoader()->popArchiveForSubframe(childFrame->tree().uniqueName(), url); |
mihaip@chromium.org | e5dbd37 | 2010-12-08 02:32:41 +0000 | [diff] [blame] | 870 | if (subframeArchive) { |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 871 | childFrame->loader().loadArchive(subframeArchive.release()); |
mihaip@chromium.org | e5dbd37 | 2010-12-08 02:32:41 +0000 | [diff] [blame] | 872 | return; |
| 873 | } |
jeremy@chromium.org | c4b86e3 | 2011-02-13 20:28:39 +0000 | [diff] [blame] | 874 | #endif // ENABLE(WEB_ARCHIVE) |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 875 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 876 | HistoryItem* parentItem = history().currentItem(); |
darin@apple.com | a7e141f | 2009-03-06 17:22:07 +0000 | [diff] [blame] | 877 | // 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] | 878 | // of this child frame with whatever was there at that point. |
japhet@chromium.org | 88c4b2b | 2011-07-22 19:01:56 +0000 | [diff] [blame] | 879 | if (parentItem && parentItem->children().size() && isBackForwardLoadType(loadType()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 880 | && !m_frame.document()->loadEventFinished()) { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 881 | HistoryItem* childItem = parentItem->childItemWithTarget(childFrame->tree().uniqueName()); |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 882 | if (childItem) { |
ap@apple.com | 4d286a9 | 2013-08-19 23:41:18 +0000 | [diff] [blame] | 883 | childFrame->loader().m_requestedHistoryItem = childItem; |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 884 | childFrame->loader().loadDifferentDocumentItem(*childItem, loadType(), MayAttemptCacheOnlyLoadForFormSubmissionItem); |
mihaip@chromium.org | e5dbd37 | 2010-12-08 02:32:41 +0000 | [diff] [blame] | 885 | return; |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 886 | } |
| 887 | } |
| 888 | |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 889 | FrameLoadRequest frameLoadRequest(m_frame.document()->securityOrigin(), ResourceRequest(url), "_self", LockHistory::No, LockBackForwardList::Yes, ShouldSendReferrer::MaybeSendReferrer, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Suppress, ReplaceDocumentIfJavaScriptURL, ShouldOpenExternalURLsPolicy::ShouldNotAllow); |
beidson@apple.com | 47ef96f | 2015-05-29 16:38:13 +0000 | [diff] [blame] | 890 | childFrame->loader().loadURL(frameLoadRequest, referer, FrameLoadType::RedirectWithLockedBackForwardList, 0, 0); |
| 891 | } |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 892 | |
jcivelli@chromium.org | c2019dd | 2011-05-24 19:32:03 +0000 | [diff] [blame] | 893 | #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
| 894 | void FrameLoader::loadArchive(PassRefPtr<Archive> archive) |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 895 | { |
japhet@chromium.org | ac5cd4b | 2012-04-12 19:27:28 +0000 | [diff] [blame] | 896 | ArchiveResource* mainResource = archive->mainResource(); |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 897 | ASSERT(mainResource); |
| 898 | if (!mainResource) |
| 899 | return; |
beidson@apple.com | ceb7cba | 2015-05-19 22:22:51 +0000 | [diff] [blame] | 900 | |
| 901 | ResourceResponse response(URL(), mainResource->mimeType(), mainResource->data()->size(), mainResource->textEncoding()); |
| 902 | SubstituteData substituteData(mainResource->data(), URL(), response, SubstituteData::SessionHistoryVisibility::Hidden); |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 903 | |
| 904 | ResourceRequest request(mainResource->url()); |
mitz@apple.com | 630ef44 | 2014-02-19 08:12:24 +0000 | [diff] [blame] | 905 | #if PLATFORM(MAC) |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 906 | request.applyWebArchiveHackForMail(); |
| 907 | #endif |
| 908 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 909 | RefPtr<DocumentLoader> documentLoader = m_client.createDocumentLoader(request, substituteData); |
japhet@chromium.org | ac5cd4b | 2012-04-12 19:27:28 +0000 | [diff] [blame] | 910 | documentLoader->setArchive(archive.get()); |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 911 | load(documentLoader.get()); |
| 912 | } |
jcivelli@chromium.org | c2019dd | 2011-05-24 19:32:03 +0000 | [diff] [blame] | 913 | #endif // ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) |
beidson@apple.com | f36a4a1 | 2008-03-25 17:11:16 +0000 | [diff] [blame] | 914 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 915 | String FrameLoader::outgoingReferrer() const |
| 916 | { |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 917 | // See http://www.whatwg.org/specs/web-apps/current-work/#fetching-resources |
| 918 | // for why we walk the parent chain for srcdoc documents. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 919 | Frame* frame = &m_frame; |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 920 | while (frame->document()->isSrcdocDocument()) { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 921 | frame = frame->tree().parent(); |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 922 | // Srcdoc documents cannot be top-level documents, by definition, |
| 923 | // because they need to be contained in iframes with the srcdoc. |
| 924 | ASSERT(frame); |
| 925 | } |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 926 | return frame->loader().m_outgoingReferrer; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 927 | } |
| 928 | |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 929 | String FrameLoader::outgoingOrigin() const |
| 930 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 931 | return m_frame.document()->securityOrigin()->toString(); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 932 | } |
| 933 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 934 | bool FrameLoader::checkIfFormActionAllowedByCSP(const URL& url) const |
commit-queue@webkit.org | 78e860e | 2012-08-16 12:42:09 +0000 | [diff] [blame] | 935 | { |
| 936 | if (m_submittedFormURL.isEmpty()) |
| 937 | return true; |
| 938 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 939 | return m_frame.document()->contentSecurityPolicy()->allowFormAction(url); |
commit-queue@webkit.org | 78e860e | 2012-08-16 12:42:09 +0000 | [diff] [blame] | 940 | } |
| 941 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 942 | Frame* FrameLoader::opener() |
| 943 | { |
| 944 | return m_opener; |
| 945 | } |
| 946 | |
| 947 | void FrameLoader::setOpener(Frame* opener) |
| 948 | { |
creis@chromium.org | 16d76c7 | 2012-12-04 17:39:26 +0000 | [diff] [blame] | 949 | if (m_opener && !opener) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 950 | m_client.didDisownOpener(); |
creis@chromium.org | 16d76c7 | 2012-12-04 17:39:26 +0000 | [diff] [blame] | 951 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 952 | if (m_opener) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 953 | m_opener->loader().m_openedFrames.remove(&m_frame); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 954 | if (opener) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 955 | opener->loader().m_openedFrames.add(&m_frame); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 956 | m_opener = opener; |
weinig | 343b6ff | 2007-08-07 03:08:53 +0000 | [diff] [blame] | 957 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 958 | if (m_frame.document()) |
| 959 | m_frame.document()->initSecurityContext(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 960 | } |
| 961 | |
eric@webkit.org | 4ffb1fe | 2010-09-03 04:28:12 +0000 | [diff] [blame] | 962 | // FIXME: This does not belong in FrameLoader! |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 963 | void FrameLoader::handleFallbackContent() |
| 964 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 965 | HTMLFrameOwnerElement* owner = m_frame.ownerElement(); |
cdumez@apple.com | a9c60c9 | 2014-10-02 19:39:41 +0000 | [diff] [blame] | 966 | if (!is<HTMLObjectElement>(owner)) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 967 | return; |
cdumez@apple.com | 72754ba | 2014-09-23 22:03:15 +0000 | [diff] [blame] | 968 | downcast<HTMLObjectElement>(*owner).renderFallbackContent(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | void FrameLoader::provisionalLoadStarted() |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 972 | { |
| 973 | if (m_stateMachine.firstLayoutDone()) |
| 974 | m_stateMachine.advanceTo(FrameLoaderStateMachine::CommittedFirstRealLoad); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 975 | m_frame.navigationScheduler().cancel(true); |
| 976 | m_client.provisionalLoadStarted(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 977 | } |
| 978 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 979 | void FrameLoader::resetMultipleFormSubmissionProtection() |
| 980 | { |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 981 | m_submittedFormURL = URL(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 982 | } |
| 983 | |
abarth@webkit.org | 622d9df | 2009-05-22 16:44:47 +0000 | [diff] [blame] | 984 | void FrameLoader::updateFirstPartyForCookies() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 985 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 986 | if (m_frame.tree().parent()) |
| 987 | setFirstPartyForCookies(m_frame.tree().parent()->document()->firstPartyForCookies()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 988 | else |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 989 | setFirstPartyForCookies(m_frame.document()->url()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 990 | } |
| 991 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 992 | void FrameLoader::setFirstPartyForCookies(const URL& url) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 993 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 994 | 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] | 995 | frame->document()->setFirstPartyForCookies(url); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 996 | } |
| 997 | |
darin@apple.com | d69216d | 2008-03-11 00:45:47 +0000 | [diff] [blame] | 998 | // 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] | 999 | // that a higher level already checked that the URLs match and the scrolling is the right thing to do. |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1000 | void FrameLoader::loadInSameDocument(const URL& url, PassRefPtr<SerializedScriptValue> stateObject, bool isNewNavigation) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1001 | { |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1002 | // If we have a state object, we cannot also be a new navigation. |
| 1003 | ASSERT(!stateObject || (stateObject && !isNewNavigation)); |
| 1004 | |
| 1005 | // 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] | 1006 | URL oldURL = m_frame.document()->url(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1007 | m_frame.document()->setURL(url); |
jochen@chromium.org | 7495f96 | 2012-05-04 16:43:03 +0000 | [diff] [blame] | 1008 | setOutgoingReferrer(url); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1009 | documentLoader()->replaceRequestURLForSameDocumentNavigation(url); |
| 1010 | if (isNewNavigation && !shouldTreatURLAsSameAsCurrent(url) && !stateObject) { |
| 1011 | // NB: must happen after replaceRequestURLForSameDocumentNavigation(), since we add |
| 1012 | // based on the current request. Must also happen before we openURL and displace the |
| 1013 | // scroll position, since adding the BF item will save away scroll state. |
| 1014 | |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 1015 | // 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] | 1016 | // it was done, currItem is now set the that slow doc, and prevItem is whatever was |
| 1017 | // before it. Adding the b/f item will bump the slow doc down to prevItem, even |
| 1018 | // though its load is not yet done. I think this all works out OK, for one because |
| 1019 | // we have already saved away the scroll and doc state for the long slow load, |
| 1020 | // but it's not an obvious case. |
| 1021 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 1022 | history().updateBackForwardListForFragmentScroll(); |
beidson@apple.com | 8127cdc | 2009-08-07 15:35:19 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
japhet@chromium.org | b254c9b | 2011-01-26 19:14:26 +0000 | [diff] [blame] | 1025 | bool hashChange = equalIgnoringFragmentIdentifier(url, oldURL) && url.fragmentIdentifier() != oldURL.fragmentIdentifier(); |
beidson@apple.com | 43a414c | 2010-03-19 18:25:21 +0000 | [diff] [blame] | 1026 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 1027 | history().updateForSameDocumentNavigation(); |
britto@apple.com | 195cc0b | 2008-07-23 16:48:47 +0000 | [diff] [blame] | 1028 | |
| 1029 | // 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] | 1030 | if (hashChange) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1031 | m_frame.eventHandler().stopAutoscrollTimer(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1032 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1033 | // It's important to model this as a load that starts and immediately finishes. |
| 1034 | // Otherwise, the parent frame may think we never finished loading. |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1035 | started(); |
japhet@chromium.org | 48bb260 | 2010-03-04 23:01:45 +0000 | [diff] [blame] | 1036 | |
| 1037 | // We need to scroll to the fragment whether or not a hash change occurred, since |
| 1038 | // the user might have scrolled since the previous navigation. |
tsepez@chromium.org | 8d3c2c1 | 2012-04-17 19:03:42 +0000 | [diff] [blame] | 1039 | scrollToFragmentWithParentBoundary(url); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1040 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1041 | m_isComplete = false; |
| 1042 | checkCompleted(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1043 | |
| 1044 | if (isNewNavigation) { |
| 1045 | // 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] | 1046 | // doing any loading. We need to make a pass on this now, since for fragment |
| 1047 | // 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] | 1048 | checkLoadComplete(); |
| 1049 | } |
| 1050 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1051 | m_client.dispatchDidNavigateWithinPage(); |
darin@chromium.org | fe27996 | 2010-03-16 17:26:59 +0000 | [diff] [blame] | 1052 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1053 | m_frame.document()->statePopped(stateObject ? stateObject : SerializedScriptValue::nullValue()); |
| 1054 | m_client.dispatchDidPopStateWithinPage(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1055 | |
| 1056 | if (hashChange) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1057 | m_frame.document()->enqueueHashchangeEvent(oldURL, url); |
| 1058 | m_client.dispatchDidChangeLocationWithinPage(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | // 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] | 1062 | m_client.didFinishLoad(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | bool FrameLoader::isComplete() const |
| 1066 | { |
| 1067 | return m_isComplete; |
| 1068 | } |
| 1069 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1070 | void FrameLoader::completed() |
| 1071 | { |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 1072 | Ref<Frame> protect(m_frame); |
beidson@apple.com | a566251 | 2009-10-27 00:19:33 +0000 | [diff] [blame] | 1073 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1074 | 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] | 1075 | descendant->navigationScheduler().startTimer(); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 1076 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1077 | if (Frame* parent = m_frame.tree().parent()) |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 1078 | parent->loader().checkCompleted(); |
beidson@apple.com | a566251 | 2009-10-27 00:19:33 +0000 | [diff] [blame] | 1079 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1080 | if (m_frame.view()) |
mmaxfield@apple.com | 6ebeece | 2014-12-09 21:03:54 +0000 | [diff] [blame] | 1081 | m_frame.view()->maintainScrollPositionAtAnchor(nullptr); |
weinig@apple.com | f2ead0f | 2013-09-30 04:36:35 +0000 | [diff] [blame] | 1082 | m_activityAssertion = nullptr; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | void FrameLoader::started() |
| 1086 | { |
barraclough@apple.com | 85709e4 | 2014-09-17 18:27:42 +0000 | [diff] [blame] | 1087 | if (m_frame.page()) |
| 1088 | m_activityAssertion = m_frame.page()->pageThrottler().pageLoadActivityToken(); |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1089 | for (Frame* frame = &m_frame; frame; frame = frame->tree().parent()) |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 1090 | frame->loader().m_isComplete = false; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1093 | void FrameLoader::prepareForLoadStart() |
| 1094 | { |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 1095 | m_progressTracker->progressStarted(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1096 | m_client.dispatchDidStartProvisionalLoad(); |
mario@webkit.org | 685258f | 2011-12-06 00:10:55 +0000 | [diff] [blame] | 1097 | |
ossy@webkit.org | 451e9b0 | 2014-01-27 12:40:18 +0000 | [diff] [blame] | 1098 | if (AXObjectCache::accessibilityEnabled()) { |
| 1099 | if (AXObjectCache* cache = m_frame.document()->existingAXObjectCache()) { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1100 | AXObjectCache::AXLoadingEvent loadingEvent = loadType() == FrameLoadType::Reload ? AXObjectCache::AXLoadingReloaded : AXObjectCache::AXLoadingStarted; |
ossy@webkit.org | 451e9b0 | 2014-01-27 12:40:18 +0000 | [diff] [blame] | 1101 | cache->frameLoadingEventNotification(&m_frame, loadingEvent); |
| 1102 | } |
mario@webkit.org | 685258f | 2011-12-06 00:10:55 +0000 | [diff] [blame] | 1103 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | void FrameLoader::setupForReplace() |
| 1107 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1108 | m_client.revertToProvisionalState(m_documentLoader.get()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1109 | setState(FrameStateProvisional); |
| 1110 | m_provisionalDocumentLoader = m_documentLoader; |
cdumez@apple.com | d839ea1 | 2015-07-04 19:42:18 +0000 | [diff] [blame] | 1111 | m_documentLoader = nullptr; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1112 | detachChildren(); |
| 1113 | } |
| 1114 | |
beidson@apple.com | dab0572 | 2015-05-31 05:53:06 +0000 | [diff] [blame] | 1115 | void FrameLoader::loadFrameRequest(const FrameLoadRequest& request, Event* event, PassRefPtr<FormState> formState) |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 1116 | { |
inferno@chromium.org | 670ab75 | 2011-07-13 18:51:44 +0000 | [diff] [blame] | 1117 | // Protect frame from getting blown away inside dispatchBeforeLoadEvent in loadWithDocumentLoader. |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 1118 | Ref<Frame> protect(m_frame); |
inferno@chromium.org | 670ab75 | 2011-07-13 18:51:44 +0000 | [diff] [blame] | 1119 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1120 | URL url = request.resourceRequest().url(); |
antti@apple.com | c633dca | 2008-11-14 21:34:55 +0000 | [diff] [blame] | 1121 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1122 | ASSERT(m_frame.document()); |
commit-queue@webkit.org | d065482 | 2011-10-04 18:00:32 +0000 | [diff] [blame] | 1123 | if (!request.requester()->canDisplay(url)) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1124 | reportLocalLoadFailed(&m_frame, url.stringCenterEllipsizedToLength()); |
darin@apple.com | 1cf3d56 | 2010-12-07 16:23:03 +0000 | [diff] [blame] | 1125 | return; |
| 1126 | } |
| 1127 | |
darin | 5a1e60e | 2007-04-17 19:58:16 +0000 | [diff] [blame] | 1128 | String argsReferrer = request.resourceRequest().httpReferrer(); |
jochen@chromium.org | 4761ef5 | 2011-11-21 10:29:55 +0000 | [diff] [blame] | 1129 | if (argsReferrer.isEmpty()) |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 1130 | argsReferrer = outgoingReferrer(); |
antti@apple.com | c633dca | 2008-11-14 21:34:55 +0000 | [diff] [blame] | 1131 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1132 | String referrer = SecurityPolicy::generateReferrerHeader(m_frame.document()->referrerPolicy(), url, argsReferrer); |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 1133 | if (request.shouldSendReferrer() == NeverSendReferrer) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1134 | referrer = String(); |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 1135 | |
ggaren@apple.com | 78b4dc6 | 2009-01-30 23:09:43 +0000 | [diff] [blame] | 1136 | FrameLoadType loadType; |
| 1137 | if (request.resourceRequest().cachePolicy() == ReloadIgnoringCacheData) |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1138 | loadType = FrameLoadType::Reload; |
beidson@apple.com | ee119d4 | 2015-04-28 19:38:13 +0000 | [diff] [blame] | 1139 | else if (request.lockBackForwardList() == LockBackForwardList::Yes) |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1140 | loadType = FrameLoadType::RedirectWithLockedBackForwardList; |
ggaren@apple.com | 78b4dc6 | 2009-01-30 23:09:43 +0000 | [diff] [blame] | 1141 | else |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1142 | loadType = FrameLoadType::Standard; |
ggaren@apple.com | 78b4dc6 | 2009-01-30 23:09:43 +0000 | [diff] [blame] | 1143 | |
| 1144 | if (request.resourceRequest().httpMethod() == "POST") |
beidson@apple.com | bd66a78 | 2015-05-29 16:31:49 +0000 | [diff] [blame] | 1145 | loadPostRequest(request, referrer, loadType, event, formState.get()); |
ggaren@apple.com | 78b4dc6 | 2009-01-30 23:09:43 +0000 | [diff] [blame] | 1146 | else |
beidson@apple.com | bd66a78 | 2015-05-29 16:31:49 +0000 | [diff] [blame] | 1147 | loadURL(request, referrer, loadType, event, formState.get()); |
ggaren@apple.com | 78b4dc6 | 2009-01-30 23:09:43 +0000 | [diff] [blame] | 1148 | |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 1149 | // FIXME: It's possible this targetFrame will not be the same frame that was targeted by the actual |
| 1150 | // load if frame names have changed. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1151 | Frame* sourceFrame = formState ? formState->sourceDocument()->frame() : &m_frame; |
abarth@webkit.org | a9da3b0 | 2012-03-27 01:09:43 +0000 | [diff] [blame] | 1152 | if (!sourceFrame) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1153 | sourceFrame = &m_frame; |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 1154 | Frame* targetFrame = sourceFrame->loader().findFrameForNavigation(request.frameName()); |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 1155 | if (targetFrame && targetFrame != sourceFrame) { |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 1156 | if (Page* page = targetFrame->page()) |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 1157 | page->chrome().focus(); |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 1158 | } |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1159 | } |
ddkilzer@apple.com | e6e7d42 | 2008-08-06 21:15:39 +0000 | [diff] [blame] | 1160 | |
mitz@apple.com | c99c715 | 2015-07-17 21:16:09 +0000 | [diff] [blame] | 1161 | static ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicyToApply(Frame& sourceFrame, ShouldOpenExternalURLsPolicy propagatedPolicy) |
| 1162 | { |
| 1163 | if (!sourceFrame.isMainFrame()) |
| 1164 | return ShouldOpenExternalURLsPolicy::ShouldNotAllow; |
| 1165 | if (ScriptController::processingUserGesture()) |
| 1166 | return ShouldOpenExternalURLsPolicy::ShouldAllow; |
| 1167 | return propagatedPolicy; |
| 1168 | } |
| 1169 | |
beidson@apple.com | dab0572 | 2015-05-31 05:53:06 +0000 | [diff] [blame] | 1170 | void FrameLoader::loadURL(const FrameLoadRequest& frameLoadRequest, const String& referrer, FrameLoadType newLoadType, Event* event, PassRefPtr<FormState> prpFormState) |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1171 | { |
commit-queue@webkit.org | cd5cda2 | 2011-02-15 15:55:21 +0000 | [diff] [blame] | 1172 | if (m_inStopAllLoaders) |
| 1173 | return; |
| 1174 | |
jpfau@apple.com | 18da22e | 2014-06-19 00:20:25 +0000 | [diff] [blame] | 1175 | Ref<Frame> protect(m_frame); |
| 1176 | |
beidson@apple.com | bd66a78 | 2015-05-29 16:31:49 +0000 | [diff] [blame] | 1177 | String frameName = frameLoadRequest.frameName(); |
| 1178 | AllowNavigationToInvalidURL allowNavigationToInvalidURL = frameLoadRequest.allowNavigationToInvalidURL(); |
| 1179 | NewFrameOpenerPolicy openerPolicy = frameLoadRequest.newFrameOpenerPolicy(); |
| 1180 | LockHistory lockHistory = frameLoadRequest.lockHistory(); |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1181 | RefPtr<FormState> formState = prpFormState; |
andersca | 3513ce0 | 2007-05-17 08:38:44 +0000 | [diff] [blame] | 1182 | bool isFormSubmission = formState; |
beidson@apple.com | bd66a78 | 2015-05-29 16:31:49 +0000 | [diff] [blame] | 1183 | |
| 1184 | const URL& newURL = frameLoadRequest.resourceRequest().url(); |
weinig@apple.com | c500266 | 2007-12-12 07:26:19 +0000 | [diff] [blame] | 1185 | ResourceRequest request(newURL); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 1186 | if (!referrer.isEmpty()) { |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1187 | request.setHTTPReferrer(referrer); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 1188 | RefPtr<SecurityOrigin> referrerOrigin = SecurityOrigin::createFromString(referrer); |
abarth@webkit.org | 48cade3 | 2008-10-23 09:43:34 +0000 | [diff] [blame] | 1189 | addHTTPOriginIfNeeded(request, referrerOrigin->toString()); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 1190 | } |
jpfau@apple.com | 46b3c4e0 | 2013-03-05 00:22:27 +0000 | [diff] [blame] | 1191 | #if ENABLE(CACHE_PARTITIONING) |
akling@apple.com | 5298947 | 2013-09-16 20:09:25 +0000 | [diff] [blame] | 1192 | if (&m_frame.tree().top() != &m_frame) |
cdumez@apple.com | 8730b6e | 2014-10-21 02:10:47 +0000 | [diff] [blame] | 1193 | request.setDomainForCachePartition(m_frame.tree().top().document()->securityOrigin()->domainForCachePartition()); |
jpfau@apple.com | 46b3c4e0 | 2013-03-05 00:22:27 +0000 | [diff] [blame] | 1194 | #endif |
jochen@chromium.org | dac140c | 2011-08-01 21:18:49 +0000 | [diff] [blame] | 1195 | addExtraFieldsToRequest(request, newLoadType, true); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1196 | if (newLoadType == FrameLoadType::Reload || newLoadType == FrameLoadType::ReloadFromOrigin) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1197 | request.setCachePolicy(ReloadIgnoringCacheData); |
| 1198 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1199 | ASSERT(newLoadType != FrameLoadType::Same); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1200 | |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 1201 | // The search for a target frame is done earlier in the case of form submission. |
| 1202 | Frame* targetFrame = isFormSubmission ? 0 : findFrameForNavigation(frameName); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1203 | if (targetFrame && targetFrame != &m_frame) { |
beidson@apple.com | bd66a78 | 2015-05-29 16:31:49 +0000 | [diff] [blame] | 1204 | FrameLoadRequest newFrameLoadRequest(frameLoadRequest); |
| 1205 | newFrameLoadRequest.setFrameName("_self"); |
| 1206 | targetFrame->loader().loadURL(newFrameLoadRequest, referrer, newLoadType, event, formState.release()); |
darin@apple.com | 19c05e9 | 2009-03-30 17:26:16 +0000 | [diff] [blame] | 1207 | return; |
| 1208 | } |
| 1209 | |
cdumez@apple.com | 83847a9 | 2015-06-26 18:26:19 +0000 | [diff] [blame] | 1210 | if (m_pageDismissalEventBeingDispatched != PageDismissalType::None) |
eric@webkit.org | 6cae31a | 2009-09-26 02:35:15 +0000 | [diff] [blame] | 1211 | return; |
| 1212 | |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 1213 | NavigationAction action(request, newLoadType, isFormSubmission, event, frameLoadRequest.shouldOpenExternalURLsPolicy()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1214 | |
darin@apple.com | 19c05e9 | 2009-03-30 17:26:16 +0000 | [diff] [blame] | 1215 | if (!targetFrame && !frameName.isEmpty()) { |
mitz@apple.com | c99c715 | 2015-07-17 21:16:09 +0000 | [diff] [blame] | 1216 | action = action.copyWithShouldOpenExternalURLsPolicy(shouldOpenExternalURLsPolicyToApply(m_frame, frameLoadRequest.shouldOpenExternalURLsPolicy())); |
ap@apple.com | a383f25 | 2015-02-14 18:16:00 +0000 | [diff] [blame] | 1217 | policyChecker().checkNewWindowPolicy(action, request, formState.release(), frameName, [this, allowNavigationToInvalidURL, openerPolicy](const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName, const NavigationAction& action, bool shouldContinue) { |
| 1218 | continueLoadAfterNewWindowPolicy(request, formState, frameName, action, shouldContinue, allowNavigationToInvalidURL, openerPolicy); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1219 | }); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1220 | return; |
| 1221 | } |
| 1222 | |
| 1223 | RefPtr<DocumentLoader> oldDocumentLoader = m_documentLoader; |
| 1224 | |
weinig@apple.com | c500266 | 2007-12-12 07:26:19 +0000 | [diff] [blame] | 1225 | bool sameURL = shouldTreatURLAsSameAsCurrent(newURL); |
yael.aharon@nokia.com | 79f6905 | 2010-12-30 19:31:00 +0000 | [diff] [blame] | 1226 | const String& httpMethod = request.httpMethod(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1227 | |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 1228 | // Make sure to do scroll to fragment processing even if the URL is |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1229 | // exactly the same so pages with '#' links and DHTML side effects |
| 1230 | // work properly. |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 1231 | if (shouldPerformFragmentNavigation(isFormSubmission, httpMethod, newLoadType, newURL)) { |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1232 | oldDocumentLoader->setTriggeringAction(action); |
andersca@apple.com | 97ab6d9 | 2013-10-21 22:55:14 +0000 | [diff] [blame] | 1233 | oldDocumentLoader->setLastCheckedRequest(ResourceRequest()); |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1234 | policyChecker().stopCheck(); |
| 1235 | policyChecker().setLoadType(newLoadType); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1236 | policyChecker().checkNavigationPolicy(request, oldDocumentLoader.get(), formState.release(), [this](const ResourceRequest& request, PassRefPtr<FormState>, bool shouldContinue) { |
| 1237 | continueFragmentScrollAfterNavigationPolicy(request, shouldContinue); |
| 1238 | }); |
| 1239 | return; |
| 1240 | } |
| 1241 | |
| 1242 | // must grab this now, since this load may stop the previous load and clear this flag |
| 1243 | bool isRedirect = m_quickRedirectComing; |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 1244 | loadWithNavigationAction(request, action, lockHistory, newLoadType, formState.release(), allowNavigationToInvalidURL); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1245 | if (isRedirect) { |
| 1246 | m_quickRedirectComing = false; |
| 1247 | if (m_provisionalDocumentLoader) |
| 1248 | m_provisionalDocumentLoader->setIsClientRedirect(true); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1249 | } else if (sameURL && newLoadType != FrameLoadType::Reload && newLoadType != FrameLoadType::ReloadFromOrigin) { |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1250 | // Example of this case are sites that reload the same URL with a different cookie |
| 1251 | // driving the generated content, or a master frame with links that drive a target |
| 1252 | // frame, where the user has clicked on the same link repeatedly. |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1253 | m_loadType = FrameLoadType::Same; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1254 | } |
| 1255 | } |
| 1256 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1257 | SubstituteData FrameLoader::defaultSubstituteDataForURL(const URL& url) |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 1258 | { |
| 1259 | if (!shouldTreatURLAsSrcdocDocument(url)) |
| 1260 | return SubstituteData(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1261 | String srcdoc = m_frame.ownerElement()->fastGetAttribute(srcdocAttr); |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 1262 | ASSERT(!srcdoc.isNull()); |
| 1263 | CString encodedSrcdoc = srcdoc.utf8(); |
beidson@apple.com | ceb7cba | 2015-05-19 22:22:51 +0000 | [diff] [blame] | 1264 | |
| 1265 | ResourceResponse response(URL(), ASCIILiteral("text/html"), encodedSrcdoc.length(), ASCIILiteral("UTF-8")); |
| 1266 | 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] | 1267 | } |
| 1268 | |
simonjam@chromium.org | c98850b | 2012-11-28 01:07:36 +0000 | [diff] [blame] | 1269 | void FrameLoader::load(const FrameLoadRequest& passedRequest) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1270 | { |
simonjam@chromium.org | c98850b | 2012-11-28 01:07:36 +0000 | [diff] [blame] | 1271 | FrameLoadRequest request(passedRequest); |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 1272 | |
andersca | 8567b3d | 2007-03-21 05:46:49 +0000 | [diff] [blame] | 1273 | if (m_inStopAllLoaders) |
| 1274 | return; |
simonjam@chromium.org | c98850b | 2012-11-28 01:07:36 +0000 | [diff] [blame] | 1275 | |
| 1276 | if (!request.frameName().isEmpty()) { |
| 1277 | Frame* frame = findFrameForNavigation(request.frameName()); |
| 1278 | if (frame) { |
| 1279 | request.setShouldCheckNewWindowPolicy(false); |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 1280 | if (&frame->loader() != this) { |
| 1281 | frame->loader().load(request); |
simonjam@chromium.org | c98850b | 2012-11-28 01:07:36 +0000 | [diff] [blame] | 1282 | return; |
| 1283 | } |
| 1284 | } |
| 1285 | } |
| 1286 | |
| 1287 | if (request.shouldCheckNewWindowPolicy()) { |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 1288 | NavigationAction action(request.resourceRequest(), NavigationType::Other, passedRequest.shouldOpenExternalURLsPolicy()); |
| 1289 | policyChecker().checkNewWindowPolicy(action, request.resourceRequest(), nullptr, request.frameName(), [this](const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName, const NavigationAction& action, bool shouldContinue) { |
ap@apple.com | a383f25 | 2015-02-14 18:16:00 +0000 | [diff] [blame] | 1290 | continueLoadAfterNewWindowPolicy(request, formState, frameName, action, shouldContinue, AllowNavigationToInvalidURL::Yes, NewFrameOpenerPolicy::Suppress); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1291 | }); |
| 1292 | |
simonjam@chromium.org | c98850b | 2012-11-28 01:07:36 +0000 | [diff] [blame] | 1293 | return; |
| 1294 | } |
| 1295 | |
| 1296 | if (!request.hasSubstituteData()) |
| 1297 | request.setSubstituteData(defaultSubstituteDataForURL(request.resourceRequest().url())); |
| 1298 | |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 1299 | Ref<DocumentLoader> loader = m_client.createDocumentLoader(request.resourceRequest(), request.substituteData()); |
| 1300 | applyShouldOpenExternalURLsPolicyToNewDocumentLoader(loader, request.shouldOpenExternalURLsPolicy()); |
beidson@apple.com | d055853 | 2015-05-28 04:52:25 +0000 | [diff] [blame] | 1301 | |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 1302 | load(loader.ptr()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 1305 | void FrameLoader::loadWithNavigationAction(const ResourceRequest& request, const NavigationAction& action, LockHistory lockHistory, FrameLoadType type, PassRefPtr<FormState> formState, AllowNavigationToInvalidURL allowNavigationToInvalidURL) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1306 | { |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 1307 | Ref<DocumentLoader> loader = m_client.createDocumentLoader(request, defaultSubstituteDataForURL(request.url())); |
| 1308 | applyShouldOpenExternalURLsPolicyToNewDocumentLoader(loader, action.shouldOpenExternalURLsPolicy()); |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 1309 | |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 1310 | if (lockHistory == LockHistory::Yes && m_documentLoader) |
commit-queue@webkit.org | 63040d0 | 2011-03-26 00:30:40 +0000 | [diff] [blame] | 1311 | loader->setClientRedirectSourceForHistory(m_documentLoader->didCreateGlobalHistoryEntry() ? m_documentLoader->urlForHistory().string() : m_documentLoader->clientRedirectSourceForHistory()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1312 | |
| 1313 | loader->setTriggeringAction(action); |
| 1314 | if (m_documentLoader) |
| 1315 | loader->setOverrideEncoding(m_documentLoader->overrideEncoding()); |
| 1316 | |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 1317 | loadWithDocumentLoader(loader.ptr(), type, formState, allowNavigationToInvalidURL); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | void FrameLoader::load(DocumentLoader* newDocumentLoader) |
| 1321 | { |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1322 | ResourceRequest& r = newDocumentLoader->request(); |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 1323 | addExtraFieldsToMainResourceRequest(r); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1324 | FrameLoadType type; |
| 1325 | |
| 1326 | if (shouldTreatURLAsSameAsCurrent(newDocumentLoader->originalRequest().url())) { |
| 1327 | r.setCachePolicy(ReloadIgnoringCacheData); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1328 | type = FrameLoadType::Same; |
| 1329 | } else if (shouldTreatURLAsSameAsCurrent(newDocumentLoader->unreachableURL()) && m_loadType == FrameLoadType::Reload) |
| 1330 | type = FrameLoadType::Reload; |
jpfau@apple.com | 6e5a605 | 2012-07-27 00:52:32 +0000 | [diff] [blame] | 1331 | else |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1332 | type = FrameLoadType::Standard; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1333 | |
| 1334 | if (m_documentLoader) |
| 1335 | newDocumentLoader->setOverrideEncoding(m_documentLoader->overrideEncoding()); |
| 1336 | |
| 1337 | // 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] | 1338 | // 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] | 1339 | // is appropriately maintained. |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1340 | // |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1341 | // 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] | 1342 | // shouldn't a more explicit type of reload be defined, that means roughly |
| 1343 | // "load without affecting history" ? |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 1344 | if (shouldReloadToHandleUnreachableURL(newDocumentLoader)) { |
commit-queue@webkit.org | 072ac24 | 2011-04-04 17:05:55 +0000 | [diff] [blame] | 1345 | // shouldReloadToHandleUnreachableURL() returns true only when the original load type is back-forward. |
| 1346 | // In this case we should save the document state now. Otherwise the state can be lost because load type is |
| 1347 | // changed and updateForBackForwardNavigation() will not be called when loading is committed. |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 1348 | history().saveDocumentAndScrollState(); |
commit-queue@webkit.org | 072ac24 | 2011-04-04 17:05:55 +0000 | [diff] [blame] | 1349 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1350 | ASSERT(type == FrameLoadType::Standard); |
| 1351 | type = FrameLoadType::Reload; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 1354 | loadWithDocumentLoader(newDocumentLoader, type, 0, AllowNavigationToInvalidURL::Yes); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
cdumez@apple.com | 841ecde | 2015-01-12 22:30:59 +0000 | [diff] [blame] | 1357 | static void logNavigation(MainFrame& frame, FrameLoadType type) |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1358 | { |
cdumez@apple.com | 841ecde | 2015-01-12 22:30:59 +0000 | [diff] [blame] | 1359 | String navigationDescription; |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1360 | switch (type) { |
| 1361 | case FrameLoadType::Standard: |
cdumez@apple.com | 841ecde | 2015-01-12 22:30:59 +0000 | [diff] [blame] | 1362 | navigationDescription = ASCIILiteral("standard"); |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1363 | break; |
| 1364 | case FrameLoadType::Back: |
cdumez@apple.com | 841ecde | 2015-01-12 22:30:59 +0000 | [diff] [blame] | 1365 | navigationDescription = ASCIILiteral("back"); |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1366 | break; |
| 1367 | case FrameLoadType::Forward: |
cdumez@apple.com | 841ecde | 2015-01-12 22:30:59 +0000 | [diff] [blame] | 1368 | navigationDescription = ASCIILiteral("forward"); |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1369 | break; |
| 1370 | case FrameLoadType::IndexedBackForward: |
cdumez@apple.com | 841ecde | 2015-01-12 22:30:59 +0000 | [diff] [blame] | 1371 | navigationDescription = ASCIILiteral("indexedBackForward"); |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1372 | break; |
| 1373 | case FrameLoadType::Reload: |
cdumez@apple.com | 841ecde | 2015-01-12 22:30:59 +0000 | [diff] [blame] | 1374 | navigationDescription = ASCIILiteral("reload"); |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1375 | break; |
| 1376 | case FrameLoadType::Same: |
cdumez@apple.com | 841ecde | 2015-01-12 22:30:59 +0000 | [diff] [blame] | 1377 | navigationDescription = ASCIILiteral("same"); |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1378 | break; |
| 1379 | case FrameLoadType::ReloadFromOrigin: |
cdumez@apple.com | 841ecde | 2015-01-12 22:30:59 +0000 | [diff] [blame] | 1380 | navigationDescription = ASCIILiteral("reloadFromOrigin"); |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1381 | break; |
| 1382 | case FrameLoadType::Replace: |
| 1383 | case FrameLoadType::RedirectWithLockedBackForwardList: |
| 1384 | // Not logging those for now. |
| 1385 | return; |
| 1386 | } |
cdumez@apple.com | 216d257 | 2015-02-23 22:08:45 +0000 | [diff] [blame] | 1387 | frame.diagnosticLoggingClient().logDiagnosticMessage(DiagnosticLoggingKeys::navigationKey(), navigationDescription, ShouldSample::No); |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 1390 | void FrameLoader::loadWithDocumentLoader(DocumentLoader* loader, FrameLoadType type, PassRefPtr<FormState> prpFormState, AllowNavigationToInvalidURL allowNavigationToInvalidURL) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1391 | { |
inferno@chromium.org | 6e8e347 | 2010-10-26 13:29:04 +0000 | [diff] [blame] | 1392 | // Retain because dispatchBeforeLoadEvent may release the last reference to it. |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 1393 | Ref<Frame> protect(m_frame); |
inferno@chromium.org | 6e8e347 | 2010-10-26 13:29:04 +0000 | [diff] [blame] | 1394 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1395 | ASSERT(m_client.hasWebView()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1396 | |
| 1397 | // Unfortunately the view must be non-nil, this is ultimately due |
| 1398 | // to parser requiring a FrameView. We should fix this dependency. |
| 1399 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1400 | ASSERT(m_frame.view()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1401 | |
cdumez@apple.com | 83847a9 | 2015-06-26 18:26:19 +0000 | [diff] [blame] | 1402 | if (m_pageDismissalEventBeingDispatched != PageDismissalType::None) |
abarth@webkit.org | 89fa350 | 2009-09-21 02:30:12 +0000 | [diff] [blame] | 1403 | return; |
| 1404 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1405 | if (m_frame.document()) |
| 1406 | m_previousURL = m_frame.document()->url(); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 1407 | |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1408 | // Log main frame navigation types. |
| 1409 | if (m_frame.isMainFrame()) |
cdumez@apple.com | 841ecde | 2015-01-12 22:30:59 +0000 | [diff] [blame] | 1410 | logNavigation(static_cast<MainFrame&>(m_frame), type); |
cdumez@apple.com | 4c54fa7 | 2014-12-18 18:42:27 +0000 | [diff] [blame] | 1411 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1412 | policyChecker().setLoadType(type); |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1413 | RefPtr<FormState> formState = prpFormState; |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 1414 | bool isFormSubmission = formState; |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1415 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1416 | const URL& newURL = loader->request().url(); |
yael.aharon@nokia.com | 79f6905 | 2010-12-30 19:31:00 +0000 | [diff] [blame] | 1417 | const String& httpMethod = loader->request().httpMethod(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1418 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1419 | if (shouldPerformFragmentNavigation(isFormSubmission, httpMethod, policyChecker().loadType(), newURL)) { |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 1420 | RefPtr<DocumentLoader> oldDocumentLoader = m_documentLoader; |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1421 | NavigationAction action(loader->request(), policyChecker().loadType(), isFormSubmission); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1422 | |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 1423 | oldDocumentLoader->setTriggeringAction(action); |
andersca@apple.com | 97ab6d9 | 2013-10-21 22:55:14 +0000 | [diff] [blame] | 1424 | oldDocumentLoader->setLastCheckedRequest(ResourceRequest()); |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1425 | policyChecker().stopCheck(); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1426 | policyChecker().checkNavigationPolicy(loader->request(), oldDocumentLoader.get(), formState, [this](const ResourceRequest& request, PassRefPtr<FormState>, bool shouldContinue) { |
| 1427 | continueFragmentScrollAfterNavigationPolicy(request, shouldContinue); |
| 1428 | }); |
| 1429 | return; |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 1430 | } |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1431 | |
| 1432 | if (Frame* parent = m_frame.tree().parent()) |
| 1433 | loader->setOverrideEncoding(parent->loader().documentLoader()->overrideEncoding()); |
| 1434 | |
| 1435 | policyChecker().stopCheck(); |
| 1436 | setPolicyDocumentLoader(loader); |
| 1437 | if (loader->triggeringAction().isEmpty()) |
| 1438 | loader->setTriggeringAction(NavigationAction(loader->request(), policyChecker().loadType(), isFormSubmission)); |
| 1439 | |
| 1440 | if (Element* ownerElement = m_frame.ownerElement()) { |
| 1441 | // We skip dispatching the beforeload event if we've already |
| 1442 | // committed a real document load because the event would leak |
| 1443 | // subsequent activity by the frame which the parent frame isn't |
| 1444 | // supposed to learn. For example, if the child frame navigated to |
| 1445 | // a new URL, the parent frame shouldn't learn the URL. |
| 1446 | if (!m_stateMachine.committedFirstRealDocumentLoad() |
| 1447 | && !ownerElement->dispatchBeforeLoadEvent(loader->request().url().string())) { |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 1448 | continueLoadAfterNavigationPolicy(loader->request(), formState, false, allowNavigationToInvalidURL); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1449 | return; |
| 1450 | } |
| 1451 | } |
| 1452 | |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 1453 | policyChecker().checkNavigationPolicy(loader->request(), loader, formState, [this, allowNavigationToInvalidURL](const ResourceRequest& request, PassRefPtr<FormState> formState, bool shouldContinue) { |
| 1454 | continueLoadAfterNavigationPolicy(request, formState, shouldContinue, allowNavigationToInvalidURL); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 1455 | }); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
aroben@apple.com | 92cfa90 | 2008-04-16 19:19:00 +0000 | [diff] [blame] | 1458 | void FrameLoader::reportLocalLoadFailed(Frame* frame, const String& url) |
kmccullo | 23d362f | 2007-04-06 01:05:58 +0000 | [diff] [blame] | 1459 | { |
| 1460 | ASSERT(!url.isEmpty()); |
aroben@apple.com | 92cfa90 | 2008-04-16 19:19:00 +0000 | [diff] [blame] | 1461 | if (!frame) |
| 1462 | return; |
| 1463 | |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 1464 | 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] | 1465 | } |
| 1466 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1467 | const ResourceRequest& FrameLoader::initialRequest() const |
| 1468 | { |
andersca@apple.com | 48ffa33 | 2008-03-13 19:08:06 +0000 | [diff] [blame] | 1469 | return activeDocumentLoader()->originalRequest(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1472 | bool FrameLoader::willLoadMediaElementURL(URL& url) |
weinig@apple.com | 6893525 | 2009-10-07 02:48:12 +0000 | [diff] [blame] | 1473 | { |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1474 | #if PLATFORM(IOS) |
| 1475 | // MobileStore depends on the iOS 4.0 era client delegate method because webView:resource:willSendRequest:redirectResponse:fromDataSource |
| 1476 | // doesn't let them tell when a load request is coming from a media element. See <rdar://problem/8266916> for more details. |
| 1477 | if (applicationIsMobileStore()) |
| 1478 | return m_client.shouldLoadMediaElementURL(url); |
| 1479 | #endif |
| 1480 | |
weinig@apple.com | 6893525 | 2009-10-07 02:48:12 +0000 | [diff] [blame] | 1481 | ResourceRequest request(url); |
| 1482 | |
| 1483 | unsigned long identifier; |
| 1484 | ResourceError error; |
| 1485 | requestFromDelegate(request, identifier, error); |
antti@apple.com | 021dc01 | 2014-09-04 20:00:11 +0000 | [diff] [blame] | 1486 | 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] | 1487 | |
| 1488 | url = request.url(); |
| 1489 | |
| 1490 | return error.isNull(); |
| 1491 | } |
| 1492 | |
mjs | 2d326f5 | 2007-01-29 12:50:49 +0000 | [diff] [blame] | 1493 | bool FrameLoader::shouldReloadToHandleUnreachableURL(DocumentLoader* docLoader) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1494 | { |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1495 | URL unreachableURL = docLoader->unreachableURL(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1496 | |
| 1497 | if (unreachableURL.isEmpty()) |
| 1498 | return false; |
| 1499 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1500 | if (!isBackForwardLoadType(policyChecker().loadType())) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1501 | return false; |
| 1502 | |
| 1503 | // We only treat unreachableURLs specially during the delegate callbacks |
| 1504 | // for provisional load errors and navigation policy decisions. The former |
| 1505 | // case handles well-formed URLs that can't be loaded, and the latter |
| 1506 | // case handles malformed URLs and unknown schemes. Loading alternate content |
| 1507 | // at other times behaves like a standard load. |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1508 | if (policyChecker().delegateIsDecidingNavigationPolicy() || policyChecker().delegateIsHandlingUnimplementablePolicy()) |
mitz@apple.com | 6699e27 | 2015-05-01 23:47:03 +0000 | [diff] [blame] | 1509 | return m_policyDocumentLoader && unreachableURL == m_policyDocumentLoader->request().url(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1510 | |
mitz@apple.com | 6699e27 | 2015-05-01 23:47:03 +0000 | [diff] [blame] | 1511 | return unreachableURL == m_provisionalLoadErrorBeingHandledURL; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
ggaren@apple.com | 3eaa7c0 | 2009-01-29 07:38:54 +0000 | [diff] [blame] | 1514 | void FrameLoader::reloadWithOverrideEncoding(const String& encoding) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1515 | { |
| 1516 | if (!m_documentLoader) |
| 1517 | return; |
| 1518 | |
| 1519 | ResourceRequest request = m_documentLoader->request(); |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1520 | URL unreachableURL = m_documentLoader->unreachableURL(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1521 | if (!unreachableURL.isEmpty()) |
| 1522 | request.setURL(unreachableURL); |
| 1523 | |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 1524 | // FIXME: If the resource is a result of form submission and is not cached, the form will be silently resubmitted. |
| 1525 | // We should ask the user for confirmation in this case. |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1526 | request.setCachePolicy(ReturnCacheDataElseLoad); |
| 1527 | |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 1528 | Ref<DocumentLoader> loader = m_client.createDocumentLoader(request, defaultSubstituteDataForURL(request.url())); |
| 1529 | applyShouldOpenExternalURLsPolicyToNewDocumentLoader(loader, m_documentLoader->shouldOpenExternalURLsPolicyToPropagate()); |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 1530 | |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 1531 | setPolicyDocumentLoader(loader.ptr()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1532 | |
| 1533 | loader->setOverrideEncoding(encoding); |
| 1534 | |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 1535 | loadWithDocumentLoader(loader.ptr(), FrameLoadType::Reload, 0, AllowNavigationToInvalidURL::Yes); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1536 | } |
| 1537 | |
achristensen@apple.com | d40e0ba | 2015-10-14 20:03:14 +0000 | [diff] [blame] | 1538 | void FrameLoader::reload(bool endToEndReload, bool contentBlockersEnabled) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1539 | { |
| 1540 | if (!m_documentLoader) |
| 1541 | return; |
| 1542 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1543 | // If a window is created by javascript, its main frame can have an empty but non-nil URL. |
| 1544 | // Reloading in this case will lose the current contents (see 4151001). |
darin@chromium.org | 4824685 | 2008-11-04 19:40:56 +0000 | [diff] [blame] | 1545 | if (m_documentLoader->request().url().isEmpty()) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1546 | return; |
| 1547 | |
| 1548 | // 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] | 1549 | ResourceRequest initialRequest = m_documentLoader->request(); |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1550 | URL unreachableURL = m_documentLoader->unreachableURL(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1551 | if (!unreachableURL.isEmpty()) |
darin@chromium.org | 4824685 | 2008-11-04 19:40:56 +0000 | [diff] [blame] | 1552 | initialRequest.setURL(unreachableURL); |
commit-queue@webkit.org | 2090e27 | 2012-06-28 16:05:43 +0000 | [diff] [blame] | 1553 | |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 1554 | // Create a new document loader for the reload, this will become m_documentLoader eventually, |
| 1555 | // 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] | 1556 | Ref<DocumentLoader> loader = m_client.createDocumentLoader(initialRequest, defaultSubstituteDataForURL(initialRequest.url())); |
| 1557 | applyShouldOpenExternalURLsPolicyToNewDocumentLoader(loader, m_documentLoader->shouldOpenExternalURLsPolicyToPropagate()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1558 | |
achristensen@apple.com | d40e0ba | 2015-10-14 20:03:14 +0000 | [diff] [blame] | 1559 | loader->setUserContentExtensionsEnabled(contentBlockersEnabled); |
| 1560 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1561 | ResourceRequest& request = loader->request(); |
| 1562 | |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 1563 | // FIXME: We don't have a mechanism to revalidate the main resource without reloading at the moment. |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1564 | request.setCachePolicy(ReloadIgnoringCacheData); |
| 1565 | |
| 1566 | // If we're about to re-post, set up action so the application can warn the user. |
| 1567 | if (request.httpMethod() == "POST") |
beidson@apple.com | 32654c4 | 2015-04-27 18:46:15 +0000 | [diff] [blame] | 1568 | loader->setTriggeringAction(NavigationAction(request, NavigationType::FormResubmitted)); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1569 | |
| 1570 | loader->setOverrideEncoding(m_documentLoader->overrideEncoding()); |
| 1571 | |
gyuyoung.kim@webkit.org | c39073e | 2015-07-19 00:16:50 +0000 | [diff] [blame] | 1572 | loadWithDocumentLoader(loader.ptr(), endToEndReload ? FrameLoadType::ReloadFromOrigin : FrameLoadType::Reload, 0, AllowNavigationToInvalidURL::Yes); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 1573 | } |
| 1574 | |
commit-queue@webkit.org | fc5833b | 2011-02-23 06:58:46 +0000 | [diff] [blame] | 1575 | void FrameLoader::stopAllLoaders(ClearProvisionalItemPolicy clearProvisionalItemPolicy) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1576 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1577 | ASSERT(!m_frame.document() || !m_frame.document()->inPageCache()); |
cdumez@apple.com | 83847a9 | 2015-06-26 18:26:19 +0000 | [diff] [blame] | 1578 | if (m_pageDismissalEventBeingDispatched != PageDismissalType::None) |
weinig@apple.com | f239bbf | 2009-04-09 18:30:32 +0000 | [diff] [blame] | 1579 | return; |
| 1580 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1581 | // If this method is called from within this method, infinite recursion can occur (3442218). Avoid this. |
| 1582 | if (m_inStopAllLoaders) |
| 1583 | return; |
inferno@chromium.org | bc05aa5 | 2012-08-06 16:30:40 +0000 | [diff] [blame] | 1584 | |
| 1585 | // Calling stopLoading() on the provisional document loader can blow away |
| 1586 | // the frame from underneath. |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 1587 | Ref<Frame> protect(m_frame); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1588 | |
| 1589 | m_inStopAllLoaders = true; |
| 1590 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 1591 | policyChecker().stopCheck(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1592 | |
commit-queue@webkit.org | 987fd77 | 2011-01-21 18:26:42 +0000 | [diff] [blame] | 1593 | // If no new load is in progress, we should clear the provisional item from history |
| 1594 | // before we call stopLoading. |
| 1595 | if (clearProvisionalItemPolicy == ShouldClearProvisionalItem) |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 1596 | history().setProvisionalItem(nullptr); |
commit-queue@webkit.org | 987fd77 | 2011-01-21 18:26:42 +0000 | [diff] [blame] | 1597 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1598 | 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] | 1599 | child->loader().stopAllLoaders(clearProvisionalItemPolicy); |
darin | 7208e93 | 2007-02-13 17:52:53 +0000 | [diff] [blame] | 1600 | if (m_provisionalDocumentLoader) |
commit-queue@webkit.org | fc5833b | 2011-02-23 06:58:46 +0000 | [diff] [blame] | 1601 | m_provisionalDocumentLoader->stopLoading(); |
beidson@apple.com | 4642121 | 2008-08-25 21:48:56 +0000 | [diff] [blame] | 1602 | if (m_documentLoader) |
commit-queue@webkit.org | fc5833b | 2011-02-23 06:58:46 +0000 | [diff] [blame] | 1603 | m_documentLoader->stopLoading(); |
beidson@apple.com | 4642121 | 2008-08-25 21:48:56 +0000 | [diff] [blame] | 1604 | |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 1605 | setProvisionalDocumentLoader(nullptr); |
darin | 7208e93 | 2007-02-13 17:52:53 +0000 | [diff] [blame] | 1606 | |
ap@apple.com | 376647e | 2010-01-21 23:19:57 +0000 | [diff] [blame] | 1607 | m_checkTimer.stop(); |
| 1608 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1609 | m_inStopAllLoaders = false; |
| 1610 | } |
| 1611 | |
beidson | 398923b | 2007-07-31 20:29:02 +0000 | [diff] [blame] | 1612 | void FrameLoader::stopForUserCancel(bool deferCheckLoadComplete) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 1613 | { |
| 1614 | stopAllLoaders(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1615 | |
| 1616 | #if PLATFORM(IOS) |
| 1617 | // Lay out immediately when stopping to immediately clear the old page if we just committed this one |
| 1618 | // but haven't laid out/painted yet. |
| 1619 | // FIXME: Is this behavior specific to iOS? Or should we expose a setting to toggle this behavior? |
| 1620 | if (m_frame.view() && !m_frame.view()->didFirstLayout()) |
| 1621 | m_frame.view()->layout(); |
| 1622 | #endif |
| 1623 | |
beidson | 398923b | 2007-07-31 20:29:02 +0000 | [diff] [blame] | 1624 | if (deferCheckLoadComplete) |
| 1625 | scheduleCheckLoadComplete(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1626 | else if (m_frame.page()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 1627 | checkLoadComplete(); |
| 1628 | } |
| 1629 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1630 | DocumentLoader* FrameLoader::activeDocumentLoader() const |
| 1631 | { |
| 1632 | if (m_state == FrameStateProvisional) |
| 1633 | return m_provisionalDocumentLoader.get(); |
| 1634 | return m_documentLoader.get(); |
| 1635 | } |
| 1636 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1637 | bool FrameLoader::isLoading() const |
| 1638 | { |
darin | 8207db4 | 2007-02-20 18:18:39 +0000 | [diff] [blame] | 1639 | DocumentLoader* docLoader = activeDocumentLoader(); |
| 1640 | if (!docLoader) |
| 1641 | return false; |
japhet@chromium.org | 4bcb80b | 2012-03-26 20:34:00 +0000 | [diff] [blame] | 1642 | return docLoader->isLoading(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1643 | } |
| 1644 | |
mjs | 7545bb5 | 2007-05-15 08:24:53 +0000 | [diff] [blame] | 1645 | bool FrameLoader::frameHasLoaded() const |
| 1646 | { |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 1647 | return m_stateMachine.committedFirstRealDocumentLoad() || (m_provisionalDocumentLoader && !m_stateMachine.creatingInitialEmptyDocument()); |
mjs | 7545bb5 | 2007-05-15 08:24:53 +0000 | [diff] [blame] | 1648 | } |
| 1649 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1650 | void FrameLoader::setDocumentLoader(DocumentLoader* loader) |
| 1651 | { |
| 1652 | if (!loader && !m_documentLoader) |
| 1653 | return; |
| 1654 | |
| 1655 | ASSERT(loader != m_documentLoader); |
| 1656 | ASSERT(!loader || loader->frameLoader() == this); |
| 1657 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1658 | m_client.prepareForDataSourceReplacement(); |
darin | c3d2605 | 2007-03-22 18:17:12 +0000 | [diff] [blame] | 1659 | detachChildren(); |
japhet@chromium.org | a9a58bb | 2012-09-01 01:09:02 +0000 | [diff] [blame] | 1660 | |
| 1661 | // detachChildren() can trigger this frame's unload event, and therefore |
| 1662 | // script can run and do just about anything. For example, an unload event that calls |
| 1663 | // document.write("") on its parent frame can lead to a recursive detachChildren() |
| 1664 | // invocation for this frame. In that case, we can end up at this point with a |
| 1665 | // loader that hasn't been deleted but has been detached from its frame. Such a |
| 1666 | // DocumentLoader has been sufficiently detached that we'll end up in an inconsistent |
| 1667 | // state if we try to use it. |
| 1668 | if (loader && !loader->frame()) |
| 1669 | return; |
| 1670 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1671 | if (m_documentLoader) |
| 1672 | m_documentLoader->detachFromFrame(); |
| 1673 | |
| 1674 | m_documentLoader = loader; |
| 1675 | } |
| 1676 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1677 | void FrameLoader::setPolicyDocumentLoader(DocumentLoader* loader) |
| 1678 | { |
| 1679 | if (m_policyDocumentLoader == loader) |
| 1680 | return; |
| 1681 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1682 | if (loader) |
beidson@apple.com | 10a537f | 2015-07-09 22:30:42 +0000 | [diff] [blame] | 1683 | loader->attachToFrame(m_frame); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1684 | if (m_policyDocumentLoader |
| 1685 | && m_policyDocumentLoader != m_provisionalDocumentLoader |
| 1686 | && m_policyDocumentLoader != m_documentLoader) |
| 1687 | m_policyDocumentLoader->detachFromFrame(); |
| 1688 | |
| 1689 | m_policyDocumentLoader = loader; |
| 1690 | } |
eric@webkit.org | 14774f4 | 2008-04-21 17:50:37 +0000 | [diff] [blame] | 1691 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1692 | void FrameLoader::setProvisionalDocumentLoader(DocumentLoader* loader) |
| 1693 | { |
| 1694 | ASSERT(!loader || !m_provisionalDocumentLoader); |
| 1695 | ASSERT(!loader || loader->frameLoader() == this); |
| 1696 | |
| 1697 | if (m_provisionalDocumentLoader && m_provisionalDocumentLoader != m_documentLoader) |
| 1698 | m_provisionalDocumentLoader->detachFromFrame(); |
| 1699 | |
| 1700 | m_provisionalDocumentLoader = loader; |
| 1701 | } |
| 1702 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1703 | void FrameLoader::setState(FrameState newState) |
| 1704 | { |
| 1705 | m_state = newState; |
| 1706 | |
| 1707 | if (newState == FrameStateProvisional) |
| 1708 | provisionalLoadStarted(); |
| 1709 | else if (newState == FrameStateComplete) { |
| 1710 | frameLoadCompleted(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1711 | if (m_documentLoader) |
| 1712 | m_documentLoader->stopRecordingResponses(); |
| 1713 | } |
| 1714 | } |
| 1715 | |
| 1716 | void FrameLoader::clearProvisionalLoad() |
| 1717 | { |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 1718 | setProvisionalDocumentLoader(nullptr); |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 1719 | m_progressTracker->progressCompleted(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1720 | setState(FrameStateComplete); |
| 1721 | } |
| 1722 | |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 1723 | void FrameLoader::commitProvisionalLoad() |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1724 | { |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1725 | RefPtr<DocumentLoader> pdl = m_provisionalDocumentLoader; |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 1726 | Ref<Frame> protect(m_frame); |
beidson@apple.com | 3a5e3b9 | 2009-01-27 08:05:59 +0000 | [diff] [blame] | 1727 | |
andersca@apple.com | e776c2f | 2014-01-18 01:47:19 +0000 | [diff] [blame] | 1728 | std::unique_ptr<CachedPage> cachedPage; |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 1729 | if (m_loadingFromCachedPage && history().provisionalItem()) |
cdumez@apple.com | 4faf1ef | 2015-01-30 20:49:33 +0000 | [diff] [blame] | 1730 | cachedPage = PageCache::singleton().take(*history().provisionalItem(), m_frame.page()); |
akling@apple.com | 9663f4b | 2013-09-05 21:25:32 +0000 | [diff] [blame] | 1731 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1732 | LOG(PageCache, "WebCoreLoading %s: About to commit provisional load from previous URL '%s' to new URL '%s'", m_frame.tree().uniqueName().string().utf8().data(), |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1733 | m_frame.document() ? m_frame.document()->url().stringCenterEllipsizedToLength().utf8().data() : "", |
mkwst@chromium.org | 6f6d9bc | 2013-05-30 12:08:58 +0000 | [diff] [blame] | 1734 | pdl ? pdl->url().stringCenterEllipsizedToLength().utf8().data() : "<no provisional DocumentLoader>"); |
beidson@apple.com | 3a5e3b9 | 2009-01-27 08:05:59 +0000 | [diff] [blame] | 1735 | |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1736 | #if PLATFORM(IOS) |
| 1737 | // In the case where we are not navigating to a cached page, and the system is under (speculative) memory pressure, |
| 1738 | // we can try to preemptively release some of the pages in the cache. |
| 1739 | // FIXME: Right now the capacity is 1 on iOS devices with 256 MB of RAM, so this will always blow away the whole |
| 1740 | // page cache. We could still preemptively prune the page cache while navigating to a cached page if capacity > 1. |
| 1741 | // See <rdar://problem/11779846> for more details. |
| 1742 | if (!cachedPage) { |
cdumez@apple.com | 681b4aa | 2015-02-17 17:30:34 +0000 | [diff] [blame] | 1743 | if (MemoryPressureHandler::singleton().isUnderMemoryPressure()) { |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1744 | LOG(MemoryPressure, "Pruning page cache because under memory pressure at: %s", __PRETTY_FUNCTION__); |
| 1745 | LOG(PageCache, "Pruning page cache to 0 due to memory pressure"); |
| 1746 | // Don't cache any page if we are under memory pressure. |
cdumez@apple.com | 4faf1ef | 2015-01-30 20:49:33 +0000 | [diff] [blame] | 1747 | PageCache::singleton().pruneToSizeNow(0, PruningReason::MemoryPressure); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1748 | } else if (systemMemoryLevel() <= memoryLevelThresholdToPrunePageCache) { |
| 1749 | LOG(MemoryPressure, "Pruning page cache because system memory level is %d at: %s", systemMemoryLevel(), __PRETTY_FUNCTION__); |
cdumez@apple.com | 4faf1ef | 2015-01-30 20:49:33 +0000 | [diff] [blame] | 1750 | auto& pageCache = PageCache::singleton(); |
| 1751 | LOG(PageCache, "Pruning page cache to %d due to low memory (level %d less or equal to %d threshold)", pageCache.maxSize() / 2, systemMemoryLevel(), memoryLevelThresholdToPrunePageCache); |
| 1752 | pageCache.pruneToSizeNow(pageCache.maxSize() / 2, PruningReason::MemoryPressure); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1753 | } |
| 1754 | } |
| 1755 | #endif |
| 1756 | |
ap@apple.com | e042b63 | 2013-05-17 20:04:43 +0000 | [diff] [blame] | 1757 | willTransitionToCommitted(); |
| 1758 | |
adachan@apple.com | 0781d12 | 2008-01-11 23:56:40 +0000 | [diff] [blame] | 1759 | // Check to see if we need to cache the page we are navigating away from into the back/forward cache. |
| 1760 | // We are doing this here because we know for sure that a new page is about to be loaded. |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 1761 | HistoryItem& item = *history().currentItem(); |
cdumez@apple.com | 4faf1ef | 2015-01-30 20:49:33 +0000 | [diff] [blame] | 1762 | if (!m_frame.tree().parent() && PageCache::singleton().canCache(m_frame.page()) && !item.isInPageCache()) |
| 1763 | PageCache::singleton().add(item, *m_frame.page()); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 1764 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1765 | if (m_loadType != FrameLoadType::Replace) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1766 | closeOldDataSources(); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 1767 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 1768 | if (!cachedPage && !m_stateMachine.creatingInitialEmptyDocument()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1769 | m_client.makeRepresentation(pdl.get()); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 1770 | |
akling@apple.com | 9663f4b | 2013-09-05 21:25:32 +0000 | [diff] [blame] | 1771 | transitionToCommitted(cachedPage.get()); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 1772 | |
abarth@webkit.org | f12783f | 2012-10-03 19:34:30 +0000 | [diff] [blame] | 1773 | if (pdl && m_documentLoader) { |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 1774 | // 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] | 1775 | Ref<SecurityOrigin> securityOrigin(SecurityOrigin::create(pdl->request().url())); |
akling@apple.com | 5a7607f | 2015-01-21 22:33:49 +0000 | [diff] [blame] | 1776 | m_documentLoader->timing().setHasSameOriginAsPreviousDocument(securityOrigin.get().canRequest(m_previousURL)); |
simonjam@chromium.org | 92bc9b0 | 2011-01-06 02:41:13 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
beidson | b72fe2e | 2007-05-03 21:35:24 +0000 | [diff] [blame] | 1779 | // 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] | 1780 | // status has changed, if there was a redirect. The frame load delegate may have saved some state about |
| 1781 | // the redirect in its -webView:willPerformClientRedirectToURL:delay:fireDate:forFrame:. Since we are |
| 1782 | // just about to commit a new page, there cannot possibly be a pending redirect at this point. |
| 1783 | if (m_sentRedirectNotification) |
| 1784 | clientRedirectCancelledOrFinished(false); |
| 1785 | |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 1786 | if (cachedPage && cachedPage->document()) { |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1787 | #if PLATFORM(IOS) |
| 1788 | // FIXME: CachedPage::restore() would dispatch viewport change notification. However UIKit expects load |
| 1789 | // commit to happen before any changes to viewport arguments and dealing with this there is difficult. |
| 1790 | m_frame.page()->chrome().setDispatchViewportDataDidChangeSuppressed(true); |
| 1791 | #endif |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 1792 | prepareForCachedPageRestore(); |
commit-queue@webkit.org | cbb6a49 | 2010-09-20 20:20:25 +0000 | [diff] [blame] | 1793 | |
akling@apple.com | 9663f4b | 2013-09-05 21:25:32 +0000 | [diff] [blame] | 1794 | // FIXME: This API should be turned around so that we ground CachedPage into the Page. |
| 1795 | cachedPage->restore(*m_frame.page()); |
commit-queue@webkit.org | 1686e5d | 2012-10-19 23:13:08 +0000 | [diff] [blame] | 1796 | |
commit-queue@webkit.org | cbb6a49 | 2010-09-20 20:20:25 +0000 | [diff] [blame] | 1797 | dispatchDidCommitLoad(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1798 | #if PLATFORM(IOS) |
| 1799 | m_frame.page()->chrome().setDispatchViewportDataDidChangeSuppressed(false); |
| 1800 | m_frame.page()->chrome().dispatchViewportPropertiesDidChange(m_frame.page()->viewportArguments()); |
| 1801 | #endif |
commit-queue@webkit.org | cbb6a49 | 2010-09-20 20:20:25 +0000 | [diff] [blame] | 1802 | // If we have a title let the WebView know about it. |
evan@chromium.org | c3532e9 | 2011-03-31 15:17:13 +0000 | [diff] [blame] | 1803 | StringWithDirection title = m_documentLoader->title(); |
| 1804 | if (!title.isNull()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1805 | m_client.dispatchDidReceiveTitle(title); |
commit-queue@webkit.org | cbb6a49 | 2010-09-20 20:20:25 +0000 | [diff] [blame] | 1806 | |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 1807 | checkCompleted(); |
akling@apple.com | 9663f4b | 2013-09-05 21:25:32 +0000 | [diff] [blame] | 1808 | } else |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 1809 | didOpenURL(); |
beidson@apple.com | 3a5e3b9 | 2009-01-27 08:05:59 +0000 | [diff] [blame] | 1810 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 1811 | 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] | 1812 | m_frame.document() ? m_frame.document()->url().stringCenterEllipsizedToLength().utf8().data() : ""); |
beidson@apple.com | 3a5e3b9 | 2009-01-27 08:05:59 +0000 | [diff] [blame] | 1813 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1814 | if (m_loadType == FrameLoadType::Standard && m_documentLoader->isClientRedirect()) |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 1815 | history().updateForClientRedirect(); |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 1816 | |
beidson@apple.com | ac095c0 | 2009-08-18 01:37:56 +0000 | [diff] [blame] | 1817 | if (m_loadingFromCachedPage) { |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1818 | #if PLATFORM(IOS) |
| 1819 | // Note, didReceiveDocType is expected to be called for cached pages. See <rdar://problem/5906758> for more details. |
| 1820 | if (m_frame.document()->doctype() && m_frame.page()) |
| 1821 | m_frame.page()->chrome().didReceiveDocType(&m_frame); |
| 1822 | #endif |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1823 | m_frame.document()->documentDidResumeFromPageCache(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1824 | |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 1825 | // Force a layout to update view size and thereby update scrollbars. |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1826 | #if PLATFORM(IOS) |
simon.fraser@apple.com | 72978b3 | 2014-03-09 18:14:07 +0000 | [diff] [blame] | 1827 | if (!m_client.forceLayoutOnRestoreFromPageCache()) |
| 1828 | m_frame.view()->forceLayout(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1829 | #else |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1830 | m_frame.view()->forceLayout(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1831 | #endif |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 1832 | |
commit-queue@webkit.org | acddfad | 2015-09-30 05:53:51 +0000 | [diff] [blame] | 1833 | for (auto& response : m_documentLoader->responses()) { |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 1834 | // FIXME: If the WebKit client changes or cancels the request, this is not respected. |
| 1835 | ResourceError error; |
| 1836 | unsigned long identifier; |
| 1837 | ResourceRequest request(response.url()); |
| 1838 | requestFromDelegate(request, identifier, error); |
| 1839 | // FIXME: If we get a resource with more than 2B bytes, this code won't do the right thing. |
| 1840 | // However, with today's computers and networking speeds, this won't happen in practice. |
| 1841 | // Could be an issue with a giant local file. |
akling@apple.com | 654fd9a | 2013-10-06 21:07:29 +0000 | [diff] [blame] | 1842 | 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] | 1843 | } |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 1844 | |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 1845 | // FIXME: Why only this frame and not parent frames? |
| 1846 | checkLoadCompleteForThisFrame(); |
| 1847 | } |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
akling@apple.com | 9663f4b | 2013-09-05 21:25:32 +0000 | [diff] [blame] | 1850 | void FrameLoader::transitionToCommitted(CachedPage* cachedPage) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1851 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1852 | ASSERT(m_client.hasWebView()); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1853 | ASSERT(m_state == FrameStateProvisional); |
| 1854 | |
| 1855 | if (m_state != FrameStateProvisional) |
| 1856 | return; |
| 1857 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1858 | if (FrameView* view = m_frame.view()) { |
bdakin@apple.com | 3fec69c | 2012-03-23 21:02:51 +0000 | [diff] [blame] | 1859 | if (ScrollAnimator* scrollAnimator = view->existingScrollAnimator()) |
bdakin@apple.com | 87235fc | 2012-03-23 20:36:31 +0000 | [diff] [blame] | 1860 | scrollAnimator->cancelAnimations(); |
| 1861 | } |
bdakin@apple.com | e0a38ad | 2011-03-15 18:30:41 +0000 | [diff] [blame] | 1862 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1863 | m_client.setCopiesOnScroll(); |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 1864 | history().updateForCommit(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1865 | |
| 1866 | // The call to closeURL() invokes the unload event handler, which can execute arbitrary |
| 1867 | // JavaScript. If the script initiates a new load, we need to abandon the current load, |
| 1868 | // or the two will stomp each other. |
| 1869 | DocumentLoader* pdl = m_provisionalDocumentLoader.get(); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 1870 | if (m_documentLoader) |
| 1871 | closeURL(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1872 | if (pdl != m_provisionalDocumentLoader) |
| 1873 | return; |
| 1874 | |
beidson | 4a28913 | 2007-05-03 18:50:41 +0000 | [diff] [blame] | 1875 | // Nothing else can interupt this commit - set the Provisional->Committed transition in stone |
| 1876 | if (m_documentLoader) |
| 1877 | m_documentLoader->stopLoadingSubresources(); |
| 1878 | if (m_documentLoader) |
| 1879 | m_documentLoader->stopLoadingPlugIns(); |
| 1880 | |
| 1881 | setDocumentLoader(m_provisionalDocumentLoader.get()); |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 1882 | setProvisionalDocumentLoader(nullptr); |
japhet@chromium.org | a9a58bb | 2012-09-01 01:09:02 +0000 | [diff] [blame] | 1883 | |
| 1884 | if (pdl != m_documentLoader) { |
| 1885 | ASSERT(m_state == FrameStateComplete); |
| 1886 | return; |
| 1887 | } |
| 1888 | |
commit-queue@webkit.org | 1af3b43 | 2011-08-05 07:00:47 +0000 | [diff] [blame] | 1889 | setState(FrameStateCommittedPage); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1890 | |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 1891 | #if ENABLE(TOUCH_EVENTS) && !PLATFORM(IOS) |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 1892 | if (m_frame.isMainFrame()) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1893 | m_frame.page()->chrome().client().needTouchEvents(false); |
commit-queue@webkit.org | 52b6833 | 2011-06-07 16:20:07 +0000 | [diff] [blame] | 1894 | #endif |
| 1895 | |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1896 | // Handle adding the URL to the back/forward list. |
| 1897 | DocumentLoader* dl = m_documentLoader.get(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1898 | |
| 1899 | switch (m_loadType) { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1900 | case FrameLoadType::Forward: |
| 1901 | case FrameLoadType::Back: |
| 1902 | case FrameLoadType::IndexedBackForward: |
| 1903 | if (m_frame.page()) { |
| 1904 | // If the first load within a frame is a navigation within a back/forward list that was attached |
| 1905 | // without any of the items being loaded then we need to update the history in a similar manner as |
| 1906 | // for a standard load with the exception of updating the back/forward list (<rdar://problem/8091103>). |
| 1907 | if (!m_stateMachine.committedFirstRealDocumentLoad() && m_frame.isMainFrame()) |
| 1908 | history().updateForStandardLoad(HistoryController::UpdateAllExceptBackForwardList); |
mrowe@apple.com | 04fa487 | 2010-06-16 02:23:45 +0000 | [diff] [blame] | 1909 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1910 | history().updateForBackForwardNavigation(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1911 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1912 | // For cached pages, CachedFrame::restore will take care of firing the popstate event with the history item's state object |
| 1913 | if (history().currentItem() && !cachedPage) |
| 1914 | m_pendingStateObject = history().currentItem()->stateObject(); |
mrowe@apple.com | 04fa487 | 2010-06-16 02:23:45 +0000 | [diff] [blame] | 1915 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1916 | // Create a document view for this document, or used the cached view. |
| 1917 | if (cachedPage) { |
| 1918 | DocumentLoader* cachedDocumentLoader = cachedPage->documentLoader(); |
| 1919 | ASSERT(cachedDocumentLoader); |
beidson@apple.com | 10a537f | 2015-07-09 22:30:42 +0000 | [diff] [blame] | 1920 | cachedDocumentLoader->attachToFrame(m_frame); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1921 | m_client.transitionToCommittedFromCachedFrame(cachedPage->cachedMainFrame()); |
| 1922 | } else |
| 1923 | m_client.transitionToCommittedForNewPage(); |
| 1924 | } |
| 1925 | break; |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1926 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1927 | case FrameLoadType::Reload: |
| 1928 | case FrameLoadType::ReloadFromOrigin: |
| 1929 | case FrameLoadType::Same: |
| 1930 | case FrameLoadType::Replace: |
| 1931 | history().updateForReload(); |
| 1932 | m_client.transitionToCommittedForNewPage(); |
| 1933 | break; |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1934 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1935 | case FrameLoadType::Standard: |
| 1936 | history().updateForStandardLoad(); |
| 1937 | if (m_frame.view()) |
| 1938 | m_frame.view()->setScrollbarsSuppressed(true); |
| 1939 | m_client.transitionToCommittedForNewPage(); |
| 1940 | break; |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1941 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1942 | case FrameLoadType::RedirectWithLockedBackForwardList: |
| 1943 | history().updateForRedirectWithLockedBackForwardList(); |
| 1944 | m_client.transitionToCommittedForNewPage(); |
| 1945 | break; |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1946 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 1947 | // FIXME Remove this check when dummy ds is removed (whatever "dummy ds" is). |
| 1948 | // An exception should be thrown if we're in the FrameLoadTypeUninitialized state. |
| 1949 | default: |
| 1950 | ASSERT_NOT_REACHED(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
weinig@apple.com | ee87b2f | 2013-10-05 23:59:58 +0000 | [diff] [blame] | 1953 | m_documentLoader->writer().setMIMEType(dl->responseMIMEType()); |
weinig | 9288333 | 2007-02-20 01:05:27 +0000 | [diff] [blame] | 1954 | |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1955 | // Tell the client we've committed this URL. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1956 | ASSERT(m_frame.view()); |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 1957 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 1958 | if (m_stateMachine.creatingInitialEmptyDocument()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 1959 | return; |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 1960 | |
| 1961 | if (!m_stateMachine.committedFirstRealDocumentLoad()) |
| 1962 | m_stateMachine.advanceTo(FrameLoaderStateMachine::DisplayingInitialEmptyDocumentPostCommit); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1965 | void FrameLoader::clientRedirectCancelledOrFinished(bool cancelWithLoadInProgress) |
| 1966 | { |
| 1967 | // Note that -webView:didCancelClientRedirectForFrame: is called on the frame load delegate even if |
| 1968 | // the redirect succeeded. We should either rename this API, or add a new method, like |
| 1969 | // -webView:didFinishClientRedirectForFrame: |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1970 | m_client.dispatchDidCancelClientRedirect(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1971 | |
| 1972 | if (!cancelWithLoadInProgress) |
| 1973 | m_quickRedirectComing = false; |
| 1974 | |
| 1975 | m_sentRedirectNotification = false; |
| 1976 | } |
| 1977 | |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 1978 | void FrameLoader::clientRedirected(const URL& url, double seconds, double fireDate, LockBackForwardList lockBackForwardList) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1979 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 1980 | m_client.dispatchWillPerformClientRedirect(url, seconds, fireDate); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1981 | |
| 1982 | // Remember that we sent a redirect notification to the frame load delegate so that when we commit |
| 1983 | // the next provisional load, we can send a corresponding -webView:didCancelClientRedirectForFrame: |
| 1984 | m_sentRedirectNotification = true; |
| 1985 | |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 1986 | // If a "quick" redirect comes in, we set a special mode so we treat the next |
| 1987 | // 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] | 1988 | // 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] | 1989 | // Loads triggered by JavaScript form submissions never count as quick redirects. |
mrowe@apple.com | bf5eaa6 | 2014-04-03 00:51:04 +0000 | [diff] [blame] | 1990 | m_quickRedirectComing = (lockBackForwardList == LockBackForwardList::Yes || history().currentItemShouldBeReplaced()) && m_documentLoader && !m_isExecutingJavaScriptFormAction; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1991 | } |
| 1992 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 1993 | bool FrameLoader::shouldReload(const URL& currentURL, const URL& destinationURL) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1994 | { |
| 1995 | // This function implements the rule: "Don't reload if navigating by fragment within |
| 1996 | // the same URL, but do reload if going to a new URL or to the same URL with no |
| 1997 | // fragment identifier at all." |
beidson@apple.com | ee49725 | 2009-08-10 16:35:00 +0000 | [diff] [blame] | 1998 | if (!destinationURL.hasFragmentIdentifier()) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 1999 | return true; |
beidson@apple.com | ee49725 | 2009-08-10 16:35:00 +0000 | [diff] [blame] | 2000 | return !equalIgnoringFragmentIdentifier(currentURL, destinationURL); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | void FrameLoader::closeOldDataSources() |
| 2004 | { |
| 2005 | // FIXME: Is it important for this traversal to be postorder instead of preorder? |
| 2006 | // If so, add helpers for postorder traversal, and use them. If not, then lets not |
| 2007 | // use a recursive algorithm here. |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2008 | 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] | 2009 | child->loader().closeOldDataSources(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2010 | |
| 2011 | if (m_documentLoader) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2012 | m_client.dispatchWillClose(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2013 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2014 | m_client.setMainFrameDocumentReady(false); // stop giving out the actual DOMDocument to observers |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 2017 | void FrameLoader::prepareForCachedPageRestore() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2018 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2019 | ASSERT(!m_frame.tree().parent()); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2020 | ASSERT(m_frame.page()); |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 2021 | ASSERT(m_frame.isMainFrame()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2022 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2023 | m_frame.navigationScheduler().cancel(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2024 | |
| 2025 | // We still have to close the previous part page. |
| 2026 | closeURL(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2027 | |
| 2028 | // 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] | 2029 | if (m_frame.script().canExecuteScripts(NotAboutToExecuteScript)) { |
| 2030 | DOMWindow* window = m_frame.document()->domWindow(); |
abarth@webkit.org | 13fe1e2 | 2012-08-16 22:29:48 +0000 | [diff] [blame] | 2031 | window->setStatus(String()); |
| 2032 | window->setDefaultStatus(String()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2033 | } |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2034 | } |
| 2035 | |
beidson@apple.com | 913c7f8 | 2009-09-02 20:16:38 +0000 | [diff] [blame] | 2036 | void FrameLoader::open(CachedFrameBase& cachedFrame) |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2037 | { |
| 2038 | m_isComplete = false; |
| 2039 | |
| 2040 | // Don't re-emit the load event. |
| 2041 | m_didCallImplicitClose = true; |
| 2042 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2043 | URL url = cachedFrame.url(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2044 | |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 2045 | // FIXME: I suspect this block of code doesn't do anything. |
benjamin@webkit.org | f726d63 | 2012-03-04 03:26:27 +0000 | [diff] [blame] | 2046 | if (url.protocolIsInHTTPFamily() && !url.host().isEmpty() && url.path().isEmpty()) |
weinig@apple.com | c500266 | 2007-12-12 07:26:19 +0000 | [diff] [blame] | 2047 | url.setPath("/"); |
abarth@webkit.org | 55d49da | 2011-06-20 23:32:54 +0000 | [diff] [blame] | 2048 | |
abarth@webkit.org | 91289c3 | 2010-04-12 04:54:55 +0000 | [diff] [blame] | 2049 | started(); |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2050 | Document* document = cachedFrame.document(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2051 | ASSERT(document); |
abarth@webkit.org | 23ea90a | 2012-08-14 19:47:59 +0000 | [diff] [blame] | 2052 | ASSERT(document->domWindow()); |
| 2053 | |
| 2054 | clear(document, true, true, cachedFrame.isMainFrame()); |
| 2055 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2056 | document->setInPageCache(false); |
| 2057 | |
| 2058 | m_needsClear = true; |
| 2059 | m_isComplete = false; |
ggaren | a57755c | 2007-07-09 21:08:10 +0000 | [diff] [blame] | 2060 | m_didCallImplicitClose = false; |
weinig@apple.com | c500266 | 2007-12-12 07:26:19 +0000 | [diff] [blame] | 2061 | m_outgoingReferrer = url.string(); |
kmccullo | 6b1b5c2 | 2007-05-24 20:06:56 +0000 | [diff] [blame] | 2062 | |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2063 | FrameView* view = cachedFrame.view(); |
| 2064 | |
| 2065 | // When navigating to a CachedFrame its FrameView should never be null. If it is we'll crash in creative ways downstream. |
| 2066 | ASSERT(view); |
beidson@apple.com | 24f92a5 | 2009-09-03 00:07:51 +0000 | [diff] [blame] | 2067 | view->setWasScrolledByUser(false); |
adachan@apple.com | 95f492a | 2009-08-24 19:55:23 +0000 | [diff] [blame] | 2068 | |
cdumez@apple.com | 665ca3b | 2015-05-08 18:15:57 +0000 | [diff] [blame] | 2069 | Optional<IntRect> previousViewFrameRect = m_frame.view() ? m_frame.view()->frameRect() : Optional<IntRect>(Nullopt); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2070 | m_frame.setView(view); |
cdumez@apple.com | 665ca3b | 2015-05-08 18:15:57 +0000 | [diff] [blame] | 2071 | |
| 2072 | // Use the previous ScrollView's frame rect. |
| 2073 | if (previousViewFrameRect) |
| 2074 | view->setFrameRect(previousViewFrameRect.value()); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2075 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2076 | m_frame.setDocument(document); |
abarth@webkit.org | 23ea90a | 2012-08-14 19:47:59 +0000 | [diff] [blame] | 2077 | document->domWindow()->resumeFromPageCache(); |
weinig@apple.com | 5367c41 | 2008-06-27 00:03:25 +0000 | [diff] [blame] | 2078 | |
abarth@webkit.org | 622d9df | 2009-05-22 16:44:47 +0000 | [diff] [blame] | 2079 | updateFirstPartyForCookies(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2080 | |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2081 | cachedFrame.restore(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2084 | bool FrameLoader::isHostedByObjectElement() const |
| 2085 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2086 | HTMLFrameOwnerElement* owner = m_frame.ownerElement(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2087 | return owner && owner->hasTagName(objectTag); |
| 2088 | } |
| 2089 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2090 | bool FrameLoader::isReplacing() const |
| 2091 | { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2092 | return m_loadType == FrameLoadType::Replace; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | void FrameLoader::setReplacing() |
| 2096 | { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2097 | m_loadType = FrameLoadType::Replace; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2098 | } |
| 2099 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2100 | bool FrameLoader::subframeIsLoading() const |
| 2101 | { |
| 2102 | // 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] | 2103 | 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] | 2104 | FrameLoader& childLoader = child->loader(); |
| 2105 | DocumentLoader* documentLoader = childLoader.documentLoader(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2106 | if (documentLoader && documentLoader->isLoadingInAPISense()) |
| 2107 | return true; |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2108 | documentLoader = childLoader.provisionalDocumentLoader(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2109 | if (documentLoader && documentLoader->isLoadingInAPISense()) |
| 2110 | return true; |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2111 | documentLoader = childLoader.policyDocumentLoader(); |
mjs@apple.com | 17a175d | 2010-07-18 00:15:31 +0000 | [diff] [blame] | 2112 | if (documentLoader) |
| 2113 | return true; |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2114 | } |
| 2115 | return false; |
| 2116 | } |
| 2117 | |
| 2118 | void FrameLoader::willChangeTitle(DocumentLoader* loader) |
| 2119 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2120 | m_client.willChangeTitle(loader); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | FrameLoadType FrameLoader::loadType() const |
| 2124 | { |
| 2125 | return m_loadType; |
| 2126 | } |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2127 | |
beidson@apple.com | ee54c99 | 2009-05-19 23:41:15 +0000 | [diff] [blame] | 2128 | CachePolicy FrameLoader::subresourceCachePolicy() const |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2129 | { |
| 2130 | if (m_isComplete) |
| 2131 | return CachePolicyVerify; |
ap@webkit.org | 86b1098 | 2009-05-18 15:30:10 +0000 | [diff] [blame] | 2132 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2133 | if (m_loadType == FrameLoadType::ReloadFromOrigin) |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2134 | return CachePolicyReload; |
ap@webkit.org | 86b1098 | 2009-05-18 15:30:10 +0000 | [diff] [blame] | 2135 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2136 | if (Frame* parentFrame = m_frame.tree().parent()) { |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2137 | CachePolicy parentCachePolicy = parentFrame->loader().subresourceCachePolicy(); |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2138 | if (parentCachePolicy != CachePolicyVerify) |
| 2139 | return parentCachePolicy; |
| 2140 | } |
slewis@apple.com | ef236f4 | 2011-05-25 23:00:45 +0000 | [diff] [blame] | 2141 | |
cdumez@apple.com | 7449316 | 2014-12-08 18:42:12 +0000 | [diff] [blame] | 2142 | switch (m_loadType) { |
| 2143 | case FrameLoadType::Reload: |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2144 | return CachePolicyRevalidate; |
cdumez@apple.com | 7449316 | 2014-12-08 18:42:12 +0000 | [diff] [blame] | 2145 | case FrameLoadType::Back: |
| 2146 | case FrameLoadType::Forward: |
| 2147 | case FrameLoadType::IndexedBackForward: |
joepeck@webkit.org | 853e686 | 2010-11-18 17:59:53 +0000 | [diff] [blame] | 2148 | return CachePolicyHistoryBuffer; |
cdumez@apple.com | 7449316 | 2014-12-08 18:42:12 +0000 | [diff] [blame] | 2149 | case FrameLoadType::ReloadFromOrigin: |
| 2150 | ASSERT_NOT_REACHED(); // Already handled above. |
| 2151 | return CachePolicyReload; |
| 2152 | case FrameLoadType::RedirectWithLockedBackForwardList: |
| 2153 | case FrameLoadType::Replace: |
| 2154 | case FrameLoadType::Same: |
| 2155 | case FrameLoadType::Standard: |
| 2156 | return CachePolicyVerify; |
| 2157 | } |
ossy@webkit.org | 41788ca | 2014-12-08 19:30:19 +0000 | [diff] [blame] | 2158 | |
| 2159 | RELEASE_ASSERT_NOT_REACHED(); |
| 2160 | return CachePolicyVerify; |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2161 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2162 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2163 | void FrameLoader::checkLoadCompleteForThisFrame() |
| 2164 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2165 | ASSERT(m_client.hasWebView()); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2166 | |
| 2167 | switch (m_state) { |
| 2168 | case FrameStateProvisional: { |
mitz@apple.com | 6699e27 | 2015-05-01 23:47:03 +0000 | [diff] [blame] | 2169 | if (!m_provisionalLoadErrorBeingHandledURL.isEmpty()) |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2170 | return; |
| 2171 | |
| 2172 | RefPtr<DocumentLoader> pdl = m_provisionalDocumentLoader; |
| 2173 | if (!pdl) |
| 2174 | return; |
| 2175 | |
| 2176 | // If we've received any errors we may be stuck in the provisional state and actually complete. |
| 2177 | const ResourceError& error = pdl->mainDocumentError(); |
| 2178 | if (error.isNull()) |
| 2179 | return; |
| 2180 | |
| 2181 | // Check all children first. |
| 2182 | RefPtr<HistoryItem> item; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2183 | if (Page* page = m_frame.page()) |
commit-queue@webkit.org | 21a48d8 | 2011-01-09 01:27:19 +0000 | [diff] [blame] | 2184 | if (isBackForwardLoadType(loadType())) |
| 2185 | // 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] | 2186 | item = page->mainFrame().loader().history().currentItem(); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2187 | |
commit-queue@webkit.org | 987fd77 | 2011-01-21 18:26:42 +0000 | [diff] [blame] | 2188 | // 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] | 2189 | bool shouldReset = !history().provisionalItem(); |
ap@apple.com | 421e9a1 | 2011-03-24 00:50:45 +0000 | [diff] [blame] | 2190 | if (!pdl->isLoadingInAPISense() || pdl->isStopping()) { |
mitz@apple.com | 6699e27 | 2015-05-01 23:47:03 +0000 | [diff] [blame] | 2191 | m_provisionalLoadErrorBeingHandledURL = m_provisionalDocumentLoader->url(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2192 | m_client.dispatchDidFailProvisionalLoad(error); |
mitz@apple.com | 6699e27 | 2015-05-01 23:47:03 +0000 | [diff] [blame] | 2193 | m_provisionalLoadErrorBeingHandledURL = { }; |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2194 | |
ap@apple.com | 09535d1 | 2011-03-24 00:48:30 +0000 | [diff] [blame] | 2195 | ASSERT(!pdl->isLoading()); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2196 | |
eric@webkit.org | b562c40 | 2010-01-13 01:29:35 +0000 | [diff] [blame] | 2197 | // If we're in the middle of loading multipart data, we need to restore the document loader. |
| 2198 | if (isReplacing() && !m_documentLoader.get()) |
eric@webkit.org | 9074725 | 2010-01-12 18:10:14 +0000 | [diff] [blame] | 2199 | setDocumentLoader(m_provisionalDocumentLoader.get()); |
| 2200 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2201 | // Finish resetting the load state, but only if another load hasn't been started by the |
| 2202 | // delegate callback. |
| 2203 | if (pdl == m_provisionalDocumentLoader) |
| 2204 | clearProvisionalLoad(); |
tonikitoo@webkit.org | e94ac9b | 2009-11-16 15:38:19 +0000 | [diff] [blame] | 2205 | else if (activeDocumentLoader()) { |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2206 | URL unreachableURL = activeDocumentLoader()->unreachableURL(); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2207 | if (!unreachableURL.isEmpty() && unreachableURL == pdl->request().url()) |
| 2208 | shouldReset = false; |
| 2209 | } |
| 2210 | } |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 2211 | if (shouldReset && item) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2212 | if (Page* page = m_frame.page()) { |
akling@apple.com | 31cf009 | 2013-09-11 15:24:45 +0000 | [diff] [blame] | 2213 | page->backForward().setCurrentItem(item.get()); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2214 | m_frame.loader().client().updateGlobalHistoryItemForPage(); |
mitz@apple.com | bc84376 | 2008-12-08 21:18:11 +0000 | [diff] [blame] | 2215 | } |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2216 | return; |
| 2217 | } |
| 2218 | |
| 2219 | case FrameStateCommittedPage: { |
| 2220 | DocumentLoader* dl = m_documentLoader.get(); |
darin@apple.com | 40b5df6 | 2009-05-02 19:58:43 +0000 | [diff] [blame] | 2221 | if (!dl || (dl->isLoadingInAPISense() && !dl->isStopping())) |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2222 | return; |
| 2223 | |
darin@apple.com | af8b1a9 | 2011-06-25 00:09:37 +0000 | [diff] [blame] | 2224 | setState(FrameStateComplete); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2225 | |
| 2226 | // FIXME: Is this subsequent work important if we already navigated away? |
| 2227 | // Maybe there are bugs because of that, or extra work we can skip because |
| 2228 | // the new page is ready. |
| 2229 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2230 | m_client.forceLayoutForNonHTML(); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2231 | |
| 2232 | // 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] | 2233 | if (m_frame.page()) { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2234 | if (isBackForwardLoadType(m_loadType) || m_loadType == FrameLoadType::Reload || m_loadType == FrameLoadType::ReloadFromOrigin) |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2235 | history().restoreScrollPositionAndViewState(); |
darin@apple.com | e10e128 | 2010-10-30 00:44:33 +0000 | [diff] [blame] | 2236 | } |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2237 | |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 2238 | if (m_stateMachine.creatingInitialEmptyDocument() || !m_stateMachine.committedFirstRealDocumentLoad()) |
mjs | 8d620d5 | 2007-05-10 12:31:42 +0000 | [diff] [blame] | 2239 | return; |
| 2240 | |
timothy_horton@apple.com | 346f8d7 | 2013-08-01 00:06:51 +0000 | [diff] [blame] | 2241 | m_progressTracker->progressCompleted(); |
eric.carlson@apple.com | 77b4a11 | 2014-10-30 19:04:29 +0000 | [diff] [blame] | 2242 | Page* page = m_frame.page(); |
| 2243 | if (page) { |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 2244 | if (m_frame.isMainFrame()) |
timothy_horton@apple.com | 346f8d7 | 2013-08-01 00:06:51 +0000 | [diff] [blame] | 2245 | page->resetRelevantPaintedObjectCounter(); |
andersca@apple.com | 7c0a3fc | 2012-05-01 22:22:25 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2248 | const ResourceError& error = dl->mainDocumentError(); |
mario@webkit.org | 685258f | 2011-12-06 00:10:55 +0000 | [diff] [blame] | 2249 | |
| 2250 | AXObjectCache::AXLoadingEvent loadingEvent; |
| 2251 | if (!error.isNull()) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2252 | m_client.dispatchDidFailLoad(error); |
mario@webkit.org | 685258f | 2011-12-06 00:10:55 +0000 | [diff] [blame] | 2253 | loadingEvent = AXObjectCache::AXLoadingFailed; |
| 2254 | } else { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2255 | m_client.dispatchDidFinishLoad(); |
mario@webkit.org | 685258f | 2011-12-06 00:10:55 +0000 | [diff] [blame] | 2256 | loadingEvent = AXObjectCache::AXLoadingFinished; |
| 2257 | } |
| 2258 | |
| 2259 | // Notify accessibility. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2260 | if (AXObjectCache* cache = m_frame.document()->existingAXObjectCache()) |
| 2261 | cache->frameLoadingEventNotification(&m_frame, loadingEvent); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2262 | |
beidson@apple.com | 4aecb3d | 2015-07-09 04:47:09 +0000 | [diff] [blame] | 2263 | // The above calls to dispatchDidFinishLoad() might have detached the Frame |
| 2264 | // from its Page and also might have caused Page to be deleted. |
| 2265 | // Don't assume 'page' is still available to use. |
| 2266 | if (m_frame.isMainFrame() && m_frame.page()) { |
| 2267 | ASSERT(&m_frame.page()->mainFrame() == &m_frame); |
| 2268 | m_frame.page()->mainFrame().diagnosticLoggingClient().logDiagnosticMessageWithResult(DiagnosticLoggingKeys::pageLoadedKey(), emptyString(), error.isNull() ? DiagnosticLoggingResultPass : DiagnosticLoggingResultFail, ShouldSample::Yes); |
| 2269 | } |
eric.carlson@apple.com | 77b4a11 | 2014-10-30 19:04:29 +0000 | [diff] [blame] | 2270 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2271 | return; |
| 2272 | } |
| 2273 | |
| 2274 | case FrameStateComplete: |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2275 | m_loadType = FrameLoadType::Standard; |
beidson@apple.com | d141827 | 2009-01-30 17:30:47 +0000 | [diff] [blame] | 2276 | frameLoadCompleted(); |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 2277 | return; |
| 2278 | } |
| 2279 | |
| 2280 | ASSERT_NOT_REACHED(); |
| 2281 | } |
andersca | 5d5f802 | 2007-02-28 00:38:00 +0000 | [diff] [blame] | 2282 | |
abarth@webkit.org | 453854e | 2009-10-08 03:17:08 +0000 | [diff] [blame] | 2283 | void FrameLoader::continueLoadAfterWillSubmitForm() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2284 | { |
beidson | b72fe2e | 2007-05-03 21:35:24 +0000 | [diff] [blame] | 2285 | if (!m_provisionalDocumentLoader) |
| 2286 | return; |
| 2287 | |
japhet@chromium.org | 91e5e2f | 2012-04-02 22:08:19 +0000 | [diff] [blame] | 2288 | prepareForLoadStart(); |
beidson@apple.com | 1289cdb | 2008-07-03 06:10:47 +0000 | [diff] [blame] | 2289 | |
| 2290 | // The load might be cancelled inside of prepareForLoadStart(), nulling out the m_provisionalDocumentLoader, |
| 2291 | // so we need to null check it again. |
| 2292 | if (!m_provisionalDocumentLoader) |
| 2293 | return; |
beidson | b72fe2e | 2007-05-03 21:35:24 +0000 | [diff] [blame] | 2294 | |
| 2295 | DocumentLoader* activeDocLoader = activeDocumentLoader(); |
| 2296 | if (activeDocLoader && activeDocLoader->isLoadingMainResource()) |
| 2297 | return; |
| 2298 | |
beidson@apple.com | ac095c0 | 2009-08-18 01:37:56 +0000 | [diff] [blame] | 2299 | m_loadingFromCachedPage = false; |
japhet@chromium.org | d7b5ad2 | 2012-03-27 20:30:28 +0000 | [diff] [blame] | 2300 | m_provisionalDocumentLoader->startLoadingMainResource(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2301 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2302 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2303 | static URL originatingURLFromBackForwardList(Page* page) |
ap@apple.com | 456d465 | 2011-11-30 12:13:31 +0000 | [diff] [blame] | 2304 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2305 | // FIXME: Can this logic be replaced with m_frame.document()->firstPartyForCookies()? |
ap@apple.com | 456d465 | 2011-11-30 12:13:31 +0000 | [diff] [blame] | 2306 | // It has the same meaning of "page a user thinks is the current one". |
| 2307 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2308 | URL originalURL; |
akling@apple.com | 31cf009 | 2013-09-11 15:24:45 +0000 | [diff] [blame] | 2309 | int backCount = page->backForward().backCount(); |
ap@apple.com | 456d465 | 2011-11-30 12:13:31 +0000 | [diff] [blame] | 2310 | for (int backIndex = 0; backIndex <= backCount; backIndex++) { |
| 2311 | // FIXME: At one point we had code here to check a "was user gesture" flag. |
| 2312 | // Do we need to restore that logic? |
akling@apple.com | 31cf009 | 2013-09-11 15:24:45 +0000 | [diff] [blame] | 2313 | HistoryItem* historyItem = page->backForward().itemAtIndex(-backIndex); |
ap@apple.com | 456d465 | 2011-11-30 12:13:31 +0000 | [diff] [blame] | 2314 | if (!historyItem) |
| 2315 | continue; |
| 2316 | |
| 2317 | originalURL = historyItem->originalURL(); |
| 2318 | if (!originalURL.isNull()) |
| 2319 | return originalURL; |
| 2320 | } |
| 2321 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2322 | return URL(); |
ap@apple.com | 456d465 | 2011-11-30 12:13:31 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | void FrameLoader::setOriginalURLForDownloadRequest(ResourceRequest& request) |
| 2326 | { |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2327 | URL originalURL; |
ap@apple.com | 456d465 | 2011-11-30 12:13:31 +0000 | [diff] [blame] | 2328 | |
| 2329 | // If there is no referrer, assume that the download was initiated directly, so current document is |
| 2330 | // completely unrelated to it. See <rdar://problem/5294691>. |
| 2331 | // FIXME: Referrer is not sent in many other cases, so we will often miss this important information. |
| 2332 | // Find a better way to decide whether the download was unrelated to current document. |
| 2333 | if (!request.httpReferrer().isNull()) { |
| 2334 | // find the first item in the history that was originated by the user |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2335 | originalURL = originatingURLFromBackForwardList(m_frame.page()); |
ap@apple.com | 456d465 | 2011-11-30 12:13:31 +0000 | [diff] [blame] | 2336 | } |
| 2337 | |
| 2338 | if (originalURL.isNull()) |
| 2339 | originalURL = request.url(); |
| 2340 | |
| 2341 | if (!originalURL.protocol().isEmpty() && !originalURL.host().isEmpty()) { |
| 2342 | unsigned port = originalURL.port(); |
| 2343 | |
| 2344 | // Original URL is needed to show the user where a file was downloaded from. We should make a URL that won't result in downloading the file again. |
| 2345 | // FIXME: Using host-only URL is a very heavy-handed approach. We should attempt to provide the actual page where the download was initiated from, as a reminder to the user. |
| 2346 | String hostOnlyURLString; |
| 2347 | if (port) |
commit-queue@webkit.org | 9ca94b0 | 2014-08-30 23:19:32 +0000 | [diff] [blame] | 2348 | hostOnlyURLString = makeString(originalURL.protocol(), "://", originalURL.host(), ':', String::number(port)); |
ap@apple.com | 456d465 | 2011-11-30 12:13:31 +0000 | [diff] [blame] | 2349 | else |
| 2350 | hostOnlyURLString = makeString(originalURL.protocol(), "://", originalURL.host()); |
| 2351 | |
| 2352 | // FIXME: Rename firstPartyForCookies back to mainDocumentURL. It was a mistake to think that it was only used for cookies. |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2353 | request.setFirstPartyForCookies(URL(URL(), hostOnlyURLString)); |
ap@apple.com | 456d465 | 2011-11-30 12:13:31 +0000 | [diff] [blame] | 2354 | } |
| 2355 | } |
| 2356 | |
bdakin@apple.com | 0b27e9a | 2012-09-25 20:01:33 +0000 | [diff] [blame] | 2357 | void FrameLoader::didLayout(LayoutMilestones milestones) |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2358 | { |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 2359 | ASSERT(m_frame.isMainFrame()); |
bdakin@apple.com | 7ce7e1b | 2013-08-12 21:37:06 +0000 | [diff] [blame] | 2360 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2361 | m_client.dispatchDidLayout(milestones); |
bdakin@apple.com | 3ab3737 | 2012-02-01 21:52:41 +0000 | [diff] [blame] | 2362 | } |
| 2363 | |
bdakin@apple.com | e98caf1 | 2012-09-25 23:08:03 +0000 | [diff] [blame] | 2364 | void FrameLoader::didFirstLayout() |
| 2365 | { |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 2366 | #if PLATFORM(IOS) |
| 2367 | // Only send layout-related delegate callbacks synchronously for the main frame to |
| 2368 | // avoid reentering layout for the main frame while delivering a layout-related delegate |
| 2369 | // callback for a subframe. |
| 2370 | if (&m_frame != &m_frame.page()->mainFrame()) |
| 2371 | return; |
| 2372 | #endif |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2373 | if (m_frame.page() && isBackForwardLoadType(m_loadType)) |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2374 | history().restoreScrollPositionAndViewState(); |
bdakin@apple.com | e98caf1 | 2012-09-25 23:08:03 +0000 | [diff] [blame] | 2375 | |
| 2376 | if (m_stateMachine.committedFirstRealDocumentLoad() && !m_stateMachine.isDisplayingInitialEmptyDocument() && !m_stateMachine.firstLayoutDone()) |
| 2377 | m_stateMachine.advanceTo(FrameLoaderStateMachine::FirstLayoutDone); |
| 2378 | } |
| 2379 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2380 | void FrameLoader::frameLoadCompleted() |
| 2381 | { |
beidson@apple.com | d141827 | 2009-01-30 17:30:47 +0000 | [diff] [blame] | 2382 | // Note: Can be called multiple times. |
| 2383 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2384 | m_client.frameLoadCompleted(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2385 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2386 | history().updateForFrameLoadCompleted(); |
beidson@apple.com | d141827 | 2009-01-30 17:30:47 +0000 | [diff] [blame] | 2387 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2388 | // After a canceled provisional load, firstLayoutDone is false. |
| 2389 | // Reset it to true if we're displaying a page. |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 2390 | if (m_documentLoader && m_stateMachine.committedFirstRealDocumentLoad() && !m_stateMachine.isDisplayingInitialEmptyDocument() && !m_stateMachine.firstLayoutDone()) |
| 2391 | m_stateMachine.advanceTo(FrameLoaderStateMachine::FirstLayoutDone); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2394 | void FrameLoader::detachChildren() |
| 2395 | { |
akling@apple.com | 72c1c36 | 2013-09-06 01:34:05 +0000 | [diff] [blame] | 2396 | Vector<Ref<Frame>, 16> childrenToDetach; |
| 2397 | childrenToDetach.reserveInitialCapacity(m_frame.tree().childCount()); |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2398 | 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] | 2399 | childrenToDetach.uncheckedAppend(*child); |
commit-queue@webkit.org | acddfad | 2015-09-30 05:53:51 +0000 | [diff] [blame] | 2400 | for (auto& child : childrenToDetach) |
| 2401 | child->loader().detachFromParent(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2402 | } |
| 2403 | |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2404 | void FrameLoader::closeAndRemoveChild(Frame* child) |
| 2405 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2406 | child->tree().detachFromParent(); |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2407 | |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 2408 | child->setView(nullptr); |
beidson@apple.com | 24f92a5 | 2009-09-03 00:07:51 +0000 | [diff] [blame] | 2409 | if (child->ownerElement() && child->page()) |
simon.fraser@apple.com | 940f2fe | 2012-09-26 21:13:38 +0000 | [diff] [blame] | 2410 | child->page()->decrementSubframeCount(); |
kkristof@inf.u-szeged.hu | 8c9862d | 2012-06-01 13:51:14 +0000 | [diff] [blame] | 2411 | child->willDetachPage(); |
abarth@webkit.org | 047b877 | 2012-02-22 02:22:15 +0000 | [diff] [blame] | 2412 | child->detachFromPage(); |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2413 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2414 | m_frame.tree().removeChild(child); |
beidson@apple.com | 028c7a7 | 2009-02-11 22:01:22 +0000 | [diff] [blame] | 2415 | } |
| 2416 | |
darin@apple.com | af8b1a9 | 2011-06-25 00:09:37 +0000 | [diff] [blame] | 2417 | // Called every time a resource is completely loaded or an error is received. |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2418 | void FrameLoader::checkLoadComplete() |
| 2419 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2420 | ASSERT(m_client.hasWebView()); |
andersca | a315d57 | 2007-03-13 01:09:53 +0000 | [diff] [blame] | 2421 | |
darin@apple.com | f53381b | 2009-09-23 23:27:01 +0000 | [diff] [blame] | 2422 | m_shouldCallCheckLoadComplete = false; |
| 2423 | |
akling@apple.com | 72c1c36 | 2013-09-06 01:34:05 +0000 | [diff] [blame] | 2424 | if (!m_frame.page()) |
| 2425 | return; |
| 2426 | |
andersca | a315d57 | 2007-03-13 01:09:53 +0000 | [diff] [blame] | 2427 | // FIXME: Always traversing the entire frame tree is a bit inefficient, but |
| 2428 | // 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] | 2429 | Vector<Ref<Frame>, 16> frames; |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 2430 | for (Frame* frame = &m_frame.mainFrame(); frame; frame = frame->tree().traverseNext()) |
akling@apple.com | 72c1c36 | 2013-09-06 01:34:05 +0000 | [diff] [blame] | 2431 | frames.append(*frame); |
| 2432 | |
| 2433 | // To process children before their parents, iterate the vector backwards. |
| 2434 | for (unsigned i = frames.size(); i; --i) |
| 2435 | frames[i - 1]->loader().checkLoadCompleteForThisFrame(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2436 | } |
| 2437 | |
| 2438 | int FrameLoader::numPendingOrLoadingRequests(bool recurse) const |
| 2439 | { |
| 2440 | if (!recurse) |
cdumez@apple.com | 0bb03ec | 2015-01-28 05:53:53 +0000 | [diff] [blame] | 2441 | return m_frame.document()->cachedResourceLoader().requestCount(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2442 | |
| 2443 | int count = 0; |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2444 | 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] | 2445 | count += frame->document()->cachedResourceLoader().requestCount(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2446 | return count; |
| 2447 | } |
| 2448 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2449 | String FrameLoader::userAgent(const URL& url) const |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2450 | { |
seokju@webkit.org | cb8504d | 2014-01-09 17:19:34 +0000 | [diff] [blame] | 2451 | return m_client.userAgent(url); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2452 | } |
| 2453 | |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2454 | void FrameLoader::handledOnloadEvents() |
| 2455 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2456 | m_client.dispatchDidHandleOnloadEvents(); |
japhet@chromium.org | 92a952b | 2010-07-12 18:14:17 +0000 | [diff] [blame] | 2457 | |
darin@apple.com | af8b1a9 | 2011-06-25 00:09:37 +0000 | [diff] [blame] | 2458 | if (documentLoader()) |
commit-queue@webkit.org | 2ca2f77 | 2010-08-17 23:40:00 +0000 | [diff] [blame] | 2459 | documentLoader()->handledOnloadEvents(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | void FrameLoader::frameDetached() |
| 2463 | { |
| 2464 | stopAllLoaders(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2465 | m_frame.document()->stopActiveDOMObjects(); |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2466 | detachFromParent(); |
| 2467 | } |
| 2468 | |
ggaren | c04b2c5 | 2006-11-30 21:06:14 +0000 | [diff] [blame] | 2469 | void FrameLoader::detachFromParent() |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2470 | { |
akling@apple.com | a34e522 | 2013-09-10 03:44:05 +0000 | [diff] [blame] | 2471 | Ref<Frame> protect(m_frame); |
ggaren | c04b2c5 | 2006-11-30 21:06:14 +0000 | [diff] [blame] | 2472 | |
ggaren | acf2874 | 2006-12-27 07:38:18 +0000 | [diff] [blame] | 2473 | closeURL(); |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2474 | history().saveScrollPositionAndViewStateToItem(history().currentItem()); |
ggaren | c04b2c5 | 2006-11-30 21:06:14 +0000 | [diff] [blame] | 2475 | detachChildren(); |
japhet@chromium.org | 7d4347c | 2010-11-03 19:04:41 +0000 | [diff] [blame] | 2476 | // stopAllLoaders() needs to be called after detachChildren(), because detachedChildren() |
| 2477 | // will trigger the unload event handlers of any child frames, and those event |
| 2478 | // handlers might start a new subresource load in this frame. |
| 2479 | stopAllLoaders(); |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 2480 | |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 2481 | InspectorInstrumentation::frameDetachedFromParent(m_frame); |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 2482 | |
beidson@apple.com | 24f92a5 | 2009-09-03 00:07:51 +0000 | [diff] [blame] | 2483 | detachViewsAndDocumentLoader(); |
| 2484 | |
weinig@apple.com | eefc25d | 2013-11-08 22:42:27 +0000 | [diff] [blame] | 2485 | m_progressTracker = nullptr; |
japhet@chromium.org | 7879dd7 | 2012-08-30 02:58:37 +0000 | [diff] [blame] | 2486 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2487 | if (Frame* parent = m_frame.tree().parent()) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2488 | parent->loader().closeAndRemoveChild(&m_frame); |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2489 | parent->loader().scheduleCheckCompleted(); |
weinig | c34c71c | 2007-03-09 16:05:37 +0000 | [diff] [blame] | 2490 | } else { |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 2491 | m_frame.setView(nullptr); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2492 | m_frame.willDetachPage(); |
| 2493 | m_frame.detachFromPage(); |
ddkilzer | 3adeb2f | 2006-12-28 23:33:37 +0000 | [diff] [blame] | 2494 | } |
ggaren | c04b2c5 | 2006-11-30 21:06:14 +0000 | [diff] [blame] | 2495 | } |
beidson@apple.com | 24f92a5 | 2009-09-03 00:07:51 +0000 | [diff] [blame] | 2496 | |
| 2497 | void FrameLoader::detachViewsAndDocumentLoader() |
| 2498 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2499 | m_client.detachedFromParent2(); |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 2500 | setDocumentLoader(nullptr); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2501 | m_client.detachedFromParent3(); |
beidson@apple.com | 24f92a5 | 2009-09-03 00:07:51 +0000 | [diff] [blame] | 2502 | } |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2503 | |
| 2504 | void FrameLoader::addExtraFieldsToSubresourceRequest(ResourceRequest& request) |
| 2505 | { |
jochen@chromium.org | dac140c | 2011-08-01 21:18:49 +0000 | [diff] [blame] | 2506 | addExtraFieldsToRequest(request, m_loadType, false); |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2507 | } |
darin | c370e7e | 2006-11-08 05:52:27 +0000 | [diff] [blame] | 2508 | |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2509 | void FrameLoader::addExtraFieldsToMainResourceRequest(ResourceRequest& request) |
| 2510 | { |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 2511 | // FIXME: Using m_loadType seems wrong for some callers. |
| 2512 | // 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] | 2513 | addExtraFieldsToRequest(request, m_loadType, true); |
antti@apple.com | 4da613e | 2008-12-15 15:28:41 +0000 | [diff] [blame] | 2514 | } |
| 2515 | |
jochen@chromium.org | dac140c | 2011-08-01 21:18:49 +0000 | [diff] [blame] | 2516 | void FrameLoader::addExtraFieldsToRequest(ResourceRequest& request, FrameLoadType loadType, bool mainResource) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2517 | { |
beidson@apple.com | 341a3d8 | 2009-03-03 19:08:56 +0000 | [diff] [blame] | 2518 | // Don't set the cookie policy URL if it's already been set. |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 2519 | // But make sure to set it on all requests regardless of protocol, as it has significance beyond the cookie policy (<rdar://problem/6616664>). |
abarth@webkit.org | 622d9df | 2009-05-22 16:44:47 +0000 | [diff] [blame] | 2520 | if (request.firstPartyForCookies().isEmpty()) { |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 2521 | if (mainResource && m_frame.isMainFrame()) |
abarth@webkit.org | 622d9df | 2009-05-22 16:44:47 +0000 | [diff] [blame] | 2522 | request.setFirstPartyForCookies(request.url()); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2523 | else if (Document* document = m_frame.document()) |
abarth@webkit.org | 622d9df | 2009-05-22 16:44:47 +0000 | [diff] [blame] | 2524 | request.setFirstPartyForCookies(document->firstPartyForCookies()); |
beidson@apple.com | 341a3d8 | 2009-03-03 19:08:56 +0000 | [diff] [blame] | 2525 | } |
abarth@webkit.org | 622d9df | 2009-05-22 16:44:47 +0000 | [diff] [blame] | 2526 | |
beidson@apple.com | 341a3d8 | 2009-03-03 19:08:56 +0000 | [diff] [blame] | 2527 | // The remaining modifications are only necessary for HTTP and HTTPS. |
benjamin@webkit.org | f726d63 | 2012-03-04 03:26:27 +0000 | [diff] [blame] | 2528 | if (!request.url().isEmpty() && !request.url().protocolIsInHTTPFamily()) |
hyatt@apple.com | 0c933b8 | 2009-02-03 23:56:06 +0000 | [diff] [blame] | 2529 | return; |
| 2530 | |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2531 | applyUserAgent(request); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 2532 | |
japhet@chromium.org | f00dffa | 2010-07-16 07:46:22 +0000 | [diff] [blame] | 2533 | if (!mainResource) { |
| 2534 | if (request.isConditional()) |
| 2535 | request.setCachePolicy(ReloadIgnoringCacheData); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 2536 | else if (documentLoader()->isLoadingInAPISense()) { |
| 2537 | // If we inherit cache policy from a main resource, we use the DocumentLoader's |
| 2538 | // original request cache policy for two reasons: |
| 2539 | // 1. For POST requests, we mutate the cache policy for the main resource, |
| 2540 | // but we do not want this to apply to subresources |
| 2541 | // 2. Delegates that modify the cache policy using willSendRequest: should |
| 2542 | // not affect any other resources. Such changes need to be done |
| 2543 | // per request. |
| 2544 | ResourceRequestCachePolicy mainDocumentOriginalCachePolicy = documentLoader()->originalRequest().cachePolicy(); |
| 2545 | // 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. |
| 2546 | // This policy is set on initial request too, but should not be inherited. |
| 2547 | ResourceRequestCachePolicy subresourceCachePolicy = (mainDocumentOriginalCachePolicy == ReturnCacheDataDontLoad) ? ReturnCacheDataElseLoad : mainDocumentOriginalCachePolicy; |
| 2548 | request.setCachePolicy(subresourceCachePolicy); |
| 2549 | } else |
japhet@chromium.org | f00dffa | 2010-07-16 07:46:22 +0000 | [diff] [blame] | 2550 | request.setCachePolicy(UseProtocolCachePolicy); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 2551 | |
| 2552 | // FIXME: Other FrameLoader functions have duplicated code for setting cache policy of main request when reloading. |
| 2553 | // It seems better to manage it explicitly than to hide the logic inside addExtraFieldsToRequest(). |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2554 | } else if (loadType == FrameLoadType::Reload || loadType == FrameLoadType::ReloadFromOrigin || request.isConditional()) |
japhet@chromium.org | 92a952b | 2010-07-12 18:14:17 +0000 | [diff] [blame] | 2555 | request.setCachePolicy(ReloadIgnoringCacheData); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 2556 | |
antti@apple.com | 7c97e2c | 2015-03-19 05:21:40 +0000 | [diff] [blame] | 2557 | if (m_overrideCachePolicyForTesting) |
| 2558 | request.setCachePolicy(m_overrideCachePolicyForTesting.value()); |
antti@apple.com | 1229ead | 2015-03-30 21:09:14 +0000 | [diff] [blame] | 2559 | if (m_overrideResourceLoadPriorityForTesting) |
| 2560 | request.setPriority(m_overrideResourceLoadPriorityForTesting.value()); |
antti@apple.com | 7c97e2c | 2015-03-19 05:21:40 +0000 | [diff] [blame] | 2561 | |
japhet@chromium.org | 1e31314 | 2010-08-31 22:53:31 +0000 | [diff] [blame] | 2562 | if (request.cachePolicy() == ReloadIgnoringCacheData) { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2563 | if (loadType == FrameLoadType::Reload) |
andersca@apple.com | a96cf71 | 2014-06-14 17:49:44 +0000 | [diff] [blame] | 2564 | request.setHTTPHeaderField(HTTPHeaderName::CacheControl, "max-age=0"); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2565 | else if (loadType == FrameLoadType::ReloadFromOrigin) { |
andersca@apple.com | a96cf71 | 2014-06-14 17:49:44 +0000 | [diff] [blame] | 2566 | request.setHTTPHeaderField(HTTPHeaderName::CacheControl, "no-cache"); |
| 2567 | request.setHTTPHeaderField(HTTPHeaderName::Pragma, "no-cache"); |
japhet@chromium.org | 1e31314 | 2010-08-31 22:53:31 +0000 | [diff] [blame] | 2568 | } |
| 2569 | } |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2570 | |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2571 | if (mainResource) |
staikos@webkit.org | 159f11f | 2009-05-18 23:48:30 +0000 | [diff] [blame] | 2572 | request.setHTTPAccept(defaultAcceptHeader); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 2573 | |
| 2574 | // Make sure we send the Origin header. |
| 2575 | addHTTPOriginIfNeeded(request, String()); |
ap@webkit.org | 113cb8c | 2008-12-05 14:43:53 +0000 | [diff] [blame] | 2576 | |
ap@apple.com | 9454f7c | 2013-06-20 20:06:02 +0000 | [diff] [blame] | 2577 | // Only set fallback array if it's still empty (later attempts may be incorrect, see bug 117818). |
| 2578 | if (request.responseContentDispositionEncodingFallbackArray().isEmpty()) { |
| 2579 | // 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] | 2580 | 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] | 2581 | } |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 2582 | } |
| 2583 | |
tony@chromium.org | c1443b7 | 2011-06-24 22:05:16 +0000 | [diff] [blame] | 2584 | void FrameLoader::addHTTPOriginIfNeeded(ResourceRequest& request, const String& origin) |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 2585 | { |
| 2586 | if (!request.httpOrigin().isEmpty()) |
| 2587 | return; // Request already has an Origin header. |
| 2588 | |
| 2589 | // Don't send an Origin header for GET or HEAD to avoid privacy issues. |
| 2590 | // For example, if an intranet page has a hyperlink to an external web |
| 2591 | // site, we don't want to include the Origin of the request because it |
| 2592 | // will leak the internal host name. Similar privacy concerns have lead |
| 2593 | // to the widespread suppression of the Referer header at the network |
| 2594 | // layer. |
| 2595 | if (request.httpMethod() == "GET" || request.httpMethod() == "HEAD") |
| 2596 | return; |
| 2597 | |
| 2598 | // For non-GET and non-HEAD methods, always send an Origin header so the |
| 2599 | // server knows we support this feature. |
| 2600 | |
| 2601 | if (origin.isEmpty()) { |
| 2602 | // If we don't know what origin header to attach, we attach the value |
| 2603 | // for an empty origin. |
abarth@webkit.org | 29f0c1a | 2011-11-05 01:32:07 +0000 | [diff] [blame] | 2604 | request.setHTTPOrigin(SecurityOrigin::createUnique()->toString()); |
tony@chromium.org | c1443b7 | 2011-06-24 22:05:16 +0000 | [diff] [blame] | 2605 | return; |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | request.setHTTPOrigin(origin); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 2609 | } |
| 2610 | |
beidson@apple.com | dab0572 | 2015-05-31 05:53:06 +0000 | [diff] [blame] | 2611 | void FrameLoader::loadPostRequest(const FrameLoadRequest& request, const String& referrer, FrameLoadType loadType, Event* event, PassRefPtr<FormState> prpFormState) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2612 | { |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 2613 | RefPtr<FormState> formState = prpFormState; |
| 2614 | |
beidson@apple.com | bd66a78 | 2015-05-29 16:31:49 +0000 | [diff] [blame] | 2615 | String frameName = request.frameName(); |
| 2616 | LockHistory lockHistory = request.lockHistory(); |
| 2617 | AllowNavigationToInvalidURL allowNavigationToInvalidURL = request.allowNavigationToInvalidURL(); |
| 2618 | NewFrameOpenerPolicy openerPolicy = request.newFrameOpenerPolicy(); |
| 2619 | |
| 2620 | const ResourceRequest& inRequest = request.resourceRequest(); |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2621 | const URL& url = inRequest.url(); |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 2622 | RefPtr<FormData> formData = inRequest.httpBody(); |
| 2623 | const String& contentType = inRequest.httpContentType(); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 2624 | String origin = inRequest.httpOrigin(); |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 2625 | |
| 2626 | ResourceRequest workingResourceRequest(url); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2627 | |
| 2628 | if (!referrer.isEmpty()) |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 2629 | workingResourceRequest.setHTTPReferrer(referrer); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 2630 | workingResourceRequest.setHTTPOrigin(origin); |
mrowe@apple.com | 713db2e | 2008-07-27 03:49:29 +0000 | [diff] [blame] | 2631 | workingResourceRequest.setHTTPMethod("POST"); |
| 2632 | workingResourceRequest.setHTTPBody(formData); |
| 2633 | workingResourceRequest.setHTTPContentType(contentType); |
jochen@chromium.org | dac140c | 2011-08-01 21:18:49 +0000 | [diff] [blame] | 2634 | addExtraFieldsToRequest(workingResourceRequest, loadType, true); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2635 | |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 2636 | NavigationAction action(workingResourceRequest, loadType, true, event, request.shouldOpenExternalURLsPolicy()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2637 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2638 | if (!frameName.isEmpty()) { |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 2639 | // The search for a target frame is done earlier in the case of form submission. |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 2640 | if (Frame* targetFrame = formState ? 0 : findFrameForNavigation(frameName)) { |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 2641 | targetFrame->loader().loadWithNavigationAction(workingResourceRequest, action, lockHistory, loadType, formState.release(), allowNavigationToInvalidURL); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 2642 | return; |
darin@chromium.org | 1e25ab7 | 2012-04-02 20:14:07 +0000 | [diff] [blame] | 2643 | } |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 2644 | |
ap@apple.com | a383f25 | 2015-02-14 18:16:00 +0000 | [diff] [blame] | 2645 | policyChecker().checkNewWindowPolicy(action, workingResourceRequest, formState.release(), frameName, [this, allowNavigationToInvalidURL, openerPolicy](const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName, const NavigationAction& action, bool shouldContinue) { |
| 2646 | continueLoadAfterNewWindowPolicy(request, formState, frameName, action, shouldContinue, allowNavigationToInvalidURL, openerPolicy); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 2647 | }); |
| 2648 | return; |
| 2649 | } |
| 2650 | |
| 2651 | // must grab this now, since this load may stop the previous load and clear this flag |
| 2652 | bool isRedirect = m_quickRedirectComing; |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 2653 | loadWithNavigationAction(workingResourceRequest, action, lockHistory, loadType, formState.release(), allowNavigationToInvalidURL); |
andersca@apple.com | 096333f | 2013-11-07 21:37:36 +0000 | [diff] [blame] | 2654 | if (isRedirect) { |
| 2655 | m_quickRedirectComing = false; |
| 2656 | if (m_provisionalDocumentLoader) |
| 2657 | m_provisionalDocumentLoader->setIsClientRedirect(true); |
darin@chromium.org | 1e25ab7 | 2012-04-02 20:14:07 +0000 | [diff] [blame] | 2658 | } |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2659 | } |
| 2660 | |
youenn.fablet@crf.canon.fr | 0aef67f | 2015-04-29 08:18:10 +0000 | [diff] [blame] | 2661 | unsigned long FrameLoader::loadResourceSynchronously(const ResourceRequest& request, StoredCredentials storedCredentials, ClientCredentialPolicy clientCredentialPolicy, ResourceError& error, ResourceResponse& response, RefPtr<SharedBuffer>& data) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2662 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2663 | ASSERT(m_frame.document()); |
| 2664 | String referrer = SecurityPolicy::generateReferrerHeader(m_frame.document()->referrerPolicy(), request.url(), outgoingReferrer()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2665 | |
| 2666 | ResourceRequest initialRequest = request; |
| 2667 | initialRequest.setTimeoutInterval(10); |
| 2668 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2669 | if (!referrer.isEmpty()) |
| 2670 | initialRequest.setHTTPReferrer(referrer); |
abarth@webkit.org | fb07438 | 2008-10-05 19:12:30 +0000 | [diff] [blame] | 2671 | addHTTPOriginIfNeeded(initialRequest, outgoingOrigin()); |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 2672 | |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 2673 | initialRequest.setFirstPartyForCookies(m_frame.mainFrame().loader().documentLoader()->request().url()); |
japhet@chromium.org | 92a952b | 2010-07-12 18:14:17 +0000 | [diff] [blame] | 2674 | |
| 2675 | addExtraFieldsToSubresourceRequest(initialRequest); |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 2676 | |
andersca | ec429f5 | 2007-01-13 01:44:24 +0000 | [diff] [blame] | 2677 | unsigned long identifier = 0; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2678 | ResourceRequest newRequest(initialRequest); |
| 2679 | requestFromDelegate(newRequest, identifier, error); |
| 2680 | |
beidson@apple.com | e3ea01d | 2015-07-02 18:33:23 +0000 | [diff] [blame] | 2681 | #if ENABLE(CONTENT_EXTENSIONS) |
| 2682 | if (error.isNull()) { |
commit-queue@webkit.org | 8090ccb | 2015-10-06 08:18:08 +0000 | [diff] [blame] | 2683 | if (auto* page = m_frame.page()) { |
| 2684 | if (auto* controller = page->userContentController()) { |
| 2685 | if (m_documentLoader && controller->processContentExtensionRulesForLoad(newRequest, ResourceType::Raw, *m_documentLoader) == ContentExtensions::BlockedStatus::Blocked) { |
| 2686 | newRequest = { }; |
| 2687 | error = ResourceError(errorDomainWebKitInternal, 0, initialRequest.url().string(), emptyString()); |
| 2688 | response = { }; |
| 2689 | data = nullptr; |
| 2690 | } |
beidson@apple.com | e3ea01d | 2015-07-02 18:33:23 +0000 | [diff] [blame] | 2691 | } |
| 2692 | } |
beidson@apple.com | e3ea01d | 2015-07-02 18:33:23 +0000 | [diff] [blame] | 2693 | } |
| 2694 | #endif |
| 2695 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2696 | if (error.isNull()) { |
| 2697 | ASSERT(!newRequest.isNull()); |
youenn.fablet@crf.canon.fr | 0aef67f | 2015-04-29 08:18:10 +0000 | [diff] [blame] | 2698 | |
darin@chromium.org | 6042aea | 2009-07-30 23:08:33 +0000 | [diff] [blame] | 2699 | if (!documentLoader()->applicationCacheHost()->maybeLoadSynchronously(newRequest, error, response, data)) { |
youenn.fablet@crf.canon.fr | 0aef67f | 2015-04-29 08:18:10 +0000 | [diff] [blame] | 2700 | Vector<char> buffer; |
| 2701 | platformStrategies()->loaderStrategy()->loadResourceSynchronously(networkingContext(), identifier, newRequest, storedCredentials, clientCredentialPolicy, error, response, buffer); |
| 2702 | data = SharedBuffer::adoptVector(buffer); |
darin@chromium.org | 6042aea | 2009-07-30 23:08:33 +0000 | [diff] [blame] | 2703 | documentLoader()->applicationCacheHost()->maybeLoadFallbackSynchronously(newRequest, error, response, data); |
ap@webkit.org | fb96f8a | 2009-01-02 09:25:02 +0000 | [diff] [blame] | 2704 | } |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2705 | } |
youenn.fablet@crf.canon.fr | 0aef67f | 2015-04-29 08:18:10 +0000 | [diff] [blame] | 2706 | 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] | 2707 | return identifier; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2708 | } |
| 2709 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2710 | const ResourceRequest& FrameLoader::originalRequest() const |
| 2711 | { |
| 2712 | return activeDocumentLoader()->originalRequestCopy(); |
| 2713 | } |
| 2714 | |
japhet@chromium.org | 7f7bee4 | 2012-03-29 23:17:09 +0000 | [diff] [blame] | 2715 | void FrameLoader::receivedMainResourceError(const ResourceError& error) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2716 | { |
| 2717 | // Retain because the stop may release the last reference to it. |
akling@apple.com | f851598 | 2013-09-02 18:50:01 +0000 | [diff] [blame] | 2718 | Ref<Frame> protect(m_frame); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2719 | |
| 2720 | RefPtr<DocumentLoader> loader = activeDocumentLoader(); |
japhet@chromium.org | 7f7bee4 | 2012-03-29 23:17:09 +0000 | [diff] [blame] | 2721 | // FIXME: Don't want to do this if an entirely new load is going, so should check |
| 2722 | // that both data sources on the frame are either this or nil. |
| 2723 | stop(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2724 | if (m_client.shouldFallBack(error)) |
japhet@chromium.org | 7f7bee4 | 2012-03-29 23:17:09 +0000 | [diff] [blame] | 2725 | handleFallbackContent(); |
abarth@webkit.org | 1c893f4 | 2009-10-10 02:27:21 +0000 | [diff] [blame] | 2726 | |
lars | 8bf288d | 2007-10-04 08:45:12 +0000 | [diff] [blame] | 2727 | if (m_state == FrameStateProvisional && m_provisionalDocumentLoader) { |
darin@apple.com | 4cd1b24 | 2009-03-27 23:37:46 +0000 | [diff] [blame] | 2728 | if (m_submittedFormURL == m_provisionalDocumentLoader->originalRequestCopy().url()) |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2729 | m_submittedFormURL = URL(); |
antti | ac25cb4 | 2007-03-02 07:59:15 +0000 | [diff] [blame] | 2730 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2731 | // We might have made a page cache item, but now we're bailing out due to an error before we ever |
| 2732 | // transitioned to the new page (before WebFrameState == commit). The goal here is to restore any state |
| 2733 | // 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] | 2734 | history().invalidateCurrentItemCachedPage(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2735 | |
| 2736 | // Call clientRedirectCancelledOrFinished here so that the frame load delegate is notified that the redirect's |
| 2737 | // status has changed, if there was a redirect. The frame load delegate may have saved some state about |
| 2738 | // the redirect in its -webView:willPerformClientRedirectToURL:delay:fireDate:forFrame:. Since we are definitely |
| 2739 | // not going to use this provisional resource, as it was cancelled, notify the frame load delegate that the redirect |
| 2740 | // has ended. |
| 2741 | if (m_sentRedirectNotification) |
| 2742 | clientRedirectCancelledOrFinished(false); |
| 2743 | } |
abarth@webkit.org | 1c893f4 | 2009-10-10 02:27:21 +0000 | [diff] [blame] | 2744 | |
japhet@chromium.org | 7f7bee4 | 2012-03-29 23:17:09 +0000 | [diff] [blame] | 2745 | checkCompleted(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2746 | if (m_frame.page()) |
japhet@chromium.org | 7f7bee4 | 2012-03-29 23:17:09 +0000 | [diff] [blame] | 2747 | checkLoadComplete(); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2748 | } |
| 2749 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2750 | void FrameLoader::continueFragmentScrollAfterNavigationPolicy(const ResourceRequest& request, bool shouldContinue) |
| 2751 | { |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2752 | m_quickRedirectComing = false; |
darin | 4e5519d | 2007-01-22 02:46:06 +0000 | [diff] [blame] | 2753 | |
| 2754 | if (!shouldContinue) |
| 2755 | return; |
| 2756 | |
mihaip@chromium.org | d5123ba | 2011-09-16 02:16:46 +0000 | [diff] [blame] | 2757 | // If we have a provisional request for a different document, a fragment scroll should cancel it. |
| 2758 | if (m_provisionalDocumentLoader && !equalIgnoringFragmentIdentifier(m_provisionalDocumentLoader->request().url(), request.url())) { |
| 2759 | m_provisionalDocumentLoader->stopLoading(); |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 2760 | setProvisionalDocumentLoader(nullptr); |
mihaip@chromium.org | d5123ba | 2011-09-16 02:16:46 +0000 | [diff] [blame] | 2761 | } |
| 2762 | |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2763 | bool isRedirect = m_quickRedirectComing || policyChecker().loadType() == FrameLoadType::RedirectWithLockedBackForwardList; |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 2764 | loadInSameDocument(request.url(), 0, !isRedirect); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2765 | } |
| 2766 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2767 | 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] | 2768 | { |
yael.aharon@nokia.com | 79f6905 | 2010-12-30 19:31:00 +0000 | [diff] [blame] | 2769 | // 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] | 2770 | // currently displaying a frameset, or if the URL does not have a fragment. |
| 2771 | // These rules were originally based on what KHTML was doing in KHTMLPart::openURL. |
| 2772 | |
| 2773 | // FIXME: What about load types other than Standard and Reload? |
| 2774 | |
yael.aharon@nokia.com | 79f6905 | 2010-12-30 19:31:00 +0000 | [diff] [blame] | 2775 | return (!isFormSubmission || equalIgnoringCase(httpMethod, "GET")) |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 2776 | && loadType != FrameLoadType::Reload |
| 2777 | && loadType != FrameLoadType::ReloadFromOrigin |
| 2778 | && loadType != FrameLoadType::Same |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2779 | && !shouldReload(m_frame.document()->url(), url) |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 2780 | // We don't want to just scroll if a link from within a |
| 2781 | // frameset is trying to reload the frameset into _top. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2782 | && !m_frame.document()->isFrameSet(); |
ddkilzer@apple.com | 8c272a8 | 2008-07-12 21:33:52 +0000 | [diff] [blame] | 2783 | } |
| 2784 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2785 | void FrameLoader::scrollToFragmentWithParentBoundary(const URL& url) |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 2786 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2787 | FrameView* view = m_frame.view(); |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 2788 | if (!view) |
| 2789 | return; |
| 2790 | |
| 2791 | // Leaking scroll position to a cross-origin ancestor would permit the so-called "framesniffing" attack. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2792 | RefPtr<Frame> boundaryFrame(url.hasFragmentIdentifier() ? m_frame.document()->findUnsafeParentScrollPropagationBoundary() : 0); |
tsepez@chromium.org | 8d3c2c1 | 2012-04-17 19:03:42 +0000 | [diff] [blame] | 2793 | |
| 2794 | if (boundaryFrame) |
| 2795 | boundaryFrame->view()->setSafeToPropagateScrollToParent(false); |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 2796 | |
| 2797 | view->scrollToFragment(url); |
tsepez@chromium.org | 8d3c2c1 | 2012-04-17 19:03:42 +0000 | [diff] [blame] | 2798 | |
| 2799 | if (boundaryFrame) |
| 2800 | boundaryFrame->view()->setSafeToPropagateScrollToParent(true); |
tsepez@chromium.org | f896056 | 2012-04-06 22:15:02 +0000 | [diff] [blame] | 2801 | } |
| 2802 | |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 2803 | bool FrameLoader::shouldClose() |
| 2804 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2805 | Page* page = m_frame.page(); |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 2806 | if (!page) |
| 2807 | return true; |
| 2808 | if (!page->chrome().canRunBeforeUnloadConfirmPanel()) |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 2809 | return true; |
| 2810 | |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 2811 | // 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] | 2812 | Vector<Ref<Frame>, 16> targetFrames; |
| 2813 | targetFrames.append(m_frame); |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2814 | 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] | 2815 | targetFrames.append(*child); |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 2816 | |
| 2817 | bool shouldClose = false; |
| 2818 | { |
| 2819 | NavigationDisablerForBeforeUnload navigationDisabler; |
| 2820 | size_t i; |
| 2821 | |
| 2822 | for (i = 0; i < targetFrames.size(); i++) { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2823 | if (!targetFrames[i]->tree().isDescendantOf(&m_frame)) |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 2824 | continue; |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2825 | if (!targetFrames[i]->loader().handleBeforeUnloadEvent(page->chrome(), this)) |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 2826 | break; |
| 2827 | } |
| 2828 | |
| 2829 | if (i == targetFrames.size()) |
| 2830 | shouldClose = true; |
| 2831 | } |
| 2832 | |
aestes@apple.com | c7f1761 | 2011-08-12 19:56:56 +0000 | [diff] [blame] | 2833 | if (!shouldClose) |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 2834 | m_submittedFormURL = URL(); |
aestes@apple.com | c7f1761 | 2011-08-12 19:56:56 +0000 | [diff] [blame] | 2835 | |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 2836 | m_currentNavigationHasShownBeforeUnloadConfirmPanel = false; |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 2837 | return shouldClose; |
| 2838 | } |
| 2839 | |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame^] | 2840 | void FrameLoader::handleUnloadEvents(UnloadEventPolicy unloadEventPolicy) |
| 2841 | { |
| 2842 | if (!m_frame.document()) |
| 2843 | return; |
| 2844 | |
| 2845 | // We store the frame's page in a local variable because the frame might get detached inside dispatchEvent. |
| 2846 | ForbidPromptsScope forbidPrompts(m_frame.page()); |
| 2847 | |
| 2848 | if (m_didCallImplicitClose && !m_wasUnloadEventEmitted) { |
| 2849 | auto* currentFocusedElement = m_frame.document()->focusedElement(); |
| 2850 | if (is<HTMLInputElement>(currentFocusedElement)) |
| 2851 | downcast<HTMLInputElement>(*currentFocusedElement).endEditing(); |
| 2852 | if (m_pageDismissalEventBeingDispatched == PageDismissalType::None) { |
| 2853 | if (unloadEventPolicy == UnloadEventPolicyUnloadAndPageHide) { |
| 2854 | m_pageDismissalEventBeingDispatched = PageDismissalType::PageHide; |
| 2855 | m_frame.document()->domWindow()->dispatchEvent(PageTransitionEvent::create(eventNames().pagehideEvent, m_frame.document()->inPageCache()), m_frame.document()); |
| 2856 | } |
| 2857 | |
| 2858 | // FIXME: update Page Visibility state here. |
| 2859 | // https://bugs.webkit.org/show_bug.cgi?id=116770 |
| 2860 | |
| 2861 | if (!m_frame.document()->inPageCache()) { |
| 2862 | RefPtr<Event> unloadEvent(Event::create(eventNames().unloadEvent, false, false)); |
| 2863 | // The DocumentLoader (and thus its DocumentLoadTiming) might get destroyed |
| 2864 | // while dispatching the event, so protect it to prevent writing the end |
| 2865 | // time into freed memory. |
| 2866 | RefPtr<DocumentLoader> documentLoader = m_provisionalDocumentLoader; |
| 2867 | m_pageDismissalEventBeingDispatched = PageDismissalType::Unload; |
| 2868 | if (documentLoader && documentLoader->timing().navigationStart() && !documentLoader->timing().unloadEventStart() && !documentLoader->timing().unloadEventEnd()) { |
| 2869 | auto& timing = documentLoader->timing(); |
| 2870 | timing.markUnloadEventStart(); |
| 2871 | m_frame.document()->domWindow()->dispatchEvent(unloadEvent, m_frame.document()); |
| 2872 | timing.markUnloadEventEnd(); |
| 2873 | } else |
| 2874 | m_frame.document()->domWindow()->dispatchEvent(unloadEvent, m_frame.document()); |
| 2875 | } |
| 2876 | } |
| 2877 | m_pageDismissalEventBeingDispatched = PageDismissalType::None; |
| 2878 | if (m_frame.document()) |
| 2879 | m_frame.document()->updateStyleIfNeeded(); |
| 2880 | m_wasUnloadEventEmitted = true; |
| 2881 | } |
| 2882 | |
| 2883 | // Dispatching the unload event could have made m_frame.document() null. |
| 2884 | if (!m_frame.document()) |
| 2885 | return; |
| 2886 | |
| 2887 | if (m_frame.document()->inPageCache()) |
| 2888 | return; |
| 2889 | |
| 2890 | // Don't remove event listeners from a transitional empty document (see bug 28716 for more information). |
| 2891 | bool keepEventListeners = m_stateMachine.isDisplayingInitialEmptyDocument() && m_provisionalDocumentLoader |
| 2892 | && m_frame.document()->isSecureTransitionTo(m_provisionalDocumentLoader->url()); |
| 2893 | |
| 2894 | if (!keepEventListeners) |
| 2895 | m_frame.document()->removeAllEventListeners(); |
| 2896 | } |
| 2897 | |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 2898 | bool FrameLoader::handleBeforeUnloadEvent(Chrome& chrome, FrameLoader* frameLoaderBeingNavigated) |
rniwa@webkit.org | cf46007 | 2011-01-08 02:15:10 +0000 | [diff] [blame] | 2899 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2900 | DOMWindow* domWindow = m_frame.document()->domWindow(); |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 2901 | if (!domWindow) |
| 2902 | return true; |
| 2903 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2904 | RefPtr<Document> document = m_frame.document(); |
cdumez@apple.com | f978083 | 2015-01-27 00:26:21 +0000 | [diff] [blame] | 2905 | if (!document->bodyOrFrameset()) |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 2906 | return true; |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 2907 | |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 2908 | RefPtr<BeforeUnloadEvent> beforeUnloadEvent = BeforeUnloadEvent::create(); |
cdumez@apple.com | 83847a9 | 2015-06-26 18:26:19 +0000 | [diff] [blame] | 2909 | m_pageDismissalEventBeingDispatched = PageDismissalType::BeforeUnload; |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 2910 | |
ggaren@apple.com | fe41e1b | 2015-11-10 22:19:44 +0000 | [diff] [blame^] | 2911 | { |
| 2912 | ForbidPromptsScope forbidPrompts(m_frame.page()); |
| 2913 | domWindow->dispatchEvent(beforeUnloadEvent.get(), domWindow->document()); |
| 2914 | } |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 2915 | |
cdumez@apple.com | 83847a9 | 2015-06-26 18:26:19 +0000 | [diff] [blame] | 2916 | m_pageDismissalEventBeingDispatched = PageDismissalType::None; |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 2917 | |
| 2918 | if (!beforeUnloadEvent->defaultPrevented()) |
| 2919 | document->defaultEventHandler(beforeUnloadEvent.get()); |
ch.dumez@sisa.samsung.com | 231386f | 2013-09-09 18:40:04 +0000 | [diff] [blame] | 2920 | if (beforeUnloadEvent->returnValue().isNull()) |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 2921 | return true; |
| 2922 | |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 2923 | // If the navigating FrameLoader has already shown a beforeunload confirmation panel for the current navigation attempt, |
| 2924 | // this frame is not allowed to cause another one to be shown. |
| 2925 | if (frameLoaderBeingNavigated->m_currentNavigationHasShownBeforeUnloadConfirmPanel) { |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 2926 | document->addConsoleMessage(MessageSource::JS, MessageLevel::Error, ASCIILiteral("Blocked attempt to show multiple beforeunload confirmation dialogs for the same navigation.")); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 2927 | return true; |
| 2928 | } |
| 2929 | |
| 2930 | // We should only display the beforeunload dialog for an iframe if its SecurityOrigin matches all |
| 2931 | // ancestor frame SecurityOrigins up through the navigating FrameLoader. |
| 2932 | if (frameLoaderBeingNavigated != this) { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2933 | Frame* parentFrame = m_frame.tree().parent(); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 2934 | while (parentFrame) { |
| 2935 | Document* parentDocument = parentFrame->document(); |
| 2936 | if (!parentDocument) |
| 2937 | return true; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2938 | if (!m_frame.document() || !m_frame.document()->securityOrigin()->canAccess(parentDocument->securityOrigin())) { |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 2939 | document->addConsoleMessage(MessageSource::JS, MessageLevel::Error, ASCIILiteral("Blocked attempt to show beforeunload confirmation dialog on behalf of a frame with different security origin. Protocols, domains, and ports must match.")); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 2940 | return true; |
| 2941 | } |
| 2942 | |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2943 | if (&parentFrame->loader() == frameLoaderBeingNavigated) |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 2944 | break; |
| 2945 | |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 2946 | parentFrame = parentFrame->tree().parent(); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | // The navigatingFrameLoader should always be in our ancestory. |
| 2950 | ASSERT(parentFrame); |
andersca@apple.com | df550b9 | 2013-08-15 22:17:17 +0000 | [diff] [blame] | 2951 | ASSERT(&parentFrame->loader() == frameLoaderBeingNavigated); |
beidson@apple.com | 1390a81 | 2013-07-20 06:43:51 +0000 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | frameLoaderBeingNavigated->m_currentNavigationHasShownBeforeUnloadConfirmPanel = true; |
| 2955 | |
ch.dumez@sisa.samsung.com | 231386f | 2013-09-09 18:40:04 +0000 | [diff] [blame] | 2956 | String text = document->displayStringModifiedByEncoding(beforeUnloadEvent->returnValue()); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2957 | return chrome.runBeforeUnloadConfirmPanel(text, &m_frame); |
beidson@apple.com | 7617ce7 | 2010-05-13 20:31:46 +0000 | [diff] [blame] | 2958 | } |
| 2959 | |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 2960 | void FrameLoader::continueLoadAfterNavigationPolicy(const ResourceRequest& request, PassRefPtr<FormState> formState, bool shouldContinue, AllowNavigationToInvalidURL allowNavigationToInvalidURL) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2961 | { |
| 2962 | // If we loaded an alternate page to replace an unreachableURL, we'll get in here with a |
| 2963 | // nil policyDataSource because loading the alternate page will have passed |
| 2964 | // through this method already, nested; otherwise, policyDataSource should still be set. |
| 2965 | ASSERT(m_policyDocumentLoader || !m_provisionalDocumentLoader->unreachableURL().isEmpty()); |
| 2966 | |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 2967 | bool isTargetItem = history().provisionalItem() ? history().provisionalItem()->isTargetItem() : false; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2968 | |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 2969 | bool urlIsDisallowed = allowNavigationToInvalidURL == AllowNavigationToInvalidURL::No && !request.url().isValid(); |
| 2970 | |
| 2971 | // Three reasons we can't continue: |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2972 | // 1) Navigation policy delegate said we can't so request is nil. A primary case of this |
| 2973 | // is the user responding Cancel to the form repost nag sheet. |
| 2974 | // 2) User responded Cancel to an alert popped up by the before unload event handler. |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 2975 | // 3) The request's URL is invalid and navigation to invalid URLs is disallowed. |
| 2976 | bool canContinue = shouldContinue && shouldClose() && !urlIsDisallowed; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2977 | |
| 2978 | if (!canContinue) { |
| 2979 | // If we were waiting for a quick redirect, but the policy delegate decided to ignore it, then we |
| 2980 | // need to report that the client redirect was cancelled. |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 2981 | // FIXME: The client should be told about ignored non-quick redirects, too. |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2982 | if (m_quickRedirectComing) |
| 2983 | clientRedirectCancelledOrFinished(false); |
| 2984 | |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 2985 | setPolicyDocumentLoader(nullptr); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2986 | |
| 2987 | // If the navigation request came from the back/forward menu, and we punt on it, we have the |
| 2988 | // problem that we have optimistically moved the b/f cursor already, so move it back. For sanity, |
| 2989 | // 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] | 2990 | if ((isTargetItem || m_frame.isMainFrame()) && isBackForwardLoadType(policyChecker().loadType())) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2991 | if (Page* page = m_frame.page()) { |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 2992 | if (HistoryItem* resetItem = m_frame.mainFrame().loader().history().currentItem()) { |
akling@apple.com | 31cf009 | 2013-09-11 15:24:45 +0000 | [diff] [blame] | 2993 | page->backForward().setCurrentItem(resetItem); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 2994 | m_frame.loader().client().updateGlobalHistoryItemForPage(); |
mitz@apple.com | bc84376 | 2008-12-08 21:18:11 +0000 | [diff] [blame] | 2995 | } |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 2996 | } |
andersca@apple.com | b85d674 | 2011-03-04 03:21:07 +0000 | [diff] [blame] | 2997 | } |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 2998 | return; |
| 2999 | } |
| 3000 | |
akling@apple.com | 24f4d6c | 2013-09-08 08:17:10 +0000 | [diff] [blame] | 3001 | FrameLoadType type = policyChecker().loadType(); |
commit-queue@webkit.org | 987fd77 | 2011-01-21 18:26:42 +0000 | [diff] [blame] | 3002 | // 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] | 3003 | stopAllLoaders(ShouldNotClearProvisionalItem); |
beidson@apple.com | c90a442 | 2008-10-09 20:43:24 +0000 | [diff] [blame] | 3004 | |
| 3005 | // <rdar://problem/6250856> - In certain circumstances on pages with multiple frames, stopAllLoaders() |
| 3006 | // might detach the current FrameLoader, in which case we should bail on this newly defunct load. |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3007 | if (!m_frame.page()) |
beidson@apple.com | c90a442 | 2008-10-09 20:43:24 +0000 | [diff] [blame] | 3008 | return; |
timothy@apple.com | 8f20734 | 2009-04-11 05:31:05 +0000 | [diff] [blame] | 3009 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3010 | setProvisionalDocumentLoader(m_policyDocumentLoader.get()); |
| 3011 | m_loadType = type; |
| 3012 | setState(FrameStateProvisional); |
| 3013 | |
hs85.jeong@samsung.com | 1317914 | 2015-10-21 02:12:32 +0000 | [diff] [blame] | 3014 | setPolicyDocumentLoader(nullptr); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3015 | |
cdumez@apple.com | 2574377 | 2015-08-17 22:57:27 +0000 | [diff] [blame] | 3016 | if (isBackForwardLoadType(type)) { |
| 3017 | auto& diagnosticLoggingClient = m_frame.mainFrame().diagnosticLoggingClient(); |
| 3018 | if (history().provisionalItem()->isInPageCache()) { |
| 3019 | diagnosticLoggingClient.logDiagnosticMessageWithResult(DiagnosticLoggingKeys::pageCacheKey(), DiagnosticLoggingKeys::retrievalKey(), DiagnosticLoggingResultPass, ShouldSample::Yes); |
| 3020 | loadProvisionalItemFromCachedPage(); |
| 3021 | return; |
| 3022 | } |
| 3023 | diagnosticLoggingClient.logDiagnosticMessageWithResult(DiagnosticLoggingKeys::pageCacheKey(), DiagnosticLoggingKeys::retrievalKey(), DiagnosticLoggingResultFail, ShouldSample::Yes); |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 3024 | } |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3025 | |
andersca@apple.com | 61e3332 | 2013-10-05 04:52:04 +0000 | [diff] [blame] | 3026 | if (!formState) { |
beidson | b72fe2e | 2007-05-03 21:35:24 +0000 | [diff] [blame] | 3027 | continueLoadAfterWillSubmitForm(); |
andersca@apple.com | 61e3332 | 2013-10-05 04:52:04 +0000 | [diff] [blame] | 3028 | return; |
| 3029 | } |
| 3030 | |
| 3031 | m_client.dispatchWillSubmitForm(formState, [this](PolicyAction action) { |
| 3032 | policyChecker().continueLoadAfterWillSubmitForm(action); |
| 3033 | }); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3034 | } |
| 3035 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3036 | void FrameLoader::continueLoadAfterNewWindowPolicy(const ResourceRequest& request, |
ap@apple.com | a383f25 | 2015-02-14 18:16:00 +0000 | [diff] [blame] | 3037 | PassRefPtr<FormState> formState, const String& frameName, const NavigationAction& action, bool shouldContinue, AllowNavigationToInvalidURL allowNavigationToInvalidURL, NewFrameOpenerPolicy openerPolicy) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3038 | { |
| 3039 | if (!shouldContinue) |
| 3040 | return; |
| 3041 | |
akling@apple.com | 55cde01 | 2013-10-05 00:35:12 +0000 | [diff] [blame] | 3042 | Ref<Frame> frame(m_frame); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3043 | RefPtr<Frame> mainFrame = m_client.dispatchCreatePage(action); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3044 | if (!mainFrame) |
| 3045 | return; |
| 3046 | |
mjs | c946c5e | 2007-01-31 05:45:47 +0000 | [diff] [blame] | 3047 | if (frameName != "_blank") |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3048 | mainFrame->tree().setName(frameName); |
kmccullo | 1f90121 | 2007-05-16 20:57:47 +0000 | [diff] [blame] | 3049 | |
eric@webkit.org | 5aee676 | 2009-10-06 18:20:33 +0000 | [diff] [blame] | 3050 | mainFrame->page()->setOpenedByDOM(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3051 | mainFrame->loader().m_client.dispatchShow(); |
ap@apple.com | a383f25 | 2015-02-14 18:16:00 +0000 | [diff] [blame] | 3052 | if (openerPolicy == NewFrameOpenerPolicy::Allow) { |
cdumez@apple.com | 7814173 | 2014-11-04 23:00:48 +0000 | [diff] [blame] | 3053 | mainFrame->loader().setOpener(frame.ptr()); |
jochen@chromium.org | 235ee97 | 2012-05-09 22:13:12 +0000 | [diff] [blame] | 3054 | mainFrame->document()->setReferrerPolicy(frame->document()->referrerPolicy()); |
| 3055 | } |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 3056 | |
| 3057 | NavigationAction newAction(request, action.shouldOpenExternalURLsPolicy()); |
| 3058 | mainFrame->loader().loadWithNavigationAction(request, newAction, LockHistory::No, FrameLoadType::Standard, formState, allowNavigationToInvalidURL); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3059 | } |
| 3060 | |
andersca | ec429f5 | 2007-01-13 01:44:24 +0000 | [diff] [blame] | 3061 | void FrameLoader::requestFromDelegate(ResourceRequest& request, unsigned long& identifier, ResourceError& error) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3062 | { |
| 3063 | ASSERT(!request.isNull()); |
| 3064 | |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 3065 | identifier = 0; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3066 | if (Page* page = m_frame.page()) { |
akling@apple.com | eb67e0a | 2013-08-19 08:24:08 +0000 | [diff] [blame] | 3067 | identifier = page->progress().createUniqueIdentifier(); |
akling@apple.com | 654fd9a | 2013-10-06 21:07:29 +0000 | [diff] [blame] | 3068 | notifier().assignIdentifierToInitialRequest(identifier, m_documentLoader.get(), request); |
darin | e0cef43 | 2007-07-10 19:21:23 +0000 | [diff] [blame] | 3069 | } |
andersca | ec429f5 | 2007-01-13 01:44:24 +0000 | [diff] [blame] | 3070 | |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3071 | ResourceRequest newRequest(request); |
akling@apple.com | 654fd9a | 2013-10-06 21:07:29 +0000 | [diff] [blame] | 3072 | notifier().dispatchWillSendRequest(m_documentLoader.get(), identifier, newRequest, ResourceResponse()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3073 | |
| 3074 | if (newRequest.isNull()) |
weinig@apple.com | 87a569c | 2008-05-18 01:21:20 +0000 | [diff] [blame] | 3075 | error = cancelledError(request); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3076 | else |
| 3077 | error = ResourceError(); |
| 3078 | |
| 3079 | request = newRequest; |
| 3080 | } |
| 3081 | |
aestes@apple.com | 0c8e191 | 2013-04-06 03:09:25 +0000 | [diff] [blame] | 3082 | void FrameLoader::loadedResourceFromMemoryCache(CachedResource* resource, ResourceRequest& newRequest) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3083 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3084 | Page* page = m_frame.page(); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3085 | if (!page) |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3086 | return; |
| 3087 | |
japhet@chromium.org | ede5cc5 | 2012-10-16 19:45:46 +0000 | [diff] [blame] | 3088 | if (!resource->shouldSendResourceLoadCallbacks() || m_documentLoader->haveToldClientAboutLoad(resource->url())) |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3089 | return; |
| 3090 | |
japhet@chromium.org | 3e31718 | 2013-01-29 20:06:19 +0000 | [diff] [blame] | 3091 | // Main resource delegate messages are synthesized in MainResourceLoader, so we must not send them here. |
| 3092 | if (resource->type() == CachedResource::MainResource) |
| 3093 | return; |
| 3094 | |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3095 | if (!page->areMemoryCacheClientCallsEnabled()) { |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 3096 | InspectorInstrumentation::didLoadResourceFromMemoryCache(*page, m_documentLoader.get(), resource); |
jpfau@apple.com | 97c6a7f | 2013-02-26 00:49:17 +0000 | [diff] [blame] | 3097 | m_documentLoader->recordMemoryCacheLoadForFutureClientNotification(resource->resourceRequest()); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3098 | m_documentLoader->didTellClientAboutLoad(resource->url()); |
| 3099 | return; |
| 3100 | } |
| 3101 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3102 | if (m_client.dispatchDidLoadResourceFromMemoryCache(m_documentLoader.get(), newRequest, resource->response(), resource->encodedSize())) { |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 3103 | InspectorInstrumentation::didLoadResourceFromMemoryCache(*page, m_documentLoader.get(), resource); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3104 | m_documentLoader->didTellClientAboutLoad(resource->url()); |
timothy@apple.com | 8f85dce | 2008-01-08 23:51:28 +0000 | [diff] [blame] | 3105 | return; |
| 3106 | } |
| 3107 | |
andersca | ec429f5 | 2007-01-13 01:44:24 +0000 | [diff] [blame] | 3108 | unsigned long identifier; |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3109 | ResourceError error; |
aestes@apple.com | 0c8e191 | 2013-04-06 03:09:25 +0000 | [diff] [blame] | 3110 | requestFromDelegate(newRequest, identifier, error); |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 3111 | InspectorInstrumentation::markResourceAsCached(*page, identifier); |
akling@apple.com | 654fd9a | 2013-10-06 21:07:29 +0000 | [diff] [blame] | 3112 | notifier().sendRemainingDelegateMessages(m_documentLoader.get(), identifier, newRequest, resource->response(), 0, resource->encodedSize(), 0, error); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | void FrameLoader::applyUserAgent(ResourceRequest& request) |
| 3116 | { |
caseq@chromium.org | 3d57ec6 | 2011-02-04 13:25:42 +0000 | [diff] [blame] | 3117 | String userAgent = this->userAgent(request.url()); |
andersca | de5715d | 2007-01-06 00:55:49 +0000 | [diff] [blame] | 3118 | ASSERT(!userAgent.isNull()); |
| 3119 | request.setHTTPUserAgent(userAgent); |
| 3120 | } |
| 3121 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3122 | 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] | 3123 | { |
akling@apple.com | 5298947 | 2013-09-16 20:09:25 +0000 | [diff] [blame] | 3124 | Frame& topFrame = m_frame.tree().top(); |
| 3125 | if (&m_frame == &topFrame) |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 3126 | return false; |
| 3127 | |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3128 | XFrameOptionsDisposition disposition = parseXFrameOptionsHeader(content); |
| 3129 | |
| 3130 | switch (disposition) { |
| 3131 | case XFrameOptionsSameOrigin: { |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 3132 | RefPtr<SecurityOrigin> origin = SecurityOrigin::create(url); |
akling@apple.com | 5298947 | 2013-09-16 20:09:25 +0000 | [diff] [blame] | 3133 | if (!origin->isSameSchemeHostPort(topFrame.document()->securityOrigin())) |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 3134 | return true; |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3135 | 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] | 3136 | if (!origin->isSameSchemeHostPort(frame->document()->securityOrigin())) |
mkwst@chromium.org | f9d8fa0 | 2013-03-19 21:12:24 +0000 | [diff] [blame] | 3137 | break; |
mkwst@chromium.org | f9d8fa0 | 2013-03-19 21:12:24 +0000 | [diff] [blame] | 3138 | } |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3139 | return false; |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 3140 | } |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3141 | case XFrameOptionsDeny: |
| 3142 | return true; |
| 3143 | case XFrameOptionsAllowAll: |
| 3144 | return false; |
| 3145 | case XFrameOptionsConflict: |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 3146 | 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] | 3147 | return true; |
| 3148 | case XFrameOptionsInvalid: |
joepeck@webkit.org | 1f45df9 | 2014-02-06 23:45:53 +0000 | [diff] [blame] | 3149 | 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] | 3150 | return false; |
psolanki@apple.com | e2dc3b9 | 2014-02-20 18:23:24 +0000 | [diff] [blame] | 3151 | case XFrameOptionsNone: |
mkwst@chromium.org | 97421c0 | 2013-03-28 08:59:00 +0000 | [diff] [blame] | 3152 | return false; |
| 3153 | } |
psolanki@apple.com | e2dc3b9 | 2014-02-20 18:23:24 +0000 | [diff] [blame] | 3154 | ASSERT_NOT_REACHED(); |
| 3155 | return false; |
weinig@apple.com | 5af461c | 2009-04-08 22:16:23 +0000 | [diff] [blame] | 3156 | } |
| 3157 | |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 3158 | void FrameLoader::loadProvisionalItemFromCachedPage() |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3159 | { |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 3160 | DocumentLoader* provisionalLoader = provisionalDocumentLoader(); |
mkwst@chromium.org | 6f6d9bc | 2013-05-30 12:08:58 +0000 | [diff] [blame] | 3161 | LOG(PageCache, "WebCorePageCache: 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] | 3162 | |
japhet@chromium.org | 91e5e2f | 2012-04-02 22:08:19 +0000 | [diff] [blame] | 3163 | prepareForLoadStart(); |
beidson@apple.com | ac095c0 | 2009-08-18 01:37:56 +0000 | [diff] [blame] | 3164 | |
| 3165 | m_loadingFromCachedPage = true; |
simonjam@chromium.org | dfab5cf | 2011-12-15 18:45:29 +0000 | [diff] [blame] | 3166 | |
eric@webkit.org | f939615 | 2010-08-08 06:19:48 +0000 | [diff] [blame] | 3167 | // Should have timing data from previous time(s) the page was shown. |
akling@apple.com | 5a7607f | 2015-01-21 22:33:49 +0000 | [diff] [blame] | 3168 | ASSERT(provisionalLoader->timing().navigationStart()); |
eric@webkit.org | f939615 | 2010-08-08 06:19:48 +0000 | [diff] [blame] | 3169 | provisionalLoader->resetTiming(); |
akling@apple.com | 5a7607f | 2015-01-21 22:33:49 +0000 | [diff] [blame] | 3170 | provisionalLoader->timing().markNavigationStart(); |
beidson@apple.com | ac095c0 | 2009-08-18 01:37:56 +0000 | [diff] [blame] | 3171 | |
| 3172 | provisionalLoader->setCommitted(true); |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 3173 | commitProvisionalLoad(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3174 | } |
| 3175 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3176 | bool FrameLoader::shouldTreatURLAsSameAsCurrent(const URL& url) const |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3177 | { |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3178 | if (!history().currentItem()) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3179 | return false; |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3180 | return url == history().currentItem()->url() || url == history().currentItem()->originalURL(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3181 | } |
| 3182 | |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3183 | bool FrameLoader::shouldTreatURLAsSrcdocDocument(const URL& url) const |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 3184 | { |
| 3185 | if (!equalIgnoringCase(url.string(), "about:srcdoc")) |
| 3186 | return false; |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3187 | HTMLFrameOwnerElement* ownerElement = m_frame.ownerElement(); |
abarth@webkit.org | b2515fa | 2012-04-04 05:54:26 +0000 | [diff] [blame] | 3188 | if (!ownerElement) |
| 3189 | return false; |
| 3190 | if (!ownerElement->hasTagName(iframeTag)) |
| 3191 | return false; |
| 3192 | return ownerElement->fastHasAttribute(srcdocAttr); |
| 3193 | } |
| 3194 | |
abarth@webkit.org | b46fdef | 2012-04-13 00:42:37 +0000 | [diff] [blame] | 3195 | Frame* FrameLoader::findFrameForNavigation(const AtomicString& name, Document* activeDocument) |
weinig@apple.com | 7742780 | 2008-01-11 00:23:13 +0000 | [diff] [blame] | 3196 | { |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3197 | Frame* frame = m_frame.tree().find(name); |
abarth@webkit.org | b46fdef | 2012-04-13 00:42:37 +0000 | [diff] [blame] | 3198 | |
ap@apple.com | f8c414e | 2013-08-13 03:44:57 +0000 | [diff] [blame] | 3199 | // FIXME: Eventually all callers should supply the actual activeDocument so we can call canNavigate with the right document. |
| 3200 | if (!activeDocument) |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3201 | activeDocument = m_frame.document(); |
ap@apple.com | f8c414e | 2013-08-13 03:44:57 +0000 | [diff] [blame] | 3202 | |
| 3203 | if (!activeDocument->canNavigate(frame)) |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3204 | return nullptr; |
abarth@webkit.org | b46fdef | 2012-04-13 00:42:37 +0000 | [diff] [blame] | 3205 | |
darin@apple.com | 0f88bda | 2009-04-02 00:30:50 +0000 | [diff] [blame] | 3206 | return frame; |
weinig@apple.com | 7742780 | 2008-01-11 00:23:13 +0000 | [diff] [blame] | 3207 | } |
| 3208 | |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3209 | void FrameLoader::loadSameDocumentItem(HistoryItem& item) |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3210 | { |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3211 | ASSERT(item.documentSequenceNumber() == history().currentItem()->documentSequenceNumber()); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3212 | |
| 3213 | // Save user view state to the current history item here since we don't do a normal load. |
| 3214 | // FIXME: Does form state need to be saved here too? |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3215 | history().saveScrollPositionAndViewStateToItem(history().currentItem()); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3216 | if (FrameView* view = m_frame.view()) |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3217 | view->setWasScrolledByUser(false); |
| 3218 | |
beidson@apple.com | c16ea84 | 2015-07-10 19:01:51 +0000 | [diff] [blame] | 3219 | history().setCurrentItem(&item); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3220 | |
| 3221 | // 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] | 3222 | loadInSameDocument(item.url(), item.stateObject(), false); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3223 | |
| 3224 | // 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] | 3225 | history().restoreScrollPositionAndViewState(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3226 | } |
| 3227 | |
abarth@webkit.org | 1c893f4 | 2009-10-10 02:27:21 +0000 | [diff] [blame] | 3228 | // FIXME: This function should really be split into a couple pieces, some of |
| 3229 | // which should be methods of HistoryController and some of which should be |
| 3230 | // methods of FrameLoader. |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3231 | void FrameLoader::loadDifferentDocumentItem(HistoryItem& item, FrameLoadType loadType, FormSubmissionCacheLoadPolicy cacheLoadPolicy) |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3232 | { |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3233 | // 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] | 3234 | history().setProvisionalItem(&item); |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 3235 | |
cdumez@apple.com | 4faf1ef | 2015-01-30 20:49:33 +0000 | [diff] [blame] | 3236 | if (CachedPage* cachedPage = PageCache::singleton().get(item, m_frame.page())) { |
mitz@apple.com | 4a60442 | 2014-11-13 23:22:50 +0000 | [diff] [blame] | 3237 | auto documentLoader = cachedPage->documentLoader(); |
cdumez@apple.com | 6478e4d | 2015-06-14 04:53:14 +0000 | [diff] [blame] | 3238 | m_client.updateCachedDocumentLoader(*documentLoader); |
mitz@apple.com | 4a60442 | 2014-11-13 23:22:50 +0000 | [diff] [blame] | 3239 | documentLoader->setTriggeringAction(NavigationAction(documentLoader->request(), loadType, false)); |
| 3240 | documentLoader->setLastCheckedRequest(ResourceRequest()); |
| 3241 | loadWithDocumentLoader(documentLoader, loadType, 0, AllowNavigationToInvalidURL::Yes); |
japhet@chromium.org | d48109c | 2010-06-04 17:41:26 +0000 | [diff] [blame] | 3242 | return; |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3243 | } |
adele@apple.com | f3d6b89 | 2008-04-29 01:30:20 +0000 | [diff] [blame] | 3244 | |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3245 | URL itemURL = item.url(); |
| 3246 | URL itemOriginalURL = item.originalURL(); |
darin@apple.com | 5ffbb5c | 2013-09-27 16:39:41 +0000 | [diff] [blame] | 3247 | URL currentURL; |
beidson | 0c34599 | 2007-02-13 08:59:33 +0000 | [diff] [blame] | 3248 | if (documentLoader()) |
weinig@apple.com | c500266 | 2007-12-12 07:26:19 +0000 | [diff] [blame] | 3249 | currentURL = documentLoader()->url(); |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3250 | RefPtr<FormData> formData = item.formData(); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3251 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3252 | ResourceRequest request(itemURL); |
| 3253 | |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3254 | if (!item.referrer().isNull()) |
| 3255 | request.setHTTPReferrer(item.referrer()); |
dbates@webkit.org | ae34b60 | 2015-08-05 16:05:55 +0000 | [diff] [blame] | 3256 | |
| 3257 | ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLsPolicyToApply(m_frame, item.shouldOpenExternalURLsPolicy()); |
| 3258 | bool isFormSubmission = false; |
| 3259 | Event* event = nullptr; |
| 3260 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3261 | // If this was a repost that failed the page cache, we might try to repost the form. |
| 3262 | NavigationAction action; |
| 3263 | if (formData) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3264 | formData->generateFiles(m_frame.document()); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3265 | |
| 3266 | request.setHTTPMethod("POST"); |
| 3267 | request.setHTTPBody(formData); |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3268 | request.setHTTPContentType(item.formContentType()); |
| 3269 | RefPtr<SecurityOrigin> securityOrigin = SecurityOrigin::createFromString(item.referrer()); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3270 | addHTTPOriginIfNeeded(request, securityOrigin->toString()); |
| 3271 | |
| 3272 | // Make sure to add extra fields to the request after the Origin header is added for the FormData case. |
| 3273 | // 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] | 3274 | addExtraFieldsToRequest(request, loadType, true); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3275 | |
| 3276 | // FIXME: Slight hack to test if the NSURL cache contains the page we're going to. |
| 3277 | // We want to know this before talking to the policy delegate, since it affects whether |
| 3278 | // we show the DoYouReallyWantToRepost nag. |
| 3279 | // |
| 3280 | // This trick has a small bug (3123893) where we might find a cache hit, but then |
| 3281 | // have the item vanish when we try to use it in the ensuing nav. This should be |
| 3282 | // extremely rare, but in that case the user will get an error on the navigation. |
| 3283 | |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3284 | if (cacheLoadPolicy == MayAttemptCacheOnlyLoadForFormSubmissionItem) { |
| 3285 | request.setCachePolicy(ReturnCacheDataDontLoad); |
dbates@webkit.org | ae34b60 | 2015-08-05 16:05:55 +0000 | [diff] [blame] | 3286 | action = NavigationAction(request, loadType, isFormSubmission, event, shouldOpenExternalURLsPolicy); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3287 | } else { |
| 3288 | request.setCachePolicy(ReturnCacheDataElseLoad); |
dbates@webkit.org | ae34b60 | 2015-08-05 16:05:55 +0000 | [diff] [blame] | 3289 | action = NavigationAction(request, NavigationType::FormResubmitted, event, shouldOpenExternalURLsPolicy); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3290 | } |
| 3291 | } else { |
| 3292 | switch (loadType) { |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3293 | case FrameLoadType::Reload: |
| 3294 | case FrameLoadType::ReloadFromOrigin: |
| 3295 | request.setCachePolicy(ReloadIgnoringCacheData); |
| 3296 | break; |
| 3297 | case FrameLoadType::Back: |
| 3298 | case FrameLoadType::Forward: |
| 3299 | case FrameLoadType::IndexedBackForward: |
cdumez@apple.com | 49421c9 | 2015-03-20 05:45:38 +0000 | [diff] [blame] | 3300 | request.setCachePolicy(ReturnCacheDataElseLoad); |
andersca@apple.com | b50fcc3 | 2014-06-19 00:13:20 +0000 | [diff] [blame] | 3301 | break; |
| 3302 | case FrameLoadType::Standard: |
| 3303 | case FrameLoadType::RedirectWithLockedBackForwardList: |
| 3304 | break; |
| 3305 | case FrameLoadType::Same: |
| 3306 | default: |
| 3307 | ASSERT_NOT_REACHED(); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3308 | } |
| 3309 | |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3310 | addExtraFieldsToRequest(request, loadType, true); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3311 | |
jochen@chromium.org | 056b7fa | 2011-10-18 04:47:05 +0000 | [diff] [blame] | 3312 | ResourceRequest requestForOriginalURL(request); |
| 3313 | requestForOriginalURL.setURL(itemOriginalURL); |
dbates@webkit.org | ae34b60 | 2015-08-05 16:05:55 +0000 | [diff] [blame] | 3314 | action = NavigationAction(requestForOriginalURL, loadType, isFormSubmission, event, shouldOpenExternalURLsPolicy); |
jochen@chromium.org | 056b7fa | 2011-10-18 04:47:05 +0000 | [diff] [blame] | 3315 | } |
| 3316 | |
aestes@apple.com | 47ac5e1 | 2014-08-18 17:48:48 +0000 | [diff] [blame] | 3317 | loadWithNavigationAction(request, action, LockHistory::No, loadType, 0, AllowNavigationToInvalidURL::Yes); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | // Loads content into this frame, as specified by history item |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3321 | void FrameLoader::loadItem(HistoryItem& item, FrameLoadType loadType) |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3322 | { |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3323 | m_requestedHistoryItem = &item; |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3324 | HistoryItem* currentItem = history().currentItem(); |
cdumez@apple.com | fea5cb9 | 2015-02-02 00:49:36 +0000 | [diff] [blame] | 3325 | bool sameDocumentNavigation = currentItem && item.shouldDoSameDocumentNavigationTo(*currentItem); |
darin@chromium.org | e71dd0f | 2009-04-17 20:31:17 +0000 | [diff] [blame] | 3326 | |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3327 | if (sameDocumentNavigation) |
mihaip@chromium.org | e5dbd37 | 2010-12-08 02:32:41 +0000 | [diff] [blame] | 3328 | loadSameDocumentItem(item); |
beidson@apple.com | 08c6175 | 2009-12-03 19:04:40 +0000 | [diff] [blame] | 3329 | else |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3330 | loadDifferentDocumentItem(item, loadType, MayAttemptCacheOnlyLoadForFormSubmissionItem); |
| 3331 | } |
| 3332 | |
| 3333 | void FrameLoader::retryAfterFailedCacheOnlyMainResourceLoad() |
| 3334 | { |
| 3335 | ASSERT(m_state == FrameStateProvisional); |
| 3336 | ASSERT(!m_loadingFromCachedPage); |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3337 | ASSERT(history().provisionalItem()); |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3338 | ASSERT(history().provisionalItem()->formData()); |
| 3339 | ASSERT(history().provisionalItem() == m_requestedHistoryItem.get()); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3340 | |
| 3341 | FrameLoadType loadType = m_loadType; |
cdumez@apple.com | 67e10f7 | 2015-01-29 18:38:51 +0000 | [diff] [blame] | 3342 | HistoryItem& item = *history().provisionalItem(); |
ap@apple.com | 8d5f01b | 2013-01-07 18:40:55 +0000 | [diff] [blame] | 3343 | |
| 3344 | stopAllLoaders(ShouldNotClearProvisionalItem); |
| 3345 | loadDifferentDocumentItem(item, loadType, MayNotAttemptCacheOnlyLoadForFormSubmissionItem); |
beidson | 50c3bd8 | 2007-01-03 03:11:18 +0000 | [diff] [blame] | 3346 | } |
| 3347 | |
andersca | c8ee246 | 2007-01-05 22:26:32 +0000 | [diff] [blame] | 3348 | ResourceError FrameLoader::cancelledError(const ResourceRequest& request) const |
| 3349 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3350 | ResourceError error = m_client.cancelledError(request); |
weinig@apple.com | 87a569c | 2008-05-18 01:21:20 +0000 | [diff] [blame] | 3351 | error.setIsCancellation(true); |
| 3352 | return error; |
andersca | c8ee246 | 2007-01-05 22:26:32 +0000 | [diff] [blame] | 3353 | } |
| 3354 | |
commit-queue@webkit.org | 8090ccb | 2015-10-06 08:18:08 +0000 | [diff] [blame] | 3355 | ResourceError FrameLoader::blockedByContentBlockerError(const ResourceRequest& request) const |
| 3356 | { |
| 3357 | return m_client.blockedByContentBlockerError(request); |
| 3358 | } |
| 3359 | |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 3360 | #if PLATFORM(IOS) |
| 3361 | RetainPtr<CFDictionaryRef> FrameLoader::connectionProperties(ResourceLoader* loader) |
| 3362 | { |
| 3363 | return m_client.connectionProperties(loader->documentLoader(), loader->identifier()); |
| 3364 | } |
| 3365 | #endif |
| 3366 | |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 3367 | String FrameLoader::referrer() const |
| 3368 | { |
ap@apple.com | 9fd2000 | 2010-07-01 18:47:57 +0000 | [diff] [blame] | 3369 | return m_documentLoader ? m_documentLoader->request().httpReferrer() : ""; |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 3370 | } |
| 3371 | |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3372 | void FrameLoader::dispatchDidClearWindowObjectsInAllWorlds() |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3373 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3374 | if (!m_frame.script().canExecuteScripts(NotAboutToExecuteScript)) |
thatcher | 10840e5 | 2007-09-22 00:49:09 +0000 | [diff] [blame] | 3375 | return; |
| 3376 | |
weinig@apple.com | 8f71603 | 2013-10-02 17:03:09 +0000 | [diff] [blame] | 3377 | Vector<Ref<DOMWrapperWorld>> worlds; |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3378 | ScriptController::getAllWorlds(worlds); |
cdumez@apple.com | 2f66120 | 2014-11-04 07:22:18 +0000 | [diff] [blame] | 3379 | for (auto& world : worlds) |
| 3380 | dispatchDidClearWindowObjectInWorld(world); |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3381 | } |
| 3382 | |
weinig@apple.com | 8f71603 | 2013-10-02 17:03:09 +0000 | [diff] [blame] | 3383 | void FrameLoader::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld& world) |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3384 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3385 | if (!m_frame.script().canExecuteScripts(NotAboutToExecuteScript) || !m_frame.script().existingWindowShell(world)) |
aroben@apple.com | 11dd526 | 2009-11-13 23:49:05 +0000 | [diff] [blame] | 3386 | return; |
| 3387 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3388 | m_client.dispatchDidClearWindowObjectInWorld(world); |
timothy@apple.com | efb8ac1 | 2008-07-24 02:48:36 +0000 | [diff] [blame] | 3389 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3390 | if (Page* page = m_frame.page()) |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 3391 | page->inspectorController().didClearWindowObjectInWorld(m_frame, world); |
loislo@chromium.org | e971cb5 | 2011-02-08 17:32:44 +0000 | [diff] [blame] | 3392 | |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 3393 | InspectorInstrumentation::didClearWindowObjectInWorld(m_frame, world); |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3394 | } |
| 3395 | |
beidson@apple.com | 2a75a96 | 2012-04-24 18:12:55 +0000 | [diff] [blame] | 3396 | void FrameLoader::dispatchGlobalObjectAvailableInAllWorlds() |
| 3397 | { |
weinig@apple.com | 8f71603 | 2013-10-02 17:03:09 +0000 | [diff] [blame] | 3398 | Vector<Ref<DOMWrapperWorld>> worlds; |
beidson@apple.com | 2a75a96 | 2012-04-24 18:12:55 +0000 | [diff] [blame] | 3399 | ScriptController::getAllWorlds(worlds); |
cdumez@apple.com | 2f66120 | 2014-11-04 07:22:18 +0000 | [diff] [blame] | 3400 | for (auto& world : worlds) |
| 3401 | m_client.dispatchGlobalObjectAvailable(world); |
beidson@apple.com | 2a75a96 | 2012-04-24 18:12:55 +0000 | [diff] [blame] | 3402 | } |
| 3403 | |
abarth@webkit.org | 8b45d86 | 2011-11-05 21:55:59 +0000 | [diff] [blame] | 3404 | SandboxFlags FrameLoader::effectiveSandboxFlags() const |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3405 | { |
abarth@webkit.org | f2c54c2 | 2010-04-11 06:57:13 +0000 | [diff] [blame] | 3406 | SandboxFlags flags = m_forcedSandboxFlags; |
darin@apple.com | fed4d16 | 2013-08-25 02:28:06 +0000 | [diff] [blame] | 3407 | if (Frame* parentFrame = m_frame.tree().parent()) |
abarth@webkit.org | 8b45d86 | 2011-11-05 21:55:59 +0000 | [diff] [blame] | 3408 | flags |= parentFrame->document()->sandboxFlags(); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3409 | if (HTMLFrameOwnerElement* ownerElement = m_frame.ownerElement()) |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3410 | flags |= ownerElement->sandboxFlags(); |
abarth@webkit.org | 8b45d86 | 2011-11-05 21:55:59 +0000 | [diff] [blame] | 3411 | return flags; |
abarth@webkit.org | f5267a4 | 2010-01-10 08:14:05 +0000 | [diff] [blame] | 3412 | } |
abarth@webkit.org | b8a1055 | 2009-12-02 02:40:35 +0000 | [diff] [blame] | 3413 | |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3414 | void FrameLoader::didChangeTitle(DocumentLoader* loader) |
| 3415 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3416 | m_client.didChangeTitle(loader); |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3417 | |
darin@apple.com | 719d29c | 2009-07-24 00:09:17 +0000 | [diff] [blame] | 3418 | if (loader == m_documentLoader) { |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3419 | // Must update the entries in the back-forward list too. |
akling@apple.com | 672cb85 | 2013-08-22 20:27:27 +0000 | [diff] [blame] | 3420 | history().setCurrentItemTitle(loader->title()); |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3421 | // 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] | 3422 | m_client.setTitle(loader->title(), loader->urlForHistory()); |
| 3423 | m_client.setMainFrameDocumentReady(true); // update observers with new DOMDocument |
| 3424 | m_client.dispatchDidReceiveTitle(loader->title()); |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3425 | } |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 3426 | |
| 3427 | #if ENABLE(REMOTE_INSPECTOR) |
| 3428 | if (m_frame.isMainFrame()) |
| 3429 | m_frame.page()->remoteInspectorInformationDidChange(); |
| 3430 | #endif |
lars | 1e1dad3 | 2007-01-23 10:28:38 +0000 | [diff] [blame] | 3431 | } |
andersca | 4422e37 | 2007-01-12 19:56:19 +0000 | [diff] [blame] | 3432 | |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 3433 | void FrameLoader::dispatchDidCommitLoad() |
| 3434 | { |
japhet@chromium.org | 61d4b9c | 2010-06-21 20:06:02 +0000 | [diff] [blame] | 3435 | if (m_stateMachine.creatingInitialEmptyDocument()) |
darin@apple.com | 87134f2 | 2007-12-05 22:58:41 +0000 | [diff] [blame] | 3436 | return; |
| 3437 | |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3438 | m_client.dispatchDidCommitLoad(); |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 3439 | |
darin@apple.com | 0e83ab1 | 2013-09-28 17:19:04 +0000 | [diff] [blame] | 3440 | if (m_frame.isMainFrame()) { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3441 | m_frame.page()->resetSeenPlugins(); |
| 3442 | m_frame.page()->resetSeenMediaEngines(); |
jer.noble@apple.com | 2d0a60a | 2012-10-18 18:12:57 +0000 | [diff] [blame] | 3443 | } |
jer.noble@apple.com | 381b467 | 2012-07-28 00:41:18 +0000 | [diff] [blame] | 3444 | |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 3445 | InspectorInstrumentation::didCommitLoad(m_frame, m_documentLoader.get()); |
commit-queue@webkit.org | 42b4787 | 2013-02-19 19:19:02 +0000 | [diff] [blame] | 3446 | |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 3447 | #if ENABLE(REMOTE_INSPECTOR) |
akling@apple.com | fbea406 | 2014-02-27 20:24:03 +0000 | [diff] [blame] | 3448 | if (m_frame.isMainFrame()) |
joepeck@webkit.org | d2ecf37 | 2013-12-04 18:20:37 +0000 | [diff] [blame] | 3449 | m_frame.page()->remoteInspectorInformationDidChange(); |
| 3450 | #endif |
aroben | dfc5666 | 2007-06-21 01:37:24 +0000 | [diff] [blame] | 3451 | } |
| 3452 | |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3453 | void FrameLoader::tellClientAboutPastMemoryCacheLoads() |
| 3454 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3455 | ASSERT(m_frame.page()); |
| 3456 | ASSERT(m_frame.page()->areMemoryCacheClientCallsEnabled()); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3457 | |
| 3458 | if (!m_documentLoader) |
| 3459 | return; |
| 3460 | |
jpfau@apple.com | 97c6a7f | 2013-02-26 00:49:17 +0000 | [diff] [blame] | 3461 | Vector<ResourceRequest> pastLoads; |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3462 | m_documentLoader->takeMemoryCacheLoadsForClientNotification(pastLoads); |
| 3463 | |
commit-queue@webkit.org | acddfad | 2015-09-30 05:53:51 +0000 | [diff] [blame] | 3464 | for (auto& pastLoad : pastLoads) { |
| 3465 | CachedResource* resource = MemoryCache::singleton().resourceForRequest(pastLoad, m_frame.page()->sessionID()); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3466 | |
| 3467 | // FIXME: These loads, loaded from cache, but now gone from the cache by the time |
| 3468 | // Page::setMemoryCacheClientCallsEnabled(true) is called, will not be seen by the client. |
| 3469 | // Consider if there's some efficient way of remembering enough to deliver this client call. |
| 3470 | // We have the URL, but not the rest of the response or the length. |
| 3471 | if (!resource) |
| 3472 | continue; |
| 3473 | |
| 3474 | ResourceRequest request(resource->url()); |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3475 | m_client.dispatchDidLoadResourceFromMemoryCache(m_documentLoader.get(), request, resource->response(), resource->encodedSize()); |
darin@apple.com | 837a78c | 2009-01-07 15:40:24 +0000 | [diff] [blame] | 3476 | } |
| 3477 | } |
| 3478 | |
diegohcg@webkit.org | 838e0a2 | 2010-09-04 14:48:30 +0000 | [diff] [blame] | 3479 | NetworkingContext* FrameLoader::networkingContext() const |
| 3480 | { |
| 3481 | return m_networkingContext.get(); |
| 3482 | } |
| 3483 | |
antti@apple.com | a6775c1 | 2013-04-05 21:19:56 +0000 | [diff] [blame] | 3484 | void FrameLoader::loadProgressingStatusChanged() |
| 3485 | { |
antti@apple.com | 08536d1 | 2014-06-27 21:58:06 +0000 | [diff] [blame] | 3486 | if (auto* view = m_frame.mainFrame().view()) |
| 3487 | view->loadProgressingStatusChanged(); |
antti@apple.com | a6775c1 | 2013-04-05 21:19:56 +0000 | [diff] [blame] | 3488 | } |
| 3489 | |
timothy_horton@apple.com | 88756d6 | 2013-05-30 06:24:36 +0000 | [diff] [blame] | 3490 | void FrameLoader::forcePageTransitionIfNeeded() |
| 3491 | { |
akling@apple.com | 7f50aae | 2013-08-22 16:01:31 +0000 | [diff] [blame] | 3492 | m_client.forcePageTransitionIfNeeded(); |
timothy_horton@apple.com | 88756d6 | 2013-05-30 06:24:36 +0000 | [diff] [blame] | 3493 | } |
| 3494 | |
antti@apple.com | 1229ead | 2015-03-30 21:09:14 +0000 | [diff] [blame] | 3495 | void FrameLoader::clearTestingOverrides() |
| 3496 | { |
| 3497 | m_overrideCachePolicyForTesting = Nullopt; |
| 3498 | m_overrideResourceLoadPriorityForTesting = Nullopt; |
antti@apple.com | 2c4a2a2 | 2015-08-14 14:08:59 +0000 | [diff] [blame] | 3499 | m_isStrictRawResourceValidationPolicyDisabledForTesting = false; |
antti@apple.com | 1229ead | 2015-03-30 21:09:14 +0000 | [diff] [blame] | 3500 | } |
| 3501 | |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 3502 | void FrameLoader::applyShouldOpenExternalURLsPolicyToNewDocumentLoader(DocumentLoader& documentLoader, ShouldOpenExternalURLsPolicy propagatedPolicy) |
| 3503 | { |
mitz@apple.com | c99c715 | 2015-07-17 21:16:09 +0000 | [diff] [blame] | 3504 | documentLoader.setShouldOpenExternalURLsPolicy(shouldOpenExternalURLsPolicyToApply(m_frame, propagatedPolicy)); |
beidson@apple.com | 87dc631 | 2015-06-02 18:43:13 +0000 | [diff] [blame] | 3505 | } |
| 3506 | |
darin@apple.com | 90a0f15 | 2009-02-01 00:55:03 +0000 | [diff] [blame] | 3507 | bool FrameLoaderClient::hasHTMLView() const |
| 3508 | { |
| 3509 | return true; |
| 3510 | } |
| 3511 | |
cdumez@apple.com | 468ca18 | 2015-05-15 05:07:22 +0000 | [diff] [blame] | 3512 | RefPtr<Frame> createWindow(Frame& openerFrame, Frame& lookupFrame, const FrameLoadRequest& request, const WindowFeatures& features, bool& created) |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3513 | { |
| 3514 | ASSERT(!features.dialog || request.frameName().isEmpty()); |
| 3515 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 3516 | created = false; |
| 3517 | |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3518 | if (!request.frameName().isEmpty() && request.frameName() != "_blank") { |
cdumez@apple.com | 468ca18 | 2015-05-15 05:07:22 +0000 | [diff] [blame] | 3519 | if (RefPtr<Frame> frame = lookupFrame.loader().findFrameForNavigation(request.frameName(), openerFrame.document())) { |
jochen@chromium.org | b2c684a | 2013-05-11 19:09:01 +0000 | [diff] [blame] | 3520 | if (request.frameName() != "_self") { |
| 3521 | if (Page* page = frame->page()) |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 3522 | page->chrome().focus(); |
jochen@chromium.org | b2c684a | 2013-05-11 19:09:01 +0000 | [diff] [blame] | 3523 | } |
cdumez@apple.com | 468ca18 | 2015-05-15 05:07:22 +0000 | [diff] [blame] | 3524 | return WTF::move(frame); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3525 | } |
| 3526 | } |
| 3527 | |
| 3528 | // Sandboxed frames cannot open new auxiliary browsing contexts. |
mkwst@chromium.org | b10ebb43 | 2012-12-04 18:34:27 +0000 | [diff] [blame] | 3529 | if (isDocumentSandboxed(openerFrame, SandboxPopups)) { |
| 3530 | // 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] | 3531 | 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] | 3532 | return nullptr; |
mkwst@chromium.org | b10ebb43 | 2012-12-04 18:34:27 +0000 | [diff] [blame] | 3533 | } |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3534 | |
| 3535 | // FIXME: Setting the referrer should be the caller's responsibility. |
| 3536 | FrameLoadRequest requestWithReferrer = request; |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 3537 | 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] | 3538 | if (!referrer.isEmpty()) |
| 3539 | requestWithReferrer.resourceRequest().setHTTPReferrer(referrer); |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 3540 | FrameLoader::addHTTPOriginIfNeeded(requestWithReferrer.resourceRequest(), openerFrame.loader().outgoingOrigin()); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3541 | |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 3542 | Page* oldPage = openerFrame.page(); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3543 | if (!oldPage) |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 3544 | return nullptr; |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3545 | |
mitz@apple.com | c99c715 | 2015-07-17 21:16:09 +0000 | [diff] [blame] | 3546 | ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy = shouldOpenExternalURLsPolicyToApply(openerFrame, request.shouldOpenExternalURLsPolicy()); |
| 3547 | Page* page = oldPage->chrome().createWindow(&openerFrame, requestWithReferrer, features, NavigationAction(requestWithReferrer.resourceRequest(), shouldOpenExternalURLsPolicy)); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3548 | if (!page) |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 3549 | return nullptr; |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3550 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 3551 | RefPtr<Frame> frame = &page->mainFrame(); |
| 3552 | |
cdumez@apple.com | d6738dc | 2015-05-04 23:58:32 +0000 | [diff] [blame] | 3553 | frame->loader().forceSandboxFlags(openerFrame.document()->sandboxFlags()); |
abarth@webkit.org | 7155e25 | 2011-11-04 18:14:58 +0000 | [diff] [blame] | 3554 | |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3555 | if (request.frameName() != "_blank") |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 3556 | frame->tree().setName(request.frameName()); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3557 | |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 3558 | page->chrome().setToolbarsVisible(features.toolBarVisible || features.locationBarVisible); |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 3559 | |
| 3560 | if (!frame->page()) |
| 3561 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 3562 | page->chrome().setStatusbarVisible(features.statusBarVisible); |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 3563 | |
| 3564 | if (!frame->page()) |
| 3565 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 3566 | page->chrome().setScrollbarsVisible(features.scrollbarsVisible); |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 3567 | |
| 3568 | if (!frame->page()) |
| 3569 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 3570 | page->chrome().setMenubarVisible(features.menuBarVisible); |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 3571 | |
| 3572 | if (!frame->page()) |
| 3573 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 3574 | page->chrome().setResizable(features.resizable); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3575 | |
| 3576 | // '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] | 3577 | // specify the size of the viewport. We can only resize the window, so adjust |
| 3578 | // for the difference between the window size and the viewport size. |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3579 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 3580 | // FIXME: We should reconcile the initialization of viewport arguments between iOS and non-IOS. |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 3581 | #if !PLATFORM(IOS) |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 3582 | FloatSize viewportSize = page->chrome().pageRect().size(); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 3583 | FloatRect windowRect = page->chrome().windowRect(); |
andersca@apple.com | c1242ad | 2015-08-13 17:37:27 +0000 | [diff] [blame] | 3584 | if (features.x) |
| 3585 | windowRect.setX(*features.x); |
| 3586 | if (features.y) |
| 3587 | windowRect.setY(*features.y); |
ap@apple.com | 8d15a82 | 2013-08-09 23:25:11 +0000 | [diff] [blame] | 3588 | // Zero width and height mean using default size, not minumum one. |
andersca@apple.com | c1242ad | 2015-08-13 17:37:27 +0000 | [diff] [blame] | 3589 | if (features.width && *features.width) |
| 3590 | windowRect.setWidth(*features.width + (windowRect.width() - viewportSize.width())); |
| 3591 | if (features.height && *features.height) |
| 3592 | windowRect.setHeight(*features.height + (windowRect.height() - viewportSize.height())); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3593 | |
kenneth@webkit.org | dc092f7 | 2012-11-14 11:05:20 +0000 | [diff] [blame] | 3594 | // Ensure non-NaN values, minimum size as well as being within valid screen area. |
| 3595 | FloatRect newWindowRect = DOMWindow::adjustWindowRect(page, windowRect); |
| 3596 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 3597 | if (!frame->page()) |
| 3598 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 3599 | page->chrome().setWindowRect(newWindowRect); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 3600 | #else |
| 3601 | // On iOS, width and height refer to the viewport dimensions. |
| 3602 | ViewportArguments arguments; |
| 3603 | // Zero width and height mean using default size, not minimum one. |
andersca@apple.com | c1242ad | 2015-08-13 17:37:27 +0000 | [diff] [blame] | 3604 | if (features.width && *features.width) |
| 3605 | arguments.width = *features.width; |
| 3606 | if (features.height && *features.height) |
| 3607 | arguments.height = *features.height; |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 3608 | frame->setViewportArguments(arguments); |
dbates@webkit.org | 46a1c6f | 2013-12-19 18:10:07 +0000 | [diff] [blame] | 3609 | #endif |
| 3610 | |
darin@apple.com | 14800c1 | 2014-04-27 04:09:45 +0000 | [diff] [blame] | 3611 | if (!frame->page()) |
| 3612 | return nullptr; |
akling@apple.com | bd77481 | 2013-05-17 00:03:01 +0000 | [diff] [blame] | 3613 | page->chrome().show(); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3614 | |
| 3615 | created = true; |
cdumez@apple.com | 468ca18 | 2015-05-15 05:07:22 +0000 | [diff] [blame] | 3616 | return WTF::move(frame); |
cjerdonek@webkit.org | e1d4541 | 2010-08-11 17:40:23 +0000 | [diff] [blame] | 3617 | } |
| 3618 | |
ggaren | 58e230c | 2006-11-12 04:53:17 +0000 | [diff] [blame] | 3619 | } // namespace WebCore |