OLD | NEW |
(Empty) | |
| 1 // Copyright 2011, 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 DartApplicationLoader_h |
| 31 #define DartApplicationLoader_h |
| 32 |
| 33 #include "ScriptSourceCode.h" |
| 34 |
| 35 #include <dart_api.h> |
| 36 #include <wtf/HashMap.h> |
| 37 #include <wtf/HashSet.h> |
| 38 #include <wtf/text/StringHash.h> |
| 39 |
| 40 struct NPObject; |
| 41 |
| 42 namespace WebCore { |
| 43 |
| 44 class Document; |
| 45 class KURL; |
| 46 class ScriptSourceCode; |
| 47 |
| 48 // FIXME: move into a file on its own when source reinjection is implemented. |
| 49 class DartApplicationLoader : public ThreadSafeRefCounted<DartApplicationLoader>
{ |
| 50 public: |
| 51 DartApplicationLoader(Document*, NPObject* layoutTestController); |
| 52 void load(const String& url, const String& source); |
| 53 void triggerImport(const String& libraryUrl, const String& importedUrl, Dart
_LibraryTag); |
| 54 Dart_Handle reinject(Dart_Handle library, const String& libraryUrl, const St
ring& importedUrl, Dart_LibraryTag); |
| 55 void reinjectSources(); |
| 56 bool isLoadingMainIsolate() const { return m_libraryUrl.isNull(); } |
| 57 private: |
| 58 void importBuiltinLibrary(const String& url, const String& source); |
| 59 void reinjectLibrary(const ScriptSourceCode&); |
| 60 void scriptLoaded(const ScriptSourceCode&, Dart_Isolate); |
| 61 void scriptLoadError(const KURL&); |
| 62 void scriptLoadCancelled(const KURL&); |
| 63 |
| 64 static Dart_Handle reinjectTagHandler(Dart_LibraryTag, Dart_Handle, Dart_Han
dle); |
| 65 |
| 66 // Client must ensure that DartApplicationLoader doesn't outlive correspondi
ng document. |
| 67 Document* m_document; |
| 68 NPObject* m_layoutTestController; |
| 69 String m_libraryUrl; |
| 70 |
| 71 void loadScript(const String& url, const String& source); |
| 72 void loadLibrary(const String& url, const String& source); |
| 73 void loadSource(const String& url, const String& source); |
| 74 void callEntryPoint(); |
| 75 |
| 76 Dart_Handle topLevelLibrary(); |
| 77 Dart_Handle domLibrary(); |
| 78 |
| 79 typedef HashSet<String> UrlSet; |
| 80 typedef HashMap<String, UrlSet*> UrlMultiMap; |
| 81 |
| 82 void add(UrlMultiMap&, const String& key, const String& value); |
| 83 |
| 84 UrlSet m_importedLibraries; |
| 85 UrlMultiMap m_importersForSource; |
| 86 |
| 87 // Sources of resources loaded from the URL. |
| 88 // We save them verbatim to be able to reinject them later. |
| 89 HashMap<String, String> m_sources; |
| 90 |
| 91 bool m_mainScriptHasBeenLoaded; |
| 92 |
| 93 friend class ScriptLoadCallback; |
| 94 }; |
| 95 |
| 96 // FIXME: consolidate when we have multiple isolates. |
| 97 // FIXME: merge with DartUtilities' per isolate data. |
| 98 typedef HashMap<Dart_Isolate, DartApplicationLoader*> IsolateToDartApplicationLo
aderMap; |
| 99 |
| 100 IsolateToDartApplicationLoaderMap& isolateToDartApplicationLoaderMap(); |
| 101 } |
| 102 |
| 103 #endif // DartApplicationLoader_h |
OLD | NEW |