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

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: 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 <algorithm>
6 #include <functional> 6 #include <functional>
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/browser/media/media_stream_devices_prefs.h"
9 #include "chrome/browser/ui/media_stream_infobar_delegate.h" 10 #include "chrome/browser/ui/media_stream_infobar_delegate.h"
10 #include "content/public/common/media_stream_request.h" 11 #include "content/public/common/media_stream_request.h"
11 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
12 #include "grit/theme_resources_standard.h" 13 #include "grit/theme_resources_standard.h"
13 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
14 15
15 namespace { 16 namespace {
16 17
17 // A predicate that checks if a StreamDeviceInfo object has the same ID as the 18 // A predicate that checks if a StreamDeviceInfo object has the same ID as the
18 // device ID specified at construction. 19 // device ID specified at construction.
19 class DeviceIdEquals { 20 class DeviceIdEquals {
20 public: 21 public:
21 explicit DeviceIdEquals(const std::string& device_id) 22 explicit DeviceIdEquals(const std::string& device_id)
22 : device_id_(device_id) { 23 : device_id_(device_id) {
23 } 24 }
24 25
25 bool operator() (const content::MediaStreamDevice& device) { 26 bool operator() (const content::MediaStreamDevice& device) {
26 return device.device_id == device_id_; 27 return device.device_id == device_id_;
27 } 28 }
28 29
29 private: 30 private:
30 std::string device_id_; 31 std::string device_id_;
31 }; 32 };
32 33
33 } // namespace 34 } // namespace
34 35
35 MediaStreamInfoBarDelegate::MediaStreamInfoBarDelegate( 36 MediaStreamInfoBarDelegate::MediaStreamInfoBarDelegate(
36 InfoBarTabHelper* tab_helper, 37 InfoBarTabHelper* tab_helper,
38 Profile* profile,
37 const content::MediaStreamRequest* request, 39 const content::MediaStreamRequest* request,
38 const content::MediaResponseCallback& callback) 40 const content::MediaResponseCallback& callback)
39 : InfoBarDelegate(tab_helper), 41 : InfoBarDelegate(tab_helper),
40 request_(request), 42 request_(request),
41 callback_(callback) { 43 callback_(callback),
44 prefs_(profile) {
42 DCHECK(request_); 45 DCHECK(request_);
43 has_audio_ = request_->devices.count( 46 has_audio_ = request_->devices.count(
44 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) != 0; 47 content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE) != 0;
45 has_video_ = request_->devices.count( 48 has_video_ = request_->devices.count(
46 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE) != 0; 49 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE) != 0;
47 } 50 }
48 51
49 MediaStreamInfoBarDelegate::~MediaStreamInfoBarDelegate() { 52 MediaStreamInfoBarDelegate::~MediaStreamInfoBarDelegate() {
50 } 53 }
51 54
(...skipping 14 matching lines...) Expand all
66 content::MediaStreamDeviceMap::const_iterator it = 69 content::MediaStreamDeviceMap::const_iterator it =
67 request_->devices.find(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE); 70 request_->devices.find(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE);
68 DCHECK(it != request_->devices.end()); 71 DCHECK(it != request_->devices.end());
69 return it->second; 72 return it->second;
70 } 73 }
71 74
72 const GURL& MediaStreamInfoBarDelegate::GetSecurityOrigin() const { 75 const GURL& MediaStreamInfoBarDelegate::GetSecurityOrigin() const {
73 return request_->security_origin; 76 return request_->security_origin;
74 } 77 }
75 78
79 bool MediaStreamInfoBarDelegate::ShouldShowInfoBar() {
Evan Stade 2012/06/12 01:51:12 it's unexpected that a function called ShouldShowI
no longer working on chromium 2012/06/14 13:03:25 The name has been changed to DismissInfoBarAndTake
80 DCHECK(has_audio_ || has_video_);
81 if (prefs_.IsMediaDeviceBlocked()){
82 // Users has blocked the access to the media device in content settings,
Bernhard Bauer 2012/06/11 18:16:00 Nit: "The user has blocked […]"
no longer working on chromium 2012/06/14 13:03:25 Done.
83 // deny the request without showing the infobar.
84 Deny();
85 return false;
86 }
87
88 std::string audio_id, video_id;
89 if (GetAlwaysAllowedDevices(&audio_id, &video_id)) {
90 // There are always allowed devices available for this request, grant the
91 // permission immediately without showing the infobar.
92 Accept(audio_id, video_id, false);
93 return false;
94 }
95
96 return true;
97 }
98
76 void MediaStreamInfoBarDelegate::Accept(const std::string& audio_id, 99 void MediaStreamInfoBarDelegate::Accept(const std::string& audio_id,
77 const std::string& video_id) { 100 const std::string& video_id,
101 bool always_allow) {
78 content::MediaStreamDevices devices; 102 content::MediaStreamDevices devices;
103 GetDevicesWithId(audio_id, video_id, &devices);
104 DCHECK(devices.size());
79 105
80 if (has_audio_) { 106 if (always_allow)
81 AddDeviceWithId(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE, 107 prefs_.WhitelistOriginAndDevices(request_->security_origin, devices);
82 audio_id, &devices);
83 }
84 if (has_video_) {
85 AddDeviceWithId(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE,
86 video_id, &devices);
87 }
88 108
89 callback_.Run(devices); 109 callback_.Run(devices);
90 } 110 }
91 111
92 void MediaStreamInfoBarDelegate::Deny() { 112 void MediaStreamInfoBarDelegate::Deny() {
93 callback_.Run(content::MediaStreamDevices()); 113 callback_.Run(content::MediaStreamDevices());
94 } 114 }
95 115
116 void MediaStreamInfoBarDelegate::GetDevicesWithId(
117 const std::string& audio_id,
118 const std::string& video_id,
119 content::MediaStreamDevices* devices) {
120 if (has_audio_) {
121 AddDeviceWithId(content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE,
122 audio_id, devices);
123 }
124 if (has_video_) {
125 AddDeviceWithId(content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE,
126 video_id, devices);
127 }
128 }
129
96 void MediaStreamInfoBarDelegate::AddDeviceWithId( 130 void MediaStreamInfoBarDelegate::AddDeviceWithId(
97 content::MediaStreamDeviceType type, 131 content::MediaStreamDeviceType type,
98 const std::string& id, 132 const std::string& id,
99 content::MediaStreamDevices* devices) { 133 content::MediaStreamDevices* devices) {
100 DCHECK(devices); 134 DCHECK(devices);
101 content::MediaStreamDeviceMap::const_iterator device_it = 135 content::MediaStreamDeviceMap::const_iterator device_it =
102 request_->devices.find(type); 136 request_->devices.find(type);
103 if (device_it != request_->devices.end()) { 137 if (device_it != request_->devices.end()) {
104 content::MediaStreamDevices::const_iterator it = std::find_if( 138 content::MediaStreamDevices::const_iterator it = std::find_if(
105 device_it->second.begin(), device_it->second.end(), DeviceIdEquals(id)); 139 device_it->second.begin(), device_it->second.end(), DeviceIdEquals(id));
106 if (it != device_it->second.end()) 140 if (it != device_it->second.end())
107 devices->push_back(*it); 141 devices->push_back(*it);
108 } 142 }
109 } 143 }
110 144
145 bool MediaStreamInfoBarDelegate::GetAlwaysAllowedDevices(
Evan Stade 2012/06/12 01:51:12 with the addition of these new methods, this class
no longer working on chromium 2012/06/14 13:03:25 Added a MediaStreamDevicesController, moved most o
146 std::string* audio_id, std::string* video_id) {
147 // Check if the |origin| is in content settings exception list.
148 if (!prefs_.IsOriginAlwaysAllowed(request_->security_origin)) {
149 // Remove the |origin| if it exists in the device whitelists.
150 prefs_.RemoveOriginFromWhitelists(request_->security_origin);
151 return false;
152 }
153
154 // Check if the always allowed devices are available.
155 if (has_audio_) {
156 content::MediaStreamDevices devices = GetAudioDevices();
157 *audio_id = prefs_.GetAlwaysAllowedAudioDevice(request_->security_origin,
158 devices);
159 if (audio_id->empty())
160 return false;
161 }
162 if (has_video_) {
163 content::MediaStreamDevices devices = GetVideoDevices();
164 *video_id = prefs_.GetAlwaysAllowedVideoDevice(request_->security_origin,
165 devices);
166 if (video_id->empty())
167 return false;
168 }
169
170 return true;
171 }
172
111 // MediaStreamInfoBarDelegate::CreateInfoBar is implemented in platform-specific 173 // MediaStreamInfoBarDelegate::CreateInfoBar is implemented in platform-specific
112 // files. 174 // files.
113 175
114 void MediaStreamInfoBarDelegate::InfoBarDismissed() { 176 void MediaStreamInfoBarDelegate::InfoBarDismissed() {
115 // Deny the request if the infobar was closed with the 'x' button, since 177 // 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. 178 // we don't want WebRTC to be waiting for an answer that will never come.
117 Deny(); 179 Deny();
118 } 180 }
119 181
120 gfx::Image* MediaStreamInfoBarDelegate::GetIcon() const { 182 gfx::Image* MediaStreamInfoBarDelegate::GetIcon() const {
121 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(has_video_ ? 183 return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(has_video_ ?
122 IDR_INFOBAR_MEDIA_STREAM_CAMERA : IDR_INFOBAR_MEDIA_STREAM_MIC); 184 IDR_INFOBAR_MEDIA_STREAM_CAMERA : IDR_INFOBAR_MEDIA_STREAM_MIC);
123 } 185 }
124 186
125 InfoBarDelegate::Type MediaStreamInfoBarDelegate::GetInfoBarType() const { 187 InfoBarDelegate::Type MediaStreamInfoBarDelegate::GetInfoBarType() const {
126 return PAGE_ACTION_TYPE; 188 return PAGE_ACTION_TYPE;
127 } 189 }
128 190
129 MediaStreamInfoBarDelegate* 191 MediaStreamInfoBarDelegate*
130 MediaStreamInfoBarDelegate::AsMediaStreamInfoBarDelegate() { 192 MediaStreamInfoBarDelegate::AsMediaStreamInfoBarDelegate() {
131 return this; 193 return this;
132 } 194 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698