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 "print_extension.h"
17
18 #include "ability_loader.h"
19 #include "connection_manager.h"
20 #include "js_print_extension.h"
21 #include "print_extension_context.h"
22 #include "print_log.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 PrintExtension *PrintExtension::Create(const std::unique_ptr<Runtime> &runtime)
29 {
30 PRINT_HILOGD("jws PrintExtension::Create runtime");
31 if (!runtime) {
32 return new PrintExtension();
33 }
34 PRINT_HILOGD("jws PrintExtension::Create runtime");
35 switch (runtime->GetLanguage()) {
36 case Runtime::Language::JS:
37 return JsPrintExtension::Create(runtime);
38
39 default:
40 return new PrintExtension();
41 }
42 }
43
Init(const std::shared_ptr<AbilityLocalRecord> & record,const std::shared_ptr<OHOSApplication> & application,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token)44 void PrintExtension::Init(const std::shared_ptr<AbilityLocalRecord> &record,
45 const std::shared_ptr<OHOSApplication> &application, std::shared_ptr<AbilityHandler> &handler,
46 const sptr<IRemoteObject> &token)
47 {
48 PRINT_HILOGD("jws PrintExtension begin init context");
49 ExtensionBase<PrintExtensionContext>::Init(record, application, handler, token);
50 PRINT_HILOGD("PrintExtension begin init context");
51 }
52
CreateAndInitContext(const std::shared_ptr<AbilityLocalRecord> & record,const std::shared_ptr<OHOSApplication> & application,std::shared_ptr<AbilityHandler> & handler,const sptr<IRemoteObject> & token)53 std::shared_ptr<PrintExtensionContext> PrintExtension::CreateAndInitContext(
54 const std::shared_ptr<AbilityLocalRecord> &record, const std::shared_ptr<OHOSApplication> &application,
55 std::shared_ptr<AbilityHandler> &handler, const sptr<IRemoteObject> &token)
56 {
57 PRINT_HILOGD("jws PrintExtension begin init context");
58 std::shared_ptr<PrintExtensionContext> context =
59 ExtensionBase<PrintExtensionContext>::CreateAndInitContext(record, application, handler, token);
60 if (context == nullptr) {
61 PRINT_HILOGE("PrintExtension::CreateAndInitContext context is nullptr");
62 return context;
63 }
64 return context;
65 }
66
OnStop()67 void PrintExtension::OnStop()
68 {
69 Extension::OnStop();
70 GetContext()->TerminateAbility();
71 }
72 } // namespace AbilityRuntime
73 } // namespace OHOS