Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / dom / MessagePort.h
index 4540a9b..1e7f49e 100644 (file)
 #ifndef MessagePort_h
 #define MessagePort_h
 
-#include "bindings/v8/ScriptWrappable.h"
+#include "core/dom/ActiveDOMObject.h"
 #include "core/events/EventListener.h"
 #include "core/events/EventTarget.h"
-#include "core/dom/MessagePortChannel.h"
-#include "wtf/Forward.h"
+#include "public/platform/WebMessagePortChannel.h"
+#include "public/platform/WebMessagePortChannelClient.h"
 #include "wtf/OwnPtr.h"
 #include "wtf/PassOwnPtr.h"
 #include "wtf/PassRefPtr.h"
+#include "wtf/RefCounted.h"
 #include "wtf/RefPtr.h"
 #include "wtf/Vector.h"
+#include "wtf/WeakPtr.h"
 
-namespace WebCore {
+namespace blink {
 
-class Event;
 class ExceptionState;
-class Frame;
 class MessagePort;
 class ExecutionContext;
+class SerializedScriptValue;
 
 // The overwhelmingly common case is sending a single port, so handle that efficiently with an inline buffer of size 1.
-typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray;
+typedef WillBeHeapVector<RefPtrWillBeMember<MessagePort>, 1> MessagePortArray;
 
-class MessagePort : public RefCounted<MessagePort>, public ScriptWrappable, public EventTargetWithInlineData {
+// Not to be confused with WebMessagePortChannelArray; this one uses Vector and OwnPtr instead of WebVector and raw pointers.
+typedef Vector<OwnPtr<WebMessagePortChannel>, 1> MessagePortChannelArray;
+
+class MessagePort final : public RefCountedWillBeGarbageCollectedFinalized<MessagePort>
+    , public ActiveDOMObject
+    , public EventTargetWithInlineData
+    , public WebMessagePortChannelClient {
+    DEFINE_WRAPPERTYPEINFO();
     REFCOUNTED_EVENT_TARGET(MessagePort);
+    WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(MessagePort);
 public:
-    static PassRefPtr<MessagePort> create(ExecutionContext& executionContext) { return adoptRef(new MessagePort(executionContext)); }
+    static PassRefPtrWillBeRawPtr<MessagePort> create(ExecutionContext&);
     virtual ~MessagePort();
 
-    void postMessage(PassRefPtr<SerializedScriptValue> message, const MessagePortArray*, ExceptionState&);
+    void postMessage(ExecutionContext*, PassRefPtr<SerializedScriptValue> message, const MessagePortArray*, ExceptionState&);
 
     void start();
     void close();
 
-    void entangle(PassOwnPtr<MessagePortChannel>);
-    PassOwnPtr<MessagePortChannel> disentangle();
+    void entangle(PassOwnPtr<WebMessagePortChannel>);
+    PassOwnPtr<WebMessagePortChannel> disentangle();
+
+    static PassOwnPtr<WebMessagePortChannelArray> toWebMessagePortChannelArray(PassOwnPtr<MessagePortChannelArray>);
+    static PassOwnPtrWillBeRawPtr<MessagePortArray> toMessagePortArray(ExecutionContext*, const WebMessagePortChannelArray&);
 
     // Returns 0 if there is an exception, or if the passed-in array is 0/empty.
     static PassOwnPtr<MessagePortChannelArray> disentanglePorts(const MessagePortArray*, ExceptionState&);
 
     // Returns 0 if the passed array is 0/empty.
-    static PassOwnPtr<MessagePortArray> entanglePorts(ExecutionContext&, PassOwnPtr<MessagePortChannelArray>);
+    static PassOwnPtrWillBeRawPtr<MessagePortArray> entanglePorts(ExecutionContext&, PassOwnPtr<MessagePortChannelArray>);
 
-    void messageAvailable();
     bool started() const { return m_started; }
 
-    void contextDestroyed();
+    virtual const AtomicString& interfaceName() const override;
+    virtual ExecutionContext* executionContext() const override { return ActiveDOMObject::executionContext(); }
+    virtual MessagePort* toMessagePort() override { return this; }
 
-    virtual const AtomicString& interfaceName() const OVERRIDE;
-    virtual ExecutionContext* executionContext() const OVERRIDE;
-    MessagePort* toMessagePort() OVERRIDE { return this; }
-
-    void dispatchMessages();
+    // ActiveDOMObject implementation.
+    virtual bool hasPendingActivity() const override;
+    virtual void stop() override { close(); }
 
-    bool hasPendingActivity();
-
-    void setOnmessage(PassRefPtr<EventListener> listener, DOMWrapperWorld* world)
+    void setOnmessage(PassRefPtr<EventListener> listener)
     {
-        setAttributeEventListener(EventTypeNames::message, listener, world);
+        setAttributeEventListener(EventTypeNames::message, listener);
         start();
     }
-    EventListener* onmessage(DOMWrapperWorld* world) { return getAttributeEventListener(EventTypeNames::message, world); }
+    EventListener* onmessage() { return getAttributeEventListener(EventTypeNames::message); }
 
     // A port starts out its life entangled, and remains entangled until it is closed or is cloned.
-    bool isEntangled() { return !m_closed && !isNeutered(); }
+    bool isEntangled() const { return !m_closed && !isNeutered(); }
 
     // A port gets neutered when it is transferred to a new owner via postMessage().
-    bool isNeutered() { return !m_entangledChannel; }
+    bool isNeutered() const { return !m_entangledChannel; }
 
 private:
     explicit MessagePort(ExecutionContext&);
 
-    OwnPtr<MessagePortChannel> m_entangledChannel;
+    // WebMessagePortChannelClient implementation.
+    virtual void messageAvailable() override;
+    void dispatchMessages();
+
+    OwnPtr<WebMessagePortChannel> m_entangledChannel;
 
     bool m_started;
     bool m_closed;
 
-    ExecutionContext* m_executionContext;
+    WeakPtrFactory<MessagePort> m_weakFactory;
 };
 
-} // namespace WebCore
+} // namespace blink
 
 #endif // MessagePort_h