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

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

Issue 2379703002: [Presentation API] (alternative) 1-UA: send message between controller and receiver page (Closed)
Patch Set: merge with master 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..e98f6b588379d4c2318e4edea4920309cbc71ecb
--- /dev/null
+++ b/content/renderer/presentation/presentation_connection_proxy.h
@@ -0,0 +1,70 @@
+// 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/WebPresentationConnection.h"
+#include "third_party/WebKit/public/platform/modules/presentation/WebPresentationConnectionProxy.h"
+#include "third_party/WebKit/public/platform/modules/presentation/presentation.mojom.h"
+
+namespace content {
+
+// This class connects PresentationConnection owned by one frame with
+// PresentationConnection owned by a different frame.
+//
+// |SetSourceConnection| sets |source_connection_| to PresentationConnection
+// object owned by current 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 SendString(const blink::WebString& message) override;
+ void SendArrayBuffer(const uint8_t* data, size_t length) override;
+
+ // blink::mojom::PresentationConnection implementation
+ void SetTargetConnection(
+ blink::mojom::PresentationConnectionPtr connection) override;
+ void OnMessage(blink::mojom::SessionMessagePtr message) override;
+
+ private:
+ mojo::Binding<blink::mojom::PresentationConnection> binding_;
+ blink::mojom::PresentationConnectionPtr target_connection_;
+ blink::WebPresentationConnection* source_connection_;
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_CONNECTION_PROXY_H_

Powered by Google App Engine
This is Rietveld 408576698