| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PresentationSession_h | 5 #ifndef PresentationSession_h |
| 6 #define PresentationSession_h | 6 #define PresentationSession_h |
| 7 | 7 |
| 8 #include "core/events/EventTarget.h" | 8 #include "core/events/EventTarget.h" |
| 9 #include "core/fileapi/Blob.h" |
| 10 #include "core/fileapi/FileError.h" |
| 9 #include "core/frame/DOMWindowProperty.h" | 11 #include "core/frame/DOMWindowProperty.h" |
| 10 #include "public/platform/modules/presentation/WebPresentationSessionClient.h" | 12 #include "public/platform/modules/presentation/WebPresentationSessionClient.h" |
| 11 #include "wtf/text/WTFString.h" | 13 #include "wtf/text/WTFString.h" |
| 12 | 14 |
| 13 namespace WTF { | 15 namespace WTF { |
| 14 class AtomicString; | 16 class AtomicString; |
| 15 } // namespace WTF | 17 } // namespace WTF |
| 16 | 18 |
| 17 namespace blink { | 19 namespace blink { |
| 18 | 20 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 35 // EventTarget implementation. | 37 // EventTarget implementation. |
| 36 virtual const AtomicString& interfaceName() const override; | 38 virtual const AtomicString& interfaceName() const override; |
| 37 virtual ExecutionContext* executionContext() const override; | 39 virtual ExecutionContext* executionContext() const override; |
| 38 | 40 |
| 39 DECLARE_VIRTUAL_TRACE(); | 41 DECLARE_VIRTUAL_TRACE(); |
| 40 | 42 |
| 41 const String id() const { return m_id; } | 43 const String id() const { return m_id; } |
| 42 const WTF::AtomicString& state() const; | 44 const WTF::AtomicString& state() const; |
| 43 | 45 |
| 44 void send(const String& message, ExceptionState&); | 46 void send(const String& message, ExceptionState&); |
| 45 void send(PassRefPtr<DOMArrayBuffer> data, ExceptionState&); | 47 void send(PassRefPtr<DOMArrayBuffer>, ExceptionState&); |
| 46 void send(PassRefPtr<DOMArrayBufferView> data, ExceptionState&); | 48 void send(PassRefPtr<DOMArrayBufferView>, ExceptionState&); |
| 49 void send(Blob*, ExceptionState&); |
| 47 void close(); | 50 void close(); |
| 48 | 51 |
| 49 DEFINE_ATTRIBUTE_EVENT_LISTENER(message); | 52 DEFINE_ATTRIBUTE_EVENT_LISTENER(message); |
| 50 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); | 53 DEFINE_ATTRIBUTE_EVENT_LISTENER(statechange); |
| 51 | 54 |
| 52 // Returns true if and only if the WebPresentationSessionClient represents t
his session. | 55 // Returns true if and only if the WebPresentationSessionClient represents t
his session. |
| 53 bool matches(WebPresentationSessionClient*) const; | 56 bool matches(WebPresentationSessionClient*) const; |
| 54 | 57 |
| 55 // Notifies the session about its state change. | 58 // Notifies the session about its state change. |
| 56 void didChangeState(WebPresentationSessionState); | 59 void didChangeState(WebPresentationSessionState); |
| 57 | 60 |
| 58 // Notifies the session about new text message. | 61 // Notifies the session about new text message. |
| 59 void didReceiveTextMessage(const String& message); | 62 void didReceiveTextMessage(const String& message); |
| 60 | 63 |
| 61 private: | 64 private: |
| 65 class BlobLoader; |
| 66 |
| 67 enum MessageType { |
| 68 MessageTypeText, |
| 69 MessageTypeArrayBuffer, |
| 70 MessageTypeBlob, |
| 71 }; |
| 72 |
| 73 struct Message { |
| 74 Message(const String& text) |
| 75 : type(MessageTypeText) |
| 76 , text(text) { } |
| 77 |
| 78 Message(PassRefPtr<DOMArrayBuffer> arrayBuffer) |
| 79 : type(MessageTypeArrayBuffer) |
| 80 , arrayBuffer(arrayBuffer) { } |
| 81 |
| 82 Message(PassRefPtr<BlobDataHandle> blobDataHandle) |
| 83 : type(MessageTypeBlob) |
| 84 , blobDataHandle(blobDataHandle) { } |
| 85 |
| 86 MessageType type; |
| 87 String text; |
| 88 RefPtr<DOMArrayBuffer> arrayBuffer; |
| 89 RefPtr<BlobDataHandle> blobDataHandle; |
| 90 }; |
| 91 |
| 62 PresentationSession(LocalFrame*, const String& id, const String& url); | 92 PresentationSession(LocalFrame*, const String& id, const String& url); |
| 63 | 93 |
| 64 // Returns the |PresentationController| object associated with the frame | 94 // Returns the |PresentationController| object associated with the frame |
| 65 // |Presentation| corresponds to. Can return |nullptr| if the frame is | 95 // |Presentation| corresponds to. Can return |nullptr| if the frame is |
| 66 // detached from the document. | 96 // detached from the document. |
| 67 PresentationController* presentationController(); | 97 PresentationController* presentationController(); |
| 68 | 98 |
| 69 // Common send method for both ArrayBufferView and ArrayBuffer. | 99 bool canSendMessage(ExceptionState&); |
| 70 void sendInternal(const uint8_t* data, size_t, ExceptionState&); | 100 void handleMessageQueue(); |
| 101 |
| 102 // Callbacks invoked from BlobLoader. |
| 103 void didFinishLoadingBlob(PassRefPtr<DOMArrayBuffer>); |
| 104 void didFailLoadingBlob(FileError::ErrorCode); |
| 71 | 105 |
| 72 String m_id; | 106 String m_id; |
| 73 String m_url; | 107 String m_url; |
| 74 WebPresentationSessionState m_state; | 108 WebPresentationSessionState m_state; |
| 109 |
| 110 // For Blob data handling. |
| 111 Member<BlobLoader> m_blobLoader; |
| 112 Deque<OwnPtr<Message>> m_messages; |
| 75 }; | 113 }; |
| 76 | 114 |
| 77 } // namespace blink | 115 } // namespace blink |
| 78 | 116 |
| 79 #endif // PresentationSession_h | 117 #endif // PresentationSession_h |
| OLD | NEW |