Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1442)

Unified Diff: chrome/browser/permissions/permission_dialog_delegate.cc

Issue 2899973002: Hide modal permission prompts on Android upon tab navigation/destruction (Closed)
Patch Set: fix test (permission request from js goes through mojo so need to poll) Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..d6082290ed37c02b285430e51d1eff0275ce24fe 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"
@@ -102,14 +103,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 +118,7 @@ ScopedJavaLocalRef<jobject> PermissionDialogDelegate::CreateJavaDelegate(
ConvertUTF16ToJavaString(env,
infobar_delegate_->GetButtonLabel(
PermissionInfoBarDelegate::BUTTON_CANCEL)),
- infobar_delegate_->ShouldShowPersistenceToggle());
+ infobar_delegate_->ShouldShowPersistenceToggle()));
}
void PermissionDialogDelegate::Accept(JNIEnv* env,
@@ -164,19 +163,40 @@ void PermissionDialogDelegate::Destroy(JNIEnv* env,
PermissionDialogDelegate::PermissionDialogDelegate(
TabAndroid* tab,
std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate)
- : tab_(tab), infobar_delegate_(std::move(infobar_delegate)) {
+ : content::WebContentsObserver(tab->web_contents()),
+ 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::DismissDialog() {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_PermissionDialogDelegate_dismissFromNative(env, j_delegate_.obj());
+}
+
+void PermissionDialogDelegate::DidFinishNavigation(
+ content::NavigationHandle* navigation_handle) {
+ if (!navigation_handle->IsInMainFrame() ||
+ !navigation_handle->HasCommitted() ||
+ navigation_handle->IsSameDocument()) {
+ return;
+ }
+
+ DismissDialog();
+}
+
+void PermissionDialogDelegate::WebContentsDestroyed() {
+ DismissDialog();
+}
« no previous file with comments | « chrome/browser/permissions/permission_dialog_delegate.h ('k') | content/test/data/android/permission_navigation.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698