Chromium Code Reviews| 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 "chrome/browser/media/media_capture_devices_dispatcher.h" | |
| 10 #include "content/public/browser/browser_thread.h" | |
| 11 | |
| 12 using content::BrowserThread; | |
| 13 | |
| 14 CaptureAccessHandlerBase::CaptureAccessHandlerBase() {} | |
| 15 | |
| 16 CaptureAccessHandlerBase::~CaptureAccessHandlerBase() {} | |
| 17 | |
| 18 void CaptureAccessHandlerBase::AddCaptureSession(int render_process_id, | |
| 19 int render_frame_id, | |
| 20 int page_request_id, | |
| 21 bool is_extension_trusted) { | |
| 22 Session session = {render_process_id, render_frame_id, page_request_id, | |
| 23 is_extension_trusted, false}; | |
|
miu
2016/05/02 21:02:45
I'm concerned about defaulting this to "false" (wh
xjz
2016/05/04 18:23:48
Done. Changed the default to true.
| |
| 24 sessions_.push_back(session); | |
| 25 } | |
| 26 | |
| 27 void CaptureAccessHandlerBase::RemoveCaptureSession(int render_process_id, | |
| 28 int render_frame_id, | |
| 29 int page_request_id) { | |
| 30 std::list<CaptureAccessHandlerBase::Session>::iterator it = | |
| 31 FindSession(render_process_id, render_frame_id, page_request_id); | |
| 32 if (it != sessions_.end()) | |
| 33 sessions_.erase(it); | |
| 34 } | |
| 35 | |
| 36 std::list<CaptureAccessHandlerBase::Session>::iterator | |
| 37 CaptureAccessHandlerBase::FindSession(int render_process_id, | |
| 38 int render_frame_id, | |
| 39 int page_request_id) { | |
| 40 for (auto it = sessions_.begin(); it != sessions_.end(); ++it) { | |
| 41 if (it->render_process_id == render_process_id && | |
| 42 it->render_frame_id == render_frame_id && | |
| 43 it->page_request_id == page_request_id) { | |
| 44 return it; | |
| 45 } | |
| 46 } | |
| 47 return sessions_.end(); | |
| 48 } | |
| 49 | |
| 50 void CaptureAccessHandlerBase::UpdateMediaRequestState( | |
| 51 int render_process_id, | |
| 52 int render_frame_id, | |
| 53 int page_request_id, | |
| 54 content::MediaStreamType stream_type, | |
| 55 content::MediaRequestState state) { | |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 57 if ((stream_type != content::MEDIA_DESKTOP_VIDEO_CAPTURE) && | |
| 58 (stream_type != content::MEDIA_TAB_VIDEO_CAPTURE)) | |
| 59 return; | |
| 60 | |
| 61 if (state == content::MEDIA_REQUEST_STATE_DONE) { | |
| 62 if (FindSession(render_process_id, render_frame_id, page_request_id) == | |
| 63 sessions_.end()) { | |
| 64 AddCaptureSession(render_process_id, render_frame_id, page_request_id, | |
| 65 false); | |
| 66 VLOG(2) << "Add new session while UpdateMediaRequestState" | |
| 67 << " render_process_id: " << render_process_id | |
| 68 << " render_frame_id: " << render_frame_id | |
| 69 << " page_request_id: " << page_request_id; | |
| 70 } | |
| 71 } else if (state == content::MEDIA_REQUEST_STATE_CLOSING) { | |
| 72 RemoveCaptureSession(render_process_id, render_frame_id, page_request_id); | |
| 73 VLOG(2) << "Remove session: " | |
| 74 << " render_process_id: " << render_process_id | |
| 75 << " render_frame_id: " << render_frame_id | |
| 76 << " page_request_id: " << page_request_id; | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 void CaptureAccessHandlerBase::UpdateExtensionTrusted( | |
| 81 const content::MediaStreamRequest& request, | |
| 82 const extensions::Extension* extension) { | |
| 83 bool is_extension_trusted = | |
| 84 MediaCaptureDevicesDispatcher::IsOriginForCasting( | |
| 85 request.security_origin) || | |
| 86 IsExtensionWhitelistedForScreenCapture(extension) || | |
| 87 IsBuiltInExtension(request.security_origin); | |
| 88 | |
| 89 std::list<CaptureAccessHandlerBase::Session>::iterator it = | |
| 90 FindSession(request.render_process_id, request.render_frame_id, | |
| 91 request.page_request_id); | |
| 92 if (it != sessions_.end()) { | |
| 93 it->is_extension_trusted = is_extension_trusted; | |
| 94 VLOG(2) << "CaptureAccessHandlerBase::UpdateExtensionTrusted" | |
| 95 << " render_process_id: " << request.render_process_id | |
| 96 << " render_frame_id: " << request.render_frame_id | |
| 97 << "page_request_id: " << request.page_request_id | |
| 98 << " is_extension_trusted: " << is_extension_trusted; | |
| 99 return; | |
| 100 } | |
| 101 | |
| 102 AddCaptureSession(request.render_process_id, request.render_frame_id, | |
| 103 request.page_request_id, is_extension_trusted); | |
| 104 VLOG(2) << "Add new session while UpdateExtensionTrusted" | |
| 105 << " render_process_id: " << request.render_process_id | |
| 106 << " render_frame_id: " << request.render_frame_id | |
| 107 << " page_request_id: " << request.page_request_id | |
| 108 << " is_extension_trusted: " << is_extension_trusted; | |
| 109 } | |
| 110 | |
| 111 bool CaptureAccessHandlerBase::IsCaptureInProgress() { | |
| 112 return sessions_.size() > 0; | |
| 113 } | |
| 114 | |
| 115 bool CaptureAccessHandlerBase::IsInsecureCapturingInProgress( | |
| 116 int render_process_id, | |
| 117 int render_frame_id) { | |
| 118 if (sessions_.empty()) | |
| 119 return false; | |
| 120 for (const Session& session : sessions_) { | |
| 121 if (session.render_process_id != render_process_id || | |
| 122 session.render_frame_id != render_frame_id) | |
| 123 continue; | |
| 124 if (!session.is_extension_trusted || !session.is_capturing_link_secure) | |
| 125 return true; | |
| 126 } | |
| 127 return false; | |
| 128 } | |
| 129 | |
| 130 void CaptureAccessHandlerBase::UpdateCapturingLinkSecured(int render_process_id, | |
| 131 int render_frame_id, | |
| 132 int page_request_id, | |
| 133 bool is_secure) { | |
| 134 std::list<CaptureAccessHandlerBase::Session>::iterator it = | |
| 135 FindSession(render_process_id, render_frame_id, page_request_id); | |
| 136 if (it != sessions_.end()) { | |
| 137 it->is_capturing_link_secure = is_secure; | |
| 138 VLOG(2) << "UpdateCapturingLinkSecured:" | |
| 139 << " render_process_id: " << render_process_id | |
| 140 << " render_frame_id: " << render_frame_id | |
| 141 << " page_request_id: " << page_request_id | |
| 142 << " is_capturing_link_secure: " << is_secure; | |
| 143 } | |
| 144 } | |
| 145 | |
| 146 bool CaptureAccessHandlerBase::IsExtensionWhitelistedForScreenCapture( | |
| 147 const extensions::Extension* extension) { | |
| 148 if (!extension) | |
| 149 return false; | |
| 150 | |
| 151 #if defined(OS_CHROMEOS) | |
| 152 std::string hash = base::SHA1HashString(extension->id()); | |
| 153 std::string hex_hash = base::HexEncode(hash.c_str(), hash.length()); | |
| 154 | |
| 155 // crbug.com/446688 | |
| 156 return hex_hash == "4F25792AF1AA7483936DE29C07806F203C7170A0" || | |
| 157 hex_hash == "BD8781D757D830FC2E85470A1B6E8A718B7EE0D9" || | |
| 158 hex_hash == "4AC2B6C63C6480D150DFDA13E4A5956EB1D0DDBB" || | |
| 159 hex_hash == "81986D4F846CEDDDB962643FA501D1780DD441BB"; | |
| 160 #else | |
| 161 return false; | |
| 162 #endif // defined(OS_CHROMEOS) | |
| 163 } | |
| 164 | |
| 165 bool CaptureAccessHandlerBase::IsBuiltInExtension(const GURL& origin) { | |
| 166 return | |
| 167 // Feedback Extension. | |
| 168 origin.spec() == "chrome-extension://gfdkimpbcpahaombhbimeihdjnejgicl/"; | |
| 169 } | |
| OLD | NEW |