Commit 07b5068f authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Add skeleton for Serial API feature

This change adds the beginnings of the Serial API[1] to Blink. The
functions on navigator.serial and SerialPort are unimplemented.

[1]: https://wicg.github.io/serial

Bug: 884928
Change-Id: I76b26337570b07ecf9b265c2876c516058e90ee8
Reviewed-on: https://chromium-review.googlesource.com/1238486Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594052}
parent dee130a8
......@@ -50,6 +50,8 @@ PASS window.cached_navigator_mediaSession.metadata is null
PASS window.cached_navigator_mediaSession.playbackState is 'none'
PASS window.cached_navigator_presentation.defaultRequest is null
PASS window.cached_navigator_presentation.receiver is null
PASS window.cached_navigator_serial.onconnect is null
PASS window.cached_navigator_serial.ondisconnect is null
PASS window.cached_navigator_serviceWorker.controller is null
PASS window.cached_navigator_serviceWorker.oncontrollerchange is null
PASS window.cached_navigator_serviceWorker.onmessage is null
......
......@@ -50,6 +50,8 @@ PASS window.cached_navigator_mediaSession.metadata is null
PASS window.cached_navigator_mediaSession.playbackState is 'none'
PASS window.cached_navigator_presentation.defaultRequest is null
PASS window.cached_navigator_presentation.receiver is null
PASS window.cached_navigator_serial.onconnect is null
PASS window.cached_navigator_serial.ondisconnect is null
PASS window.cached_navigator_serviceWorker.controller is null
PASS window.cached_navigator_serviceWorker.oncontrollerchange is null
PASS window.cached_navigator_serviceWorker.onmessage is null
......
......@@ -50,6 +50,8 @@ PASS window.cached_navigator_mediaSession.metadata is null
PASS window.cached_navigator_mediaSession.playbackState is 'none'
PASS window.cached_navigator_presentation.defaultRequest is null
PASS window.cached_navigator_presentation.receiver is null
PASS window.cached_navigator_serial.onconnect is null
PASS window.cached_navigator_serial.ondisconnect is null
PASS window.cached_navigator_serviceWorker.controller is null
PASS window.cached_navigator_serviceWorker.oncontrollerchange is null
PASS window.cached_navigator_serviceWorker.onmessage is null
......
......@@ -56,6 +56,8 @@ PASS oldChildWindow.navigator.presentation.defaultRequest is newChildWindow.navi
PASS oldChildWindow.navigator.presentation.receiver is newChildWindow.navigator.presentation.receiver
PASS oldChildWindow.navigator.product is newChildWindow.navigator.product
PASS oldChildWindow.navigator.productSub is newChildWindow.navigator.productSub
PASS oldChildWindow.navigator.serial.onconnect is newChildWindow.navigator.serial.onconnect
PASS oldChildWindow.navigator.serial.ondisconnect is newChildWindow.navigator.serial.ondisconnect
PASS oldChildWindow.navigator.serviceWorker.controller is newChildWindow.navigator.serviceWorker.controller
PASS oldChildWindow.navigator.serviceWorker.oncontrollerchange is newChildWindow.navigator.serviceWorker.oncontrollerchange
PASS oldChildWindow.navigator.serviceWorker.onmessage is newChildWindow.navigator.serviceWorker.onmessage
......
......@@ -3473,6 +3473,7 @@ interface WorkerNavigator
getter permissions
getter platform
getter product
getter serial
getter storage
getter usb
getter userAgent
......
......@@ -1041,6 +1041,21 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method formData
[Worker] method json
[Worker] method text
[Worker] interface Serial : EventTarget
[Worker] attribute @@toStringTag
[Worker] getter onconnect
[Worker] getter ondisconnect
[Worker] method constructor
[Worker] method getPorts
[Worker] setter onconnect
[Worker] setter ondisconnect
[Worker] interface SerialPort
[Worker] attribute @@toStringTag
[Worker] getter in
[Worker] getter out
[Worker] method close
[Worker] method constructor
[Worker] method open
[Worker] interface ServiceWorkerRegistration : EventTarget
[Worker] attribute @@toStringTag
[Worker] getter active
......@@ -3485,6 +3500,7 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter permissions
[Worker] getter platform
[Worker] getter product
[Worker] getter serial
[Worker] getter storage
[Worker] getter usb
[Worker] getter userAgent
......
......@@ -4693,6 +4693,7 @@ interface Navigator
getter presentation
getter product
getter productSub
getter serial
getter serviceWorker
getter storage
getter usb
......@@ -6944,6 +6945,22 @@ interface SensorErrorEvent : Event
attribute @@toStringTag
getter error
method constructor
interface Serial : EventTarget
attribute @@toStringTag
getter onconnect
getter ondisconnect
method constructor
method getPorts
method requestPort
setter onconnect
setter ondisconnect
interface SerialPort
attribute @@toStringTag
getter in
getter out
method close
method constructor
method open
interface ServiceWorker : EventTarget
attribute @@toStringTag
getter onerror
......
......@@ -3372,6 +3372,7 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter permissions
[Worker] getter platform
[Worker] getter product
[Worker] getter serial
[Worker] getter storage
[Worker] getter usb
[Worker] getter userAgent
......
......@@ -1995,6 +1995,10 @@ enum WebFeature {
kPaymentAddressLanguageCode = 2542,
kDocumentDomainBlockedCrossOriginAccess = 2543,
kDocumentDomainEnabledCrossOriginAccess = 2544,
kSerialGetPorts = 2545,
kSerialRequestPort = 2546,
kSerialPortOpen = 2547,
kSerialPortClose = 2548,
// Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots.
......
......@@ -143,6 +143,7 @@ target("jumbo_" + modules_target_type, "modules") {
"//third_party/blink/renderer/modules/remoteplayback",
"//third_party/blink/renderer/modules/screen_orientation",
"//third_party/blink/renderer/modules/sensor",
"//third_party/blink/renderer/modules/serial",
"//third_party/blink/renderer/modules/service_worker",
"//third_party/blink/renderer/modules/shapedetection",
"//third_party/blink/renderer/modules/speech",
......
......@@ -41,6 +41,7 @@
"modules/remoteplayback/RemotePlayback",
"modules/screen_orientation/ScreenOrientation",
"modules/sensor/Sensor",
"modules/serial/Serial",
"modules/service_worker/ServiceWorker",
"modules/service_worker/ServiceWorkerContainer",
"modules/service_worker/ServiceWorkerGlobalScope",
......
......@@ -272,6 +272,8 @@ modules_idl_files =
"sensor/relative_orientation_sensor.idl",
"sensor/sensor.idl",
"sensor/sensor_error_event.idl",
"serial/serial.idl",
"serial/serial_port.idl",
"service_worker/client.idl",
"service_worker/clients.idl",
"service_worker/extendable_event.idl",
......@@ -635,6 +637,8 @@ modules_dictionary_idl_files =
"sensor/sensor_error_event_init.idl",
"sensor/sensor_options.idl",
"sensor/spatial_sensor_options.idl",
"serial/serial_options.idl",
"serial/serial_port_request_options.idl",
"service_worker/client_query_options.idl",
"service_worker/extendable_event_init.idl",
"service_worker/extendable_message_event_init.idl",
......@@ -777,6 +781,8 @@ modules_dependency_idl_files =
"quota/worker_navigator_storage_quota.idl",
"remoteplayback/html_media_element_remote_playback.idl",
"screen_orientation/screen_screen_orientation.idl",
"serial/navigator_serial.idl",
"serial/worker_navigator_serial.idl",
"service_worker/navigator_service_worker.idl",
"speech/window_speech.idl",
"speech/window_speech_synthesis.idl",
......
# Copyright 2018 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.
import("//third_party/blink/renderer/modules/modules.gni")
blink_modules_sources("serial") {
sources = [
"navigator_serial.cc",
"navigator_serial.h",
"serial.cc",
"serial.h",
"serial_port.cc",
"serial_port.h",
"worker_navigator_serial.cc",
"worker_navigator_serial.h",
]
}
// Copyright 2018 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/modules/serial/navigator_serial.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/modules/serial/serial.h"
namespace blink {
const char NavigatorSerial::kSupplementName[] = "NavigatorSerial";
NavigatorSerial& NavigatorSerial::From(Navigator& navigator) {
NavigatorSerial* supplement =
Supplement<Navigator>::From<NavigatorSerial>(navigator);
if (!supplement) {
supplement = new NavigatorSerial(navigator);
ProvideTo(navigator, supplement);
}
return *supplement;
}
Serial* NavigatorSerial::serial(Navigator& navigator) {
return NavigatorSerial::From(navigator).serial();
}
void NavigatorSerial::Trace(blink::Visitor* visitor) {
visitor->Trace(serial_);
Supplement<Navigator>::Trace(visitor);
}
NavigatorSerial::NavigatorSerial(Navigator& navigator)
: Supplement<Navigator>(navigator) {
if (navigator.GetFrame()) {
DCHECK(navigator.GetFrame()->GetDocument());
serial_ = Serial::Create(*navigator.GetFrame()->GetDocument());
}
}
} // namespace blink
// Copyright 2018 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_MODULES_SERIAL_NAVIGATOR_SERIAL_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SERIAL_NAVIGATOR_SERIAL_H_
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
class Serial;
class NavigatorSerial final : public GarbageCollected<NavigatorSerial>,
public Supplement<Navigator> {
USING_GARBAGE_COLLECTED_MIXIN(NavigatorSerial);
public:
static const char kSupplementName[];
static NavigatorSerial& From(Navigator&);
static Serial* serial(Navigator&);
Serial* serial() { return serial_; }
void Trace(Visitor*) override;
private:
explicit NavigatorSerial(Navigator&);
Member<Serial> serial_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_SERIAL_NAVIGATOR_SERIAL_H_
// Copyright 2018 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.
// https://wicg.github.io/serial
[
ImplementedAs=NavigatorSerial,
RuntimeEnabled=Serial,
SecureContext
] partial interface Navigator {
[SameObject] readonly attribute Serial serial;
};
// Copyright 2018 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/modules/serial/serial.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/modules/event_target_modules_names.h"
namespace blink {
// static
Serial* Serial::Create(ExecutionContext& execution_context) {
return new Serial(execution_context);
}
ExecutionContext* Serial::GetExecutionContext() const {
return ContextLifecycleObserver::GetExecutionContext();
}
const AtomicString& Serial::InterfaceName() const {
return EventTargetNames::Serial;
}
ScriptPromise Serial::getPorts(ScriptState* script_state) {
return ScriptPromise::RejectWithDOMException(
script_state, DOMException::Create(DOMExceptionCode::kNotSupportedError));
}
ScriptPromise Serial::requestPort(ScriptState* script_state,
const SerialPortRequestOptions& options) {
return ScriptPromise::RejectWithDOMException(
script_state, DOMException::Create(DOMExceptionCode::kNotSupportedError));
}
void Serial::Trace(Visitor* visitor) {
EventTargetWithInlineData::Trace(visitor);
ContextLifecycleObserver::Trace(visitor);
}
Serial::Serial(ExecutionContext& execution_context)
: ContextLifecycleObserver(&execution_context) {}
} // namespace blink
// Copyright 2018 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_MODULES_SERIAL_SERIAL_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SERIAL_SERIAL_H_
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/core/dom/context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/dom/events/event_target.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
namespace blink {
class ExecutionContext;
class ScriptState;
class SerialPortRequestOptions;
class Serial final : public EventTargetWithInlineData,
public ContextLifecycleObserver {
DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(Serial);
public:
static Serial* Create(ExecutionContext& executionContext);
// EventTarget
ExecutionContext* GetExecutionContext() const override;
const AtomicString& InterfaceName() const override;
DEFINE_ATTRIBUTE_EVENT_LISTENER(connect);
DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect);
ScriptPromise getPorts(ScriptState*);
ScriptPromise requestPort(ScriptState*, const SerialPortRequestOptions&);
void Trace(Visitor*) override;
private:
explicit Serial(ExecutionContext&);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_SERIAL_SERIAL_H_
// Copyright 2018 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.
// https://wicg.github.io/serial
[
Exposed(Window Serial,DedicatedWorker Serial),
SecureContext
] interface Serial : EventTarget {
attribute EventHandler onconnect;
attribute EventHandler ondisconnect;
[CallWith=ScriptState, MeasureAs=SerialGetPorts]
Promise<sequence<SerialPort>> getPorts();
[CallWith=ScriptState, MeasureAs=SerialRequestPort, Exposed=Window]
Promise<SerialPort> requestPort(SerialPortRequestOptions options);
};
// Copyright 2018 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.
// https://wicg.github.io/serial
enum ParityType {
"none",
"even",
"odd",
};
dictionary SerialOptions {
long baudrate = 9600;
octet databits = 8;
octet stopbits = 1;
ParityType parity = "none";
long buffersize = 255;
boolean rtscts = false;
};
// Copyright 2018 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/modules/serial/serial_port.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
namespace blink {
ScriptValue SerialPort::in(ScriptState* script_state) {
return ScriptValue::CreateNull(script_state);
}
ScriptValue SerialPort::out(ScriptState* script_state) {
return ScriptValue::CreateNull(script_state);
}
ScriptPromise SerialPort::open(ScriptState* script_state,
const SerialOptions& options) {
return ScriptPromise::RejectWithDOMException(
script_state, DOMException::Create(DOMExceptionCode::kNotSupportedError));
}
ScriptPromise SerialPort::close(ScriptState* script_state) {
return ScriptPromise::RejectWithDOMException(
script_state, DOMException::Create(DOMExceptionCode::kNotSupportedError));
}
} // namespace blink
// Copyright 2018 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_MODULES_SERIAL_SERIAL_PORT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SERIAL_SERIAL_PORT_H_
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
namespace blink {
class ScriptState;
class SerialOptions;
class SerialPort final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
ScriptValue in(ScriptState*);
ScriptValue out(ScriptState*);
ScriptPromise open(ScriptState*, const SerialOptions& options);
ScriptPromise close(ScriptState*);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_SERIAL_SERIAL_PORT_H_
// Copyright 2018 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.
// https://wicg.github.io/serial
[
Exposed(Window Serial,DedicatedWorker Serial),
SecureContext
] interface SerialPort {
// TODO(https://crbug.com/888165): "any" is used here because the IDL
// processor does not recognize ReadableStream or WritableStream when
// implemented with V8 extras.
[CallWith=ScriptState] readonly attribute any in;
[CallWith=ScriptState] readonly attribute any out;
[CallWith=ScriptState, MeasureAs=SerialPortOpen]
Promise<void> open(SerialOptions options);
[CallWith=ScriptState, MeasureAs=SerialPortClose]
Promise<void> close();
};
// Copyright 2018 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.
// https://wicg.github.io/serial
dictionary SerialPortRequestOptions {
};
// Copyright 2018 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/modules/serial/worker_navigator_serial.h"
#include "third_party/blink/renderer/modules/serial/serial.h"
namespace blink {
const char WorkerNavigatorSerial::kSupplementName[] = "WorkerNavigatorSerial";
WorkerNavigatorSerial& WorkerNavigatorSerial::From(WorkerNavigator& navigator) {
WorkerNavigatorSerial* supplement =
Supplement<WorkerNavigator>::From<WorkerNavigatorSerial>(navigator);
if (!supplement) {
supplement = new WorkerNavigatorSerial(navigator);
ProvideTo(navigator, supplement);
}
return *supplement;
}
Serial* WorkerNavigatorSerial::serial(ScriptState* script_state,
WorkerNavigator& navigator) {
return WorkerNavigatorSerial::From(navigator).serial(script_state);
}
Serial* WorkerNavigatorSerial::serial(ScriptState* script_state) {
if (!serial_) {
auto* execution_context = ExecutionContext::From(script_state);
DCHECK(execution_context);
// TODO(https://crbug.com/839117): Remove this check once the Exposed
// attribute is fixed to only expose this property in dedicated workers.
if (execution_context->IsDedicatedWorkerGlobalScope())
serial_ = Serial::Create(*execution_context);
}
return serial_;
}
void WorkerNavigatorSerial::Trace(blink::Visitor* visitor) {
visitor->Trace(serial_);
Supplement<WorkerNavigator>::Trace(visitor);
}
WorkerNavigatorSerial::WorkerNavigatorSerial(WorkerNavigator& navigator)
: Supplement<WorkerNavigator>(navigator) {}
} // namespace blink
// Copyright 2018 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_MODULES_SERIAL_WORKER_NAVIGATOR_SERIAL_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SERIAL_WORKER_NAVIGATOR_SERIAL_H_
#include "third_party/blink/renderer/core/workers/worker_navigator.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/supplementable.h"
namespace blink {
class ScriptState;
class Serial;
class WorkerNavigatorSerial final
: public GarbageCollected<WorkerNavigatorSerial>,
public Supplement<WorkerNavigator> {
USING_GARBAGE_COLLECTED_MIXIN(WorkerNavigatorSerial);
public:
static const char kSupplementName[];
static WorkerNavigatorSerial& From(WorkerNavigator&);
static Serial* serial(ScriptState*, WorkerNavigator&);
Serial* serial(ScriptState*);
void Trace(Visitor*) override;
private:
explicit WorkerNavigatorSerial(WorkerNavigator&);
Member<Serial> serial_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_SERIAL_WORKER_NAVIGATOR_SERIAL_H_
// Copyright 2018 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.
// https://wicg.github.io/serial
[
Exposed=DedicatedWorker,
ImplementedAs=WorkerNavigatorSerial,
RuntimeEnabled=Serial,
SecureContext
] partial interface WorkerNavigator {
[CallWith=ScriptState, SameObject] readonly attribute Serial serial;
};
......@@ -1135,6 +1135,10 @@
depends_on: ["Sensor"],
status: "experimental",
},
{
name: "Serial",
status: "experimental",
},
{
name: "ServiceWorkerScriptFullCodeCache",
},
......
......@@ -20222,6 +20222,10 @@ Called by update_net_error_codes.py.-->
<int value="2542" label="PaymentAddressLanguageCode"/>
<int value="2543" label="DocumentDomainBlockedCrossOriginAccess"/>
<int value="2544" label="DocumentDomainEnabledCrossOriginAccess"/>
<int value="2545" label="SerialGetPorts"/>
<int value="2546" label="SerialRequestPort"/>
<int value="2547" label="SerialPortOpen"/>
<int value="2548" label="SerialPortClose"/>
</enum>
<enum name="FeaturePolicyFeature">
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