Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: Source/modules/webmidi/NavigatorWebMIDI.cpp

Issue 77773003: Make WebMIDI use blink Promise. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: \ Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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()) {
74 return 0; 80 ScriptPromise promise = ScriptPromise::createPending();
81 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(p romise);
82 // FIXME: Currently this rejection does not work because the context is stopped.
83 resolver->reject(DOMError::create("AbortError"));
84 return promise;
85 }
75 86
76 ExecutionContext* context = frame()->document(); 87 return MIDIAccess::create(MIDIOptions(options), frame()->document(), this)-> startRequest();
77 ASSERT(context); 88 }
78 89
79 return MIDIAccessPromise::create(context, options); 90 void NavigatorWebMIDI::registerPending(MIDIAccess* access)
91 {
92 m_pending.add(PassRefPtr<MIDIAccess>(access));
93 }
94
95 void NavigatorWebMIDI::unregisterPending(MIDIAccess* access)
96 {
97 m_pending.remove(PassRefPtr<MIDIAccess>(access));
98 }
99
100 void NavigatorWebMIDI::clearPending()
101 {
102 HashSet<RefPtr<MIDIAccess> > pending;
103 pending.swap(m_pending);
104 for (HashSet<RefPtr<MIDIAccess> >::iterator i = pending.begin(); i != pendin g.end(); ++i)
105 (*i)->stop();
80 } 106 }
81 107
82 } // namespace WebCore 108 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698