1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "inputmethod_extension.h"
17
18 #include "ability_loader.h"
19 #include "connection_manager.h"
20 #include "global.h"
21 #include "inputmethod_extension_context.h"
22 #include "js_inputmethod_extension.h"
23 #include "runtime.h"
24
25 namespace OHOS {
26 namespace AbilityRuntime {
27 using namespace OHOS::AppExecFwk;
Create(const std::unique_ptr<Runtime> & runtime)28 InputMethodExtension *InputMethodExtension::Create(const std::unique_ptr<Runtime> &runtime)
29 {
30 IMSA_HILOGI("InputMethodExtension::Create runtime");
31 if (runtime == nullptr) {
32 return new InputMethodExtension();
33 }
34 switch (runtime->GetLanguage()) {
35 case Runtime::Language::JS:
36 return JsInputMethodExtension::Create(runtime);
37 default:
38 return new InputMethodExtension();
39 }
40 }
41
Init(const std::shared_ptr<AbilityLocalRecord> & record,const std::shared_ptr<OHOSApplication> & application,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token)42 void InputMethodExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
43 const std::shared_ptr<OHOSApplication> &application, std::shared_ptr<AbilityHandler> &handler,
44 const sptr<IRemoteObject> &token)
45 {
46 IMSA_HILOGI("InputMethodExtension init context");
47 ExtensionBase<InputMethodExtensionContext>::Init(record, application, handler, token);
48 }
49
CreateAndInitContext(const std::shared_ptr<AbilityLocalRecord> & record,const std::shared_ptr<OHOSApplication> & application,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token)50 std::shared_ptr<InputMethodExtensionContext> InputMethodExtension::CreateAndInitContext(
51 const std::shared_ptr<AbilityLocalRecord> &record, const std::shared_ptr<OHOSApplication> &application,
52 std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token)
53 {
54 IMSA_HILOGI("InputMethodExtension CreateAndInitContext");
55 std::shared_ptr<InputMethodExtensionContext> context =
56 ExtensionBase<InputMethodExtensionContext>::CreateAndInitContext(record, application, handler, token);
57 if (context == nullptr) {
58 IMSA_HILOGE("InputMethodExtension::CreateAndInitContext context is nullptr");
59 return context;
60 }
61 return context;
62 }
63 } // namespace AbilityRuntime
64 } // namespace OHOS