diff options
author | mikhail.pozdnyakov <mikhail.pozdnyakov@intel.com> | 2015-12-09 04:09:40 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-09 12:10:32 +0000 |
commit | 79486f1c04861a577489fa63b1f82342aaee095b (patch) | |
tree | 824933762da51d3ad91d77ec8639d6c96b299bf5 /extensions/renderer/api | |
parent | aae35e589d9df6d5111cf658e69a82faa1ebed3e (diff) | |
download | chromium_src-79486f1c04861a577489fa63b1f82342aaee095b.zip chromium_src-79486f1c04861a577489fa63b1f82342aaee095b.tar.gz chromium_src-79486f1c04861a577489fa63b1f82342aaee095b.tar.bz2 |
chrome.displaySource custom bindings
This patch introduces custom bindings for 'chrome.displaySource' API.
These are bindings for 'startSession', 'terminateSession' methods
and for the 'onSessionStarted', 'onSessionTerminated',
'onSessionErrorOccured' events.
The bindings should belong to render process (i.e. be custom) as:
1) they accept dom objects arguments (MediaStreamTrack)
2) for security reasons: to keep all protocols handling within sandbox
The abstract 'DisplaySourceSession' class is added to be implemented
by the 'chrome.displaySource' API backends.
BUG=242107
Review URL: https://codereview.chromium.org/1471243002
Cr-Commit-Position: refs/heads/master@{#364045}
Diffstat (limited to 'extensions/renderer/api')
3 files changed, 133 insertions, 0 deletions
diff --git a/extensions/renderer/api/display_source/OWNERS b/extensions/renderer/api/display_source/OWNERS new file mode 100644 index 0000000..f7e4f6f --- /dev/null +++ b/extensions/renderer/api/display_source/OWNERS @@ -0,0 +1,2 @@ +alexander.shalamov@intel.com +mikhail.pozdnyakov@intel.com diff --git a/extensions/renderer/api/display_source/display_source_session.cc b/extensions/renderer/api/display_source/display_source_session.cc new file mode 100644 index 0000000..8e66b6f --- /dev/null +++ b/extensions/renderer/api/display_source/display_source_session.cc @@ -0,0 +1,37 @@ +// 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/display_source_session.h" + +namespace extensions { + +DisplaySourceSession::DisplaySourceSession() + : state_(Idle) { +} + +DisplaySourceSession::~DisplaySourceSession() { +} + +void DisplaySourceSession::SetCallbacks( + const SinkIdCallback& started_callback, + const SinkIdCallback& terminated_callback, + const ErrorCallback& error_callback) { + DCHECK(started_callback_.is_null()); + DCHECK(terminated_callback_.is_null()); + DCHECK(error_callback_.is_null()); + + started_callback_ = started_callback; + terminated_callback_ = terminated_callback; + error_callback_ = error_callback; +} + +scoped_ptr<DisplaySourceSession> DisplaySourceSessionFactory::CreateSession( + int sink_id, + const blink::WebMediaStreamTrack& video_track, + const blink::WebMediaStreamTrack& audio_track, + scoped_ptr<DisplaySourceAuthInfo> auth_info) { + return nullptr; +} + +} // namespace extensions diff --git a/extensions/renderer/api/display_source/display_source_session.h b/extensions/renderer/api/display_source/display_source_session.h new file mode 100644 index 0000000..b10dce9 --- /dev/null +++ b/extensions/renderer/api/display_source/display_source_session.h @@ -0,0 +1,94 @@ +// 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_DISPLAY_SOURCE_SESSION_H_ +#define EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_SESSION_H_ + +#include "base/callback.h" +#include "base/macros.h" +#include "extensions/common/api/display_source.h" +#include "third_party/WebKit/public/web/WebDOMMediaStreamTrack.h" + +namespace extensions { + +using DisplaySourceAuthInfo = api::display_source::AuthenticationInfo; +using DisplaySourceErrorType = api::display_source::ErrorType; + +// This class represents a generic display source session interface. +class DisplaySourceSession { + public: + using SinkIdCallback = base::Callback<void(int sink_id)>; + using ErrorCallback = + base::Callback<void(int sink_id, + DisplaySourceErrorType error_type, + const std::string& error_description)>; + + // State flow is ether: + // 'Idle' -> 'Establishing' -> 'Established' -> 'Terminating' -> 'Idle' + // (terminated by Terminate() call) + // or + // 'Idle' -> 'Establishing' -> 'Established' -> 'Idle' + // (terminated from sink device or due to an error) + enum State { + Idle, + Establishing, + Established, + Terminating + }; + + virtual ~DisplaySourceSession(); + + // Starts the session. + // The session state should be set to 'Establishing' immediately after this + // method is called. + virtual void Start() = 0; + + // Terminates the session. + // The session state should be set to 'Terminating' immediately after this + // method is called. + virtual void Terminate() = 0; + + State state() const { return state_; } + + // Sets the callbacks invoked to inform about the session's state changes. + // It is required to set the callbacks before the session is started. + // |started_callback| : Called when the session was actually started (state + // should be set to 'Established') + // |terminated_callback| : Called when the session was actually started (state + // should be set to 'Idle') + // |error_callback| : Called if a fatal error has occured and the session + // either cannot be started (if was invoked in + // 'Establishing' state) or will be terminated soon for + // emergency reasons (if was invoked in 'Established' + // state). + void SetCallbacks(const SinkIdCallback& started_callback, + const SinkIdCallback& terminated_callback, + const ErrorCallback& error_callback); + + protected: + DisplaySourceSession(); + + State state_; + SinkIdCallback started_callback_; + SinkIdCallback terminated_callback_; + ErrorCallback error_callback_; + + private: + DISALLOW_COPY_AND_ASSIGN(DisplaySourceSession); +}; + +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); + private: + DISALLOW_COPY_AND_ASSIGN(DisplaySourceSessionFactory); +}; + +} // namespace extensions + +#endif // EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_SESSION_H_ |