1 /* 2 * Copyright (c) 2024 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_MANAGER_PRIVACY_SENSITIVE_PRIVACY_SENSITIVE_MANAGER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_PRIVACY_SENSITIVE_PRIVACY_SENSITIVE_MANAGER_H 18 19 #include <unordered_set> 20 21 #include "base/memory/ace_type.h" 22 #include "base/memory/referenced.h" 23 #include "base/utils/noncopyable.h" 24 #include "core/components_ng/base/frame_node.h" 25 26 namespace OHOS::Ace::NG { 27 // PrivacySensitiveManager stores sensitive node to apply style correctly. 28 class PrivacySensitiveManager : public virtual AceType { 29 DECLARE_ACE_TYPE(PrivacySensitiveManager, AceType); 30 31 public: 32 PrivacySensitiveManager() = default; 33 ~PrivacySensitiveManager() override = default; StoreNode(WeakPtr<FrameNode> node)34 void StoreNode(WeakPtr<FrameNode> node) 35 { 36 sensitiveNodes_.insert(node); 37 } 38 RemoveNode(WeakPtr<FrameNode> node)39 void RemoveNode(WeakPtr<FrameNode> node) 40 { 41 if (sensitiveNodes_.empty()) { 42 return; 43 } 44 sensitiveNodes_.erase(node); 45 } 46 GetSensitiveNodes()47 const std::set<WeakPtr<FrameNode>>& GetSensitiveNodes() const 48 { 49 return sensitiveNodes_; 50 } 51 TriggerFrameNodesSensitive(bool sensitive)52 void TriggerFrameNodesSensitive(bool sensitive) 53 { 54 if (sensitiveNodes_.empty()) { 55 LOGI("Current no sensitive nodes."); 56 return; 57 } 58 LOGI("Begin to ChangeSensitiveStyle"); 59 for (auto iter = sensitiveNodes_.begin(); iter != sensitiveNodes_.end();) { 60 auto weakNode = *iter; 61 auto sensitiveNode = weakNode.Upgrade(); 62 if (!sensitiveNode) { 63 iter = sensitiveNodes_.erase(iter); 64 continue; 65 } 66 sensitiveNode->ChangeSensitiveStyle(sensitive); 67 iter++; 68 } 69 } 70 71 private: 72 std::set<WeakPtr<FrameNode>> sensitiveNodes_; 73 74 ACE_DISALLOW_COPY_AND_MOVE(PrivacySensitiveManager); 75 }; 76 } // namespace OHOS::Ace::NG 77 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_PRIVACY_SENSITIVE_PRIVACY_SENSITIVE_MANAGER_H 78