| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 MessagePort* port = new MessagePort(executionContext); | 48 MessagePort* port = new MessagePort(executionContext); |
| 49 port->suspendIfNeeded(); | 49 port->suspendIfNeeded(); |
| 50 return port; | 50 return port; |
| 51 } | 51 } |
| 52 | 52 |
| 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 , m_weakFactory(this) | |
| 59 { | 58 { |
| 60 } | 59 } |
| 61 | 60 |
| 62 MessagePort::~MessagePort() | 61 MessagePort::~MessagePort() |
| 63 { | 62 { |
| 64 close(); | 63 close(); |
| 65 if (m_scriptStateForConversion) | 64 if (m_scriptStateForConversion) |
| 66 m_scriptStateForConversion->disposePerContextData(); | 65 m_scriptStateForConversion->disposePerContextData(); |
| 67 } | 66 } |
| 68 | 67 |
| 69 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) |
| 70 { | 69 { |
| 71 if (!isEntangled()) | 70 if (!isEntangled()) |
| 72 return; | 71 return; |
| 73 DCHECK(getExecutionContext()); | 72 DCHECK(getExecutionContext()); |
| 74 DCHECK(m_entangledChannel); | 73 DCHECK(m_entangledChannel); |
| 75 | 74 |
| 76 OwnPtr<MessagePortChannelArray> channels; | |
| 77 // Make sure we aren't connected to any of the passed-in ports. | 75 // Make sure we aren't connected to any of the passed-in ports. |
| 78 for (unsigned i = 0; i < ports.size(); ++i) { | 76 for (unsigned i = 0; i < ports.size(); ++i) { |
| 79 if (ports[i] == this) { | 77 if (ports[i] == this) { |
| 80 exceptionState.throwDOMException(DataCloneError, "Port at index " +
String::number(i) + " contains the source port."); | 78 exceptionState.throwDOMException(DataCloneError, "Port at index " +
String::number(i) + " contains the source port."); |
| 81 return; | 79 return; |
| 82 } | 80 } |
| 83 } | 81 } |
| 84 channels = MessagePort::disentanglePorts(context, ports, exceptionState); | 82 OwnPtr<MessagePortChannelArray> channels = MessagePort::disentanglePorts(con
text, ports, exceptionState); |
| 85 if (exceptionState.hadException()) | 83 if (exceptionState.hadException()) |
| 86 return; | 84 return; |
| 87 | 85 |
| 88 if (message->containsTransferableArrayBuffer()) | 86 if (message->containsTransferableArrayBuffer()) |
| 89 getExecutionContext()->addConsoleMessage(ConsoleMessage::create(JSMessag
eSource, WarningMessageLevel, "MessagePort cannot send an ArrayBuffer as a trans
ferable object yet. See http://crbug.com/334408")); | 87 getExecutionContext()->addConsoleMessage(ConsoleMessage::create(JSMessag
eSource, WarningMessageLevel, "MessagePort cannot send an ArrayBuffer as a trans
ferable object yet. See http://crbug.com/334408")); |
| 90 | 88 |
| 91 WebString messageString = message->toWireString(); | 89 WebString messageString = message->toWireString(); |
| 92 OwnPtr<WebMessagePortChannelArray> webChannels = toWebMessagePortChannelArra
y(channels.release()); | 90 OwnPtr<WebMessagePortChannelArray> webChannels = toWebMessagePortChannelArra
y(channels.release()); |
| 93 m_entangledChannel->postMessage(messageString, webChannels.leakPtr()); | 91 m_entangledChannel->postMessage(messageString, webChannels.leakPtr()); |
| 94 } | 92 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 119 DCHECK(m_entangledChannel); | 117 DCHECK(m_entangledChannel); |
| 120 m_entangledChannel->setClient(0); | 118 m_entangledChannel->setClient(0); |
| 121 return m_entangledChannel.release(); | 119 return m_entangledChannel.release(); |
| 122 } | 120 } |
| 123 | 121 |
| 124 // 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. |
| 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). | 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). |
| 126 void MessagePort::messageAvailable() | 124 void MessagePort::messageAvailable() |
| 127 { | 125 { |
| 128 DCHECK(getExecutionContext()); | 126 DCHECK(getExecutionContext()); |
| 129 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&Mess
agePort::dispatchMessages, m_weakFactory.createWeakPtr())); | 127 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&Mess
agePort::dispatchMessages, CrossThreadWeakPersistentThisPointer<MessagePort>(thi
s))); |
| 130 } | 128 } |
| 131 | 129 |
| 132 void MessagePort::start() | 130 void MessagePort::start() |
| 133 { | 131 { |
| 134 // Do nothing if we've been cloned or closed. | 132 // Do nothing if we've been cloned or closed. |
| 135 if (!isEntangled()) | 133 if (!isEntangled()) |
| 136 return; | 134 return; |
| 137 | 135 |
| 138 DCHECK(getExecutionContext()); | 136 DCHECK(getExecutionContext()); |
| 139 if (m_started) | 137 if (m_started) |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 { | 283 { |
| 286 DCHECK(getExecutionContext()); | 284 DCHECK(getExecutionContext()); |
| 287 if (!m_scriptStateForConversion) { | 285 if (!m_scriptStateForConversion) { |
| 288 v8::Isolate* isolate = scriptIsolate(); | 286 v8::Isolate* isolate = scriptIsolate(); |
| 289 m_scriptStateForConversion = ScriptState::create(v8::Context::New(isolat
e), DOMWrapperWorld::create(isolate)); | 287 m_scriptStateForConversion = ScriptState::create(v8::Context::New(isolat
e), DOMWrapperWorld::create(isolate)); |
| 290 } | 288 } |
| 291 return m_scriptStateForConversion->context(); | 289 return m_scriptStateForConversion->context(); |
| 292 } | 290 } |
| 293 | 291 |
| 294 } // namespace blink | 292 } // namespace blink |
| OLD | NEW |