diff --git a/extension/extension_connection/src/window_extension_connection.cpp b/extension/extension_connection/src/window_extension_connection.cpp index faebd31b..638e4f27 100644 --- a/extension/extension_connection/src/window_extension_connection.cpp +++ b/extension/extension_connection/src/window_extension_connection.cpp @@ -113,7 +113,7 @@ int WindowExtensionConnection::Impl::ConnectExtension(const AppExecFwk::ElementN want.SetParam(RECT_FORM_KEY_WIDTH, static_cast(rect.width_)); want.SetParam(RECT_FORM_KEY_HEIGHT, static_cast(rect.height_)); // 100 default userId - auto ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, this, nullptr, 100); + auto ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, this, nullptr, uid); if (ret == ERR_OK) { componentCallback_ = callback; } diff --git a/extension/window_extension/src/js_window_extension.cpp b/extension/window_extension/src/js_window_extension.cpp index cc3cde91..07cba700 100644 --- a/extension/window_extension/src/js_window_extension.cpp +++ b/extension/window_extension/src/js_window_extension.cpp @@ -189,6 +189,12 @@ void JsWindowExtension::OnDisconnect(const AAFwk::Want& want) std::unique_ptr execute = nullptr; AbilityRuntime::AsyncTask::Schedule("JsWindowExtension::OnDisconnect", engine, std::make_unique(callback, std::move(execute), std::move(complete))); + + auto window = stub_ != nullptr ? stub_->GetWindow() : nullptr; + if (window != nullptr) { + window->Destroy(); + WLOGFI("Destroy window."); + } WLOGFI("called."); } diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn index d738b430..e1deb24b 100644 --- a/interfaces/kits/napi/BUILD.gn +++ b/interfaces/kits/napi/BUILD.gn @@ -20,7 +20,7 @@ group("napi_packages") { "screen_recorder:screenrecorder_napi", "screen_runtime:screen_napi", "screenshot:screenshot", - "window_extension:windowextension_napi", + "window_extension_ability:windowextensionability_napi", "window_extension_context:windowextensioncontext_napi", "window_runtime:window_napi", "window_runtime:window_native_kit", diff --git a/interfaces/kits/napi/window_extension/BUILD.gn b/interfaces/kits/napi/window_extension/BUILD.gn deleted file mode 100644 index 3a3b02f7..00000000 --- a/interfaces/kits/napi/window_extension/BUILD.gn +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (c) 2022-2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//ark/ts2abc/ts2panda/ts2abc_config.gni") -import("//build/ohos.gni") - -ts2abc_gen_abc("gen_window_extension_abc") { - src_js = rebase_path("window_extension.js") - dst_file = rebase_path(target_out_dir + "/window_extension.abc") - in_puts = [ "window_extension.js" ] - out_puts = [ target_out_dir + "/window_extension.abc" ] - extra_args = [ "--module" ] -} - -gen_js_obj("window_extension_js") { - input = "window_extension.js" - output = target_out_dir + "/window_extension.o" -} - -gen_js_obj("window_extension_abc") { - input = get_label_info(":gen_window_extension_abc", "target_out_dir") + - "/window_extension.abc" - output = target_out_dir + "/window_extension_abc.o" - dep = ":gen_window_extension_abc" -} - -ohos_shared_library("windowextension_napi") { - sources = [ "window_extension_module.cpp" ] - - deps = [ - ":window_extension_abc", - ":window_extension_js", - ] - - external_deps = [ "napi:ace_napi" ] - - relative_install_dir = "module/application" - subsystem_name = "window" - part_name = "window_manager" -} diff --git a/interfaces/kits/napi/window_extension/window_extension_module.cpp b/interfaces/kits/napi/window_extension/window_extension_module.cpp deleted file mode 100644 index 71a23c4c..00000000 --- a/interfaces/kits/napi/window_extension/window_extension_module.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2022-2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -extern const char _binary_window_extension_js_start[]; -extern const char _binary_window_extension_js_end[]; -extern const char _binary_window_extension_abc_start[]; -extern const char _binary_window_extension_abc_end[]; - -extern "C" __attribute__((constructor)) -void NAPI_application_WindowExtension_AutoRegister() -{ - auto moduleManager = NativeModuleManager::GetInstance(); - NativeModule newModuleInfo = { - .name = "application.WindowExtension", - .fileName = "application/libwindowextension_napi.so/WindowExtension.js", - }; - - moduleManager->Register(&newModuleInfo); -} - -extern "C" __attribute__((visibility("default"))) -void NAPI_application_WindowExtension_GetJSCode(const char **buf, int *bufLen) -{ - if (buf != nullptr) { - *buf = _binary_window_extension_js_start; - } - - if (bufLen != nullptr) { - *bufLen = _binary_window_extension_js_end - _binary_window_extension_js_start; - } -} - -// window_extension JS register -extern "C" __attribute__((visibility("default"))) -void NAPI_application_WindowExtension_GetABCCode(const char **buf, int *buflen) -{ - if (buf != nullptr) { - *buf = _binary_window_extension_abc_start; - } - if (buflen != nullptr) { - *buflen = _binary_window_extension_abc_end - _binary_window_extension_abc_start; - } -} \ No newline at end of file diff --git a/interfaces/kits/napi/window_extension_ability/BUILD.gn b/interfaces/kits/napi/window_extension_ability/BUILD.gn new file mode 100644 index 00000000..cadf1e1b --- /dev/null +++ b/interfaces/kits/napi/window_extension_ability/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/ts2abc/ts2panda/ts2abc_config.gni") +import("//build/ohos.gni") + +ts2abc_gen_abc("gen_window_extension_ability_abc") { + src_js = rebase_path("window_extension_ability.js") + dst_file = rebase_path(target_out_dir + "/window_extension_ability.abc") + in_puts = [ "window_extension_ability.js" ] + out_puts = [ target_out_dir + "/window_extension_ability.abc" ] + extra_args = [ "--module" ] +} + +gen_js_obj("window_extension_ability_js") { + input = "window_extension_ability.js" + output = target_out_dir + "/window_extension_ability.o" +} + +gen_js_obj("window_extension_ability_abc") { + input = get_label_info(":gen_window_extension_ability_abc", + "target_out_dir") + "/window_extension_ability.abc" + output = target_out_dir + "/window_extension_ability_abc.o" + dep = ":gen_window_extension_ability_abc" +} + +ohos_shared_library("windowextensionability_napi") { + sources = [ "window_extension_ability_module.cpp" ] + + deps = [ + ":window_extension_ability_abc", + ":window_extension_ability_js", + ] + + external_deps = [ "napi:ace_napi" ] + + relative_install_dir = "module/application" + subsystem_name = "window" + part_name = "window_manager" +} diff --git a/interfaces/kits/napi/window_extension/window_extension.js b/interfaces/kits/napi/window_extension_ability/window_extension_ability.js similarity index 85% rename from interfaces/kits/napi/window_extension/window_extension.js rename to interfaces/kits/napi/window_extension_ability/window_extension_ability.js index fd338977..29fd9328 100644 --- a/interfaces/kits/napi/window_extension/window_extension.js +++ b/interfaces/kits/napi/window_extension_ability/window_extension_ability.js @@ -1,30 +1,30 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -class WindowExtension { - onWindowReady(window) { - console.log('WindowExtension windowReady'); - } - - onConnect(want) { - console.log('WindowExtension onConnect, want:' + want.abilityName); - } - - onDisconnect(want) { - console.log('WindowExtension onDisconnect' + want.abilityName); - } -} - -export default WindowExtension \ No newline at end of file +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class WindowExtensionAbility { + onWindowReady(window) { + console.log('WindowExtension windowReady'); + } + + onConnect(want) { + console.log('WindowExtension onConnect, want:' + want.abilityName); + } + + onDisconnect(want) { + console.log('WindowExtension onDisconnect' + want.abilityName); + } +} + +export default WindowExtensionAbility \ No newline at end of file diff --git a/interfaces/kits/napi/window_extension_ability/window_extension_ability_module.cpp b/interfaces/kits/napi/window_extension_ability/window_extension_ability_module.cpp new file mode 100644 index 00000000..8625522e --- /dev/null +++ b/interfaces/kits/napi/window_extension_ability/window_extension_ability_module.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "native_engine/native_engine.h" + +extern const char _binary_window_extension_ability_js_start[]; +extern const char _binary_window_extension_ability_js_end[]; +extern const char _binary_window_extension_ability_abc_start[]; +extern const char _binary_window_extension_ability_abc_end[]; + +extern "C" __attribute__((constructor)) +void NAPI_application_WindowExtensionAbility_AutoRegister() +{ + auto moduleManager = NativeModuleManager::GetInstance(); + NativeModule newModuleInfo = { + .name = "application.WindowExtensionAbility", + .fileName = "application/libwindowextensionability_napi.so/window_extension_ability.js", + }; + + moduleManager->Register(&newModuleInfo); +} + +extern "C" __attribute__((visibility("default"))) +void NAPI_application_WindowExtensionAbility_GetJSCode(const char **buf, int *bufLen) +{ + if (buf != nullptr) { + *buf = _binary_window_extension_ability_js_start; + } + + if (bufLen != nullptr) { + *bufLen = _binary_window_extension_ability_js_end - _binary_window_extension_ability_js_start; + } +} + +extern "C" __attribute__((visibility("default"))) +void NAPI_application_WindowExtensionAbility_GetABCCode(const char **buf, int *buflen) +{ + if (buf != nullptr) { + *buf = _binary_window_extension_ability_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_window_extension_ability_abc_end - _binary_window_extension_ability_abc_start; + } +} \ No newline at end of file