Index: chrome/browser/permissions/permission_dialog_delegate.cc |
diff --git a/chrome/browser/permissions/permission_dialog_delegate.cc b/chrome/browser/permissions/permission_dialog_delegate.cc |
index 1c1e81cea63b23d579cc1cb2f3d139807811fdd1..b62a9a062174dc096f08fad0ec49c800dd7f6603 100644 |
--- a/chrome/browser/permissions/permission_dialog_delegate.cc |
+++ b/chrome/browser/permissions/permission_dialog_delegate.cc |
@@ -21,6 +21,7 @@ |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/common/chrome_features.h" |
#include "components/variations/variations_associated_data.h" |
+#include "content/public/browser/navigation_handle.h" |
#include "content/public/browser/web_contents.h" |
#include "jni/PermissionDialogController_jni.h" |
#include "jni/PermissionDialogDelegate_jni.h" |
@@ -55,8 +56,9 @@ void PermissionDialogDelegate::Create( |
// Dispatch the dialog to Java, which manages the lifetime of this object. |
new PermissionDialogDelegate( |
- tab, PermissionInfoBarDelegate::CreateDelegate( |
- type, requesting_frame, user_gesture, profile, callback)); |
+ tab, web_contents, |
+ PermissionInfoBarDelegate::CreateDelegate( |
+ type, requesting_frame, user_gesture, profile, callback)); |
} |
// static |
@@ -80,7 +82,7 @@ void PermissionDialogDelegate::CreateMediaStreamDialog( |
user_gesture, std::move(request))); |
// Dispatch the dialog to Java, which manages the lifetime of this object. |
- new PermissionDialogDelegate(tab, std::move(infobar_delegate)); |
+ new PermissionDialogDelegate(tab, web_contents, std::move(infobar_delegate)); |
} |
// static |
@@ -102,14 +104,12 @@ bool PermissionDialogDelegate::RegisterPermissionDialogDelegate(JNIEnv* env) { |
return RegisterNativesImpl(env); |
} |
-ScopedJavaLocalRef<jobject> PermissionDialogDelegate::CreateJavaDelegate( |
- JNIEnv* env) { |
+void PermissionDialogDelegate::CreateJavaDelegate(JNIEnv* env) { |
std::vector<int> content_settings_types{ |
infobar_delegate_->content_settings_types()}; |
- return Java_PermissionDialogDelegate_create( |
- env, reinterpret_cast<uintptr_t>(this), |
- tab_->GetJavaObject(), |
+ j_delegate_.Reset(Java_PermissionDialogDelegate_create( |
+ env, reinterpret_cast<uintptr_t>(this), tab_->GetJavaObject(), |
base::android::ToJavaIntArray(env, content_settings_types).obj(), |
ResourceMapper::MapFromChromiumId(infobar_delegate_->GetIconId()), |
ConvertUTF16ToJavaString(env, infobar_delegate_->GetMessageText()), |
@@ -119,7 +119,7 @@ ScopedJavaLocalRef<jobject> PermissionDialogDelegate::CreateJavaDelegate( |
ConvertUTF16ToJavaString(env, |
infobar_delegate_->GetButtonLabel( |
PermissionInfoBarDelegate::BUTTON_CANCEL)), |
- infobar_delegate_->ShouldShowPersistenceToggle()); |
+ infobar_delegate_->ShouldShowPersistenceToggle())); |
} |
void PermissionDialogDelegate::Accept(JNIEnv* env, |
@@ -158,25 +158,50 @@ void PermissionDialogDelegate::LinkClicked(JNIEnv* env, |
void PermissionDialogDelegate::Destroy(JNIEnv* env, |
const JavaParamRef<jobject>& obj) { |
+ j_delegate_ = nullptr; |
delete this; |
} |
PermissionDialogDelegate::PermissionDialogDelegate( |
TabAndroid* tab, |
+ content::WebContents* web_contents, |
dominickn
2017/05/24 03:33:38
No need to pass this: use tab->web_contents()
Timothy Loh
2017/05/24 04:59:33
Done.
|
std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate) |
- : tab_(tab), infobar_delegate_(std::move(infobar_delegate)) { |
+ : WebContentsObserver(web_contents), |
dominickn
2017/05/24 03:33:38
Nit: content::WebContentsObserver for completeness
Timothy Loh
2017/05/24 04:59:33
Done.
|
+ tab_(tab), |
+ infobar_delegate_(std::move(infobar_delegate)) { |
DCHECK(tab_); |
DCHECK(infobar_delegate_); |
// Create our Java counterpart, which manages our lifetime. |
JNIEnv* env = base::android::AttachCurrentThread(); |
- base::android::ScopedJavaLocalRef<jobject> j_delegate = |
- CreateJavaDelegate(env); |
+ CreateJavaDelegate(env); |
// Send the Java delegate to the Java PermissionDialogController for display. |
// The controller takes over lifetime management; when the Java delegate is no |
// longer needed it will in turn free the native delegate. |
- Java_PermissionDialogController_createDialog(env, j_delegate.obj()); |
+ Java_PermissionDialogController_createDialog(env, j_delegate_.obj()); |
} |
PermissionDialogDelegate::~PermissionDialogDelegate() {} |
+ |
+void PermissionDialogDelegate::DestroyJavaDelegate() { |
dominickn
2017/05/24 03:33:38
Call this DismissDialog()
Timothy Loh
2017/05/24 04:59:33
Done.
|
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ Java_PermissionDialogDelegate_destroyFromNative(env, j_delegate_.obj()); |
+} |
+ |
+void PermissionDialogDelegate::DidFinishNavigation( |
+ content::NavigationHandle* navigation_handle) { |
+ if (!navigation_handle->IsInMainFrame() || |
dominickn
2017/05/24 03:33:38
This means that if we have a third party iframe th
Timothy Loh
2017/05/24 04:59:33
Yeah, I might add some tests in a separate patch.
|
+ !navigation_handle->HasCommitted() || |
+ navigation_handle->IsSameDocument()) { |
+ return; |
+ } |
+ |
+ DestroyJavaDelegate(); |
+ delete this; |
+} |
+ |
+void PermissionDialogDelegate::WebContentsDestroyed() { |
+ DestroyJavaDelegate(); |
+ delete this; |
+} |