Chromium Code Reviews| 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 14 matching lines...) Expand all Loading... | |
| 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/ScriptPromise.h" | 34 #include "bindings/v8/ScriptPromise.h" |
| 35 #include "bindings/v8/ScriptPromiseResolverWithContext.h" | |
| 36 #include "bindings/v8/ScriptWrappable.h" | 35 #include "bindings/v8/ScriptWrappable.h" |
| 37 #include "core/dom/ActiveDOMObject.h" | 36 #include "core/dom/ActiveDOMObject.h" |
| 38 #include "modules/EventTargetModules.h" | 37 #include "modules/EventTargetModules.h" |
| 39 #include "modules/webmidi/MIDIAccessor.h" | 38 #include "modules/webmidi/MIDIAccessor.h" |
| 40 #include "modules/webmidi/MIDIAccessorClient.h" | 39 #include "modules/webmidi/MIDIAccessorClient.h" |
| 41 #include "modules/webmidi/MIDIInput.h" | 40 #include "modules/webmidi/MIDIInput.h" |
| 42 #include "modules/webmidi/MIDIOptions.h" | |
| 43 #include "modules/webmidi/MIDIOutput.h" | 41 #include "modules/webmidi/MIDIOutput.h" |
| 44 #include "platform/AsyncMethodRunner.h" | 42 #include "platform/AsyncMethodRunner.h" |
| 45 #include "platform/heap/Handle.h" | 43 #include "platform/heap/Handle.h" |
| 46 #include "wtf/RefCounted.h" | 44 #include "wtf/RefCounted.h" |
| 47 #include "wtf/RefPtr.h" | 45 #include "wtf/RefPtr.h" |
| 48 #include "wtf/WeakPtr.h" | 46 #include "wtf/WeakPtr.h" |
| 49 | 47 |
| 50 namespace WebCore { | 48 namespace WebCore { |
| 51 | 49 |
| 52 class ExecutionContext; | 50 class ExecutionContext; |
| 51 class MIDIAccessInitializer; | |
| 52 struct MIDIOptions; | |
| 53 | 53 |
| 54 class MIDIAccess FINAL : public RefCountedWillBeRefCountedGarbageCollected<MIDIA ccess>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithIn lineData, public MIDIAccessorClient { | 54 class MIDIAccess FINAL : public RefCountedWillBeRefCountedGarbageCollected<MIDIA ccess>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithIn lineData, public MIDIAccessorClient { |
| 55 REFCOUNTED_EVENT_TARGET(MIDIAccess); | 55 REFCOUNTED_EVENT_TARGET(MIDIAccess); |
| 56 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MIDIAccess); | 56 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MIDIAccess); |
| 57 public: | 57 public: |
| 58 virtual ~MIDIAccess(); | 58 virtual ~MIDIAccess(); |
| 59 // Returns a promise object that will be resolved with this MIDIAccess. | 59 // Returns a promise object that will be resolved with this MIDIAccess. |
| 60 static ScriptPromise request(const MIDIOptions&, ScriptState*); | 60 static ScriptPromise request(const MIDIOptions&, ScriptState*); |
| 61 | 61 |
| 62 MIDIInputVector inputs() const { return m_inputs; } | 62 MIDIInputVector inputs() const { return m_inputs; } |
| 63 MIDIOutputVector outputs() const { return m_outputs; } | 63 MIDIOutputVector outputs() const { return m_outputs; } |
| 64 | 64 |
| 65 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); | 65 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); |
| 66 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); | 66 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); |
| 67 | 67 |
| 68 void setSysexEnabled(bool); | |
| 69 bool sysexEnabled() const { return m_sysexEnabled; } | 68 bool sysexEnabled() const { return m_sysexEnabled; } |
| 70 | 69 |
| 71 // EventTarget | 70 // EventTarget |
| 72 virtual const AtomicString& interfaceName() const OVERRIDE { return EventTar getNames::MIDIAccess; } | 71 virtual const AtomicString& interfaceName() const OVERRIDE { return EventTar getNames::MIDIAccess; } |
| 73 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD OMObject::executionContext(); } | 72 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD OMObject::executionContext(); } |
| 74 | 73 |
| 75 // ActiveDOMObject | 74 // ActiveDOMObject |
| 76 virtual void stop() OVERRIDE; | 75 virtual void stop() OVERRIDE; |
| 77 virtual bool hasPendingActivity() const OVERRIDE; | 76 virtual bool hasPendingActivity() const OVERRIDE; |
| 78 | 77 |
| 79 // MIDIAccessorClient | 78 // MIDIAccessorClient |
| 80 virtual void didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) OVERRIDE; | 79 virtual void didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) OVERRIDE; |
| 81 virtual void didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) OVERRIDE; | 80 virtual void didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) OVERRIDE; |
|
Takashi Toyoshima
2014/06/04 22:03:53
We may want to have a comment here.
Why didStartSe
kouhei (in TOK)
2014/06/05 01:19:44
Can we have this as { ASSERT_NOT_REACHED(); }
yhirano
2014/06/05 11:35:25
Done.
yhirano
2014/06/05 11:35:25
Done.
| |
| 82 virtual void didStartSession(bool success, const String& error, const String & message) OVERRIDE; | 81 virtual void didStartSession(bool success, const String& error, const String & message) OVERRIDE { } |
| 83 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) OVERRIDE; | 82 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) OVERRIDE; |
| 84 | 83 |
| 85 // |timeStampInMilliseconds| is in the same time coordinate system as perfor mance.now(). | 84 // |timeStampInMilliseconds| is in the same time coordinate system as perfor mance.now(). |
| 86 void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t leng th, double timeStampInMilliseconds); | 85 void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t leng th, double timeStampInMilliseconds); |
| 87 | 86 |
| 87 // Initialize this object before exposing it to JavaScript. | |
| 88 void initialize(PassOwnPtr<MIDIAccessor>, bool sysexEnabled); | |
| 89 | |
| 88 virtual void trace(Visitor*) OVERRIDE; | 90 virtual void trace(Visitor*) OVERRIDE; |
| 89 | 91 |
| 90 private: | 92 private: |
| 91 class PostAction; | 93 MIDIAccess(const MIDIOptions&, ExecutionContext*); |
| 92 enum State { | |
| 93 Requesting, | |
| 94 Resolved, | |
| 95 Stopped, | |
| 96 }; | |
| 97 | 94 |
| 98 MIDIAccess(const MIDIOptions&, ExecutionContext*); | |
| 99 ScriptPromise startRequest(ScriptState*); | |
| 100 | |
| 101 void permissionDenied(); | |
| 102 | |
| 103 // Called when the promise is resolved or rejected. | |
| 104 void doPostAction(State); | |
| 105 | |
| 106 State m_state; | |
| 107 WeakPtrFactory<MIDIAccess> m_weakPtrFactory; | |
| 108 MIDIInputVector m_inputs; | 95 MIDIInputVector m_inputs; |
| 109 MIDIOutputVector m_outputs; | 96 MIDIOutputVector m_outputs; |
| 110 OwnPtr<MIDIAccessor> m_accessor; | 97 OwnPtr<MIDIAccessor> m_accessor; |
| 111 MIDIOptions m_options; | |
| 112 bool m_sysexEnabled; | 98 bool m_sysexEnabled; |
| 113 RefPtr<ScriptPromiseResolverWithContext> m_resolver; | 99 |
| 100 // FIXME: Stop owning initializer in this class. | |
| 101 OwnPtr<MIDIAccessInitializer> m_initializer; | |
| 114 }; | 102 }; |
| 115 | 103 |
| 116 } // namespace WebCore | 104 } // namespace WebCore |
| 117 | 105 |
| 118 #endif // MIDIAccess_h | 106 #endif // MIDIAccess_h |
| OLD | NEW |