OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/webmidi/NavigatorWebMIDI.h" | 32 #include "modules/webmidi/NavigatorWebMIDI.h" |
33 | 33 |
34 #include "bindings/v8/DOMRequestState.h" | |
35 #include "bindings/v8/ScriptPromise.h" | |
36 #include "bindings/v8/ScriptPromiseResolver.h" | |
37 #include "core/dom/DOMError.h" | |
34 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" |
35 #include "core/dom/ExecutionContext.h" | 39 #include "core/dom/ExecutionContext.h" |
36 #include "core/frame/Frame.h" | 40 #include "core/frame/Frame.h" |
37 #include "core/frame/Navigator.h" | 41 #include "core/frame/Navigator.h" |
38 #include "modules/webmidi/MIDIAccessPromise.h" | 42 #include "modules/webmidi/MIDIAccess.h" |
43 #include "modules/webmidi/MIDIOptions.h" | |
39 | 44 |
40 namespace WebCore { | 45 namespace WebCore { |
41 | 46 |
42 NavigatorWebMIDI::NavigatorWebMIDI(Frame* frame) | 47 NavigatorWebMIDI::NavigatorWebMIDI(Frame* frame) |
43 : DOMWindowProperty(frame) | 48 : DOMWindowProperty(frame) |
44 { | 49 { |
45 } | 50 } |
46 | 51 |
47 NavigatorWebMIDI::~NavigatorWebMIDI() | 52 NavigatorWebMIDI::~NavigatorWebMIDI() |
48 { | 53 { |
54 clearPending(); | |
49 } | 55 } |
50 | 56 |
51 const char* NavigatorWebMIDI::supplementName() | 57 const char* NavigatorWebMIDI::supplementName() |
52 { | 58 { |
53 return "NavigatorWebMIDI"; | 59 return "NavigatorWebMIDI"; |
54 } | 60 } |
55 | 61 |
56 NavigatorWebMIDI* NavigatorWebMIDI::from(Navigator* navigator) | 62 NavigatorWebMIDI* NavigatorWebMIDI::from(Navigator* navigator) |
57 { | 63 { |
58 NavigatorWebMIDI* supplement = static_cast<NavigatorWebMIDI*>(Supplement<Nav igator>::from(navigator, supplementName())); | 64 NavigatorWebMIDI* supplement = static_cast<NavigatorWebMIDI*>(Supplement<Nav igator>::from(navigator, supplementName())); |
59 if (!supplement) { | 65 if (!supplement) { |
60 supplement = new NavigatorWebMIDI(navigator->frame()); | 66 supplement = new NavigatorWebMIDI(navigator->frame()); |
61 provideTo(navigator, supplementName(), adoptPtr(supplement)); | 67 provideTo(navigator, supplementName(), adoptPtr(supplement)); |
62 } | 68 } |
63 return supplement; | 69 return supplement; |
64 } | 70 } |
65 | 71 |
66 PassRefPtr<MIDIAccessPromise> NavigatorWebMIDI::requestMIDIAccess(Navigator* nav igator, const Dictionary& options) | 72 ScriptPromise NavigatorWebMIDI::requestMIDIAccess(Navigator* navigator, const Di ctionary& options) |
67 { | 73 { |
68 return NavigatorWebMIDI::from(navigator)->requestMIDIAccess(options); | 74 return NavigatorWebMIDI::from(navigator)->requestMIDIAccess(options); |
69 } | 75 } |
70 | 76 |
71 PassRefPtr<MIDIAccessPromise> NavigatorWebMIDI::requestMIDIAccess(const Dictiona ry& options) | 77 ScriptPromise NavigatorWebMIDI::requestMIDIAccess(const Dictionary& options) |
72 { | 78 { |
73 if (!frame()) | 79 if (!frame()) { |
Takashi Toyoshima
2013/12/03 10:48:50
optional: Can we have a layout test which confirm
yhirano
2013/12/03 12:14:16
I found that this rejection is currently not worki
| |
74 return 0; | 80 ScriptPromise promise = ScriptPromise::createPending(); |
81 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(p romise); | |
82 resolver->reject(DOMError::create("InvalidStateError")); | |
Takashi Toyoshima
2013/12/03 10:48:50
This is not the case described in the spec, but I
Takashi Toyoshima
2013/12/03 11:34:49
Sent a pull request to use AbortError here.
https:
yhirano
2013/12/03 12:14:16
Done.
| |
83 return promise; | |
84 } | |
75 | 85 |
76 ExecutionContext* context = frame()->document(); | 86 ExecutionContext* context = frame()->document(); |
77 ASSERT(context); | 87 ASSERT(context); |
88 if (!m_requestState.get()) | |
89 m_requestState = adoptPtr(new DOMRequestState(context)); | |
90 ScriptPromise promise = ScriptPromise::createPending(context); | |
91 RefPtr<MIDIAccess> access = MIDIAccess::create(MIDIOptions(options), context , this); | |
92 m_pending.add(access, ScriptPromiseResolver::create(promise, context)); | |
93 access->startRequest(); | |
94 return promise; | |
95 } | |
78 | 96 |
79 return MIDIAccessPromise::create(context, options); | 97 void NavigatorWebMIDI::didFinishRequest(MIDIAccess* access) |
98 { | |
99 // FIXME: We should care about suspend / stop. | |
100 RefPtr<MIDIAccess> key(access); | |
101 if (!m_pending.contains(key)) | |
102 return; | |
103 RefPtr<ScriptPromiseResolver> resolver = m_pending.get(key); | |
104 m_pending.remove(key); | |
105 | |
106 if (!frame()) { | |
107 // We can break the promise if the frame does not exist. | |
108 return; | |
109 } | |
110 ASSERT(m_requestState); | |
111 DOMRequestState::Scope scope(*m_requestState); | |
112 resolver->resolve(access, access->executionContext()); | |
Takashi Toyoshima
2013/12/03 11:34:49
I proposed to remove the second argument of the MI
| |
113 } | |
114 | |
115 void NavigatorWebMIDI::didFailRequest(MIDIAccess* access, PassRefPtr<DOMError> e rror) | |
116 { | |
117 // FIXME: We should care about suspend / stop. | |
118 RefPtr<MIDIAccess> key(access); | |
119 if (!m_pending.contains(key)) | |
120 return; | |
121 RefPtr<ScriptPromiseResolver> resolver = m_pending.get(key); | |
122 m_pending.remove(key); | |
123 if (!frame()) { | |
124 // We can break the promise if the frame does not exist. | |
125 return; | |
126 } | |
127 ASSERT(m_requestState); | |
128 DOMRequestState::Scope scope(*m_requestState); | |
129 resolver->reject(error, access->executionContext()); | |
130 } | |
131 | |
132 void NavigatorWebMIDI::clearPending() | |
133 { | |
134 // FIXME: We should care about suspend / stop. | |
135 HashMap<RefPtr<MIDIAccess>, RefPtr<ScriptPromiseResolver> > pending; | |
136 pending.swap(m_pending); | |
137 | |
138 if (!frame()) { | |
139 // We can break promises if the frame does not exist. | |
140 return; | |
141 } | |
142 | |
143 ASSERT(m_requestState); | |
144 for (HashMap<RefPtr<MIDIAccess>, RefPtr<ScriptPromiseResolver> >::iterator i = pending.begin(); | |
145 i != pending.end(); ++i) { | |
146 DOMRequestState::Scope scope(*m_requestState); | |
147 MIDIAccess* access = i->key.get(); | |
148 i->value->reject(DOMError::create("InvalidStateError"), access->executio nContext()); | |
Takashi Toyoshima
2013/12/03 10:48:50
AbortError?
yhirano
2013/12/03 12:14:16
Done.
| |
149 } | |
80 } | 150 } |
81 | 151 |
82 } // namespace WebCore | 152 } // namespace WebCore |
OLD | NEW |