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 "content/public/browser/browser_thread.h" | |
| 10 | |
| 11 using content::BrowserThread; | |
| 12 | |
| 13 CaptureAccessHandlerBase::CaptureAccessHandlerBase() {} | |
| 14 | |
| 15 CaptureAccessHandlerBase::~CaptureAccessHandlerBase() {} | |
| 16 | |
| 17 void CaptureAccessHandlerBase::AddCaptureSession(int render_process_id, | |
| 18 int render_frame_id, | |
| 19 int page_request_id, | |
| 20 bool is_extension_trusted, | |
| 21 bool is_link_secure) { | |
|
miu
2016/04/26 01:25:13
I'm thinking, when a capture session is first star
xjz
2016/04/29 00:11:42
Yes, you are correct. Actually I did always set it
| |
| 22 Session session = {render_process_id, render_frame_id, page_request_id, | |
| 23 is_extension_trusted, is_link_secure}; | |
| 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, false); | |
| 66 VLOG(1) << "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(1) << "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 int render_process_id, | |
| 82 int render_frame_id, | |
| 83 int page_request_id, | |
| 84 bool is_extension_trusted) { | |
| 85 std::list<CaptureAccessHandlerBase::Session>::iterator it = | |
| 86 FindSession(render_process_id, render_frame_id, page_request_id); | |
| 87 if (it != sessions_.end()) { | |
| 88 it->is_extension_trusted = is_extension_trusted; | |
| 89 VLOG(1) << "CaptureAccessHandlerBase::UpdateExtensionTrusted" | |
| 90 << " render_process_id: " << render_process_id | |
| 91 << " render_frame_id: " << render_frame_id | |
| 92 << "page_request_id: " << page_request_id | |
| 93 << " is_extension_trusted: " << is_extension_trusted; | |
| 94 return; | |
| 95 } | |
| 96 | |
| 97 AddCaptureSession(render_process_id, render_frame_id, page_request_id, | |
| 98 is_extension_trusted, false); | |
| 99 VLOG(1) << "Add new session while UpdateExtensionTrusted" | |
| 100 << " render_process_id: " << render_process_id | |
| 101 << " render_frame_id: " << render_frame_id | |
| 102 << " page_request_id: " << page_request_id | |
| 103 << " is_extension_trusted: " << is_extension_trusted; | |
| 104 } | |
| 105 | |
| 106 bool CaptureAccessHandlerBase::IsCaptureInProgress() { | |
| 107 return sessions_.size() > 0; | |
| 108 } | |
| 109 | |
| 110 bool CaptureAccessHandlerBase::IsInsecureCapturingInProgress( | |
| 111 int render_process_id, | |
| 112 int render_frame_id) { | |
| 113 if (sessions_.size() <= 0) | |
|
miu
2016/04/26 01:25:13
nit: size_t can never be less than zero. How abou
xjz
2016/04/29 00:11:42
Done.
| |
| 114 return false; | |
| 115 bool capturing_in_process = false; | |
| 116 bool is_link_secure = false; | |
| 117 for (auto it = sessions_.begin(); it != sessions_.end(); ++it) { | |
|
miu
2016/04/26 01:25:13
This seems a bit more complex than it needs to be.
xjz
2016/04/29 00:11:42
Done. This is much simpler and more readable. Than
| |
| 118 if (it->render_process_id == render_process_id && | |
| 119 it->render_frame_id == render_frame_id) { | |
| 120 bool is_secure = it->is_capturing_link_secure && it->is_extension_trusted; | |
| 121 is_link_secure = | |
| 122 capturing_in_process ? is_link_secure && is_secure : is_secure; | |
| 123 capturing_in_process = true; | |
| 124 } | |
| 125 } | |
| 126 return capturing_in_process && !is_link_secure; | |
| 127 } | |
| 128 | |
| 129 void CaptureAccessHandlerBase::UpdateCapturingLinkSecured(int render_process_id, | |
| 130 int render_frame_id, | |
| 131 int page_request_id, | |
| 132 bool is_secure) { | |
| 133 std::list<CaptureAccessHandlerBase::Session>::iterator it = | |
| 134 FindSession(render_process_id, render_frame_id, page_request_id); | |
| 135 if (it != sessions_.end()) { | |
|
miu
2016/04/26 01:25:13
Will/should this ever be false? I suppose we don'
xjz
2016/04/29 00:11:41
I think this will be false only when a session has
| |
| 136 it->is_capturing_link_secure = is_secure; | |
| 137 VLOG(1) << "UpdateCapturingLinkSecured:" | |
| 138 << " render_process_id: " << render_process_id | |
| 139 << " render_frame_id: " << render_frame_id | |
| 140 << " page_request_id: " << page_request_id | |
| 141 << " is_capturing_link_secure: " << is_secure; | |
| 142 } | |
| 143 } | |
| OLD | NEW |