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 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 #ifndef MIDIAccess_h | 31 #ifndef MIDIAccess_h |
| 32 #define MIDIAccess_h | 32 #define MIDIAccess_h |
| 33 | 33 |
| 34 #include "bindings/v8/DOMWrapperWorld.h" | |
| 35 #include "bindings/v8/ScriptPromise.h" | |
| 36 #include "bindings/v8/ScriptPromiseResolver.h" | |
| 34 #include "bindings/v8/ScriptWrappable.h" | 37 #include "bindings/v8/ScriptWrappable.h" |
| 35 #include "core/dom/ActiveDOMObject.h" | 38 #include "core/dom/ActiveDOMObject.h" |
| 36 #include "core/events/EventTarget.h" | 39 #include "core/events/EventTarget.h" |
| 37 #include "modules/webmidi/MIDIAccessor.h" | 40 #include "modules/webmidi/MIDIAccessor.h" |
| 38 #include "modules/webmidi/MIDIAccessorClient.h" | 41 #include "modules/webmidi/MIDIAccessorClient.h" |
| 39 #include "modules/webmidi/MIDIInput.h" | 42 #include "modules/webmidi/MIDIInput.h" |
| 43 #include "modules/webmidi/MIDIOptions.h" | |
| 40 #include "modules/webmidi/MIDIOutput.h" | 44 #include "modules/webmidi/MIDIOutput.h" |
| 41 #include "wtf/RefCounted.h" | 45 #include "wtf/RefCounted.h" |
| 42 #include "wtf/RefPtr.h" | 46 #include "wtf/RefPtr.h" |
| 43 #include "wtf/Vector.h" | 47 #include "wtf/Vector.h" |
| 44 | 48 |
| 45 namespace WebCore { | 49 namespace WebCore { |
| 46 | 50 |
| 47 class ExecutionContext; | 51 class ExecutionContext; |
| 48 class MIDIAccessPromise; | 52 class NavigatorWebMIDI; |
| 49 | 53 |
| 50 class MIDIAccess : public RefCounted<MIDIAccess>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithInlineData, public MIDIAccessorClient { | 54 class MIDIAccess : public RefCounted<MIDIAccess>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithInlineData, public MIDIAccessorClient { |
| 51 REFCOUNTED_EVENT_TARGET(MIDIAccess); | 55 REFCOUNTED_EVENT_TARGET(MIDIAccess); |
| 52 public: | 56 public: |
| 53 virtual ~MIDIAccess(); | 57 virtual ~MIDIAccess(); |
| 54 static PassRefPtr<MIDIAccess> create(ExecutionContext*, MIDIAccessPromise*); | 58 static PassRefPtr<MIDIAccess> create(const MIDIOptions&, ExecutionContext*, NavigatorWebMIDI*); |
| 55 | 59 |
| 56 MIDIInputVector inputs() const { return m_inputs; } | 60 MIDIInputVector inputs() const { return m_inputs; } |
| 57 MIDIOutputVector outputs() const { return m_outputs; } | 61 MIDIOutputVector outputs() const { return m_outputs; } |
| 58 | 62 |
| 59 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); | 63 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); |
| 60 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); | 64 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); |
| 61 | 65 |
| 62 void setSysExEnabled(bool); | 66 void setSysExEnabled(bool); |
| 63 bool sysExEnabled() const { return m_sysExEnabled; } | 67 bool sysExEnabled() const { return m_sysExEnabled; } |
| 64 | 68 |
| 65 // EventTarget | 69 // EventTarget |
| 66 virtual const AtomicString& interfaceName() const OVERRIDE { return EventTar getNames::MIDIAccess; } | 70 virtual const AtomicString& interfaceName() const OVERRIDE { return EventTar getNames::MIDIAccess; } |
| 67 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD OMObject::executionContext(); } | 71 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD OMObject::executionContext(); } |
| 68 | 72 |
| 69 // ActiveDOMObject | 73 // ActiveDOMObject |
| 70 virtual void stop(); | 74 virtual void stop(); |
| 71 | 75 |
| 72 // MIDIAccessorClient | 76 // MIDIAccessorClient |
| 73 virtual void didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) OVERRIDE; | 77 virtual void didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) OVERRIDE; |
| 74 virtual void didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) OVERRIDE; | 78 virtual void didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) OVERRIDE; |
| 75 virtual void didStartSession(bool success) OVERRIDE; | 79 virtual void didStartSession(bool success) OVERRIDE; |
| 76 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) OVERRIDE; | 80 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) OVERRIDE; |
| 77 | 81 |
| 78 // |timeStampInMilliseconds| is in the same time coordinate system as perfor mance.now(). | 82 // |timeStampInMilliseconds| is in the same time coordinate system as perfor mance.now(). |
| 79 void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t leng th, double timeStampInMilliseconds); | 83 void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t leng th, double timeStampInMilliseconds); |
| 80 | 84 |
| 85 ScriptPromise startRequest(); | |
| 86 | |
| 81 private: | 87 private: |
| 82 MIDIAccess(ExecutionContext*, MIDIAccessPromise*); | 88 MIDIAccess(const MIDIOptions&, ExecutionContext*, NavigatorWebMIDI*); |
| 83 | 89 |
| 84 void startRequest(); | |
| 85 virtual void permissionDenied(); | 90 virtual void permissionDenied(); |
| 91 // This method can delete |this| object. | |
| 92 void resolve(); | |
| 93 // This method can delete |this| object. | |
| 94 void reject(PassRefPtr<DOMError>); | |
| 95 | |
| 96 // A NavigatorWebMIDI holds this MIDIAccess object as long as it is | |
| 97 // a PENDING state. Once the request succeeds or fails this object | |
| 98 // deregister itself from the navigator object. | |
|
haraken
2013/12/06 00:42:29
deregister => unregister
yhirano
2014/02/21 10:52:30
deleted
| |
| 99 // the navigator will call |stop| method when it goes invalid | |
| 100 // and then |m_navigator| will be cleard. | |
|
haraken
2013/12/06 00:42:29
cleared
yhirano
2014/02/21 10:52:30
deleted
| |
| 101 NavigatorWebMIDI* m_navigator; | |
| 86 | 102 |
| 87 MIDIInputVector m_inputs; | 103 MIDIInputVector m_inputs; |
| 88 MIDIOutputVector m_outputs; | 104 MIDIOutputVector m_outputs; |
| 89 MIDIAccessPromise* m_promise; | |
| 90 | 105 |
| 91 OwnPtr<MIDIAccessor> m_accessor; | 106 OwnPtr<MIDIAccessor> m_accessor; |
| 107 RefPtr<DOMWrapperWorld> m_world; | |
| 108 RefPtr<ScriptPromiseResolver> m_resolver; | |
| 109 MIDIOptions m_options; | |
| 92 bool m_hasAccess; | 110 bool m_hasAccess; |
| 93 bool m_sysExEnabled; | 111 bool m_sysExEnabled; |
| 94 bool m_requesting; | 112 bool m_requesting; |
| 95 }; | 113 }; |
| 96 | 114 |
| 97 } // namespace WebCore | 115 } // namespace WebCore |
| 98 | 116 |
| 99 #endif // MIDIAccess_h | 117 #endif // MIDIAccess_h |
| OLD | NEW |