| 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/LocalFrame.h" | 40 #include "core/frame/LocalFrame.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(LocalFrame* frame) | 47 NavigatorWebMIDI::NavigatorWebMIDI(LocalFrame* frame) |
| 43 : DOMWindowProperty(frame) | 48 : DOMWindowProperty(frame) |
| 44 { | 49 { |
| 45 } | 50 } |
| 46 | 51 |
| 47 NavigatorWebMIDI::~NavigatorWebMIDI() | 52 NavigatorWebMIDI::~NavigatorWebMIDI() |
| 48 { | 53 { |
| 49 } | 54 } |
| 50 | 55 |
| 51 const char* NavigatorWebMIDI::supplementName() | 56 const char* NavigatorWebMIDI::supplementName() |
| 52 { | 57 { |
| 53 return "NavigatorWebMIDI"; | 58 return "NavigatorWebMIDI"; |
| 54 } | 59 } |
| 55 | 60 |
| 56 NavigatorWebMIDI& NavigatorWebMIDI::from(Navigator& navigator) | 61 NavigatorWebMIDI& NavigatorWebMIDI::from(Navigator& navigator) |
| 57 { | 62 { |
| 58 NavigatorWebMIDI* supplement = static_cast<NavigatorWebMIDI*>(Supplement<Nav
igator>::from(navigator, supplementName())); | 63 NavigatorWebMIDI* supplement = static_cast<NavigatorWebMIDI*>(Supplement<Nav
igator>::from(navigator, supplementName())); |
| 59 if (!supplement) { | 64 if (!supplement) { |
| 60 supplement = new NavigatorWebMIDI(navigator.frame()); | 65 supplement = new NavigatorWebMIDI(navigator.frame()); |
| 61 provideTo(navigator, supplementName(), adoptPtr(supplement)); | 66 provideTo(navigator, supplementName(), adoptPtr(supplement)); |
| 62 } | 67 } |
| 63 return *supplement; | 68 return *supplement; |
| 64 } | 69 } |
| 65 | 70 |
| 66 PassRefPtrWillBeRawPtr<MIDIAccessPromise> NavigatorWebMIDI::requestMIDIAccess(Na
vigator& navigator, const Dictionary& options) | 71 ScriptPromise NavigatorWebMIDI::requestMIDIAccess(Navigator& navigator, const Di
ctionary& options) |
| 67 { | 72 { |
| 68 return NavigatorWebMIDI::from(navigator).requestMIDIAccess(options); | 73 return NavigatorWebMIDI::from(navigator).requestMIDIAccess(options); |
| 69 } | 74 } |
| 70 | 75 |
| 71 PassRefPtrWillBeRawPtr<MIDIAccessPromise> NavigatorWebMIDI::requestMIDIAccess(co
nst Dictionary& options) | 76 ScriptPromise NavigatorWebMIDI::requestMIDIAccess(const Dictionary& options) |
| 72 { | 77 { |
| 73 if (!frame()) | 78 if (!frame()) { |
| 74 return nullptr; | 79 ScriptPromise promise = ScriptPromise::createPending(); |
| 80 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(p
romise); |
| 81 // FIXME: Currently this rejection does not work because the context is
stopped. |
| 82 resolver->reject(DOMError::create("AbortError")); |
| 83 return promise; |
| 84 } |
| 75 | 85 |
| 76 ExecutionContext* context = frame()->document(); | 86 return MIDIAccess::create(MIDIOptions(options), frame()->document())->startR
equest(); |
| 77 ASSERT(context); | |
| 78 | |
| 79 return MIDIAccessPromise::create(context, options); | |
| 80 } | 87 } |
| 81 | 88 |
| 82 } // namespace WebCore | 89 } // namespace WebCore |
| OLD | NEW |