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