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 "modules/webmidi/MIDIAccessInitializer.h" | 5 #include "modules/webmidi/MIDIAccessInitializer.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromise.h" | 7 #include "bindings/core/v8/ScriptPromise.h" |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 { | 36 { |
37 dispose(); | 37 dispose(); |
38 LifecycleObserver::contextDestroyed(); | 38 LifecycleObserver::contextDestroyed(); |
39 } | 39 } |
40 | 40 |
41 void MIDIAccessInitializer::dispose() | 41 void MIDIAccessInitializer::dispose() |
42 { | 42 { |
43 if (m_hasBeenDisposed) | 43 if (m_hasBeenDisposed) |
44 return; | 44 return; |
45 | 45 |
46 if (!executionContext()) | 46 if (!getExecutionContext()) |
47 return; | 47 return; |
48 | 48 |
49 if (!m_permissionResolved) { | 49 if (!m_permissionResolved) { |
50 Document* document = toDocument(executionContext()); | 50 Document* document = toDocument(getExecutionContext()); |
51 ASSERT(document); | 51 ASSERT(document); |
52 if (MIDIController* controller = MIDIController::from(document->frame())
) | 52 if (MIDIController* controller = MIDIController::from(document->frame())
) |
53 controller->cancelPermissionRequest(this); | 53 controller->cancelPermissionRequest(this); |
54 m_permissionResolved = true; | 54 m_permissionResolved = true; |
55 } | 55 } |
56 | 56 |
57 m_hasBeenDisposed = true; | 57 m_hasBeenDisposed = true; |
58 } | 58 } |
59 | 59 |
60 ScriptPromise MIDIAccessInitializer::start() | 60 ScriptPromise MIDIAccessInitializer::start() |
61 { | 61 { |
62 ScriptPromise promise = this->promise(); | 62 ScriptPromise promise = this->promise(); |
63 m_accessor = MIDIAccessor::create(this); | 63 m_accessor = MIDIAccessor::create(this); |
64 | 64 |
65 Document* document = toDocument(executionContext()); | 65 Document* document = toDocument(getExecutionContext()); |
66 ASSERT(document); | 66 ASSERT(document); |
67 if (MIDIController* controller = MIDIController::from(document->frame())) | 67 if (MIDIController* controller = MIDIController::from(document->frame())) |
68 controller->requestPermission(this, m_options); | 68 controller->requestPermission(this, m_options); |
69 else | 69 else |
70 reject(DOMException::create(SecurityError)); | 70 reject(DOMException::create(SecurityError)); |
71 | 71 |
72 return promise; | 72 return promise; |
73 } | 73 } |
74 | 74 |
75 void MIDIAccessInitializer::didAddInputPort(const String& id, const String& manu
facturer, const String& name, const String& version, PortState state) | 75 void MIDIAccessInitializer::didAddInputPort(const String& id, const String& manu
facturer, const String& name, const String& version, PortState state) |
(...skipping 19 matching lines...) Expand all Loading... |
95 void MIDIAccessInitializer::didSetOutputPortState(unsigned portIndex, PortState
state) | 95 void MIDIAccessInitializer::didSetOutputPortState(unsigned portIndex, PortState
state) |
96 { | 96 { |
97 // See comments on didSetInputPortState(). | 97 // See comments on didSetInputPortState(). |
98 ASSERT_NOT_REACHED(); | 98 ASSERT_NOT_REACHED(); |
99 } | 99 } |
100 | 100 |
101 void MIDIAccessInitializer::didStartSession(bool success, const String& error, c
onst String& message) | 101 void MIDIAccessInitializer::didStartSession(bool success, const String& error, c
onst String& message) |
102 { | 102 { |
103 ASSERT(m_accessor); | 103 ASSERT(m_accessor); |
104 if (success) { | 104 if (success) { |
105 resolve(MIDIAccess::create(m_accessor.release(), m_options.hasSysex() &&
m_options.sysex(), m_portDescriptors, executionContext())); | 105 resolve(MIDIAccess::create(m_accessor.release(), m_options.hasSysex() &&
m_options.sysex(), m_portDescriptors, getExecutionContext())); |
106 } else { | 106 } else { |
107 // The spec says the name is one of | 107 // The spec says the name is one of |
108 // - SecurityError | 108 // - SecurityError |
109 // - AbortError | 109 // - AbortError |
110 // - InvalidStateError | 110 // - InvalidStateError |
111 // - NotSupportedError | 111 // - NotSupportedError |
112 // TODO(toyoshim): Do not rely on |error| string. Instead an enum | 112 // TODO(toyoshim): Do not rely on |error| string. Instead an enum |
113 // representing an ExceptionCode should be defined and deliverred. | 113 // representing an ExceptionCode should be defined and deliverred. |
114 ExceptionCode ec = InvalidStateError; | 114 ExceptionCode ec = InvalidStateError; |
115 if (error == DOMException::getErrorName(SecurityError)) { | 115 if (error == DOMException::getErrorName(SecurityError)) { |
(...skipping 11 matching lines...) Expand all Loading... |
127 | 127 |
128 void MIDIAccessInitializer::resolvePermission(bool allowed) | 128 void MIDIAccessInitializer::resolvePermission(bool allowed) |
129 { | 129 { |
130 m_permissionResolved = true; | 130 m_permissionResolved = true; |
131 if (allowed) | 131 if (allowed) |
132 m_accessor->startSession(); | 132 m_accessor->startSession(); |
133 else | 133 else |
134 reject(DOMException::create(SecurityError)); | 134 reject(DOMException::create(SecurityError)); |
135 } | 135 } |
136 | 136 |
137 SecurityOrigin* MIDIAccessInitializer::securityOrigin() const | 137 SecurityOrigin* MIDIAccessInitializer::getSecurityOrigin() const |
138 { | 138 { |
139 return executionContext()->securityOrigin(); | 139 return getExecutionContext()->getSecurityOrigin(); |
140 } | 140 } |
141 | 141 |
142 ExecutionContext* MIDIAccessInitializer::executionContext() const | 142 ExecutionContext* MIDIAccessInitializer::getExecutionContext() const |
143 { | 143 { |
144 return scriptState()->executionContext(); | 144 return getScriptState()->getExecutionContext(); |
145 } | 145 } |
146 | 146 |
147 } // namespace blink | 147 } // namespace blink |
OLD | NEW |