Commit b4b724f2 authored by Adam Rice's avatar Adam Rice Committed by Commit Bot

Throw a TypeError for sendBeacon with stream body

Make sendBeacon() throw when the supplied body is a ReadableStream
object, for alignment with the standard.

BUG=973659

Change-Id: I0efce29d3857a3e2cd125e3210cc6646095fa4cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2029476Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738848}
parent 783de18a
......@@ -25,8 +25,8 @@ bindings_modules_generated_union_type_files = [
"$bindings_modules_v8_output_dir/array_buffer_or_array_buffer_view_or_string.h",
"$bindings_modules_v8_output_dir/array_buffer_or_array_buffer_view_or_usv_string.cc",
"$bindings_modules_v8_output_dir/array_buffer_or_array_buffer_view_or_usv_string.h",
"$bindings_modules_v8_output_dir/array_buffer_view_or_blob_or_string_or_form_data.cc",
"$bindings_modules_v8_output_dir/array_buffer_view_or_blob_or_string_or_form_data.h",
"$bindings_modules_v8_output_dir/array_buffer_view_or_blob_or_string_or_form_data_or_readable_stream.cc",
"$bindings_modules_v8_output_dir/array_buffer_view_or_blob_or_string_or_form_data_or_readable_stream.h",
"$bindings_modules_v8_output_dir/audio_context_latency_category_or_double.cc",
"$bindings_modules_v8_output_dir/audio_context_latency_category_or_double.h",
"$bindings_modules_v8_output_dir/boolean_or_constrain_boolean_parameters.cc",
......
......@@ -4,7 +4,7 @@
#include "third_party/blink/renderer/modules/beacon/navigator_beacon.h"
#include "third_party/blink/renderer/bindings/modules/v8/array_buffer_view_or_blob_or_string_or_form_data.h"
#include "third_party/blink/renderer/bindings/modules/v8/array_buffer_view_or_blob_or_string_or_form_data_or_readable_stream.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/fileapi/blob.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
......@@ -67,7 +67,7 @@ bool NavigatorBeacon::sendBeacon(
ScriptState* script_state,
Navigator& navigator,
const String& urlstring,
const ArrayBufferViewOrBlobOrStringOrFormData& data,
const ArrayBufferViewOrBlobOrStringOrFormDataOrReadableStream& data,
ExceptionState& exception_state) {
return NavigatorBeacon::From(navigator).SendBeaconImpl(
script_state, urlstring, data, exception_state);
......@@ -76,7 +76,7 @@ bool NavigatorBeacon::sendBeacon(
bool NavigatorBeacon::SendBeaconImpl(
ScriptState* script_state,
const String& urlstring,
const ArrayBufferViewOrBlobOrStringOrFormData& data,
const ArrayBufferViewOrBlobOrStringOrFormDataOrReadableStream& data,
ExceptionState& exception_state) {
ExecutionContext* context = ExecutionContext::From(script_state);
KURL url = context->CompleteURL(urlstring);
......@@ -121,6 +121,10 @@ bool NavigatorBeacon::SendBeaconImpl(
} else if (data.IsFormData()) {
allowed = PingLoader::SendBeacon(GetSupplementable()->GetFrame(), url,
data.GetAsFormData());
} else if (data.IsReadableStream()) {
exception_state.ThrowTypeError(
"sendBeacon cannot have a ReadableStream body.");
return false;
} else {
allowed =
PingLoader::SendBeacon(GetSupplementable()->GetFrame(), url, String());
......
......@@ -14,7 +14,7 @@ namespace blink {
class ScriptState;
class ExceptionState;
class KURL;
class ArrayBufferViewOrBlobOrStringOrFormData;
class ArrayBufferViewOrBlobOrStringOrFormDataOrReadableStream;
class NavigatorBeacon final : public GarbageCollected<NavigatorBeacon>,
public Supplement<Navigator> {
......@@ -28,19 +28,21 @@ class NavigatorBeacon final : public GarbageCollected<NavigatorBeacon>,
explicit NavigatorBeacon(Navigator&);
virtual ~NavigatorBeacon();
static bool sendBeacon(ScriptState*,
Navigator&,
const String&,
const ArrayBufferViewOrBlobOrStringOrFormData&,
ExceptionState&);
static bool sendBeacon(
ScriptState*,
Navigator&,
const String&,
const ArrayBufferViewOrBlobOrStringOrFormDataOrReadableStream&,
ExceptionState&);
void Trace(blink::Visitor*) override;
private:
bool SendBeaconImpl(ScriptState*,
const String&,
const ArrayBufferViewOrBlobOrStringOrFormData&,
ExceptionState&);
bool SendBeaconImpl(
ScriptState*,
const String&,
const ArrayBufferViewOrBlobOrStringOrFormDataOrReadableStream&,
ExceptionState&);
bool CanSendBeacon(ExecutionContext*, const KURL&, ExceptionState&);
};
......
......@@ -7,5 +7,7 @@
[
ImplementedAs=NavigatorBeacon
] partial interface Navigator {
[CallWith=ScriptState, MeasureAs=SendBeacon, RaisesException] boolean sendBeacon(USVString url, optional (ArrayBufferView or Blob or DOMString or FormData)? data = null);
// TODO(ricea): |data| should be BodyInit? when the IDL compiler supports
// it.
[CallWith=ScriptState, MeasureAs=SendBeacon, RaisesException] boolean sendBeacon(USVString url, optional (ArrayBufferView or Blob or DOMString or FormData or ReadableStream)? data = null);
};
This is a testharness.js-based test.
FAIL sendBeacon() with a stream does not work due to the keepalive flag being set assert_throws_js: function "() => navigator.sendBeacon("...", new ReadableStream())" did not throw
Harness: the test ran to completion.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment