summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/api
diff options
context:
space:
mode:
authormikhail.pozdnyakov <mikhail.pozdnyakov@intel.com>2016-01-14 07:24:05 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-14 15:26:35 +0000
commit61a28e373720d8f205d9fc37c09580804a36b038 (patch)
treeb2272bdbd457a7b8aab8491764d2cebeb6e95f46 /extensions/renderer/api
parentc2103fb08d07c310047e7c4923e9caaa0ef76e35 (diff)
downloadchromium_src-61a28e373720d8f205d9fc37c09580804a36b038.zip
chromium_src-61a28e373720d8f205d9fc37c09580804a36b038.tar.gz
chromium_src-61a28e373720d8f205d9fc37c09580804a36b038.tar.bz2
Add WiFi Display session class skeleton and mojo service
This patch introduces a WiFi Display session class skeleton and mojo service which provides network access for the render-hosted session. The introduced code is compiled only if a newly added 'enable_wifi_display' build option is set. Besides, some minor changes were applied to the DisplaySourceConnectionDelegate interface in order to better define its methods behavior. BUG=242107 Review URL: https://codereview.chromium.org/1540563002 Cr-Commit-Position: refs/heads/master@{#369415}
Diffstat (limited to 'extensions/renderer/api')
-rw-r--r--extensions/renderer/api/display_source/display_source_session.cc23
-rw-r--r--extensions/renderer/api/display_source/display_source_session.h22
-rw-r--r--extensions/renderer/api/display_source/wifi_display/wifi_display_session.cc118
-rw-r--r--extensions/renderer/api/display_source/wifi_display/wifi_display_session.h52
4 files changed, 204 insertions, 11 deletions
diff --git a/extensions/renderer/api/display_source/display_source_session.cc b/extensions/renderer/api/display_source/display_source_session.cc
index 8e66b6f..df83007 100644
--- a/extensions/renderer/api/display_source/display_source_session.cc
+++ b/extensions/renderer/api/display_source/display_source_session.cc
@@ -4,15 +4,24 @@
#include "extensions/renderer/api/display_source/display_source_session.h"
+#if defined(ENABLE_WIFI_DISPLAY)
+#include "extensions/renderer/api/display_source/wifi_display/wifi_display_session.h"
+#endif
+
namespace extensions {
-DisplaySourceSession::DisplaySourceSession()
- : state_(Idle) {
+DisplaySourceSessionParams::DisplaySourceSessionParams()
+ : auth_method(api::display_source::AUTHENTICATION_METHOD_NONE) {
}
-DisplaySourceSession::~DisplaySourceSession() {
+DisplaySourceSessionParams::~DisplaySourceSessionParams() = default;
+
+DisplaySourceSession::DisplaySourceSession()
+ : state_(Idle) {
}
+DisplaySourceSession::~DisplaySourceSession() = default;
+
void DisplaySourceSession::SetCallbacks(
const SinkIdCallback& started_callback,
const SinkIdCallback& terminated_callback,
@@ -27,10 +36,10 @@ void DisplaySourceSession::SetCallbacks(
}
scoped_ptr<DisplaySourceSession> DisplaySourceSessionFactory::CreateSession(
- int sink_id,
- const blink::WebMediaStreamTrack& video_track,
- const blink::WebMediaStreamTrack& audio_track,
- scoped_ptr<DisplaySourceAuthInfo> auth_info) {
+ const DisplaySourceSessionParams& params) {
+#if defined(ENABLE_WIFI_DISPLAY)
+ return scoped_ptr<DisplaySourceSession>(new WiFiDisplaySession(params));
+#endif
return nullptr;
}
diff --git a/extensions/renderer/api/display_source/display_source_session.h b/extensions/renderer/api/display_source/display_source_session.h
index b10dce9..2c4053c 100644
--- a/extensions/renderer/api/display_source/display_source_session.h
+++ b/extensions/renderer/api/display_source/display_source_session.h
@@ -10,9 +10,14 @@
#include "extensions/common/api/display_source.h"
#include "third_party/WebKit/public/web/WebDOMMediaStreamTrack.h"
+namespace content {
+class RenderFrame;
+}
+
namespace extensions {
using DisplaySourceAuthInfo = api::display_source::AuthenticationInfo;
+using DisplaySourceAuthMethod = api::display_source::AuthenticationMethod;
using DisplaySourceErrorType = api::display_source::ErrorType;
// This class represents a generic display source session interface.
@@ -78,13 +83,22 @@ class DisplaySourceSession {
DISALLOW_COPY_AND_ASSIGN(DisplaySourceSession);
};
+struct DisplaySourceSessionParams {
+ DisplaySourceSessionParams();
+ ~DisplaySourceSessionParams();
+
+ int sink_id;
+ blink::WebMediaStreamTrack video_track;
+ blink::WebMediaStreamTrack audio_track;
+ DisplaySourceAuthMethod auth_method;
+ std::string auth_data;
+ content::RenderFrame* render_frame;
+};
+
class DisplaySourceSessionFactory {
public:
static scoped_ptr<DisplaySourceSession> CreateSession(
- int sink_id,
- const blink::WebMediaStreamTrack& video_track,
- const blink::WebMediaStreamTrack& audio_track,
- scoped_ptr<DisplaySourceAuthInfo> auth_info);
+ const DisplaySourceSessionParams& params);
private:
DISALLOW_COPY_AND_ASSIGN(DisplaySourceSessionFactory);
};
diff --git a/extensions/renderer/api/display_source/wifi_display/wifi_display_session.cc b/extensions/renderer/api/display_source/wifi_display/wifi_display_session.cc
new file mode 100644
index 0000000..ceb6ad9
--- /dev/null
+++ b/extensions/renderer/api/display_source/wifi_display/wifi_display_session.cc
@@ -0,0 +1,118 @@
+// Copyright 2015 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.
+
+#include "extensions/renderer/api/display_source/wifi_display/wifi_display_session.h"
+
+#include "base/logging.h"
+#include "base/timer/timer.h"
+#include "content/public/common/service_registry.h"
+#include "content/public/renderer/render_frame.h"
+
+namespace {
+const char kErrorInternal[] = "An internal error has occurred";
+} // namespace
+
+namespace extensions {
+
+using api::display_source::ErrorType;
+
+WiFiDisplaySession::WiFiDisplaySession(
+ const DisplaySourceSessionParams& params)
+ : binding_(this),
+ params_(params),
+ weak_factory_(this) {
+ DCHECK(params_.render_frame);
+ params.render_frame->GetServiceRegistry()->ConnectToRemoteService(
+ mojo::GetProxy(&service_));
+ service_.set_connection_error_handler(base::Bind(
+ &WiFiDisplaySession::OnConnectionError,
+ weak_factory_.GetWeakPtr()));
+
+ WiFiDisplaySessionServiceClientPtr client_ptr;
+ binding_.Bind(GetProxy(&client_ptr));
+ binding_.set_connection_error_handler(base::Bind(
+ &WiFiDisplaySession::OnConnectionError,
+ weak_factory_.GetWeakPtr()));
+ DCHECK(client_ptr);
+ service_->SetClient(std::move(client_ptr));
+}
+
+WiFiDisplaySession::~WiFiDisplaySession() {
+}
+
+void WiFiDisplaySession::Start() {
+ DCHECK(state_ == DisplaySourceSession::Idle);
+ service_->Connect(params_.sink_id, params_.auth_method, params_.auth_data);
+ state_ = DisplaySourceSession::Establishing;
+}
+
+void WiFiDisplaySession::Terminate() {
+ DCHECK(state_ != DisplaySourceSession::Idle);
+ switch (state_) {
+ case DisplaySourceSession::Idle:
+ case DisplaySourceSession::Terminating:
+ // Nothing to do.
+ return;
+ case DisplaySourceSession::Establishing:
+ case DisplaySourceSession::Established:
+ service_->Disconnect();
+ state_ = DisplaySourceSession::Terminating;
+ break;
+ default:
+ NOTREACHED();
+ }
+}
+
+void WiFiDisplaySession::OnConnected(
+ int32_t sink_id, const mojo::String& ip_address) {
+ if (sink_id == params_.sink_id) {
+ DCHECK(state_ != DisplaySourceSession::Established);
+ ip_address_ = ip_address;
+ state_ = DisplaySourceSession::Established;
+ }
+
+ if (!started_callback_.is_null())
+ started_callback_.Run(sink_id);
+}
+
+void WiFiDisplaySession::OnDisconnected(int32_t sink_id) {
+ if (sink_id == params_.sink_id) {
+ DCHECK(state_ == DisplaySourceSession::Established ||
+ state_ == DisplaySourceSession::Terminating);
+ state_ = DisplaySourceSession::Idle;
+ }
+
+ if (!terminated_callback_.is_null())
+ terminated_callback_.Run(sink_id);
+}
+
+void WiFiDisplaySession::OnError(
+ int32_t sink_id, int32_t type, const mojo::String& description) {
+ DCHECK(type > api::display_source::ERROR_TYPE_NONE
+ && type <= api::display_source::ERROR_TYPE_LAST);
+ if (!error_callback_.is_null())
+ error_callback_.Run(sink_id, static_cast<ErrorType>(type), description);
+}
+
+void WiFiDisplaySession::OnMessage(const mojo::String& data) {
+ DCHECK(state_ == DisplaySourceSession::Established);
+}
+
+void WiFiDisplaySession::OnConnectionError() {
+ if (!error_callback_.is_null()) {
+ error_callback_.Run(params_.sink_id,
+ api::display_source::ERROR_TYPE_UNKNOWN_ERROR,
+ kErrorInternal);
+ }
+
+ if (state_ == DisplaySourceSession::Established ||
+ state_ == DisplaySourceSession::Terminating) {
+ // We must explicitly notify the session termination as it will never
+ // arrive from browser process (IPC is broken).
+ if (!terminated_callback_.is_null())
+ terminated_callback_.Run(params_.sink_id);
+ }
+}
+
+} // namespace extensions
diff --git a/extensions/renderer/api/display_source/wifi_display/wifi_display_session.h b/extensions/renderer/api/display_source/wifi_display/wifi_display_session.h
new file mode 100644
index 0000000..b807993
--- /dev/null
+++ b/extensions/renderer/api/display_source/wifi_display/wifi_display_session.h
@@ -0,0 +1,52 @@
+// Copyright 2015 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 EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_WIFI_DISPLAY_WIFI_DISPLAY_SESSION_H_
+#define EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_WIFI_DISPLAY_WIFI_DISPLAY_SESSION_H_
+
+#include <string>
+
+#include "extensions/common/mojo/wifi_display_session_service.mojom.h"
+#include "extensions/renderer/api/display_source/display_source_session.h"
+#include "mojo/public/cpp/bindings/binding.h"
+
+namespace extensions {
+
+class WiFiDisplaySession: public DisplaySourceSession,
+ public WiFiDisplaySessionServiceClient {
+ public:
+ explicit WiFiDisplaySession(
+ const DisplaySourceSessionParams& params);
+ ~WiFiDisplaySession() override;
+
+ private:
+ // DisplaySourceSession overrides.
+ void Start() override;
+ void Terminate() override;
+
+ // WiFiDisplaySessionServiceClient overrides.
+ void OnConnected(int32_t sink_id,
+ const mojo::String& ip_address) override;
+ void OnDisconnected(int32_t sink_id) override;
+ void OnError(int32_t sink_id,
+ int32_t type,
+ const mojo::String& description) override;
+ void OnMessage(const mojo::String& data) override;
+
+ // A connection error handler for the mojo objects used in this class.
+ void OnConnectionError();
+
+ private:
+ WiFiDisplaySessionServicePtr service_;
+ mojo::Binding<WiFiDisplaySessionServiceClient> binding_;
+ std::string ip_address_;
+ DisplaySourceSessionParams params_;
+ base::WeakPtrFactory<WiFiDisplaySession> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(WiFiDisplaySession);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_WIFI_DISPLAY_WIFI_DISPLAY_SESSION_H_