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