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