Index: Source/bindings/core/v8/V8ScriptStreamer.h |
diff --git a/Source/bindings/core/v8/V8ScriptStreamer.h b/Source/bindings/core/v8/V8ScriptStreamer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d7ce4377221e573e6f0bbcdb0a8656bc4c20b7e1 |
--- /dev/null |
+++ b/Source/bindings/core/v8/V8ScriptStreamer.h |
@@ -0,0 +1,86 @@ |
+/* |
+ * Copyright (C) 2014 Google Inc. All rights reserved. |
haraken
2014/08/17 16:05:27
Nit: Use the 3-line copyright.
// Copyright 2014
marja
2014/08/20 11:45:55
Done.
|
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions |
+ * are met: |
+ * 1. Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * 2. 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. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS 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 APPLE INC. OR ITS 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 V8ScriptStreamer_h |
+#define V8ScriptStreamer_h |
+ |
+#include "wtf/RefCounted.h" |
+ |
+#include <v8.h> |
+ |
+namespace blink { |
+ |
+class HTMLScriptRunner; |
+class PendingScript; |
+class ScriptResource; |
+class SourceStream; |
+ |
+// V8ScriptStreamer streams incomplete script data to V8 so that it can be |
+// parsed while it's loaded. PendingScript holds a reference to |
+// V8ScriptStreamer. At the moment, V8ScriptStreamer is only used for parser |
+// blocking scripts; this means that the Document stays stable and no other |
+// scripts are executing while we're streaming. It is possible, though, that |
+// Document and the PendingScript are destroyed while the streaming is in |
+// progress, and V8ScriptStreamer handles it gracefully. |
+class V8ScriptStreamer : public RefCounted<V8ScriptStreamer> { |
haraken
2014/08/17 16:05:27
(We might want to move V8ScriptStreamer to oilpan'
haraken
2014/08/17 16:05:27
V8ScriptStreamer => ScriptStreamer
We're planning
marja
2014/08/20 11:45:55
Acknowledged.
marja
2014/08/20 11:45:56
Done.
|
+public: |
+ static bool startStreaming(PendingScript*, HTMLScriptRunner*); |
haraken
2014/08/17 16:05:27
Add a comment about what startStreaming() does.
marja
2014/08/20 11:45:55
Done.
|
+ |
+ bool streamingInProgress() const { return !m_loadingDone || !m_v8Done; } |
+ |
+ v8::ScriptCompiler::StreamedSource* source() { return &m_source; } |
+ |
+ // Called when data arrives from the network. |
+ void notifyAppendData(); |
+ void notifyFinished(); |
+ |
+ // Called when we have streamed all data to V8 and it has processed it. |
+ void streamingComplete(); |
+ |
+ // Cancel is called if the PendingScript is deleted and we don't need to |
+ // stream the script any more. After calling cancel, PendingScript will drop |
+ // its reference, and V8ScriptStreamer takes care of deleting itself. |
+ void cancel(); |
+ |
+ unsigned cachedDataDataType() const { return m_cachedDataDataType; } |
+ |
+private: |
+ V8ScriptStreamer(PendingScript*, HTMLScriptRunner*); |
haraken
2014/08/17 16:05:27
Why do both V8ScriptStreamer's constructor and sta
marja
2014/08/20 11:45:55
startStreaming is a static function which construc
|
+ |
+ // This pointer is weak, and the PendingScript can be deleted before |
+ // V8ScriptStreamer. However, it'll notify V8ScriptStreamer of its deletion |
+ // by calling cancel(). |
+ PendingScript* m_script; |
+ HTMLScriptRunner* m_runner; |
+ SourceStream* m_stream; |
+ v8::ScriptCompiler::StreamedSource m_source; |
+ bool m_loadingDone; // Whether loading from the network is done. |
+ bool m_v8Done; // Whether the V8 side processing is done. |
+ unsigned m_cachedDataDataType; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // V8ScriptStreamer_h |