Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/webmidi/MIDIAccessInitializer.h" | 6 #include "modules/webmidi/MIDIAccessInitializer.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "core/dom/DOMError.h" | 10 #include "core/dom/DOMError.h" |
| 11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
| 12 #include "core/frame/Navigator.h" | 12 #include "core/frame/Navigator.h" |
| 13 #include "modules/webmidi/MIDIAccess.h" | 13 #include "modules/webmidi/MIDIAccess.h" |
| 14 #include "modules/webmidi/MIDIController.h" | 14 #include "modules/webmidi/MIDIController.h" |
| 15 #include "modules/webmidi/MIDIOptions.h" | 15 #include "modules/webmidi/MIDIOptions.h" |
| 16 #include "modules/webmidi/MIDIPort.h" | 16 #include "modules/webmidi/MIDIPort.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 MIDIAccessInitializer::MIDIAccessInitializer(ScriptState* scriptState, const MID IOptions& options) | 20 MIDIAccessInitializer::MIDIAccessInitializer(ScriptState* scriptState, const MID IOptions* options) |
|
tkent
2014/09/10 23:44:05
It seems we still assume |options| is non-null. C
bashi
2014/09/12 00:19:13
IDL dictionaries are garbage collected. We need to
tkent
2014/09/12 00:20:53
It should be safe.
| |
| 21 : ScriptPromiseResolver(scriptState) | 21 : ScriptPromiseResolver(scriptState) |
| 22 , m_options(options) | 22 , m_requestSysex(false) |
| 23 , m_sysexEnabled(false) | |
| 24 { | 23 { |
| 24 if (options->hasSysex()) | |
| 25 m_requestSysex = options->sysex(); | |
| 25 } | 26 } |
| 26 | 27 |
| 27 MIDIAccessInitializer::~MIDIAccessInitializer() | 28 MIDIAccessInitializer::~MIDIAccessInitializer() |
| 28 { | 29 { |
| 29 // It is safe to cancel a request which is already finished or canceld. | 30 // It is safe to cancel a request which is already finished or canceld. |
| 30 Document* document = toDocument(executionContext()); | 31 Document* document = toDocument(executionContext()); |
| 31 ASSERT(document); | 32 ASSERT(document); |
| 32 MIDIController* controller = MIDIController::from(document->frame()); | 33 MIDIController* controller = MIDIController::from(document->frame()); |
| 33 if (controller) | 34 if (controller) |
| 34 controller->cancelSysexPermissionRequest(this); | 35 controller->cancelSysexPermissionRequest(this); |
| 35 } | 36 } |
| 36 | 37 |
| 37 ScriptPromise MIDIAccessInitializer::start() | 38 ScriptPromise MIDIAccessInitializer::start() |
| 38 { | 39 { |
| 39 ScriptPromise promise = this->promise(); | 40 ScriptPromise promise = this->promise(); |
| 40 m_accessor = MIDIAccessor::create(this); | 41 m_accessor = MIDIAccessor::create(this); |
| 41 | 42 |
| 42 if (!m_options.sysex) { | 43 if (!m_requestSysex) { |
| 43 m_accessor->startSession(); | 44 m_accessor->startSession(); |
| 44 return promise; | 45 return promise; |
| 45 } | 46 } |
| 46 Document* document = toDocument(executionContext()); | 47 Document* document = toDocument(executionContext()); |
| 47 ASSERT(document); | 48 ASSERT(document); |
| 48 MIDIController* controller = MIDIController::from(document->frame()); | 49 MIDIController* controller = MIDIController::from(document->frame()); |
| 49 if (controller) { | 50 if (controller) { |
| 50 controller->requestSysexPermission(this); | 51 controller->requestSysexPermission(this); |
| 51 } else { | 52 } else { |
| 52 reject(DOMError::create("SecurityError")); | 53 reject(DOMError::create("SecurityError")); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 63 void MIDIAccessInitializer::didAddOutputPort(const String& id, const String& man ufacturer, const String& name, const String& version) | 64 void MIDIAccessInitializer::didAddOutputPort(const String& id, const String& man ufacturer, const String& name, const String& version) |
| 64 { | 65 { |
| 65 ASSERT(m_accessor); | 66 ASSERT(m_accessor); |
| 66 m_portDescriptors.append(PortDescriptor(id, manufacturer, name, MIDIPort::MI DIPortTypeOutput, version)); | 67 m_portDescriptors.append(PortDescriptor(id, manufacturer, name, MIDIPort::MI DIPortTypeOutput, version)); |
| 67 } | 68 } |
| 68 | 69 |
| 69 void MIDIAccessInitializer::didStartSession(bool success, const String& error, c onst String& message) | 70 void MIDIAccessInitializer::didStartSession(bool success, const String& error, c onst String& message) |
| 70 { | 71 { |
| 71 ASSERT(m_accessor); | 72 ASSERT(m_accessor); |
| 72 if (success) { | 73 if (success) { |
| 73 resolve(MIDIAccess::create(m_accessor.release(), m_sysexEnabled, m_portD escriptors, executionContext())); | 74 resolve(MIDIAccess::create(m_accessor.release(), m_requestSysex, m_portD escriptors, executionContext())); |
| 74 } else { | 75 } else { |
| 75 reject(DOMError::create(error, message)); | 76 reject(DOMError::create(error, message)); |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 | 79 |
| 79 void MIDIAccessInitializer::setSysexEnabled(bool enable) | 80 void MIDIAccessInitializer::resolveSysexPermission(bool allowed) |
| 80 { | 81 { |
| 81 m_sysexEnabled = enable; | 82 if (allowed) |
| 82 if (enable) | |
| 83 m_accessor->startSession(); | 83 m_accessor->startSession(); |
| 84 else | 84 else |
| 85 reject(DOMError::create("SecurityError")); | 85 reject(DOMError::create("SecurityError")); |
| 86 } | 86 } |
| 87 | 87 |
| 88 SecurityOrigin* MIDIAccessInitializer::securityOrigin() const | 88 SecurityOrigin* MIDIAccessInitializer::securityOrigin() const |
| 89 { | 89 { |
| 90 return executionContext()->securityOrigin(); | 90 return executionContext()->securityOrigin(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 ExecutionContext* MIDIAccessInitializer::executionContext() const | 93 ExecutionContext* MIDIAccessInitializer::executionContext() const |
| 94 { | 94 { |
| 95 return scriptState()->executionContext(); | 95 return scriptState()->executionContext(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 } // namespace blink | 98 } // namespace blink |
| OLD | NEW |