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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_JAVASCRIPT_VALUE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_JAVASCRIPT_VALUE_H 18 19 namespace OHOS::Ace { 20 enum class WebHitTestType : int { 21 EDIT = 0, 22 EMAIL, 23 HTTP, 24 HTTP_IMG, 25 IMG, 26 MAP, 27 PHONE, 28 UNKNOWN 29 }; 30 31 enum class WebJavaScriptBridgeError : int { 32 NO_ERROR = 0, 33 UNKNOWN_OBJECT_ID, 34 OBJECT_IS_GONE, 35 METHOD_NOT_FOUND, 36 ACCESS_TO_OBJECT_GET_CLASS_IS_BLOCKED, 37 EXCEPTION_RAISED, 38 NON_ASSIGNABLE_TYPES, 39 RENDER_FRAME_DELETED 40 }; 41 42 union WebJSValueUnion { 43 int n; 44 double f; 45 bool b; 46 }; 47 48 class WebJavaScriptValue { 49 public: 50 enum class Type : unsigned char { 51 NONE = 0, 52 BOOLEAN, 53 INTEGER, 54 DOUBLE, 55 STRING, 56 BINARY, 57 DICTIONARY, 58 LIST 59 }; 60 WebJavaScriptValue(Type type)61 WebJavaScriptValue(Type type) : type_(type) {} 62 63 ~WebJavaScriptValue() = default; 64 GetBoolean()65 bool GetBoolean() 66 { 67 return data_.b; 68 } 69 SetBoolean(bool value)70 void SetBoolean(bool value) 71 { 72 data_.b = value; 73 } 74 SetString(std::string value)75 void SetString(std::string value) 76 { 77 str_ = value; 78 } 79 GetString()80 std::string GetString() 81 { 82 return str_; 83 } 84 SetDouble(double value)85 void SetDouble(double value) 86 { 87 data_.f = value; 88 } 89 GetDouble()90 double GetDouble() 91 { 92 return data_.f; 93 } 94 SetInt(int value)95 void SetInt(int value) 96 { 97 data_.n = value; 98 } 99 GetInt()100 int GetInt() 101 { 102 return data_.n; 103 } 104 SetJsonString(std::string value)105 void SetJsonString(std::string value) 106 { 107 json_ = value; 108 } 109 GetJsonString()110 std::string GetJsonString() 111 { 112 return json_; 113 } 114 GetType()115 Type GetType() 116 { 117 return type_; 118 } 119 SetType(Type type)120 void SetType(Type type) 121 { 122 type_ = type; 123 } 124 125 int error_ = 0; 126 127 private: 128 Type type_ = Type::NONE; 129 WebJSValueUnion data_; 130 std::string str_; 131 std::string json_; 132 }; 133 using WebJSValue = WebJavaScriptValue; 134 } // namespace OHOS::Ace 135 136 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_JAVASCRIPT_VALUE_H 137