| Index: Source/modules/webmidi/MIDIAccessInitializer.cpp
|
| diff --git a/Source/modules/webmidi/MIDIAccessInitializer.cpp b/Source/modules/webmidi/MIDIAccessInitializer.cpp
|
| index d7535b3a641f93f7a310fae01635453ada6201c8..b1bbbef29852ca720031c8b49130ddb705bdef2f 100644
|
| --- a/Source/modules/webmidi/MIDIAccessInitializer.cpp
|
| +++ b/Source/modules/webmidi/MIDIAccessInitializer.cpp
|
| @@ -40,58 +40,58 @@
|
| #include "modules/webmidi/MIDIConnectionEvent.h"
|
| #include "modules/webmidi/MIDIController.h"
|
| #include "modules/webmidi/MIDIOptions.h"
|
| +#include "modules/webmidi/MIDIPort.h"
|
|
|
| namespace WebCore {
|
|
|
| -class MIDIAccessInitializer::PostAction : public ScriptFunction {
|
| -public:
|
| - static PassOwnPtr<MIDIAccessInitializer::PostAction> create(v8::Isolate* isolate, WeakPtr<MIDIAccessInitializer> owner, State state) { return adoptPtr(new PostAction(isolate, owner, state)); }
|
| -
|
| -private:
|
| - PostAction(v8::Isolate* isolate, WeakPtr<MIDIAccessInitializer> owner, State state): ScriptFunction(isolate), m_owner(owner), m_state(state) { }
|
| - virtual ScriptValue call(ScriptValue value) OVERRIDE
|
| - {
|
| - if (!m_owner.get())
|
| - return value;
|
| - m_owner->doPostAction(m_state);
|
| - return value;
|
| - }
|
| -
|
| - WeakPtr<MIDIAccessInitializer> m_owner;
|
| - State m_state;
|
| -};
|
| +MIDIAccessInitializer::MIDIAccessInitializer(const MIDIOptions& options)
|
| + : m_resolver(nullptr)
|
| + , m_options(options)
|
| + , m_sysexEnabled(false)
|
| +{
|
| +}
|
|
|
| MIDIAccessInitializer::~MIDIAccessInitializer()
|
| {
|
| - ASSERT(m_state != Requesting);
|
| + cancel();
|
| }
|
|
|
| -MIDIAccessInitializer::MIDIAccessInitializer(const MIDIOptions& options, MIDIAccess* access)
|
| - : m_state(Requesting)
|
| - , m_weakPtrFactory(this)
|
| - , m_options(options)
|
| - , m_sysexEnabled(false)
|
| - , m_access(access)
|
| +void MIDIAccessInitializer::start(AsyncInitializerResolver<MIDIAccessInitializer>* resolver)
|
| {
|
| + m_resolver = resolver;
|
| m_accessor = MIDIAccessor::create(this);
|
| +
|
| + if (!m_options.sysex) {
|
| + m_accessor->startSession();
|
| + return;
|
| + }
|
| + Document* document = toDocument(executionContext());
|
| + ASSERT(document);
|
| + MIDIController* controller = MIDIController::from(document->page());
|
| + if (controller) {
|
| + controller->requestSysexPermission(this);
|
| + } else {
|
| + m_resolver->reject(DOMError::create("SecurityError"));
|
| + }
|
| }
|
|
|
| void MIDIAccessInitializer::didAddInputPort(const String& id, const String& manufacturer, const String& name, const String& version)
|
| {
|
| - m_access->didAddInputPort(id, manufacturer, name, version);
|
| + m_portDescriptors.append(PortDescriptor(id, manufacturer, name, MIDIPort::MIDIPortTypeInput, version));
|
| }
|
|
|
| void MIDIAccessInitializer::didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version)
|
| {
|
| - m_access->didAddOutputPort(id, manufacturer, name, version);
|
| + m_portDescriptors.append(PortDescriptor(id, manufacturer, name, MIDIPort::MIDIPortTypeOutput, version));
|
| }
|
|
|
| void MIDIAccessInitializer::didStartSession(bool success, const String& error, const String& message)
|
| {
|
| - if (success)
|
| - m_resolver->resolve(m_access);
|
| - else
|
| + if (success) {
|
| + m_resolver->resolve(MIDIAccess::create(m_accessor.release(), m_sysexEnabled, m_portDescriptors, executionContext()));
|
| + } else {
|
| m_resolver->reject(DOMError::create(error, message));
|
| + }
|
| }
|
|
|
| void MIDIAccessInitializer::setSysexEnabled(bool enable)
|
| @@ -106,26 +106,17 @@ void MIDIAccessInitializer::setSysexEnabled(bool enable)
|
|
|
| SecurityOrigin* MIDIAccessInitializer::securityOrigin() const
|
| {
|
| - return m_access->executionContext()->securityOrigin();
|
| + return executionContext()->securityOrigin();
|
| }
|
|
|
| void MIDIAccessInitializer::cancel()
|
| {
|
| - if (m_state != Requesting)
|
| - return;
|
| m_accessor.clear();
|
| - m_weakPtrFactory.revokeAll();
|
| Document* document = toDocument(executionContext());
|
| ASSERT(document);
|
| MIDIController* controller = MIDIController::from(document->page());
|
| ASSERT(controller);
|
| controller->cancelSysexPermissionRequest(this);
|
| - m_state = Stopped;
|
| -}
|
| -
|
| -ExecutionContext* MIDIAccessInitializer::executionContext() const
|
| -{
|
| - return m_access->executionContext();
|
| }
|
|
|
| void MIDIAccessInitializer::permissionDenied()
|
| @@ -134,38 +125,10 @@ void MIDIAccessInitializer::permissionDenied()
|
| m_resolver->reject(DOMError::create("SecurityError"));
|
| }
|
|
|
| -ScriptPromise MIDIAccessInitializer::initialize(ScriptState* scriptState)
|
| -{
|
| - m_resolver = ScriptPromiseResolverWithContext::create(scriptState);
|
| - ScriptPromise promise = m_resolver->promise();
|
| - promise.then(PostAction::create(scriptState->isolate(), m_weakPtrFactory.createWeakPtr(), Resolved),
|
| - PostAction::create(scriptState->isolate(), m_weakPtrFactory.createWeakPtr(), Stopped));
|
| -
|
| - if (!m_options.sysex) {
|
| - m_accessor->startSession();
|
| - return promise;
|
| - }
|
| - Document* document = toDocument(executionContext());
|
| - ASSERT(document);
|
| - MIDIController* controller = MIDIController::from(document->page());
|
| - if (controller) {
|
| - controller->requestSysexPermission(this);
|
| - } else {
|
| - m_resolver->reject(DOMError::create("SecurityError"));
|
| - }
|
| - return promise;
|
| -}
|
| -
|
| -void MIDIAccessInitializer::doPostAction(State state)
|
| +ExecutionContext* MIDIAccessInitializer::executionContext() const
|
| {
|
| - ASSERT(m_state == Requesting);
|
| - ASSERT(state == Resolved || state == Stopped);
|
| - if (state == Resolved) {
|
| - m_access->initialize(m_accessor.release(), m_sysexEnabled);
|
| - }
|
| - m_accessor.clear();
|
| - m_weakPtrFactory.revokeAll();
|
| - m_state = state;
|
| + ASSERT(m_resolver);
|
| + return m_resolver->scriptState()->executionContext();
|
| }
|
|
|
| } // namespace WebCore
|
|
|