diff --git a/bundle.json b/bundle.json index c22d7134..fbc57c0e 100644 --- a/bundle.json +++ b/bundle.json @@ -52,7 +52,7 @@ "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/extension/extension_connection:libwindow_extension_client", - "//foundation/windowmanager/extension/window_extension:libwindow_exteinsion", + "//foundation/windowmanager/extension/window_extension:libwindow_extension", "//foundation/windowmanager/extension/window_extension:window_extension_module", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", diff --git a/extension/extension_connection/BUILD.gn b/extension/extension_connection/BUILD.gn index 18f99799..97c6333b 100644 --- a/extension/extension_connection/BUILD.gn +++ b/extension/extension_connection/BUILD.gn @@ -44,7 +44,7 @@ ohos_shared_library("libwindow_extension_client") { "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", "//foundation/windowmanager/wm:libwm", - "//foundation/windowmanager/extension/window_extension:libwindow_exteinsion", + "//foundation/windowmanager/extension/window_extension:libwindow_extension", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", ] diff --git a/extension/extension_connection/include/window_extension_client_stub_impl.h b/extension/extension_connection/include/window_extension_client_stub_impl.h index 955b1c79..64c6b92b 100644 --- a/extension/extension_connection/include/window_extension_client_stub_impl.h +++ b/extension/extension_connection/include/window_extension_client_stub_impl.h @@ -24,7 +24,7 @@ namespace Rosen { class WindowExtensionClientStubImpl : public WindowExtensionClientStub { public: explicit WindowExtensionClientStubImpl(sptr& componentCallback) - : componentCallback_(componentCallback) {}; + : componentCallback_(componentCallback) {}; ~WindowExtensionClientStubImpl() = default; void OnWindowReady(std::shared_ptr& surfaceNode) override; diff --git a/extension/extension_connection/src/window_extension_client_proxy.cpp b/extension/extension_connection/src/window_extension_client_proxy.cpp index f893b07c..3f6ba8a4 100644 --- a/extension/extension_connection/src/window_extension_client_proxy.cpp +++ b/extension/extension_connection/src/window_extension_client_proxy.cpp @@ -73,7 +73,7 @@ void WindowExtensionClientProxy::OnKeyEvent(std::shared_ptr& keyE return; } - if (!keyEvent->WriteToParcel(data)) { + if (!keyEvent->WriteToParcel(data)) { WLOGFE("write key event failed"); return; } diff --git a/extension/extension_connection/src/window_extension_connection.cpp b/extension/extension_connection/src/window_extension_connection.cpp index 8ef67de1..44dfc2de 100644 --- a/extension/extension_connection/src/window_extension_connection.cpp +++ b/extension/extension_connection/src/window_extension_connection.cpp @@ -31,8 +31,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowExtensionConnection"}; } -class WindowExtensionConnection::Impl - : public AAFwk::AbilityConnectionStub { +class WindowExtensionConnection::Impl : public AAFwk::AbilityConnectionStub { public: Impl() = default; ~Impl() = default; @@ -68,7 +67,8 @@ WindowExtensionConnection::WindowExtensionConnection() { } -WindowExtensionConnection::Impl::WindowExtensionClientRecipient::WindowExtensionClientRecipient(sptr callback) +WindowExtensionConnection::Impl::WindowExtensionClientRecipient::WindowExtensionClientRecipient( + sptr callback) { callback_ = callback; } @@ -93,7 +93,7 @@ void WindowExtensionConnection::Impl::WindowExtensionClientRecipient::OnRemoteDi WLOGFI("Remote died"); } void WindowExtensionConnection::Impl::ConnectExtension(const AppExecFwk::ElementName &element, Rect rect, - uint32_t uid, sptr& callback) + uint32_t uid, sptr& callback) { AAFwk::Want want; want.SetElement(element); @@ -140,7 +140,7 @@ void WindowExtensionConnection::Impl::RequestFocus() } void WindowExtensionConnection::Impl::OnAbilityConnectDone(const AppExecFwk::ElementName &element, - const sptr &remoteObject, int resultCode) + const sptr &remoteObject, int resultCode) { if (!remoteObject) { WLOGFE("remote object is null"); @@ -178,7 +178,7 @@ void WindowExtensionConnection::Impl::OnAbilityDisconnectDone(const AppExecFwk:: // WindowExtensionConnection void WindowExtensionConnection::ConnectExtension(const AppExecFwk::ElementName &element, Rect rect, - uint32_t uid, sptr& callback) + uint32_t uid, sptr& callback) { pImpl_->ConnectExtension(element, rect, uid, callback); } diff --git a/extension/window_extension/BUILD.gn b/extension/window_extension/BUILD.gn index d9df3d43..b81bd3e3 100644 --- a/extension/window_extension/BUILD.gn +++ b/extension/window_extension/BUILD.gn @@ -13,7 +13,7 @@ import("//build/ohos.gni") -config("libwindow_exteinsion_private_config") { +config("libwindow_extension_private_config") { visibility = [ ":*" ] include_dirs = [ @@ -21,19 +21,21 @@ config("libwindow_exteinsion_private_config") { "include/zidl", "../extension_connection/include", "../extension_connection/include/zidl", + "../../interfaces/kits/napi/window_runtime/window_napi", "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", + "//foundation/aafwk/standard/interfaces/innerkits/runtime/include", ] } -config("libwindow_exteinsion_public_config") { +config("libwindow_extension_public_config") { include_dirs = [ "../../interfaces/innerkits/wm", "../../utils/include", ] } -## Build libwindow_exteinsion.so -ohos_shared_library("libwindow_exteinsion") { +## Build libwindow_extension.so +ohos_shared_library("libwindow_extension") { sources = [ "../extension_connection/src/window_extension_client_proxy.cpp", "src/js_window_extension_context.cpp", @@ -43,12 +45,13 @@ ohos_shared_library("libwindow_exteinsion") { "src/window_extension.cpp", ] - configs = [ ":libwindow_exteinsion_private_config" ] + configs = [ ":libwindow_extension_private_config" ] - public_configs = [ ":libwindow_exteinsion_public_config" ] + public_configs = [ ":libwindow_extension_public_config" ] deps = [ "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/windowmanager/interfaces/kits/napi/window_runtime:window_native_kit", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/utils:libwmutil", ] @@ -63,6 +66,7 @@ ohos_shared_library("libwindow_exteinsion") { "graphic_standard:surface", "hilog_native:libhilog", "input:libmmi-client", + "utils_base:utils", ] part_name = "window_manager" @@ -84,7 +88,7 @@ ohos_shared_library("window_extension_module") { configs = [ ":window_extension_module_private_config" ] deps = [ - "//foundation/windowmanager/extension/window_extension:libwindow_exteinsion", + "//foundation/windowmanager/extension/window_extension:libwindow_extension", ] external_deps = [ diff --git a/extension/window_extension/include/js_window_extension.h b/extension/window_extension/include/js_window_extension.h index 384f3816..72d772dc 100644 --- a/extension/window_extension/include/js_window_extension.h +++ b/extension/window_extension/include/js_window_extension.h @@ -82,8 +82,9 @@ public: virtual void OnStart(const AAFwk::Want &want) override; private: void GetSrcPath(std::string &srcPath); + NativeValue* CallJsMethod(const char* name, NativeValue* const* argv = nullptr, size_t argc = 0); + void OnWindowCreated(); - //sptr extensionToken_; // TODO IWindowExtensionClient下沉到window_extension AbilityRuntime::JsRuntime& jsRuntime_; std::unique_ptr jsObj_; std::shared_ptr shellContextRef_; diff --git a/extension/window_extension/include/window_extension_stub_impl.h b/extension/window_extension/include/window_extension_stub_impl.h index dc9851ad..3c44fc88 100644 --- a/extension/window_extension/include/window_extension_stub_impl.h +++ b/extension/window_extension/include/window_extension_stub_impl.h @@ -36,7 +36,9 @@ public: virtual void RequestFocus() override; virtual void ConnectToExtension(sptr& token) override; - std::shared_ptr CreateWindow(Rect& rect); + sptr CreateWindow(Rect& rect, const std::shared_ptr& context); + void DestroyWindow(); + sptr GetWindow() const; private: sptr dispatchInputEventListener_; diff --git a/extension/window_extension/src/js_window_extension.cpp b/extension/window_extension/src/js_window_extension.cpp index aa0c399a..2e9985b0 100644 --- a/extension/window_extension/src/js_window_extension.cpp +++ b/extension/window_extension/src/js_window_extension.cpp @@ -18,7 +18,9 @@ #include #include #include +#include +#include "js_window.h" #include "js_window_extension_context.h" #include "window_extension_connection.h" #include "window_manager_hilog.h" @@ -115,11 +117,11 @@ void JsWindowExtension::Init(const std::shared_ptr &record, void JsWindowExtension::GetSrcPath(std::string &srcPath) { if (!Extension::abilityInfo_) { - HILOG_ERROR("abilityInfo_ is nullptr"); + WLOGFE("abilityInfo_ is nullptr"); return; } - if (!Extension::abilityInfo_->isModuleJson) { + if (!Extension::abilityInfo_->isModuleJson) { srcPath.append(Extension::abilityInfo_->package); srcPath.append("/assets/js/"); if (!Extension::abilityInfo_->srcPath.empty()) { @@ -142,10 +144,6 @@ sptr JsWindowExtension::OnConnect(const AAFwk::Want &want) WLOGFI("called."); Extension::OnConnect(want); - ElementName elementName = want.GetElement(); // TODO 为何之前是GetElementName()? - std::string windowName = elementName.GetBundleName(); - - stub_ = new(std::nothrow) WindowExtensionStubImpl(windowName); if (!stub_) { WLOGFE("stub is nullptr."); return nullptr; @@ -163,14 +161,84 @@ void JsWindowExtension::OnDisconnect(const AAFwk::Want &want) void JsWindowExtension::OnStart(const AAFwk::Want &want) { Extension::OnStart(want); + + ElementName elementName = want.GetElement(); // TODO 为何之前是GetElementName()? + std::string windowName = elementName.GetBundleName(); + + stub_ = new(std::nothrow)WindowExtensionStubImpl(windowName); WLOGFI("JsWindowExtension OnStart begin.."); Rect rect { want.GetIntParam(RECT_FORM_KEY_POS_X, 0), want.GetIntParam(RECT_FORM_KEY_POS_Y, 0), want.GetIntParam(RECT_FORM_KEY_WIDTH, 0), want.GetIntParam(RECT_FORM_KEY_HEIGHT, 0) }; - // stub_->CreateWindow(rect); - WLOGFI(" create window rect x =%{public}d y=%{public}d w=%{public}d h=%{public}d ", - rect.posX_, rect.posY_, rect.width_, rect.height_); + if (stub_ != nullptr) { + auto context = GetContext(); + if (context == nullptr) { + WLOGFE("get context failed"); + return; + } + sptr window = stub_->CreateWindow(rect, context); + if (window == nullptr) { + WLOGFE("create window failed"); + return; + } + OnWindowCreated(); + WLOGFI("ability context onWindowReady rect x =%{public}d y=%{public}d w=%{public}d h=%{public}d ", + rect.posX_, rect.posY_, rect.width_, rect.height_); + } +} + +void JsWindowExtension::OnWindowCreated() +{ + NativeEngine& engine = jsRuntime_.GetNativeEngine(); + std::unique_ptr complete = std::make_unique( + [=] (NativeEngine &engine, AsyncTask &task, int32_t status) { + auto window = stub_->GetWindow(); + if (window == nullptr) { + WLOGFE("get window failed"); + return; + } + NativeValue* value = CreateJsWindowObject(engine, window, false); + if (value == nullptr) { + WLOGFE("Create js window failed"); + return; + } + NativeValue* argv[] = { value }; + CallJsMethod("onWindowReady", argv, ArraySize(argv)); + } + ); + + NativeReference* callback = nullptr; + std::unique_ptr execute = nullptr; + AsyncTask::Schedule(engine, std::make_unique(callback, std::move(execute), std::move(complete))); +} + +NativeValue* JsWindowExtension::CallJsMethod(const char* name, NativeValue* const* argv, size_t argc) +{ + WLOGFI("called (%{public}s), begin", name); + + if (!jsObj_) { + WLOGFW("Not found ServiceExtension.js"); + return nullptr; + } + + HandleScope handleScope(jsRuntime_); + auto& nativeEngine = jsRuntime_.GetNativeEngine(); + + NativeValue* value = jsObj_->Get(); + NativeObject* obj = ConvertNativeValueTo(value); + if (obj == nullptr) { + WLOGFE("Failed to get ServiceExtension object"); + return nullptr; + } + + NativeValue* method = obj->GetProperty(name); + if (method == nullptr || method->TypeOf() != NATIVE_FUNCTION) { + WLOGFE("Failed to get '%{public}s' from ServiceExtension object", name); + return nullptr; + } + WLOGFI("(%{public}s), success", name); + return nativeEngine.CallFunction(value, method, argv, argc); } } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/extension/window_extension/src/js_window_extension_context.cpp b/extension/window_extension/src/js_window_extension_context.cpp index f088a73e..e22e20f7 100644 --- a/extension/window_extension/src/js_window_extension_context.cpp +++ b/extension/window_extension/src/js_window_extension_context.cpp @@ -59,7 +59,7 @@ void JsWindowConnectCallback::OnAbilityDisconnectDone(const AppExecFwk::ElementN } NativeValue* CreateJsWindowExtensionContext(NativeEngine& engine, - std::shared_ptr context) + std::shared_ptr context) { WLOGFI("CreateJsWindowExtensionContext begin"); NativeValue* objValue = CreateJsExtensionContext(engine, context); // TODO CreateJsBaseContext? diff --git a/extension/window_extension/src/window_extension_stub_impl.cpp b/extension/window_extension/src/window_extension_stub_impl.cpp index 01d7415b..72fd3bea 100644 --- a/extension/window_extension/src/window_extension_stub_impl.cpp +++ b/extension/window_extension/src/window_extension_stub_impl.cpp @@ -38,26 +38,21 @@ WindowExtensionStubImpl::~WindowExtensionStubImpl() } } -std::shared_ptr WindowExtensionStubImpl::CreateWindow(Rect& rect) +sptr WindowExtensionStubImpl::CreateWindow(Rect& rect, + const std::shared_ptr& context) { - // WLOGFI("call start windowName_ %{public}s", windowName_.c_str()); sptr option = new (std::nothrow)WindowOption(); if (option == nullptr) { WLOGFE("Get option failed"); return nullptr; } - option->SetWindowType(WindowType::WINDOW_TYPE_APP_COMPONENT); - option->SetWindowMode(OHOS::Rosen::WindowMode::WINDOW_MODE_FLOATING); - option->SetWindowRect(rect); - WLOGFI("create window"); - window_ = Window::Create(windowName_, option, nullptr); - if (window_ == nullptr) { - WLOGFE("create window failed"); - return nullptr; - } - WLOGFI("call end"); - return nullptr; //window_->GetSurfaceNode(); + option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + option->SetWindowMode(OHOS::Rosen::WindowMode::WINDOW_MODE_FULLSCREEN); + // option->SetWindowRect(rect); + WLOGFI("Window::Create"); + window_ = Window::Create(windowName_, option, context); + return window_; } void WindowExtensionStubImpl::Resize(Rect rect) @@ -91,8 +86,12 @@ void WindowExtensionStubImpl::RequestFocus() void WindowExtensionStubImpl::ConnectToExtension(sptr& token) { token_ = token; - token_->OnBackPress(); WLOGFI("called"); } + +sptr WindowExtensionStubImpl::GetWindow() const +{ + return window_; +} } // namespace Rosen } // namespace OHOS \ No newline at end of file