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 #include "ui/base/geometry/dimension.h" 28 29 namespace OHOS::Ace::NG { 30 struct NodeMaps { 31 std::unordered_map<int32_t, std::pair<std::string, NG::RectF>> nodeId2Rect; 32 std::unordered_map<int32_t, int32_t> nodeId2Zindex; 33 }; 34 class SecurityComponentHandler { 35 public: 36 static int32_t RegisterSecurityComponent(RefPtr<FrameNode>& node, int32_t& scId); 37 static int32_t UpdateSecurityComponent(RefPtr<FrameNode>& node, int32_t& scId); 38 static int32_t UnregisterSecurityComponent(int32_t& scId); 39 static int32_t ReportSecurityComponentClickEvent(int32_t& scId, 40 RefPtr<FrameNode>& node, GestureEvent& event, 41 Security::SecurityComponent::OnFirstUseDialogCloseFunc&& callback, 42 std::string& message); 43 static int32_t ReportSecurityComponentClickEvent(int32_t& scId, 44 RefPtr<FrameNode>& node, const KeyEvent& event, 45 Security::SecurityComponent::OnFirstUseDialogCloseFunc&& callback); 46 static bool InitButtonInfo(std::string& componentInfo, 47 RefPtr<FrameNode>& node, Security::SecurityComponent::SecCompType& scType, std::string& message); 48 static bool GetDisplayOffset(RefPtr<FrameNode>& node, double& offsetX, double& offsetY); 49 static bool GetWindowRect(RefPtr<FrameNode>& node, OHOS::Security::SecurityComponent::SecCompRect& winRect); 50 static OHOS::Security::SecurityComponent::SecCompUiRegister uiRegister; 51 static SecurityComponentProbe probe; 52 static int32_t ReportSecurityComponentClickEventInner(int32_t& scId, 53 RefPtr<FrameNode>& node, Security::SecurityComponent::SecCompClickEvent& event, 54 Security::SecurityComponent::OnFirstUseDialogCloseFunc&& callback, std::string& message); 55 static bool IsSecurityComponentServiceExist(); 56 static bool LoadSecurityComponentService(); 57 static bool IsSystemAppCalling(); 58 59 private: 60 static bool CheckOpacity(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 61 std::string& message); 62 static bool CheckBrightness(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 63 std::string& message); 64 static bool CheckVisibility(const RefPtr<FrameNode>& node, RefPtr<LayoutProperty>& layoutProperty, 65 std::string& message); 66 static bool CheckBlur(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 67 std::string& message); 68 static bool CheckForegroundBlurStyle(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 69 std::string& message); 70 static bool CheckBlendMode(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 71 std::string& message); 72 static bool CheckParentBorder(const RefPtr<FrameNode>& parentNode, const RectF& scRect, std::string& message); 73 static bool GetBorderRect(const RefPtr<FrameNode>& parentNode, std::vector<RectF>& borderRects); 74 static float GetLinearGradientBlurRatio(std::vector<std::pair<float, float>>& fractionStops); 75 static bool CheckDistance(const float& deltaY, const float& radius, const float& distance, 76 const int32_t& multiplier); 77 static bool CheckDiagonalLinearGradientBlur(const RectF& parentRect, const RectF& rect, 78 const NG::GradientDirection direction, const float& ratio, const float& radius); 79 static float GetBorderRadius(RefPtr<FrameNode>& node, const NG::GradientDirection direction); 80 static bool CheckLinearGradientBlur(const RefPtr<FrameNode>& parentNode, RefPtr<FrameNode>& node, 81 bool& isBlured, double& blurRadius); 82 static bool CheckGrayScale(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 83 std::string& message); 84 static bool CheckSaturate(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 85 std::string& message); 86 static bool CheckContrast(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 87 std::string& message); 88 static bool CheckInvert(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 89 std::string& message); 90 static bool CheckSepia(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 91 std::string& message); 92 static bool CheckHueRotate(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 93 std::string& message); 94 static bool CheckColorBlend(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 95 std::string& message); 96 static bool CheckClipMask(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 97 std::string& message); 98 static bool CheckForegroundColor(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 99 std::string& message); 100 static bool CheckSphericalEffect(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 101 std::string& message); 102 static bool CheckLightUpEffect(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 103 std::string& message); 104 static bool CheckPixelStretchEffect(const RefPtr<FrameNode>& node, const RefPtr<RenderContext>& renderContext, 105 std::string& message); 106 static bool CheckRenderEffect(RefPtr<FrameNode>& node, std::string& message); 107 static bool CheckParentNodesEffect(RefPtr<FrameNode>& node, 108 OHOS::Security::SecurityComponent::SecCompBase& buttonInfo, 109 std::string& message); 110 static void GetVisibleRect(RefPtr<FrameNode>& node, RectF& visibleRect); 111 static bool IsOutOfParentWithRound(const RectF& visibleRect, const RectF& renderRect, 112 OHOS::Security::SecurityComponent::SecCompBase& buttonInfo); 113 static bool GetWindowSceneWindowId(RefPtr<FrameNode>& node, uint32_t& windId); 114 static bool InitBaseInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo, RefPtr<FrameNode>& node); 115 static bool GetPaddingInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo, RefPtr<FrameNode>& node); 116 static bool InitChildInfo(OHOS::Security::SecurityComponent::SecCompBase& buttonInfo, RefPtr<FrameNode>& node); 117 static NG::RectF UpdateClipRect(NG::RectF& clipRect, NG::RectF& paintRect); 118 static NG::RectF UpdatePaintRect(NG::RectF& paintRect, NG::RectF& clipRect); 119 static bool CheckSecurityComponentStatus(const RefPtr<UINode>& root, NodeMaps& maps, 120 int32_t secNodeId, NG::RectF& clipRect, std::string& message); 121 static bool CheckRectIntersect(const RectF& dest, int32_t secNodeId, 122 const std::unordered_map<int32_t, std::pair<std::string, NG::RectF>>& nodeId2Rect, 123 std::unordered_map<int32_t, int32_t>& nodeId2Zindex, std::string& message); 124 static bool IsSecurityComponent(RefPtr<FrameNode>& node); 125 static bool CheckComponentCoveredStatus(int32_t secNodeId, std::string& message); 126 static bool IsContextTransparent(const RefPtr<FrameNode>& frameNode); 127 static bool CheckContainerTags(const RefPtr<FrameNode>& frameNode); 128 static bool IsInModalPage(const RefPtr<UINode>& node); 129 static int32_t GetNodeZIndex(const RefPtr<UINode>& root); 130 static void UpdateAllZindex(const RefPtr<UINode>& root, std::unordered_map<int32_t, int32_t>& nodeId2Zindex); 131 static void WriteButtonInfo(const RefPtr<OHOS::Ace::NG::SecurityComponentLayoutProperty>& layoutProperty, 132 RefPtr<FrameNode>& node, OHOS::Security::SecurityComponent::SecCompBase& buttonInfo, std::string& message); 133 static bool IsSecComponentClipped(RefPtr<FrameNode>& parentNode, RectF& visibleRect, const RectF& frameRect, 134 OHOS::Security::SecurityComponent::SecCompBase& buttonInfo); 135 static bool CheckSecurityComponentTextLimits(const RefPtr<FrameNode>& node, std::string& message); 136 }; 137 } // namespace OHOS::Ace 138 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_HANDLER_H 139