OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SKY_ENGINE_CORE_HTML_PARSER_HTMLSCRIPTRUNNER_H_ | 5 #ifndef SKY_ENGINE_CORE_HTML_PARSER_HTMLSCRIPTRUNNER_H_ |
6 #define SKY_ENGINE_CORE_HTML_PARSER_HTMLSCRIPTRUNNER_H_ | 6 #define SKY_ENGINE_CORE_HTML_PARSER_HTMLSCRIPTRUNNER_H_ |
7 | 7 |
| 8 #include "base/memory/weak_ptr.h" |
| 9 #include "sky/engine/core/app/AbstractModule.h" |
8 #include "sky/engine/core/html/HTMLElement.h" | 10 #include "sky/engine/core/html/HTMLElement.h" |
9 #include "sky/engine/wtf/Vector.h" | 11 #include "sky/engine/wtf/Vector.h" |
10 #include "sky/engine/wtf/text/TextPosition.h" | 12 #include "sky/engine/wtf/text/TextPosition.h" |
11 | 13 |
12 namespace blink { | 14 namespace blink { |
13 | 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 |
14 class HTMLScriptRunner { | 27 class HTMLScriptRunner { |
15 public: | 28 public: |
16 HTMLScriptRunner(); | 29 static PassOwnPtr<HTMLScriptRunner> createForScript( |
| 30 PassRefPtr<HTMLScriptElement>, |
| 31 TextPosition, |
| 32 HTMLScriptRunnerHost*); |
17 ~HTMLScriptRunner(); | 33 ~HTMLScriptRunner(); |
18 | 34 |
19 bool isExecutingScript() const { return m_isExecutingScript; } | 35 void start(); |
20 | 36 |
21 void runScript(PassRefPtr<HTMLScriptElement>, TextPosition); | 37 bool isExecutingScript() const; |
22 | 38 |
23 private: | 39 private: |
24 void executeScript(PassRefPtr<HTMLScriptElement>, TextPosition); | 40 HTMLScriptRunner(PassRefPtr<HTMLScriptElement>, |
| 41 TextPosition, |
| 42 HTMLScriptRunnerHost*); |
25 | 43 |
26 bool m_isExecutingScript; | 44 enum State { |
27 TextPosition m_textPosition; | 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; |
28 }; | 67 }; |
29 | 68 |
30 } // namespace blink | 69 } // namespace blink |
31 | 70 |
32 #endif // SKY_ENGINE_CORE_HTML_PARSER_HTMLSCRIPTRUNNER_H_ | 71 #endif // SKY_ENGINE_CORE_HTML_PARSER_HTMLSCRIPTRUNNER_H_ |
OLD | NEW |