| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 class MessagePort; | 46 class MessagePort; |
| 47 class ExecutionContext; | 47 class ExecutionContext; |
| 48 class SerializedScriptValue; | 48 class SerializedScriptValue; |
| 49 | 49 |
| 50 // The overwhelmingly common case is sending a single port, so handle that effic
iently with an inline buffer of size 1. | 50 // The overwhelmingly common case is sending a single port, so handle that effic
iently with an inline buffer of size 1. |
| 51 typedef WillBeHeapVector<RefPtrWillBeMember<MessagePort>, 1> MessagePortArray; | 51 typedef WillBeHeapVector<RefPtrWillBeMember<MessagePort>, 1> MessagePortArray; |
| 52 | 52 |
| 53 // Not to be confused with WebMessagePortChannelArray; this one uses Vector and
OwnPtr instead of WebVector and raw pointers. | 53 // Not to be confused with WebMessagePortChannelArray; this one uses Vector and
OwnPtr instead of WebVector and raw pointers. |
| 54 typedef Vector<OwnPtr<WebMessagePortChannel>, 1> MessagePortChannelArray; | 54 typedef Vector<OwnPtr<WebMessagePortChannel>, 1> MessagePortChannelArray; |
| 55 | 55 |
| 56 class MessagePort FINAL : public RefCountedWillBeGarbageCollectedFinalized<Messa
gePort> | 56 class MessagePort final : public RefCountedWillBeGarbageCollectedFinalized<Messa
gePort> |
| 57 , public ActiveDOMObject | 57 , public ActiveDOMObject |
| 58 , public EventTargetWithInlineData | 58 , public EventTargetWithInlineData |
| 59 , public WebMessagePortChannelClient { | 59 , public WebMessagePortChannelClient { |
| 60 DEFINE_WRAPPERTYPEINFO(); | 60 DEFINE_WRAPPERTYPEINFO(); |
| 61 REFCOUNTED_EVENT_TARGET(MessagePort); | 61 REFCOUNTED_EVENT_TARGET(MessagePort); |
| 62 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MessagePort); | 62 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MessagePort); |
| 63 public: | 63 public: |
| 64 static PassRefPtrWillBeRawPtr<MessagePort> create(ExecutionContext&); | 64 static PassRefPtrWillBeRawPtr<MessagePort> create(ExecutionContext&); |
| 65 virtual ~MessagePort(); | 65 virtual ~MessagePort(); |
| 66 | 66 |
| 67 void postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> messag
e, const MessagePortArray*, ExceptionState&); | 67 void postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> messag
e, const MessagePortArray*, ExceptionState&); |
| 68 | 68 |
| 69 void start(); | 69 void start(); |
| 70 void close(); | 70 void close(); |
| 71 | 71 |
| 72 void entangle(PassOwnPtr<WebMessagePortChannel>); | 72 void entangle(PassOwnPtr<WebMessagePortChannel>); |
| 73 PassOwnPtr<WebMessagePortChannel> disentangle(); | 73 PassOwnPtr<WebMessagePortChannel> disentangle(); |
| 74 | 74 |
| 75 static PassOwnPtr<WebMessagePortChannelArray> toWebMessagePortChannelArray(P
assOwnPtr<MessagePortChannelArray>); | 75 static PassOwnPtr<WebMessagePortChannelArray> toWebMessagePortChannelArray(P
assOwnPtr<MessagePortChannelArray>); |
| 76 static PassOwnPtrWillBeRawPtr<MessagePortArray> toMessagePortArray(Execution
Context*, const WebMessagePortChannelArray&); | 76 static PassOwnPtrWillBeRawPtr<MessagePortArray> toMessagePortArray(Execution
Context*, const WebMessagePortChannelArray&); |
| 77 | 77 |
| 78 // Returns 0 if there is an exception, or if the passed-in array is 0/empty. | 78 // Returns 0 if there is an exception, or if the passed-in array is 0/empty. |
| 79 static PassOwnPtr<MessagePortChannelArray> disentanglePorts(const MessagePor
tArray*, ExceptionState&); | 79 static PassOwnPtr<MessagePortChannelArray> disentanglePorts(const MessagePor
tArray*, ExceptionState&); |
| 80 | 80 |
| 81 // Returns 0 if the passed array is 0/empty. | 81 // Returns 0 if the passed array is 0/empty. |
| 82 static PassOwnPtrWillBeRawPtr<MessagePortArray> entanglePorts(ExecutionConte
xt&, PassOwnPtr<MessagePortChannelArray>); | 82 static PassOwnPtrWillBeRawPtr<MessagePortArray> entanglePorts(ExecutionConte
xt&, PassOwnPtr<MessagePortChannelArray>); |
| 83 | 83 |
| 84 bool started() const { return m_started; } | 84 bool started() const { return m_started; } |
| 85 | 85 |
| 86 virtual const AtomicString& interfaceName() const OVERRIDE; | 86 virtual const AtomicString& interfaceName() const override; |
| 87 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD
OMObject::executionContext(); } | 87 virtual ExecutionContext* executionContext() const override { return ActiveD
OMObject::executionContext(); } |
| 88 virtual MessagePort* toMessagePort() OVERRIDE { return this; } | 88 virtual MessagePort* toMessagePort() override { return this; } |
| 89 | 89 |
| 90 // ActiveDOMObject implementation. | 90 // ActiveDOMObject implementation. |
| 91 virtual bool hasPendingActivity() const OVERRIDE; | 91 virtual bool hasPendingActivity() const override; |
| 92 virtual void stop() OVERRIDE { close(); } | 92 virtual void stop() override { close(); } |
| 93 | 93 |
| 94 void setOnmessage(PassRefPtr<EventListener> listener) | 94 void setOnmessage(PassRefPtr<EventListener> listener) |
| 95 { | 95 { |
| 96 setAttributeEventListener(EventTypeNames::message, listener); | 96 setAttributeEventListener(EventTypeNames::message, listener); |
| 97 start(); | 97 start(); |
| 98 } | 98 } |
| 99 EventListener* onmessage() { return getAttributeEventListener(EventTypeNames
::message); } | 99 EventListener* onmessage() { return getAttributeEventListener(EventTypeNames
::message); } |
| 100 | 100 |
| 101 // A port starts out its life entangled, and remains entangled until it is c
losed or is cloned. | 101 // A port starts out its life entangled, and remains entangled until it is c
losed or is cloned. |
| 102 bool isEntangled() const { return !m_closed && !isNeutered(); } | 102 bool isEntangled() const { return !m_closed && !isNeutered(); } |
| 103 | 103 |
| 104 // A port gets neutered when it is transferred to a new owner via postMessag
e(). | 104 // A port gets neutered when it is transferred to a new owner via postMessag
e(). |
| 105 bool isNeutered() const { return !m_entangledChannel; } | 105 bool isNeutered() const { return !m_entangledChannel; } |
| 106 | 106 |
| 107 private: | 107 private: |
| 108 explicit MessagePort(ExecutionContext&); | 108 explicit MessagePort(ExecutionContext&); |
| 109 | 109 |
| 110 // WebMessagePortChannelClient implementation. | 110 // WebMessagePortChannelClient implementation. |
| 111 virtual void messageAvailable() OVERRIDE; | 111 virtual void messageAvailable() override; |
| 112 void dispatchMessages(); | 112 void dispatchMessages(); |
| 113 | 113 |
| 114 OwnPtr<WebMessagePortChannel> m_entangledChannel; | 114 OwnPtr<WebMessagePortChannel> m_entangledChannel; |
| 115 | 115 |
| 116 bool m_started; | 116 bool m_started; |
| 117 bool m_closed; | 117 bool m_closed; |
| 118 | 118 |
| 119 WeakPtrFactory<MessagePort> m_weakFactory; | 119 WeakPtrFactory<MessagePort> m_weakFactory; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 } // namespace blink | 122 } // namespace blink |
| 123 | 123 |
| 124 #endif // MessagePort_h | 124 #endif // MessagePort_h |
| OLD | NEW |