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_RESULT_CALLBACK_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_JAVASCRIPT_RESULT_CALLBACK_H 18 19 #include <string> 20 #include <vector> 21 22 #include "nweb_javascript_result_callback.h" 23 #include "nweb_value.h" 24 #include "core/components/web/resource/web_javascript_value.h" 25 26 namespace OHOS::Ace { 27 using namespace OHOS::NWeb; 28 class WebJavaScriptResultCallBack : public NWebJavaScriptResultCallBack { 29 public: WebJavaScriptResultCallBack(int32_t instanceId)30 WebJavaScriptResultCallBack(int32_t instanceId) : instanceId_(instanceId) {} 31 ~WebJavaScriptResultCallBack() = default; 32 33 std::shared_ptr<NWebValue> GetJavaScriptResult(std::vector<std::shared_ptr<NWebValue>> args, 34 const std::string& method, 35 const std::string& object_name) override; 36 37 using JavaScriptCallBackImpl = std::function<std::shared_ptr<WebJSValue>( 38 const std::string& objectName, 39 const std::string& objectMethod, 40 const std::vector<std::shared_ptr<WebJSValue>>& args)>; SetJavaScriptCallBack(const JavaScriptCallBackImpl && javaScriptCallBackImpl)41 void SetJavaScriptCallBack(const JavaScriptCallBackImpl&& javaScriptCallBackImpl) 42 { 43 javaScriptCallBackImpl_ = javaScriptCallBackImpl; 44 } 45 46 protected: 47 JavaScriptCallBackImpl javaScriptCallBackImpl_; 48 49 private: 50 int32_t instanceId_ = -1; 51 }; 52 } // namespace OHOS::Ace 53 54 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_RESOURCE_WEB_JAVASCRIPT_RESULT_CALLBACK_H 55