已合并
web支持复制保险箱 #77335
xiongjun_gitee11创建于 2025年12月4日
web支持复制保险箱 #77335
已合并
xiongjun_gitee11创建于 2025年12月4日
共 8 个文件变更+141-9
@@ -1731,9 +1731,9 @@ public:
1731 auto node = node_.Upgrade();1731 auto node = node_.Upgrade();
1732 CHECK_NULL_VOID(node);1732 CHECK_NULL_VOID(node);
1733 taskExecutor->PostTask(1733 taskExecutor->PostTask(
1734- [viewDataWrap, node, autoFillType = autoFillType_]() {1734+ [viewDataWrap, node, autoFillType = autoFillType_, triggerType = triggerType_]() {
1735 if (node) {1735 if (node) {
1736- node->NotifyFillRequestSuccess(viewDataWrap, nullptr, autoFillType);1736+ node->NotifyFillRequestSuccess(viewDataWrap, nullptr, autoFillType, triggerType);
xiongjun_gitee11
xiongjun_gitee11xiongjun_gitee112025年12月5日

将触发类型通知到frame_node

likedislike
1737 }1737 }
1738 },1738 },
1739 TaskExecutor::TaskType::UI, "ArkUINotifyWebFillRequestSuccess");1739 TaskExecutor::TaskType::UI, "ArkUINotifyWebFillRequestSuccess");
@@ -149,6 +149,16 @@ std::string SpanstringConvertHtmlImpl::SpanstringConvertHtml(const std::vector<u
149 return delegate->SpanstringConvertHtml(content);149 return delegate->SpanstringConvertHtml(content);
150}150}
151 151 
152+bool VaultPlainTextImpl::ProcessAutoFillOnPaste()
153+{
154+ ContainerScope scope(instanceId_);
155+ auto delegate = webDelegate_.Upgrade();
156+ if (!delegate) {
157+ return false;
158+ }
159+ return delegate->ProcessAutoFillOnPaste();
160+}
161+ 
152void WebClientImpl::OnPageLoadEnd(int httpStatusCode, const std::string& url)162void WebClientImpl::OnPageLoadEnd(int httpStatusCode, const std::string& url)
153{163{
154 auto delegate = webDelegate_.Upgrade();164 auto delegate = webDelegate_.Upgrade();
@@ -103,6 +103,24 @@ private:
103 int32_t instanceId_ = -1;103 int32_t instanceId_ = -1;
104};104};
105 105 
106+class VaultPlainTextImpl : public OHOS::NWeb::NWebVaultPlainTextCallback {
107+public:
108+ VaultPlainTextImpl() = default;
109+ explicit VaultPlainTextImpl(int32_t instanceId) : instanceId_(instanceId) {}
110+ ~VaultPlainTextImpl() = default;
111+ 
112+ bool ProcessAutoFillOnPaste() override;
113+ 
114+ void SetWebDelegate(const WeakPtr<WebDelegate>& delegate)
115+ {
116+ webDelegate_ = delegate;
117+ }
118+ 
119+private:
120+ WeakPtr<WebDelegate> webDelegate_;
121+ int32_t instanceId_ = -1;
122+};
123+ 
106class WebClientImpl :124class WebClientImpl :
107 public std::enable_shared_from_this<WebClientImpl>,125 public std::enable_shared_from_this<WebClientImpl>,
108 public OHOS::NWeb::NWebHandler {126 public OHOS::NWeb::NWebHandler {
@@ -3093,6 +3093,10 @@ void WebDelegate::InitWebViewWithWindow()
3093 spanstringConvertHtmlImpl->SetWebDelegate(weak);3093 spanstringConvertHtmlImpl->SetWebDelegate(weak);
3094 delegate->nweb_->PutSpanstringConvertHtmlCallback(spanstringConvertHtmlImpl);3094 delegate->nweb_->PutSpanstringConvertHtmlCallback(spanstringConvertHtmlImpl);
3095 3095 
3096+ auto vaultPlainTextImpl = std::make_shared<VaultPlainTextImpl>(Container::CurrentId());
3097+ vaultPlainTextImpl->SetWebDelegate(weak);
3098+ delegate->nweb_->PutVaultPlainTextCallback(vaultPlainTextImpl);
3099+ 
3096 std::optional<std::string> src;3100 std::optional<std::string> src;
3097 auto isNewPipe = Container::IsCurrentUseNewPipeline();3101 auto isNewPipe = Container::IsCurrentUseNewPipeline();
3098 delegate->UpdateSettting(isNewPipe);3102 delegate->UpdateSettting(isNewPipe);
@@ -3622,6 +3626,9 @@ void WebDelegate::InitWebViewWithSurface()
3622 auto spanstringConvertHtmlImpl = std::make_shared<SpanstringConvertHtmlImpl>(Container::CurrentId());3626 auto spanstringConvertHtmlImpl = std::make_shared<SpanstringConvertHtmlImpl>(Container::CurrentId());
3623 spanstringConvertHtmlImpl->SetWebDelegate(weak);3627 spanstringConvertHtmlImpl->SetWebDelegate(weak);
3624 delegate->nweb_->PutSpanstringConvertHtmlCallback(spanstringConvertHtmlImpl);3628 delegate->nweb_->PutSpanstringConvertHtmlCallback(spanstringConvertHtmlImpl);
3629+ auto vaultPlainTextImpl = std::make_shared<VaultPlainTextImpl>(Container::CurrentId());
3630+ vaultPlainTextImpl->SetWebDelegate(weak);
3631+ delegate->nweb_->PutVaultPlainTextCallback(vaultPlainTextImpl);
3625 auto pattern = delegate->webPattern_.Upgrade();3632 auto pattern = delegate->webPattern_.Upgrade();
3626 CHECK_NULL_VOID(pattern);3633 CHECK_NULL_VOID(pattern);
3627 pattern->InitDataDetector();3634 pattern->InitDataDetector();
@@ -7288,18 +7295,23 @@ void WebDelegate::HandleAccessibilityHoverEvent(
7288 nweb_->SendAccessibilityHoverEventV2(x, y, isHoverEnter);7295 nweb_->SendAccessibilityHoverEventV2(x, y, isHoverEnter);
7289}7296}
7290 7297 
7291-void WebDelegate::NotifyAutoFillViewData(const std::string& jsonStr)7298+void WebDelegate::NotifyAutoFillViewData(
7299+ const std::string& jsonStr, const OHOS::NWeb::NWebAutoFillTriggerType& type)
7292{7300{
7293 auto context = context_.Upgrade();7301 auto context = context_.Upgrade();
7294 CHECK_NULL_VOID(context);7302 CHECK_NULL_VOID(context);
7295 context->GetTaskExecutor()->PostTask(7303 context->GetTaskExecutor()->PostTask(
7296- [weak = WeakClaim(this), jsonStr]() {7304+ [weak = WeakClaim(this), jsonStr, type]() {
7297 auto delegate = weak.Upgrade();7305 auto delegate = weak.Upgrade();
7298 CHECK_NULL_VOID(delegate);7306 CHECK_NULL_VOID(delegate);
7299 CHECK_NULL_VOID(delegate->nweb_);7307 CHECK_NULL_VOID(delegate->nweb_);
7300 auto romMessage = std::make_shared<OHOS::NWeb::WebViewValue>(NWebRomValue::Type::NONE);7308 auto romMessage = std::make_shared<OHOS::NWeb::WebViewValue>(NWebRomValue::Type::NONE);
7301 romMessage->SetType(NWebRomValue::Type::STRING);7309 romMessage->SetType(NWebRomValue::Type::STRING);
7302 romMessage->SetString(jsonStr);7310 romMessage->SetString(jsonStr);
7311+ delegate->nweb_->FillAutofillDataFromTriggerType(romMessage, type);
xiongjun_gitee11
xiongjun_gitee11xiongjun_gitee112025年12月5日

将触发类型通知到内核,以便内核可以区分当前触发来源是什么

likedislike
7312+ if (ArkWebGetErrno() == RESULT_OK) {
7313+ return;
7314+ }
7303 delegate->nweb_->FillAutofillDataV2(romMessage);7315 delegate->nweb_->FillAutofillDataV2(romMessage);
7304 if (ArkWebGetErrno() != RESULT_OK) {7316 if (ArkWebGetErrno() != RESULT_OK) {
7305 auto webMessage = std::make_shared<OHOS::NWeb::NWebMessage>(NWebValue::Type::NONE);7317 auto webMessage = std::make_shared<OHOS::NWeb::NWebMessage>(NWebValue::Type::NONE);
@@ -9109,6 +9121,15 @@ std::string WebDelegate::SpanstringConvertHtml(const std::vector<uint8_t> &conte
9109 return htmlStr;9121 return htmlStr;
9110}9122}
9111 9123 
9124+bool WebDelegate::ProcessAutoFillOnPaste()
9125+{
9126+ TAG_LOGI(AceLogTag::ACE_WEB, "ProcessAutoFillOnPaste");
9127+ auto webPattern = webPattern_.Upgrade();
9128+ CHECK_NULL_RETURN(webPattern, false);
9129+ bool isPopup = false;
9130+ return webPattern->RequestAutoFill(isPopup, false, AceAutoFillTriggerType::PASTE_REQUEST);
9131+}
9132+ 
9112void WebDelegate::StartVibraFeedback(const std::string& vibratorType)9133void WebDelegate::StartVibraFeedback(const std::string& vibratorType)
9113{9134{
9114 auto webPattern = webPattern_.Upgrade();9135 auto webPattern = webPattern_.Upgrade();
@@ -1144,7 +1144,7 @@ public:
1144 }1144 }
1145 void HandleAccessibilityHoverEvent(1145 void HandleAccessibilityHoverEvent(
1146 const NG::PointF& point, SourceType source, NG::AccessibilityHoverEventType eventType, TimeStamp time);1146 const NG::PointF& point, SourceType source, NG::AccessibilityHoverEventType eventType, TimeStamp time);
1147- void NotifyAutoFillViewData(const std::string& jsonStr);1147+ void NotifyAutoFillViewData(const std::string& jsonStr, const OHOS::NWeb::NWebAutoFillTriggerType& type);
1148 void AutofillCancel(const std::string& fillContent);1148 void AutofillCancel(const std::string& fillContent);
1149 bool HandleAutoFillEvent(const std::shared_ptr<OHOS::NWeb::NWebMessage>& viewDataJson);1149 bool HandleAutoFillEvent(const std::shared_ptr<OHOS::NWeb::NWebMessage>& viewDataJson);
1150 bool HandleAutoFillEvent(const std::shared_ptr<OHOS::NWeb::NWebHapValue>& viewDataJson);1150 bool HandleAutoFillEvent(const std::shared_ptr<OHOS::NWeb::NWebHapValue>& viewDataJson);
@@ -1296,6 +1296,7 @@ public:
1296 void SetDragResizeStartFlag(bool isDragResizeStart);1296 void SetDragResizeStartFlag(bool isDragResizeStart);
1297 void SetDragResizePreSize(const double& pre_height, const double& pre_width);1297 void SetDragResizePreSize(const double& pre_height, const double& pre_width);
1298 std::string SpanstringConvertHtml(const std::vector<uint8_t> &content);1298 std::string SpanstringConvertHtml(const std::vector<uint8_t> &content);
1299+ bool ProcessAutoFillOnPaste();
1299 bool CloseImageOverlaySelection();1300 bool CloseImageOverlaySelection();
1300 void GetVisibleRectToWeb(int& visibleX, int& visibleY, int& visibleWidth, int& visibleHeight);1301 void GetVisibleRectToWeb(int& visibleX, int& visibleY, int& visibleWidth, int& visibleHeight);
1301 void RestoreRenderFit();1302 void RestoreRenderFit();
@@ -5386,6 +5386,20 @@ void WebPattern::DumpViewDataPageNode(RefPtr<ViewDataWrap> viewDataWrap, bool ne
5386 viewDataWrap->SetOtherAccount(viewDataCommon_->IsOtherAccount());5386 viewDataWrap->SetOtherAccount(viewDataCommon_->IsOtherAccount());
5387}5387}
5388 5388 
5389+OHOS::NWeb::NWebAutoFillTriggerType ConvertAceAutoFillTriggerType(const AceAutoFillTriggerType& type)
5390+{
5391+ switch (type) {
5392+ case AceAutoFillTriggerType::AUTO_REQUEST:
5393+ return OHOS::NWeb::NWebAutoFillTriggerType::AUTO_REQUEST;
5394+ case AceAutoFillTriggerType::MANUAL_REQUEST:
5395+ return OHOS::NWeb::NWebAutoFillTriggerType::MANUAL_REQUEST;
5396+ case AceAutoFillTriggerType::PASTE_REQUEST:
5397+ return OHOS::NWeb::NWebAutoFillTriggerType::PASTE_REQUEST;
5398+ default:
5399+ return OHOS::NWeb::NWebAutoFillTriggerType::UNSPECIFIED;
5400+ }
5401+}
5402+ 
5389void WebPattern::NotifyFillRequestSuccess(RefPtr<ViewDataWrap> viewDataWrap,5403void WebPattern::NotifyFillRequestSuccess(RefPtr<ViewDataWrap> viewDataWrap,
5390 RefPtr<PageNodeInfoWrap> nodeWrap, AceAutoFillType autoFillType, AceAutoFillTriggerType triggerType)5404 RefPtr<PageNodeInfoWrap> nodeWrap, AceAutoFillType autoFillType, AceAutoFillTriggerType triggerType)
5391{5405{
@@ -5399,8 +5413,9 @@ void WebPattern::NotifyFillRequestSuccess(RefPtr<ViewDataWrap> viewDataWrap,
5399 continue;5413 continue;
5400 }5414 }
5401 auto type = nodeInfoWrap->GetAutoFillType();5415 auto type = nodeInfoWrap->GetAutoFillType();
5402- // white list check5416+ if (triggerType == AceAutoFillTriggerType::PASTE_REQUEST) {
5403- if (ACE_AUTOFILL_TYPE_TO_NWEB.count(type) != 0) {5417+ jsonNode->Put(OHOS::NWeb::NWEB_VIEW_DATA_KEY_VALUE.c_str(), nodeInfoWrap->GetValue().c_str());
5418+ } else if (ACE_AUTOFILL_TYPE_TO_NWEB.count(type) != 0) { // white list check
5404 std::string key = ACE_AUTOFILL_TYPE_TO_NWEB.at(type);5419 std::string key = ACE_AUTOFILL_TYPE_TO_NWEB.at(type);
5405 if (nodeInfoWrap->GetMetadata() != IS_HINT_TYPE) {5420 if (nodeInfoWrap->GetMetadata() != IS_HINT_TYPE) {
5406 jsonNode->Put(key.c_str(), nodeInfoWrap->GetValue().c_str());5421 jsonNode->Put(key.c_str(), nodeInfoWrap->GetValue().c_str());
@@ -5419,7 +5434,7 @@ void WebPattern::NotifyFillRequestSuccess(RefPtr<ViewDataWrap> viewDataWrap,
5419 jsonNode->Put(AUTO_FILL_VIEW_DATA_PAGE_URL.c_str(), pageUrl.c_str());5434 jsonNode->Put(AUTO_FILL_VIEW_DATA_PAGE_URL.c_str(), pageUrl.c_str());
5420 auto otherAccount = viewDataWrap->GetOtherAccount();5435 auto otherAccount = viewDataWrap->GetOtherAccount();
5421 jsonNode->Put(AUTO_FILL_VIEW_DATA_OTHER_ACCOUNT.c_str(), otherAccount);5436 jsonNode->Put(AUTO_FILL_VIEW_DATA_OTHER_ACCOUNT.c_str(), otherAccount);
5422- delegate_->NotifyAutoFillViewData(jsonNode->ToString());5437+ delegate_->NotifyAutoFillViewData(jsonNode->ToString(), ConvertAceAutoFillTriggerType(triggerType));
5423 5438 
5424 // shift focus after autofill5439 // shift focus after autofill
5425 if (focusType != AceAutoFillType::ACE_UNSPECIFIED && !isPasswordFill_) {5440 if (focusType != AceAutoFillType::ACE_UNSPECIFIED && !isPasswordFill_) {
@@ -5726,6 +5741,66 @@ bool WebPattern::RequestAutoFill(AceAutoFillType autoFillType, const std::vector
5726 AceAutoFillError::ACE_AUTO_FILL_SUCCESS;5741 AceAutoFillError::ACE_AUTO_FILL_SUCCESS;
5727}5742}
5728 5743 
5744+void WebPattern::FakePageNodeInfo()
5745+{
5746+ auto host = GetHost();
5747+ CHECK_NULL_VOID(host);
5748+ RefPtr<PageNodeInfoWrap> nodeInfo = PageNodeInfoWrap::CreatePageNodeInfoWrap();
5749+ CHECK_NULL_VOID(nodeInfo);
5750+ pageNodeInfo_.clear();
5751+ nodeInfo->SetId(host->GetId());
5752+ nodeInfo->SetDepth(host->GetDepth());
5753+ nodeInfo->SetTag(host->GetTag());
5754+ auto offset = GetCoordinatePoint().value_or(OffsetF());
5755+ NG::RectF pageNodeRect;
5756+ pageNodeRect.SetRect(offset.GetX(), offset.GetY(), drawSize_.Width(), drawSize_.Height());
5757+ nodeInfo->SetPageNodeRect(pageNodeRect);
5758+ nodeInfo->SetIsFocus(true);
5759+ pageNodeInfo_.emplace_back(nodeInfo);
5760+ viewDataCommon_ = std::make_shared<ViewDataCommon>();
5761+}
xiongjun_gitee11
xiongjun_gitee11xiongjun_gitee112025年12月5日

🤖 AI 代码检视意见

类别: 🛡️ Reliability 严重级别: High 文件: frameworks/core/components_ng/pattern/web/web_pattern.cpp 行号: L5744-L5761

问题描述: FakePageNodeInfo函数修改了成员变量pageNodeInfo_和viewDataCommon_,但没有使用任何同步机制。在多线程环境下,如果多个线程同时调用RequestAutoFill,可能导致数据竞争和未定义行为。

修复建议:

void WebPattern::FakePageNodeInfo()
{
    std::lock_guard<std::mutex> lock(autoFillMutex_); // 添加互斥锁保护
    auto host = GetHost();
    CHECK_NULL_VOID(host);
    RefPtr<PageNodeInfoWrap> nodeInfo = PageNodeInfoWrap::CreatePageNodeInfoWrap();
    CHECK_NULL_VOID(nodeInfo);
    pageNodeInfo_.clear();
    nodeInfo->SetId(host->GetId());
    // ... 其余代码保持不变
}

并在类中添加成员:mutable std::mutex autoFillMutex_;


此评论由 OpenHarmony Insight Review Lite 自动生成

likedislike
5762+ 
5763+bool WebPattern::RequestAutoFill(bool& isPopup, bool isNewPassWord,
5764+ const AceAutoFillTriggerType& triggerType)
5765+{
5766+ TAG_LOGI(AceLogTag::ACE_WEB, "ProCessAutoFillOnPaste RequestAutoFill");
5767+ auto host = GetHost();
5768+ CHECK_NULL_RETURN(host, false);
5769+ auto container = Container::Current();
5770+ if (container == nullptr) {
5771+ TAG_LOGW(AceLogTag::ACE_WEB, "Get current container is nullptr.");
5772+ return false;
5773+ }
5774+ 
5775+ FakePageNodeInfo();
5776+ 
5777+ auto onUIExtNodeDestroy = [weak = WeakPtr<FrameNode>(host)]() {
5778+ TAG_LOGI(AceLogTag::ACE_WEB, "onUIExtNodeDestroy called.");
5779+ auto node = weak.Upgrade();
5780+ CHECK_NULL_VOID(node);
5781+ auto pageNode = node->GetPageNode();
5782+ CHECK_NULL_VOID(pageNode);
5783+ auto pagePattern = pageNode->GetPattern<PagePattern>();
5784+ CHECK_NULL_VOID(pagePattern);
5785+ pagePattern->SetIsModalCovered(false);
5786+ };
5787+ auto onUIExtNodeBindingCompleted = [weak = WeakPtr<FrameNode>(host)]() {
5788+ TAG_LOGI(AceLogTag::ACE_WEB, "onUIExtNodeBindingCompleted called.");
5789+ auto node = weak.Upgrade();
5790+ CHECK_NULL_VOID(node);
5791+ auto pageNode = node->GetPageNode();
5792+ CHECK_NULL_VOID(pageNode);
5793+ auto pagePattern = pageNode->GetPattern<PagePattern>();
5794+ CHECK_NULL_VOID(pagePattern);
5795+ pagePattern->SetIsModalCovered(true);
zhufenghao
zhufenghaozhufenghao2025年12月5日

回调的实际作用

likedislike
5796+ };
5797+ AceAutoFillType autoFillType = AceAutoFillType::ACE_UNSPECIFIED;
5798+ isAutoFillClosing_ = false;
5799+ auto resultCode = container->RequestAutoFill(host, autoFillType, isNewPassWord, isPopup,
5800+ autoFillSessionId_, false, onUIExtNodeDestroy, onUIExtNodeBindingCompleted, triggerType);
5801+ return resultCode == AceAutoFillError::ACE_AUTO_FILL_SUCCESS;
5802+}
5803+ 
5729std::string WebPattern::GetAllTextInfo() const5804std::string WebPattern::GetAllTextInfo() const
5730{5805{
5731 CHECK_NULL_RETURN(delegate_, std::string());5806 CHECK_NULL_RETURN(delegate_, std::string());
@@ -696,6 +696,7 @@ public:
696 bool HandleAutoFillEvent(const std::shared_ptr<OHOS::NWeb::NWebHapValue>& viewDataJson);696 bool HandleAutoFillEvent(const std::shared_ptr<OHOS::NWeb::NWebHapValue>& viewDataJson);
697 bool RequestAutoFill(AceAutoFillType autoFillType);697 bool RequestAutoFill(AceAutoFillType autoFillType);
698 bool RequestAutoFill(AceAutoFillType autoFillType, const std::vector<RefPtr<PageNodeInfoWrap>>& nodeInfos);698 bool RequestAutoFill(AceAutoFillType autoFillType, const std::vector<RefPtr<PageNodeInfoWrap>>& nodeInfos);
699+ bool RequestAutoFill(bool& isPopup, bool isNewPassWord, const AceAutoFillTriggerType& triggerType);
699 bool RequestAutoSave();700 bool RequestAutoSave();
700 bool UpdateAutoFillPopup();701 bool UpdateAutoFillPopup();
701 bool CloseAutoFillPopup();702 bool CloseAutoFillPopup();
@@ -1022,6 +1023,7 @@ private:
1022 friend class WebDataDetectorAdapter;1023 friend class WebDataDetectorAdapter;
1023 friend class WebAccessibilityEventReport;1024 friend class WebAccessibilityEventReport;
1024 1025 
1026+ void FakePageNodeInfo();
1025 bool Pip(int status, int delegateId, int childId, int frameRoutingId, int width, int height);1027 bool Pip(int status, int delegateId, int childId, int frameRoutingId, int width, int height);
1026 napi_env CreateEnv();1028 napi_env CreateEnv();
1027 bool CreatePip(int status, napi_env env, bool& init, uint32_t &pipController, const PipInfo &pipInfo);1029 bool CreatePip(int status, napi_env env, bool& init, uint32_t &pipController, const PipInfo &pipInfo);
@@ -1084,7 +1084,8 @@ int64_t WebDelegate::GetWebAccessibilityIdBySurfaceId(const std::string& surface
1084 }1084 }
1085 return -1;1085 return -1;
1086}1086}
1087-void WebDelegate::NotifyAutoFillViewData(const std::string& jsonStr) {}1087+void WebDelegate::NotifyAutoFillViewData(
1088+ const std::string& jsonStr, const OHOS::NWeb::NWebAutoFillTriggerType& type) {}
1088void WebDelegate::AutofillCancel(const std::string& fillContent) {}1089void WebDelegate::AutofillCancel(const std::string& fillContent) {}
1089bool WebDelegate::HandleAutoFillEvent(const std::shared_ptr<OHOS::NWeb::NWebMessage>& viewDataJson)1090bool WebDelegate::HandleAutoFillEvent(const std::shared_ptr<OHOS::NWeb::NWebMessage>& viewDataJson)
1090{1091{
@@ -1355,6 +1356,10 @@ std::string WebDelegate::SpanstringConvertHtml(const std::vector<uint8_t>& conte
1355{1356{
1356 return "";1357 return "";
1357}1358}
1359+bool WebDelegate::ProcessAutoFillOnPaste()
1360+{
1361+ return false;
1362+}
1358bool WebDelegate::CloseImageOverlaySelection()1363bool WebDelegate::CloseImageOverlaySelection()
1359{1364{
1360 return false;1365 return false;