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 "js_uri_perm_mgr.h"
17
18 #include "hilog_wrapper.h"
19 #include "js_error_utils.h"
20 #include "js_runtime_utils.h"
21 #include "uri.h"
22 #include "uri_permission_manager_client.h"
23
24 namespace OHOS {
25 namespace AbilityRuntime {
26 class JsUriPermMgr {
27 public:
28 JsUriPermMgr() = default;
29 ~JsUriPermMgr() = default;
30
Finalizer(NativeEngine * engine,void * data,void * hint)31 static void Finalizer(NativeEngine* engine, void* data, void* hint)
32 {
33 HILOG_INFO("JsUriPermMgr::Finalizer is called");
34 std::unique_ptr<JsUriPermMgr>(static_cast<JsUriPermMgr*>(data));
35 }
36 };
37
CreateJsUriPermMgr(NativeEngine * engine,NativeValue * exportObj)38 NativeValue* CreateJsUriPermMgr(NativeEngine* engine, NativeValue* exportObj)
39 {
40 HILOG_INFO("CreateJsUriPermMgr is called");
41 if (engine == nullptr || exportObj == nullptr) {
42 HILOG_INFO("Invalid input parameters");
43 return nullptr;
44 }
45
46 NativeObject* object = ConvertNativeValueTo<NativeObject>(exportObj);
47 if (object == nullptr) {
48 HILOG_INFO("object is nullptr");
49 return nullptr;
50 }
51
52 std::unique_ptr<JsUriPermMgr> jsUriPermMgr = std::make_unique<JsUriPermMgr>();
53 object->SetNativePointer(jsUriPermMgr.release(), JsUriPermMgr::Finalizer, nullptr);
54
55 return engine->CreateUndefined();
56 }
57 } // namespace AbilityRuntime
58 } // namespace OHOS
59