mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-23 07:10:19 +00:00
commit
e0b3242f8d
@ -36,6 +36,7 @@
|
||||
#include "js_data_struct_converter.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "js_utils.h"
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
#include "js_window_stage.h"
|
||||
#endif
|
||||
@ -70,10 +71,10 @@ napi_value PromiseCallback(napi_env env, napi_callback_info info)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
napi_value AttachJsAbilityContext(napi_env env, void *value, void *)
|
||||
napi_value AttachJsAbilityContext(napi_env env, void *value, void *extValue)
|
||||
{
|
||||
HILOG_DEBUG("Begin.");
|
||||
if (value == nullptr) {
|
||||
if (value == nullptr || extValue == nullptr) {
|
||||
HILOG_ERROR("Invalid parameter.");
|
||||
return nullptr;
|
||||
}
|
||||
@ -82,14 +83,27 @@ napi_value AttachJsAbilityContext(napi_env env, void *value, void *)
|
||||
HILOG_ERROR("Invalid context.");
|
||||
return nullptr;
|
||||
}
|
||||
napi_value object = CreateJsAbilityContext(env, ptr);
|
||||
auto systemModule = JsRuntime::LoadSystemModuleByEngine(env, "application.AbilityContext", &object, 1);
|
||||
if (systemModule == nullptr) {
|
||||
HILOG_ERROR("Invalid systemModule.");
|
||||
std::shared_ptr<NativeReference> systemModule = nullptr;
|
||||
auto screenModePtr = reinterpret_cast<std::weak_ptr<int32_t> *>(extValue)->lock();
|
||||
if (screenModePtr == nullptr) {
|
||||
HILOG_ERROR("Invalid screenModePtr.");
|
||||
return nullptr;
|
||||
}
|
||||
if (*screenModePtr == AAFwk::IDLE_SCREEN_MODE) {
|
||||
auto uiAbiObject = CreateJsAbilityContext(env, ptr);
|
||||
CHECK_POINTER_AND_RETURN(uiAbiObject, nullptr);
|
||||
systemModule = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(env,
|
||||
"application.AbilityContext", &uiAbiObject, 1).release());
|
||||
} else {
|
||||
auto emUIObject = JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(env,
|
||||
ptr, nullptr, *screenModePtr);
|
||||
CHECK_POINTER_AND_RETURN(emUIObject, nullptr);
|
||||
systemModule = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(env,
|
||||
"application.EmbeddableUIAbilityContext", &emUIObject, 1).release());
|
||||
}
|
||||
CHECK_POINTER_AND_RETURN(systemModule, nullptr);
|
||||
auto contextObj = systemModule->GetNapiValue();
|
||||
napi_coerce_to_native_binding_object(env, contextObj, DetachCallbackFunc, AttachJsAbilityContext, value, nullptr);
|
||||
napi_coerce_to_native_binding_object(env, contextObj, DetachCallbackFunc, AttachJsAbilityContext, value, extValue);
|
||||
auto workContext = new (std::nothrow) std::weak_ptr<AbilityRuntime::AbilityContext>(ptr);
|
||||
napi_wrap(env, contextObj, workContext,
|
||||
[](napi_env, void* data, void*) {
|
||||
@ -189,9 +203,7 @@ void JsUIAbility::SetAbilityContext(std::shared_ptr<AbilityInfo> abilityInfo,
|
||||
}
|
||||
napi_value contextObj = nullptr;
|
||||
int32_t screenMode = want->GetIntParam(AAFwk::SCREEN_MODE_KEY, AAFwk::IDLE_SCREEN_MODE);
|
||||
CreateAbilityContext(env, contextObj, screenMode);
|
||||
shellContextRef_ = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(
|
||||
env, "application.AbilityContext", &contextObj, 1).release());
|
||||
CreateJSContext(env, contextObj, screenMode);
|
||||
if (shellContextRef_ == nullptr) {
|
||||
HILOG_ERROR("shellContextRef_ is nullptr.");
|
||||
return;
|
||||
@ -202,12 +214,12 @@ void JsUIAbility::SetAbilityContext(std::shared_ptr<AbilityInfo> abilityInfo,
|
||||
return;
|
||||
}
|
||||
auto workContext = new (std::nothrow) std::weak_ptr<AbilityRuntime::AbilityContext>(abilityContext_);
|
||||
if (workContext == nullptr) {
|
||||
HILOG_ERROR("workContext is nullptr.");
|
||||
return;
|
||||
}
|
||||
CHECK_POINTER(workContext);
|
||||
screenModePtr_ = std::make_shared<int32_t>(screenMode);
|
||||
auto workScreenMode = new (std::nothrow) std::weak_ptr<int32_t>(screenModePtr_);
|
||||
CHECK_POINTER(workScreenMode);
|
||||
napi_coerce_to_native_binding_object(
|
||||
env, contextObj, DetachCallbackFunc, AttachJsAbilityContext, workContext, nullptr);
|
||||
env, contextObj, DetachCallbackFunc, AttachJsAbilityContext, workContext, workScreenMode);
|
||||
abilityContext_->Bind(jsRuntime_, shellContextRef_.get());
|
||||
napi_set_named_property(env, obj, "context", contextObj);
|
||||
HILOG_DEBUG("Set ability context");
|
||||
@ -219,15 +231,22 @@ void JsUIAbility::SetAbilityContext(std::shared_ptr<AbilityInfo> abilityInfo,
|
||||
HILOG_DEBUG("Finalizer for weak_ptr ability context is called");
|
||||
delete static_cast<std::weak_ptr<AbilityRuntime::AbilityContext> *>(data);
|
||||
}, nullptr, nullptr);
|
||||
HILOG_DEBUG("Init end.");
|
||||
}
|
||||
|
||||
void JsUIAbility::CreateAbilityContext(napi_env env, napi_value &contextObj, int32_t screenMode)
|
||||
void JsUIAbility::CreateJSContext(napi_env env, napi_value &contextObj, int32_t screenMode)
|
||||
{
|
||||
if (screenMode == AAFwk::IDLE_SCREEN_MODE) {
|
||||
contextObj = CreateJsAbilityContext(env, abilityContext_);
|
||||
CHECK_POINTER(contextObj);
|
||||
shellContextRef_ = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(
|
||||
env, "application.AbilityContext", &contextObj, 1).release());
|
||||
} else {
|
||||
contextObj =
|
||||
JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(env, abilityContext_, screenMode);
|
||||
contextObj = JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(env,
|
||||
abilityContext_, nullptr, screenMode);
|
||||
CHECK_POINTER(contextObj);
|
||||
shellContextRef_ = std::shared_ptr<NativeReference>(JsRuntime::LoadSystemModuleByEngine(
|
||||
env, "application.EmbeddableUIAbilityContext", &contextObj, 1).release());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "ability_manager_client.h"
|
||||
#include "event_handler.h"
|
||||
@ -41,16 +42,21 @@ namespace AbilityRuntime {
|
||||
return nullptr; \
|
||||
}
|
||||
|
||||
JsEmbeddableUIAbilityContext::JsEmbeddableUIAbilityContext(const std::shared_ptr<AbilityContext>& context,
|
||||
int32_t screenMode)
|
||||
namespace {
|
||||
const std::string ERR_MSG_NOT_SUPPORT = "Not support the interface in half screen mode of atomic service.";
|
||||
}
|
||||
|
||||
JsEmbeddableUIAbilityContext::JsEmbeddableUIAbilityContext(const std::shared_ptr<AbilityContext>& uiAbiContext,
|
||||
const std::shared_ptr<UIExtensionContext>& uiExtContext, int32_t screenMode)
|
||||
{
|
||||
jsAbilityContext_ = std::make_shared<JsAbilityContext>(context);
|
||||
jsAbilityContext_ = std::make_shared<JsAbilityContext>(uiAbiContext);
|
||||
jsUIExtensionContext_ = std::make_shared<JsUIExtensionContext>(uiExtContext);
|
||||
screenMode_ = screenMode;
|
||||
}
|
||||
|
||||
void JsEmbeddableUIAbilityContext::Finalizer(napi_env env, void* data, void* hint)
|
||||
{
|
||||
HILOG_DEBUG("JsEmbeddableUIAbilityContext Finalizer is called");
|
||||
HILOG_DEBUG("The Finalizer of embeddable UI ability context is called.");
|
||||
std::unique_ptr<JsEmbeddableUIAbilityContext>(static_cast<JsEmbeddableUIAbilityContext*>(data));
|
||||
}
|
||||
|
||||
@ -84,11 +90,92 @@ napi_value JsEmbeddableUIAbilityContext::TerminateSelfWithResult(napi_env env, n
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnTerminateSelfWithResult);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::StartAbilityAsCaller(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbilityAsCaller);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::StartAbilityWithAccount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbilityWithAccount);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::StartAbilityByCall(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbilityByCall);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::StartAbilityForResultWithAccount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbilityForResultWithAccount);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::StartServiceExtensionAbility(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartExtensionAbility);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::StartServiceExtensionAbilityWithAccount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartExtensionAbilityWithAccount);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::StopServiceExtensionAbility(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStopExtensionAbility);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::StopServiceExtensionAbilityWithAccount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStopExtensionAbilityWithAccount);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::ConnectAbilityWithAccount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnConnectAbilityWithAccount);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::RestoreWindowStage(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnRestoreWindowStage);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::IsTerminating(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnIsTerminating);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::StartRecentAbility(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartRecentAbility);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::RequestDialogService(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnRequestDialogService);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::ReportDrawnCompleted(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnReportDrawnCompleted);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::SetMissionContinueState(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnSetMissionContinueState);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::StartAbilityByType(napi_env env, napi_callback_info info)
|
||||
{
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbilityByType);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnStartAbility(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("OnStartAbility Half screen mode");
|
||||
return nullptr;
|
||||
HILOG_INFO("Start ability in half screen mode.");
|
||||
CHECK_POINTER_RETURN(jsUIExtensionContext_);
|
||||
return jsUIExtensionContext_->OnStartAbility(env, info);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnStartAbility(env, info);
|
||||
@ -97,8 +184,9 @@ napi_value JsEmbeddableUIAbilityContext::OnStartAbility(napi_env env, NapiCallba
|
||||
napi_value JsEmbeddableUIAbilityContext::OnStartAbilityForResult(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("OnStartAbilityForResult Half screen mode");
|
||||
return nullptr;
|
||||
HILOG_INFO("Start ability for result in half screen mode.");
|
||||
CHECK_POINTER_RETURN(jsUIExtensionContext_);
|
||||
return jsUIExtensionContext_->OnStartAbilityForResult(env, info);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnStartAbilityForResult(env, info);
|
||||
@ -107,8 +195,9 @@ napi_value JsEmbeddableUIAbilityContext::OnStartAbilityForResult(napi_env env, N
|
||||
napi_value JsEmbeddableUIAbilityContext::OnConnectAbility(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("OnConnectAbility Half screen mode");
|
||||
return nullptr;
|
||||
HILOG_INFO("Connect ability in half screen mode.");
|
||||
CHECK_POINTER_RETURN(jsUIExtensionContext_);
|
||||
return jsUIExtensionContext_->OnConnectAbility(env, info);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnConnectAbility(env, info);
|
||||
@ -117,8 +206,9 @@ napi_value JsEmbeddableUIAbilityContext::OnConnectAbility(napi_env env, NapiCall
|
||||
napi_value JsEmbeddableUIAbilityContext::OnDisconnectAbility(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("OnDisconnectAbility Half screen mode");
|
||||
return nullptr;
|
||||
HILOG_INFO("Disconnect ability in half screen mode.");
|
||||
CHECK_POINTER_RETURN(jsUIExtensionContext_);
|
||||
return jsUIExtensionContext_->OnDisconnectAbility(env, info);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnDisconnectAbility(env, info);
|
||||
@ -127,8 +217,9 @@ napi_value JsEmbeddableUIAbilityContext::OnDisconnectAbility(napi_env env, NapiC
|
||||
napi_value JsEmbeddableUIAbilityContext::OnTerminateSelf(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("OnTerminateSelf Half screen mode");
|
||||
return nullptr;
|
||||
HILOG_INFO("Terminate self in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnTerminateSelf(env, info);
|
||||
@ -137,32 +228,282 @@ napi_value JsEmbeddableUIAbilityContext::OnTerminateSelf(napi_env env, NapiCallb
|
||||
napi_value JsEmbeddableUIAbilityContext::OnTerminateSelfWithResult(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("OnTerminateSelfWithResult Half screen mode");
|
||||
return nullptr;
|
||||
HILOG_INFO("Terminate self with result in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnTerminateSelfWithResult(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(napi_env env,
|
||||
std::shared_ptr<AbilityContext> context, int32_t screenMode)
|
||||
napi_value JsEmbeddableUIAbilityContext::OnStartAbilityAsCaller(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
HILOG_INFO("CreateJsEmbeddableUIAbilityContext begin");
|
||||
napi_value objValue = CreateJsBaseContext(env, context);
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Start ability as caller in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnStartAbilityAsCaller(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnStartAbilityWithAccount(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Start ability with account in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnStartAbilityWithAccount(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnStartAbilityByCall(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Start ability by caller in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnStartAbilityByCall(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnStartAbilityForResultWithAccount(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Start ability for result in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnStartAbilityForResultWithAccount(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnStartExtensionAbility(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Start extension in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnStartExtensionAbility(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnStartExtensionAbilityWithAccount(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Start extensionin with account in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnStartExtensionAbilityWithAccount(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnStopExtensionAbility(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Stop extensionin in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnStopExtensionAbility(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnStopExtensionAbilityWithAccount(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Stop extensionin with account in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnStopExtensionAbilityWithAccount(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnConnectAbilityWithAccount(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Connect ability with account in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnConnectAbilityWithAccount(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnRestoreWindowStage(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Restore window stage with account in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnRestoreWindowStage(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnIsTerminating(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Get terminating state in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnIsTerminating(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnStartRecentAbility(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Start recent ability in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnStartRecentAbility(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnRequestDialogService(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Request dialog service in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnRequestDialogService(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnReportDrawnCompleted(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Report drawn completed in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnReportDrawnCompleted(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnSetMissionContinueState(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Set mission continue state in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnSetMissionContinueState(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnStartAbilityByType(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Start ability by type in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnStartAbilityByType(env, info);
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
napi_value JsEmbeddableUIAbilityContext::SetMissionLabel(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_INFO("Set mission label is called.");
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnSetMissionLabel);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::SetMissionIcon(napi_env env, napi_callback_info info)
|
||||
{
|
||||
HILOG_INFO("Set mission icon is called.");
|
||||
GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnSetMissionIcon);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnSetMissionLabel(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Set mission label in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnSetMissionLabel(env, info);
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::OnSetMissionIcon(napi_env env, NapiCallbackInfo& info)
|
||||
{
|
||||
if (screenMode_ == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_INFO("Set mission icon in half screen mode.");
|
||||
ThrowError(env, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER), ERR_MSG_NOT_SUPPORT);
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
CHECK_POINTER_RETURN(jsAbilityContext_);
|
||||
return jsAbilityContext_->OnSetMissionIcon(env, info);
|
||||
}
|
||||
#endif
|
||||
|
||||
void JsEmbeddableUIAbilityContext::WrapJsUIAbilityContext(napi_env env,
|
||||
std::shared_ptr<AbilityContext> uiAbiContext, napi_value &objValue, int32_t screenMode)
|
||||
{
|
||||
if (uiAbiContext == nullptr) {
|
||||
HILOG_ERROR("UI ability context is nullptr");
|
||||
return;
|
||||
}
|
||||
objValue = CreateJsBaseContext(env, uiAbiContext);
|
||||
std::unique_ptr<JsEmbeddableUIAbilityContext> jsContext = std::make_unique<JsEmbeddableUIAbilityContext>(
|
||||
context, screenMode);
|
||||
uiAbiContext, nullptr, screenMode);
|
||||
napi_wrap(env, objValue, jsContext.release(), Finalizer, nullptr, nullptr);
|
||||
CHECK_POINTER_RETURN(context);
|
||||
auto abilityInfo = context->GetAbilityInfo();
|
||||
|
||||
auto abilityInfo = uiAbiContext->GetAbilityInfo();
|
||||
if (abilityInfo != nullptr) {
|
||||
napi_set_named_property(env, objValue, "abilityInfo", CreateJsAbilityInfo(env, *abilityInfo));
|
||||
}
|
||||
|
||||
auto configuration = context->GetConfiguration();
|
||||
auto configuration = uiAbiContext->GetConfiguration();
|
||||
if (configuration != nullptr) {
|
||||
napi_set_named_property(env, objValue, "config", CreateJsConfiguration(env, *configuration));
|
||||
}
|
||||
}
|
||||
|
||||
void JsEmbeddableUIAbilityContext::WrapJsUIExtensionContext(napi_env env,
|
||||
std::shared_ptr<UIExtensionContext> uiExtContext, napi_value &objValue, int32_t screenMode)
|
||||
{
|
||||
if (uiExtContext == nullptr) {
|
||||
HILOG_ERROR("UI extension context is nullptr");
|
||||
return;
|
||||
}
|
||||
objValue = CreateJsBaseContext(env, uiExtContext);
|
||||
std::unique_ptr<JsEmbeddableUIAbilityContext> jsContext = std::make_unique<JsEmbeddableUIAbilityContext>(
|
||||
nullptr, uiExtContext, screenMode);
|
||||
napi_wrap(env, objValue, jsContext.release(), Finalizer, nullptr, nullptr);
|
||||
|
||||
auto abilityInfo = uiExtContext->GetAbilityInfo();
|
||||
if (abilityInfo != nullptr) {
|
||||
napi_set_named_property(env, objValue, "abilityInfo", CreateJsAbilityInfo(env, *abilityInfo));
|
||||
}
|
||||
|
||||
auto configuration = uiExtContext->GetConfiguration();
|
||||
if (configuration != nullptr) {
|
||||
napi_set_named_property(env, objValue, "config", CreateJsConfiguration(env, *configuration));
|
||||
}
|
||||
}
|
||||
|
||||
napi_value JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(napi_env env,
|
||||
std::shared_ptr<AbilityContext> uiAbiContext, std::shared_ptr<UIExtensionContext> uiExtContext, int32_t screenMode)
|
||||
{
|
||||
HILOG_DEBUG("Create JS embeddable UIAbility context begin.");
|
||||
napi_value objValue = nullptr;
|
||||
if (screenMode == AAFwk::FULL_SCREEN_MODE) {
|
||||
WrapJsUIAbilityContext(env, uiAbiContext, objValue, screenMode);
|
||||
} else if (screenMode == AAFwk::HALF_SCREEN_MODE) {
|
||||
WrapJsUIExtensionContext(env, uiExtContext, objValue, screenMode);
|
||||
}
|
||||
|
||||
const char* moduleName = "JsEmbeddableUIAbilityContext";
|
||||
BindNativeFunction(env, objValue, "startAbility", moduleName, StartAbility);
|
||||
@ -171,7 +512,30 @@ napi_value JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(napi
|
||||
BindNativeFunction(env, objValue, "disconnectServiceExtensionAbility", moduleName, DisconnectAbility);
|
||||
BindNativeFunction(env, objValue, "terminateSelf", moduleName, TerminateSelf);
|
||||
BindNativeFunction(env, objValue, "terminateSelfWithResult", moduleName, TerminateSelfWithResult);
|
||||
|
||||
BindNativeFunction(env, objValue, "startAbilityAsCaller", moduleName, StartAbilityAsCaller);
|
||||
BindNativeFunction(env, objValue, "startAbilityWithAccount", moduleName, StartAbilityWithAccount);
|
||||
BindNativeFunction(env, objValue, "startAbilityByCall", moduleName, StartAbilityByCall);
|
||||
BindNativeFunction(env, objValue, "startAbilityForResultWithAccount", moduleName,
|
||||
StartAbilityForResultWithAccount);
|
||||
BindNativeFunction(env, objValue, "startServiceExtensionAbility", moduleName, StartServiceExtensionAbility);
|
||||
BindNativeFunction(env, objValue, "startServiceExtensionAbilityWithAccount", moduleName,
|
||||
StartServiceExtensionAbilityWithAccount);
|
||||
BindNativeFunction(env, objValue, "stopServiceExtensionAbility", moduleName, StopServiceExtensionAbility);
|
||||
BindNativeFunction(env, objValue, "stopServiceExtensionAbilityWithAccount", moduleName,
|
||||
StopServiceExtensionAbilityWithAccount);
|
||||
BindNativeFunction(env, objValue, "connectServiceExtensionAbilityWithAccount", moduleName,
|
||||
ConnectAbilityWithAccount);
|
||||
BindNativeFunction(env, objValue, "restoreWindowStage", moduleName, RestoreWindowStage);
|
||||
BindNativeFunction(env, objValue, "isTerminating", moduleName, IsTerminating);
|
||||
BindNativeFunction(env, objValue, "startRecentAbility", moduleName, StartRecentAbility);
|
||||
BindNativeFunction(env, objValue, "requestDialogService", moduleName, RequestDialogService);
|
||||
BindNativeFunction(env, objValue, "reportDrawnCompleted", moduleName, ReportDrawnCompleted);
|
||||
BindNativeFunction(env, objValue, "setMissionContinueState", moduleName, SetMissionContinueState);
|
||||
BindNativeFunction(env, objValue, "startAbilityByType", moduleName, StartAbilityByType);
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
BindNativeFunction(env, objValue, "setMissionLabel", moduleName, SetMissionLabel);
|
||||
BindNativeFunction(env, objValue, "setMissionIcon", moduleName, SetMissionIcon);
|
||||
#endif
|
||||
return objValue;
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
|
@ -27,12 +27,14 @@
|
||||
#include "insight_intent_executor_info.h"
|
||||
#include "insight_intent_executor_mgr.h"
|
||||
#include "int_wrapper.h"
|
||||
#include "js_embeddable_ui_ability_context.h"
|
||||
#include "js_extension_common.h"
|
||||
#include "js_extension_context.h"
|
||||
#include "js_runtime.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "js_ui_extension_content_session.h"
|
||||
#include "js_ui_extension_context.h"
|
||||
#include "js_utils.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
#include "napi_common_configuration.h"
|
||||
@ -49,10 +51,10 @@ constexpr size_t ARGC_ONE = 1;
|
||||
constexpr size_t ARGC_TWO = 2;
|
||||
}
|
||||
|
||||
napi_value AttachUIExtensionContext(napi_env env, void *value, void *)
|
||||
napi_value AttachUIExtensionContext(napi_env env, void *value, void *extValue)
|
||||
{
|
||||
HILOG_DEBUG("AttachUIExtensionContext");
|
||||
if (value == nullptr) {
|
||||
if (value == nullptr || extValue == nullptr) {
|
||||
HILOG_ERROR("invalid parameter.");
|
||||
return nullptr;
|
||||
}
|
||||
@ -62,14 +64,30 @@ napi_value AttachUIExtensionContext(napi_env env, void *value, void *)
|
||||
HILOG_ERROR("invalid context.");
|
||||
return nullptr;
|
||||
}
|
||||
napi_value object = JsUIExtensionContext::CreateJsUIExtensionContext(env, ptr);
|
||||
auto contextObj = JsRuntime::LoadSystemModuleByEngine(env, "application.UIExtensionContext",
|
||||
&object, 1)->GetNapiValue();
|
||||
auto screenModePtr = reinterpret_cast<std::weak_ptr<int32_t> *>(extValue)->lock();
|
||||
if (screenModePtr == nullptr) {
|
||||
HILOG_ERROR("Invalid screenModePtr.");
|
||||
return nullptr;
|
||||
}
|
||||
napi_value contextObj = nullptr;
|
||||
if (*screenModePtr == AAFwk::IDLE_SCREEN_MODE) {
|
||||
auto uiExtObject = JsUIExtensionContext::CreateJsUIExtensionContext(env, ptr);
|
||||
CHECK_POINTER_AND_RETURN(uiExtObject, nullptr);
|
||||
contextObj = JsRuntime::LoadSystemModuleByEngine(env, "application.UIExtensionContext",
|
||||
&uiExtObject, 1)->GetNapiValue();
|
||||
} else {
|
||||
auto emUIObject = JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(env,
|
||||
nullptr, ptr, *screenModePtr);
|
||||
CHECK_POINTER_AND_RETURN(emUIObject, nullptr);
|
||||
contextObj = JsRuntime::LoadSystemModuleByEngine(env, "application.EmbeddableUIAbilityContext",
|
||||
&emUIObject, 1)->GetNapiValue();
|
||||
}
|
||||
if (contextObj == nullptr) {
|
||||
HILOG_ERROR("load context error.");
|
||||
return nullptr;
|
||||
}
|
||||
napi_coerce_to_native_binding_object(env, contextObj, DetachCallbackFunc, AttachUIExtensionContext, value, nullptr);
|
||||
napi_coerce_to_native_binding_object(env, contextObj, DetachCallbackFunc,
|
||||
AttachUIExtensionContext, value, extValue);
|
||||
auto workContext = new (std::nothrow) std::weak_ptr<UIExtensionContext>(ptr);
|
||||
napi_wrap(env, contextObj, workContext,
|
||||
[](napi_env, void *data, void *) {
|
||||
@ -138,6 +156,7 @@ void JsUIExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
const sptr<IRemoteObject> &token)
|
||||
{
|
||||
HILOG_DEBUG("JsUIExtension begin init");
|
||||
CHECK_POINTER(record);
|
||||
UIExtension::Init(record, application, handler, token);
|
||||
if (Extension::abilityInfo_ == nullptr || Extension::abilityInfo_->srcEntrance.empty()) {
|
||||
HILOG_ERROR("JsUIExtension Init abilityInfo error");
|
||||
@ -166,13 +185,30 @@ void JsUIExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
|
||||
return;
|
||||
}
|
||||
|
||||
BindContext(env, obj);
|
||||
BindContext(env, obj, record->GetWant());
|
||||
|
||||
SetExtensionCommon(
|
||||
JsExtensionCommon::Create(jsRuntime_, static_cast<NativeReference&>(*jsObj_), shellContextRef_));
|
||||
}
|
||||
|
||||
void JsUIExtension::BindContext(napi_env env, napi_value obj)
|
||||
void JsUIExtension::CreateJSContext(napi_env env, napi_value &contextObj,
|
||||
std::shared_ptr<UIExtensionContext> context, int32_t screenMode)
|
||||
{
|
||||
if (screenMode == AAFwk::IDLE_SCREEN_MODE) {
|
||||
contextObj = JsUIExtensionContext::CreateJsUIExtensionContext(env, context);
|
||||
CHECK_POINTER(contextObj);
|
||||
shellContextRef_ = JsRuntime::LoadSystemModuleByEngine(env, "application.UIExtensionContext",
|
||||
&contextObj, ARGC_ONE);
|
||||
} else {
|
||||
contextObj = JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(env,
|
||||
nullptr, context, screenMode);
|
||||
CHECK_POINTER(contextObj);
|
||||
shellContextRef_ = JsRuntime::LoadSystemModuleByEngine(env, "application.EmbeddableUIAbilityContext",
|
||||
&contextObj, ARGC_ONE);
|
||||
}
|
||||
}
|
||||
|
||||
void JsUIExtension::BindContext(napi_env env, napi_value obj, std::shared_ptr<AAFwk::Want> want)
|
||||
{
|
||||
auto context = GetContext();
|
||||
if (context == nullptr) {
|
||||
@ -180,16 +216,15 @@ void JsUIExtension::BindContext(napi_env env, napi_value obj)
|
||||
return;
|
||||
}
|
||||
HILOG_DEBUG("BindContext CreateJsUIExtensionContext.");
|
||||
napi_value contextObj = JsUIExtensionContext::CreateJsUIExtensionContext(env, context);
|
||||
if (contextObj == nullptr) {
|
||||
HILOG_ERROR("Create js ui extension context error.");
|
||||
if (want == nullptr) {
|
||||
HILOG_ERROR("Want info is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
shellContextRef_ = JsRuntime::LoadSystemModuleByEngine(env, "application.UIExtensionContext",
|
||||
&contextObj, ARGC_ONE);
|
||||
int32_t screenMode = want->GetIntParam(AAFwk::SCREEN_MODE_KEY, AAFwk::IDLE_SCREEN_MODE);
|
||||
napi_value contextObj = nullptr;
|
||||
CreateJSContext(env, contextObj, context, screenMode);
|
||||
if (shellContextRef_ == nullptr) {
|
||||
HILOG_ERROR("Failed to get LoadSystemModuleByEngine");
|
||||
HILOG_ERROR("Failed to get LoadSystemModuleByEngine.");
|
||||
return;
|
||||
}
|
||||
contextObj = shellContextRef_->GetNapiValue();
|
||||
@ -198,8 +233,12 @@ void JsUIExtension::BindContext(napi_env env, napi_value obj)
|
||||
return;
|
||||
}
|
||||
auto workContext = new (std::nothrow) std::weak_ptr<UIExtensionContext>(context);
|
||||
CHECK_POINTER(workContext);
|
||||
screenModePtr_ = std::make_shared<int32_t>(screenMode);
|
||||
auto workScreenMode = new (std::nothrow) std::weak_ptr<int32_t>(screenModePtr_);
|
||||
CHECK_POINTER(workScreenMode);
|
||||
napi_coerce_to_native_binding_object(
|
||||
env, contextObj, DetachCallbackFunc, AttachUIExtensionContext, workContext, nullptr);
|
||||
env, contextObj, DetachCallbackFunc, AttachUIExtensionContext, workContext, workScreenMode);
|
||||
context->Bind(jsRuntime_, shellContextRef_.get());
|
||||
napi_set_named_property(env, obj, "context", contextObj);
|
||||
napi_wrap(env, contextObj, workContext,
|
||||
@ -208,7 +247,6 @@ void JsUIExtension::BindContext(napi_env env, napi_value obj)
|
||||
delete static_cast<std::weak_ptr<UIExtensionContext>*>(data);
|
||||
},
|
||||
nullptr, nullptr);
|
||||
|
||||
HILOG_DEBUG("Init end.");
|
||||
}
|
||||
|
||||
|
@ -155,6 +155,11 @@ napi_value JsUIExtensionContext::OnStartAbility(napi_env env, NapiCallbackInfo&
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
if (want.GetIntParam(AAFwk::SCREEN_MODE_KEY, AAFwk::IDLE_SCREEN_MODE) == AAFwk::HALF_SCREEN_MODE) {
|
||||
HILOG_ERROR("Not support half screen pulling up half screen");
|
||||
return CreateJsUndefined(env);
|
||||
}
|
||||
|
||||
NapiAsyncTask::CompleteCallback complete =
|
||||
[weak = context_, want, startOptions, unwrapArgc](napi_env env, NapiAsyncTask& task, int32_t status) {
|
||||
HILOG_DEBUG("startAbility begin");
|
||||
|
@ -305,11 +305,12 @@ private:
|
||||
napi_env env, napi_value dumpInfo, napi_value onDumpInfo, std::vector<std::string> &info);
|
||||
void AddLifecycleEventBeforeJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const;
|
||||
void AddLifecycleEventAfterJSCall(FreezeUtil::TimeoutState state, const std::string &methodName) const;
|
||||
void CreateAbilityContext(napi_env env, napi_value &contextObj, int32_t screenMode);
|
||||
void CreateJSContext(napi_env env, napi_value &contextObj, int32_t screenMode);
|
||||
|
||||
JsRuntime &jsRuntime_;
|
||||
std::shared_ptr<NativeReference> shellContextRef_;
|
||||
std::shared_ptr<NativeReference> jsAbilityObj_;
|
||||
std::shared_ptr<int32_t> screenModePtr_;
|
||||
sptr<IRemoteObject> remoteCallee_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
|
@ -32,7 +32,8 @@ namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class JsEmbeddableUIAbilityContext final {
|
||||
public:
|
||||
JsEmbeddableUIAbilityContext(const std::shared_ptr<AbilityContext>& context, int32_t screenMode);
|
||||
JsEmbeddableUIAbilityContext(const std::shared_ptr<AbilityContext>& uiAbiContext,
|
||||
const std::shared_ptr<UIExtensionContext>& uiExtContext, int32_t screenMode);
|
||||
~JsEmbeddableUIAbilityContext() = default;
|
||||
static void Finalizer(napi_env env, void* data, void* hint);
|
||||
static napi_value StartAbility(napi_env env, napi_callback_info info);
|
||||
@ -41,16 +42,61 @@ public:
|
||||
static napi_value DisconnectAbility(napi_env env, napi_callback_info info);
|
||||
static napi_value TerminateSelf(napi_env env, napi_callback_info info);
|
||||
static napi_value TerminateSelfWithResult(napi_env env, napi_callback_info info);
|
||||
static napi_value CreateJsEmbeddableUIAbilityContext(napi_env env, std::shared_ptr<AbilityContext> context,
|
||||
int32_t screenMode);
|
||||
static napi_value CreateJsEmbeddableUIAbilityContext(napi_env env, std::shared_ptr<AbilityContext> uiAbiContext,
|
||||
std::shared_ptr<UIExtensionContext> uiExtContext, int32_t screenMode);
|
||||
static napi_value StartAbilityAsCaller(napi_env env, napi_callback_info info);
|
||||
static napi_value StartAbilityWithAccount(napi_env env, napi_callback_info info);
|
||||
static napi_value StartAbilityByCall(napi_env env, napi_callback_info info);
|
||||
static napi_value StartAbilityForResultWithAccount(napi_env env, napi_callback_info info);
|
||||
static napi_value StartServiceExtensionAbility(napi_env env, napi_callback_info info);
|
||||
static napi_value StartServiceExtensionAbilityWithAccount(napi_env env, napi_callback_info info);
|
||||
static napi_value StopServiceExtensionAbility(napi_env env, napi_callback_info info);
|
||||
static napi_value StopServiceExtensionAbilityWithAccount(napi_env env, napi_callback_info info);
|
||||
static napi_value ConnectAbilityWithAccount(napi_env env, napi_callback_info info);
|
||||
static napi_value RestoreWindowStage(napi_env env, napi_callback_info info);
|
||||
static napi_value IsTerminating(napi_env env, napi_callback_info info);
|
||||
static napi_value StartRecentAbility(napi_env env, napi_callback_info info);
|
||||
static napi_value RequestDialogService(napi_env env, napi_callback_info info);
|
||||
static napi_value ReportDrawnCompleted(napi_env env, napi_callback_info info);
|
||||
static napi_value SetMissionContinueState(napi_env env, napi_callback_info info);
|
||||
static napi_value StartAbilityByType(napi_env env, napi_callback_info info);
|
||||
|
||||
private:
|
||||
static void WrapJsUIAbilityContext(napi_env env, std::shared_ptr<AbilityContext> uiAbiContext,
|
||||
napi_value &objValue, int32_t screenMode);
|
||||
static void WrapJsUIExtensionContext(napi_env env, std::shared_ptr<UIExtensionContext> uiExtContext,
|
||||
napi_value &objValue, int32_t screenMode);
|
||||
napi_value OnStartAbility(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnStartAbilityForResult(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnConnectAbility(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnDisconnectAbility(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnTerminateSelf(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnTerminateSelfWithResult(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnStartAbilityAsCaller(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnStartAbilityWithAccount(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnStartAbilityByCall(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnStartAbilityForResultWithAccount(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnStartExtensionAbility(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnStartExtensionAbilityWithAccount(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnStopExtensionAbility(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnStopExtensionAbilityWithAccount(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnConnectAbilityWithAccount(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnRestoreWindowStage(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnIsTerminating(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnStartRecentAbility(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnRequestDialogService(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnReportDrawnCompleted(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnSetMissionContinueState(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnStartAbilityByType(napi_env env, NapiCallbackInfo& info);
|
||||
|
||||
#ifdef SUPPORT_GRAPHICS
|
||||
public:
|
||||
static napi_value SetMissionLabel(napi_env env, napi_callback_info info);
|
||||
static napi_value SetMissionIcon(napi_env env, napi_callback_info info);
|
||||
private:
|
||||
napi_value OnSetMissionLabel(napi_env env, NapiCallbackInfo& info);
|
||||
napi_value OnSetMissionIcon(napi_env env, NapiCallbackInfo& info);
|
||||
#endif
|
||||
|
||||
private:
|
||||
std::shared_ptr<JsAbilityContext> jsAbilityContext_;
|
||||
|
@ -182,7 +182,9 @@ public:
|
||||
void OnAbilityResult(int requestCode, int resultCode, const Want &resultData) override;
|
||||
|
||||
private:
|
||||
virtual void BindContext(napi_env env, napi_value obj);
|
||||
virtual void BindContext(napi_env env, napi_value obj, std::shared_ptr<AAFwk::Want> want);
|
||||
void CreateJSContext(napi_env env, napi_value &contextObj,
|
||||
std::shared_ptr<UIExtensionContext> context, int32_t screenMode);
|
||||
|
||||
napi_value CallObjectMethod(const char *name, napi_value const *argv = nullptr, size_t argc = 0,
|
||||
bool withResult = false);
|
||||
@ -211,6 +213,7 @@ private:
|
||||
std::map<uint64_t, std::shared_ptr<NativeReference>> contentSessions_;
|
||||
std::shared_ptr<AbilityResultListeners> abilityResultListeners_ = nullptr;
|
||||
int32_t screenMode_ = AAFwk::IDLE_SCREEN_MODE;
|
||||
std::shared_ptr<int32_t> screenModePtr_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
@ -39,11 +39,6 @@ public:
|
||||
static napi_value ConnectAbility(napi_env env, napi_callback_info info);
|
||||
static napi_value DisconnectAbility(napi_env env, napi_callback_info info);
|
||||
|
||||
void SetScreenMode(int32_t screenMode)
|
||||
{
|
||||
screenMode_ = screenMode;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual napi_value OnStartAbility(napi_env env, NapiCallbackInfo& info);
|
||||
virtual napi_value OnTerminateSelf(napi_env env, NapiCallbackInfo& info);
|
||||
@ -54,8 +49,8 @@ protected:
|
||||
|
||||
private:
|
||||
std::weak_ptr<UIExtensionContext> context_;
|
||||
int32_t screenMode_ = AAFwk::IDLE_SCREEN_MODE;
|
||||
friend class JsEmbeddableUIAbilityContext;
|
||||
|
||||
bool CheckStartAbilityInputParam(napi_env env, NapiCallbackInfo& info, AAFwk::Want& want,
|
||||
AAFwk::StartOptions& startOptions, size_t& unwrapArgc) const;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user