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 13 matching lines...) Expand all Loading... | |
| 24 * | 24 * |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef MessagePort_h | 27 #ifndef MessagePort_h |
| 28 #define MessagePort_h | 28 #define MessagePort_h |
| 29 | 29 |
| 30 #include "bindings/v8/ScriptWrappable.h" | 30 #include "bindings/v8/ScriptWrappable.h" |
| 31 #include "core/dom/ActiveDOMObject.h" | 31 #include "core/dom/ActiveDOMObject.h" |
| 32 #include "core/events/EventListener.h" | 32 #include "core/events/EventListener.h" |
| 33 #include "core/events/EventTarget.h" | 33 #include "core/events/EventTarget.h" |
| 34 #include "heap/Handle.h" | |
| 34 #include "public/platform/WebMessagePortChannel.h" | 35 #include "public/platform/WebMessagePortChannel.h" |
| 35 #include "public/platform/WebMessagePortChannelClient.h" | 36 #include "public/platform/WebMessagePortChannelClient.h" |
| 36 #include "wtf/OwnPtr.h" | 37 #include "wtf/OwnPtr.h" |
| 37 #include "wtf/PassOwnPtr.h" | 38 #include "wtf/PassOwnPtr.h" |
| 38 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
| 39 #include "wtf/RefCounted.h" | 40 #include "wtf/RefCounted.h" |
| 40 #include "wtf/RefPtr.h" | 41 #include "wtf/RefPtr.h" |
| 41 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
| 42 #include "wtf/WeakPtr.h" | 43 #include "wtf/WeakPtr.h" |
| 43 | 44 |
| 44 namespace WebCore { | 45 namespace WebCore { |
| 45 | 46 |
| 46 class Event; | 47 class Event; |
| 47 class ExceptionState; | 48 class ExceptionState; |
| 48 class Frame; | 49 class Frame; |
| 49 class MessagePort; | 50 class MessagePort; |
| 50 class ExecutionContext; | 51 class ExecutionContext; |
| 51 class SerializedScriptValue; | 52 class SerializedScriptValue; |
| 52 | 53 |
| 53 // The overwhelmingly common case is sending a single port, so handle that effic iently with an inline buffer of size 1. | 54 // The overwhelmingly common case is sending a single port, so handle that effic iently with an inline buffer of size 1. |
| 54 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; | 55 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; |
| 55 | 56 |
| 56 // Not to be confused with blink::WebMessagePortChannelArray; this one uses Vect or and OwnPtr instead of WebVector and raw pointers. | 57 // Not to be confused with blink::WebMessagePortChannelArray; this one uses Vect or and OwnPtr instead of WebVector and raw pointers. |
| 57 typedef Vector<OwnPtr<blink::WebMessagePortChannel>, 1> MessagePortChannelArray; | 58 typedef Vector<OwnPtr<blink::WebMessagePortChannel>, 1> MessagePortChannelArray; |
| 58 | 59 |
| 59 class MessagePort FINAL : public RefCounted<MessagePort> | 60 class MessagePort FINAL : public RefCountedWillBeRefCountedGarbageCollected<Mess agePort> |
| 60 , public ActiveDOMObject | 61 , public ActiveDOMObject |
| 61 , public EventTargetWithInlineData | 62 , public EventTargetWithInlineData |
| 62 , public ScriptWrappable | 63 , public ScriptWrappable |
| 63 , public blink::WebMessagePortChannelClient { | 64 , public blink::WebMessagePortChannelClient { |
| 64 REFCOUNTED_EVENT_TARGET(MessagePort); | 65 DECLARE_GC_INFO; |
| 66 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<M essagePort>); | |
| 65 public: | 67 public: |
| 66 static PassRefPtr<MessagePort> create(ExecutionContext&); | 68 static PassRefPtrWillBeRawPtr<MessagePort> create(ExecutionContext&); |
| 67 virtual ~MessagePort(); | 69 virtual ~MessagePort(); |
| 68 | 70 |
| 69 void postMessage(PassRefPtr<SerializedScriptValue> message, const MessagePor tArray*, ExceptionState&); | 71 void postMessage(PassRefPtr<SerializedScriptValue> message, const MessagePor tArray*, ExceptionState&); |
| 70 | 72 |
| 71 void start(); | 73 void start(); |
| 72 void close(); | 74 void close(); |
| 73 | 75 |
| 74 void entangle(PassOwnPtr<blink::WebMessagePortChannel>); | 76 void entangle(PassOwnPtr<blink::WebMessagePortChannel>); |
| 75 PassOwnPtr<blink::WebMessagePortChannel> disentangle(); | 77 PassOwnPtr<blink::WebMessagePortChannel> disentangle(); |
| 76 | 78 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 96 start(); | 98 start(); |
| 97 } | 99 } |
| 98 EventListener* onmessage() { return getAttributeEventListener(EventTypeNames ::message); } | 100 EventListener* onmessage() { return getAttributeEventListener(EventTypeNames ::message); } |
| 99 | 101 |
| 100 // A port starts out its life entangled, and remains entangled until it is c losed or is cloned. | 102 // A port starts out its life entangled, and remains entangled until it is c losed or is cloned. |
| 101 bool isEntangled() const { return !m_closed && !isNeutered(); } | 103 bool isEntangled() const { return !m_closed && !isNeutered(); } |
| 102 | 104 |
| 103 // A port gets neutered when it is transferred to a new owner via postMessag e(). | 105 // A port gets neutered when it is transferred to a new owner via postMessag e(). |
| 104 bool isNeutered() const { return !m_entangledChannel; } | 106 bool isNeutered() const { return !m_entangledChannel; } |
| 105 | 107 |
| 108 void trace(Visitor*) { } | |
| 109 | |
| 106 private: | 110 private: |
| 107 explicit MessagePort(ExecutionContext&); | 111 explicit MessagePort(ExecutionContext&); |
| 108 | 112 |
| 109 // WebMessagePortChannelClient implementation. | 113 // WebMessagePortChannelClient implementation. |
| 110 virtual void messageAvailable() OVERRIDE; | 114 virtual void messageAvailable() OVERRIDE; |
| 111 void dispatchMessages(); | 115 void dispatchMessages(); |
| 112 | 116 |
| 113 OwnPtr<blink::WebMessagePortChannel> m_entangledChannel; | 117 OwnPtr<blink::WebMessagePortChannel> m_entangledChannel; |
|
Mads Ager (chromium)
2014/02/24 13:27:53
This doesn't actually point back to a WebCore Mess
| |
| 114 | 118 |
| 115 bool m_started; | 119 bool m_started; |
| 116 bool m_closed; | 120 bool m_closed; |
| 117 | 121 |
| 118 WeakPtrFactory<MessagePort> m_weakFactory; | 122 WeakPtrFactory<MessagePort> m_weakFactory; |
|
Mads Ager (chromium)
2014/02/24 13:27:53
Down the line we should use real weak pointers pro
haraken
2014/02/24 13:28:36
Shouldn't this become a WeakMember<MessagePort> ?
| |
| 119 }; | 123 }; |
| 120 | 124 |
| 121 } // namespace WebCore | 125 } // namespace WebCore |
| 122 | 126 |
| 123 #endif // MessagePort_h | 127 #endif // MessagePort_h |
| OLD | NEW |