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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_HANDLER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_HANDLER_H 18 #include "base/geometry/ng/rect_t.h" 19 #include "core/components_ng/base/frame_node.h" 20 #include "core/components_ng/pattern/security_component/security_component_pattern.h" 21 #include "core/components_ng/pattern/security_component/security_component_probe.h" 22 #include "location_button.h" 23 #include "paste_button.h" 24 #include "save_button.h" 25 #include "sec_comp_err.h" 26 #include "sec_comp_kit.h" 27 28 namespace OHOS::Ace::NG { 29 struct NodeMaps { 30 std::unordered_map<int32_t, NG::RectF> nodeId2Rect; 31 std::unordered_map<int32_t, int32_t> nodeId2Zindex; 32 }; 33 class SecurityComponentHandler { 34 public: 35 static int32_t RegisterSecurityComponent(RefPtr<FrameNode>& node, int32_t& scId); 36 static int32_t UpdateSecurityComponent(RefPtr<FrameNode>& node, int32_t& scId); 37 static int32_t UnregisterSecurityComponent(int32_t& scId); 38 static int32_t ReportSecurityComponentClickEvent(int32_t& scId, 39 RefPtr<FrameNode>& node, GestureEvent& event, 40 Security::SecurityComponent::OnFirstUseDialogCloseFunc&& callback); 41 static int32_t ReportSecurityComponentClickEvent(int32_t& scId, 42 RefPtr<FrameNode>& node, const KeyEvent& event, 43 Security::SecurityComponent::OnFirstUseDialogCloseFunc&& callback); 44 static bool InitButtonInfo(std::string& componentInfo, 45 RefPtr<FrameNode>& node, Security::SecurityComponent::SecCompType& scType); 46 static bool GetDisplayOffset(RefPtr<FrameNode>& node, double& offsetX, double& offsetY); 47 static bool GetWindowRect(RefPtr<FrameNode>& node, OHOS::Security::SecurityComponent::SecCompRect& winRect); 48 static OHOS::Security::SecurityComponent::SecCompUiRegister uiRegister; 49 static SecurityComponentProbe probe; 50 static int32_t ReportSecurityComponentClickEventInner(int32_t& scId, 51 RefPtr<FrameNode>& node, Security::SecurityComponent::SecCompClickEvent& event, 52 Security::SecurityComponent::OnFirstUseDialogCloseFunc&& callback); 53 static bool IsSecurityComponentServiceExist(); 54 static bool LoadSecurityComponentService(); 55 static bool IsSystemAppCalling(); 56 57 private: 58 static bool CheckOpacity(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 59 static bool CheckBrightness(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 60 static bool CheckVisibility(const RefPtr<FrameNode>& node, RefPtr<LayoutProperty>& layoutProperty); 61 static bool CheckBlur(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 62 static bool CheckForegroundBlurStyle(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 63 static bool CheckBlendMode(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 64 static float GetLinearGradientBlurRatio(std::vector<std::pair<float, float>>& fractionStops); 65 static bool CheckDistance(const float& deltaY, const float& radius, const float& distance, 66 const int32_t& multiplier); 67 static bool CheckDiagonalLinearGradientBlur(const RectF& parentRect, const RectF& rect, 68 const NG::GradientDirection direction, const float& ratio, const float& radius); 69 static float GetBorderRadius(RefPtr<FrameNode>& node, const NG::GradientDirection direction); 70 static bool CheckLinearGradientBlur(const RefPtr<FrameNode>& parentNode, RefPtr<FrameNode>& node); 71 static bool CheckGrayScale(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 72 static bool CheckSaturate(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 73 static bool CheckContrast(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 74 static bool CheckInvert(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 75 static bool CheckSepia(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 76 static bool CheckHueRotate(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 77 static bool CheckColorBlend(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 78 static bool CheckClipMask(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 79 static bool CheckForegroundColor(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 80 static bool CheckSphericalEffect(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 81 static bool CheckLightUpEffect(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 82 static bool CheckPixelStretchEffect(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext); 83 static bool CheckRenderEffect(RefPtr<FrameNode>& node); 84 static bool CheckParentNodesEffect(RefPtr<FrameNode>& node, 85 OHOS::Security::SecurityComponent::SecCompBase& buttonInfo); 86 static void GetVisibleRect(RefPtr<FrameNode>& node, RectF& visibleRect); 87 static bool IsOutOfParentWithRound(const RectF& visibleRect, const RectF& renderRect, 88 OHOS::Security::SecurityComponent::SecCompBase& buttonInfo); 89 static bool GetWindowSceneWindowId(RefPtr<FrameNode>& node, uint32_t& windId); 90 static bool InitBaseInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo, RefPtr<FrameNode>& node); 91 static bool GetPaddingInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo, RefPtr<FrameNode>& node); 92 static bool InitChildInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo, RefPtr<FrameNode>& node); 93 static NG::RectF UpdateClipRect(NG::RectF& clipRect, NG::RectF& paintRect); 94 static NG::RectF UpdatePaintRect(NG::RectF& paintRect, NG::RectF& clipRect); 95 static bool CheckSecurityComponentStatus(const RefPtr<UINode>& root, NodeMaps& maps, 96 int32_t secNodeId, NG::RectF& clipRect); 97 static bool CheckRectIntersect(const RectF& dest, int32_t secNodeId, 98 const std::unordered_map<int32_t, NG::RectF>& nodeId2Rect, 99 std::unordered_map<int32_t, int32_t>& nodeId2Zindex); 100 static bool IsSecurityComponent(RefPtr<FrameNode>& node); 101 static bool CheckComponentCoveredStatus(int32_t secNodeId); 102 static bool IsContextTransparent(const RefPtr<FrameNode>& frameNode); 103 static bool CheckContainerTags(const RefPtr<FrameNode>& frameNode); 104 static bool IsInModalPage(const RefPtr<UINode>& node); 105 static int32_t GetNodeZIndex(const RefPtr<UINode>& root); 106 static void UpdateAllZindex(const RefPtr<UINode>& root, std::unordered_map<int32_t, int32_t>& nodeId2Zindex); 107 static void WriteButtonInfo(const RefPtr<OHOS::Ace::NG::SecurityComponentLayoutProperty>& layoutProperty, 108 RefPtr<FrameNode>& node, OHOS::Security::SecurityComponent::SecCompBase& buttonInfo); 109 }; 110 } // namespace OHOS::Ace 111 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_HANDLER_H 112