Chromium Code Reviews| 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/permissions/permission_prompt_android.h" | |
| 13 #include "chrome/browser/permissions/permission_util.h" | 14 #include "chrome/browser/permissions/permission_util.h" |
| 14 #include "components/content_settings/core/common/content_settings_types.h" | 15 #include "components/content_settings/core/common/content_settings_types.h" |
| 15 | 16 |
| 16 using base::android::JavaParamRef; | 17 using base::android::JavaParamRef; |
| 17 using base::android::ScopedJavaLocalRef; | 18 using base::android::ScopedJavaLocalRef; |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 class WebContents; | 21 class WebContents; |
| 21 } | 22 } |
| 22 | 23 |
| 23 class MediaStreamDevicesController; | 24 class MediaStreamDevicesController; |
| 24 class GURL; | 25 class GURL; |
| 25 class PermissionInfoBarDelegate; | 26 class PermissionInfoBarDelegate; |
| 26 class Profile; | 27 class Profile; |
| 27 class TabAndroid; | 28 class TabAndroid; |
| 28 | 29 |
| 29 // Delegate class for displaying a permission prompt as a modal dialog. Used as | 30 // Delegate class for displaying a permission prompt as a modal dialog. Used as |
| 30 // the native to Java interface to allow Java to communicate the user's | 31 // the native to Java interface to allow Java to communicate the user's |
| 31 // decision. | 32 // decision. |
| 32 // | 33 // |
| 33 // This class currently wraps a PermissionInfoBarDelegate. Future refactoring | 34 // This class owns a PermissionInfoBarDelegate if the PermissionRequestManager |
| 34 // will consolidate PermissionInfoBarDelegate and its subclasses together into | 35 // is disabled and points to a PermissionPromptAndroid if it's enabled. When the |
| 35 // GroupedPermissionInfoBarDelegate, which will then source all of its data from | 36 // PermissionRequestManager is enabled by default, we can remove the code path |
| 36 // an underlying PermissionPromptAndroid object. At that time, this class will | 37 // for using a PermissionInfoBarDelegate. |
|
raymes
2017/04/11 02:50:35
nit: can you add a bug link here?
Timothy Loh
2017/05/24 03:30:22
Done.
| |
| 37 // also change to wrap a PermissionPromptAndroid. | 38 // |
| 39 // TODO(timloh): Make this a WebContentsObserver so we can remove this if the | |
|
raymes
2017/04/11 02:50:35
nit: can you clarify what "this" means here
Timothy Loh
2017/05/24 03:30:22
Done.
| |
| 40 // page navigates under us. | |
| 38 class PermissionDialogDelegate { | 41 class PermissionDialogDelegate { |
| 39 public: | 42 public: |
| 40 using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>; | 43 using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>; |
| 41 | 44 |
| 45 static void Create(content::WebContents* web_contents, | |
| 46 PermissionPromptAndroid* permission_prompt); | |
|
raymes
2017/04/11 02:50:35
nit: could you add more documentation on when each
Timothy Loh
2017/05/24 03:30:22
Done.
| |
| 47 | |
| 42 // Creates a modal dialog for |type|. | 48 // Creates a modal dialog for |type|. |
| 43 static void Create(content::WebContents* web_contents, | 49 static void Create(content::WebContents* web_contents, |
| 44 ContentSettingsType type, | 50 ContentSettingsType type, |
| 45 const GURL& requesting_frame, | 51 const GURL& requesting_frame, |
| 46 bool user_gesture, | 52 bool user_gesture, |
| 47 Profile* profile, | 53 Profile* profile, |
| 48 const PermissionSetCallback& callback); | 54 const PermissionSetCallback& callback); |
| 49 | 55 |
| 50 // Creates a modal dialog for a media stream permission request. | 56 // Creates a modal dialog for a media stream permission request. |
| 51 // TODO(dominickn): remove this when media stream requests are eventually | 57 // TODO(dominickn): remove this when media stream requests are eventually |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 64 void Accept(JNIEnv* env, const JavaParamRef<jobject>& obj, jboolean persist); | 70 void Accept(JNIEnv* env, const JavaParamRef<jobject>& obj, jboolean persist); |
| 65 void Cancel(JNIEnv* env, const JavaParamRef<jobject>& obj, jboolean persist); | 71 void Cancel(JNIEnv* env, const JavaParamRef<jobject>& obj, jboolean persist); |
| 66 void Dismissed(JNIEnv* env, const JavaParamRef<jobject>& obj); | 72 void Dismissed(JNIEnv* env, const JavaParamRef<jobject>& obj); |
| 67 void LinkClicked(JNIEnv* env, const JavaParamRef<jobject>& obj); | 73 void LinkClicked(JNIEnv* env, const JavaParamRef<jobject>& obj); |
| 68 | 74 |
| 69 // Frees this object and the wrapped PermissionInfoBarDelegate. Called from | 75 // Frees this object and the wrapped PermissionInfoBarDelegate. Called from |
| 70 // Java once the permission dialog has been responded to. | 76 // Java once the permission dialog has been responded to. |
| 71 void Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj); | 77 void Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj); |
| 72 | 78 |
| 73 private: | 79 private: |
| 80 PermissionDialogDelegate(TabAndroid* tab, | |
| 81 PermissionPromptAndroid* permission_prompt); | |
| 74 PermissionDialogDelegate( | 82 PermissionDialogDelegate( |
| 75 TabAndroid* tab, | 83 TabAndroid* tab, |
| 76 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate_); | 84 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate_); |
| 77 ~PermissionDialogDelegate(); | 85 ~PermissionDialogDelegate(); |
| 78 | 86 |
| 87 void Init(); | |
| 88 | |
| 79 ScopedJavaLocalRef<jobject> CreateJavaDelegate(JNIEnv* env); | 89 ScopedJavaLocalRef<jobject> CreateJavaDelegate(JNIEnv* env); |
| 80 | 90 |
| 81 TabAndroid* tab_; | 91 TabAndroid* tab_; |
| 82 | 92 |
| 83 // The InfoBarDelegate which this class is wrapping. | 93 // TODO(timloh): Remove this when the refactoring is finished and we can |
| 84 // TODO(dominickn,lshang) replace this with PermissionPromptAndroid as the | 94 // delete the PermissionQueueController. |
| 85 // permission prompt refactoring continues. | |
| 86 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate_; | 95 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate_; |
| 87 | 96 |
| 97 PermissionPromptAndroid* permission_prompt_; | |
|
raymes
2017/04/11 02:50:35
nit: could you make a comment on the lifetime of t
Timothy Loh
2017/05/24 03:30:22
Done.
| |
| 98 | |
| 88 DISALLOW_COPY_AND_ASSIGN(PermissionDialogDelegate); | 99 DISALLOW_COPY_AND_ASSIGN(PermissionDialogDelegate); |
| 89 }; | 100 }; |
| 90 | 101 |
| 91 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DIALOG_DELEGATE_H_ | 102 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DIALOG_DELEGATE_H_ |
| OLD | NEW |