OLD | NEW |
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 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_DIALOG_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_DIALOG_DELEGATE_H_ |
6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_DIALOG_DELEGATE_H_ | 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_DIALOG_DELEGATE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" | 13 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" |
| 14 #include "chrome/browser/permissions/permission_prompt_android.h" |
14 #include "chrome/browser/permissions/permission_util.h" | 15 #include "chrome/browser/permissions/permission_util.h" |
15 #include "components/content_settings/core/common/content_settings_types.h" | 16 #include "components/content_settings/core/common/content_settings_types.h" |
16 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
17 | 18 |
18 using base::android::JavaParamRef; | 19 using base::android::JavaParamRef; |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 class WebContents; | 22 class WebContents; |
22 } | 23 } |
23 class GURL; | 24 class GURL; |
24 class PermissionInfoBarDelegate; | 25 class PermissionInfoBarDelegate; |
25 class Profile; | 26 class Profile; |
26 class TabAndroid; | 27 class TabAndroid; |
27 | 28 |
28 // Delegate class for displaying a permission prompt as a modal dialog. Used as | 29 // Delegate class for displaying a permission prompt as a modal dialog. Used as |
29 // the native to Java interface to allow Java to communicate the user's | 30 // the native to Java interface to allow Java to communicate the user's |
30 // decision. | 31 // decision. |
31 // | 32 // |
32 // This class currently wraps a PermissionInfoBarDelegate. Future refactoring | 33 // This class owns a PermissionInfoBarDelegate if the PermissionRequestManager |
33 // will consolidate PermissionInfoBarDelegate and its subclasses together into | 34 // is disabled and points to a PermissionPromptAndroid if it's enabled. When the |
34 // GroupedPermissionInfoBarDelegate, which will then source all of its data from | 35 // PermissionRequestManager is enabled by default, we can remove the code path |
35 // an underlying PermissionPromptAndroid object. At that time, this class will | 36 // for using a PermissionInfoBarDelegate. This is tracked in crbug.com/606138. |
36 // also change to wrap a PermissionPromptAndroid. | |
37 class PermissionDialogDelegate : public content::WebContentsObserver { | 37 class PermissionDialogDelegate : public content::WebContentsObserver { |
38 public: | 38 public: |
39 using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>; | 39 using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>; |
40 | 40 |
41 // Creates a modal dialog for |type|. | 41 // The interface for creating a modal dialog when the PermissionRequestManager |
| 42 // is enabled. |
| 43 static void Create(content::WebContents* web_contents, |
| 44 PermissionPromptAndroid* permission_prompt); |
| 45 |
| 46 // The interface for creating a modal dialog when the PermissionRequestManager |
| 47 // is disabled, i.e. we're using the PermissionQueueController. |
42 static void Create(content::WebContents* web_contents, | 48 static void Create(content::WebContents* web_contents, |
43 ContentSettingsType type, | 49 ContentSettingsType type, |
44 const GURL& requesting_frame, | 50 const GURL& requesting_frame, |
45 bool user_gesture, | 51 bool user_gesture, |
46 Profile* profile, | 52 Profile* profile, |
47 const PermissionSetCallback& callback); | 53 const PermissionSetCallback& callback); |
48 | 54 |
49 // Creates a modal dialog for a media stream permission request. | 55 // Creates a modal dialog for a media stream permission request. |
50 // TODO(dominickn): remove this when media stream requests are eventually | 56 // TODO(dominickn): remove this when media stream requests are eventually |
51 // folded in with other permission requests. | 57 // folded in with other permission requests. |
(...skipping 13 matching lines...) Expand all Loading... |
65 void Dismissed(JNIEnv* env, const JavaParamRef<jobject>& obj); | 71 void Dismissed(JNIEnv* env, const JavaParamRef<jobject>& obj); |
66 void LinkClicked(JNIEnv* env, const JavaParamRef<jobject>& obj); | 72 void LinkClicked(JNIEnv* env, const JavaParamRef<jobject>& obj); |
67 | 73 |
68 // Frees this object and the wrapped PermissionInfoBarDelegate. Called from | 74 // Frees this object and the wrapped PermissionInfoBarDelegate. Called from |
69 // Java once the permission dialog has been responded to. | 75 // Java once the permission dialog has been responded to. |
70 void Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj); | 76 void Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj); |
71 | 77 |
72 private: | 78 private: |
73 PermissionDialogDelegate( | 79 PermissionDialogDelegate( |
74 TabAndroid* tab, | 80 TabAndroid* tab, |
75 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate_); | 81 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate, |
| 82 PermissionPromptAndroid* permission_prompt); |
76 ~PermissionDialogDelegate() override; | 83 ~PermissionDialogDelegate() override; |
77 | 84 |
78 void CreateJavaDelegate(JNIEnv* env); | 85 void CreateJavaDelegate(JNIEnv* env); |
79 | 86 |
80 // On navigation or page destruction, hide the dialog. | 87 // On navigation or page destruction, hide the dialog. |
81 void DismissDialog(); | 88 void DismissDialog(); |
82 | 89 |
83 // WebContentsObserver: | 90 // WebContentsObserver: |
84 void DidFinishNavigation( | 91 void DidFinishNavigation( |
85 content::NavigationHandle* navigation_handle) override; | 92 content::NavigationHandle* navigation_handle) override; |
86 void WebContentsDestroyed() override; | 93 void WebContentsDestroyed() override; |
87 | 94 |
88 base::android::ScopedJavaGlobalRef<jobject> j_delegate_; | 95 base::android::ScopedJavaGlobalRef<jobject> j_delegate_; |
89 | 96 |
90 TabAndroid* tab_; | 97 TabAndroid* tab_; |
91 | 98 |
92 // The InfoBarDelegate which this class is wrapping. | 99 // TODO(timloh): Remove this when the refactoring is finished and we can |
93 // TODO(dominickn,lshang) replace this with PermissionPromptAndroid as the | 100 // delete the PermissionQueueController. |
94 // permission prompt refactoring continues. | |
95 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate_; | 101 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate_; |
96 | 102 |
| 103 // The PermissionPromptAndroid is alive until the tab navigates or is closed. |
| 104 // We close the prompt on DidFinishNavigation and WebContentsDestroyed, so it |
| 105 // should always be safe to use this pointer. |
| 106 PermissionPromptAndroid* permission_prompt_; |
| 107 |
97 DISALLOW_COPY_AND_ASSIGN(PermissionDialogDelegate); | 108 DISALLOW_COPY_AND_ASSIGN(PermissionDialogDelegate); |
98 }; | 109 }; |
99 | 110 |
100 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DIALOG_DELEGATE_H_ | 111 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DIALOG_DELEGATE_H_ |
OLD | NEW |