Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/ui/media_stream_infobar_delegate.cc

Issue 10537099: add "always allow" option to the mediastream infobar and allow user to allow/not allow acces to devi (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments from joaodasilva and bauerb, added support to Incognito mode. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/ui/media_stream_infobar_delegate.h"
6 #include <functional>
7 6
8 #include "base/logging.h" 7 #include "base/logging.h"
9 #include "chrome/browser/ui/media_stream_infobar_delegate.h"
10 #include "content/public/common/media_stream_request.h"
11 #include "googleurl/src/gurl.h" 8 #include "googleurl/src/gurl.h"
no longer working on chromium 2012/06/20 17:24:38 To joaodasilva: Done with cleaning up the #includ
12 #include "grit/theme_resources_standard.h" 9 #include "grit/theme_resources_standard.h"
13 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
14 11
15 namespace {
16
17 // A predicate that checks if a StreamDeviceInfo object has the same ID as the
18 // device ID specified at construction.
19 class DeviceIdEquals {
20 public:
21 explicit DeviceIdEquals(const std::string& device_id)
22 : device_id_(device_id) {
23 }
24
25 bool operator() (const content::MediaStreamDevice& device) {
26 return device.device_id == device_id_;
27 }
28
29 private:
30 std::string device_id_;
31 };
32
33 } // namespace
34
35 MediaStreamInfoBarDelegate::MediaStreamInfoBarDelegate( 12 MediaStreamInfoBarDelegate::MediaStreamInfoBarDelegate(
36 InfoBarTabHelper* tab_helper, 13 InfoBarTabHelper* tab_helper,
37 const content::MediaStreamRequest* request, 14 MediaStreamDevicesController* controller)
38 const content::MediaResponseCallback& callback)
39 : InfoBarDelegate(tab_helper), 15 : InfoBarDelegate(tab_helper),
40 request_(request), 16 controller_(controller) {
41 callback_(callback) { 17 DCHECK(controller_.get());
42 DCHECK(request_);
43 has_audio_ = request_->devices.count(
44 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) != 0;
45 has_video_ = request_->devices.count(
46 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE) != 0;
47 } 18 }
48 19
49 MediaStreamInfoBarDelegate::~MediaStreamInfoBarDelegate() { 20 MediaStreamInfoBarDelegate::~MediaStreamInfoBarDelegate() {}
21
22 bool MediaStreamInfoBarDelegate::HasAudio() const {
23 return controller_->has_audio();
24 }
25
26 bool MediaStreamInfoBarDelegate::HasVideo() const {
27 return controller_->has_video();
50 } 28 }
51 29
52 content::MediaStreamDevices 30 content::MediaStreamDevices
53 MediaStreamInfoBarDelegate::GetAudioDevices() const { 31 MediaStreamInfoBarDelegate::GetAudioDevices() const {
54 if (!has_audio_) 32 return controller_->GetAudioDevices();
55 return content::MediaStreamDevices();
56 content::MediaStreamDeviceMap::const_iterator it =
57 request_->devices.find(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE);
58 DCHECK(it != request_->devices.end());
59 return it->second;
60 } 33 }
61 34
62 content::MediaStreamDevices 35 content::MediaStreamDevices
63 MediaStreamInfoBarDelegate::GetVideoDevices() const { 36 MediaStreamInfoBarDelegate::GetVideoDevices() const {
64 if (!has_video_) 37 return controller_->GetVideoDevices();
65 return content::MediaStreamDevices();
66 content::MediaStreamDeviceMap::const_iterator it =
67 request_->devices.find(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE);
68 DCHECK(it != request_->devices.end());
69 return it->second;
70 } 38 }
71 39
72 const GURL& MediaStreamInfoBarDelegate::GetSecurityOrigin() const { 40 const GURL& MediaStreamInfoBarDelegate::GetSecurityOrigin() const {
73 return request_->security_origin; 41 return controller_->GetSecurityOrigin();
74 } 42 }
75 43
76 void MediaStreamInfoBarDelegate::Accept(const std::string& audio_id, 44 void MediaStreamInfoBarDelegate::Accept(const std::string& audio_id,
77 const std::string& video_id) { 45 const std::string& video_id,
78 content::MediaStreamDevices devices; 46 bool always_allow) {
79 47 controller_->Accept(audio_id, video_id, always_allow);
80 if (has_audio_) {
81 AddDeviceWithId(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
82 audio_id, &devices);
83 }
84 if (has_video_) {
85 AddDeviceWithId(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE,
86 video_id, &devices);
87 }
88
89 callback_.Run(devices);
90 } 48 }
91 49
92 void MediaStreamInfoBarDelegate::Deny() { 50 void MediaStreamInfoBarDelegate::Deny() {
93 callback_.Run(content::MediaStreamDevices()); 51 controller_->Deny();
94 }
95
96 void MediaStreamInfoBarDelegate::AddDeviceWithId(
97 content::MediaStreamDeviceType type,
98 const std::string& id,
99 content::MediaStreamDevices* devices) {
100 DCHECK(devices);
101 content::MediaStreamDeviceMap::const_iterator device_it =
102 request_->devices.find(type);
103 if (device_it != request_->devices.end()) {
104 content::MediaStreamDevices::const_iterator it = std::find_if(
105 device_it->second.begin(), device_it->second.end(), DeviceIdEquals(id));
106 if (it != device_it->second.end())
107 devices->push_back(*it);
108 }
109 } 52 }
110 53
111 // MediaStreamInfoBarDelegate::CreateInfoBar is implemented in platform-specific 54 // MediaStreamInfoBarDelegate::CreateInfoBar is implemented in platform-specific
112 // files. 55 // files.
113 56
114 void MediaStreamInfoBarDelegate::InfoBarDismissed() { 57 void MediaStreamInfoBarDelegate::InfoBarDismissed() {
115 // Deny the request if the infobar was closed with the 'x' button, since 58 // 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. 59 // we don't want WebRTC to be waiting for an answer that will never come.
117 Deny(); 60 Deny();
118 } 61 }
119 62
120 gfx::Image* MediaStreamInfoBarDelegate::GetIcon() const { 63 gfx::Image* MediaStreamInfoBarDelegate::GetIcon() const {
121 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(has_video_ ? 64 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(HasVideo() ?
122 IDR_INFOBAR_MEDIA_STREAM_CAMERA : IDR_INFOBAR_MEDIA_STREAM_MIC); 65 IDR_INFOBAR_MEDIA_STREAM_CAMERA : IDR_INFOBAR_MEDIA_STREAM_MIC);
123 } 66 }
124 67
125 InfoBarDelegate::Type MediaStreamInfoBarDelegate::GetInfoBarType() const { 68 InfoBarDelegate::Type MediaStreamInfoBarDelegate::GetInfoBarType() const {
126 return PAGE_ACTION_TYPE; 69 return PAGE_ACTION_TYPE;
127 } 70 }
128 71
129 MediaStreamInfoBarDelegate* 72 MediaStreamInfoBarDelegate*
130 MediaStreamInfoBarDelegate::AsMediaStreamInfoBarDelegate() { 73 MediaStreamInfoBarDelegate::AsMediaStreamInfoBarDelegate() {
131 return this; 74 return this;
132 } 75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698