• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "web_scheme_handler_response_impl.h"
17 
18 #include <cstdint>
19 
20 #include "application_context.h"
21 #include "cj_common_ffi.h"
22 #include "native_arkweb_utils.h"
23 #include "native_interface_arkweb.h"
24 #include "nweb_store_web_archive_callback.h"
25 #include "webview_javascript_execute_callback.h"
26 #include "webview_log.h"
27 #include "webview_utils.h"
28 
29 namespace OHOS::Webview {
~WebSchemeHandlerResponseImpl()30 WebSchemeHandlerResponseImpl::~WebSchemeHandlerResponseImpl()
31 {
32     (void)response_;
33     OH_ArkWeb_DestroyResponse(response_);
34 }
35 
GetUrl()36 char* WebSchemeHandlerResponseImpl::GetUrl()
37 {
38     if (!response_) {
39         WEBVIEWLOGE("WebSchemeHandlerResponse is nullptr");
40         return nullptr;
41     }
42     char* url;
43     OH_ArkWebResponse_GetUrl(response_, &url);
44     return url;
45 }
46 
SetUrl(const char * url)47 int32_t WebSchemeHandlerResponseImpl::SetUrl(const char* url)
48 {
49     return OH_ArkWebResponse_SetUrl(response_, url);
50 }
51 
GetStatus()52 int32_t WebSchemeHandlerResponseImpl::GetStatus()
53 {
54     return OH_ArkWebResponse_GetStatus(response_);
55 }
56 
SetStatus(int32_t status)57 int32_t WebSchemeHandlerResponseImpl::SetStatus(int32_t status)
58 {
59     return OH_ArkWebResponse_SetStatus(response_, status);
60 }
61 
GetStatusText()62 char* WebSchemeHandlerResponseImpl::GetStatusText()
63 {
64     if (!response_) {
65         WEBVIEWLOGE("WebSchemeHandlerResponse is nullptr");
66         return nullptr;
67     }
68     char* statusText;
69     OH_ArkWebResponse_GetStatusText(response_, &statusText);
70     return statusText;
71 }
72 
SetStatusText(const char * statusText)73 int32_t WebSchemeHandlerResponseImpl::SetStatusText(const char* statusText)
74 {
75     return OH_ArkWebResponse_SetStatusText(response_, statusText);
76 }
77 
GetMimeType()78 char* WebSchemeHandlerResponseImpl::GetMimeType()
79 {
80     if (!response_) {
81         WEBVIEWLOGE("WebSchemeHandlerResponse is nullptr");
82         return nullptr;
83     }
84     char* mimeType;
85     OH_ArkWebResponse_GetMimeType(response_, &mimeType);
86     return mimeType;
87 }
88 
SetMimeType(const char * mimeType)89 int32_t WebSchemeHandlerResponseImpl::SetMimeType(const char* mimeType)
90 {
91     return OH_ArkWebResponse_SetMimeType(response_, mimeType);
92 }
93 
GetEncoding()94 char* WebSchemeHandlerResponseImpl::GetEncoding()
95 {
96     if (!response_) {
97         WEBVIEWLOGE("WebSchemeHandlerResponse is nullptr");
98         return nullptr;
99     }
100     char* encoding;
101     OH_ArkWebResponse_GetCharset(response_, &encoding);
102     return encoding;
103 }
104 
SetEncoding(const char * encoding)105 int32_t WebSchemeHandlerResponseImpl::SetEncoding(const char* encoding)
106 {
107     return OH_ArkWebResponse_SetCharset(response_, encoding);
108 }
109 
GetHeaderByName(const char * name)110 char* WebSchemeHandlerResponseImpl::GetHeaderByName(const char* name)
111 {
112     if (!response_) {
113         WEBVIEWLOGE("WebSchemeHandlerResponse is nullptr");
114         return nullptr;
115     }
116     char* value;
117     OH_ArkWebResponse_GetHeaderByName(response_, name, &value);
118     return value;
119 }
120 
SetHeaderByName(const char * name,const char * value,bool overwrite)121 int32_t WebSchemeHandlerResponseImpl::SetHeaderByName(const char* name, const char* value, bool overwrite)
122 {
123     return OH_ArkWebResponse_SetHeaderByName(response_, name, value, overwrite);
124 }
125 
GetErrorCode()126 int32_t WebSchemeHandlerResponseImpl::GetErrorCode()
127 {
128     return static_cast<int32_t>(OH_ArkWebResponse_GetError(response_));
129 }
130 
SetErrorCode(int32_t code)131 int32_t WebSchemeHandlerResponseImpl::SetErrorCode(int32_t code)
132 {
133     return OH_ArkWebResponse_SetError(response_, static_cast<ArkWeb_NetError>(code));
134 }
135 } // namespace OHOS::Webview