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

Side by Side Diff: chrome/browser/permissions/permission_dialog_delegate.cc

Issue 2462963002: Implement modal permission prompts for media permissions on Android. (Closed)
Patch Set: Nits Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/permissions/permission_dialog_delegate.h" 5 #include "chrome/browser/permissions/permission_dialog_delegate.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "base/feature_list.h" 11 #include "base/feature_list.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/android/resource_mapper.h" 13 #include "chrome/browser/android/resource_mapper.h"
14 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" 14 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h"
15 #include "chrome/browser/media/midi_permission_infobar_delegate_android.h" 15 #include "chrome/browser/media/midi_permission_infobar_delegate_android.h"
16 #include "chrome/browser/media/protected_media_identifier_infobar_delegate_andro id.h" 16 #include "chrome/browser/media/protected_media_identifier_infobar_delegate_andro id.h"
17 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h"
18 #include "chrome/browser/media/webrtc/media_stream_infobar_delegate_android.h"
17 #include "chrome/browser/notifications/notification_permission_infobar_delegate. h" 19 #include "chrome/browser/notifications/notification_permission_infobar_delegate. h"
20 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/chrome_features.h" 21 #include "chrome/common/chrome_features.h"
19 #include "components/variations/variations_associated_data.h" 22 #include "components/variations/variations_associated_data.h"
20 #include "content/public/browser/android/content_view_core.h" 23 #include "content/public/browser/android/content_view_core.h"
21 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
22 #include "jni/PermissionDialogController_jni.h" 25 #include "jni/PermissionDialogController_jni.h"
23 #include "jni/PermissionDialogDelegate_jni.h" 26 #include "jni/PermissionDialogDelegate_jni.h"
24 #include "ui/android/window_android.h" 27 #include "ui/android/window_android.h"
25 #include "ui/base/window_open_disposition.h" 28 #include "ui/base/window_open_disposition.h"
26 29
27 using base::android::ConvertUTF16ToJavaString; 30 using base::android::ConvertUTF16ToJavaString;
(...skipping 16 matching lines...) Expand all
44 DCHECK(web_contents); 47 DCHECK(web_contents);
45 48
46 // Dispatch the dialog to Java, which manages the lifetime of this object. 49 // Dispatch the dialog to Java, which manages the lifetime of this object.
47 new PermissionDialogDelegate( 50 new PermissionDialogDelegate(
48 web_contents, 51 web_contents,
49 PermissionInfoBarDelegate::CreateDelegate( 52 PermissionInfoBarDelegate::CreateDelegate(
50 type, requesting_frame, user_gesture, profile, callback)); 53 type, requesting_frame, user_gesture, profile, callback));
51 } 54 }
52 55
53 // static 56 // static
57 void PermissionDialogDelegate::CreateMediaStreamDialog(
58 content::WebContents* web_contents,
59 std::unique_ptr<MediaStreamDevicesController> controller) {
60 // Called this way because the infobar delegate has a private destructor.
61 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate;
62 infobar_delegate.reset(new MediaStreamInfoBarDelegateAndroid(
63 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
64 std::move(controller)));
65
66 // Dispatch the dialog to Java, which manages the lifetime of this object.
67 new PermissionDialogDelegate(web_contents, std::move(infobar_delegate));
68 }
69
70 // static
54 bool PermissionDialogDelegate::ShouldShowDialog(bool has_user_gesture) { 71 bool PermissionDialogDelegate::ShouldShowDialog(bool has_user_gesture) {
55 if (!base::FeatureList::IsEnabled(features::kModalPermissionPrompts)) 72 if (!base::FeatureList::IsEnabled(features::kModalPermissionPrompts))
56 return false; 73 return false;
57 74
58 // Only use modals when the prompt is triggered by a user gesture, unless the 75 // Only use modals when the prompt is triggered by a user gesture, unless the
59 // kModalParamsUserGestureKey is set to false. 76 // kModalParamsUserGestureKey is set to false.
60 std::string require_gesture = variations::GetVariationParamValueByFeature( 77 std::string require_gesture = variations::GetVariationParamValueByFeature(
61 features::kModalPermissionPrompts, kModalParamsUserGestureKey); 78 features::kModalPermissionPrompts, kModalParamsUserGestureKey);
62 if (require_gesture == "false") 79 if (require_gesture == "false")
63 return true; 80 return true;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 base::android::ScopedJavaLocalRef<jobject> j_delegate = 157 base::android::ScopedJavaLocalRef<jobject> j_delegate =
141 CreateJavaDelegate(env); 158 CreateJavaDelegate(env);
142 159
143 // Send the Java delegate to the Java PermissionDialogController for display. 160 // Send the Java delegate to the Java PermissionDialogController for display.
144 // The controller takes over lifetime management; when the Java delegate is no 161 // The controller takes over lifetime management; when the Java delegate is no
145 // longer needed it will in turn free the native delegate. 162 // longer needed it will in turn free the native delegate.
146 Java_PermissionDialogController_createDialog(env, j_delegate.obj()); 163 Java_PermissionDialogController_createDialog(env, j_delegate.obj());
147 } 164 }
148 165
149 PermissionDialogDelegate::~PermissionDialogDelegate() {} 166 PermissionDialogDelegate::~PermissionDialogDelegate() {}
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_dialog_delegate.h ('k') | content/test/data/android/media_permissions.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698