Files
UnrealEngineUWP/Engine/Source/Runtime/WebBrowser/Private/Android/AndroidWebBrowserDialog.cpp
ryan durand 0f0464a30e Updating copyright for Engine Runtime.
#rnx
#rb none


#ROBOMERGE-OWNER: ryan.durand
#ROBOMERGE-AUTHOR: ryan.durand
#ROBOMERGE-SOURCE: CL 10869210 via CL 10869511 via CL 10869900
#ROBOMERGE-BOT: (v613-10869866)

[CL 10870549 by ryan durand in Main branch]
2019-12-26 14:45:42 -05:00

65 lines
1.7 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "AndroidWebBrowserDialog.h"
#if USE_ANDROID_JNI
#include "Android/AndroidApplication.h"
#include "Android/AndroidJava.h"
#include <jni.h>
namespace
{
FText GetFText(jstring InString)
{
if (InString == nullptr)
{
return FText::GetEmpty();
}
JNIEnv* JEnv = FAndroidApplication::GetJavaEnv();
FString Temp = FJavaHelper::FStringFromParam(JEnv, InString);
FText Retval = FText::FromString(Temp);
return Retval;
}
}
FAndroidWebBrowserDialog::FAndroidWebBrowserDialog(jstring InMessageText, jstring InDefaultPrompt, jobject InCallback)
: Type(EWebBrowserDialogType::Prompt)
, MessageText(GetFText(InMessageText))
, DefaultPrompt(GetFText(InDefaultPrompt))
, Callback(InCallback)
{
}
FAndroidWebBrowserDialog::FAndroidWebBrowserDialog(EWebBrowserDialogType InDialogType, jstring InMessageText, jobject InCallback)
: Type(InDialogType)
, MessageText(GetFText(InMessageText))
, DefaultPrompt()
, Callback(InCallback)
{
}
void FAndroidWebBrowserDialog::Continue(bool Success, const FText& UserResponse)
{
check(Callback != nullptr);
JNIEnv* JEnv = FAndroidApplication::GetJavaEnv();
const char* MethodName = Success?"confirm":"cancel";
const char* MethodSignature = (Success && Type==EWebBrowserDialogType::Prompt)?"(Ljava/lang/String;)V":"()V";
auto Class = NewScopedJavaObject(JEnv, JEnv->GetObjectClass(Callback));
jmethodID MethodId = JEnv->GetMethodID(*Class, MethodName, MethodSignature);
if (Success && Type==EWebBrowserDialogType::Prompt)
{
auto JUserResponse = FJavaClassObject::GetJString(UserResponse.ToString());
JEnv->CallVoidMethod(Callback, MethodId, *JUserResponse);
}
else
{
JEnv->CallVoidMethod(Callback, MethodId, nullptr);
}
}
#endif // USE_ANDROID_JNI