Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: third_party/WebKit/Source/core/dom/ScriptRunner.cpp

Issue 1526293003: Gracefully discharge a failed script load in disposed documents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/ScriptRunner.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 25 matching lines...) Expand all
36 #include "public/platform/WebThread.h" 36 #include "public/platform/WebThread.h"
37 37
38 namespace blink { 38 namespace blink {
39 39
40 ScriptRunner::ScriptRunner(Document* document) 40 ScriptRunner::ScriptRunner(Document* document)
41 : m_document(document) 41 : m_document(document)
42 , m_taskRunner(Platform::current()->currentThread()->scheduler()->loadingTas kRunner()) 42 , m_taskRunner(Platform::current()->currentThread()->scheduler()->loadingTas kRunner())
43 , m_numberOfInOrderScriptsWithPendingNotification(0) 43 , m_numberOfInOrderScriptsWithPendingNotification(0)
44 , m_isSuspended(false) 44 , m_isSuspended(false)
45 #if !ENABLE(OILPAN) 45 #if !ENABLE(OILPAN)
46 , m_isDisposed(false)
46 , m_weakPointerFactoryForTasks(this) 47 , m_weakPointerFactoryForTasks(this)
47 #endif 48 #endif
48 { 49 {
49 ASSERT(document); 50 ASSERT(document);
50 #ifndef NDEBUG 51 #ifndef NDEBUG
51 m_hasEverBeenSuspended = false; 52 m_hasEverBeenSuspended = false;
52 #endif 53 #endif
53 } 54 }
54 55
55 ScriptRunner::~ScriptRunner() 56 ScriptRunner::~ScriptRunner()
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 scriptLoader->detach(); 92 scriptLoader->detach();
92 for (ScriptLoader* scriptLoader : m_inOrderScriptsToExecuteSoon) 93 for (ScriptLoader* scriptLoader : m_inOrderScriptsToExecuteSoon)
93 scriptLoader->detach(); 94 scriptLoader->detach();
94 for (ScriptLoader* scriptLoader : m_asyncScriptsToExecuteSoon) 95 for (ScriptLoader* scriptLoader : m_asyncScriptsToExecuteSoon)
95 scriptLoader->detach(); 96 scriptLoader->detach();
96 97
97 m_pendingInOrderScripts.clear(); 98 m_pendingInOrderScripts.clear();
98 m_pendingAsyncScripts.clear(); 99 m_pendingAsyncScripts.clear();
99 m_inOrderScriptsToExecuteSoon.clear(); 100 m_inOrderScriptsToExecuteSoon.clear();
100 m_asyncScriptsToExecuteSoon.clear(); 101 m_asyncScriptsToExecuteSoon.clear();
102 m_isDisposed = true;
101 } 103 }
102 #endif 104 #endif
103 105
104 void ScriptRunner::addPendingAsyncScript(ScriptLoader* scriptLoader) 106 void ScriptRunner::addPendingAsyncScript(ScriptLoader* scriptLoader)
105 { 107 {
106 m_document->incrementLoadEventDelayCount(); 108 m_document->incrementLoadEventDelayCount();
107 m_pendingAsyncScripts.add(scriptLoader); 109 m_pendingAsyncScripts.add(scriptLoader);
108 } 110 }
109 111
110 void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, Execution Type executionType) 112 void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, Execution Type executionType)
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 postTask(BLINK_FROM_HERE); 188 postTask(BLINK_FROM_HERE);
187 } 189 }
188 190
189 break; 191 break;
190 } 192 }
191 } 193 }
192 194
193 void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, ExecutionTy pe executionType) 195 void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, ExecutionTy pe executionType)
194 { 196 {
195 switch (executionType) { 197 switch (executionType) {
196 case ASYNC_EXECUTION: 198 case ASYNC_EXECUTION: {
199 bool foundLoader = m_pendingAsyncScripts.contains(scriptLoader);
200 #if !ENABLE(OILPAN)
201 // If the document and ScriptRunner has been disposed of, there's
202 // no bookkeeping to be done here.
203 foundLoader = foundLoader || m_isDisposed;
204 #endif
197 // RELEASE_ASSERT makes us crash in a controlled way in error cases 205 // RELEASE_ASSERT makes us crash in a controlled way in error cases
198 // where the ScriptLoader is associated with the wrong ScriptRunner 206 // where the ScriptLoader is associated with the wrong ScriptRunner
199 // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries 207 // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries
200 // to detach). 208 // to detach).
201 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(m_pendingAsyncScripts.contains( scriptLoader)); 209 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(foundLoader);
202 m_pendingAsyncScripts.remove(scriptLoader); 210 m_pendingAsyncScripts.remove(scriptLoader);
203 break; 211 break;
204 212 }
205 case IN_ORDER_EXECUTION: 213 case IN_ORDER_EXECUTION:
206 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(m_numberOfInOrderScriptsWithPen dingNotification > 0); 214 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(m_numberOfInOrderScriptsWithPen dingNotification > 0);
207 m_numberOfInOrderScriptsWithPendingNotification--; 215 m_numberOfInOrderScriptsWithPendingNotification--;
208 216
209 bool foundPendingScript = false; 217 bool foundPendingScript = false;
210 for (auto it = m_pendingInOrderScripts.begin(); it != m_pendingInOrderSc ripts.end(); ++it) { 218 for (auto it = m_pendingInOrderScripts.begin(); it != m_pendingInOrderSc ripts.end(); ++it) {
211 if (*it == scriptLoader) { 219 if (*it == scriptLoader) {
212 m_pendingInOrderScripts.remove(it); 220 m_pendingInOrderScripts.remove(it);
213 foundPendingScript = true; 221 foundPendingScript = true;
214 break; 222 break;
215 } 223 }
216 } 224 }
225 #if !ENABLE(OILPAN)
226 foundPendingScript = foundPendingScript || m_isDisposed;
227 #endif
217 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(foundPendingScript); 228 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(foundPendingScript);
218 break; 229 break;
219 } 230 }
220 scriptLoader->detach(); 231 scriptLoader->detach();
221 m_document->decrementLoadEventDelayCount(); 232 m_document->decrementLoadEventDelayCount();
222 } 233 }
223 234
224 void ScriptRunner::movePendingAsyncScript(Document& oldDocument, Document& newDo cument, ScriptLoader* scriptLoader) 235 void ScriptRunner::movePendingAsyncScript(Document& oldDocument, Document& newDo cument, ScriptLoader* scriptLoader)
225 { 236 {
226 RefPtrWillBeRawPtr<Document> newContextDocument = newDocument.contextDocumen t().get(); 237 RefPtrWillBeRawPtr<Document> newContextDocument = newDocument.contextDocumen t().get();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 #if ENABLE(OILPAN) 300 #if ENABLE(OILPAN)
290 visitor->trace(m_document); 301 visitor->trace(m_document);
291 visitor->trace(m_pendingInOrderScripts); 302 visitor->trace(m_pendingInOrderScripts);
292 visitor->trace(m_pendingAsyncScripts); 303 visitor->trace(m_pendingAsyncScripts);
293 visitor->trace(m_asyncScriptsToExecuteSoon); 304 visitor->trace(m_asyncScriptsToExecuteSoon);
294 visitor->trace(m_inOrderScriptsToExecuteSoon); 305 visitor->trace(m_inOrderScriptsToExecuteSoon);
295 #endif 306 #endif
296 } 307 }
297 308
298 } // namespace blink 309 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/ScriptRunner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698