OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/media/permission_bubble_media_access_handler.h" | 5 #include "chrome/browser/media/permission_bubble_media_access_handler.h" |
6 | 6 |
7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
8 #include "chrome/browser/media/media_permission.h" | 8 #include "chrome/browser/media/media_permission.h" |
9 #include "chrome/browser/media/media_stream_device_permissions.h" | 9 #include "chrome/browser/media/media_stream_device_permissions.h" |
10 #include "chrome/browser/media/media_stream_infobar_delegate.h" | 10 #include "chrome/browser/media/media_stream_infobar_delegate.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 12 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 #include "components/content_settings/core/browser/host_content_settings_map.h" | 14 #include "components/content_settings/core/browser/host_content_settings_map.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
17 #include "content/public/browser/notification_types.h" | 17 #include "content/public/browser/notification_types.h" |
18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
19 | 19 |
20 #if defined(OS_ANDROID) | |
21 #include <vector> | |
22 | |
23 #include "base/bind.h" | |
24 #include "base/bind_helpers.h" | |
25 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h" | |
26 | |
27 namespace { | |
28 // Callback for the permission update infobar when the site and Chrome | |
29 // permissions are mismatched on Android. | |
30 void OnPermissionConflictResolved( | |
31 scoped_ptr<MediaStreamDevicesController> controller, bool allowed) { | |
32 if (allowed) | |
33 controller->PermissionGranted(); | |
34 else | |
35 controller->ForcePermissionDeniedTemporarily(); | |
36 } | |
37 } // namespace | |
38 | |
39 #endif // OS_ANDROID | |
40 | |
20 using content::BrowserThread; | 41 using content::BrowserThread; |
21 | 42 |
22 struct PermissionBubbleMediaAccessHandler::PendingAccessRequest { | 43 struct PermissionBubbleMediaAccessHandler::PendingAccessRequest { |
23 PendingAccessRequest(const content::MediaStreamRequest& request, | 44 PendingAccessRequest(const content::MediaStreamRequest& request, |
24 const content::MediaResponseCallback& callback) | 45 const content::MediaResponseCallback& callback) |
25 : request(request), callback(callback) {} | 46 : request(request), callback(callback) {} |
26 ~PendingAccessRequest() {} | 47 ~PendingAccessRequest() {} |
27 | 48 |
28 // TODO(gbillock): make the MediaStreamDevicesController owned by | 49 // TODO(gbillock): make the MediaStreamDevicesController owned by |
29 // this object when we're using bubbles. | 50 // this object when we're using bubbles. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 std::map<content::WebContents*, RequestsQueue>::iterator it = | 116 std::map<content::WebContents*, RequestsQueue>::iterator it = |
96 pending_requests_.find(web_contents); | 117 pending_requests_.find(web_contents); |
97 | 118 |
98 if (it == pending_requests_.end() || it->second.empty()) { | 119 if (it == pending_requests_.end() || it->second.empty()) { |
99 // Don't do anything if the tab was closed. | 120 // Don't do anything if the tab was closed. |
100 return; | 121 return; |
101 } | 122 } |
102 | 123 |
103 DCHECK(!it->second.empty()); | 124 DCHECK(!it->second.empty()); |
104 | 125 |
126 scoped_ptr<MediaStreamDevicesController> controller( | |
127 new MediaStreamDevicesController( | |
128 web_contents, it->second.front().request, | |
129 base::Bind( | |
130 &PermissionBubbleMediaAccessHandler::OnAccessRequestResponse, | |
131 base::Unretained(this), web_contents))); | |
132 if (!controller->IsAskingForAudio() && !controller->IsAskingForVideo()) { | |
133 #if defined(OS_ANDROID) | |
134 // If either audio or video was previously allowed and Chrome no longer has | |
135 // the necessary permissions, show a infobar to attempt to address this | |
136 // mismatch. | |
137 if (controller->IsAllowedForAudio() || controller->IsAllowedForVideo()) { | |
mlamouri (slow - plz ping)
2015/09/24 10:57:02
Maybe you could remove that and simply check if th
Ted C
2015/09/24 22:07:27
Done.
| |
138 std::vector<ContentSettingsType> content_settings_types; | |
139 if (controller->IsAllowedForAudio()) | |
140 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | |
141 if (controller->IsAllowedForVideo()) | |
mlamouri (slow - plz ping)
2015/09/24 10:57:02
style: as above
Ted C
2015/09/24 22:07:27
Done.
| |
142 content_settings_types.push_back( | |
143 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
144 | |
145 if (PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar( | |
146 web_contents, content_settings_types)) { | |
147 PermissionUpdateInfoBarDelegate::Create( | |
148 web_contents, content_settings_types, | |
149 base::Bind( | |
150 &OnPermissionConflictResolved, base::Passed(&controller))); | |
151 } | |
152 } | |
153 #endif | |
154 return; | |
155 } | |
156 | |
105 if (PermissionBubbleManager::Enabled()) { | 157 if (PermissionBubbleManager::Enabled()) { |
106 scoped_ptr<MediaStreamDevicesController> controller( | |
107 new MediaStreamDevicesController( | |
108 web_contents, it->second.front().request, | |
109 base::Bind( | |
110 &PermissionBubbleMediaAccessHandler::OnAccessRequestResponse, | |
111 base::Unretained(this), web_contents))); | |
112 if (!controller->IsAskingForAudio() && !controller->IsAskingForVideo()) | |
113 return; | |
114 PermissionBubbleManager* bubble_manager = | 158 PermissionBubbleManager* bubble_manager = |
115 PermissionBubbleManager::FromWebContents(web_contents); | 159 PermissionBubbleManager::FromWebContents(web_contents); |
116 if (bubble_manager) | 160 if (bubble_manager) |
117 bubble_manager->AddRequest(controller.release()); | 161 bubble_manager->AddRequest(controller.release()); |
118 return; | 162 } else { |
163 // TODO(gbillock): delete this block and the MediaStreamInfoBarDelegate | |
164 // when we've transitioned to bubbles. (crbug/337458) | |
mlamouri (slow - plz ping)
2015/09/24 10:57:02
nit: as long as you move that, could you add https
Ted C
2015/09/24 22:07:27
Done.
| |
165 MediaStreamInfoBarDelegate::Create(web_contents, controller.Pass()); | |
119 } | 166 } |
120 | |
121 // TODO(gbillock): delete this block and the MediaStreamInfoBarDelegate | |
122 // when we've transitioned to bubbles. (crbug/337458) | |
123 MediaStreamInfoBarDelegate::Create( | |
124 web_contents, it->second.front().request, | |
125 base::Bind(&PermissionBubbleMediaAccessHandler::OnAccessRequestResponse, | |
126 base::Unretained(this), web_contents)); | |
127 } | 167 } |
128 | 168 |
129 void PermissionBubbleMediaAccessHandler::UpdateMediaRequestState( | 169 void PermissionBubbleMediaAccessHandler::UpdateMediaRequestState( |
130 int render_process_id, | 170 int render_process_id, |
131 int render_frame_id, | 171 int render_frame_id, |
132 int page_request_id, | 172 int page_request_id, |
133 content::MediaStreamType stream_type, | 173 content::MediaStreamType stream_type, |
134 content::MediaRequestState state) { | 174 content::MediaRequestState state) { |
135 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 175 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
136 if (state != content::MEDIA_REQUEST_STATE_CLOSING) | 176 if (state != content::MEDIA_REQUEST_STATE_CLOSING) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 int type, | 233 int type, |
194 const content::NotificationSource& source, | 234 const content::NotificationSource& source, |
195 const content::NotificationDetails& details) { | 235 const content::NotificationDetails& details) { |
196 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 236 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
197 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 237 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
198 content::WebContents* web_contents = | 238 content::WebContents* web_contents = |
199 content::Source<content::WebContents>(source).ptr(); | 239 content::Source<content::WebContents>(source).ptr(); |
200 pending_requests_.erase(web_contents); | 240 pending_requests_.erase(web_contents); |
201 } | 241 } |
202 } | 242 } |
OLD | NEW |