OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/pepper/pepper_media_device_manager.h" | 5 #include "content/renderer/pepper/pepper_media_device_manager.h" |
6 | 6 |
| 7 #include "base/feature_list.h" |
7 #include "base/location.h" | 8 #include "base/location.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "content/public/common/console_message_level.h" |
| 13 #include "content/public/common/content_features.h" |
11 #include "content/renderer/media/media_devices_event_dispatcher.h" | 14 #include "content/renderer/media/media_devices_event_dispatcher.h" |
12 #include "content/renderer/media/media_stream_dispatcher.h" | 15 #include "content/renderer/media/media_stream_dispatcher.h" |
| 16 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
13 #include "content/renderer/render_frame_impl.h" | 17 #include "content/renderer/render_frame_impl.h" |
14 #include "media/media_features.h" | 18 #include "media/media_features.h" |
15 #include "ppapi/shared_impl/ppb_device_ref_shared.h" | 19 #include "ppapi/shared_impl/ppb_device_ref_shared.h" |
16 #include "services/service_manager/public/cpp/interface_provider.h" | 20 #include "services/service_manager/public/cpp/interface_provider.h" |
17 | 21 |
18 namespace content { | 22 namespace content { |
19 | 23 |
20 namespace { | 24 namespace { |
21 | 25 |
| 26 const char kPepperInsecureOriginMessage[] = |
| 27 "Microphone and Camera access no longer works on insecure origins. To use " |
| 28 "this feature, you should consider switching your application to a " |
| 29 "secure origin, such as HTTPS. See https://goo.gl/rStTGz for more " |
| 30 "details."; |
| 31 |
22 PP_DeviceType_Dev FromMediaDeviceType(MediaDeviceType type) { | 32 PP_DeviceType_Dev FromMediaDeviceType(MediaDeviceType type) { |
23 switch (type) { | 33 switch (type) { |
24 case MEDIA_DEVICE_TYPE_AUDIO_INPUT: | 34 case MEDIA_DEVICE_TYPE_AUDIO_INPUT: |
25 return PP_DEVICETYPE_DEV_AUDIOCAPTURE; | 35 return PP_DEVICETYPE_DEV_AUDIOCAPTURE; |
26 case MEDIA_DEVICE_TYPE_VIDEO_INPUT: | 36 case MEDIA_DEVICE_TYPE_VIDEO_INPUT: |
27 return PP_DEVICETYPE_DEV_VIDEOCAPTURE; | 37 return PP_DEVICETYPE_DEV_VIDEOCAPTURE; |
28 case MEDIA_DEVICE_TYPE_AUDIO_OUTPUT: | 38 case MEDIA_DEVICE_TYPE_AUDIO_OUTPUT: |
29 return PP_DEVICETYPE_DEV_AUDIOOUTPUT; | 39 return PP_DEVICETYPE_DEV_AUDIOOUTPUT; |
30 default: | 40 default: |
31 NOTREACHED(); | 41 NOTREACHED(); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 #if BUILDFLAG(ENABLE_WEBRTC) | 132 #if BUILDFLAG(ENABLE_WEBRTC) |
123 base::WeakPtr<MediaDevicesEventDispatcher> event_dispatcher = | 133 base::WeakPtr<MediaDevicesEventDispatcher> event_dispatcher = |
124 MediaDevicesEventDispatcher::GetForRenderFrame(render_frame()); | 134 MediaDevicesEventDispatcher::GetForRenderFrame(render_frame()); |
125 event_dispatcher->UnsubscribeDeviceChangeNotifications( | 135 event_dispatcher->UnsubscribeDeviceChangeNotifications( |
126 ToMediaDeviceType(type), subscription_id); | 136 ToMediaDeviceType(type), subscription_id); |
127 #endif | 137 #endif |
128 } | 138 } |
129 | 139 |
130 int PepperMediaDeviceManager::OpenDevice(PP_DeviceType_Dev type, | 140 int PepperMediaDeviceManager::OpenDevice(PP_DeviceType_Dev type, |
131 const std::string& device_id, | 141 const std::string& device_id, |
132 const GURL& document_url, | 142 PP_Instance pp_instance, |
133 const OpenDeviceCallback& callback) { | 143 const OpenDeviceCallback& callback) { |
134 open_callbacks_[next_id_] = callback; | 144 open_callbacks_[next_id_] = callback; |
135 int request_id = next_id_++; | 145 int request_id = next_id_++; |
136 | 146 |
| 147 RendererPpapiHostImpl* host = |
| 148 RendererPpapiHostImpl::GetForPPInstance(pp_instance); |
| 149 if (base::FeatureList::IsEnabled( |
| 150 features::kRequireSecureOriginsForPepperMediaRequests) && |
| 151 !host->IsSecureContext(pp_instance)) { |
| 152 RenderFrame* render_frame = host->GetRenderFrameForInstance(pp_instance); |
| 153 if (render_frame) { |
| 154 render_frame->AddMessageToConsole(CONSOLE_MESSAGE_LEVEL_WARNING, |
| 155 kPepperInsecureOriginMessage); |
| 156 } |
| 157 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 158 FROM_HERE, base::Bind(&PepperMediaDeviceManager::OnDeviceOpenFailed, |
| 159 AsWeakPtr(), request_id)); |
| 160 return request_id; |
| 161 } |
| 162 |
137 #if BUILDFLAG(ENABLE_WEBRTC) | 163 #if BUILDFLAG(ENABLE_WEBRTC) |
138 GetMediaStreamDispatcher()->OpenDevice( | 164 GetMediaStreamDispatcher()->OpenDevice( |
139 request_id, AsWeakPtr(), device_id, | 165 request_id, AsWeakPtr(), device_id, |
140 PepperMediaDeviceManager::FromPepperDeviceType(type), | 166 PepperMediaDeviceManager::FromPepperDeviceType(type), |
141 url::Origin(document_url.GetOrigin())); | 167 url::Origin(host->GetDocumentURL(pp_instance).GetOrigin())); |
142 #else | 168 #else |
143 base::ThreadTaskRunnerHandle::Get()->PostTask( | 169 base::ThreadTaskRunnerHandle::Get()->PostTask( |
144 FROM_HERE, base::Bind(&PepperMediaDeviceManager::OnDeviceOpenFailed, | 170 FROM_HERE, base::Bind(&PepperMediaDeviceManager::OnDeviceOpenFailed, |
145 AsWeakPtr(), request_id)); | 171 AsWeakPtr(), request_id)); |
146 #endif | 172 #endif |
147 | 173 |
148 return request_id; | 174 return request_id; |
149 } | 175 } |
150 | 176 |
151 void PepperMediaDeviceManager::CancelOpenDevice(int request_id) { | 177 void PepperMediaDeviceManager::CancelOpenDevice(int request_id) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 } | 299 } |
274 | 300 |
275 return media_devices_dispatcher_; | 301 return media_devices_dispatcher_; |
276 } | 302 } |
277 | 303 |
278 void PepperMediaDeviceManager::OnDestruct() { | 304 void PepperMediaDeviceManager::OnDestruct() { |
279 delete this; | 305 delete this; |
280 } | 306 } |
281 | 307 |
282 } // namespace content | 308 } // namespace content |
OLD | NEW |