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/media/permission_bubble_media_access_handler.cc

Issue 1362803002: Add logic to resolve permission mismatches in Android M for webrtc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add blankline Created 5 years, 2 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
OLDNEW
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
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 std::vector<ContentSettingsType> content_settings_types;
138 if (controller->IsAllowedForAudio())
139 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
140
141 if (controller->IsAllowedForVideo()) {
142 content_settings_types.push_back(
143 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
144 }
145 if (!content_settings_types.empty() &&
146 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar(
147 web_contents, content_settings_types)) {
148 PermissionUpdateInfoBarDelegate::Create(
149 web_contents, content_settings_types,
150 base::Bind(
151 &OnPermissionConflictResolved, base::Passed(&controller)));
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. (https://crbug/337458)
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698