Chromium Code Reviews| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 MessagePort::MessagePort(ExecutionContext& executionContext) | 55 MessagePort::MessagePort(ExecutionContext& executionContext) |
| 56 : ActiveScriptWrappable(this) | 56 : ActiveScriptWrappable(this) |
| 57 , ActiveDOMObject(&executionContext) | 57 , ActiveDOMObject(&executionContext) |
| 58 , m_started(false) | 58 , m_started(false) |
| 59 , m_closed(false) | 59 , m_closed(false) |
| 60 { | 60 { |
| 61 } | 61 } |
| 62 | 62 |
| 63 MessagePort::~MessagePort() | 63 MessagePort::~MessagePort() |
| 64 { | 64 { |
| 65 close(); | 65 close(); |
|
yhirano
2016/07/14 04:30:22
DCHECK(!started() || !isEntangled()) is better tha
tzik
2016/07/14 04:59:56
Done.
| |
| 66 if (m_scriptStateForConversion) | 66 if (m_scriptStateForConversion) |
| 67 m_scriptStateForConversion->disposePerContextData(); | 67 m_scriptStateForConversion->disposePerContextData(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void MessagePort::postMessage(ExecutionContext* context, PassRefPtr<SerializedSc riptValue> message, const MessagePortArray& ports, ExceptionState& exceptionStat e) | 70 void MessagePort::postMessage(ExecutionContext* context, PassRefPtr<SerializedSc riptValue> message, const MessagePortArray& ports, ExceptionState& exceptionStat e) |
| 71 { | 71 { |
| 72 if (!isEntangled()) | 72 if (!isEntangled()) |
| 73 return; | 73 return; |
| 74 DCHECK(getExecutionContext()); | 74 DCHECK(getExecutionContext()); |
| 75 DCHECK(m_entangledChannel); | 75 DCHECK(m_entangledChannel); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 { | 110 { |
| 111 std::unique_ptr<MessagePortChannelArray> channels = wrapUnique(new MessagePo rtChannelArray(webChannels.size())); | 111 std::unique_ptr<MessagePortChannelArray> channels = wrapUnique(new MessagePo rtChannelArray(webChannels.size())); |
| 112 for (size_t i = 0; i < webChannels.size(); ++i) | 112 for (size_t i = 0; i < webChannels.size(); ++i) |
| 113 (*channels)[i] = WebMessagePortChannelUniquePtr(webChannels[i]); | 113 (*channels)[i] = WebMessagePortChannelUniquePtr(webChannels[i]); |
| 114 return MessagePort::entanglePorts(*context, std::move(channels)); | 114 return MessagePort::entanglePorts(*context, std::move(channels)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 WebMessagePortChannelUniquePtr MessagePort::disentangle() | 117 WebMessagePortChannelUniquePtr MessagePort::disentangle() |
| 118 { | 118 { |
| 119 DCHECK(m_entangledChannel); | 119 DCHECK(m_entangledChannel); |
| 120 m_entangledChannel->setClient(0); | 120 m_entangledChannel->setClient(nullptr); |
| 121 return std::move(m_entangledChannel); | 121 return std::move(m_entangledChannel); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Invoked to notify us that there are messages available for this port. | 124 // Invoked to notify us that there are messages available for this port. |
| 125 // 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). | 125 // 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). |
| 126 void MessagePort::messageAvailable() | 126 void MessagePort::messageAvailable() |
| 127 { | 127 { |
| 128 DCHECK(getExecutionContext()); | 128 DCHECK(getExecutionContext()); |
| 129 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&Mess agePort::dispatchMessages, wrapCrossThreadWeakPersistent(this))); | 129 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&Mess agePort::dispatchMessages, wrapCrossThreadWeakPersistent(this))); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void MessagePort::start() | 132 void MessagePort::start() |
| 133 { | 133 { |
| 134 // Do nothing if we've been cloned or closed. | 134 // Do nothing if we've been cloned or closed. |
| 135 if (!isEntangled()) | 135 if (!isEntangled()) |
| 136 return; | 136 return; |
| 137 | 137 |
| 138 DCHECK(getExecutionContext()); | 138 DCHECK(getExecutionContext()); |
| 139 if (m_started) | 139 if (m_started) |
| 140 return; | 140 return; |
| 141 | 141 |
| 142 m_entangledChannel->setClient(this); | |
| 142 m_started = true; | 143 m_started = true; |
| 143 messageAvailable(); | 144 messageAvailable(); |
| 144 } | 145 } |
| 145 | 146 |
| 146 void MessagePort::close() | 147 void MessagePort::close() |
| 147 { | 148 { |
| 148 if (isEntangled()) | 149 if (isEntangled()) |
| 149 m_entangledChannel->setClient(0); | 150 m_entangledChannel->setClient(nullptr); |
| 150 m_closed = true; | 151 m_closed = true; |
| 151 } | 152 } |
| 152 | 153 |
| 153 void MessagePort::entangle(WebMessagePortChannelUniquePtr remote) | 154 void MessagePort::entangle(WebMessagePortChannelUniquePtr remote) |
| 154 { | 155 { |
| 155 // Only invoked to set our initial entanglement. | 156 // Only invoked to set our initial entanglement. |
| 156 DCHECK(!m_entangledChannel); | 157 DCHECK(!m_entangledChannel); |
| 157 DCHECK(getExecutionContext()); | 158 DCHECK(getExecutionContext()); |
| 158 | 159 |
| 159 m_entangledChannel = std::move(remote); | 160 m_entangledChannel = std::move(remote); |
| 160 m_entangledChannel->setClient(this); | |
| 161 } | 161 } |
| 162 | 162 |
| 163 const AtomicString& MessagePort::interfaceName() const | 163 const AtomicString& MessagePort::interfaceName() const |
| 164 { | 164 { |
| 165 return EventTargetNames::MessagePort; | 165 return EventTargetNames::MessagePort; |
| 166 } | 166 } |
| 167 | 167 |
| 168 static bool tryGetMessageFrom(WebMessagePortChannel& webChannel, RefPtr<Serializ edScriptValue>& message, std::unique_ptr<MessagePortChannelArray>& channels) | 168 static bool tryGetMessageFrom(WebMessagePortChannel& webChannel, RefPtr<Serializ edScriptValue>& message, std::unique_ptr<MessagePortChannelArray>& channels) |
| 169 { | 169 { |
| 170 WebString messageString; | 170 WebString messageString; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 return portArray; | 269 return portArray; |
| 270 } | 270 } |
| 271 | 271 |
| 272 DEFINE_TRACE(MessagePort) | 272 DEFINE_TRACE(MessagePort) |
| 273 { | 273 { |
| 274 ActiveDOMObject::trace(visitor); | 274 ActiveDOMObject::trace(visitor); |
| 275 EventTargetWithInlineData::trace(visitor); | 275 EventTargetWithInlineData::trace(visitor); |
| 276 } | 276 } |
| 277 | 277 |
| 278 } // namespace blink | 278 } // namespace blink |
| OLD | NEW |