| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <functional> | 6 #include <functional> |
| 7 | 7 |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/browser/ui/media_stream_infobar_delegate.h" | 9 #include "chrome/browser/ui/media_stream_infobar_delegate.h" |
| 10 #include "content/public/common/media_stream_request.h" | 10 #include "content/public/common/media_stream_request.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 std::string device_id_; | 30 std::string device_id_; |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 MediaStreamInfoBarDelegate::MediaStreamInfoBarDelegate( | 35 MediaStreamInfoBarDelegate::MediaStreamInfoBarDelegate( |
| 36 InfoBarTabHelper* tab_helper, | 36 InfoBarTabHelper* tab_helper, |
| 37 const content::MediaStreamRequest* request, | 37 const content::MediaStreamRequest* request, |
| 38 const content::MediaResponseCallback& callback) | 38 const content::MediaResponseCallback& callback) |
| 39 : InfoBarDelegate(tab_helper), | 39 : InfoBarDelegate(tab_helper), |
| 40 request_(request), | 40 request_(*request), |
| 41 callback_(callback) { | 41 callback_(callback) { |
| 42 DCHECK(request_); | 42 has_audio_ = request_.devices.count( |
| 43 has_audio_ = request_->devices.count( | |
| 44 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) != 0; | 43 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) != 0; |
| 45 has_video_ = request_->devices.count( | 44 has_video_ = request_.devices.count( |
| 46 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE) != 0; | 45 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE) != 0; |
| 47 } | 46 } |
| 48 | 47 |
| 49 MediaStreamInfoBarDelegate::~MediaStreamInfoBarDelegate() { | 48 MediaStreamInfoBarDelegate::~MediaStreamInfoBarDelegate() { |
| 50 } | 49 } |
| 51 | 50 |
| 52 content::MediaStreamDevices | 51 content::MediaStreamDevices |
| 53 MediaStreamInfoBarDelegate::GetAudioDevices() const { | 52 MediaStreamInfoBarDelegate::GetAudioDevices() const { |
| 54 if (!has_audio_) | 53 if (!has_audio_) |
| 55 return content::MediaStreamDevices(); | 54 return content::MediaStreamDevices(); |
| 56 content::MediaStreamDeviceMap::const_iterator it = | 55 content::MediaStreamDeviceMap::const_iterator it = |
| 57 request_->devices.find(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE); | 56 request_.devices.find(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE); |
| 58 DCHECK(it != request_->devices.end()); | 57 DCHECK(it != request_.devices.end()); |
| 59 return it->second; | 58 return it->second; |
| 60 } | 59 } |
| 61 | 60 |
| 62 content::MediaStreamDevices | 61 content::MediaStreamDevices |
| 63 MediaStreamInfoBarDelegate::GetVideoDevices() const { | 62 MediaStreamInfoBarDelegate::GetVideoDevices() const { |
| 64 if (!has_video_) | 63 if (!has_video_) |
| 65 return content::MediaStreamDevices(); | 64 return content::MediaStreamDevices(); |
| 66 content::MediaStreamDeviceMap::const_iterator it = | 65 content::MediaStreamDeviceMap::const_iterator it = |
| 67 request_->devices.find(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE); | 66 request_.devices.find(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE); |
| 68 DCHECK(it != request_->devices.end()); | 67 DCHECK(it != request_.devices.end()); |
| 69 return it->second; | 68 return it->second; |
| 70 } | 69 } |
| 71 | 70 |
| 72 const GURL& MediaStreamInfoBarDelegate::GetSecurityOrigin() const { | 71 const GURL& MediaStreamInfoBarDelegate::GetSecurityOrigin() const { |
| 73 return request_->security_origin; | 72 return request_.security_origin; |
| 74 } | 73 } |
| 75 | 74 |
| 76 void MediaStreamInfoBarDelegate::Accept(const std::string& audio_id, | 75 void MediaStreamInfoBarDelegate::Accept(const std::string& audio_id, |
| 77 const std::string& video_id) { | 76 const std::string& video_id) { |
| 78 content::MediaStreamDevices devices; | 77 content::MediaStreamDevices devices; |
| 79 | 78 |
| 80 if (has_audio_) { | 79 if (has_audio_) { |
| 81 AddDeviceWithId(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, | 80 AddDeviceWithId(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, |
| 82 audio_id, &devices); | 81 audio_id, &devices); |
| 83 } | 82 } |
| 84 if (has_video_) { | 83 if (has_video_) { |
| 85 AddDeviceWithId(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, | 84 AddDeviceWithId(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE, |
| 86 video_id, &devices); | 85 video_id, &devices); |
| 87 } | 86 } |
| 88 | 87 |
| 89 callback_.Run(devices); | 88 callback_.Run(devices); |
| 90 } | 89 } |
| 91 | 90 |
| 92 void MediaStreamInfoBarDelegate::Deny() { | 91 void MediaStreamInfoBarDelegate::Deny() { |
| 93 callback_.Run(content::MediaStreamDevices()); | 92 callback_.Run(content::MediaStreamDevices()); |
| 94 } | 93 } |
| 95 | 94 |
| 96 void MediaStreamInfoBarDelegate::AddDeviceWithId( | 95 void MediaStreamInfoBarDelegate::AddDeviceWithId( |
| 97 content::MediaStreamDeviceType type, | 96 content::MediaStreamDeviceType type, |
| 98 const std::string& id, | 97 const std::string& id, |
| 99 content::MediaStreamDevices* devices) { | 98 content::MediaStreamDevices* devices) { |
| 100 DCHECK(devices); | 99 DCHECK(devices); |
| 101 content::MediaStreamDeviceMap::const_iterator device_it = | 100 content::MediaStreamDeviceMap::const_iterator device_it = |
| 102 request_->devices.find(type); | 101 request_.devices.find(type); |
| 103 if (device_it != request_->devices.end()) { | 102 if (device_it != request_.devices.end()) { |
| 104 content::MediaStreamDevices::const_iterator it = std::find_if( | 103 content::MediaStreamDevices::const_iterator it = std::find_if( |
| 105 device_it->second.begin(), device_it->second.end(), DeviceIdEquals(id)); | 104 device_it->second.begin(), device_it->second.end(), DeviceIdEquals(id)); |
| 106 if (it != device_it->second.end()) | 105 if (it != device_it->second.end()) |
| 107 devices->push_back(*it); | 106 devices->push_back(*it); |
| 108 } | 107 } |
| 109 } | 108 } |
| 110 | 109 |
| 111 // MediaStreamInfoBarDelegate::CreateInfoBar is implemented in platform-specific | 110 // MediaStreamInfoBarDelegate::CreateInfoBar is implemented in platform-specific |
| 112 // files. | 111 // files. |
| 113 | 112 |
| 114 void MediaStreamInfoBarDelegate::InfoBarDismissed() { | 113 void MediaStreamInfoBarDelegate::InfoBarDismissed() { |
| 115 // Deny the request if the infobar was closed with the 'x' button, since | 114 // Deny the request if the infobar was closed with the 'x' button, since |
| 116 // we don't want WebRTC to be waiting for an answer that will never come. | 115 // we don't want WebRTC to be waiting for an answer that will never come. |
| 117 Deny(); | 116 Deny(); |
| 118 } | 117 } |
| 119 | 118 |
| 120 gfx::Image* MediaStreamInfoBarDelegate::GetIcon() const { | 119 gfx::Image* MediaStreamInfoBarDelegate::GetIcon() const { |
| 121 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(has_video_ ? | 120 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(has_video_ ? |
| 122 IDR_INFOBAR_MEDIA_STREAM_CAMERA : IDR_INFOBAR_MEDIA_STREAM_MIC); | 121 IDR_INFOBAR_MEDIA_STREAM_CAMERA : IDR_INFOBAR_MEDIA_STREAM_MIC); |
| 123 } | 122 } |
| 124 | 123 |
| 125 InfoBarDelegate::Type MediaStreamInfoBarDelegate::GetInfoBarType() const { | 124 InfoBarDelegate::Type MediaStreamInfoBarDelegate::GetInfoBarType() const { |
| 126 return PAGE_ACTION_TYPE; | 125 return PAGE_ACTION_TYPE; |
| 127 } | 126 } |
| 128 | 127 |
| 129 MediaStreamInfoBarDelegate* | 128 MediaStreamInfoBarDelegate* |
| 130 MediaStreamInfoBarDelegate::AsMediaStreamInfoBarDelegate() { | 129 MediaStreamInfoBarDelegate::AsMediaStreamInfoBarDelegate() { |
| 131 return this; | 130 return this; |
| 132 } | 131 } |
| OLD | NEW |