| 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 d6082290ed37c02b285430e51d1eff0275ce24fe..a71d49dcf4bf608fb82976167546e663cadf7015 100644
|
| --- a/chrome/browser/permissions/permission_dialog_delegate.cc
|
| +++ b/chrome/browser/permissions/permission_dialog_delegate.cc
|
| @@ -20,12 +20,14 @@
|
| #include "chrome/browser/notifications/notification_permission_infobar_delegate.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/common/chrome_features.h"
|
| +#include "chrome/grit/generated_resources.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"
|
| #include "ui/android/window_android.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
| #include "ui/base/window_open_disposition.h"
|
|
|
| using base::android::ConvertUTF16ToJavaString;
|
| @@ -40,11 +42,28 @@ const char kModalParamsUserGestureKey[] = "require_gesture";
|
| // static
|
| void PermissionDialogDelegate::Create(
|
| content::WebContents* web_contents,
|
| - ContentSettingsType type,
|
| - const GURL& requesting_frame,
|
| - bool user_gesture,
|
| - Profile* profile,
|
| - const PermissionSetCallback& callback) {
|
| + PermissionPromptAndroid* permission_prompt) {
|
| + DCHECK(web_contents);
|
| +
|
| + // If we don't have a tab, just act as though the prompt was dismissed.
|
| + TabAndroid* tab = TabAndroid::FromWebContents(web_contents);
|
| + if (!tab) {
|
| + permission_prompt->Closing();
|
| + return;
|
| + }
|
| +
|
| + // Dispatch the dialog to Java, which manages the lifetime of this object.
|
| + new PermissionDialogDelegate(tab, /*infobar_delegate=*/nullptr,
|
| + permission_prompt);
|
| +}
|
| +
|
| +// static
|
| +void PermissionDialogDelegate::Create(content::WebContents* web_contents,
|
| + ContentSettingsType type,
|
| + const GURL& requesting_frame,
|
| + bool user_gesture,
|
| + Profile* profile,
|
| + const PermissionSetCallback& callback) {
|
| DCHECK(web_contents);
|
|
|
| // If we don't have a tab, just act as though the prompt was dismissed.
|
| @@ -56,8 +75,10 @@ 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,
|
| + PermissionInfoBarDelegate::CreateDelegate(
|
| + type, requesting_frame, user_gesture, profile, callback),
|
| + /*permission_prompt=*/nullptr);
|
| }
|
|
|
| // static
|
| @@ -81,7 +102,8 @@ 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, std::move(infobar_delegate),
|
| + /*permission_prompt=*/nullptr);
|
| }
|
|
|
| // static
|
| @@ -104,42 +126,83 @@ bool PermissionDialogDelegate::RegisterPermissionDialogDelegate(JNIEnv* env) {
|
| }
|
|
|
| void PermissionDialogDelegate::CreateJavaDelegate(JNIEnv* env) {
|
| + base::android::ScopedJavaLocalRef<jstring> primaryButtonText =
|
| + ConvertUTF16ToJavaString(env,
|
| + l10n_util::GetStringUTF16(IDS_PERMISSION_ALLOW));
|
| + base::android::ScopedJavaLocalRef<jstring> secondaryButtonText =
|
| + ConvertUTF16ToJavaString(env,
|
| + l10n_util::GetStringUTF16(IDS_PERMISSION_DENY));
|
| +
|
| + if (infobar_delegate_) {
|
| + std::vector<int> content_settings_types{
|
| + infobar_delegate_->content_settings_types()};
|
| +
|
| + 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()),
|
| + ConvertUTF16ToJavaString(env, infobar_delegate_->GetLinkText()),
|
| + primaryButtonText, secondaryButtonText,
|
| + infobar_delegate_->ShouldShowPersistenceToggle()));
|
| + return;
|
| + }
|
| +
|
| + // TODO(timloh): Handle grouped media permissions (camera + microphone).
|
| + DCHECK_EQ(1u, permission_prompt_->PermissionCount());
|
| +
|
| std::vector<int> content_settings_types{
|
| - infobar_delegate_->content_settings_types()};
|
| + permission_prompt_->GetContentSettingType(0)};
|
|
|
| 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()),
|
| - ConvertUTF16ToJavaString(env, infobar_delegate_->GetLinkText()),
|
| - ConvertUTF16ToJavaString(env, infobar_delegate_->GetButtonLabel(
|
| - PermissionInfoBarDelegate::BUTTON_OK)),
|
| + ResourceMapper::MapFromChromiumId(
|
| + permission_prompt_->GetIconIdForPermission(0)),
|
| + // TODO(timloh): This is the wrong string.
|
| ConvertUTF16ToJavaString(env,
|
| - infobar_delegate_->GetButtonLabel(
|
| - PermissionInfoBarDelegate::BUTTON_CANCEL)),
|
| - infobar_delegate_->ShouldShowPersistenceToggle()));
|
| + permission_prompt_->GetMessageTextFragment(0)),
|
| + // TODO(timloh): Pass the actual link text for EME.
|
| + ConvertUTF16ToJavaString(env, base::string16()), primaryButtonText,
|
| + secondaryButtonText,
|
| + // TODO(timloh): Hook up the persistence toggle.
|
| + false));
|
| }
|
|
|
| void PermissionDialogDelegate::Accept(JNIEnv* env,
|
| const JavaParamRef<jobject>& obj,
|
| jboolean persist) {
|
| - if (infobar_delegate_->ShouldShowPersistenceToggle())
|
| - infobar_delegate_->set_persist(persist);
|
| - infobar_delegate_->Accept();
|
| + if (infobar_delegate_) {
|
| + if (infobar_delegate_->ShouldShowPersistenceToggle())
|
| + infobar_delegate_->set_persist(persist);
|
| + infobar_delegate_->Accept();
|
| + return;
|
| + }
|
| +
|
| + permission_prompt_->Accept();
|
| }
|
|
|
| void PermissionDialogDelegate::Cancel(JNIEnv* env,
|
| const JavaParamRef<jobject>& obj,
|
| jboolean persist) {
|
| - if (infobar_delegate_->ShouldShowPersistenceToggle())
|
| - infobar_delegate_->set_persist(persist);
|
| - infobar_delegate_->Cancel();
|
| + if (infobar_delegate_) {
|
| + if (infobar_delegate_->ShouldShowPersistenceToggle())
|
| + infobar_delegate_->set_persist(persist);
|
| + infobar_delegate_->Cancel();
|
| + return;
|
| + }
|
| +
|
| + permission_prompt_->Deny();
|
| }
|
|
|
| void PermissionDialogDelegate::Dismissed(JNIEnv* env,
|
| const JavaParamRef<jobject>& obj) {
|
| - infobar_delegate_->InfoBarDismissed();
|
| + if (infobar_delegate_) {
|
| + infobar_delegate_->InfoBarDismissed();
|
| + return;
|
| + }
|
| +
|
| + permission_prompt_->Closing();
|
| }
|
|
|
| void PermissionDialogDelegate::LinkClicked(JNIEnv* env,
|
| @@ -148,10 +211,14 @@ void PermissionDialogDelegate::LinkClicked(JNIEnv* env,
|
| // InfoBarService as an owner() to open the link. That will fail since the
|
| // wrapped delegate has no owner (it hasn't been added as an infobar).
|
| if (tab_->web_contents()) {
|
| - tab_->web_contents()->OpenURL(content::OpenURLParams(
|
| - infobar_delegate_->GetLinkURL(), content::Referrer(),
|
| - WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
|
| - false));
|
| + if (infobar_delegate_) {
|
| + tab_->web_contents()->OpenURL(content::OpenURLParams(
|
| + infobar_delegate_->GetLinkURL(), content::Referrer(),
|
| + WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
|
| + false));
|
| + }
|
| + // TODO(timloh): Show a 'learn more' link in the PermissionRequestManager
|
| + // codepath for EME.
|
| }
|
| }
|
|
|
| @@ -162,12 +229,16 @@ void PermissionDialogDelegate::Destroy(JNIEnv* env,
|
|
|
| PermissionDialogDelegate::PermissionDialogDelegate(
|
| TabAndroid* tab,
|
| - std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate)
|
| + std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate,
|
| + PermissionPromptAndroid* permission_prompt)
|
| : content::WebContentsObserver(tab->web_contents()),
|
| tab_(tab),
|
| - infobar_delegate_(std::move(infobar_delegate)) {
|
| + infobar_delegate_(std::move(infobar_delegate)),
|
| + permission_prompt_(permission_prompt) {
|
| DCHECK(tab_);
|
| - DCHECK(infobar_delegate_);
|
| + // Only one of the PermissionPromptAndroid and PermissionInfoBarDelegate is
|
| + // used, depending on whether the PermissionRequestManager is enabled or not.
|
| + DCHECK(!!permission_prompt_ ^ !!infobar_delegate_);
|
|
|
| // Create our Java counterpart, which manages our lifetime.
|
| JNIEnv* env = base::android::AttachCurrentThread();
|
|
|