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 "accessibility_extension.h"
17 #include "accessibility_extension_context.h"
18 #include "ability_local_record.h"
19 #include "hilog_wrapper.h"
20 #include "js_accessibility_extension.h"
21
22 namespace OHOS {
23 namespace Accessibility {
Create(const std::unique_ptr<AbilityRuntime::Runtime> & runtime)24 AccessibilityExtension* AccessibilityExtension::Create(const std::unique_ptr<AbilityRuntime::Runtime>& runtime)
25 {
26 if (!runtime) {
27 return new AccessibilityExtension();
28 }
29 HILOG_INFO("AccessibilityExtension::Create runtime");
30 switch (runtime->GetLanguage()) {
31 case AbilityRuntime::Runtime::Language::JS:
32 return JsAccessibilityExtension::Create(runtime);
33
34 default:
35 return new AccessibilityExtension();
36 }
37 }
38
Init(const std::shared_ptr<AbilityRuntime::AbilityLocalRecord> & record,const std::shared_ptr<AbilityRuntime::OHOSApplication> & application,std::shared_ptr<AbilityRuntime::AbilityHandler> & handler,const sptr<IRemoteObject> & token)39 void AccessibilityExtension::Init(const std::shared_ptr<AbilityRuntime::AbilityLocalRecord> &record,
40 const std::shared_ptr<AbilityRuntime::OHOSApplication> &application,
41 std::shared_ptr<AbilityRuntime::AbilityHandler> &handler,
42 const sptr<IRemoteObject> &token)
43 {
44 ExtensionBase<AccessibilityExtensionContext>::Init(record, application, handler, token);
45 HILOG_INFO("AccessibilityExtension begin init");
46 }
47
CreateAndInitContext(const std::shared_ptr<AbilityRuntime::AbilityLocalRecord> & record,const std::shared_ptr<AbilityRuntime::OHOSApplication> & application,std::shared_ptr<AbilityRuntime::AbilityHandler> & handler,const sptr<IRemoteObject> & token)48 std::shared_ptr<AccessibilityExtensionContext> AccessibilityExtension::CreateAndInitContext(
49 const std::shared_ptr<AbilityRuntime::AbilityLocalRecord> &record,
50 const std::shared_ptr<AbilityRuntime::OHOSApplication> &application,
51 std::shared_ptr<AbilityRuntime::AbilityHandler> &handler,
52 const sptr<IRemoteObject> &token)
53 {
54 std::shared_ptr<AccessibilityExtensionContext> context =
55 ExtensionBase<AccessibilityExtensionContext>::CreateAndInitContext(record, application, handler, token);
56 if (!record) {
57 HILOG_ERROR("AccessibilityExtension::CreateAndInitContext record is nullptr");
58 }
59 return context;
60 }
61 } // namespace Accessibility
62 } // namespace OHOS