OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_PERMISSIONS_PERMISSION_DIALOG_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_PERMISSIONS_PERMISSION_DIALOG_DELEGATE_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/callback.h" |
| 12 #include "base/macros.h" |
| 13 #include "chrome/browser/permissions/permission_util.h" |
| 14 #include "content/public/browser/permission_type.h" |
| 15 #include "content/public/browser/web_contents_observer.h" |
| 16 |
| 17 using base::android::JavaParamRef; |
| 18 using base::android::ScopedJavaLocalRef; |
| 19 |
| 20 namespace content { |
| 21 class WebContents; |
| 22 } |
| 23 |
| 24 class GURL; |
| 25 class PermissionInfoBarDelegate; |
| 26 class Profile; |
| 27 |
| 28 // 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 // decision. |
| 31 // |
| 32 // This class currently wraps a PermissionInfoBarDelegate. Future refactoring |
| 33 // will consolidate PermissionInfoBarDelegate and its subclasses together into |
| 34 // GroupedPermissionInfoBarDelegate, which will then source all of its data from |
| 35 // an underlying PermissionPromptAndroid object. At that time, this class will |
| 36 // also change to wrap a PermissionPromptAndroid. |
| 37 class PermissionDialogDelegate : content::WebContentsObserver { |
| 38 public: |
| 39 using PermissionSetCallback = base::Callback<void(bool, PermissionAction)>; |
| 40 |
| 41 // Creates a modal dialog for |type|. |
| 42 static void Create(content::PermissionType type, |
| 43 content::WebContents* web_contents, |
| 44 const GURL& requesting_frame, |
| 45 bool user_gesture, |
| 46 Profile* profile, |
| 47 const PermissionSetCallback& callback); |
| 48 |
| 49 static bool ShouldShowModalPrompt(bool has_user_gesture); |
| 50 |
| 51 // JNI methods. |
| 52 static bool RegisterPermissionDialogDelegate(JNIEnv* env); |
| 53 ScopedJavaLocalRef<jobject> CreateJavaDelegate(JNIEnv* env); |
| 54 void Accept(JNIEnv* env, const JavaParamRef<jobject>& obj, jboolean persist); |
| 55 void Cancel(JNIEnv* env, const JavaParamRef<jobject>& obj, jboolean persist); |
| 56 void Dismissed(JNIEnv* env, const JavaParamRef<jobject>& obj); |
| 57 void LinkClicked(JNIEnv* env, const JavaParamRef<jobject>& obj); |
| 58 |
| 59 // Frees this object and the wrapped PermissionInfoBarDelegate. Called from |
| 60 // Java once the permission dialog has been responded to. |
| 61 void Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj); |
| 62 |
| 63 private: |
| 64 PermissionDialogDelegate( |
| 65 content::WebContents* web_contents, |
| 66 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate_); |
| 67 ~PermissionDialogDelegate() override; |
| 68 |
| 69 // The InfoBarDelegate which this class is wrapping. |
| 70 // TODO(dominickn,lshang) replace this with PermissionPromptAndroid as the |
| 71 // permission prompt refactoring continues. |
| 72 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(PermissionDialogDelegate); |
| 75 }; |
| 76 |
| 77 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DIALOG_DELEGATE_H_ |
OLD | NEW |