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..ca0c08fc9a438c35ef0cf86d8590a9ff0510e2a5 |
| --- /dev/null |
| +++ b/content/renderer/presentation/presentation_connection_proxy.h |
| @@ -0,0 +1,123 @@ |
| +// Copyright 2017 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. |
| +// |
| +// PresentationConnectionProxy's ctor sets |source_connection_| to |
| +// PresentationConnection object owned by one frame. |
| +// |
| +// To connect |controller_connection_proxy| on controlling frame with |
| +// |receiver_connection_proxy| on receiver frame: |
| +// 1. On controlling frame, create PresentationConnection object and |
| +// ControllerConnectionProxy object |controller_connection_proxy|; |
| +// 2. Create |target_connection_request|, an interface request of |
| +// controller proxy's |target_connection_| by invoking: |
| +// ControllerConnectionProxy::MakeRemoveRequest() { |
|
imcheng
2017/01/20 20:15:43
s/Remove/Remote
zhaobin
2017/01/23 19:38:49
Done.
|
| +// return mojo::MakeRequest(&target_connection_); |
| +// } |
| +// 3. Pass |controller_connection_proxy|'s interface pointer and |
| +// |target_connection_request| to browser; |
| +// 4. Browser passes |controller_connection_proxy|'s interface pointer and |
| +// |target_connection_request| to receiver frame; |
| +// 5. On receiver frame, create PresentationConnection object and |
| +// ReceiverConnectionProxy object |receiver_connection_proxy|; |
| +// 6. Bind |target_connection_request| with |receiver_connection_proxy| by |
| +// invoking: |
| +// ReceiverConnectionProxy::Bind( |
|
imcheng
2017/01/20 20:15:43
nit: This statement doesn't parse for me. Is this
zhaobin
2017/01/23 19:38:49
Done.
|
| +// blink::mojom::PresentationConnectionRequest |
| +// target_connection_request); |
| +// 7. Set receiver proxy's |target_connection_| to |
| +// |controller_connection_proxy|'s interface pointer: |
| +// ReceiverConnectionProxy::BindTargetConnection( |
| +// blink::mojom::PresentationConnectionPtr connection) |
| +// |
| +// 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(). |
| +// ControllerConnectionProxy::SendConnectionMessage() { |
| +// target_connection_->OnMessage(); |
| +// } |
| +// 3. ReceiverConnectionProxy::OnMessage() 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 created for both offscreen and non offscreen |
| +// presentations. |
| +class CONTENT_EXPORT PresentationConnectionProxy |
| + : public blink::WebPresentationConnectionProxy, |
| + public NON_EXPORTED_BASE(blink::mojom::PresentationConnection) { |
| + public: |
| + ~PresentationConnectionProxy() override; |
| + |
| + virtual void SendConnectionMessage( |
|
imcheng
2017/01/20 20:15:43
Does this need to be virtual?
zhaobin
2017/01/23 19:38:49
Used in unit test in 5th patch. (Cannot reference
|
| + 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: |
| + explicit PresentationConnectionProxy( |
| + blink::WebPresentationConnection* connection); |
| + mojo::Binding<blink::mojom::PresentationConnection> binding_; |
| + mojo::InterfacePtr<blink::mojom::PresentationConnection> target_connection_; |
| + |
| + private: |
| + blink::WebPresentationConnection* source_connection_; |
|
imcheng
2017/01/20 20:15:43
Can the pointer be const? Please also document own
zhaobin
2017/01/23 19:38:49
Done.
|
| +}; |
| + |
| +// Represents PresentationConnectionProxy object on controlling frame. |
| +class CONTENT_EXPORT ControllerConnectionProxy |
| + : public PresentationConnectionProxy { |
| + public: |
| + explicit ControllerConnectionProxy( |
| + blink::WebPresentationConnection* connection); |
| + ~ControllerConnectionProxy() override; |
| + |
| + virtual blink::mojom::PresentationConnectionPtr Bind(); |
|
imcheng
2017/01/20 20:15:43
ditto on virtual here and below. Please also inclu
zhaobin
2017/01/23 19:38:49
Done.
|
| + virtual blink::mojom::PresentationConnectionRequest MakeRemoteRequest(); |
| +}; |
| + |
| +// Represents PresentationConnectionProxy object on receiver frame. |
| +class CONTENT_EXPORT ReceiverConnectionProxy |
| + : public PresentationConnectionProxy { |
| + public: |
| + explicit ReceiverConnectionProxy( |
| + blink::WebPresentationConnection* connection); |
| + ~ReceiverConnectionProxy() override; |
| + |
| + virtual void Bind( |
| + blink::mojom::PresentationConnectionRequest target_connection_request); |
| + virtual void BindTargetConnection( |
| + blink::mojom::PresentationConnectionPtr connection); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_CONNECTION_PROXY_H_ |