OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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. |
| 4 |
| 5 #include "chrome/browser/media/capture_access_handler_base.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "extensions/common/extension.h" |
| 13 |
| 14 #if defined(OS_CHROMEOS) |
| 15 #include "base/sha1.h" |
| 16 #endif // defined(OS_CHROMEOS) |
| 17 |
| 18 using content::BrowserThread; |
| 19 |
| 20 // Tracks MEDIA_DESKTOP/TAB_VIDEO_CAPTURE sessions. Sessions are removed when |
| 21 // MEDIA_REQUEST_STATE_CLOSING is encountered. |
| 22 struct CaptureAccessHandlerBase::Session { |
| 23 int render_process_id; |
| 24 int render_frame_id; |
| 25 int page_request_id; |
| 26 // Extensions control the routing of the captured MediaStream content. |
| 27 // Therefore, only built-in extensions (and certain whitelisted ones) can be |
| 28 // trusted to set-up secure links. |
| 29 bool is_extension_trusted; |
| 30 |
| 31 // This is true only if all connected video sinks are reported secure. |
| 32 bool is_capturing_link_secure; |
| 33 }; |
| 34 |
| 35 CaptureAccessHandlerBase::CaptureAccessHandlerBase() {} |
| 36 |
| 37 CaptureAccessHandlerBase::~CaptureAccessHandlerBase() {} |
| 38 |
| 39 void CaptureAccessHandlerBase::AddCaptureSession(int render_process_id, |
| 40 int render_frame_id, |
| 41 int page_request_id, |
| 42 bool is_extension_trusted) { |
| 43 Session session = {render_process_id, render_frame_id, page_request_id, |
| 44 is_extension_trusted, true}; |
| 45 sessions_.push_back(session); |
| 46 } |
| 47 |
| 48 void CaptureAccessHandlerBase::RemoveCaptureSession(int render_process_id, |
| 49 int render_frame_id, |
| 50 int page_request_id) { |
| 51 auto it = FindSession(render_process_id, render_frame_id, page_request_id); |
| 52 if (it != sessions_.end()) |
| 53 sessions_.erase(it); |
| 54 } |
| 55 |
| 56 std::list<CaptureAccessHandlerBase::Session>::iterator |
| 57 CaptureAccessHandlerBase::FindSession(int render_process_id, |
| 58 int render_frame_id, |
| 59 int page_request_id) { |
| 60 return std::find_if(sessions_.begin(), sessions_.end(), |
| 61 [render_process_id, render_frame_id, |
| 62 page_request_id](const Session& session) { |
| 63 return session.render_process_id == render_process_id && |
| 64 session.render_frame_id == render_frame_id && |
| 65 session.page_request_id == page_request_id; |
| 66 }); |
| 67 } |
| 68 |
| 69 void CaptureAccessHandlerBase::UpdateMediaRequestState( |
| 70 int render_process_id, |
| 71 int render_frame_id, |
| 72 int page_request_id, |
| 73 content::MediaStreamType stream_type, |
| 74 content::MediaRequestState state) { |
| 75 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 76 if ((stream_type != content::MEDIA_DESKTOP_VIDEO_CAPTURE) && |
| 77 (stream_type != content::MEDIA_TAB_VIDEO_CAPTURE)) |
| 78 return; |
| 79 |
| 80 if (state == content::MEDIA_REQUEST_STATE_DONE) { |
| 81 if (FindSession(render_process_id, render_frame_id, page_request_id) == |
| 82 sessions_.end()) { |
| 83 AddCaptureSession(render_process_id, render_frame_id, page_request_id, |
| 84 false); |
| 85 DVLOG(2) << "Add new session while UpdateMediaRequestState" |
| 86 << " render_process_id: " << render_process_id |
| 87 << " render_frame_id: " << render_frame_id |
| 88 << " page_request_id: " << page_request_id; |
| 89 } |
| 90 } else if (state == content::MEDIA_REQUEST_STATE_CLOSING) { |
| 91 RemoveCaptureSession(render_process_id, render_frame_id, page_request_id); |
| 92 DVLOG(2) << "Remove session: " |
| 93 << " render_process_id: " << render_process_id |
| 94 << " render_frame_id: " << render_frame_id |
| 95 << " page_request_id: " << page_request_id; |
| 96 } |
| 97 } |
| 98 |
| 99 void CaptureAccessHandlerBase::UpdateExtensionTrusted( |
| 100 const content::MediaStreamRequest& request, |
| 101 const extensions::Extension* extension) { |
| 102 bool is_extension_trusted = |
| 103 MediaCaptureDevicesDispatcher::IsOriginForCasting( |
| 104 request.security_origin) || |
| 105 IsExtensionWhitelistedForScreenCapture(extension) || |
| 106 IsBuiltInExtension(request.security_origin); |
| 107 |
| 108 std::list<CaptureAccessHandlerBase::Session>::iterator it = |
| 109 FindSession(request.render_process_id, request.render_frame_id, |
| 110 request.page_request_id); |
| 111 if (it != sessions_.end()) { |
| 112 it->is_extension_trusted = is_extension_trusted; |
| 113 DVLOG(2) << "CaptureAccessHandlerBase::UpdateExtensionTrusted" |
| 114 << " render_process_id: " << request.render_process_id |
| 115 << " render_frame_id: " << request.render_frame_id |
| 116 << "page_request_id: " << request.page_request_id |
| 117 << " is_extension_trusted: " << is_extension_trusted; |
| 118 return; |
| 119 } |
| 120 |
| 121 AddCaptureSession(request.render_process_id, request.render_frame_id, |
| 122 request.page_request_id, is_extension_trusted); |
| 123 DVLOG(2) << "Add new session while UpdateExtensionTrusted" |
| 124 << " render_process_id: " << request.render_process_id |
| 125 << " render_frame_id: " << request.render_frame_id |
| 126 << " page_request_id: " << request.page_request_id |
| 127 << " is_extension_trusted: " << is_extension_trusted; |
| 128 } |
| 129 |
| 130 bool CaptureAccessHandlerBase::IsInsecureCapturingInProgress( |
| 131 int render_process_id, |
| 132 int render_frame_id) { |
| 133 if (sessions_.empty()) |
| 134 return false; |
| 135 for (const Session& session : sessions_) { |
| 136 if (session.render_process_id != render_process_id || |
| 137 session.render_frame_id != render_frame_id) |
| 138 continue; |
| 139 if (!session.is_extension_trusted || !session.is_capturing_link_secure) |
| 140 return true; |
| 141 } |
| 142 return false; |
| 143 } |
| 144 |
| 145 void CaptureAccessHandlerBase::UpdateCapturingLinkSecured(int render_process_id, |
| 146 int render_frame_id, |
| 147 int page_request_id, |
| 148 bool is_secure) { |
| 149 std::list<CaptureAccessHandlerBase::Session>::iterator it = |
| 150 FindSession(render_process_id, render_frame_id, page_request_id); |
| 151 if (it != sessions_.end()) { |
| 152 it->is_capturing_link_secure = is_secure; |
| 153 DVLOG(2) << "UpdateCapturingLinkSecured:" |
| 154 << " render_process_id: " << render_process_id |
| 155 << " render_frame_id: " << render_frame_id |
| 156 << " page_request_id: " << page_request_id |
| 157 << " is_capturing_link_secure: " << is_secure; |
| 158 } |
| 159 } |
| 160 |
| 161 bool CaptureAccessHandlerBase::IsExtensionWhitelistedForScreenCapture( |
| 162 const extensions::Extension* extension) { |
| 163 if (!extension) |
| 164 return false; |
| 165 |
| 166 #if defined(OS_CHROMEOS) |
| 167 std::string hash = base::SHA1HashString(extension->id()); |
| 168 std::string hex_hash = base::HexEncode(hash.c_str(), hash.length()); |
| 169 |
| 170 // crbug.com/446688 |
| 171 return hex_hash == "4F25792AF1AA7483936DE29C07806F203C7170A0" || |
| 172 hex_hash == "BD8781D757D830FC2E85470A1B6E8A718B7EE0D9" || |
| 173 hex_hash == "4AC2B6C63C6480D150DFDA13E4A5956EB1D0DDBB" || |
| 174 hex_hash == "81986D4F846CEDDDB962643FA501D1780DD441BB"; |
| 175 #else |
| 176 return false; |
| 177 #endif // defined(OS_CHROMEOS) |
| 178 } |
| 179 |
| 180 bool CaptureAccessHandlerBase::IsBuiltInExtension(const GURL& origin) { |
| 181 return |
| 182 // Feedback Extension. |
| 183 origin.spec() == "chrome-extension://gfdkimpbcpahaombhbimeihdjnejgicl/"; |
| 184 } |
OLD | NEW |