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 #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_array.h" | 10 #include "base/android/jni_array.h" |
11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
12 #include "base/feature_list.h" | 12 #include "base/feature_list.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "chrome/browser/android/resource_mapper.h" | 14 #include "chrome/browser/android/resource_mapper.h" |
15 #include "chrome/browser/android/tab_android.h" | 15 #include "chrome/browser/android/tab_android.h" |
16 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" | 16 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" |
17 #include "chrome/browser/media/midi_permission_infobar_delegate_android.h" | 17 #include "chrome/browser/media/midi_permission_infobar_delegate_android.h" |
18 #include "chrome/browser/media/protected_media_identifier_infobar_delegate_andro
id.h" | 18 #include "chrome/browser/media/protected_media_identifier_infobar_delegate_andro
id.h" |
19 #include "chrome/browser/media/webrtc/media_stream_infobar_delegate_android.h" | 19 #include "chrome/browser/media/webrtc/media_stream_infobar_delegate_android.h" |
20 #include "chrome/browser/notifications/notification_permission_infobar_delegate.
h" | 20 #include "chrome/browser/notifications/notification_permission_infobar_delegate.
h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/common/chrome_features.h" | 22 #include "chrome/common/chrome_features.h" |
23 #include "components/variations/variations_associated_data.h" | 23 #include "components/variations/variations_associated_data.h" |
| 24 #include "content/public/browser/navigation_handle.h" |
24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
25 #include "jni/PermissionDialogController_jni.h" | 26 #include "jni/PermissionDialogController_jni.h" |
26 #include "jni/PermissionDialogDelegate_jni.h" | 27 #include "jni/PermissionDialogDelegate_jni.h" |
27 #include "ui/android/window_android.h" | 28 #include "ui/android/window_android.h" |
28 #include "ui/base/window_open_disposition.h" | 29 #include "ui/base/window_open_disposition.h" |
29 | 30 |
30 using base::android::ConvertUTF16ToJavaString; | 31 using base::android::ConvertUTF16ToJavaString; |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 if (require_gesture == "false") | 96 if (require_gesture == "false") |
96 return true; | 97 return true; |
97 return has_user_gesture; | 98 return has_user_gesture; |
98 } | 99 } |
99 | 100 |
100 // static | 101 // static |
101 bool PermissionDialogDelegate::RegisterPermissionDialogDelegate(JNIEnv* env) { | 102 bool PermissionDialogDelegate::RegisterPermissionDialogDelegate(JNIEnv* env) { |
102 return RegisterNativesImpl(env); | 103 return RegisterNativesImpl(env); |
103 } | 104 } |
104 | 105 |
105 ScopedJavaLocalRef<jobject> PermissionDialogDelegate::CreateJavaDelegate( | 106 void PermissionDialogDelegate::CreateJavaDelegate(JNIEnv* env) { |
106 JNIEnv* env) { | |
107 std::vector<int> content_settings_types{ | 107 std::vector<int> content_settings_types{ |
108 infobar_delegate_->content_settings_types()}; | 108 infobar_delegate_->content_settings_types()}; |
109 | 109 |
110 return Java_PermissionDialogDelegate_create( | 110 j_delegate_.Reset(Java_PermissionDialogDelegate_create( |
111 env, reinterpret_cast<uintptr_t>(this), | 111 env, reinterpret_cast<uintptr_t>(this), tab_->GetJavaObject(), |
112 tab_->GetJavaObject(), | |
113 base::android::ToJavaIntArray(env, content_settings_types).obj(), | 112 base::android::ToJavaIntArray(env, content_settings_types).obj(), |
114 ResourceMapper::MapFromChromiumId(infobar_delegate_->GetIconId()), | 113 ResourceMapper::MapFromChromiumId(infobar_delegate_->GetIconId()), |
115 ConvertUTF16ToJavaString(env, infobar_delegate_->GetMessageText()), | 114 ConvertUTF16ToJavaString(env, infobar_delegate_->GetMessageText()), |
116 ConvertUTF16ToJavaString(env, infobar_delegate_->GetLinkText()), | 115 ConvertUTF16ToJavaString(env, infobar_delegate_->GetLinkText()), |
117 ConvertUTF16ToJavaString(env, infobar_delegate_->GetButtonLabel( | 116 ConvertUTF16ToJavaString(env, infobar_delegate_->GetButtonLabel( |
118 PermissionInfoBarDelegate::BUTTON_OK)), | 117 PermissionInfoBarDelegate::BUTTON_OK)), |
119 ConvertUTF16ToJavaString(env, | 118 ConvertUTF16ToJavaString(env, |
120 infobar_delegate_->GetButtonLabel( | 119 infobar_delegate_->GetButtonLabel( |
121 PermissionInfoBarDelegate::BUTTON_CANCEL)), | 120 PermissionInfoBarDelegate::BUTTON_CANCEL)), |
122 infobar_delegate_->ShouldShowPersistenceToggle()); | 121 infobar_delegate_->ShouldShowPersistenceToggle())); |
123 } | 122 } |
124 | 123 |
125 void PermissionDialogDelegate::Accept(JNIEnv* env, | 124 void PermissionDialogDelegate::Accept(JNIEnv* env, |
126 const JavaParamRef<jobject>& obj, | 125 const JavaParamRef<jobject>& obj, |
127 jboolean persist) { | 126 jboolean persist) { |
128 if (infobar_delegate_->ShouldShowPersistenceToggle()) | 127 if (infobar_delegate_->ShouldShowPersistenceToggle()) |
129 infobar_delegate_->set_persist(persist); | 128 infobar_delegate_->set_persist(persist); |
130 infobar_delegate_->Accept(); | 129 infobar_delegate_->Accept(); |
131 } | 130 } |
132 | 131 |
(...skipping 24 matching lines...) Expand all Loading... |
157 } | 156 } |
158 | 157 |
159 void PermissionDialogDelegate::Destroy(JNIEnv* env, | 158 void PermissionDialogDelegate::Destroy(JNIEnv* env, |
160 const JavaParamRef<jobject>& obj) { | 159 const JavaParamRef<jobject>& obj) { |
161 delete this; | 160 delete this; |
162 } | 161 } |
163 | 162 |
164 PermissionDialogDelegate::PermissionDialogDelegate( | 163 PermissionDialogDelegate::PermissionDialogDelegate( |
165 TabAndroid* tab, | 164 TabAndroid* tab, |
166 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate) | 165 std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate) |
167 : tab_(tab), infobar_delegate_(std::move(infobar_delegate)) { | 166 : content::WebContentsObserver(tab->web_contents()), |
| 167 tab_(tab), |
| 168 infobar_delegate_(std::move(infobar_delegate)) { |
168 DCHECK(tab_); | 169 DCHECK(tab_); |
169 DCHECK(infobar_delegate_); | 170 DCHECK(infobar_delegate_); |
170 | 171 |
171 // Create our Java counterpart, which manages our lifetime. | 172 // Create our Java counterpart, which manages our lifetime. |
172 JNIEnv* env = base::android::AttachCurrentThread(); | 173 JNIEnv* env = base::android::AttachCurrentThread(); |
173 base::android::ScopedJavaLocalRef<jobject> j_delegate = | 174 CreateJavaDelegate(env); |
174 CreateJavaDelegate(env); | |
175 | 175 |
176 // Send the Java delegate to the Java PermissionDialogController for display. | 176 // Send the Java delegate to the Java PermissionDialogController for display. |
177 // The controller takes over lifetime management; when the Java delegate is no | 177 // The controller takes over lifetime management; when the Java delegate is no |
178 // longer needed it will in turn free the native delegate. | 178 // longer needed it will in turn free the native delegate. |
179 Java_PermissionDialogController_createDialog(env, j_delegate.obj()); | 179 Java_PermissionDialogController_createDialog(env, j_delegate_.obj()); |
180 } | 180 } |
181 | 181 |
182 PermissionDialogDelegate::~PermissionDialogDelegate() {} | 182 PermissionDialogDelegate::~PermissionDialogDelegate() {} |
| 183 |
| 184 void PermissionDialogDelegate::DismissDialog() { |
| 185 JNIEnv* env = base::android::AttachCurrentThread(); |
| 186 Java_PermissionDialogDelegate_dismissFromNative(env, j_delegate_.obj()); |
| 187 } |
| 188 |
| 189 void PermissionDialogDelegate::DidFinishNavigation( |
| 190 content::NavigationHandle* navigation_handle) { |
| 191 if (!navigation_handle->IsInMainFrame() || |
| 192 !navigation_handle->HasCommitted() || |
| 193 navigation_handle->IsSameDocument()) { |
| 194 return; |
| 195 } |
| 196 |
| 197 DismissDialog(); |
| 198 } |
| 199 |
| 200 void PermissionDialogDelegate::WebContentsDestroyed() { |
| 201 DismissDialog(); |
| 202 } |
OLD | NEW |