Clean up extension confirmation prompts and make them consistent between Views and...
[chromium-blink-merge.git] / remoting / host / host_extension_session_manager.cc
blobb6ce83e79c5ddc598d411db922748f4a018dc6bf
1 // Copyright 2014 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.
5 #include "remoting/host/host_extension_session_manager.h"
7 #include "remoting/base/capabilities.h"
8 #include "remoting/codec/video_encoder.h"
9 #include "remoting/host/client_session_control.h"
10 #include "remoting/host/host_extension.h"
11 #include "remoting/host/host_extension_session.h"
12 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
13 namespace remoting {
15 HostExtensionSessionManager::HostExtensionSessionManager(
16 const std::vector<HostExtension*>& extensions,
17 ClientSessionControl* client_session_control)
18 : client_session_control_(client_session_control),
19 client_stub_(nullptr),
20 extensions_(extensions) {
23 HostExtensionSessionManager::~HostExtensionSessionManager() {
26 std::string HostExtensionSessionManager::GetCapabilities() const {
27 std::string capabilities;
28 for (HostExtensions::const_iterator extension = extensions_.begin();
29 extension != extensions_.end(); ++extension) {
30 const std::string& capability = (*extension)->capability();
31 if (capability.empty()) {
32 continue;
34 if (!capabilities.empty()) {
35 capabilities.append(" ");
37 capabilities.append(capability);
39 return capabilities;
42 void HostExtensionSessionManager::OnCreateVideoCapturer(
43 scoped_ptr<webrtc::DesktopCapturer>* capturer) {
44 for (HostExtensionSessions::const_iterator it = extension_sessions_.begin();
45 it != extension_sessions_.end(); ++it) {
46 if ((*it)->ModifiesVideoPipeline()) {
47 (*it)->OnCreateVideoCapturer(capturer);
52 void HostExtensionSessionManager::OnCreateVideoEncoder(
53 scoped_ptr<VideoEncoder>* encoder) {
54 for (HostExtensionSessions::const_iterator it = extension_sessions_.begin();
55 it != extension_sessions_.end(); ++it) {
56 if ((*it)->ModifiesVideoPipeline()) {
57 (*it)->OnCreateVideoEncoder(encoder);
62 void HostExtensionSessionManager::OnNegotiatedCapabilities(
63 protocol::ClientStub* client_stub,
64 const std::string& capabilities) {
65 DCHECK(client_stub);
66 DCHECK(!client_stub_);
68 client_stub_ = client_stub;
70 bool reset_video_pipeline = false;
72 for (HostExtensions::const_iterator extension = extensions_.begin();
73 extension != extensions_.end(); ++extension) {
74 // If the extension requires a capability that was not negotiated then do
75 // not instantiate it.
76 if (!(*extension)->capability().empty() &&
77 !HasCapability(capabilities, (*extension)->capability())) {
78 continue;
81 scoped_ptr<HostExtensionSession> extension_session =
82 (*extension)->CreateExtensionSession(
83 client_session_control_, client_stub_);
84 DCHECK(extension_session);
86 if (extension_session->ModifiesVideoPipeline()) {
87 reset_video_pipeline = true;
90 extension_sessions_.push_back(extension_session.release());
93 // Re-create the video pipeline if one or more extensions need to modify it.
94 if (reset_video_pipeline) {
95 client_session_control_->ResetVideoPipeline();
99 bool HostExtensionSessionManager::OnExtensionMessage(
100 const protocol::ExtensionMessage& message) {
101 for(HostExtensionSessions::const_iterator it = extension_sessions_.begin();
102 it != extension_sessions_.end(); ++it) {
103 if ((*it)->OnExtensionMessage(
104 client_session_control_, client_stub_, message)) {
105 return true;
108 return false;
111 } // namespace remoting