| 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
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b76c1debfac32b498e90d19922046103b75550a6
|
| --- /dev/null
|
| +++ b/chrome/browser/permissions/permission_dialog_delegate.cc
|
| @@ -0,0 +1,145 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/permissions/permission_dialog_delegate.h"
|
| +
|
| +#include <utility>
|
| +
|
| +#include "base/android/jni_android.h"
|
| +#include "base/android/jni_string.h"
|
| +#include "build/build_config.h"
|
| +#include "chrome/browser/android/resource_mapper.h"
|
| +#include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h"
|
| +#include "chrome/browser/media/midi_permission_infobar_delegate_android.h"
|
| +#include "chrome/browser/media/protected_media_identifier_infobar_delegate_android.h"
|
| +#include "chrome/browser/notifications/notification_permission_infobar_delegate.h"
|
| +#include "content/public/browser/android/content_view_core.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/window_open_disposition.h"
|
| +
|
| +using base::android::ConvertUTF16ToJavaString;
|
| +
|
| +// static
|
| +void PermissionDialogDelegate::Create(
|
| + content::PermissionType type,
|
| + content::WebContents* web_contents,
|
| + const GURL& requesting_frame,
|
| + bool user_gesture,
|
| + Profile* profile,
|
| + const PermissionSetCallback& callback) {
|
| + DCHECK(web_contents);
|
| +
|
| + std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate = nullptr;
|
| + switch (type) {
|
| + case content::PermissionType::GEOLOCATION:
|
| + infobar_delegate.reset(new GeolocationInfoBarDelegateAndroid(
|
| + requesting_frame, user_gesture, profile, callback));
|
| + break;
|
| +#if defined(ENABLE_NOTIFICATIONS)
|
| + case content::PermissionType::NOTIFICATIONS:
|
| + case content::PermissionType::PUSH_MESSAGING:
|
| + infobar_delegate.reset(new NotificationPermissionInfoBarDelegate(
|
| + requesting_frame, user_gesture, profile, callback));
|
| + break;
|
| +#endif // ENABLE_NOTIFICATIONS
|
| + case content::PermissionType::MIDI_SYSEX:
|
| + infobar_delegate.reset(new MidiPermissionInfoBarDelegateAndroid(
|
| + requesting_frame, user_gesture, profile, callback));
|
| + break;
|
| + case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER:
|
| + infobar_delegate.reset(new ProtectedMediaIdentifierInfoBarDelegateAndroid(
|
| + requesting_frame, user_gesture, profile, callback));
|
| + break;
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| +
|
| + PermissionDialogDelegate* dialog_delegate =
|
| + new PermissionDialogDelegate(web_contents, std::move(infobar_delegate));
|
| +
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| + base::android::ScopedJavaLocalRef<jobject> j_delegate =
|
| + dialog_delegate->CreateJavaDelegate(env);
|
| +
|
| + // Java queues the dialog request if neccesary, and owns the the lifetime of
|
| + // the delegate.
|
| + Java_PermissionDialogController_createDialog(env, j_delegate.obj());
|
| +}
|
| +
|
| +// static
|
| +bool PermissionDialogDelegate::RegisterPermissionDialogDelegate(JNIEnv* env) {
|
| + return RegisterNativesImpl(env);
|
| +}
|
| +
|
| +ScopedJavaLocalRef<jobject> PermissionDialogDelegate::CreateJavaDelegate(
|
| + JNIEnv* env) {
|
| + content::ContentViewCore* cvc =
|
| + content::ContentViewCore::FromWebContents(web_contents());
|
| + DCHECK(cvc);
|
| +
|
| + return Java_PermissionDialogDelegate_create(
|
| + env, reinterpret_cast<uintptr_t>(this),
|
| + cvc->GetWindowAndroid()->GetJavaObject(),
|
| + ResourceMapper::MapFromChromiumId(infobar_delegate_->GetIconId()),
|
| + ConvertUTF16ToJavaString(env, infobar_delegate_->GetMessageText()),
|
| + ConvertUTF16ToJavaString(env, infobar_delegate_->GetLinkText()),
|
| + ConvertUTF16ToJavaString(env, infobar_delegate_->GetButtonLabel(
|
| + PermissionInfoBarDelegate::BUTTON_OK)),
|
| + ConvertUTF16ToJavaString(env,
|
| + infobar_delegate_->GetButtonLabel(
|
| + PermissionInfoBarDelegate::BUTTON_CANCEL)),
|
| + infobar_delegate_->ShouldShowPersistenceToggle());
|
| +}
|
| +
|
| +void PermissionDialogDelegate::Accept(JNIEnv* env,
|
| + const JavaParamRef<jobject>& obj,
|
| + jboolean persist) {
|
| + if (infobar_delegate_->ShouldShowPersistenceToggle())
|
| + infobar_delegate_->set_persist(persist);
|
| + infobar_delegate_->Accept();
|
| +}
|
| +
|
| +void PermissionDialogDelegate::Cancel(JNIEnv* env,
|
| + const JavaParamRef<jobject>& obj,
|
| + jboolean persist) {
|
| + if (infobar_delegate_->ShouldShowPersistenceToggle())
|
| + infobar_delegate_->set_persist(persist);
|
| + infobar_delegate_->Cancel();
|
| +}
|
| +
|
| +void PermissionDialogDelegate::Dismissed(JNIEnv* env,
|
| + const JavaParamRef<jobject>& obj) {
|
| + infobar_delegate_->InfoBarDismissed();
|
| +}
|
| +
|
| +void PermissionDialogDelegate::LinkClicked(JNIEnv* env,
|
| + const JavaParamRef<jobject>& obj) {
|
| + // Don't call delegate_->LinkClicked() because that relies on having an
|
| + // InfoBarService as an owner() to open the link. That will fail since the
|
| + // wrapped delegate has no owner (is hasn't been added as an infobar).
|
| + if (web_contents()) {
|
| + web_contents()->OpenURL(content::OpenURLParams(
|
| + infobar_delegate_->GetLinkURL(), content::Referrer(),
|
| + WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
|
| + false));
|
| + }
|
| +}
|
| +
|
| +void PermissionDialogDelegate::Destroy(JNIEnv* env,
|
| + const JavaParamRef<jobject>& obj) {
|
| + delete this;
|
| +}
|
| +
|
| +PermissionDialogDelegate::PermissionDialogDelegate(
|
| + content::WebContents* web_contents,
|
| + std::unique_ptr<PermissionInfoBarDelegate> infobar_delegate)
|
| + : content::WebContentsObserver(web_contents),
|
| + infobar_delegate_(std::move(infobar_delegate)) {
|
| + DCHECK(infobar_delegate_);
|
| +}
|
| +
|
| +PermissionDialogDelegate::~PermissionDialogDelegate() {}
|
|
|