1 /* 2 * Copyright (c) 2023 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 #ifndef NWEB_INIT_PARAMS_H 16 #define NWEB_INIT_PARAMS_H 17 18 #include "nweb.h" 19 #include "nweb_download_manager.h" 20 21 namespace OHOS::NWeb { 22 23 class NWebDOHConfigImpl : public NWebDOHConfig { 24 public: 25 NWebDOHConfigImpl() = default; 26 ~NWebDOHConfigImpl() = default; 27 SetMode(int mode)28 void SetMode(int mode) 29 { 30 mode_ = mode; 31 } 32 GetMode()33 int GetMode() override 34 { 35 return mode_; 36 } 37 SetConfig(const std::string & config)38 void SetConfig(const std::string& config) 39 { 40 config_ = config; 41 } 42 GetConfig()43 std::string GetConfig() override 44 { 45 return config_; 46 } 47 48 private: 49 int mode_ = -1; 50 std::string config_; 51 }; 52 53 class NWebCreateInfoImpl : public NWebCreateInfo { 54 public: 55 NWebCreateInfoImpl() = default; 56 ~NWebCreateInfoImpl() = default; 57 SetWidth(uint32_t width)58 void SetWidth(uint32_t width) 59 { 60 width_ = width; 61 } 62 GetWidth()63 uint32_t GetWidth() override 64 { 65 return width_; 66 } 67 SetHeight(uint32_t height)68 void SetHeight(uint32_t height) 69 { 70 height_ = height; 71 } 72 GetHeight()73 uint32_t GetHeight() override 74 { 75 return height_; 76 } 77 SetIsIncognitoMode(bool isIncognitoMode)78 void SetIsIncognitoMode(bool isIncognitoMode) 79 { 80 isIncognitoMode_ = isIncognitoMode; 81 } 82 GetIsIncognitoMode()83 bool GetIsIncognitoMode() override 84 { 85 return isIncognitoMode_; 86 } 87 SetProducerSurface(void * producerSurface)88 void SetProducerSurface(void* producerSurface) 89 { 90 producerSurface_ = producerSurface; 91 } 92 GetProducerSurface()93 void* GetProducerSurface() override 94 { 95 return producerSurface_; 96 } 97 SetEnhanceSurfaceInfo(void * enhanceSurfaceInfo)98 void SetEnhanceSurfaceInfo(void* enhanceSurfaceInfo) 99 { 100 enhanceSurfaceInfo_ = enhanceSurfaceInfo; 101 } 102 GetEnhanceSurfaceInfo()103 void* GetEnhanceSurfaceInfo() override 104 { 105 return enhanceSurfaceInfo_; 106 } 107 SetEngineInitArgs(std::shared_ptr<NWebEngineInitArgs> initArgs)108 void SetEngineInitArgs(std::shared_ptr<NWebEngineInitArgs> initArgs) 109 { 110 initArgs_ = initArgs; 111 } 112 GetEngineInitArgs()113 std::shared_ptr<NWebEngineInitArgs> GetEngineInitArgs() override 114 { 115 return initArgs_; 116 } 117 SetOutputFrameCallback(std::shared_ptr<NWebOutputFrameCallback> outputFrameCallback)118 void SetOutputFrameCallback(std::shared_ptr<NWebOutputFrameCallback> outputFrameCallback) 119 { 120 outputFrameCallback_ = outputFrameCallback; 121 } 122 GetOutputFrameCallback()123 std::shared_ptr<NWebOutputFrameCallback> GetOutputFrameCallback() override 124 { 125 return outputFrameCallback_; 126 } 127 128 private: 129 uint32_t width_ = 0; 130 uint32_t height_ = 0; 131 132 bool isIncognitoMode_ = false; 133 134 void* producerSurface_ = nullptr; 135 void* enhanceSurfaceInfo_ = nullptr; 136 137 std::shared_ptr<NWebEngineInitArgs> initArgs_ = nullptr; 138 std::shared_ptr<NWebOutputFrameCallback> outputFrameCallback_ = nullptr; 139 }; 140 141 class NWebEngineInitArgsImpl : public NWebEngineInitArgs { 142 public: 143 NWebEngineInitArgsImpl() = default; 144 ~NWebEngineInitArgsImpl() = default; 145 AddArg(const std::string & arg)146 void AddArg(const std::string& arg) 147 { 148 argsToAdd_.emplace_back(arg); 149 } 150 AddDeleteArg(const std::string & arg)151 void AddDeleteArg(const std::string& arg) 152 { 153 argsToDelete_.emplace_back(arg); 154 } 155 SetDumpPath(const std::string & dumpPath)156 void SetDumpPath(const std::string& dumpPath) 157 { 158 dumpPath_ = dumpPath; 159 } 160 GetDumpPath()161 std::string GetDumpPath() override 162 { 163 return dumpPath_; 164 } 165 SetIsPopup(bool isPopup)166 void SetIsPopup(bool isPopup) 167 { 168 isPopup_ = isPopup; 169 } 170 GetIsPopup()171 bool GetIsPopup() override 172 { 173 return isPopup_; 174 } 175 SetIsFrameInfoDump(bool isFrameInfoDump)176 void SetIsFrameInfoDump(bool isFrameInfoDump) 177 { 178 isFrameInfoDump_ = isFrameInfoDump; 179 } 180 GetIsFrameInfoDump()181 bool GetIsFrameInfoDump() override 182 { 183 return isFrameInfoDump_; 184 } 185 SetIsEnhanceSurface(bool isEnhanceSurface)186 void SetIsEnhanceSurface(bool isEnhanceSurface) 187 { 188 isEnhanceSurface_ = isEnhanceSurface; 189 } 190 GetIsEnhanceSurface()191 bool GetIsEnhanceSurface() override 192 { 193 return isEnhanceSurface_; 194 } 195 SetIsMultiRendererProcess(bool isMultiRendererProcess)196 void SetIsMultiRendererProcess(bool isMultiRendererProcess) 197 { 198 isMultiRendererProcess_ = isMultiRendererProcess; 199 } 200 GetIsMultiRendererProcess()201 bool GetIsMultiRendererProcess() override 202 { 203 return isMultiRendererProcess_; 204 } 205 SetArgsToAdd(const std::list<std::string> & argsToAdd)206 void SetArgsToAdd(const std::list<std::string>& argsToAdd) 207 { 208 argsToAdd_ = argsToAdd; 209 } 210 GetArgsToAdd()211 std::list<std::string> GetArgsToAdd() override 212 { 213 return argsToAdd_; 214 } 215 SetArgsToDelete(const std::list<std::string> & argsToDelete)216 void SetArgsToDelete(const std::list<std::string>& argsToDelete) 217 { 218 argsToDelete_ = argsToDelete; 219 } 220 GetArgsToDelete()221 std::list<std::string> GetArgsToDelete() override 222 { 223 return argsToDelete_; 224 } 225 SetSharedRenderProcessToken(const std::string & sharedRenderProcessToken)226 void SetSharedRenderProcessToken(const std::string& sharedRenderProcessToken) 227 { 228 sharedRenderProcessToken_ = sharedRenderProcessToken; 229 } 230 GetSharedRenderProcessToken()231 std::string GetSharedRenderProcessToken() override 232 { 233 return sharedRenderProcessToken_; 234 } 235 236 private: 237 std::string dumpPath_; 238 239 bool isPopup_ = false; 240 bool isFrameInfoDump_ = false; 241 bool isEnhanceSurface_ = false; 242 bool isMultiRendererProcess_ = false; 243 244 std::list<std::string> argsToAdd_; 245 std::list<std::string> argsToDelete_; 246 std::string sharedRenderProcessToken_; 247 }; 248 249 class NWebEnginePrefetchArgsImpl : public NWebEnginePrefetchArgs { 250 public: NWebEnginePrefetchArgsImpl(const std::string & url,const std::string & method,const std::string & formData)251 NWebEnginePrefetchArgsImpl(const std::string& url, const std::string& method, const std::string& formData) 252 : url_(url), method_(method), form_data_(formData) 253 {} 254 255 ~NWebEnginePrefetchArgsImpl() = default; 256 GetUrl()257 std::string GetUrl() override 258 { 259 return url_; 260 } 261 GetMethod()262 std::string GetMethod() override 263 { 264 return method_; 265 } 266 GetFormData()267 std::string GetFormData() override 268 { 269 return form_data_; 270 } 271 272 private: 273 std::string url_; 274 std::string method_; 275 std::string form_data_; 276 }; 277 278 } // namespace OHOS::NWeb 279 280 #endif // NWEB_INIT_PARAMS_H 281