Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_PRESENTATION_PRESENTATION_CONNECTION_PROXY_H_ | |
| 6 #define CONTENT_RENDERER_PRESENTATION_PRESENTATION_CONNECTION_PROXY_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "mojo/public/cpp/bindings/binding.h" | |
| 10 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nConnectionProxy.h" | |
| 11 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 class WebPresentationConnection; | |
| 15 } // namespace blink | |
| 16 | |
| 17 namespace content { | |
| 18 | |
| 19 using OnMessageCallback = base::Callback<void(bool)>; | |
| 20 | |
| 21 // This class connects PresentationConnection owned by one frame with | |
| 22 // PresentationConnection owned by a different frame. | |
| 23 // | |
| 24 // PresentationConnectionProxy's ctor sets |source_connection_| to | |
| 25 // PresentationConnection object owned by one frame. | |
| 26 // | |
| 27 // To connect |controller_connection_proxy| on controlling frame with | |
| 28 // |receiver_connection_proxy| on receiver frame: | |
| 29 // 1. On controlling frame, create PresentationConnection object and | |
| 30 // ControllerConnectionProxy object |controller_connection_proxy|; | |
| 31 // 2. Create |target_connection_request|, an interface request of | |
| 32 // controller proxy's |target_connection_| by invoking: | |
| 33 // ControllerConnectionProxy::MakeRemoveRequest() { | |
|
imcheng
2017/01/20 20:15:43
s/Remove/Remote
zhaobin
2017/01/23 19:38:49
Done.
| |
| 34 // return mojo::MakeRequest(&target_connection_); | |
| 35 // } | |
| 36 // 3. Pass |controller_connection_proxy|'s interface pointer and | |
| 37 // |target_connection_request| to browser; | |
| 38 // 4. Browser passes |controller_connection_proxy|'s interface pointer and | |
| 39 // |target_connection_request| to receiver frame; | |
| 40 // 5. On receiver frame, create PresentationConnection object and | |
| 41 // ReceiverConnectionProxy object |receiver_connection_proxy|; | |
| 42 // 6. Bind |target_connection_request| with |receiver_connection_proxy| by | |
| 43 // invoking: | |
| 44 // 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.
| |
| 45 // blink::mojom::PresentationConnectionRequest | |
| 46 // target_connection_request); | |
| 47 // 7. Set receiver proxy's |target_connection_| to | |
| 48 // |controller_connection_proxy|'s interface pointer: | |
| 49 // ReceiverConnectionProxy::BindTargetConnection( | |
| 50 // blink::mojom::PresentationConnectionPtr connection) | |
| 51 // | |
| 52 // When both |source_connection_| and |target_connection_| are set, | |
| 53 // we can send message or notify state changes between controller and receiver. | |
| 54 // | |
| 55 // To send message from controlling frame to receiver frame: | |
| 56 // 1. Controlling frame invokes connection.sendMessage(); | |
| 57 // 2. This call is delegated to controller presentation connection proxy's | |
| 58 // SendString(). | |
| 59 // ControllerConnectionProxy::SendConnectionMessage() { | |
| 60 // target_connection_->OnMessage(); | |
| 61 // } | |
| 62 // 3. ReceiverConnectionProxy::OnMessage() is invoked. | |
| 63 // 4. connection.onmessage event on receiver frame is fired. | |
| 64 // | |
| 65 // Sending message from receiver frame to controlling frame and notifying state | |
| 66 // changes works the same. | |
| 67 // | |
| 68 // Instance of this class is created for both offscreen and non offscreen | |
| 69 // presentations. | |
| 70 class CONTENT_EXPORT PresentationConnectionProxy | |
| 71 : public blink::WebPresentationConnectionProxy, | |
| 72 public NON_EXPORTED_BASE(blink::mojom::PresentationConnection) { | |
| 73 public: | |
| 74 ~PresentationConnectionProxy() override; | |
| 75 | |
| 76 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
| |
| 77 blink::mojom::ConnectionMessagePtr session_message, | |
| 78 const OnMessageCallback& callback) const; | |
| 79 | |
| 80 // blink::mojom::PresentationConnection implementation | |
| 81 void OnMessage(blink::mojom::ConnectionMessagePtr message, | |
| 82 const OnMessageCallback& callback) override; | |
| 83 void DidChangeState(blink::mojom::PresentationConnectionState state) override; | |
| 84 | |
| 85 protected: | |
| 86 explicit PresentationConnectionProxy( | |
| 87 blink::WebPresentationConnection* connection); | |
| 88 mojo::Binding<blink::mojom::PresentationConnection> binding_; | |
| 89 mojo::InterfacePtr<blink::mojom::PresentationConnection> target_connection_; | |
| 90 | |
| 91 private: | |
| 92 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.
| |
| 93 }; | |
| 94 | |
| 95 // Represents PresentationConnectionProxy object on controlling frame. | |
| 96 class CONTENT_EXPORT ControllerConnectionProxy | |
| 97 : public PresentationConnectionProxy { | |
| 98 public: | |
| 99 explicit ControllerConnectionProxy( | |
| 100 blink::WebPresentationConnection* connection); | |
| 101 ~ControllerConnectionProxy() override; | |
| 102 | |
| 103 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.
| |
| 104 virtual blink::mojom::PresentationConnectionRequest MakeRemoteRequest(); | |
| 105 }; | |
| 106 | |
| 107 // Represents PresentationConnectionProxy object on receiver frame. | |
| 108 class CONTENT_EXPORT ReceiverConnectionProxy | |
| 109 : public PresentationConnectionProxy { | |
| 110 public: | |
| 111 explicit ReceiverConnectionProxy( | |
| 112 blink::WebPresentationConnection* connection); | |
| 113 ~ReceiverConnectionProxy() override; | |
| 114 | |
| 115 virtual void Bind( | |
| 116 blink::mojom::PresentationConnectionRequest target_connection_request); | |
| 117 virtual void BindTargetConnection( | |
| 118 blink::mojom::PresentationConnectionPtr connection); | |
| 119 }; | |
| 120 | |
| 121 } // namespace content | |
| 122 | |
| 123 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_CONNECTION_PROXY_H_ | |
| OLD | NEW |