| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SKY_ENGINE_CORE_HTML_PARSER_HTMLSCRIPTRUNNER_H_ | |
| 6 #define SKY_ENGINE_CORE_HTML_PARSER_HTMLSCRIPTRUNNER_H_ | |
| 7 | |
| 8 #include "base/memory/weak_ptr.h" | |
| 9 #include "sky/engine/core/app/AbstractModule.h" | |
| 10 #include "sky/engine/core/html/HTMLElement.h" | |
| 11 #include "sky/engine/wtf/Vector.h" | |
| 12 #include "sky/engine/wtf/text/TextPosition.h" | |
| 13 | |
| 14 namespace blink { | |
| 15 | |
| 16 class HTMLScriptRunnerHost { | |
| 17 public: | |
| 18 virtual void scriptExecutionCompleted() = 0; | |
| 19 }; | |
| 20 | |
| 21 // Dart script blocks can include 'import' statements which can introduce | |
| 22 // additional dependencies which need to be resolved before the script can | |
| 23 // be executed. The job of this class is to insulate the rest of the system | |
| 24 // from this complexity and take in a script and always produce a callback | |
| 25 // to continue parsing when that script completes/errors out, etc. | |
| 26 | |
| 27 class HTMLScriptRunner { | |
| 28 public: | |
| 29 static PassOwnPtr<HTMLScriptRunner> createForScript( | |
| 30 PassRefPtr<HTMLScriptElement>, | |
| 31 TextPosition, | |
| 32 HTMLScriptRunnerHost*); | |
| 33 ~HTMLScriptRunner(); | |
| 34 | |
| 35 void start(); | |
| 36 | |
| 37 bool isExecutingScript() const; | |
| 38 | |
| 39 private: | |
| 40 HTMLScriptRunner(PassRefPtr<HTMLScriptElement>, | |
| 41 TextPosition, | |
| 42 HTMLScriptRunnerHost*); | |
| 43 | |
| 44 enum State { | |
| 45 StateInitial, // No script. | |
| 46 StateLoading, // Waiting on imports to load. | |
| 47 StateExecuting, // Actually running the script. | |
| 48 StateCompleted, // Done, always hit this state regardless of success. | |
| 49 }; | |
| 50 | |
| 51 enum AdvanceType { | |
| 52 ExecutionNormal, | |
| 53 ExecutionFailure, | |
| 54 }; | |
| 55 | |
| 56 // Advancing to StateCompleted may cause the host to delete us. | |
| 57 void advanceTo(State, AdvanceType = ExecutionNormal); | |
| 58 | |
| 59 void executeLibrary(RefPtr<AbstractModule> module, RefPtr<DartValue> library); | |
| 60 void scriptFailed(); | |
| 61 | |
| 62 HTMLScriptRunnerHost* m_host; | |
| 63 RefPtr<HTMLScriptElement> m_element; | |
| 64 TextPosition m_position; | |
| 65 State m_state; | |
| 66 base::WeakPtrFactory<HTMLScriptRunner> m_weakFactory; | |
| 67 }; | |
| 68 | |
| 69 } // namespace blink | |
| 70 | |
| 71 #endif // SKY_ENGINE_CORE_HTML_PARSER_HTMLSCRIPTRUNNER_H_ | |
| OLD | NEW |