Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Unified Diff: Source/bindings/dart/DartAsyncLoader.h

Issue 26490003: Reapply "Move isolate loading to a separate loader isolate." (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Initialize flag properly Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/dart/DartApplicationLoader.cpp ('k') | Source/bindings/dart/DartAsyncLoader.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/dart/DartAsyncLoader.h
diff --git a/Source/bindings/dart/DartAsyncLoader.h b/Source/bindings/dart/DartAsyncLoader.h
new file mode 100644
index 0000000000000000000000000000000000000000..31cf6f874dcad92a9d4279075a6b45886c6a071e
--- /dev/null
+++ b/Source/bindings/dart/DartAsyncLoader.h
@@ -0,0 +1,116 @@
+// Copyright 2013, 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 DartAsyncLoader_h
+#define DartAsyncLoader_h
+
+#include "core/dom/Document.h"
+#include "wtf/HashMap.h"
+#include "wtf/HashSet.h"
+
+#include <dart_api.h>
+
+namespace WebCore {
+
+class FetchRequest;
+class KURL;
+class ScriptLoader;
+class ScriptResource;
+
+class DartAsyncLoader : public RefCounted<DartAsyncLoader> {
+public:
+ class LoadCallback : public RefCounted<LoadCallback> {
+ public:
+ LoadCallback(Document* originDocument, ScriptLoader* scriptLoader = 0)
+ : m_originDocument(originDocument)
+ , m_scriptLoader(scriptLoader) { }
+
+ virtual ~LoadCallback() { }
+
+ virtual void ready(PassRefPtr<DartAsyncLoader>) = 0;
+ void reportError(const String& error, const String& url);
+
+ KURL completeURL(const String& url) { return m_originDocument->completeURL(url); }
+ ResourcePtr<ScriptResource> requestScript(FetchRequest&);
+
+ Document* document() const { return m_originDocument; }
+
+ private:
+ Document* m_originDocument;
+ ScriptLoader* m_scriptLoader;
+ };
+
+ DartAsyncLoader(const String&, PassRefPtr<LoadCallback>);
+ ~DartAsyncLoader();
+
+ void process(const String& url, const String& source, intptr_t lineNumber);
+ void fetchScriptResource(const String& url);
+
+ // The main script has been processed. The top-level source and lineNumber are valid.
+ bool mainScriptFetched() const { return m_mainScriptFetched; }
+
+ // All dependences are available.
+ bool ready() const { return mainScriptFetched() && m_pendingLibraries.isEmpty() && m_pendingSource.isEmpty(); }
+
+ bool contains(const String& url) const { return m_urlSourceMap.contains(url); }
+ String get(const String& url) const { return m_urlSourceMap.get(url); }
+
+ typedef HashMap<String, String> UrlSourceMap;
+
+ const String& scriptUrl() const { return m_topUrl; }
+ const String& scriptSource() const { return m_topSource; }
+ intptr_t scriptLineNumber() const { return m_lineNumber; }
+
+private:
+ void findDependences(const String& url, const String& source, intptr_t lineNumber);
+ void processLibrary(const String& url, const String& source);
+ void reportError(Dart_Handle error, const String& url);
+ void reportError(const String& error, const String& url) { m_loadCallback->reportError(error, url); }
+ static Dart_Handle libraryTagHandlerCallback(Dart_LibraryTag, Dart_Handle library, Dart_Handle urlHandle);
+
+ RefPtr<LoadCallback> m_loadCallback;
+
+ typedef HashSet<String> UrlSet;
+
+ UrlSourceMap m_urlSourceMap;
+ UrlSet m_pendingLibraries;
+ UrlSet m_pendingSource;
+ bool m_mainScriptFetched;
+ String m_topUrl;
+ String m_topSource;
+ intptr_t m_lineNumber;
+
+ // Private isolate for parsing and processing Dart files.
+ Dart_Isolate m_parseIsolate;
+
+ friend class ScriptLoadedCallback;
+};
+
+}
+#endif // DartAsyncLoader_h
« no previous file with comments | « Source/bindings/dart/DartApplicationLoader.cpp ('k') | Source/bindings/dart/DartAsyncLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698