• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 NWEB_NAPI_WEB_STORAGE_H
17 #define NWEB_NAPI_WEB_STORAGE_H
18 
19 #include <cstdint>
20 #include <iosfwd>
21 #include <string>
22 #include <vector>
23 
24 #include "napi/native_api.h"
25 #include "napi/native_node_api.h"
26 #include "node_api_types.h"
27 
28 namespace OHOS {
29 namespace NWeb {
30 struct GetOriginUsageOrQuotaParam {
31     int retValue;
32     bool isQuato;
33     std::string origin;
34     napi_ref jsStringRef;
35     napi_env env;
36     napi_async_work asyncWork;
37     napi_deferred deferred;
38     napi_ref callbackRef;
39     napi_status status;
40     int errCode;
41 };
42 
43 struct NapiWebStorageOrigin {
44     std::string origin;
45     int64_t quota;
46     int64_t usage;
47 };
48 
49 struct GetOriginsParam {
50     std::vector<NapiWebStorageOrigin> origins;
51     napi_env env;
52     napi_async_work asyncWork;
53     napi_deferred deferred;
54     napi_ref callbackRef;
55     napi_status status;
56     int errCode;
57 };
58 
59 class NapiWebStorage {
60 public:
NapiWebStorage()61     NapiWebStorage() {}
62     ~NapiWebStorage() = default;
63     static napi_value Init(napi_env env, napi_value exports);
64 
65 private:
66     static napi_value JsDeleteAllData(napi_env env, napi_callback_info info);
67     static napi_value JsDeleteOrigin(napi_env env, napi_callback_info info);
68     static napi_value GetErrorCodeValue(napi_env env, int errCode);
69     static void ExecuteGetOrigins(napi_env env, void *data);
70     static void GetNapiWebStorageOriginForResult(napi_env env,
71         const std::vector<NapiWebStorageOrigin> &info, napi_value result);
72     static void GetOriginComplete(napi_env env, napi_status status, void *data);
73     static void GetOriginsPromiseComplete(napi_env env, napi_status status, void *data);
74     static napi_value GetOriginsAsync(napi_env env, napi_value *argv);
75     static napi_value GetOriginsPromise(napi_env env);
76     static napi_value JsGetOrigins(napi_env env, napi_callback_info info);
77     static void ExecuteGetOriginUsageOrQuota(napi_env env, void *data);
78     static void GetOriginUsageOrQuotaComplete(napi_env env, napi_status status, void *data);
79     static void GetOriginUsageOrQuotaPromiseComplete(napi_env env, napi_status status, void *data);
80     static napi_value GetOriginUsageOrQuotaAsync(napi_env env,
81         napi_value *argv, const std::string& origin, bool isQuato);
82     static napi_value GetOriginUsageOrQuotaPromise(napi_env env,
83         napi_value *argv, const std::string& origin, bool isQuato);
84     static napi_value JsGetOriginUsageOrQuota(napi_env env, napi_callback_info info, bool isQuato);
85     static napi_value JsGetOriginQuota(napi_env env, napi_callback_info info);
86     static napi_value JsGetOriginUsage(napi_env env, napi_callback_info info);
87     static napi_value JsConstructor(napi_env env, napi_callback_info info);
88 };
89 } // namespace NWeb
90 } // namespace OHOS
91 
92 #endif // NWEB_NAPI_WEB_STORAGE_H
93