diff options
author | crogers@google.com <crogers@google.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2013-07-23 01:12:12 +0000 |
---|---|---|
committer | crogers@google.com <crogers@google.com@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2013-07-23 01:12:12 +0000 |
commit | 0cc2da880e23fdcba468fb121eb3430a14cabf25 (patch) | |
tree | 983842c84aa86f541b8babf95512bef9b905b879 /third_party/WebKit | |
parent | 5905c690079ab5b2381560e9793cdc0d5c136b37 (diff) | |
download | chromium_src-0cc2da880e23fdcba468fb121eb3430a14cabf25.zip chromium_src-0cc2da880e23fdcba468fb121eb3430a14cabf25.tar.gz chromium_src-0cc2da880e23fdcba468fb121eb3430a14cabf25.tar.bz2 |
Revert 154697 "Implement MIDIOutput.send()"
> Implement MIDIOutput.send()
>
> This fully implements the Web MIDI API sending of MIDI data in Blink, but further work is still
> needed in the chromium back-end.
>
> BUG=163795
> TEST=requestmidiaccess.html updated to test send() method
> R=abarth@chromium.org, toyoshim@chromium.org
>
> Review URL: https://codereview.chromium.org/18858006
TBR=crogers@google.com
Review URL: https://codereview.chromium.org/19542006
git-svn-id: svn://svn.chromium.org/blink/trunk@154703 bbb929c8-8fbe-4397-9dbb-9b2b20218538
Diffstat (limited to 'third_party/WebKit')
8 files changed, 28 insertions, 108 deletions
diff --git a/third_party/WebKit/LayoutTests/webmidi/requestmidiaccess.html b/third_party/WebKit/LayoutTests/webmidi/requestmidiaccess.html index 0696dc7..67167c6 100644 --- a/third_party/WebKit/LayoutTests/webmidi/requestmidiaccess.html +++ b/third_party/WebKit/LayoutTests/webmidi/requestmidiaccess.html @@ -45,16 +45,6 @@ function successCallback1(a) { testFailed('output attributes are not correct'); } - // Test sending of MIDI data with a Uint8Array. - var typedArrayData = new Uint8Array([0x90, 0x45, 0x7f]); - output.send(typedArrayData); - - // Test sending of MIDI data with a regular Array. - output.send([0x90, 0x45, 0x7f]); - - // Test sending of MIDI data with a regular Array giving an explicit timestamp. - output.send([0x90, 0x45, 0x7f], performance.now()); - // Now test System Exclusive access - our test mock should not allow this type of access. try { navigator.requestMIDIAccess( { sysex: true } ).then(successCallback2, errorCallback2); diff --git a/third_party/WebKit/Source/modules/webmidi/MIDIAccess.cpp b/third_party/WebKit/Source/modules/webmidi/MIDIAccess.cpp index d579ba3..220d597 100644 --- a/third_party/WebKit/Source/modules/webmidi/MIDIAccess.cpp +++ b/third_party/WebKit/Source/modules/webmidi/MIDIAccess.cpp @@ -61,17 +61,17 @@ MIDIAccess::MIDIAccess(ScriptExecutionContext* context, MIDIAccessPromise* promi : ActiveDOMObject(context) , m_promise(promise) , m_hasAccess(false) - , m_sysExEnabled(false) + , m_enableSysEx(false) , m_requesting(false) { ScriptWrappable::init(this); m_accessor = MIDIAccessor::create(this); } -void MIDIAccess::setSysExEnabled(bool enable) +void MIDIAccess::enableSysEx(bool enable) { m_requesting = false; - m_sysExEnabled = enable; + m_enableSysEx = enable; if (enable) m_accessor->startSession(); else @@ -82,7 +82,7 @@ void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c { ASSERT(isMainThread()); - // FIXME: Pass in |this| to create() method so we can filter system exclusive messages correctly. + // FIXME: Pass m_enableSysEx flag to filter system exclusive messages correctly. m_inputs.append(MIDIInput::create(scriptExecutionContext(), id, manufacturer, name, version)); } @@ -90,8 +90,8 @@ void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer, { ASSERT(isMainThread()); - unsigned portIndex = m_outputs.size(); - m_outputs.append(MIDIOutput::create(this, portIndex, scriptExecutionContext(), id, manufacturer, name, version)); + // FIXME: Pass m_enableSysEx flag to filter system exclusive messages correctly. + m_outputs.append(MIDIOutput::create(scriptExecutionContext(), id, manufacturer, name, version)); } void MIDIAccess::didStartSession() @@ -119,28 +119,6 @@ void MIDIAccess::didReceiveMIDIData(unsigned portIndex, const unsigned char* dat } } -void MIDIAccess::sendMIDIData(unsigned portIndex, const unsigned char* data, size_t length, double timeStampInMilliseconds) -{ - if (m_hasAccess && portIndex < m_outputs.size() && data && length > 1) { - // Convert from a time in milliseconds (a DOMHighResTimeStamp) according to the same time coordinate system as performance.now() - // into a time in seconds which is based on the time coordinate system of monotonicallyIncreasingTime(). - double timeStamp; - - if (!timeStampInMilliseconds) { - // We treat a value of 0 (which is the default value) as special, meaning "now". - // We need to translate it exactly to 0 seconds. - timeStamp = 0; - } else { - Document* document = toDocument(scriptExecutionContext()); - ASSERT(document); - double documentStartTime = document->loader()->timing()->referenceMonotonicTime(); - timeStamp = documentStartTime + 0.001 * timeStampInMilliseconds; - } - - m_accessor->sendMIDIData(portIndex, data, length, timeStamp); - } -} - void MIDIAccess::stop() { m_hasAccess = false; @@ -152,8 +130,6 @@ void MIDIAccess::stop() MIDIController* controller = MIDIController::from(document->page()); ASSERT(controller); controller->cancelSysExPermissionRequest(this); - - m_accessor.clear(); } void MIDIAccess::startRequest() @@ -182,4 +158,6 @@ void MIDIAccess::permissionDenied() m_promise->reject(error); } + + } // namespace WebCore diff --git a/third_party/WebKit/Source/modules/webmidi/MIDIAccess.h b/third_party/WebKit/Source/modules/webmidi/MIDIAccess.h index d0a286c..615e9e4 100644 --- a/third_party/WebKit/Source/modules/webmidi/MIDIAccess.h +++ b/third_party/WebKit/Source/modules/webmidi/MIDIAccess.h @@ -61,8 +61,7 @@ public: DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); - void setSysExEnabled(bool); - bool sysExEnabled() const { return m_sysExEnabled; } + void enableSysEx(bool enable); // EventTarget virtual const AtomicString& interfaceName() const OVERRIDE { return eventNames().interfaceForMIDIAccess; } @@ -78,9 +77,6 @@ public: virtual void didStartSession() OVERRIDE; virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* data, size_t length, double timeStamp) OVERRIDE; - // |timeStampInMilliseconds| is in the same time coordinate system as performance.now(). - void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t length, double timeStampInMilliseconds); - private: explicit MIDIAccess(ScriptExecutionContext*, MIDIAccessPromise*); @@ -100,7 +96,7 @@ private: OwnPtr<MIDIAccessor> m_accessor; bool m_hasAccess; - bool m_sysExEnabled; + bool m_enableSysEx; bool m_requesting; }; diff --git a/third_party/WebKit/Source/modules/webmidi/MIDIOutput.cpp b/third_party/WebKit/Source/modules/webmidi/MIDIOutput.cpp index 5e05ccc..e9066f0 100644 --- a/third_party/WebKit/Source/modules/webmidi/MIDIOutput.cpp +++ b/third_party/WebKit/Source/modules/webmidi/MIDIOutput.cpp @@ -31,66 +31,30 @@ #include "config.h" #include "modules/webmidi/MIDIOutput.h" -#include "core/dom/ExceptionCode.h" -#include "modules/webmidi/MIDIAccess.h" - namespace WebCore { -PassRefPtr<MIDIOutput> MIDIOutput::create(MIDIAccess* access, unsigned portIndex, ScriptExecutionContext* context, const String& id, const String& manufacturer, const String& name, const String& version) +PassRefPtr<MIDIOutput> MIDIOutput::create(ScriptExecutionContext* context, const String& id, const String& manufacturer, const String& name, const String& version) { - return adoptRef(new MIDIOutput(access, portIndex, context, id, manufacturer, name, version)); + return adoptRef(new MIDIOutput(context, id, manufacturer, name, version)); } -MIDIOutput::MIDIOutput(MIDIAccess* access, unsigned portIndex, ScriptExecutionContext* context, const String& id, const String& manufacturer, const String& name, const String& version) +MIDIOutput::MIDIOutput(ScriptExecutionContext* context, const String& id, const String& manufacturer, const String& name, const String& version) : MIDIPort(context, id, manufacturer, name, MIDIPortTypeOutput, version) - , m_access(access) - , m_portIndex(portIndex) { ScriptWrappable::init(this); } -void MIDIOutput::send(Uint8Array* array, double timestamp, ExceptionCode& ec) -{ - if (!array) - return; - - const unsigned char* data = array->data(); - size_t length = array->length(); - - // Filter out System Exclusive messages if we're not allowed. - // FIXME: implement more extensive filtering. - if (length > 0 && data[0] >= 0xf0 && !m_access->sysExEnabled()) { - ec = SecurityError; - return; - } - - m_access->sendMIDIData(m_portIndex, data, length, timestamp); -} - -void MIDIOutput::send(Vector<unsigned> unsignedData, double timestamp, ExceptionCode& ec) -{ - RefPtr<Uint8Array> array = Uint8Array::create(unsignedData.size()); - - for (size_t i = 0; i < unsignedData.size(); ++i) { - if (unsignedData[i] > 0xff) { - ec = InvalidStateError; - return; - } - unsigned char value = unsignedData[i] & 0xff; - array->set(i, value); - } - - send(array.get(), timestamp, ec); -} - -void MIDIOutput::send(Uint8Array* data, ExceptionCode& ec) +void MIDIOutput::send(Uint8Array* data, double timestamp) { - send(data, 0, ec); + // FIXME: Implement MIDI protocol validation here. System exclusive + // messages must be checked at the same time. + // Actual sending operation will be implemented in core/platform/midi. } -void MIDIOutput::send(Vector<unsigned> unsignedData, ExceptionCode& ec) +void MIDIOutput::send(Vector<unsigned>, double timestamp) { - send(unsignedData, 0, ec); + // FIXME: Ditto. Implementation will be shared between these two send + // functions. } } // namespace WebCore diff --git a/third_party/WebKit/Source/modules/webmidi/MIDIOutput.h b/third_party/WebKit/Source/modules/webmidi/MIDIOutput.h index 197aa0c..cecb98a 100644 --- a/third_party/WebKit/Source/modules/webmidi/MIDIOutput.h +++ b/third_party/WebKit/Source/modules/webmidi/MIDIOutput.h @@ -32,7 +32,6 @@ #define MIDIOutput_h #include "modules/webmidi/MIDIPort.h" -#include "wtf/RefPtr.h" #include "wtf/Uint8Array.h" namespace WebCore { @@ -41,21 +40,14 @@ class ScriptExecutionContext; class MIDIOutput : public MIDIPort { public: - static PassRefPtr<MIDIOutput> create(MIDIAccess*, unsigned portIndex, ScriptExecutionContext*, const String& id, const String& manufacturer, const String& name, const String& version); + static PassRefPtr<MIDIOutput> create(ScriptExecutionContext*, const String& id, const String& manufacturer, const String& name, const String& version); virtual ~MIDIOutput() { } - void send(Uint8Array*, double timestamp, ExceptionCode&); - void send(Vector<unsigned>, double timestamp, ExceptionCode&); - - // send() without optional |timestamp|. - void send(Uint8Array*, ExceptionCode&); - void send(Vector<unsigned>, ExceptionCode&); + void send(Uint8Array*, double timestamp = 0); + void send(Vector<unsigned>, double timestamp = 0); private: - MIDIOutput(MIDIAccess*, unsigned portIndex, ScriptExecutionContext*, const String& id, const String& manufacturer, const String& name, const String& version); - - RefPtr<MIDIAccess> m_access; - unsigned m_portIndex; + MIDIOutput(ScriptExecutionContext*, const String& id, const String& manufacturer, const String& name, const String& version); }; typedef Vector<RefPtr<MIDIOutput> > MIDIOutputVector; diff --git a/third_party/WebKit/Source/modules/webmidi/MIDIOutput.idl b/third_party/WebKit/Source/modules/webmidi/MIDIOutput.idl index 86a4435..a07ec6f 100644 --- a/third_party/WebKit/Source/modules/webmidi/MIDIOutput.idl +++ b/third_party/WebKit/Source/modules/webmidi/MIDIOutput.idl @@ -31,6 +31,6 @@ [ NoInterfaceObject ] interface MIDIOutput : MIDIPort { - [RaisesException] void send(Uint8Array data, optional double timestamp); - [RaisesException] void send(sequence<unsigned long> data, optional double timestamp); + void send(Uint8Array data, optional double timestamp); + void send(sequence<unsigned long> data, optional double timestamp); }; diff --git a/third_party/WebKit/Source/web/MIDIClientImpl.cpp b/third_party/WebKit/Source/web/MIDIClientImpl.cpp index 70369bf..eef236f 100644 --- a/third_party/WebKit/Source/web/MIDIClientImpl.cpp +++ b/third_party/WebKit/Source/web/MIDIClientImpl.cpp @@ -52,7 +52,7 @@ void MIDIClientImpl::requestSysExPermission(PassRefPtr<MIDIAccess> access) if (m_client) m_client->requestSysExPermission(WebMIDIPermissionRequest(access)); else - access->setSysExEnabled(false); + access->enableSysEx(false); } void MIDIClientImpl::cancelSysExPermissionRequest(MIDIAccess* access) diff --git a/third_party/WebKit/Source/web/WebMIDIPermissionRequest.cpp b/third_party/WebKit/Source/web/WebMIDIPermissionRequest.cpp index 8d663aa..2e82e95 100644 --- a/third_party/WebKit/Source/web/WebMIDIPermissionRequest.cpp +++ b/third_party/WebKit/Source/web/WebMIDIPermissionRequest.cpp @@ -67,7 +67,7 @@ WebSecurityOrigin WebMIDIPermissionRequest::securityOrigin() const void WebMIDIPermissionRequest::setIsAllowed(bool allowed) { - m_private->setSysExEnabled(allowed); + m_private->enableSysEx(allowed); } } // namespace WebKit |