Changeset 65350 in webkit
- Timestamp:
- Aug 13, 2010 8:09:36 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r65349 r65350 1 2010-08-13 Tony Gentilcore <tonyg@chromium.org> 2 3 Reviewed by Eric Seidel. 4 5 Refactor HTMLScriptRunner to allow deferred scripts to share code 6 https://bugs.webkit.org/show_bug.cgi?id=43736 7 8 No new tests because no functional change 9 10 * html/HTMLScriptRunner.cpp: 11 (WebCore::HTMLScriptRunner::sourceFromPendingScript): Make const to enforce the idea that it doesn't change m_parsingBlockingScript. 12 (WebCore::HTMLScriptRunner::executeParsingBlockingScript): Rename to make it clear this deals with the parsing blocking script and refactor to use executePendingScriptAndDispatchEvent. 13 (WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent): Factored out of executePendingScript, this can be used for executing any external script. 14 (WebCore::HTMLScriptRunner::executeScript): This can be used for executing any inline or external script. ASSERTs moved to the two calling points. 15 (WebCore::HTMLScriptRunner::executeParsingBlockingScripts): Moved method. 16 (WebCore::HTMLScriptRunner::requestParsingBlockingScript): Factored out requestPendingScript. 17 (WebCore::HTMLScriptRunner::requestPendingScript): Factored out from reqeustParsingBlockingScript. 18 (WebCore::HTMLScriptRunner::runScript): 19 * html/HTMLScriptRunner.h: 20 1 21 2010-08-13 Gavin Barraclough <barraclough@apple.com> 2 22 -
trunk/WebCore/html/HTMLScriptRunner.cpp
r64857 r65350 44 44 using namespace HTMLNames; 45 45 46 class NestScript : public Noncopyable { 46 // FIXME: Factor out to avoid duplication with HTMLDocumentParser. 47 class NestingLevelIncrementer : public Noncopyable { 47 48 public: 48 NestScript(unsigned& nestingLevel, HTMLInputStream& inputStream)49 explicit NestingLevelIncrementer(unsigned& nestingLevel) 49 50 : m_nestingLevel(&nestingLevel) 50 , m_savedInsertionPoint(inputStream)51 51 { 52 52 ++(*m_nestingLevel); 53 53 } 54 54 55 ~Nest Script()55 ~NestingLevelIncrementer() 56 56 { 57 57 --(*m_nestingLevel); … … 60 60 private: 61 61 unsigned* m_nestingLevel; 62 InsertionPointRecord m_savedInsertionPoint;63 62 }; 64 63 … … 98 97 } 99 98 100 ScriptSourceCode HTMLScriptRunner::sourceFromPendingScript(const PendingScript& script, bool& errorOccurred) 99 ScriptSourceCode HTMLScriptRunner::sourceFromPendingScript(const PendingScript& script, bool& errorOccurred) const 101 100 { 102 101 if (script.cachedScript()) { … … 119 118 } 120 119 121 void HTMLScriptRunner::executeP endingScript()120 void HTMLScriptRunner::executeParsingBlockingScript() 122 121 { 123 122 ASSERT(!m_scriptNestingLevel); 124 123 ASSERT(m_document->haveStylesheetsLoaded()); 125 bool errorOccurred = false;126 124 ASSERT(isPendingScriptReady(m_parsingBlockingScript)); 127 ScriptSourceCode sourceCode = sourceFromPendingScript(m_parsingBlockingScript, errorOccurred);128 125 129 126 // Stop watching loads before executeScript to prevent recursion if the script reloads itself. … … 131 128 stopWatchingForLoad(m_parsingBlockingScript); 132 129 130 InsertionPointRecord insertionPointRecord(m_host->inputStream()); 131 executePendingScriptAndDispatchEvent(m_parsingBlockingScript); 132 } 133 134 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendingScript) 135 { 136 bool errorOccurred = false; 137 ScriptSourceCode sourceCode = sourceFromPendingScript(pendingScript, errorOccurred); 138 133 139 // Clear the pending script before possible rentrancy from executeScript() 134 RefPtr<Element> scriptElement = m_parsingBlockingScript.releaseElementAndClear();135 { 136 Nest Script nestingLevel(m_scriptNestingLevel, m_host->inputStream());140 RefPtr<Element> scriptElement = pendingScript.releaseElementAndClear(); 141 { 142 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); 137 143 if (errorOccurred) 138 144 scriptElement->dispatchEvent(createScriptErrorEvent()); … … 145 151 } 146 152 147 void HTMLScriptRunner::executeScript(Element* element, const ScriptSourceCode& sourceCode) 148 { 149 // FIXME: We do not block inline <script> tags on stylesheets for now. 150 // When we do, || !element->hasAttribute(srcAttr) should be removed from 151 // the ASSERT below. See https://bugs.webkit.org/show_bug.cgi?id=40047 152 ASSERT(m_document->haveStylesheetsLoaded() || !element->hasAttribute(srcAttr)); 153 void HTMLScriptRunner::executeScript(Element* element, const ScriptSourceCode& sourceCode) const 154 { 153 155 ScriptElement* scriptElement = toScriptElement(element); 154 156 ASSERT(scriptElement); … … 205 207 if (!isPendingScriptReady(m_parsingBlockingScript)) 206 208 return false; 207 executeP endingScript();209 executeParsingBlockingScript(); 208 210 } 209 211 return true; … … 229 231 } 230 232 231 void HTMLScriptRunner::requestScript(Element* script) 232 { 233 ASSERT(!m_parsingBlockingScript.element()); 234 AtomicString srcValue = script->getAttribute(srcAttr); 235 // Allow the host to disllow script loads (using the XSSAuditor, etc.) 236 if (!m_host->shouldLoadExternalScriptFromSrc(srcValue)) 233 void HTMLScriptRunner::requestParsingBlockingScript(Element* element) 234 { 235 if (!requestPendingScript(m_parsingBlockingScript, element)) 237 236 return; 238 // FIXME: We need to resolve the url relative to the element. 239 if (!script->dispatchBeforeLoadEvent(srcValue)) 240 return; 241 m_parsingBlockingScript.adoptElement(script); 242 // This should correctly return 0 for empty or invalid srcValues. 243 CachedScript* cachedScript = m_document->docLoader()->requestScript(srcValue, toScriptElement(script)->scriptCharset()); 244 if (!cachedScript) { 245 notImplemented(); // Dispatch error event. 246 return; 247 } 248 249 m_parsingBlockingScript.setCachedScript(cachedScript); 237 238 ASSERT(m_parsingBlockingScript.cachedScript()); 250 239 251 240 // We only care about a load callback if cachedScript is not already … … 256 245 } 257 246 247 bool HTMLScriptRunner::requestPendingScript(PendingScript& pendingScript, Element* script) const 248 { 249 ASSERT(!pendingScript.element()); 250 const AtomicString& srcValue = script->getAttribute(srcAttr); 251 // Allow the host to disllow script loads (using the XSSAuditor, etc.) 252 if (!m_host->shouldLoadExternalScriptFromSrc(srcValue)) 253 return false; 254 // FIXME: We need to resolve the url relative to the element. 255 if (!script->dispatchBeforeLoadEvent(srcValue)) 256 return false; 257 pendingScript.adoptElement(script); 258 // This should correctly return 0 for empty or invalid srcValues. 259 CachedScript* cachedScript = m_document->docLoader()->requestScript(srcValue, toScriptElement(script)->scriptCharset()); 260 if (!cachedScript) { 261 notImplemented(); // Dispatch error event. 262 return false; 263 } 264 pendingScript.setCachedScript(cachedScript); 265 return true; 266 } 267 258 268 // This method is meant to match the HTML5 definition of "running a script" 259 269 // http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#running-a-script … … 262 272 ASSERT(!haveParsingBlockingScript()); 263 273 { 264 NestScript nestingLevel(m_scriptNestingLevel, m_host->inputStream()); 274 InsertionPointRecord insertionPointRecord(m_host->inputStream()); 275 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); 265 276 266 277 // Check script type and language, current code uses ScriptElement::shouldExecuteAsJavaScript(), but that may not be HTML5 compliant. … … 269 280 if (script->hasAttribute(srcAttr)) { 270 281 // FIXME: Handle defer and async 271 request Script(script);282 requestParsingBlockingScript(script); 272 283 } else { 273 284 // FIXME: We do not block inline <script> tags on stylesheets to match the 274 // old parser for now. See https://bugs.webkit.org/show_bug.cgi?id=40047 285 // old parser for now. When we do, the ASSERT below should be added. 286 // See https://bugs.webkit.org/show_bug.cgi?id=40047 287 // ASSERT(document()->haveStylesheetsLoaded()); 288 ASSERT(isExecutingScript()); 275 289 ScriptSourceCode sourceCode(script->textContent(), documentURLForScriptExecution(m_document), startingLineNumber); 276 290 executeScript(script, sourceCode); -
trunk/WebCore/html/HTMLScriptRunner.h
r64857 r65350 53 53 bool executeScriptsWaitingForStylesheets(); 54 54 55 bool isExecutingScript() { return !!m_scriptNestingLevel; }55 bool isExecutingScript() const { return !!m_scriptNestingLevel; } 56 56 57 57 private: 58 58 Frame* frame() const; 59 59 60 void executeParsingBlockingScript(); 61 void executePendingScriptAndDispatchEvent(PendingScript&); 62 void executeScript(Element*, const ScriptSourceCode&) const; 60 63 bool haveParsingBlockingScript() const; 61 64 bool executeParsingBlockingScripts(); 62 void executePendingScript();63 65 64 void requestScript(Element*); 66 void requestParsingBlockingScript(Element*); 67 bool requestPendingScript(PendingScript&, Element*) const; 68 65 69 void runScript(Element*, int startingLineNumber); 66 70 … … 68 72 void watchForLoad(PendingScript&); 69 73 void stopWatchingForLoad(PendingScript&); 70 void executeScript(Element*, const ScriptSourceCode&);71 72 74 bool isPendingScriptReady(const PendingScript&); 73 ScriptSourceCode sourceFromPendingScript(const PendingScript&, bool& errorOccurred) ;75 ScriptSourceCode sourceFromPendingScript(const PendingScript&, bool& errorOccurred) const; 74 76 75 77 Document* m_document;
Note: See TracChangeset
for help on using the changeset viewer.