| 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_util.h" | 14 #include "chrome/browser/permissions/permission_util.h" |
| 15 #include "components/content_settings/core/common/content_settings_types.h" | 15 #include "components/content_settings/core/common/content_settings_types.h" |
| 16 #include "content/public/browser/web_contents_observer.h" |
| 16 | 17 |
| 17 using base::android::JavaParamRef; | 18 using base::android::JavaParamRef; |
| 18 using base::android::ScopedJavaLocalRef; | |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 class WebContents; | 21 class WebContents; |
| 22 } | 22 } |
| 23 class GURL; | 23 class GURL; |
| 24 class PermissionInfoBarDelegate; | 24 class PermissionInfoBarDelegate; |
| 25 class Profile; | 25 class Profile; |
| 26 class TabAndroid; | 26 class TabAndroid; |
| 27 | 27 |
| 28 // Delegate class for displaying a permission prompt as a modal dialog. Used as | 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 | 29 // the native to Java interface to allow Java to communicate the user's |
| 30 // decision. | 30 // decision. |
| 31 // | 31 // |
| 32 // This class currently wraps a PermissionInfoBarDelegate. Future refactoring | 32 // This class currently wraps a PermissionInfoBarDelegate. Future refactoring |
| 33 // will consolidate PermissionInfoBarDelegate and its subclasses together into | 33 // will consolidate PermissionInfoBarDelegate and its subclasses together into |
| 34 // GroupedPermissionInfoBarDelegate, which will then source all of its data from | 34 // GroupedPermissionInfoBarDelegate, which will then source all of its data from |
| 35 // an underlying PermissionPromptAndroid object. At that time, this class will | 35 // an underlying PermissionPromptAndroid object. At that time, this class will |
| 36 // also change to wrap a PermissionPromptAndroid. | 36 // also change to wrap a PermissionPromptAndroid. |
| 37 class PermissionDialogDelegate { | 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 // Creates a modal dialog for |type|. |
| 42 static void Create(content::WebContents* web_contents, | 42 static void Create(content::WebContents* web_contents, |
| 43 ContentSettingsType type, | 43 ContentSettingsType type, |
| 44 const GURL& requesting_frame, | 44 const GURL& requesting_frame, |
| 45 bool user_gesture, | 45 bool user_gesture, |
| 46 Profile* profile, | 46 Profile* profile, |
| 47 const PermissionSetCallback& callback); | 47 const PermissionSetCallback& callback); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 66 void LinkClicked(JNIEnv* env, const JavaParamRef<jobject>& obj); | 66 void LinkClicked(JNIEnv* env, const JavaParamRef<jobject>& obj); |
| 67 | 67 |
| 68 // Frees this object and the wrapped PermissionInfoBarDelegate. Called from | 68 // Frees this object and the wrapped PermissionInfoBarDelegate. Called from |
| 69 // Java once the permission dialog has been responded to. | 69 // Java once the permission dialog has been responded to. |
| 70 void Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj); | 70 void Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj); |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 PermissionDialogDelegate( | 73 PermissionDialogDelegate( |
| 74 TabAndroid* tab, | 74 TabAndroid* tab, |
| 75 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate_); | 75 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate_); |
| 76 ~PermissionDialogDelegate(); | 76 ~PermissionDialogDelegate() override; |
| 77 | 77 |
| 78 ScopedJavaLocalRef<jobject> CreateJavaDelegate(JNIEnv* env); | 78 void CreateJavaDelegate(JNIEnv* env); |
| 79 |
| 80 // On navigation or page destruction, hide the dialog. |
| 81 void DismissDialog(); |
| 82 |
| 83 // WebContentsObserver: |
| 84 void DidFinishNavigation( |
| 85 content::NavigationHandle* navigation_handle) override; |
| 86 void WebContentsDestroyed() override; |
| 87 |
| 88 base::android::ScopedJavaGlobalRef<jobject> j_delegate_; |
| 79 | 89 |
| 80 TabAndroid* tab_; | 90 TabAndroid* tab_; |
| 81 | 91 |
| 82 // The InfoBarDelegate which this class is wrapping. | 92 // The InfoBarDelegate which this class is wrapping. |
| 83 // TODO(dominickn,lshang) replace this with PermissionPromptAndroid as the | 93 // TODO(dominickn,lshang) replace this with PermissionPromptAndroid as the |
| 84 // permission prompt refactoring continues. | 94 // permission prompt refactoring continues. |
| 85 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate_; | 95 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate_; |
| 86 | 96 |
| 87 DISALLOW_COPY_AND_ASSIGN(PermissionDialogDelegate); | 97 DISALLOW_COPY_AND_ASSIGN(PermissionDialogDelegate); |
| 88 }; | 98 }; |
| 89 | 99 |
| 90 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DIALOG_DELEGATE_H_ | 100 #endif // CHROME_BROWSER_PERMISSIONS_PERMISSION_DIALOG_DELEGATE_H_ |
| OLD | NEW |