Add IDL files for native ReadableStream

Design doc:
https://docs.google.com/document/d/1n0IIRmJb0R-DFc2IhhJfS2-LUwl6iKSBNaR0klr3o40/edit

Bug: 902633
Change-Id: I5f2c70db01019af9816980c2c83b0f1840ecfe3d
Reviewed-on: https://chromium-review.googlesource.com/c/1454346
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Reviewed-by: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629481}
diff --git a/third_party/blink/renderer/core/core_idl_files.gni b/third_party/blink/renderer/core/core_idl_files.gni
index d353f25..da867fb 100644
--- a/third_party/blink/renderer/core/core_idl_files.gni
+++ b/third_party/blink/renderer/core/core_idl_files.gni
@@ -327,6 +327,8 @@
                     "resize_observer/resize_observer.idl",
                     "resize_observer/resize_observer_entry.idl",
                     "streams/readable_stream.idl",
+                    "streams/readable_stream_default_controller.idl",
+                    "streams/readable_stream_default_reader.idl",
                     "streams/transform_stream.idl",
                     "streams/writable_stream.idl",
                     "streams/writable_stream_default_controller.idl",
diff --git a/third_party/blink/renderer/core/streams/BUILD.gn b/third_party/blink/renderer/core/streams/BUILD.gn
index f4a85ea..0353f0e 100644
--- a/third_party/blink/renderer/core/streams/BUILD.gn
+++ b/third_party/blink/renderer/core/streams/BUILD.gn
@@ -12,7 +12,11 @@
     "queue_with_sizes.h",
     "readable_stream.cc",
     "readable_stream.h",
+    "readable_stream_default_controller.cc",
+    "readable_stream_default_controller.h",
     "readable_stream_default_controller_wrapper.h",
+    "readable_stream_default_reader.cc",
+    "readable_stream_default_reader.h",
     "readable_stream_operations.cc",
     "readable_stream_operations.h",
     "retain_wrapper_during_construction.cc",
diff --git a/third_party/blink/renderer/core/streams/readable_stream_default_controller.cc b/third_party/blink/renderer/core/streams/readable_stream_default_controller.cc
new file mode 100644
index 0000000..94de7a4
--- /dev/null
+++ b/third_party/blink/renderer/core/streams/readable_stream_default_controller.cc
@@ -0,0 +1,31 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "third_party/blink/renderer/core/streams/readable_stream_default_controller.h"
+
+#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
+
+namespace blink {
+
+void ReadableStreamDefaultController::close(ScriptState* script_state) {}
+
+void ReadableStreamDefaultController::enqueue(ScriptState* script_state,
+                                              ExceptionState& exception_state) {
+}
+
+void ReadableStreamDefaultController::enqueue(ScriptState* script_state,
+                                              ScriptValue chunk,
+                                              ExceptionState& exception_state) {
+}
+
+void ReadableStreamDefaultController::error(ScriptState* script_state) {
+  return;
+}
+
+void ReadableStreamDefaultController::error(ScriptState* script_state,
+                                            ScriptValue e) {
+  return;
+}
+
+}  // namespace blink
diff --git a/third_party/blink/renderer/core/streams/readable_stream_default_controller.h b/third_party/blink/renderer/core/streams/readable_stream_default_controller.h
new file mode 100644
index 0000000..49e4a01
--- /dev/null
+++ b/third_party/blink/renderer/core/streams/readable_stream_default_controller.h
@@ -0,0 +1,31 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_READABLE_STREAM_DEFAULT_CONTROLLER_H_
+#define THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_READABLE_STREAM_DEFAULT_CONTROLLER_H_
+
+#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
+#include "third_party/blink/renderer/platform/bindings/trace_wrapper_member.h"
+#include "v8/include/v8.h"
+
+namespace blink {
+
+class ExceptionState;
+class ScriptState;
+class ScriptValue;
+
+class ReadableStreamDefaultController : public ScriptWrappable {
+  DEFINE_WRAPPERTYPEINFO();
+
+ public:
+  void close(ScriptState*);
+  void enqueue(ScriptState*, ExceptionState&);
+  void enqueue(ScriptState*, ScriptValue chunk, ExceptionState&);
+  void error(ScriptState*);
+  void error(ScriptState*, ScriptValue e);
+};
+
+}  // namespace blink
+
+#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_READABLE_STREAM_DEFAULT_CONTROLLER_H_
diff --git a/third_party/blink/renderer/core/streams/readable_stream_default_controller.idl b/third_party/blink/renderer/core/streams/readable_stream_default_controller.idl
new file mode 100644
index 0000000..9a587c7
--- /dev/null
+++ b/third_party/blink/renderer/core/streams/readable_stream_default_controller.idl
@@ -0,0 +1,17 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This is only used when the new C++ implementation is enabled.
+
+// https://streams.spec.whatwg.org/#rs-default-controller-class-definition
+[
+    Exposed=(Window,Worker,Worklet),
+    NoInterfaceObject,
+    RaisesException=Constructor
+] interface ReadableStreamDefaultController {
+    [CallWith=ScriptState, NotEnumerable] void close();
+    [CallWith=ScriptState, NotEnumerable, RaisesException] void enqueue(
+        optional any chunk);
+    [CallWith=ScriptState, NotEnumerable] void error(optional any e);
+};
diff --git a/third_party/blink/renderer/core/streams/readable_stream_default_reader.cc b/third_party/blink/renderer/core/streams/readable_stream_default_reader.cc
new file mode 100644
index 0000000..87e45d8
--- /dev/null
+++ b/third_party/blink/renderer/core/streams/readable_stream_default_reader.cc
@@ -0,0 +1,75 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "third_party/blink/renderer/core/streams/readable_stream_default_reader.h"
+
+#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
+#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
+#include "third_party/blink/renderer/core/streams/stream_promise_resolver.h"
+#include "third_party/blink/renderer/platform/bindings/exception_state.h"
+#include "third_party/blink/renderer/platform/bindings/script_state.h"
+#include "third_party/blink/renderer/platform/bindings/v8_binding.h"
+#include "v8/include/v8.h"
+
+namespace blink {
+
+ReadableStreamDefaultReader* ReadableStreamDefaultReader::Create(
+    ScriptState* script_state,
+    ReadableStream* stream,
+    ExceptionState& exception_state) {
+  ThrowUnimplemented(exception_state);
+  return nullptr;
+}
+
+ReadableStreamDefaultReader::ReadableStreamDefaultReader(
+    ScriptState* script_state,
+    ReadableStreamNative* stream,
+    ExceptionState& exception_state) {
+  ThrowUnimplemented(exception_state);
+  return;
+}
+
+ReadableStreamDefaultReader::~ReadableStreamDefaultReader() = default;
+
+ScriptPromise ReadableStreamDefaultReader::closed(
+    ScriptState* script_state) const {
+  return RejectUnimplemented(script_state);
+}
+
+ScriptPromise ReadableStreamDefaultReader::cancel(ScriptState* script_state) {
+  return RejectUnimplemented(script_state);
+}
+
+ScriptPromise ReadableStreamDefaultReader::cancel(ScriptState* script_state,
+                                                  ScriptValue reason) {
+  return RejectUnimplemented(script_state);
+}
+
+ScriptPromise ReadableStreamDefaultReader::read(ScriptState* script_state) {
+  return RejectUnimplemented(script_state);
+}
+
+ScriptPromise ReadableStreamDefaultReader::read(ScriptState* script_state,
+                                                ScriptValue chunk) {
+  return RejectUnimplemented(script_state);
+}
+
+void ReadableStreamDefaultReader::releaseLock(ScriptState* script_state) {
+  return;
+}
+
+void ReadableStreamDefaultReader::ThrowUnimplemented(
+    ExceptionState& exception_state) {
+  exception_state.ThrowTypeError("unimplemented");
+}
+
+ScriptPromise ReadableStreamDefaultReader::RejectUnimplemented(
+    ScriptState* script_state) {
+  return StreamPromiseResolver::CreateRejected(
+             script_state, v8::Exception::TypeError(V8String(
+                               script_state->GetIsolate(), "unimplemented")))
+      ->GetScriptPromise(script_state);
+}
+
+}  // namespace blink
diff --git a/third_party/blink/renderer/core/streams/readable_stream_default_reader.h b/third_party/blink/renderer/core/streams/readable_stream_default_reader.h
new file mode 100644
index 0000000..ad7d9ef
--- /dev/null
+++ b/third_party/blink/renderer/core/streams/readable_stream_default_reader.h
@@ -0,0 +1,51 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_READABLE_STREAM_DEFAULT_READER_H_
+#define THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_READABLE_STREAM_DEFAULT_READER_H_
+
+#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
+#include "third_party/blink/renderer/platform/bindings/trace_wrapper_member.h"
+#include "v8/include/v8.h"
+
+namespace blink {
+
+class ExceptionState;
+class ScriptPromise;
+class ScriptState;
+class ScriptValue;
+class ReadableStream;
+class ReadableStreamNative;
+
+class ReadableStreamDefaultReader : public ScriptWrappable {
+  DEFINE_WRAPPERTYPEINFO();
+
+ public:
+  static ReadableStreamDefaultReader* Create(ScriptState*,
+                                             ReadableStream* stream,
+                                             ExceptionState&);
+
+  ReadableStreamDefaultReader(ScriptState*,
+                              ReadableStreamNative* stream,
+                              ExceptionState&);
+  ~ReadableStreamDefaultReader() override;
+
+  ScriptPromise closed(ScriptState*) const;
+
+  ScriptPromise cancel(ScriptState*);
+  ScriptPromise cancel(ScriptState*, ScriptValue reason);
+
+  ScriptPromise read(ScriptState*);
+  ScriptPromise read(ScriptState*, ScriptValue chunk);
+
+  void releaseLock(ScriptState*);
+
+ private:
+  static void ThrowUnimplemented(ExceptionState&);
+  static ScriptPromise RejectUnimplemented(ScriptState*);
+};
+
+}  // namespace blink
+
+#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_STREAMS_READABLE_STREAM_DEFAULT_READER_H_
diff --git a/third_party/blink/renderer/core/streams/readable_stream_default_reader.idl b/third_party/blink/renderer/core/streams/readable_stream_default_reader.idl
new file mode 100644
index 0000000..a57b5e4
--- /dev/null
+++ b/third_party/blink/renderer/core/streams/readable_stream_default_reader.idl
@@ -0,0 +1,22 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This is only used when the new C++ implementation is enabled.
+
+// https://streams.spec.whatwg.org/#default-reader-class-definition
+[
+    Exposed=(Window,Worker,Worklet),
+    RuntimeEnabled=StreamsNative,
+    RaisesException=Constructor,
+    ConstructorCallWith=ScriptState,
+    Constructor(ReadableStream stream)
+] interface ReadableStreamDefaultReader {
+    [CallWith=ScriptState, NotEnumerable] readonly attribute Promise<void>
+        closed;
+
+    [CallWith=ScriptState, NotEnumerable] Promise<void> cancel(
+        optional any reason);
+    [CallWith=ScriptState, NotEnumerable] Promise<void> read();
+    [CallWith=ScriptState, NotEnumerable] void releaseLock();
+};