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