OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "core/dom/ActiveDOMObject.h" | 33 #include "core/dom/ActiveDOMObject.h" |
34 #include "core/events/EventListener.h" | 34 #include "core/events/EventListener.h" |
35 #include "core/events/EventTarget.h" | 35 #include "core/events/EventTarget.h" |
36 #include "public/platform/WebMessagePortChannel.h" | 36 #include "public/platform/WebMessagePortChannel.h" |
37 #include "public/platform/WebMessagePortChannelClient.h" | 37 #include "public/platform/WebMessagePortChannelClient.h" |
38 #include "wtf/OwnPtr.h" | 38 #include "wtf/OwnPtr.h" |
39 #include "wtf/PassOwnPtr.h" | 39 #include "wtf/PassOwnPtr.h" |
40 #include "wtf/PassRefPtr.h" | 40 #include "wtf/PassRefPtr.h" |
41 #include "wtf/RefPtr.h" | 41 #include "wtf/RefPtr.h" |
42 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
| 43 #include <memory> |
43 | 44 |
44 namespace blink { | 45 namespace blink { |
45 | 46 |
46 class ExceptionState; | 47 class ExceptionState; |
47 class ExecutionContext; | 48 class ExecutionContext; |
48 class MessagePort; | 49 class MessagePort; |
49 class ScriptState; | 50 class ScriptState; |
50 class SerializedScriptValue; | 51 class SerializedScriptValue; |
51 | 52 |
52 // Not to be confused with WebMessagePortChannelArray; this one uses Vector and
OwnPtr instead of WebVector and raw pointers. | 53 // Not to be confused with WebMessagePortChannelArray; this one uses Vector and
std::unique_ptr instead of WebVector and raw pointers. |
53 typedef Vector<OwnPtr<WebMessagePortChannel>, 1> MessagePortChannelArray; | 54 typedef Vector<WebMessagePortChannelUniquePtr, 1> MessagePortChannelArray; |
54 | 55 |
55 class CORE_EXPORT MessagePort | 56 class CORE_EXPORT MessagePort |
56 : public EventTargetWithInlineData | 57 : public EventTargetWithInlineData |
57 , public ActiveScriptWrappable | 58 , public ActiveScriptWrappable |
58 , public ActiveDOMObject | 59 , public ActiveDOMObject |
59 , public WebMessagePortChannelClient { | 60 , public WebMessagePortChannelClient { |
60 DEFINE_WRAPPERTYPEINFO(); | 61 DEFINE_WRAPPERTYPEINFO(); |
61 USING_GARBAGE_COLLECTED_MIXIN(MessagePort); | 62 USING_GARBAGE_COLLECTED_MIXIN(MessagePort); |
62 public: | 63 public: |
63 static MessagePort* create(ExecutionContext&); | 64 static MessagePort* create(ExecutionContext&); |
64 ~MessagePort() override; | 65 ~MessagePort() override; |
65 | 66 |
66 void postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> messag
e, const MessagePortArray&, ExceptionState&); | 67 void postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> messag
e, const MessagePortArray&, ExceptionState&); |
67 | 68 |
68 void start(); | 69 void start(); |
69 void close(); | 70 void close(); |
70 | 71 |
71 void entangle(PassOwnPtr<WebMessagePortChannel>); | 72 void entangle(WebMessagePortChannelUniquePtr); |
72 PassOwnPtr<WebMessagePortChannel> disentangle(); | 73 WebMessagePortChannelUniquePtr disentangle(); |
73 | 74 |
74 // Returns nullptr if the passed-in array is nullptr/empty. | 75 // Returns nullptr if the passed-in array is nullptr/empty. |
75 static PassOwnPtr<WebMessagePortChannelArray> toWebMessagePortChannelArray(P
assOwnPtr<MessagePortChannelArray>); | 76 static PassOwnPtr<WebMessagePortChannelArray> toWebMessagePortChannelArray(P
assOwnPtr<MessagePortChannelArray>); |
76 | 77 |
77 // Returns an empty array if the passed array is empty. | 78 // Returns an empty array if the passed array is empty. |
78 static MessagePortArray* toMessagePortArray(ExecutionContext*, const WebMess
agePortChannelArray&); | 79 static MessagePortArray* toMessagePortArray(ExecutionContext*, const WebMess
agePortChannelArray&); |
79 | 80 |
80 // Returns nullptr if there is an exception, or if the passed-in array is nu
llptr/empty. | 81 // Returns nullptr if there is an exception, or if the passed-in array is nu
llptr/empty. |
81 static PassOwnPtr<MessagePortChannelArray> disentanglePorts(ExecutionContext
*, const MessagePortArray&, ExceptionState&); | 82 static PassOwnPtr<MessagePortChannelArray> disentanglePorts(ExecutionContext
*, const MessagePortArray&, ExceptionState&); |
82 | 83 |
(...skipping 29 matching lines...) Expand all Loading... |
112 | 113 |
113 protected: | 114 protected: |
114 explicit MessagePort(ExecutionContext&); | 115 explicit MessagePort(ExecutionContext&); |
115 bool tryGetMessage(RefPtr<SerializedScriptValue>& message, OwnPtr<MessagePor
tChannelArray>& channels); | 116 bool tryGetMessage(RefPtr<SerializedScriptValue>& message, OwnPtr<MessagePor
tChannelArray>& channels); |
116 | 117 |
117 private: | 118 private: |
118 // WebMessagePortChannelClient implementation. | 119 // WebMessagePortChannelClient implementation. |
119 void messageAvailable() override; | 120 void messageAvailable() override; |
120 void dispatchMessages(); | 121 void dispatchMessages(); |
121 | 122 |
122 OwnPtr<WebMessagePortChannel> m_entangledChannel; | 123 WebMessagePortChannelUniquePtr m_entangledChannel; |
123 | 124 |
124 bool m_started; | 125 bool m_started; |
125 bool m_closed; | 126 bool m_closed; |
126 | 127 |
127 RefPtr<ScriptState> m_scriptStateForConversion; | 128 RefPtr<ScriptState> m_scriptStateForConversion; |
128 }; | 129 }; |
129 | 130 |
130 } // namespace blink | 131 } // namespace blink |
131 | 132 |
132 #endif // MessagePort_h | 133 #endif // MessagePort_h |
OLD | NEW |