| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 MessagePort::MessagePort(ExecutionContext& executionContext) | 53 MessagePort::MessagePort(ExecutionContext& executionContext) |
| 54 : ActiveScriptWrappable(this) | 54 : ActiveScriptWrappable(this) |
| 55 , ActiveDOMObject(&executionContext) | 55 , ActiveDOMObject(&executionContext) |
| 56 , m_started(false) | 56 , m_started(false) |
| 57 , m_closed(false) | 57 , m_closed(false) |
| 58 { | 58 { |
| 59 } | 59 } |
| 60 | 60 |
| 61 MessagePort::~MessagePort() | 61 MessagePort::~MessagePort() |
| 62 { | 62 { |
| 63 close(); | 63 DCHECK(!m_started || !isEntangled()); |
| 64 if (m_scriptStateForConversion) | 64 if (m_scriptStateForConversion) |
| 65 m_scriptStateForConversion->disposePerContextData(); | 65 m_scriptStateForConversion->disposePerContextData(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void MessagePort::postMessage(ExecutionContext* context, PassRefPtr<SerializedSc
riptValue> message, const MessagePortArray& ports, ExceptionState& exceptionStat
e) | 68 void MessagePort::postMessage(ExecutionContext* context, PassRefPtr<SerializedSc
riptValue> message, const MessagePortArray& ports, ExceptionState& exceptionStat
e) |
| 69 { | 69 { |
| 70 if (!isEntangled()) | 70 if (!isEntangled()) |
| 71 return; | 71 return; |
| 72 DCHECK(getExecutionContext()); | 72 DCHECK(getExecutionContext()); |
| 73 DCHECK(m_entangledChannel); | 73 DCHECK(m_entangledChannel); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 { | 108 { |
| 109 OwnPtr<MessagePortChannelArray> channels = adoptPtr(new MessagePortChannelAr
ray(webChannels.size())); | 109 OwnPtr<MessagePortChannelArray> channels = adoptPtr(new MessagePortChannelAr
ray(webChannels.size())); |
| 110 for (size_t i = 0; i < webChannels.size(); ++i) | 110 for (size_t i = 0; i < webChannels.size(); ++i) |
| 111 (*channels)[i] = adoptPtr(webChannels[i]); | 111 (*channels)[i] = adoptPtr(webChannels[i]); |
| 112 return MessagePort::entanglePorts(*context, std::move(channels)); | 112 return MessagePort::entanglePorts(*context, std::move(channels)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 PassOwnPtr<WebMessagePortChannel> MessagePort::disentangle() | 115 PassOwnPtr<WebMessagePortChannel> MessagePort::disentangle() |
| 116 { | 116 { |
| 117 DCHECK(m_entangledChannel); | 117 DCHECK(m_entangledChannel); |
| 118 m_entangledChannel->setClient(0); | 118 m_entangledChannel->setClient(nullptr); |
| 119 return std::move(m_entangledChannel); | 119 return std::move(m_entangledChannel); |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Invoked to notify us that there are messages available for this port. | 122 // Invoked to notify us that there are messages available for this port. |
| 123 // This code may be called from another thread, and so should not call any non-t
hreadsafe APIs (i.e. should not call into the entangled channel or access mutabl
e variables). | 123 // This code may be called from another thread, and so should not call any non-t
hreadsafe APIs (i.e. should not call into the entangled channel or access mutabl
e variables). |
| 124 void MessagePort::messageAvailable() | 124 void MessagePort::messageAvailable() |
| 125 { | 125 { |
| 126 DCHECK(getExecutionContext()); | 126 DCHECK(getExecutionContext()); |
| 127 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&Mess
agePort::dispatchMessages, CrossThreadWeakPersistentThisPointer<MessagePort>(thi
s))); | 127 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&Mess
agePort::dispatchMessages, CrossThreadWeakPersistentThisPointer<MessagePort>(thi
s))); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void MessagePort::start() | 130 void MessagePort::start() |
| 131 { | 131 { |
| 132 // Do nothing if we've been cloned or closed. | 132 // Do nothing if we've been cloned or closed. |
| 133 if (!isEntangled()) | 133 if (!isEntangled()) |
| 134 return; | 134 return; |
| 135 | 135 |
| 136 DCHECK(getExecutionContext()); | 136 DCHECK(getExecutionContext()); |
| 137 if (m_started) | 137 if (m_started) |
| 138 return; | 138 return; |
| 139 | 139 |
| 140 m_entangledChannel->setClient(this); |
| 140 m_started = true; | 141 m_started = true; |
| 141 messageAvailable(); | 142 messageAvailable(); |
| 142 } | 143 } |
| 143 | 144 |
| 144 void MessagePort::close() | 145 void MessagePort::close() |
| 145 { | 146 { |
| 146 if (isEntangled()) | 147 if (isEntangled()) |
| 147 m_entangledChannel->setClient(0); | 148 m_entangledChannel->setClient(nullptr); |
| 148 m_closed = true; | 149 m_closed = true; |
| 149 } | 150 } |
| 150 | 151 |
| 151 void MessagePort::entangle(PassOwnPtr<WebMessagePortChannel> remote) | 152 void MessagePort::entangle(PassOwnPtr<WebMessagePortChannel> remote) |
| 152 { | 153 { |
| 153 // Only invoked to set our initial entanglement. | 154 // Only invoked to set our initial entanglement. |
| 154 DCHECK(!m_entangledChannel); | 155 DCHECK(!m_entangledChannel); |
| 155 DCHECK(getExecutionContext()); | 156 DCHECK(getExecutionContext()); |
| 156 | 157 |
| 157 m_entangledChannel = std::move(remote); | 158 m_entangledChannel = std::move(remote); |
| 158 m_entangledChannel->setClient(this); | |
| 159 } | 159 } |
| 160 | 160 |
| 161 const AtomicString& MessagePort::interfaceName() const | 161 const AtomicString& MessagePort::interfaceName() const |
| 162 { | 162 { |
| 163 return EventTargetNames::MessagePort; | 163 return EventTargetNames::MessagePort; |
| 164 } | 164 } |
| 165 | 165 |
| 166 static bool tryGetMessageFrom(WebMessagePortChannel& webChannel, RefPtr<Serializ
edScriptValue>& message, OwnPtr<MessagePortChannelArray>& channels) | 166 static bool tryGetMessageFrom(WebMessagePortChannel& webChannel, RefPtr<Serializ
edScriptValue>& message, OwnPtr<MessagePortChannelArray>& channels) |
| 167 { | 167 { |
| 168 WebString messageString; | 168 WebString messageString; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 return portArray; | 267 return portArray; |
| 268 } | 268 } |
| 269 | 269 |
| 270 DEFINE_TRACE(MessagePort) | 270 DEFINE_TRACE(MessagePort) |
| 271 { | 271 { |
| 272 ActiveDOMObject::trace(visitor); | 272 ActiveDOMObject::trace(visitor); |
| 273 EventTargetWithInlineData::trace(visitor); | 273 EventTargetWithInlineData::trace(visitor); |
| 274 } | 274 } |
| 275 | 275 |
| 276 } // namespace blink | 276 } // namespace blink |
| OLD | NEW |