| 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/ScriptPromise.h" | |
| 35 #include "bindings/v8/ScriptPromiseResolver.h" | |
| 36 #include "core/dom/DOMError.h" | |
| 37 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/dom/ExecutionContext.h" |
| 38 #include "core/frame/LocalFrame.h" | 36 #include "core/frame/LocalFrame.h" |
| 39 #include "core/frame/Navigator.h" | 37 #include "core/frame/Navigator.h" |
| 40 #include "modules/webmidi/MIDIAccess.h" | 38 #include "modules/webmidi/MIDIAccessPromise.h" |
| 41 #include "modules/webmidi/MIDIOptions.h" | |
| 42 | 39 |
| 43 namespace WebCore { | 40 namespace WebCore { |
| 44 | 41 |
| 45 NavigatorWebMIDI::NavigatorWebMIDI(LocalFrame* frame) | 42 NavigatorWebMIDI::NavigatorWebMIDI(LocalFrame* frame) |
| 46 : DOMWindowProperty(frame) | 43 : DOMWindowProperty(frame) |
| 47 { | 44 { |
| 48 } | 45 } |
| 49 | 46 |
| 50 NavigatorWebMIDI::~NavigatorWebMIDI() | 47 NavigatorWebMIDI::~NavigatorWebMIDI() |
| 51 { | 48 { |
| 52 } | 49 } |
| 53 | 50 |
| 54 const char* NavigatorWebMIDI::supplementName() | 51 const char* NavigatorWebMIDI::supplementName() |
| 55 { | 52 { |
| 56 return "NavigatorWebMIDI"; | 53 return "NavigatorWebMIDI"; |
| 57 } | 54 } |
| 58 | 55 |
| 59 NavigatorWebMIDI& NavigatorWebMIDI::from(Navigator& navigator) | 56 NavigatorWebMIDI& NavigatorWebMIDI::from(Navigator& navigator) |
| 60 { | 57 { |
| 61 NavigatorWebMIDI* supplement = static_cast<NavigatorWebMIDI*>(WillBeHeapSupp
lement<Navigator>::from(navigator, supplementName())); | 58 NavigatorWebMIDI* supplement = static_cast<NavigatorWebMIDI*>(WillBeHeapSupp
lement<Navigator>::from(navigator, supplementName())); |
| 62 if (!supplement) { | 59 if (!supplement) { |
| 63 supplement = new NavigatorWebMIDI(navigator.frame()); | 60 supplement = new NavigatorWebMIDI(navigator.frame()); |
| 64 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement)); | 61 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement)); |
| 65 } | 62 } |
| 66 return *supplement; | 63 return *supplement; |
| 67 } | 64 } |
| 68 | 65 |
| 69 ScriptPromise NavigatorWebMIDI::requestMIDIAccess(Navigator& navigator, const Di
ctionary& options) | 66 PassRefPtrWillBeRawPtr<MIDIAccessPromise> NavigatorWebMIDI::requestMIDIAccess(Na
vigator& navigator, const Dictionary& options) |
| 70 { | 67 { |
| 71 return NavigatorWebMIDI::from(navigator).requestMIDIAccess(options); | 68 return NavigatorWebMIDI::from(navigator).requestMIDIAccess(options); |
| 72 } | 69 } |
| 73 | 70 |
| 74 ScriptPromise NavigatorWebMIDI::requestMIDIAccess(const Dictionary& options) | 71 PassRefPtrWillBeRawPtr<MIDIAccessPromise> NavigatorWebMIDI::requestMIDIAccess(co
nst Dictionary& options) |
| 75 { | 72 { |
| 76 if (!frame()) { | 73 if (!frame()) |
| 77 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(v
8::Isolate::GetCurrent()); | 74 return nullptr; |
| 78 ScriptPromise promise = resolver->promise(); | |
| 79 // FIXME: Currently this rejection does not work because the context is
stopped. | |
| 80 resolver->reject(DOMError::create("AbortError")); | |
| 81 return promise; | |
| 82 } | |
| 83 | 75 |
| 84 return MIDIAccess::request(MIDIOptions(options), frame()->document()); | 76 ExecutionContext* context = frame()->document(); |
| 77 ASSERT(context); |
| 78 |
| 79 return MIDIAccessPromise::create(context, options); |
| 85 } | 80 } |
| 86 | 81 |
| 87 } // namespace WebCore | 82 } // namespace WebCore |
| OLD | NEW |