OLD | NEW |
(Empty) | |
| 1 // Copyright 2013, Google Inc. |
| 2 // All rights reserved. |
| 3 // |
| 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are |
| 6 // met: |
| 7 // |
| 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above |
| 11 // copyright notice, this list of conditions and the following disclaimer |
| 12 // in the documentation and/or other materials provided with the |
| 13 // distribution. |
| 14 // * Neither the name of Google Inc. nor the names of its |
| 15 // contributors may be used to endorse or promote products derived from |
| 16 // this software without specific prior written permission. |
| 17 // |
| 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
| 30 #ifndef DartAsyncLoader_h |
| 31 #define DartAsyncLoader_h |
| 32 |
| 33 #include "core/dom/Document.h" |
| 34 #include "wtf/HashMap.h" |
| 35 #include "wtf/HashSet.h" |
| 36 |
| 37 #include <dart_api.h> |
| 38 |
| 39 namespace WebCore { |
| 40 |
| 41 class FetchRequest; |
| 42 class KURL; |
| 43 class ScriptLoader; |
| 44 class ScriptResource; |
| 45 |
| 46 class DartAsyncLoader : public RefCounted<DartAsyncLoader> { |
| 47 public: |
| 48 class LoadCallback : public RefCounted<LoadCallback> { |
| 49 public: |
| 50 LoadCallback(Document* originDocument, ScriptLoader* scriptLoader = 0) |
| 51 : m_originDocument(originDocument) |
| 52 , m_scriptLoader(scriptLoader) { } |
| 53 |
| 54 virtual ~LoadCallback() { } |
| 55 |
| 56 virtual void ready(PassRefPtr<DartAsyncLoader>) = 0; |
| 57 void reportError(const String& error, const String& url); |
| 58 |
| 59 KURL completeURL(const String& url) { return m_originDocument->completeU
RL(url); } |
| 60 ResourcePtr<ScriptResource> requestScript(FetchRequest&); |
| 61 |
| 62 Document* document() const { return m_originDocument; } |
| 63 |
| 64 private: |
| 65 Document* m_originDocument; |
| 66 ScriptLoader* m_scriptLoader; |
| 67 }; |
| 68 |
| 69 DartAsyncLoader(const String&, PassRefPtr<LoadCallback>); |
| 70 ~DartAsyncLoader(); |
| 71 |
| 72 void process(const String& url, const String& source, intptr_t lineNumber); |
| 73 void fetchScriptResource(const String& url); |
| 74 |
| 75 // The main script has been processed. The top-level source and lineNumber a
re valid. |
| 76 bool mainScriptFetched() const { return m_mainScriptFetched; } |
| 77 |
| 78 // All dependences are available. |
| 79 bool ready() const { return mainScriptFetched() && m_pendingLibraries.isEmpt
y() && m_pendingSource.isEmpty(); } |
| 80 |
| 81 bool contains(const String& url) const { return m_urlSourceMap.contains(url)
; } |
| 82 String get(const String& url) const { return m_urlSourceMap.get(url); } |
| 83 |
| 84 typedef HashMap<String, String> UrlSourceMap; |
| 85 |
| 86 const String& scriptUrl() const { return m_topUrl; } |
| 87 const String& scriptSource() const { return m_topSource; } |
| 88 intptr_t scriptLineNumber() const { return m_lineNumber; } |
| 89 |
| 90 private: |
| 91 void findDependences(const String& url, const String& source, intptr_t lineN
umber); |
| 92 void processLibrary(const String& url, const String& source); |
| 93 void reportError(Dart_Handle error, const String& url); |
| 94 void reportError(const String& error, const String& url) { m_loadCallback->r
eportError(error, url); } |
| 95 static Dart_Handle libraryTagHandlerCallback(Dart_LibraryTag, Dart_Handle li
brary, Dart_Handle urlHandle); |
| 96 |
| 97 RefPtr<LoadCallback> m_loadCallback; |
| 98 |
| 99 typedef HashSet<String> UrlSet; |
| 100 |
| 101 UrlSourceMap m_urlSourceMap; |
| 102 UrlSet m_pendingLibraries; |
| 103 UrlSet m_pendingSource; |
| 104 bool m_mainScriptFetched; |
| 105 String m_topUrl; |
| 106 String m_topSource; |
| 107 intptr_t m_lineNumber; |
| 108 |
| 109 // Private isolate for parsing and processing Dart files. |
| 110 Dart_Isolate m_parseIsolate; |
| 111 |
| 112 friend class ScriptLoadedCallback; |
| 113 }; |
| 114 |
| 115 } |
| 116 #endif // DartAsyncLoader_h |
OLD | NEW |