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

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 6 years, 9 months 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
« no previous file with comments | « Source/modules/webmidi/NavigatorWebMIDI.h ('k') | Source/modules/webmidi/NavigatorWebMIDI.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ScriptPromise.h"
35 #include "bindings/v8/ScriptPromiseResolver.h"
36 #include "core/dom/DOMError.h"
34 #include "core/dom/Document.h" 37 #include "core/dom/Document.h"
35 #include "core/dom/ExecutionContext.h"
36 #include "core/frame/LocalFrame.h" 38 #include "core/frame/LocalFrame.h"
37 #include "core/frame/Navigator.h" 39 #include "core/frame/Navigator.h"
38 #include "modules/webmidi/MIDIAccessPromise.h" 40 #include "modules/webmidi/MIDIAccess.h"
41 #include "modules/webmidi/MIDIOptions.h"
39 42
40 namespace WebCore { 43 namespace WebCore {
41 44
42 NavigatorWebMIDI::NavigatorWebMIDI(LocalFrame* frame) 45 NavigatorWebMIDI::NavigatorWebMIDI(LocalFrame* frame)
43 : DOMWindowProperty(frame) 46 : DOMWindowProperty(frame)
44 { 47 {
45 } 48 }
46 49
47 NavigatorWebMIDI::~NavigatorWebMIDI() 50 NavigatorWebMIDI::~NavigatorWebMIDI()
48 { 51 {
49 } 52 }
50 53
51 const char* NavigatorWebMIDI::supplementName() 54 const char* NavigatorWebMIDI::supplementName()
52 { 55 {
53 return "NavigatorWebMIDI"; 56 return "NavigatorWebMIDI";
54 } 57 }
55 58
56 NavigatorWebMIDI& NavigatorWebMIDI::from(Navigator& navigator) 59 NavigatorWebMIDI& NavigatorWebMIDI::from(Navigator& navigator)
57 { 60 {
58 NavigatorWebMIDI* supplement = static_cast<NavigatorWebMIDI*>(WillBeHeapSupp lement<Navigator>::from(navigator, supplementName())); 61 NavigatorWebMIDI* supplement = static_cast<NavigatorWebMIDI*>(WillBeHeapSupp lement<Navigator>::from(navigator, supplementName()));
59 if (!supplement) { 62 if (!supplement) {
60 supplement = new NavigatorWebMIDI(navigator.frame()); 63 supplement = new NavigatorWebMIDI(navigator.frame());
61 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement)); 64 provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement));
62 } 65 }
63 return *supplement; 66 return *supplement;
64 } 67 }
65 68
66 PassRefPtrWillBeRawPtr<MIDIAccessPromise> NavigatorWebMIDI::requestMIDIAccess(Na vigator& navigator, const Dictionary& options) 69 ScriptPromise NavigatorWebMIDI::requestMIDIAccess(Navigator& navigator, const Di ctionary& options)
67 { 70 {
68 return NavigatorWebMIDI::from(navigator).requestMIDIAccess(options); 71 return NavigatorWebMIDI::from(navigator).requestMIDIAccess(options);
69 } 72 }
70 73
71 PassRefPtrWillBeRawPtr<MIDIAccessPromise> NavigatorWebMIDI::requestMIDIAccess(co nst Dictionary& options) 74 ScriptPromise NavigatorWebMIDI::requestMIDIAccess(const Dictionary& options)
72 { 75 {
73 if (!frame()) 76 if (!frame()) {
74 return nullptr; 77 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(v 8::Isolate::GetCurrent());
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 }
75 83
76 ExecutionContext* context = frame()->document(); 84 return MIDIAccess::request(MIDIOptions(options), frame()->document());
77 ASSERT(context);
78
79 return MIDIAccessPromise::create(context, options);
80 } 85 }
81 86
82 } // namespace WebCore 87 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/webmidi/NavigatorWebMIDI.h ('k') | Source/modules/webmidi/NavigatorWebMIDI.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698