Index: Source/WebCore/bindings/dart/DartApplicationLoader.h |
diff --git a/Source/WebCore/bindings/dart/DartApplicationLoader.h b/Source/WebCore/bindings/dart/DartApplicationLoader.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..79e83ecf722e2f14676d6de9e965691d7bc94d51 |
--- /dev/null |
+++ b/Source/WebCore/bindings/dart/DartApplicationLoader.h |
@@ -0,0 +1,103 @@ |
+// Copyright 2011, Google Inc. |
+// All rights reserved. |
+// |
+// Redistribution and use in source and binary forms, with or without |
+// modification, are permitted provided that the following conditions are |
+// met: |
+// |
+// * Redistributions of source code must retain the above copyright |
+// notice, this list of conditions and the following disclaimer. |
+// * Redistributions in binary form must reproduce the above |
+// copyright notice, this list of conditions and the following disclaimer |
+// in the documentation and/or other materials provided with the |
+// distribution. |
+// * Neither the name of Google Inc. nor the names of its |
+// contributors may be used to endorse or promote products derived from |
+// this software without specific prior written permission. |
+// |
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ |
+#ifndef DartApplicationLoader_h |
+#define DartApplicationLoader_h |
+ |
+#include "ScriptSourceCode.h" |
+ |
+#include <dart_api.h> |
+#include <wtf/HashMap.h> |
+#include <wtf/HashSet.h> |
+#include <wtf/text/StringHash.h> |
+ |
+struct NPObject; |
+ |
+namespace WebCore { |
+ |
+class Document; |
+class KURL; |
+class ScriptSourceCode; |
+ |
+// FIXME: move into a file on its own when source reinjection is implemented. |
+class DartApplicationLoader : public ThreadSafeRefCounted<DartApplicationLoader> { |
+public: |
+ DartApplicationLoader(Document*, NPObject* layoutTestController); |
+ void load(const String& url, const String& source); |
+ void triggerImport(const String& libraryUrl, const String& importedUrl, Dart_LibraryTag); |
+ Dart_Handle reinject(Dart_Handle library, const String& libraryUrl, const String& importedUrl, Dart_LibraryTag); |
+ void reinjectSources(); |
+ bool isLoadingMainIsolate() const { return m_libraryUrl.isNull(); } |
+private: |
+ void importBuiltinLibrary(const String& url, const String& source); |
+ void reinjectLibrary(const ScriptSourceCode&); |
+ void scriptLoaded(const ScriptSourceCode&, Dart_Isolate); |
+ void scriptLoadError(const KURL&); |
+ void scriptLoadCancelled(const KURL&); |
+ |
+ static Dart_Handle reinjectTagHandler(Dart_LibraryTag, Dart_Handle, Dart_Handle); |
+ |
+ // Client must ensure that DartApplicationLoader doesn't outlive corresponding document. |
+ Document* m_document; |
+ NPObject* m_layoutTestController; |
+ String m_libraryUrl; |
+ |
+ void loadScript(const String& url, const String& source); |
+ void loadLibrary(const String& url, const String& source); |
+ void loadSource(const String& url, const String& source); |
+ void callEntryPoint(); |
+ |
+ Dart_Handle topLevelLibrary(); |
+ Dart_Handle domLibrary(); |
+ |
+ typedef HashSet<String> UrlSet; |
+ typedef HashMap<String, UrlSet*> UrlMultiMap; |
+ |
+ void add(UrlMultiMap&, const String& key, const String& value); |
+ |
+ UrlSet m_importedLibraries; |
+ UrlMultiMap m_importersForSource; |
+ |
+ // Sources of resources loaded from the URL. |
+ // We save them verbatim to be able to reinject them later. |
+ HashMap<String, String> m_sources; |
+ |
+ bool m_mainScriptHasBeenLoaded; |
+ |
+ friend class ScriptLoadCallback; |
+}; |
+ |
+// FIXME: consolidate when we have multiple isolates. |
+// FIXME: merge with DartUtilities' per isolate data. |
+typedef HashMap<Dart_Isolate, DartApplicationLoader*> IsolateToDartApplicationLoaderMap; |
+ |
+IsolateToDartApplicationLoaderMap& isolateToDartApplicationLoaderMap(); |
+} |
+ |
+#endif // DartApplicationLoader_h |