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 17 matching lines...) Expand all Loading... |
28 #define MessagePort_h | 28 #define MessagePort_h |
29 | 29 |
30 #include "bindings/core/v8/ActiveScriptWrappable.h" | 30 #include "bindings/core/v8/ActiveScriptWrappable.h" |
31 #include "bindings/core/v8/SerializedScriptValue.h" | 31 #include "bindings/core/v8/SerializedScriptValue.h" |
32 #include "core/CoreExport.h" | 32 #include "core/CoreExport.h" |
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" | |
39 #include "wtf/PassOwnPtr.h" | |
40 #include "wtf/PassRefPtr.h" | 38 #include "wtf/PassRefPtr.h" |
41 #include "wtf/RefPtr.h" | 39 #include "wtf/RefPtr.h" |
42 #include "wtf/Vector.h" | 40 #include "wtf/Vector.h" |
43 #include <memory> | 41 #include <memory> |
44 | 42 |
45 namespace blink { | 43 namespace blink { |
46 | 44 |
47 class ExceptionState; | 45 class ExceptionState; |
48 class ExecutionContext; | 46 class ExecutionContext; |
49 class MessagePort; | 47 class MessagePort; |
(...skipping 16 matching lines...) Expand all Loading... |
66 | 64 |
67 void postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> messag
e, const MessagePortArray&, ExceptionState&); | 65 void postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> messag
e, const MessagePortArray&, ExceptionState&); |
68 | 66 |
69 void start(); | 67 void start(); |
70 void close(); | 68 void close(); |
71 | 69 |
72 void entangle(WebMessagePortChannelUniquePtr); | 70 void entangle(WebMessagePortChannelUniquePtr); |
73 WebMessagePortChannelUniquePtr disentangle(); | 71 WebMessagePortChannelUniquePtr disentangle(); |
74 | 72 |
75 // Returns nullptr if the passed-in array is nullptr/empty. | 73 // Returns nullptr if the passed-in array is nullptr/empty. |
76 static PassOwnPtr<WebMessagePortChannelArray> toWebMessagePortChannelArray(P
assOwnPtr<MessagePortChannelArray>); | 74 static std::unique_ptr<WebMessagePortChannelArray> toWebMessagePortChannelAr
ray(std::unique_ptr<MessagePortChannelArray>); |
77 | 75 |
78 // Returns an empty array if the passed array is empty. | 76 // Returns an empty array if the passed array is empty. |
79 static MessagePortArray* toMessagePortArray(ExecutionContext*, const WebMess
agePortChannelArray&); | 77 static MessagePortArray* toMessagePortArray(ExecutionContext*, const WebMess
agePortChannelArray&); |
80 | 78 |
81 // Returns nullptr if there is an exception, or if the passed-in array is nu
llptr/empty. | 79 // Returns nullptr if there is an exception, or if the passed-in array is nu
llptr/empty. |
82 static PassOwnPtr<MessagePortChannelArray> disentanglePorts(ExecutionContext
*, const MessagePortArray&, ExceptionState&); | 80 static std::unique_ptr<MessagePortChannelArray> disentanglePorts(ExecutionCo
ntext*, const MessagePortArray&, ExceptionState&); |
83 | 81 |
84 // Returns an empty array if the passed array is nullptr/empty. | 82 // Returns an empty array if the passed array is nullptr/empty. |
85 static MessagePortArray* entanglePorts(ExecutionContext&, PassOwnPtr<Message
PortChannelArray>); | 83 static MessagePortArray* entanglePorts(ExecutionContext&, std::unique_ptr<Me
ssagePortChannelArray>); |
86 | 84 |
87 bool started() const { return m_started; } | 85 bool started() const { return m_started; } |
88 | 86 |
89 const AtomicString& interfaceName() const override; | 87 const AtomicString& interfaceName() const override; |
90 ExecutionContext* getExecutionContext() const override { return ActiveDOMObj
ect::getExecutionContext(); } | 88 ExecutionContext* getExecutionContext() const override { return ActiveDOMObj
ect::getExecutionContext(); } |
91 MessagePort* toMessagePort() override { return this; } | 89 MessagePort* toMessagePort() override { return this; } |
92 | 90 |
93 // ActiveScriptWrappable implementation. | 91 // ActiveScriptWrappable implementation. |
94 bool hasPendingActivity() const final; | 92 bool hasPendingActivity() const final; |
95 | 93 |
(...skipping 10 matching lines...) Expand all Loading... |
106 // A port starts out its life entangled, and remains entangled until it is c
losed or is cloned. | 104 // A port starts out its life entangled, and remains entangled until it is c
losed or is cloned. |
107 bool isEntangled() const { return !m_closed && !isNeutered(); } | 105 bool isEntangled() const { return !m_closed && !isNeutered(); } |
108 | 106 |
109 // A port gets neutered when it is transferred to a new owner via postMessag
e(). | 107 // A port gets neutered when it is transferred to a new owner via postMessag
e(). |
110 bool isNeutered() const { return !m_entangledChannel; } | 108 bool isNeutered() const { return !m_entangledChannel; } |
111 | 109 |
112 DECLARE_VIRTUAL_TRACE(); | 110 DECLARE_VIRTUAL_TRACE(); |
113 | 111 |
114 protected: | 112 protected: |
115 explicit MessagePort(ExecutionContext&); | 113 explicit MessagePort(ExecutionContext&); |
116 bool tryGetMessage(RefPtr<SerializedScriptValue>& message, OwnPtr<MessagePor
tChannelArray>& channels); | 114 bool tryGetMessage(RefPtr<SerializedScriptValue>& message, std::unique_ptr<M
essagePortChannelArray>& channels); |
117 | 115 |
118 private: | 116 private: |
119 // WebMessagePortChannelClient implementation. | 117 // WebMessagePortChannelClient implementation. |
120 void messageAvailable() override; | 118 void messageAvailable() override; |
121 void dispatchMessages(); | 119 void dispatchMessages(); |
122 | 120 |
123 WebMessagePortChannelUniquePtr m_entangledChannel; | 121 WebMessagePortChannelUniquePtr m_entangledChannel; |
124 | 122 |
125 bool m_started; | 123 bool m_started; |
126 bool m_closed; | 124 bool m_closed; |
127 | 125 |
128 RefPtr<ScriptState> m_scriptStateForConversion; | 126 RefPtr<ScriptState> m_scriptStateForConversion; |
129 }; | 127 }; |
130 | 128 |
131 } // namespace blink | 129 } // namespace blink |
132 | 130 |
133 #endif // MessagePort_h | 131 #endif // MessagePort_h |
OLD | NEW |