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