| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 { | 63 { |
| 64 close(); | 64 close(); |
| 65 if (m_scriptStateForConversion) | 65 if (m_scriptStateForConversion) |
| 66 m_scriptStateForConversion->disposePerContextData(); | 66 m_scriptStateForConversion->disposePerContextData(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void MessagePort::postMessage(ExecutionContext* context, PassRefPtr<SerializedSc
riptValue> message, const MessagePortArray* ports, ExceptionState& exceptionStat
e) | 69 void MessagePort::postMessage(ExecutionContext* context, PassRefPtr<SerializedSc
riptValue> message, const MessagePortArray* ports, ExceptionState& exceptionStat
e) |
| 70 { | 70 { |
| 71 if (!isEntangled()) | 71 if (!isEntangled()) |
| 72 return; | 72 return; |
| 73 ASSERT(getExecutionContext()); | 73 DCHECK(getExecutionContext()); |
| 74 ASSERT(m_entangledChannel); | 74 DCHECK(m_entangledChannel); |
| 75 | 75 |
| 76 OwnPtr<MessagePortChannelArray> channels; | 76 OwnPtr<MessagePortChannelArray> channels; |
| 77 // Make sure we aren't connected to any of the passed-in ports. | 77 // Make sure we aren't connected to any of the passed-in ports. |
| 78 if (ports) { | 78 if (ports) { |
| 79 for (unsigned i = 0; i < ports->size(); ++i) { | 79 for (unsigned i = 0; i < ports->size(); ++i) { |
| 80 MessagePort* dataPort = (*ports)[i]; | 80 MessagePort* dataPort = (*ports)[i]; |
| 81 if (dataPort == this) { | 81 if (dataPort == this) { |
| 82 exceptionState.throwDOMException(DataCloneError, "Port at index
" + String::number(i) + " contains the source port."); | 82 exceptionState.throwDOMException(DataCloneError, "Port at index
" + String::number(i) + " contains the source port."); |
| 83 return; | 83 return; |
| 84 } | 84 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 112 MessagePortArray* MessagePort::toMessagePortArray(ExecutionContext* context, con
st WebMessagePortChannelArray& webChannels) | 112 MessagePortArray* MessagePort::toMessagePortArray(ExecutionContext* context, con
st WebMessagePortChannelArray& webChannels) |
| 113 { | 113 { |
| 114 OwnPtr<MessagePortChannelArray> channels = adoptPtr(new MessagePortChannelAr
ray(webChannels.size())); | 114 OwnPtr<MessagePortChannelArray> channels = adoptPtr(new MessagePortChannelAr
ray(webChannels.size())); |
| 115 for (size_t i = 0; i < webChannels.size(); ++i) | 115 for (size_t i = 0; i < webChannels.size(); ++i) |
| 116 (*channels)[i] = adoptPtr(webChannels[i]); | 116 (*channels)[i] = adoptPtr(webChannels[i]); |
| 117 return MessagePort::entanglePorts(*context, channels.release()); | 117 return MessagePort::entanglePorts(*context, channels.release()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 PassOwnPtr<WebMessagePortChannel> MessagePort::disentangle() | 120 PassOwnPtr<WebMessagePortChannel> MessagePort::disentangle() |
| 121 { | 121 { |
| 122 ASSERT(m_entangledChannel); | 122 DCHECK(m_entangledChannel); |
| 123 m_entangledChannel->setClient(0); | 123 m_entangledChannel->setClient(0); |
| 124 return m_entangledChannel.release(); | 124 return m_entangledChannel.release(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Invoked to notify us that there are messages available for this port. | 127 // Invoked to notify us that there are messages available for this port. |
| 128 // 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). | 128 // 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). |
| 129 void MessagePort::messageAvailable() | 129 void MessagePort::messageAvailable() |
| 130 { | 130 { |
| 131 ASSERT(getExecutionContext()); | 131 DCHECK(getExecutionContext()); |
| 132 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&Mess
agePort::dispatchMessages, m_weakFactory.createWeakPtr())); | 132 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&Mess
agePort::dispatchMessages, m_weakFactory.createWeakPtr())); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void MessagePort::start() | 135 void MessagePort::start() |
| 136 { | 136 { |
| 137 // Do nothing if we've been cloned or closed. | 137 // Do nothing if we've been cloned or closed. |
| 138 if (!isEntangled()) | 138 if (!isEntangled()) |
| 139 return; | 139 return; |
| 140 | 140 |
| 141 ASSERT(getExecutionContext()); | 141 DCHECK(getExecutionContext()); |
| 142 if (m_started) | 142 if (m_started) |
| 143 return; | 143 return; |
| 144 | 144 |
| 145 m_started = true; | 145 m_started = true; |
| 146 messageAvailable(); | 146 messageAvailable(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void MessagePort::close() | 149 void MessagePort::close() |
| 150 { | 150 { |
| 151 if (isEntangled()) | 151 if (isEntangled()) |
| 152 m_entangledChannel->setClient(0); | 152 m_entangledChannel->setClient(0); |
| 153 m_closed = true; | 153 m_closed = true; |
| 154 } | 154 } |
| 155 | 155 |
| 156 void MessagePort::entangle(PassOwnPtr<WebMessagePortChannel> remote) | 156 void MessagePort::entangle(PassOwnPtr<WebMessagePortChannel> remote) |
| 157 { | 157 { |
| 158 // Only invoked to set our initial entanglement. | 158 // Only invoked to set our initial entanglement. |
| 159 ASSERT(!m_entangledChannel); | 159 DCHECK(!m_entangledChannel); |
| 160 ASSERT(getExecutionContext()); | 160 DCHECK(getExecutionContext()); |
| 161 | 161 |
| 162 m_entangledChannel = remote; | 162 m_entangledChannel = remote; |
| 163 m_entangledChannel->setClient(this); | 163 m_entangledChannel->setClient(this); |
| 164 } | 164 } |
| 165 | 165 |
| 166 const AtomicString& MessagePort::interfaceName() const | 166 const AtomicString& MessagePort::interfaceName() const |
| 167 { | 167 { |
| 168 return EventTargetNames::MessagePort; | 168 return EventTargetNames::MessagePort; |
| 169 } | 169 } |
| 170 | 170 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 274 } |
| 275 | 275 |
| 276 DEFINE_TRACE(MessagePort) | 276 DEFINE_TRACE(MessagePort) |
| 277 { | 277 { |
| 278 ActiveDOMObject::trace(visitor); | 278 ActiveDOMObject::trace(visitor); |
| 279 RefCountedGarbageCollectedEventTargetWithInlineData<MessagePort>::trace(visi
tor); | 279 RefCountedGarbageCollectedEventTargetWithInlineData<MessagePort>::trace(visi
tor); |
| 280 } | 280 } |
| 281 | 281 |
| 282 v8::Isolate* MessagePort::scriptIsolate() | 282 v8::Isolate* MessagePort::scriptIsolate() |
| 283 { | 283 { |
| 284 ASSERT(getExecutionContext()); | 284 DCHECK(getExecutionContext()); |
| 285 return toIsolate(getExecutionContext()); | 285 return toIsolate(getExecutionContext()); |
| 286 } | 286 } |
| 287 | 287 |
| 288 v8::Local<v8::Context> MessagePort::scriptContextForMessageConversion() | 288 v8::Local<v8::Context> MessagePort::scriptContextForMessageConversion() |
| 289 { | 289 { |
| 290 ASSERT(getExecutionContext()); | 290 DCHECK(getExecutionContext()); |
| 291 if (!m_scriptStateForConversion) { | 291 if (!m_scriptStateForConversion) { |
| 292 v8::Isolate* isolate = scriptIsolate(); | 292 v8::Isolate* isolate = scriptIsolate(); |
| 293 m_scriptStateForConversion = ScriptState::create(v8::Context::New(isolat
e), DOMWrapperWorld::create(isolate)); | 293 m_scriptStateForConversion = ScriptState::create(v8::Context::New(isolat
e), DOMWrapperWorld::create(isolate)); |
| 294 } | 294 } |
| 295 return m_scriptStateForConversion->context(); | 295 return m_scriptStateForConversion->context(); |
| 296 } | 296 } |
| 297 | 297 |
| 298 } // namespace blink | 298 } // namespace blink |
| OLD | NEW |