Chromium Code Reviews| Index: content/renderer/presentation/presentation_connection_proxy.h |
| diff --git a/content/renderer/presentation/presentation_connection_proxy.h b/content/renderer/presentation/presentation_connection_proxy.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..88bbd71d90e131bd10a6743089e5445989ab5800 |
| --- /dev/null |
| +++ b/content/renderer/presentation/presentation_connection_proxy.h |
| @@ -0,0 +1,96 @@ |
| +// 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 CONTENT_RENDERER_PRESENTATION_PRESENTATION_CONNECTION_PROXY_H_ |
| +#define CONTENT_RENDERER_PRESENTATION_PRESENTATION_CONNECTION_PROXY_H_ |
| + |
| +#include "base/callback.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| +#include "third_party/WebKit/public/platform/modules/presentation/WebPresentationConnectionProxy.h" |
| +#include "third_party/WebKit/public/platform/modules/presentation/presentation.mojom.h" |
| + |
| +namespace blink { |
| +class WebPresentationConnection; |
| +} // namespace blink |
| + |
| +namespace content { |
| + |
| +using OnMessageCallback = base::Callback<void(bool)>; |
| + |
| +// This class connects PresentationConnection owned by one frame with |
| +// PresentationConnection owned by a different frame. |
| +// |
| +// |SetSourceConnection| sets |source_connection_| to PresentationConnection |
| +// object owned by one frame. |
| +// |SetTargetConnection| sets |target_connection_| to mojo handle of |
| +// PresentationConnection object owned by a different frame. |
|
dcheng
2017/01/17 23:31:49
Nit: update these comments? I found them helpful w
zhaobin
2017/01/18 18:25:47
Done.
|
| +// |
| +// When both |source_connection_| and |target_connection_| are set, |
| +// we can send message or notify state changes between controller and receiver. |
| +// |
| +// To send message from controlling frame to receiver frame: |
| +// 1. Controlling frame invokes connection.sendMessage(); |
| +// 2. This call is delegated to controller presentation connection proxy's |
| +// SendString(). |
| +// PresentationConnectionProxy::SendString() { |
| +// target_connection_->OnConnectionMessageReceived(); |
| +// } |
| +// 3. Receiver PresentationConnectionProxy::OnConnectionMessageReceived() is |
| +// invoked. |
| +// 4. connection.onmessage event on receiver frame is fired. |
| +// |
| +// Sending message from receiver frame to controlling frame and notifying state |
| +// changes works the same. |
| +// |
| +// Instance of this class is only created for offscreen presentations. |
| +class CONTENT_EXPORT PresentationConnectionProxy |
| + : public blink::WebPresentationConnectionProxy, |
| + public NON_EXPORTED_BASE(blink::mojom::PresentationConnection) { |
| + public: |
| + ~PresentationConnectionProxy() override; |
| + |
| + virtual void SendConnectionMessage( |
| + blink::mojom::ConnectionMessagePtr session_message, |
| + const OnMessageCallback& callback) const; |
| + |
| + // blink::mojom::PresentationConnection implementation |
| + void OnMessage(blink::mojom::ConnectionMessagePtr message, |
| + const OnMessageCallback& callback) override; |
| + void DidChangeState(blink::mojom::PresentationConnectionState state) override; |
| + |
| + protected: |
| + PresentationConnectionProxy(blink::WebPresentationConnection*); |
|
dcheng
2017/01/17 23:31:49
Nit: explicit (also, please name the constructor p
zhaobin
2017/01/18 18:25:47
Done.
|
| + mojo::Binding<blink::mojom::PresentationConnection> binding_; |
| + mojo::InterfacePtr<blink::mojom::PresentationConnection> target_connection_; |
| + |
| + private: |
| + blink::WebPresentationConnection* source_connection_; |
| +}; |
| + |
| +// Represents PresentationConnectionProxy object on controlling frame. |
| +class CONTENT_EXPORT ControllerConnectionProxy |
| + : public PresentationConnectionProxy { |
| + public: |
| + ControllerConnectionProxy(blink::WebPresentationConnection*); |
|
dcheng
2017/01/17 23:31:49
Ditto with explicit here.
zhaobin
2017/01/18 18:25:47
Done.
|
| + ~ControllerConnectionProxy() override; |
| + |
| + virtual blink::mojom::PresentationConnectionPtr Bind(); |
| + virtual blink::mojom::PresentationConnectionRequest MakeRemoteRequest(); |
| +}; |
| + |
| +// Represents PresentationConnectionProxy object on receiver frame. |
| +class CONTENT_EXPORT ReceiverConnectionProxy |
| + : public PresentationConnectionProxy { |
| + public: |
| + ReceiverConnectionProxy(blink::WebPresentationConnection*); |
| + ~ReceiverConnectionProxy() override; |
| + |
| + virtual void Bind(blink::mojom::PresentationConnectionRequest); |
| + virtual void SetTargetConnection( |
| + blink::mojom::PresentationConnectionPtr connection); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_CONNECTION_PROXY_H_ |