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 16 #include "bridge/declarative_frontend/jsview/models/plugin_model_impl.h" 17 18 #include "bridge/declarative_frontend/view_stack_processor.h" 19 #include "core/components/plugin/plugin_component.h" 20 #include "core/event/ace_event_handler.h" 21 22 namespace OHOS::Ace::Framework { Create(const RequestPluginInfo & pluginInfo)23void PluginModelImpl::Create(const RequestPluginInfo& pluginInfo) 24 { 25 RefPtr<PluginComponent> plugin = AceType::MakeRefPtr<OHOS::Ace::PluginComponent>(); 26 plugin->SetPluginRequestInfo(pluginInfo); 27 ViewStackProcessor::GetInstance()->Push(plugin, false); 28 }; 29 SetOnComplete(std::function<void (const std::string &)> && onCompleteId)30void PluginModelImpl::SetOnComplete(std::function<void(const std::string&)>&& onCompleteId) 31 { 32 auto onComplete = EventMarker(std::move(onCompleteId)); 33 auto plugin = AceType::DynamicCast<PluginComponent>(ViewStackProcessor::GetInstance()->GetMainComponent()); 34 if (plugin) { 35 plugin->SetOnCompleteEventId(onComplete); 36 } 37 }; 38 SetOnError(std::function<void (const std::string &)> && onErrorId)39void PluginModelImpl::SetOnError(std::function<void(const std::string&)>&& onErrorId) 40 { 41 auto onError = EventMarker(std::move(onErrorId)); 42 auto plugin = AceType::DynamicCast<PluginComponent>(ViewStackProcessor::GetInstance()->GetMainComponent()); 43 if (plugin) { 44 plugin->SetOnErrorEventId(onError); 45 } 46 }; 47 SetPluginSize(const Dimension & width,const Dimension & height)48void PluginModelImpl::SetPluginSize(const Dimension& width, const Dimension& height) 49 { 50 auto plugin = AceType::DynamicCast<PluginComponent>(ViewStackProcessor::GetInstance()->GetMainComponent()); 51 if (plugin) { 52 plugin->SetPluginSize(width, height); 53 } 54 }; 55 SetWidth(const Dimension & width)56void PluginModelImpl::SetWidth(const Dimension& width) 57 { 58 auto plugin = AceType::DynamicCast<PluginComponent>(ViewStackProcessor::GetInstance()->GetMainComponent()); 59 if (plugin) { 60 plugin->SetWidth(width); 61 } 62 }; 63 SetHeight(const Dimension & height)64void PluginModelImpl::SetHeight(const Dimension& height) 65 { 66 auto plugin = AceType::DynamicCast<PluginComponent>(ViewStackProcessor::GetInstance()->GetMainComponent()); 67 if (plugin) { 68 plugin->SetHeight(height); 69 } 70 }; 71 SetData(const std::string & data)72void PluginModelImpl::SetData(const std::string& data) 73 { 74 auto plugin = AceType::DynamicCast<PluginComponent>(ViewStackProcessor::GetInstance()->GetMainComponent()); 75 if (plugin) { 76 plugin->SetData(data); 77 } 78 }; 79 } // namespace OHOS::Ace::Framework 80