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)>; | |
mlamouri (slow - plz ping)
2017/01/26 22:18:02
Can you move this inside the class? Otherwise, you
zhaobin
2017/01/26 22:48:14
Done.
| |
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::MakeRemoteRequest() { | |
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(target_connection_request); | |
45 // 7. Set receiver proxy's |target_connection_| to | |
46 // |controller_connection_proxy|'s interface pointer: | |
47 // ReceiverConnectionProxy::BindTargetConnection( | |
48 // blink::mojom::PresentationConnectionPtr connection) { | |
49 // target_connection_ = std::move(connection); | |
50 // ... | |
51 // } | |
52 // | |
53 // When both |source_connection_| and |target_connection_| are set, | |
54 // we can send message or notify state changes between controller and receiver. | |
55 // | |
56 // To send message from controlling frame to receiver frame: | |
57 // 1. Controlling frame invokes connection.sendMessage(); | |
58 // 2. This call is delegated to controller presentation connection proxy's | |
59 // SendConnectionMessage(). | |
60 // ControllerConnectionProxy::SendConnectionMessage() { | |
61 // target_connection_->OnMessage(); | |
62 // } | |
63 // 3. ReceiverConnectionProxy::OnMessage() is invoked. | |
64 // 4. connection.onmessage event on receiver frame is fired. | |
65 // | |
66 // Sending message from receiver frame to controlling frame and notifying state | |
67 // changes works the same. | |
68 // | |
69 // Instance of this class is created for both offscreen and non offscreen | |
70 // presentations. | |
mlamouri (slow - plz ping)
2017/01/26 22:18:02
That documentation looks great! :)
| |
71 class CONTENT_EXPORT PresentationConnectionProxy | |
72 : public NON_EXPORTED_BASE(blink::WebPresentationConnectionProxy), | |
73 public NON_EXPORTED_BASE(blink::mojom::PresentationConnection) { | |
74 public: | |
75 ~PresentationConnectionProxy() override; | |
76 | |
77 virtual void SendConnectionMessage( | |
78 blink::mojom::ConnectionMessagePtr connection_message, | |
79 const OnMessageCallback& callback) const; | |
80 | |
81 // blink::mojom::PresentationConnection implementation | |
82 void OnMessage(blink::mojom::ConnectionMessagePtr message, | |
83 const OnMessageCallback& callback) override; | |
84 void DidChangeState(blink::mojom::PresentationConnectionState state) override; | |
85 | |
86 protected: | |
87 explicit PresentationConnectionProxy( | |
88 blink::WebPresentationConnection* source_connection); | |
89 mojo::Binding<blink::mojom::PresentationConnection> binding_; | |
90 mojo::InterfacePtr<blink::mojom::PresentationConnection> | |
91 target_connection_ptr_; | |
92 | |
93 private: | |
94 // Raw pointer to Blink connection object owning this proxy object. Does not | |
95 // take ownership. | |
96 blink::WebPresentationConnection* const source_connection_; | |
97 }; | |
98 | |
99 // Represents PresentationConnectionProxy object on controlling frame. | |
100 class CONTENT_EXPORT ControllerConnectionProxy | |
101 : public PresentationConnectionProxy { | |
102 public: | |
103 explicit ControllerConnectionProxy( | |
104 blink::WebPresentationConnection* controller_connection); | |
105 ~ControllerConnectionProxy() override; | |
106 | |
107 blink::mojom::PresentationConnectionPtr Bind(); | |
108 blink::mojom::PresentationConnectionRequest MakeRemoteRequest(); | |
109 }; | |
110 | |
111 // Represents PresentationConnectionProxy object on receiver frame. | |
112 class CONTENT_EXPORT ReceiverConnectionProxy | |
113 : public PresentationConnectionProxy { | |
114 public: | |
115 explicit ReceiverConnectionProxy( | |
116 blink::WebPresentationConnection* receiver_connection); | |
117 ~ReceiverConnectionProxy() override; | |
118 | |
119 void Bind( | |
120 blink::mojom::PresentationConnectionRequest receiver_connection_request); | |
121 | |
122 // Sets |target_connection_ptr_| to |controller_connection_ptr|. Should be | |
123 // called only once. | |
124 void BindControllerConnection( | |
125 blink::mojom::PresentationConnectionPtr controller_connection_ptr); | |
126 }; | |
127 | |
128 } // namespace content | |
129 | |
130 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_CONNECTION_PROXY_H_ | |
OLD | NEW |