| Index: third_party/WebKit/Source/modules/broadcastchannel/BroadcastChannelConnection.h
|
| diff --git a/third_party/WebKit/Source/modules/broadcastchannel/BroadcastChannelConnection.h b/third_party/WebKit/Source/modules/broadcastchannel/BroadcastChannelConnection.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8a08b8bd59357deb8724ef702916c48f166f627e
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/modules/broadcastchannel/BroadcastChannelConnection.h
|
| @@ -0,0 +1,74 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef BroadcastChannelConnection_h
|
| +#define BroadcastChannelConnection_h
|
| +
|
| +#include "components/webmessaging/public/interfaces/broadcast_channel.mojom-blink.h"
|
| +#include "mojo/public/cpp/bindings/associated_binding.h"
|
| +#include "platform/weborigin/SecurityOriginHash.h"
|
| +#include "wtf/ListHashSet.h"
|
| +#include "wtf/text/StringHash.h"
|
| +
|
| +namespace blink {
|
| +
|
| +// To ensure proper message ordering, all BroadcastChannel instances on the same
|
| +// thread share a single mojo connection. This class represents such a
|
| +// connection. BroadcastChannel instances register themselves with the correct
|
| +// connection, and use the connection to broadcast messages.
|
| +class BroadcastChannelConnection final : public webmessaging::mojom::blink::BroadcastChannelClient {
|
| + WTF_MAKE_NONCOPYABLE(BroadcastChannelConnection);
|
| +public:
|
| + class Client {
|
| + public:
|
| + virtual String name() const = 0;
|
| + virtual SecurityOrigin* origin() const = 0;
|
| +
|
| + // Called when a message is received for this channel. Not called for
|
| + // messages send by this client to the channel.
|
| + virtual void onMessage(const String& message) = 0;
|
| +
|
| + // Called when the connection this client is registered with closes.
|
| + // After onError is called a client should not try to do anything with
|
| + // the connection anymore.
|
| + virtual void onError() = 0;
|
| + };
|
| +
|
| + // Returns the BroadcastChannelConnection instance to use for the channel
|
| + // identified by the particular origin and name. When called with the same
|
| + // parameters on the same thread this will always return the same instance,
|
| + // except if for some reason the mojo connection got severed.
|
| + // If all clients using this particular connection get closed, the
|
| + // connection itself might also be closed, in which case the next time the
|
| + // method is called a new connection is created.
|
| + static BroadcastChannelConnection* getForChannel(const RefPtr<SecurityOrigin>&, const String& name);
|
| + ~BroadcastChannelConnection();
|
| +
|
| + // Register a new client that uses this connection. The client must call
|
| + // unregisterClient when the client object is destroyed.
|
| + void registerClient(Client*);
|
| + void unregisterClient(Client*);
|
| +
|
| + // Broadcasts a message to the channel this connection is for. The message
|
| + // will be delivered to all clients except the client that send the message.
|
| + void broadcast(Client*, const String& message);
|
| +private:
|
| + BroadcastChannelConnection(const String& name, const RefPtr<SecurityOrigin>&, webmessaging::mojom::blink::BroadcastChannelClientAssociatedPtrInfo*, mojo::AssociatedGroup*);
|
| +
|
| + // webmessaging::mojom::blink::BroadcastChannelClient:
|
| + void OnMessage(const String& message) override;
|
| +
|
| + // Called when the mojo binding disconnects. Destroys this connection
|
| + // object.
|
| + void onError();
|
| +
|
| + String m_name;
|
| + RefPtr<SecurityOrigin> m_origin;
|
| + ListHashSet<Client*> m_clients;
|
| + mojo::AssociatedBinding<webmessaging::mojom::blink::BroadcastChannelClient> m_binding;
|
| +};
|
| +
|
| +} // namespace blink
|
| +
|
| +#endif // BroadcastChannelConnection_h
|
|
|