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

Side by Side Diff: Source/modules/webmidi/MIDIAccess.h

Issue 207583005: Revert of 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/modules.gypi ('k') | Source/modules/webmidi/MIDIAccess.cpp » ('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 #ifndef MIDIAccess_h 31 #ifndef MIDIAccess_h
32 #define MIDIAccess_h 32 #define MIDIAccess_h
33 33
34 #include "bindings/v8/MIDIAccessResolver.h"
35 #include "bindings/v8/ScriptPromise.h"
36 #include "bindings/v8/ScriptWrappable.h" 34 #include "bindings/v8/ScriptWrappable.h"
37 #include "core/dom/ActiveDOMObject.h" 35 #include "core/dom/ActiveDOMObject.h"
38 #include "core/events/EventTarget.h" 36 #include "core/events/EventTarget.h"
39 #include "heap/Handle.h" 37 #include "heap/Handle.h"
40 #include "modules/webmidi/MIDIAccessor.h" 38 #include "modules/webmidi/MIDIAccessor.h"
41 #include "modules/webmidi/MIDIAccessorClient.h" 39 #include "modules/webmidi/MIDIAccessorClient.h"
42 #include "modules/webmidi/MIDIInput.h" 40 #include "modules/webmidi/MIDIInput.h"
43 #include "modules/webmidi/MIDIOptions.h"
44 #include "modules/webmidi/MIDIOutput.h" 41 #include "modules/webmidi/MIDIOutput.h"
45 #include "platform/AsyncMethodRunner.h"
46 #include "wtf/RefCounted.h" 42 #include "wtf/RefCounted.h"
47 #include "wtf/RefPtr.h" 43 #include "wtf/RefPtr.h"
48 #include "wtf/WeakPtr.h" 44 #include "wtf/Vector.h"
49 45
50 namespace WebCore { 46 namespace WebCore {
51 47
52 class ExecutionContext; 48 class ExecutionContext;
49 class MIDIAccessPromise;
53 50
54 class MIDIAccess FINAL : public RefCountedWillBeRefCountedGarbageCollected<MIDIA ccess>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithIn lineData, public MIDIAccessorClient { 51 class MIDIAccess FINAL : public RefCountedWillBeRefCountedGarbageCollected<MIDIA ccess>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithIn lineData, public MIDIAccessorClient {
55 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<M IDIAccess>); 52 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<M IDIAccess>);
56 public: 53 public:
57 virtual ~MIDIAccess(); 54 virtual ~MIDIAccess();
58 // Returns a promise object that will be resolved with this MIDIAccess. 55 static PassRefPtrWillBeRawPtr<MIDIAccess> create(ExecutionContext*, MIDIAcce ssPromise*);
59 static ScriptPromise request(const MIDIOptions&, ExecutionContext*);
60 56
61 MIDIInputVector inputs() const { return m_inputs; } 57 MIDIInputVector inputs() const { return m_inputs; }
62 MIDIOutputVector outputs() const { return m_outputs; } 58 MIDIOutputVector outputs() const { return m_outputs; }
63 59
64 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); 60 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect);
65 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); 61 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect);
66 62
67 void setSysExEnabled(bool); 63 void setSysExEnabled(bool);
68 bool sysExEnabled() const { return m_sysExEnabled; } 64 bool sysExEnabled() const { return m_sysExEnabled; }
69 65
70 // EventTarget 66 // EventTarget
71 virtual const AtomicString& interfaceName() const OVERRIDE { return EventTar getNames::MIDIAccess; } 67 virtual const AtomicString& interfaceName() const OVERRIDE { return EventTar getNames::MIDIAccess; }
72 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD OMObject::executionContext(); } 68 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD OMObject::executionContext(); }
73 69
74 // ActiveDOMObject 70 // ActiveDOMObject
75 virtual void suspend() OVERRIDE;
76 virtual void resume() OVERRIDE;
77 virtual void stop() OVERRIDE; 71 virtual void stop() OVERRIDE;
78 virtual bool hasPendingActivity() const OVERRIDE;
79 72
80 // MIDIAccessorClient 73 // MIDIAccessorClient
81 virtual void didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) OVERRIDE; 74 virtual void didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) OVERRIDE;
82 virtual void didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) OVERRIDE; 75 virtual void didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) OVERRIDE;
83 virtual void didStartSession(bool success) OVERRIDE; 76 virtual void didStartSession(bool success) OVERRIDE;
84 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) OVERRIDE; 77 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) OVERRIDE;
85 78
86 // |timeStampInMilliseconds| is in the same time coordinate system as perfor mance.now(). 79 // |timeStampInMilliseconds| is in the same time coordinate system as perfor mance.now().
87 void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t leng th, double timeStampInMilliseconds); 80 void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t leng th, double timeStampInMilliseconds);
88 81
89 void trace(Visitor*); 82 void trace(Visitor*);
90 83
91 private: 84 private:
92 class PostAction; 85 MIDIAccess(ExecutionContext*, MIDIAccessPromise*);
93 enum State {
94 Requesting,
95 Resolved,
96 Stopped,
97 };
98 86
99 MIDIAccess(const MIDIOptions&, ExecutionContext*); 87 void startRequest();
100 ScriptPromise startRequest();
101
102 void permissionDenied(); 88 void permissionDenied();
103 89
104 void resolve();
105 void reject(PassRefPtr<DOMError>);
106 void resolveNow();
107 void rejectNow();
108 // Called when the promise is resolved or rejected.
109 void doPostAction(State);
110
111 State m_state;
112 WeakPtrFactory<MIDIAccess> m_weakPtrFactory;
113 MIDIInputVector m_inputs; 90 MIDIInputVector m_inputs;
114 MIDIOutputVector m_outputs; 91 MIDIOutputVector m_outputs;
92 RawPtrWillBeMember<MIDIAccessPromise> m_promise;
93
115 OwnPtr<MIDIAccessor> m_accessor; 94 OwnPtr<MIDIAccessor> m_accessor;
116 OwnPtr<MIDIAccessResolver> m_resolver; 95 bool m_hasAccess;
117 MIDIOptions m_options;
118 bool m_sysExEnabled; 96 bool m_sysExEnabled;
119 AsyncMethodRunner<MIDIAccess> m_asyncResolveRunner; 97 bool m_requesting;
120 AsyncMethodRunner<MIDIAccess> m_asyncRejectRunner;
121 RefPtr<DOMError> m_error;
122 }; 98 };
123 99
124 } // namespace WebCore 100 } // namespace WebCore
125 101
126 #endif // MIDIAccess_h 102 #endif // MIDIAccess_h
OLDNEW
« no previous file with comments | « Source/modules/modules.gypi ('k') | Source/modules/webmidi/MIDIAccess.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698