Files
UnrealEngineUWP/Engine/Source/Runtime/WebBrowser/Private/Android/AndroidWebBrowserDialog.cpp
Jeff Fisher fdd9530e96 UE-59012 //UE4/Main - Compile UE4Game Lumin - WARNING: Precompiled module 'PurchaseFlow' will not be usable without non-precompiled module 'WebBrowser'.
-Lumin is built with USE_ANDROID_JNI=0.  The Android implementation of the WebBrowser uses JNI, so it fails to compile.  This change wraps more JNI using code in #if USE_ANDROID_JNI and sets DUMMY_WEB_BROWSER if USE_ANDROID_JNI is false to avoid using the AndroidJavaWebBrowser.
-Previously WebBrowser had been set to not be precompiled, which avoided the compile breaks but created the warnings.
#review-4072139
#rb chris.babcock
#lockdown nick.penwarden
#jira UE-59012

[CL 4072723 by Jeff Fisher in Main branch]
2018-05-15 10:26:58 -04:00

62 lines
1.7 KiB
C++

// Copyright 1998-2018 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();
const char* Chars = JEnv->GetStringUTFChars(InString, 0);
FText Retval = FText::FromString(UTF8_TO_TCHAR(Chars));
JEnv->ReleaseStringUTFChars(InString, Chars);
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";
jclass Class = JEnv->GetObjectClass(Callback);
jmethodID MethodId = JEnv->GetMethodID(Class, MethodName, MethodSignature);
jstring JUserResponse = nullptr;
if (Success && Type==EWebBrowserDialogType::Prompt)
{
JUserResponse = FJavaClassObject::GetJString(UserResponse.ToString());
}
JEnv->CallVoidMethod(Callback, MethodId, JUserResponse);
}
#endif // USE_ANDROID_JNI