mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-20 20:20:13 -04:00
update wm log
Signed-off-by: qianlf <qianliangfang@huawei.com> Change-Id: I36c0f7a103be4593ccc299bf4b83f61020f7c3fe
This commit is contained in:
@@ -98,7 +98,8 @@ enum class WMError : int32_t {
|
||||
enum class WindowFlag : uint32_t {
|
||||
WINDOW_FLAG_NEED_AVOID = 1,
|
||||
WINDOW_FLAG_PARENT_LIMIT = 1 << 1,
|
||||
WINDOW_FLAG_END = 1 << 2,
|
||||
WINDOW_FLAG_SHOW_WHEN_LOCKED = 1 << 2,
|
||||
WINDOW_FLAG_END = 1 << 3,
|
||||
};
|
||||
|
||||
enum class WindowSizeChangeReason : uint32_t {
|
||||
|
||||
@@ -42,7 +42,7 @@ JsWindowManager::~JsWindowManager()
|
||||
|
||||
void JsWindowManager::Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
WLOGFI("JsWindowManager::Finalizer is called");
|
||||
WLOGFI("[NAPI]Finalizer");
|
||||
std::unique_ptr<JsWindowManager>(static_cast<JsWindowManager*>(data));
|
||||
}
|
||||
|
||||
@@ -93,24 +93,24 @@ static bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability)
|
||||
napi_value global;
|
||||
auto env = reinterpret_cast<napi_env>(&engine);
|
||||
if (napi_get_global(env, &global) != napi_ok) {
|
||||
WLOGFE("JsWindowManager::GetAPI7Ability get global failed");
|
||||
WLOGFE("[NAPI]Get global failed");
|
||||
return false;
|
||||
}
|
||||
napi_value jsAbility;
|
||||
napi_status status = napi_get_named_property(env, global, "ability", &jsAbility);
|
||||
if (status != napi_ok || jsAbility == nullptr) {
|
||||
WLOGFE("JsWindowManager::GetAPI7Ability get global failed");
|
||||
WLOGFE("[NAPI]Get ability property failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (napi_get_value_external(env, jsAbility, reinterpret_cast<void **>(&ability)) != napi_ok) {
|
||||
WLOGFE("JsWindowManager::GetAPI7Ability get global failed");
|
||||
WLOGFE("[NAPI]Get ability external failed");
|
||||
return false;
|
||||
}
|
||||
if (ability == nullptr) {
|
||||
return false;
|
||||
} else {
|
||||
WLOGI("JsWindowManager::GetAPI7Ability ability is success!");
|
||||
WLOGI("[NAPI]Get ability");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ static void GetNativeContext(NativeValue* nativeContext, void*& contextPtr, WMEr
|
||||
if (nativeContext != nullptr) {
|
||||
auto objContext = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeContext);
|
||||
if (objContext == nullptr) {
|
||||
WLOGFE("ConvertNativeValueTo Context Object failed");
|
||||
WLOGFE("[NAPI]ConvertNativeValueTo Context Object failed");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
return;
|
||||
}
|
||||
@@ -133,7 +133,7 @@ static bool GetWindowTypeAndParentName(NativeEngine& engine, std::string& parent
|
||||
{
|
||||
NativeNumber* type = ConvertNativeValueTo<NativeNumber>(nativeType);
|
||||
if (type == nullptr) {
|
||||
WLOGFE("Failed to convert parameter to windowType");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to windowType");
|
||||
return false;
|
||||
}
|
||||
// adapt to the old version
|
||||
@@ -144,7 +144,7 @@ static bool GetWindowTypeAndParentName(NativeEngine& engine, std::string& parent
|
||||
static_cast<uint32_t>(*type) <= static_cast<uint32_t>(ApiWindowType::TYPE_END)) {
|
||||
winType = JS_TO_NATIVE_WINDOW_TYPE_MAP.at(static_cast<ApiWindowType>(static_cast<uint32_t>(*type)));
|
||||
} else {
|
||||
WLOGFE("Do not surppot this type");
|
||||
WLOGFE("[NAPI]Type %{public}u is not supported", static_cast<uint32_t>(*type));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -152,18 +152,18 @@ static bool GetWindowTypeAndParentName(NativeEngine& engine, std::string& parent
|
||||
bool isOldApi = GetAPI7Ability(engine, ability);
|
||||
if (isOldApi) {
|
||||
if (ability == nullptr || !WindowHelper::IsSubWindow(winType)) {
|
||||
WLOGE("JsWindowManager FA mode GetAPI7Ability failed or type should be subWinodw!");
|
||||
WLOGE("[NAPI]FA mode GetAPI7Ability failed or type %{public}u is not subWinodw", winType);
|
||||
return false;
|
||||
}
|
||||
auto window = ability->GetWindow();
|
||||
if (window == nullptr) {
|
||||
WLOGE("JsWindowManager CheckJsWindowType in oldApi get mainWindow failed");
|
||||
WLOGE("[NAPI]Get mainWindow failed");
|
||||
return false;
|
||||
}
|
||||
parentName = window->GetWindowName();
|
||||
} else {
|
||||
if (!WindowHelper::IsSystemWindow(winType)) {
|
||||
WLOGFE("Only SystemWindow support create in stage mode!");
|
||||
WLOGFE("[NAPI]Only SystemWindow support create in stage mode, type is %{public}u", winType);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -173,13 +173,12 @@ static bool GetWindowTypeAndParentName(NativeEngine& engine, std::string& parent
|
||||
static void CreateSystemWindowTask(void* contextPtr, std::string windowName, WindowType winType,
|
||||
NativeEngine& engine, AsyncTask& task)
|
||||
{
|
||||
WLOGFI("JsWindowManager::CreateSystemWindowTask is called");
|
||||
WLOGFI("[NAPI]CreateSystemWindowTask");
|
||||
auto context = static_cast<std::weak_ptr<AbilityRuntime::Context>*>(contextPtr);
|
||||
if (contextPtr == nullptr || context == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR),
|
||||
"JsWindow::OnCreateWindow newAPI failed."));
|
||||
WLOGFE("JsWindowManager::OnCreateWindow in newApi use with empty context!");
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "Context is nullptr"));
|
||||
WLOGFE("[NAPI]Context is nullptr");
|
||||
return;
|
||||
}
|
||||
if (winType == WindowType::WINDOW_TYPE_FLOAT) {
|
||||
@@ -188,8 +187,7 @@ static void CreateSystemWindowTask(void* contextPtr, std::string windowName, Win
|
||||
if (!CheckCallingPermission("ohos.permission.SYSTEM_FLOAT_WINDOW")) {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(WMError::WM_ERROR_INVALID_PERMISSION),
|
||||
"JsWindow::OnCreateWindow newAPI failed."));
|
||||
WLOGFE("JsWindowManager::OnCreateWindow in newApi TYPE_FLOAT CheckCallingPermission failed!");
|
||||
"TYPE_FLOAT CheckCallingPermission failed"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -197,30 +195,30 @@ static void CreateSystemWindowTask(void* contextPtr, std::string windowName, Win
|
||||
sptr<WindowOption> windowOption = new(std::nothrow) WindowOption();
|
||||
if (windowOption == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnCreateWindow failed."));
|
||||
WLOGFE("JsWindowManager::OnCreateWindow windowOption malloc failed");
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "New window option failed"));
|
||||
WLOGFE("[NAPI]New window option failed");
|
||||
return;
|
||||
}
|
||||
windowOption->SetWindowType(winType);
|
||||
sptr<Window> window = Window::Create(windowName, windowOption, context->lock());
|
||||
if (window != nullptr) {
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window, false));
|
||||
WLOGFI("JsWindowManager::OnCreateWindow success");
|
||||
} else {
|
||||
WLOGFE("[NAPI]Create window failed");
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnCreateWindow failed."));
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "Create window failed"));
|
||||
}
|
||||
}
|
||||
|
||||
static void CreateSubWindowTask(std::string parentWinName, std::string windowName, WindowType winType,
|
||||
NativeEngine& engine, AsyncTask& task)
|
||||
{
|
||||
WLOGFI("JsWindowManager::CreateSubWindowTask is called");
|
||||
WLOGFI("[NAPI]CreateSubWindowTask, parent name = %{public}s", parentWinName.c_str());
|
||||
sptr<WindowOption> windowOption = new(std::nothrow) WindowOption();
|
||||
if (windowOption == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnCreateWindow failed."));
|
||||
WLOGFE("JsWindowManager::OnCreateWindow windowOption malloc failed");
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "New window option failed"));
|
||||
WLOGFE("[NAPI]New window option failed");
|
||||
return;
|
||||
}
|
||||
windowOption->SetWindowType(winType);
|
||||
@@ -229,16 +227,16 @@ static void CreateSubWindowTask(std::string parentWinName, std::string windowNam
|
||||
sptr<Window> window = Window::Create(windowName, windowOption);
|
||||
if (window != nullptr) {
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window, true));
|
||||
WLOGFI("JsWindowManager::OnCreateWindow success");
|
||||
} else {
|
||||
WLOGFE("[NAPI]Create window failed");
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnCreateWindow failed."));
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "Create window failed"));
|
||||
}
|
||||
}
|
||||
|
||||
NativeValue* JsWindowManager::OnCreateWindow(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowManager::OnCreateWindow is called");
|
||||
WLOGFI("[NAPI]OnCreateWindow");
|
||||
NativeValue* nativeString = nullptr;
|
||||
NativeValue* nativeContext = nullptr;
|
||||
NativeValue* nativeType = nullptr;
|
||||
@@ -260,7 +258,7 @@ NativeValue* JsWindowManager::OnCreateWindow(NativeEngine& engine, NativeCallbac
|
||||
std::string windowName;
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (!ConvertFromJsValue(engine, nativeString, windowName)) {
|
||||
WLOGFE("Failed to convert parameter to windowName");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to windowName");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
std::string parentName;
|
||||
@@ -271,10 +269,12 @@ NativeValue* JsWindowManager::OnCreateWindow(NativeEngine& engine, NativeCallbac
|
||||
}
|
||||
void* contextPtr = nullptr;
|
||||
GetNativeContext(nativeContext, contextPtr, errCode);
|
||||
|
||||
WLOGFI("[NAPI]Window name = %{public}s, type = %{public}u, err = %{public}d", windowName.c_str(), winType, errCode);
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params"));
|
||||
return;
|
||||
}
|
||||
if (parentName.empty()) {
|
||||
@@ -284,43 +284,45 @@ NativeValue* JsWindowManager::OnCreateWindow(NativeEngine& engine, NativeCallbac
|
||||
}
|
||||
};
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
engine, CreateAsyncTaskWithLastParam(engine, callback, nullptr, std::move(complete), &result));
|
||||
AsyncTask::Schedule(engine, CreateAsyncTaskWithLastParam(engine, callback, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* JsWindowManager::OnFindWindow(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowManager::JsOnFindWindow is called");
|
||||
WLOGFI("[NAPI]OnFindWindow");
|
||||
std::string windowName;
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("param not match!");
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
} else {
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], windowName)) {
|
||||
WLOGFE("Failed to convert parameter to windowName");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to windowName");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
}
|
||||
WLOGFI("[NAPI]Window name = %{public}s, err = %{public}d", windowName.c_str(), errCode);
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params"));
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<NativeReference> jsWindowObj = FindJsWindowObject(windowName);
|
||||
if (jsWindowObj != nullptr && jsWindowObj->Get() != nullptr) {
|
||||
WLOGFI("[NAPI]Find window: %{public}s, use exist js window", windowName.c_str());
|
||||
task.Resolve(engine, jsWindowObj->Get());
|
||||
WLOGFI("JsWindowManager::OnFindWindow success");
|
||||
} else {
|
||||
sptr<Window> window = Window::Find(windowName);
|
||||
if (window == nullptr) {
|
||||
WLOGFE("[NAPI]Cannot find window: %{public}s", windowName.c_str());
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnFindWindow failed."));
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "Cannot find window"));
|
||||
} else {
|
||||
AppExecFwk::Ability* ability = nullptr;
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window, GetAPI7Ability(engine, ability)));
|
||||
WLOGFI("[NAPI]Find window: %{public}s, create js window", windowName.c_str());
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -335,33 +337,32 @@ NativeValue* JsWindowManager::OnFindWindow(NativeEngine& engine, NativeCallbackI
|
||||
|
||||
NativeValue* JsWindowManager::OnMinimizeAll(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowManager::OnMinimizeAll is called");
|
||||
WLOGFI("[NAPI]OnMinimizeAll");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("param is too small!");
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
int64_t displayId = static_cast<int64_t>(DISPLAY_ID_INVALID);
|
||||
if (errCode == WMError::WM_OK && !ConvertFromJsValue(engine, info.argv[0], displayId)) {
|
||||
WLOGFE("Failed to convert parameter to displayId");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to displayId");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
if (displayId < 0 ||
|
||||
SingletonContainer::Get<DisplayManager>().GetDisplayById(static_cast<uint64_t>(displayId)) == nullptr) {
|
||||
WLOGFE("displayId is invalid");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
} else {
|
||||
WLOGFI("displayId %{public}" PRIu64"", static_cast<uint64_t>(displayId));
|
||||
}
|
||||
|
||||
WLOGFI("[NAPI]Display id = %{public}" PRIu64", err = %{public}d", static_cast<uint64_t>(displayId), errCode);
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params"));
|
||||
return;
|
||||
}
|
||||
SingletonContainer::Get<WindowManager>().MinimizeAllAppWindows(static_cast<uint64_t>(displayId));
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
WLOGFI("JsWindowManager::OnMinimizeAll success");
|
||||
WLOGFI("[NAPI]OnMinimizeAll success");
|
||||
};
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
@@ -373,50 +374,52 @@ NativeValue* JsWindowManager::OnMinimizeAll(NativeEngine& engine, NativeCallback
|
||||
|
||||
NativeValue* JsWindowManager::OnRegisterWindowMangerCallback(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowManager::OnRegisterWindowMangerCallback is called");
|
||||
WLOGFI("[NAPI]OnRegisterWindowMangerCallback");
|
||||
if (info.argc != 2) { // 2: params num
|
||||
WLOGFE("Params not match");
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::string cbType;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
WLOGFE("Failed to convert parameter to callbackType");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to callbackType");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeValue* value = info.argv[1];
|
||||
if (!value->IsCallable()) {
|
||||
WLOGFI("JsWindowManager::OnRegisterWindowMangerCallback info->argv[1] is not callable");
|
||||
WLOGFI("[NAPI]Callback(argv[1]) is not callable");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
registerManager_->RegisterListener(nullptr, cbType, CaseType::CASE_WINDOW_MANAGER, engine, value);
|
||||
WLOGFI("JsWindowManager::OnRegisterWindowMangerCallback end!");
|
||||
WLOGFI("[NAPI]Register end, type = %{public}s, callback = %{public}p", cbType.c_str(), value);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue* JsWindowManager::OnUnregisterWindowManagerCallback(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowManager::OnUnregisterWindowCallback is called");
|
||||
WLOGFI("[NAPI]OnUnregisterWindowManagerCallback");
|
||||
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("Params not match");
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
std::string cbType;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
|
||||
WLOGFE("Failed to convert parameter to callbackType");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to callbackType");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue* value = nullptr;
|
||||
if (info.argc == 1) {
|
||||
registerManager_->UnregisterListener(nullptr, cbType, CaseType::CASE_WINDOW_MANAGER, nullptr);
|
||||
registerManager_->UnregisterListener(nullptr, cbType, CaseType::CASE_WINDOW_MANAGER, value);
|
||||
} else {
|
||||
NativeValue* value = info.argv[1];
|
||||
value = info.argv[1];
|
||||
if (!value->IsCallable()) {
|
||||
WLOGFI("JsWindowManager::OnUnregisterWindowManagerCallback info->argv[1] is not callable");
|
||||
WLOGFI("[NAPI]Callback(argv[1]) is not callable");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
registerManager_->UnregisterListener(nullptr, cbType, CaseType::CASE_WINDOW_MANAGER, value);
|
||||
}
|
||||
WLOGFI("JsWindowManager::OnUnregisterWindowCallback end!");
|
||||
WLOGFI("[NAPI]Unregister end, type = %{public}s, callback = %{public}p", cbType.c_str(), value);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
@@ -426,10 +429,10 @@ static void GetTopWindowTask(void* contextPtr, bool isOldApi, NativeEngine& engi
|
||||
sptr<Window> window = nullptr;
|
||||
if (isOldApi) {
|
||||
AppExecFwk::Ability* ability = nullptr;
|
||||
if (!GetAPI7Ability(engine, ability)) {
|
||||
if (!GetAPI7Ability(engine, ability) || ability->GetWindow() == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "JsWindow::onGetTopWindow failed."));
|
||||
WLOGE("JsWindowManager get top windowfailed with null ability");
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "FA mode can not get ability window"));
|
||||
WLOGE("[NAPI]FA mode can not get ability window");
|
||||
return;
|
||||
}
|
||||
window = Window::GetTopWindowWithId(ability->GetWindow()->GetWindowId());
|
||||
@@ -437,17 +440,16 @@ static void GetTopWindowTask(void* contextPtr, bool isOldApi, NativeEngine& engi
|
||||
auto context = static_cast<std::weak_ptr<AbilityRuntime::Context>*>(contextPtr);
|
||||
if (contextPtr == nullptr || context == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR),
|
||||
"JsWindow::OnGetTopWindow newAPI failed."));
|
||||
WLOGFE("JsWindowManager::OnGetTopWindow in newApi use with empty context!");
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "Stage mode without context"));
|
||||
WLOGFE("[NAPI]Stage mode without context");
|
||||
return;
|
||||
}
|
||||
window = Window::GetTopWindowWithContext(context->lock());
|
||||
}
|
||||
if (window == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnGetTopWindow failed."));
|
||||
WLOGFE("JsWindowManager::OnGetTopWindow failed");
|
||||
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "Get top window failed"));
|
||||
WLOGFE("[NAPI]Get top window failed");
|
||||
return;
|
||||
}
|
||||
windowName = window->GetWindowName();
|
||||
@@ -457,20 +459,20 @@ static void GetTopWindowTask(void* contextPtr, bool isOldApi, NativeEngine& engi
|
||||
} else {
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window, isOldApi));
|
||||
}
|
||||
WLOGFI("JsWindowManager::OnGetTopWindow success");
|
||||
WLOGFI("[NAPI]Get top window %{public}s success", windowName.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
NativeValue* JsWindowManager::OnGetTopWindow(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowManager::OnGetTopWindow is called");
|
||||
WLOGFI("[NAPI]OnGetTopWindow");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
NativeValue* nativeContext = nullptr;
|
||||
NativeValue* nativeCallback = nullptr;
|
||||
void* contextPtr = nullptr;
|
||||
bool isOldApi = false;
|
||||
if (info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("param not match!");
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
} else {
|
||||
if (info.argc > 0 && info.argv[0]->TypeOf() == NATIVE_OBJECT) { // (context, callback?)
|
||||
@@ -486,10 +488,11 @@ NativeValue* JsWindowManager::OnGetTopWindow(NativeEngine& engine, NativeCallbac
|
||||
GetNativeContext(nativeContext, contextPtr, errCode);
|
||||
}
|
||||
|
||||
WLOGFI("[NAPI]Context %{public}p, FA mode %{public}u, err %{public}u", contextPtr, isOldApi, errCode);
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params"));
|
||||
return;
|
||||
}
|
||||
return GetTopWindowTask(contextPtr, isOldApi, engine, task);
|
||||
@@ -502,10 +505,10 @@ NativeValue* JsWindowManager::OnGetTopWindow(NativeEngine& engine, NativeCallbac
|
||||
|
||||
NativeValue* JsWindowManager::OnSetWindowLayoutMode(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowManager::OnSetWindowLayoutMode is called");
|
||||
WLOGFI("[NAPI]OnSetWindowLayoutMode");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
if (info.argc < 2 || info.argc > 3) { // 2: minimum params num; 3: maximum params num
|
||||
WLOGFE("JsWindowManager::OnSetWindowLayoutMode params too small");
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
WindowLayoutMode winLayoutMode = WindowLayoutMode::CASCADE;
|
||||
@@ -513,31 +516,33 @@ NativeValue* JsWindowManager::OnSetWindowLayoutMode(NativeEngine& engine, Native
|
||||
if (errCode == WMError::WM_OK) {
|
||||
NativeNumber* nativeMode = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
|
||||
if (nativeMode == nullptr) {
|
||||
WLOGFE("Failed to convert parameter to windowLayoutMode");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to windowLayoutMode");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
} else {
|
||||
winLayoutMode = static_cast<WindowLayoutMode>(static_cast<uint32_t>(*nativeMode));
|
||||
}
|
||||
|
||||
if (!ConvertFromJsValue(engine, info.argv[1], displayId)) {
|
||||
WLOGFE("Failed to convert parameter to displayId");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to displayId");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
WLOGFI("[NAPI]Display id = %{public}" PRIu64", LayoutMode = %{public}u, err = %{public}d",
|
||||
static_cast<uint64_t>(displayId), winLayoutMode, errCode);
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params"));
|
||||
return;
|
||||
}
|
||||
WMError ret = SingletonContainer::Get<WindowManager>().SetWindowLayoutMode(winLayoutMode,
|
||||
static_cast<uint64_t>(displayId));
|
||||
if (ret == WMError::WM_OK) {
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
WLOGFI("JsWindowManager::OnSetWindowLayoutMode success");
|
||||
WLOGFI("[NAPI]SetWindowLayoutMode success");
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "do failed"));
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "SetWindowLayoutMode failed"));
|
||||
}
|
||||
};
|
||||
// 2: maximum params num; 2: index of callback
|
||||
@@ -551,16 +556,16 @@ NativeValue* JsWindowManager::OnSetWindowLayoutMode(NativeEngine& engine, Native
|
||||
|
||||
NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
{
|
||||
WLOGFI("JsWindowManagerInit is called");
|
||||
WLOGFI("[NAPI]JsWindowManagerInit");
|
||||
|
||||
if (engine == nullptr || exportObj == nullptr) {
|
||||
WLOGFE("JsWindowManagerInit engine or exportObj is nullptr");
|
||||
WLOGFE("[NAPI]JsWindowManagerInit engine or exportObj is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(exportObj);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("JsWindowManagerInit object is nullptr");
|
||||
WLOGFE("[NAPI]JsWindowManagerInit object is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -581,4 +586,4 @@ NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
return engine->CreateUndefined();
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
} // namespace OHOS
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,14 +26,14 @@ constexpr uint32_t AVOID_AREA_NUM = 4;
|
||||
|
||||
void JsWindowListener::CallJsMethod(const char* methodName, NativeValue* const* argv, size_t argc)
|
||||
{
|
||||
WLOGFI("CallJsMethod methodName = %{public}s", methodName);
|
||||
WLOGFI("[NAPI]CallJsMethod methodName = %{public}s", methodName);
|
||||
if (engine_ == nullptr || jsCallBack_ == nullptr) {
|
||||
WLOGFE("engine_ nullptr or jsCallBack_ is nullptr");
|
||||
WLOGFE("[NAPI]engine_ nullptr or jsCallBack_ is nullptr");
|
||||
return;
|
||||
}
|
||||
NativeValue* method = jsCallBack_->Get();
|
||||
if (method == nullptr) {
|
||||
WLOGFE("Failed to get method callback from object");
|
||||
WLOGFE("[NAPI]Failed to get method callback from object");
|
||||
return;
|
||||
}
|
||||
engine_->CallFunction(engine_->CreateUndefined(), method, argv, argc);
|
||||
@@ -41,7 +41,7 @@ void JsWindowListener::CallJsMethod(const char* methodName, NativeValue* const*
|
||||
|
||||
void JsWindowListener::OnSizeChange(Rect rect, WindowSizeChangeReason reason)
|
||||
{
|
||||
WLOGFI("JsWindowListener::OnSizeChange is called");
|
||||
WLOGFI("[NAPI]OnSizeChange, wh[%{public}u, %{public}u], reason = %{public}u", rect.width_, rect.height_, reason);
|
||||
// js callback should run in js thread
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[this, rect] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
@@ -65,19 +65,19 @@ void JsWindowListener::OnSizeChange(Rect rect, WindowSizeChangeReason reason)
|
||||
|
||||
void JsWindowListener::OnModeChange(WindowMode mode)
|
||||
{
|
||||
WLOGFI("JsWindowListener::OnModeChange is called");
|
||||
WLOGFI("[NAPI]OnModeChange %{public}u", mode);
|
||||
}
|
||||
|
||||
void JsWindowListener::OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints)
|
||||
{
|
||||
WLOGFI("JsWindowListener::OnSystemBarPropertyChange is called");
|
||||
WLOGFI("[NAPI]OnSystemBarPropertyChange");
|
||||
// js callback should run in js thread
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[this, displayId, tints] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
NativeValue* propertyValue = engine_->CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(propertyValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to convert prop to jsObject");
|
||||
WLOGFE("[NAPI]Failed to convert prop to jsObject");
|
||||
return;
|
||||
}
|
||||
object->SetProperty("displayId", CreateJsValue(*engine_, static_cast<uint32_t>(displayId)));
|
||||
@@ -94,19 +94,19 @@ void JsWindowListener::OnSystemBarPropertyChange(DisplayId displayId, const Syst
|
||||
|
||||
void JsWindowListener::OnAvoidAreaChanged(const std::vector<Rect> avoidAreas)
|
||||
{
|
||||
WLOGFI("JsWindowListener::OnAvoidAreaChanged is called");
|
||||
WLOGFI("[NAPI]OnAvoidAreaChanged");
|
||||
// js callback should run in js thread
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[this, avoidAreas] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
NativeValue* avoidAreaValue = engine_->CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(avoidAreaValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("JsWindowListener::OnAvoidAreaChanged Failed to convert rect to jsObject");
|
||||
WLOGFE("[NAPI]Failed to convert rect to jsObject");
|
||||
return;
|
||||
}
|
||||
|
||||
if (static_cast<uint32_t>(avoidAreas.size()) != AVOID_AREA_NUM) {
|
||||
WLOGFE("AvoidAreas size is not 4 (left, top, right, bottom). Current avoidAreas size is %{public}u",
|
||||
WLOGFE("[NAPI]AvoidAreas size is not 4 (left, top, right, bottom), size is %{public}u",
|
||||
static_cast<uint32_t>(avoidAreas.size()));
|
||||
return;
|
||||
}
|
||||
@@ -127,7 +127,7 @@ void JsWindowListener::OnAvoidAreaChanged(const std::vector<Rect> avoidAreas)
|
||||
|
||||
void JsWindowListener::LifeCycleCallBack(LifeCycleEventType eventType)
|
||||
{
|
||||
WLOGFI("JsWindowListener::LifeCycleCallBack is called, type: %{public}d", eventType);
|
||||
WLOGFI("[NAPI]LifeCycleCallBack, envent type: %{public}u", eventType);
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback>(
|
||||
[=] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
NativeValue* argv[] = {CreateJsValue(*engine_, static_cast<uint32_t>(eventType))};
|
||||
@@ -159,4 +159,4 @@ void JsWindowListener::AfterUnfocused()
|
||||
LifeCycleCallBack(LifeCycleEventType::INACTIVE);
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -48,7 +48,7 @@ bool JsWindowRegisterManager::ProcessWindowChangeRegister(sptr<JsWindowListener>
|
||||
sptr<Window> window, bool isRegister)
|
||||
{
|
||||
if (window == nullptr) {
|
||||
WLOGFE("window is nullptr");
|
||||
WLOGFE("[NAPI]Window is nullptr");
|
||||
return false;
|
||||
}
|
||||
sptr<IWindowChangeListener> thisListener(listener);
|
||||
@@ -64,7 +64,7 @@ bool JsWindowRegisterManager::ProcessAvoidAreaChangeRegister(sptr<JsWindowListen
|
||||
sptr<Window> window, bool isRegister)
|
||||
{
|
||||
if (window == nullptr) {
|
||||
WLOGFE("window is nullptr");
|
||||
WLOGFE("[NAPI]Window is nullptr");
|
||||
return false;
|
||||
}
|
||||
sptr<IAvoidAreaChangedListener> thisListener(listener);
|
||||
@@ -80,7 +80,7 @@ bool JsWindowRegisterManager::ProcessLifeCycleEventRegister(sptr<JsWindowListene
|
||||
sptr<Window> window, bool isRegister)
|
||||
{
|
||||
if (window == nullptr) {
|
||||
WLOGFE("window is nullptr");
|
||||
WLOGFE("[NAPI]Window is nullptr");
|
||||
return false;
|
||||
}
|
||||
sptr<IWindowLifeCycle> thisListener(listener);
|
||||
@@ -107,13 +107,13 @@ bool JsWindowRegisterManager::ProcessSystemBarChangeRegister(sptr<JsWindowListen
|
||||
bool JsWindowRegisterManager::IsCallbackRegistered(std::string type, NativeValue* jsListenerObject)
|
||||
{
|
||||
if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
|
||||
WLOGFI("JsWindowRegisterManager::IsCallbackRegistered methodName %{public}s not registerted!", type.c_str());
|
||||
WLOGFI("[NAPI]Method %{public}s has not been registerted", type.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto iter = jsCbMap_[type].begin(); iter != jsCbMap_[type].end(); ++iter) {
|
||||
if (jsListenerObject->StrictEquals(iter->first->Get())) {
|
||||
WLOGFE("JsWindowRegisterManager::IsCallbackRegistered %{public}s already registered!", type.c_str());
|
||||
WLOGFE("[NAPI]Method %{public}s has already been registered", type.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -128,23 +128,23 @@ void JsWindowRegisterManager::RegisterListener(sptr<Window> window, std::string
|
||||
return;
|
||||
}
|
||||
if (listenerProcess_[caseType].count(type) == 0) {
|
||||
WLOGFE("JsWindowRegisterManager not support method: %{public}s!", type.c_str());
|
||||
WLOGFE("[NAPI]Type %{public}s is not supported", type.c_str());
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<NativeReference> callbackRef;
|
||||
callbackRef.reset(engine.CreateReference(value, 1));
|
||||
sptr<JsWindowListener> windowManagerListener = new(std::nothrow) JsWindowListener(&engine, callbackRef);
|
||||
if (windowManagerListener == nullptr) {
|
||||
WLOGFE("JsWindowRegisterManager::RegisterListener malloc failed");
|
||||
WLOGFE("[NAPI]New JsWindowListener failed");
|
||||
return;
|
||||
}
|
||||
if (!((this->*listenerProcess_[caseType][type])(windowManagerListener, window, true))) {
|
||||
WLOGFE("JsWindowRegisterManager::RegisterListener %{public}s failed!", type.c_str());
|
||||
WLOGFE("[NAPI]Register type %{public}s failed", type.c_str());
|
||||
return;
|
||||
}
|
||||
jsCbMap_[type][callbackRef] = windowManagerListener;
|
||||
WLOGFI("JsWindowRegisterManager::RegisterListener %{public}s success! callback map size: %{public}lu",
|
||||
type.c_str(), (unsigned long)jsCbMap_[type].size());
|
||||
WLOGFI("[NAPI]Register type %{public}s success! callback map size: %{public}zu",
|
||||
type.c_str(), jsCbMap_[type].size());
|
||||
}
|
||||
|
||||
void JsWindowRegisterManager::UnregisterListener(sptr<Window> window, std::string type,
|
||||
@@ -152,18 +152,17 @@ void JsWindowRegisterManager::UnregisterListener(sptr<Window> window, std::strin
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_);
|
||||
if (jsCbMap_.empty() || jsCbMap_.find(type) == jsCbMap_.end()) {
|
||||
WLOGFI("JsWindowRegisterManager::UnregisterListener methodName %{public}s not registerted!",
|
||||
type.c_str());
|
||||
WLOGFE("[NAPI]Type %{public}s was not registerted", type.c_str());
|
||||
return;
|
||||
}
|
||||
if (listenerProcess_[caseType].count(type) == 0) {
|
||||
WLOGFE("JsWindowRegisterManager not support method: %{public}s!", type.c_str());
|
||||
WLOGFE("[NAPI]Type %{public}s is not supported", type.c_str());
|
||||
return;
|
||||
}
|
||||
if (value == nullptr) {
|
||||
for (auto it = jsCbMap_[type].begin(); it != jsCbMap_[type].end();) {
|
||||
if (!((this->*listenerProcess_[caseType][type])(it->second, window, false))) {
|
||||
WLOGFE("JsWindowRegisterManager::UnregisterListener %{public}s failed!", type.c_str());
|
||||
WLOGFE("[NAPI]Unregister type %{public}s failed, no value", type.c_str());
|
||||
return;
|
||||
}
|
||||
jsCbMap_[type].erase(it++);
|
||||
@@ -176,24 +175,23 @@ void JsWindowRegisterManager::UnregisterListener(sptr<Window> window, std::strin
|
||||
}
|
||||
findFlag = true;
|
||||
if (!(this->*listenerProcess_[caseType][type])(it->second, window, false)) {
|
||||
WLOGFE("JsWindowRegisterManager::UnregisterListener %{public}s failed!", type.c_str());
|
||||
WLOGFE("[NAPI]Unregister type %{public}s failed", type.c_str());
|
||||
return;
|
||||
}
|
||||
jsCbMap_[type].erase(it);
|
||||
break;
|
||||
}
|
||||
if (!findFlag) {
|
||||
WLOGFE("JsWindowRegisterManager::UnregisterListener %{public}s failed because not found callback!",
|
||||
type.c_str());
|
||||
WLOGFE("[NAPI]Unregister type %{public}s failed because not found callback!", type.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
WLOGFI("JsWindowRegisterManager::UnregisterListener %{public}s success! callback map size: %{public}lu",
|
||||
type.c_str(), (unsigned long)jsCbMap_[type].size());
|
||||
WLOGFI("[NAPI]Unregister type %{public}s success! callback map size: %{public}zu",
|
||||
type.c_str(), jsCbMap_[type].size());
|
||||
// erase type when there is no callback in one type
|
||||
if (jsCbMap_[type].empty()) {
|
||||
jsCbMap_.erase(type);
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -30,18 +30,17 @@ namespace {
|
||||
|
||||
NativeValue* WindowTypeInit(NativeEngine* engine)
|
||||
{
|
||||
WLOGFI("WindowTypeInit");
|
||||
WLOGFI("[NAPI]WindowTypeInit");
|
||||
|
||||
if (engine == nullptr) {
|
||||
WLOGFE("Invalid input parameters");
|
||||
WLOGFE("[NAPI]Engine is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *objValue = engine->CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to get object");
|
||||
WLOGFE("[NAPI]Failed to get object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -68,18 +67,17 @@ NativeValue* WindowTypeInit(NativeEngine* engine)
|
||||
|
||||
NativeValue* AvoidAreaTypeInit(NativeEngine* engine)
|
||||
{
|
||||
WLOGFI("AvoidAreaTypeInit");
|
||||
WLOGFI("[NAPI]AvoidAreaTypeInit");
|
||||
|
||||
if (engine == nullptr) {
|
||||
WLOGFE("Invalid input parameters");
|
||||
WLOGFE("[NAPI]Engine is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *objValue = engine->CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to get object");
|
||||
WLOGFE("[NAPI]Failed to get object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -92,18 +90,17 @@ NativeValue* AvoidAreaTypeInit(NativeEngine* engine)
|
||||
|
||||
NativeValue* WindowModeInit(NativeEngine* engine)
|
||||
{
|
||||
WLOGFI("WindowModeInit");
|
||||
WLOGFI("[NAPI]WindowModeInit");
|
||||
|
||||
if (engine == nullptr) {
|
||||
WLOGFE("Invalid input parameters");
|
||||
WLOGFE("[NAPI]Engine is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *objValue = engine->CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to get object");
|
||||
WLOGFE("[NAPI]Failed to get object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -122,18 +119,17 @@ NativeValue* WindowModeInit(NativeEngine* engine)
|
||||
|
||||
NativeValue* ColorSpaceInit(NativeEngine* engine)
|
||||
{
|
||||
WLOGFI("ColorSpaceInit");
|
||||
WLOGFI("[NAPI]ColorSpaceInit");
|
||||
|
||||
if (engine == nullptr) {
|
||||
WLOGFE("Invalid input parameters");
|
||||
WLOGFE("[NAPI]Engine is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *objValue = engine->CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to get object");
|
||||
WLOGFE("[NAPI]Failed to get object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -146,18 +142,17 @@ NativeValue* ColorSpaceInit(NativeEngine* engine)
|
||||
|
||||
NativeValue* WindowStageEventTypeInit(NativeEngine* engine)
|
||||
{
|
||||
WLOGFI("WindowStageEventTypeInit");
|
||||
WLOGFI("[NAPI]WindowStageEventTypeInit");
|
||||
|
||||
if (engine == nullptr) {
|
||||
WLOGFE("Invalid input parameters");
|
||||
WLOGFE("[NAPI]Engine is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *objValue = engine->CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to get object");
|
||||
WLOGFE("[NAPI]Failed to get object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -177,7 +172,7 @@ NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect rect)
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to convert rect to jsObject");
|
||||
WLOGFE("[NAPI]Failed to convert rect to jsObject");
|
||||
return nullptr;
|
||||
}
|
||||
object->SetProperty("left", CreateJsValue(engine, rect.posX_));
|
||||
@@ -189,18 +184,18 @@ NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect rect)
|
||||
|
||||
NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr<Window>& window)
|
||||
{
|
||||
WLOGFI("JsWindowUtils::CreateJsWindowPropertiesObject is called");
|
||||
WLOGFI("[NAPI]CreateJsWindowPropertiesObject");
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to convert windowProperties to jsObject");
|
||||
WLOGFE("[NAPI]Failed to convert windowProperties to jsObject");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Rect rect = window->GetRect();
|
||||
NativeValue* rectObj = GetRectAndConvertToJsValue(engine, rect);
|
||||
if (rectObj == nullptr) {
|
||||
WLOGFE("GetRect failed!");
|
||||
WLOGFE("[NAPI]GetRect failed!");
|
||||
}
|
||||
object->SetProperty("windowRect", rectObj);
|
||||
WindowType type = window->GetType();
|
||||
@@ -232,39 +227,37 @@ static std::string GetHexColor(uint32_t color)
|
||||
|
||||
static NativeValue* CreateJsSystemBarRegionTintObject(NativeEngine& engine, const SystemBarRegionTint& tint)
|
||||
{
|
||||
WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject is called");
|
||||
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to convert SystemBarProperty to jsObject");
|
||||
WLOGFE("[NAPI]Failed to convert SystemBarProperty to jsObject");
|
||||
return nullptr;
|
||||
}
|
||||
object->SetProperty("type", CreateJsValue(engine, static_cast<uint32_t>(tint.type_)));
|
||||
object->SetProperty("isEnable", CreateJsValue(engine, tint.prop_.enable_));
|
||||
std::string bkgColor = GetHexColor(tint.prop_.backgroundColor_);
|
||||
WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject backgroundColir: %{public}s", bkgColor.c_str());
|
||||
object->SetProperty("backgroundColor", CreateJsValue(engine, bkgColor));
|
||||
std::string contentColor = GetHexColor(tint.prop_.contentColor_);
|
||||
WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject contentColor: %{public}s", contentColor.c_str());
|
||||
object->SetProperty("contentColor", CreateJsValue(engine, contentColor));
|
||||
Rect rect = tint.region_;
|
||||
object->SetProperty("region", GetRectAndConvertToJsValue(engine, rect));
|
||||
WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintObject rect: [%{public}d %{public}d %{public}d %{public}d]",
|
||||
|
||||
WLOGFI("[NAPI]Type %{public}u [%{public}u %{public}s %{public}s] [%{public}d %{public}d %{public}u %{public}u]",
|
||||
tint.type_, tint.prop_.enable_, bkgColor.c_str(), contentColor.c_str(),
|
||||
rect.posX_, rect.posY_, rect.width_, rect.height_);
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeValue* CreateJsSystemBarRegionTintArrayObject(NativeEngine& engine, const SystemBarRegionTints& tints)
|
||||
{
|
||||
WLOGFI("JsWindowUtils::CreateJsSystemBarRegionTintArrayObject is called");
|
||||
if (tints.empty()) {
|
||||
WLOGFE("[NAPI]Empty tints");
|
||||
return nullptr;
|
||||
}
|
||||
NativeValue* objValue = engine.CreateArray(tints.size());
|
||||
NativeArray* array = ConvertNativeValueTo<NativeArray>(objValue);
|
||||
if (array == nullptr) {
|
||||
WLOGFE("Failed to convert SystemBarPropertys to jsArrayObject");
|
||||
WLOGFE("[NAPI]Failed to convert SystemBarPropertys to jsArrayObject");
|
||||
return nullptr;
|
||||
}
|
||||
uint32_t index = 0;
|
||||
@@ -279,7 +272,7 @@ bool GetSystemBarStatus(std::map<WindowType, SystemBarProperty>& systemBarProper
|
||||
{
|
||||
NativeArray* nativeArray = ConvertNativeValueTo<NativeArray>(info.argv[0]);
|
||||
if (nativeArray == nullptr) {
|
||||
WLOGFE("Failed to convert parameter to SystemBarArray");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to SystemBarArray");
|
||||
return false;
|
||||
}
|
||||
uint32_t size = nativeArray->GetLength();
|
||||
@@ -292,7 +285,7 @@ bool GetSystemBarStatus(std::map<WindowType, SystemBarProperty>& systemBarProper
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
std::string name;
|
||||
if (!ConvertFromJsValue(engine, nativeArray->GetElement(i), name)) {
|
||||
WLOGFE("Failed to convert parameter to SystemBarName");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to SystemBarName");
|
||||
return false;
|
||||
}
|
||||
if (name.compare("status") == 0) {
|
||||
@@ -311,12 +304,12 @@ static uint32_t GetColorFromJs(NativeEngine& engine, NativeObject* jsObject,
|
||||
if (jsColor->TypeOf() != NATIVE_UNDEFINED) {
|
||||
std::string colorStr;
|
||||
if (!ConvertFromJsValue(engine, jsColor, colorStr)) {
|
||||
WLOGFE("Failed to convert parameter to color");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to color");
|
||||
return defaultColor;
|
||||
}
|
||||
std::regex pattern("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$");
|
||||
if (!std::regex_match(colorStr, pattern)) {
|
||||
WLOGFE("invalid color input");
|
||||
WLOGFE("[NAPI]Invalid color input");
|
||||
return defaultColor;
|
||||
}
|
||||
WLOGFI("origin color: %{public}s", colorStr.c_str());
|
||||
@@ -328,7 +321,8 @@ static uint32_t GetColorFromJs(NativeEngine& engine, NativeObject* jsObject,
|
||||
uint32_t hexColor;
|
||||
ss << std::hex << color;
|
||||
ss >> hexColor;
|
||||
WLOGFI("color: %{public}s, Final Color is %{public}x", color.c_str(), hexColor);
|
||||
WLOGFI("[NAPI]Origin %{public}s, process %{public}s, final %{public}x",
|
||||
colorStr.c_str(), color.c_str(), hexColor);
|
||||
return hexColor;
|
||||
}
|
||||
return defaultColor;
|
||||
@@ -353,7 +347,7 @@ bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject,
|
||||
} else if (jsStatusIcon->TypeOf() != NATIVE_UNDEFINED) {
|
||||
bool isStatusBarLightIcon;
|
||||
if (!ConvertFromJsValue(engine, jsStatusIcon, isStatusBarLightIcon)) {
|
||||
WLOGFE("Failed to convert parameter to isStatusBarLightIcon");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to isStatusBarLightIcon");
|
||||
return false;
|
||||
}
|
||||
if (isStatusBarLightIcon) {
|
||||
@@ -370,7 +364,7 @@ bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject,
|
||||
} else if (jsNavigationIcon->TypeOf() != NATIVE_UNDEFINED) {
|
||||
bool isNavigationBarLightIcon;
|
||||
if (!ConvertFromJsValue(engine, jsNavigationIcon, isNavigationBarLightIcon)) {
|
||||
WLOGFE("Failed to convert parameter to isNavigationBarLightIcon");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to isNavigationBarLightIcon");
|
||||
return false;
|
||||
}
|
||||
if (isNavigationBarLightIcon) {
|
||||
@@ -387,7 +381,7 @@ NativeValue* ChangeAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avo
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to convert rect to jsObject");
|
||||
WLOGFE("[NAPI]Failed to convert rect to jsObject");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
object->SetProperty("leftRect", GetRectAndConvertToJsValue(engine, avoidArea.leftRect));
|
||||
@@ -399,15 +393,14 @@ NativeValue* ChangeAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avo
|
||||
|
||||
bool CheckCallingPermission(std::string permission)
|
||||
{
|
||||
WLOGFI("JsWindowUtils::CheckCallingPermission, permission:%{public}s", permission.c_str());
|
||||
WLOGFI("[NAPI]Permission: %{public}s", permission.c_str());
|
||||
if (!permission.empty() &&
|
||||
Security::AccessToken::AccessTokenKit::VerifyAccessToken(IPCSkeleton::GetCallingTokenID(), permission)
|
||||
!= AppExecFwk::Constants::PERMISSION_GRANTED) {
|
||||
WLOGFE("%{public}s permission not granted.", permission.c_str());
|
||||
WLOGFE("[NAPI]Permission %{public}s is not granted", permission.c_str());
|
||||
return false;
|
||||
}
|
||||
WLOGFI("JsWindowUtils::CheckCallingPermission end.");
|
||||
return true;
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -39,116 +39,112 @@ JsWindowStage::~JsWindowStage()
|
||||
}
|
||||
void JsWindowStage::Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
WLOGFI("JsWindowStage::Finalizer is called");
|
||||
WLOGFI("[NAPI]Finalizer");
|
||||
std::unique_ptr<JsWindowStage>(static_cast<JsWindowStage*>(data));
|
||||
}
|
||||
|
||||
NativeValue* JsWindowStage::SetUIContent(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::SetUIContent is called");
|
||||
WLOGFI("[NAPI]SetUIContent");
|
||||
JsWindowStage* me = CheckParamsAndGetThis<JsWindowStage>(engine, info);
|
||||
return (me != nullptr) ? me->OnSetUIContent(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindowStage::GetMainWindow(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::GetMainWindow is called");
|
||||
WLOGFI("[NAPI]GetMainWindow");
|
||||
JsWindowStage* me = CheckParamsAndGetThis<JsWindowStage>(engine, info);
|
||||
return (me != nullptr) ? me->OnGetMainWindow(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindowStage::On(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::On is called");
|
||||
WLOGFI("[NAPI]On");
|
||||
JsWindowStage* me = CheckParamsAndGetThis<JsWindowStage>(engine, info);
|
||||
return (me != nullptr) ? me->OnEvent(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindowStage::Off(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::Off is called");
|
||||
WLOGFI("[NAPI]Off");
|
||||
JsWindowStage* me = CheckParamsAndGetThis<JsWindowStage>(engine, info);
|
||||
return (me != nullptr) ? me->OffEvent(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindowStage::LoadContent(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::LoadContent is called");
|
||||
WLOGFI("[NAPI]LoadContent");
|
||||
JsWindowStage* me = CheckParamsAndGetThis<JsWindowStage>(engine, info);
|
||||
return (me != nullptr) ? me->OnLoadContent(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindowStage::GetWindowMode(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::GetWindowMode is called");
|
||||
WLOGFI("[NAPI]GetWindowMode");
|
||||
JsWindowStage* me = CheckParamsAndGetThis<JsWindowStage>(engine, info);
|
||||
return (me != nullptr) ? me->OnGetWindowMode(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindowStage::CreateSubWindow(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::CreateSubWindow is called");
|
||||
WLOGFI("[NAPI]CreateSubWindow");
|
||||
JsWindowStage* me = CheckParamsAndGetThis<JsWindowStage>(engine, info);
|
||||
return (me != nullptr) ? me->OnCreateSubWindow(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindowStage::GetSubWindow(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::GetSubWindow is called");
|
||||
WLOGFI("[NAPI]GetSubWindow");
|
||||
JsWindowStage* me = CheckParamsAndGetThis<JsWindowStage>(engine, info);
|
||||
return (me != nullptr) ? me->OnGetSubWindow(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindowStage::OnSetUIContent(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::OnSetUIContent is called");
|
||||
if (info.argc < 2) { // 2: minimum param num
|
||||
WLOGFE("JsWindowStage::OnSetUIContent Not enough params");
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (windowScene_ == nullptr || windowScene_->GetMainWindow() == nullptr) {
|
||||
WLOGFE("JsWindowStage::OnSetUIContent windowScene_ or MainWindow is nullptr");
|
||||
WLOGFE("[NAPI]WindowScene is null or window is null");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
// Parse info->argv[0] as abilitycontext
|
||||
auto objContext = ConvertNativeValueTo<NativeObject>(info.argv[0]);
|
||||
if (objContext == nullptr) {
|
||||
WLOGFE("JsWindowStage::OnSetUIContent info->argv[0] InValid");
|
||||
WLOGFE("[NAPI]Context is nullptr");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
// Parse info->argv[1] as url
|
||||
std::string contextUrl;
|
||||
if (!ConvertFromJsValue(engine, info.argv[1], contextUrl)) {
|
||||
WLOGFE("JsWindowStage::OnSetUIContent failed to convert parameter to url");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to url");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
WLOGFI("JsWindowStage::OnSetUIContent Get url");
|
||||
|
||||
windowScene_->GetMainWindow()->SetUIContent(contextUrl, &engine, info.argv[CONTENT_STORAGE_ARG]);
|
||||
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue* JsWindowStage::OnGetMainWindow(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::OnGetMainWindow is called");
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (windowScene_ == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
WLOGFE("JsWindowStage windowScene_ is nullptr!");
|
||||
WLOGFE("[NAPI]WindowScene_ is nullptr!");
|
||||
return;
|
||||
}
|
||||
auto window = windowScene_->GetMainWindow();
|
||||
if (window != nullptr) {
|
||||
task.Resolve(engine, OHOS::Rosen::CreateJsWindowObject(engine, window, false));
|
||||
WLOGFI("JsWindowStage::OnGetMainWindow success");
|
||||
WLOGFI("[NAPI]Get main window [%{public}u, %{public}s]",
|
||||
window->GetWindowId(), window->GetWindowName().c_str());
|
||||
} else {
|
||||
task.Reject(engine, CreateJsError(engine,
|
||||
static_cast<int32_t>(Rosen::WMError::WM_ERROR_NULLPTR),
|
||||
"JsWindowStage::OnGetMainWindow failed."));
|
||||
"Get main window failed."));
|
||||
}
|
||||
};
|
||||
NativeValue* callback = (info.argv[0]->TypeOf() == NATIVE_FUNCTION) ? info.argv[0] : nullptr;
|
||||
@@ -160,76 +156,77 @@ NativeValue* JsWindowStage::OnGetMainWindow(NativeEngine& engine, NativeCallback
|
||||
|
||||
NativeValue* JsWindowStage::OnEvent(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::OnEvent is called");
|
||||
if (windowScene_ == nullptr || info.argc < 2) { // 2: minimum param nums
|
||||
WLOGFE("JsWindowStage::OnEvent windowScene_ is nullptr or params not match");
|
||||
WLOGFE("[NAPI]Window scene is null or argc is invalid: %{public}zu", info.argc);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
// Parse info->argv[0] as string
|
||||
std::string eventString;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], eventString)) {
|
||||
WLOGFE("JsWindowStage::OnEvent info->argv[0] Failed to convert parameter to string");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to string");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeValue* value = info.argv[1];
|
||||
if (!value->IsCallable()) {
|
||||
WLOGFE("JsWindowStage::OnEvent info->argv[1] is not callable");
|
||||
WLOGFE("[NAPI]Callback(info->argv[1]) is not callable");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
auto window = windowScene_->GetMainWindow();
|
||||
if (window == nullptr) {
|
||||
WLOGFE("JsWindowStage::OnEvent GetMainWindow failed");
|
||||
WLOGFE("[NAPI]Get window failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
g_listenerManager->RegisterListener(window, eventString, CaseType::CASE_STAGE, engine, value);
|
||||
WLOGFI("[NAPI]Window [%{public}u, %{public}s] register event %{public}s, callback %{public}p",
|
||||
window->GetWindowId(), window->GetWindowName().c_str(), eventString.c_str(), value);
|
||||
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue* JsWindowStage::OffEvent(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::OffEvent is called");
|
||||
if (windowScene_ == nullptr) {
|
||||
WLOGFE("JsWindowStage::OffEvent windowScene_ is nullptr");
|
||||
WLOGFE("[NAPI]Window scene is null");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
// Parse info->argv[0] as string
|
||||
std::string eventString;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], eventString)) {
|
||||
WLOGFE("JsWindowStage::OffEvent info->argv[0] Failed to convert parameter to string");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to string");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (eventString.compare("windowStageEvent") != 0) {
|
||||
WLOGFE("JsWindowStage::OffEvent info->argv[0] is InValid");
|
||||
WLOGFE("[NAPI]Envent %{public}s is invalid", eventString.c_str());
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue* value = info.argv[1];
|
||||
auto window = windowScene_->GetMainWindow();
|
||||
if (window == nullptr) {
|
||||
WLOGFE("JsWindowStage::OnEvent GetMainWindow failed");
|
||||
WLOGFE("[NAPI]Get window failed");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (value->TypeOf() == NATIVE_FUNCTION) {
|
||||
WLOGFI("JsWindowStage::OffEvent info->argv[1] is callable type");
|
||||
g_listenerManager->UnregisterListener(window, eventString, CaseType::CASE_STAGE, value);
|
||||
} else if (value->TypeOf() == NativeValueType::NATIVE_UNDEFINED) {
|
||||
WLOGFI("JsWindowStage::OffEvent info->argv[1] is native undefined type");
|
||||
g_listenerManager->UnregisterListener(window, eventString, CaseType::CASE_STAGE, nullptr);
|
||||
} else {
|
||||
WLOGFE("JsWindowStage::OffEvent info->argv[1] is InValid param");
|
||||
WLOGFE("[NAPI]Callback(info->argv[1]) is invalid");
|
||||
}
|
||||
WLOGFI("[NAPI]Window [%{public}u, %{public}s] unregister event %{public}s, callback %{public}p",
|
||||
window->GetWindowId(), window->GetWindowName().c_str(), eventString.c_str(), value);
|
||||
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::OnLoadContent is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
std::string contextUrl;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], contextUrl)) {
|
||||
WLOGFE("Failed to convert parameter to context url");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to context url");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
NativeValue* storage = nullptr;
|
||||
@@ -250,12 +247,13 @@ NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackIn
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (windowScene_ == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
WLOGFE("JsWindowStage windowScene_ is nullptr!");
|
||||
WLOGFE("[NAPI]windowScene_ is nullptr");
|
||||
return;
|
||||
}
|
||||
auto win = windowScene_->GetMainWindow();
|
||||
if (win == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
WLOGFE("[NAPI]Get window failed");
|
||||
return;
|
||||
}
|
||||
NativeValue* nativeStorage = (contentStorage == nullptr) ? nullptr : contentStorage->Get();
|
||||
@@ -265,7 +263,8 @@ NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackIn
|
||||
return;
|
||||
}
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
WLOGFI("JsWindowStage::OnLoadContent success");
|
||||
WLOGFI("[NAPI]Window [%{public}u, %{public}s] load content %{public}s, storage %{public}p",
|
||||
win->GetWindowId(), win->GetWindowName().c_str(), contextUrl.c_str(), nativeStorage);
|
||||
};
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule(
|
||||
@@ -275,28 +274,29 @@ NativeValue* JsWindowStage::OnLoadContent(NativeEngine& engine, NativeCallbackIn
|
||||
|
||||
NativeValue* JsWindowStage::OnGetWindowMode(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::OnGetWindowMode is called");
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (windowScene_ == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
WLOGFE("JsWindowStage windowScene_ is nullptr!");
|
||||
WLOGFE("[NAPI]windowScene_ is nullptr");
|
||||
return;
|
||||
}
|
||||
auto window = windowScene_->GetMainWindow();
|
||||
if (window == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(Rosen::WMError::WM_ERROR_NULLPTR),
|
||||
"JsWindowStage::OnGetWindowMode failed."));
|
||||
WLOGFE("JsWindowStage window is nullptr");
|
||||
"Get window failed"));
|
||||
WLOGFE("[NAPI]Get window failed");
|
||||
return;
|
||||
}
|
||||
Rosen::WindowMode mode = window->GetMode();
|
||||
if (NATIVE_TO_JS_WINDOW_MODE_MAP.count(mode) != 0) {
|
||||
task.Resolve(engine, CreateJsValue(engine, NATIVE_TO_JS_WINDOW_MODE_MAP.at(mode)));
|
||||
WLOGFI("JsWindowStage OnGetWindowMode success");
|
||||
WLOGFI("[NAPI]Window [%{public}u, %{public}s] get mode %{public}u, api mode %{public}u",
|
||||
window->GetWindowId(), window->GetWindowName().c_str(),
|
||||
mode, NATIVE_TO_JS_WINDOW_MODE_MAP.at(mode));
|
||||
} else {
|
||||
task.Resolve(engine, CreateJsValue(engine, mode));
|
||||
WLOGFI("JsWindowStage OnGetWindowMode success, but not in apimode");
|
||||
WLOGFE("[NAPI]Get mode %{public}u, but not in apimode", mode);
|
||||
}
|
||||
};
|
||||
NativeValue* callback = (info.argv[0]->TypeOf() == NATIVE_FUNCTION) ? info.argv[0] : nullptr;
|
||||
@@ -308,18 +308,17 @@ NativeValue* JsWindowStage::OnGetWindowMode(NativeEngine& engine, NativeCallback
|
||||
|
||||
NativeValue* JsWindowStage::OnCreateSubWindow(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::OnCreateSubWindow is called");
|
||||
WMError errCode = WMError::WM_OK;
|
||||
std::string windowName;
|
||||
if (!ConvertFromJsValue(engine, info.argv[0], windowName)) {
|
||||
WLOGFE("Failed to convert parameter to windowName");
|
||||
WLOGFE("[NAPI]Failed to convert parameter to windowName");
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (windowScene_ == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode)));
|
||||
WLOGFE("JsWindowStage windowScene_ is nullptr or invaliad params!");
|
||||
WLOGFE("[NAPI]Window scene is null or get invalid param");
|
||||
return;
|
||||
}
|
||||
sptr<Rosen::WindowOption> windowOption = new Rosen::WindowOption();
|
||||
@@ -328,12 +327,12 @@ NativeValue* JsWindowStage::OnCreateSubWindow(NativeEngine& engine, NativeCallba
|
||||
auto window = windowScene_->CreateWindow(windowName, windowOption);
|
||||
if (window == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(Rosen::WMError::WM_ERROR_NULLPTR),
|
||||
"JsWindowStage::OnCreateSubWindow failed."));
|
||||
WLOGFE("JsWindowStage window is nullptr");
|
||||
"Get window failed"));
|
||||
WLOGFE("[NAPI]Get window failed");
|
||||
return;
|
||||
}
|
||||
task.Resolve(engine, CreateJsWindowObject(engine, window, false));
|
||||
WLOGFI("JsWindowStage OnCreateSubWindow success");
|
||||
WLOGFI("[NAPI]Create sub widdow %{public}s end", windowName.c_str());
|
||||
};
|
||||
NativeValue* callback = (info.argv[1]->TypeOf() == NATIVE_FUNCTION) ? info.argv[1] : nullptr;
|
||||
NativeValue* result = nullptr;
|
||||
@@ -345,11 +344,10 @@ NativeValue* JsWindowStage::OnCreateSubWindow(NativeEngine& engine, NativeCallba
|
||||
NativeValue* JsWindowStage::CreateJsSubWindowArrayObject(NativeEngine& engine,
|
||||
std::vector<sptr<Window>> subWinVec)
|
||||
{
|
||||
WLOGFI("JsWindowUtils::CreateJsSubWindowArrayObject is called");
|
||||
NativeValue* objValue = engine.CreateArray(subWinVec.size());
|
||||
NativeArray* array = ConvertNativeValueTo<NativeArray>(objValue);
|
||||
if (array == nullptr) {
|
||||
WLOGFE("Failed to convert subWinVec to jsArrayObject");
|
||||
WLOGFE("[NAPI]Failed to convert subWinVec to jsArrayObject");
|
||||
return nullptr;
|
||||
}
|
||||
uint32_t index = 0;
|
||||
@@ -361,17 +359,16 @@ NativeValue* JsWindowStage::CreateJsSubWindowArrayObject(NativeEngine& engine,
|
||||
|
||||
NativeValue* JsWindowStage::OnGetSubWindow(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsWindowStage::OnGetSubWindow is called");
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (windowScene_ == nullptr) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(WMError::WM_ERROR_NULLPTR)));
|
||||
WLOGFE("JsWindowStage windowScene_ is nullptr!");
|
||||
WLOGFE("[NAPI]Window scene is nullptr");
|
||||
return;
|
||||
}
|
||||
std::vector<sptr<Window>> subWindowVec = windowScene_->GetSubWindow();
|
||||
task.Resolve(engine, CreateJsSubWindowArrayObject(engine, subWindowVec));
|
||||
WLOGFI("JsWindowStage OnGetSubWindow success");
|
||||
WLOGFI("[NAPI]Get sub windows, size = %{public}zu", subWindowVec.size());
|
||||
};
|
||||
NativeValue* callback = (info.argv[0]->TypeOf() == NATIVE_FUNCTION) ? info.argv[0] : nullptr;
|
||||
NativeValue* result = nullptr;
|
||||
@@ -383,7 +380,7 @@ NativeValue* JsWindowStage::OnGetSubWindow(NativeEngine& engine, NativeCallbackI
|
||||
NativeValue* CreateJsWindowStage(NativeEngine& engine,
|
||||
std::shared_ptr<Rosen::WindowScene> windowScene)
|
||||
{
|
||||
WLOGFI("JsWindowStage::CreateJsWindowStage is called");
|
||||
WLOGFI("[NAPI]CreateJsWindowStage");
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user