Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef HTMLScriptRunner_h | 26 #ifndef HTMLScriptRunner_h |
| 27 #define HTMLScriptRunner_h | 27 #define HTMLScriptRunner_h |
| 28 | 28 |
| 29 #include "core/dom/PendingScript.h" | 29 #include "core/dom/PendingScript.h" |
| 30 #include "core/fetch/ResourceClient.h" | |
| 31 #include "platform/heap/Handle.h" | |
| 30 #include "wtf/Deque.h" | 32 #include "wtf/Deque.h" |
| 31 #include "wtf/PassRefPtr.h" | 33 #include "wtf/PassRefPtr.h" |
| 32 #include "wtf/text/TextPosition.h" | 34 #include "wtf/text/TextPosition.h" |
| 33 | 35 |
| 34 namespace WebCore { | 36 namespace WebCore { |
| 35 | 37 |
| 36 class Resource; | 38 class Resource; |
| 37 class ScriptResource; | 39 class ScriptResource; |
| 38 class Document; | 40 class Document; |
| 39 class Element; | 41 class Element; |
| 40 class LocalFrame; | 42 class LocalFrame; |
| 41 class HTMLScriptRunnerHost; | 43 class HTMLScriptRunnerHost; |
| 42 class ScriptSourceCode; | 44 class ScriptSourceCode; |
| 43 | 45 |
| 44 class HTMLScriptRunner { | 46 class HTMLScriptRunner FINAL : public NoBaseWillBeGarbageCollectedFinalized<HTML ScriptRunner>, private ResourceClient { |
| 45 WTF_MAKE_NONCOPYABLE(HTMLScriptRunner); WTF_MAKE_FAST_ALLOCATED; | 47 WTF_MAKE_NONCOPYABLE(HTMLScriptRunner); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMO VED; |
| 46 public: | 48 public: |
| 47 static PassOwnPtr<HTMLScriptRunner> create(Document* document, HTMLScriptRun nerHost* host) | 49 static PassOwnPtrWillBeRawPtr<HTMLScriptRunner> create(Document* document, H TMLScriptRunnerHost* host) |
| 48 { | 50 { |
| 49 return adoptPtr(new HTMLScriptRunner(document, host)); | 51 return adoptPtrWillBeNoop(new HTMLScriptRunner(document, host)); |
| 50 } | 52 } |
| 51 ~HTMLScriptRunner(); | 53 ~HTMLScriptRunner(); |
| 52 | 54 |
| 53 void detach(); | 55 void detach(); |
| 54 | 56 |
| 55 // Processes the passed in script and any pending scripts if possible. | 57 // Processes the passed in script and any pending scripts if possible. |
| 56 void execute(PassRefPtr<Element> scriptToProcess, const TextPosition& script StartPosition); | 58 void execute(PassRefPtrWillBeRawPtr<Element> scriptToProcess, const TextPosi tion& scriptStartPosition); |
| 57 | 59 |
| 58 void executeScriptsWaitingForLoad(Resource*); | 60 void executeScriptsWaitingForLoad(Resource*); |
| 59 bool hasScriptsWaitingForResources() const { return m_hasScriptsWaitingForRe sources; } | 61 bool hasScriptsWaitingForResources() const { return m_hasScriptsWaitingForRe sources; } |
| 60 void executeScriptsWaitingForResources(); | 62 void executeScriptsWaitingForResources(); |
| 61 bool executeScriptsWaitingForParsing(); | 63 bool executeScriptsWaitingForParsing(); |
| 62 | 64 |
| 63 bool hasParserBlockingScript() const; | 65 bool hasParserBlockingScript() const; |
| 64 bool isExecutingScript() const { return !!m_scriptNestingLevel; } | 66 bool isExecutingScript() const { return !!m_scriptNestingLevel; } |
| 65 | 67 |
| 68 // ResourceClient | |
| 69 virtual void notifyFinished(Resource*) OVERRIDE; | |
| 70 | |
| 71 void trace(Visitor*); | |
| 72 | |
| 66 private: | 73 private: |
| 67 HTMLScriptRunner(Document*, HTMLScriptRunnerHost*); | 74 HTMLScriptRunner(Document*, HTMLScriptRunnerHost*); |
| 68 | 75 |
| 69 LocalFrame* frame() const; | 76 LocalFrame* frame() const; |
| 70 | 77 |
| 71 enum PendingScriptType { | 78 enum PendingScriptType { |
| 72 PendingScriptBlockingParser, | 79 PendingScriptBlockingParser, |
| 73 PendingScriptDeferred | 80 PendingScriptDeferred |
| 74 }; | 81 }; |
| 75 | 82 |
| 76 void executeParsingBlockingScript(); | 83 void executeParsingBlockingScript(); |
| 77 void executePendingScriptAndDispatchEvent(PendingScript&, PendingScriptType) ; | 84 void executePendingScriptAndDispatchEvent(PendingScript&, PendingScriptType) ; |
| 78 void executeParsingBlockingScripts(); | 85 void executeParsingBlockingScripts(); |
| 79 | 86 |
| 80 void requestParsingBlockingScript(Element*); | 87 void requestParsingBlockingScript(Element*); |
| 81 void requestDeferredScript(Element*); | 88 void requestDeferredScript(Element*); |
| 82 bool requestPendingScript(PendingScript&, Element*) const; | 89 bool requestPendingScript(PendingScript&, Element*) const; |
| 83 | 90 |
| 84 void runScript(Element*, const TextPosition& scriptStartPosition); | 91 void runScript(Element*, const TextPosition& scriptStartPosition); |
| 85 | 92 |
| 86 // Helpers for dealing with HTMLScriptRunnerHost | 93 // Helpers for dealing with HTMLScriptRunnerHost |
| 87 void watchForLoad(PendingScript&); | 94 void watchForLoad(PendingScript&); |
| 88 void stopWatchingForLoad(PendingScript&); | 95 void stopWatchingForLoad(PendingScript&); |
| 89 bool isPendingScriptReady(const PendingScript&); | 96 bool isPendingScriptReady(const PendingScript&); |
| 90 ScriptSourceCode sourceFromPendingScript(const PendingScript&, bool& errorOc curred) const; | 97 ScriptSourceCode sourceFromPendingScript(const PendingScript&, bool& errorOc curred) const; |
| 91 | 98 |
| 92 Document* m_document; | 99 RawPtrWillBeMember<Document> m_document; |
| 93 HTMLScriptRunnerHost* m_host; | 100 HTMLScriptRunnerHost* m_host; |
|
haraken
2014/05/29 01:46:08
This raw pointer looks OK, but it'd be better if w
sof
2014/05/29 06:02:07
Yes, it is safe.
| |
| 94 PendingScript m_parserBlockingScript; | 101 PendingScript m_parserBlockingScript; |
| 95 Deque<PendingScript> m_scriptsToExecuteAfterParsing; // http://www.whatwg.or g/specs/web-apps/current-work/#list-of-scripts-that-will-execute-when-the-docume nt-has-finished-parsing | 102 Deque<PendingScript> m_scriptsToExecuteAfterParsing; // http://www.whatwg.or g/specs/web-apps/current-work/#list-of-scripts-that-will-execute-when-the-docume nt-has-finished-parsing |
|
haraken
2014/05/29 01:46:08
Add a FIXME to change this to a HeapDeque.
sof
2014/05/29 06:02:07
It's a non-heap version for a reason. i.e., we can
| |
| 96 unsigned m_scriptNestingLevel; | 103 unsigned m_scriptNestingLevel; |
| 97 | 104 |
| 98 // We only want stylesheet loads to trigger script execution if script | 105 // We only want stylesheet loads to trigger script execution if script |
| 99 // execution is currently stopped due to stylesheet loads, otherwise we'd | 106 // execution is currently stopped due to stylesheet loads, otherwise we'd |
| 100 // cause nested script execution when parsing <style> tags since </style> | 107 // cause nested script execution when parsing <style> tags since </style> |
| 101 // tags can cause Document to call executeScriptsWaitingForResources. | 108 // tags can cause Document to call executeScriptsWaitingForResources. |
| 102 bool m_hasScriptsWaitingForResources; | 109 bool m_hasScriptsWaitingForResources; |
| 103 }; | 110 }; |
| 104 | 111 |
| 105 } | 112 } |
| 106 | 113 |
| 107 #endif | 114 #endif |
| OLD | NEW |