OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
29 */ | |
30 | |
31 #include "config.h" | |
32 #include "modules/webmidi/MIDIAccessFuture.h" | |
33 | |
34 #include "core/dom/DOMError.h" | |
35 #include "modules/webmidi/MIDIAccess.h" | |
36 #include "modules/webmidi/MIDIErrorCallback.h" | |
37 #include "modules/webmidi/MIDISuccessCallback.h" | |
38 | |
39 namespace WebCore { | |
40 | |
41 PassRefPtr<MIDIAccessFuture> MIDIAccessFuture::create(ScriptExecutionContext* co ntext) | |
42 { | |
43 return adoptRef(new MIDIAccessFuture(context)); | |
44 } | |
45 | |
46 MIDIAccessFuture::MIDIAccessFuture(ScriptExecutionContext* context) | |
47 : m_context(context) | |
48 , m_state(Pending) | |
49 { | |
50 ScriptWrappable::init(this); | |
51 } | |
52 | |
53 void MIDIAccessFuture::done(PassRefPtr<MIDISuccessCallback> successCallback, Pas sRefPtr<MIDIErrorCallback> errorCallback) | |
54 { | |
55 switch (m_state) { | |
56 case Accepted: | |
57 successCallback->scheduleCallback(m_context); | |
58 m_state = Invoked; | |
59 break; | |
60 case Rejected: | |
61 successCallback->scheduleCallback(m_context); | |
Chris Rogers
2013/06/04 04:28:58
shouldn't this be errorCallback?
Takashi Toyoshima
2013/06/04 11:44:37
Done.
| |
62 m_state = Invoked; | |
63 break; | |
64 case Pending: | |
65 m_successCallback = successCallback; | |
66 m_errorCallback = errorCallback; | |
67 break; | |
68 case Invoked: | |
69 break; | |
70 default: | |
71 ASSERT_NOT_REACHED(); | |
72 } | |
73 } | |
74 | |
75 void MIDIAccessFuture::accept(MIDIOptions* options) | |
76 { | |
77 if (m_state != Pending || !m_successCallback) | |
dglazkov
2013/06/04 08:08:03
Should you clear error callback before returning?
Takashi Toyoshima
2013/06/04 11:44:37
Thank you.
I reconstruct this function to meet thi
| |
78 return; | |
79 m_state = Invoked; | |
80 m_successCallback->handleEvent(MIDIAccess::create(m_context).leakRef(), opti ons->sysexEnabled); | |
81 m_successCallback.clear(); | |
82 if (m_errorCallback) | |
dglazkov
2013/06/04 08:08:03
Don't need this check, right?
Takashi Toyoshima
2013/06/04 11:44:37
Done.
| |
83 m_errorCallback.clear(); | |
84 } | |
85 | |
86 void MIDIAccessFuture::reject(DOMError* error) | |
87 { | |
88 if (m_state != Pending || !m_errorCallback) | |
dglazkov
2013/06/04 08:08:03
Should you clear success callback before returning
Takashi Toyoshima
2013/06/04 11:44:37
Done.
| |
89 return; | |
90 m_state = Invoked; | |
91 m_errorCallback->handleEvent(error); | |
92 m_errorCallback.clear(); | |
93 if (m_successCallback) | |
dglazkov
2013/06/04 08:08:03
Ditto.
Takashi Toyoshima
2013/06/04 11:44:37
Done.
| |
94 m_successCallback.clear(); | |
95 } | |
96 | |
97 } // namespace WebCore | |
OLD | NEW |