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 #ifndef OHOS_WEB_PERMISSION_DATA_BASE_ADAPTER_IMPL_H 17 #define OHOS_WEB_PERMISSION_DATA_BASE_ADAPTER_IMPL_H 18 19 #include "ohos_web_data_base_adapter.h" 20 21 #include <string> 22 23 #include "rdb_errno.h" 24 #include "rdb_helper.h" 25 #include "rdb_open_callback.h" 26 #include "rdb_store.h" 27 #include "rdb_store_config.h" 28 #include "rdb_types.h" 29 30 namespace OHOS::NWeb { 31 class PermissionDataBaseRdbOpenCallBack : public OHOS::NativeRdb::RdbOpenCallback { 32 public: 33 int32_t OnCreate(OHOS::NativeRdb::RdbStore& rdbStore) override; 34 35 int32_t OnUpgrade(OHOS::NativeRdb::RdbStore& rdbStore, int32_t currentVersion, int32_t targetVersion) override; 36 }; 37 38 class OhosWebPermissionDataBaseAdapterImpl : public OhosWebPermissionDataBaseAdapter { 39 public: 40 static OhosWebPermissionDataBaseAdapterImpl& GetInstance(); 41 42 ~OhosWebPermissionDataBaseAdapterImpl() override = default; 43 44 bool ExistPermissionByOrigin(const std::string& origin, const WebPermissionType& key) const override; 45 46 bool GetPermissionResultByOrigin(const std::string& origin, const WebPermissionType& key, 47 bool &result) const override; 48 49 void SetPermissionByOrigin(const std::string& origin, const WebPermissionType& key, bool result) override; 50 51 void ClearPermissionByOrigin(const std::string& origin, const WebPermissionType& key) override; 52 53 void ClearAllPermission(const WebPermissionType& key) override; 54 55 void GetOriginsByPermission(const WebPermissionType& key, std::vector<std::string>& origins) const override; 56 57 private: 58 OhosWebPermissionDataBaseAdapterImpl(); 59 60 OhosWebPermissionDataBaseAdapterImpl(const OhosWebPermissionDataBaseAdapterImpl& other) = delete; 61 62 OhosWebPermissionDataBaseAdapterImpl& operator=(const OhosWebPermissionDataBaseAdapterImpl&) = delete; 63 64 std::shared_ptr<OHOS::NativeRdb::RdbStore> CreateDataBase(const std::string& dataBeseName, 65 OHOS::NativeRdb::RdbOpenCallback& callBack); 66 67 std::string KeyToTableName(const WebPermissionType& key) const; 68 69 std::shared_ptr<OHOS::NativeRdb::RdbStore> rdbStore_; 70 }; 71 } // namespace 72 #endif // OHOS_WEB_PERMISSION_DATA_BASE_ADAPTER_IMPL_H