Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Unified Diff: content/renderer/presentation/presentation_connection_proxy.h

Issue 2471263003: [Presentation API] (4th)(1-UA blink side) Add WebPresentationConnection and WebPresentationConnecti… (Closed)
Patch Set: rebase and resolve code review comments from haraken Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..4d8e8cd6521d44e7f5b6a91bd86ae6630da11ef9
--- /dev/null
+++ b/content/renderer/presentation/presentation_connection_proxy.h
@@ -0,0 +1,78 @@
+// 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 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.
+//
+// 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 PresentationConnectionProxy
+ : public blink::WebPresentationConnectionProxy,
+ public NON_EXPORTED_BASE(blink::mojom::PresentationConnection) {
+ public:
+ PresentationConnectionProxy();
+ ~PresentationConnectionProxy() override;
+
+ blink::mojom::PresentationConnectionPtr Bind();
+
+ // WebPresentationConnectionProxy Implementation
+ void SetSourceConnection(
+ blink::WebPresentationConnection* connection) override;
+
+ void SendSessionMessage(
+ blink::mojom::PresentationSessionInfoPtr session,
+ blink::mojom::SessionMessagePtr session_message) const;
+
+ // blink::mojom::PresentationConnection implementation
+ void SetTargetConnection(
+ blink::mojom::PresentationConnectionPtr connection) override;
+ void OnMessage(blink::mojom::SessionMessagePtr message,
+ const OnMessageCallback& callback) override;
+ void DidChangeState(blink::mojom::PresentationConnectionState state) override;
+
+ void RegisterOnMessageCallback(const OnMessageCallback& callback);
mark a. foltz 2016/12/02 22:44:00 Document this method: specifically, that |callback
zhaobin 2016/12/05 20:28:17 Done.
+
+ private:
+ mojo::Binding<blink::mojom::PresentationConnection> binding_;
+ blink::mojom::PresentationConnectionPtr target_connection_;
+ blink::WebPresentationConnection* source_connection_;
+ OnMessageCallback on_message_callback_;
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_CONNECTION_PROXY_H_

Powered by Google App Engine
This is Rietveld 408576698