diff --git a/components/performance_manager/graph/frame_node_impl.cc b/components/performance_manager/graph/frame_node_impl.cc index 8d6b3eef91abc08685db5f98ee579e5055ea7f68..03807c0eeef10ca2bc00641a95be24e42d61f7ee 100644 --- a/components/performance_manager/graph/frame_node_impl.cc +++ b/components/performance_manager/graph/frame_node_impl.cc @@ -93,6 +93,17 @@ void FrameNodeImpl::SetHadFormInteraction() { document_.had_form_interaction.SetAndMaybeNotify(this, true); } +#if BUILDFLAG(IS_OHOS) +void FrameNodeImpl::OnFormEditingStateChanged(uint64_t form_id, bool did_submit) { + LOG(INFO) << "FrameNodeImpl::OnFormEditingStateChanged id: " << form_id << "did submit: " << did_submit; + content::GlobalRenderFrameHostId global_frame_routing_id = render_frame_host_proxy().global_frame_routing_id(); + content::WebContents* web_contents = content::WebContentsImpl::FromRenderFrameHostID(global_frame_routing_id); + if (web_contents) { + web_contents->OnFormEditingStateChanged(form_id, did_submit); + } +} +#endif + void FrameNodeImpl::OnNonPersistentNotificationCreated() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); for (auto* observer : GetObservers()) diff --git a/components/performance_manager/graph/frame_node_impl.h b/components/performance_manager/graph/frame_node_impl.h index 4f333b7ccd9c9987adf42a280a339b8c02f71bae..e51f69710141b42fbc2fb57165446014d8205aea 100644 --- a/components/performance_manager/graph/frame_node_impl.h +++ b/components/performance_manager/graph/frame_node_impl.h @@ -18,6 +18,8 @@ #include "components/performance_manager/public/mojom/coordination_unit.mojom.h" #include "components/performance_manager/public/mojom/web_memory.mojom.h" #include "components/performance_manager/public/render_frame_host_proxy.h" +#include "content/public/browser/web_contents.h" +#include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/browsing_instance_id.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/receiver.h" @@ -74,7 +76,9 @@ class FrameNodeImpl void OnWebMemoryMeasurementRequested( mojom::WebMemoryMeasurement::Mode mode, OnWebMemoryMeasurementRequestedCallback callback) override; - +#if BUILDFLAG(IS_OHOS) + void OnFormEditingStateChanged(uint64_t form_id, bool did_submit) override; +#endif // Partial FrameNodbase::TimeDelta time_since_navigatione implementation: bool IsMainFrame() const override; diff --git a/components/performance_manager/public/mojom/coordination_unit.mojom b/components/performance_manager/public/mojom/coordination_unit.mojom index 3598751b15970e66ddbddbad37627d9866a3d61a..06d8bbe15b0b59e475f65bdb9be8d32b13af6972 100644 --- a/components/performance_manager/public/mojom/coordination_unit.mojom +++ b/components/performance_manager/public/mojom/coordination_unit.mojom @@ -55,6 +55,10 @@ interface DocumentCoordinationUnit { // the performance.measureUserAgentSpecificMemory API. OnWebMemoryMeasurementRequested(WebMemoryMeasurement.Mode mode) => (WebMemoryMeasurement measurement); + + // Called when form editing state is changed + [EnableIf=is_ohos] + OnFormEditingStateChanged(uint64 form_id, bool did_submit); }; // Interface used by the RendererResourceCoordinator singleton to send state diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc index d6c9e59da6a739273ce377d459fab5c43e980536..6a14389df8a829988c7c6bb5d6f824c6dea426ff 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -7838,6 +7838,27 @@ void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, node->current_frame_host()); } +#if BUILDFLAG(IS_OHOS) +void WebContentsImpl::OnFormEditingStateChanged(uint64_t form_id, bool did_submit) { + LOG(INFO) << "WebContentsImpl::OnFormEditingStateChanged form_id: " << form_id << " did_submit: " << did_submit; + bool form_editing_state_ = edited_forms_id_.size(); + std::vector::iterator it = find(edited_forms_id_.begin(), edited_forms_id_.end(), form_id); + + if (it == edited_forms_id_.end() && !did_submit) { + edited_forms_id_.push_back(form_id); + } else if (it != edited_forms_id_.end() && did_submit) { + edited_forms_id_.erase(it); + } else { + return; + } + + bool current_is_editing_ = edited_forms_id_.size() != 0; + if (current_is_editing_ != form_editing_state_) { + observers_.NotifyObservers(&WebContentsObserver::OnFormEditingStateChanged, current_is_editing_); + } +} +#endif + void WebContentsImpl::DidCallFocus() { OPTIONAL_TRACE_EVENT0("content", "WebContentsImpl::DidCallFocus"); // Any explicit focusing of another window while this WebContents is in diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 271a4873b7ba5c0cd60c852ce661584ae0874e48..79f322e002f0835f0c7bcbfd01f287fb0c88bd88 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -640,7 +640,9 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, bool animate) override; void SetTabSwitchStartTime(base::TimeTicks start_time, bool destination_is_loaded) final; - +#if BUILDFLAG(IS_OHOS) + void OnFormEditingStateChanged(uint64_t form_id, bool did_submit) override; +#endif // Implementation of PageNavigator. WebContents* OpenURL(const OpenURLParams& params) override; @@ -2374,6 +2376,10 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, VisibleTimeRequestTrigger visible_time_request_trigger_; +#if BUILDFLAG(IS_OHOS) + std::vector edited_forms_id_; +#endif + #if defined(OHOS_NWEB_EX) bool force_enable_zoom_; bool is_selectable_; diff --git a/content/public/browser/web_contents.h b/content/public/browser/web_contents.h index 570f65e01c4220f7521a2f2c58d6da183bb14454..eae4aaedc45607aa146bb2c7f4dab91a90ec6d24 100644 --- a/content/public/browser/web_contents.h +++ b/content/public/browser/web_contents.h @@ -1406,6 +1406,10 @@ class WebContents : public PageNavigator, PrerenderTriggerType trigger_type, const std::string& embedder_histogram_suffix) = 0; +#if BUILDFLAG(IS_OHOS) + virtual void OnFormEditingStateChanged(uint64_t form_id, bool did_submit) = 0; +#endif + #ifdef BUILDFLAG(IS_OHOS) virtual void ClearContextMenu() = 0; #endif //BUILDFLAG(IS_OHOS) diff --git a/content/public/browser/web_contents_observer.h b/content/public/browser/web_contents_observer.h index 1005bdd0a2ae0dcb3f55560cce6a9a73dbdaa896..c82449fb3047520ca0966e28ca3074b7ac08bf15 100644 --- a/content/public/browser/web_contents_observer.h +++ b/content/public/browser/web_contents_observer.h @@ -790,6 +790,10 @@ class CONTENT_EXPORT WebContentsObserver { // be invoked before DidUpdateFaviconURL(). virtual void DidUpdateWebManifestURL(RenderFrameHost* target_frame, const GURL& manifest_url) {} +#if BUILDFLAG(IS_OHOS) + // Called when form editing state changed + virtual void OnFormEditingStateChanged(bool state) {} +#endif // Called when "audible" playback starts or stops on a WebAudio AudioContext. using AudioContextId = std::pair; diff --git a/ohos_nweb/include/nweb_handler.h b/ohos_nweb/include/nweb_handler.h index 53f62b4af337e24e4efcead5a3fd2fadd92676c1..e4b834bb35c081898e2eb3615383acb0f71b0ef9 100755 --- a/ohos_nweb/include/nweb_handler.h +++ b/ohos_nweb/include/nweb_handler.h @@ -163,6 +163,11 @@ enum class MediaPlayingState { END_OF_STREAM, }; +enum class FormState { + kHadInteraction, + kNoInteraction, +}; + enum class ActivityType { VIDEO = 0, AUDIO, @@ -618,6 +623,7 @@ public: * screen capture permission. */ virtual void OnScreenCaptureRequest(std::shared_ptr request) {} + /** * @brief Called when the media or form state on the web page changed. diff --git a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc index 56f61ed2b493339e2ea4f0f567b4db21bb777a42..2c00680f60c9f8dd9277eea62bfec265e7072448 100644 --- a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc +++ b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.cc @@ -473,6 +473,10 @@ CefRefPtr NWebHandlerDelegate::GetKeyboardHandler() { CefRefPtr NWebHandlerDelegate::GetPrintHandler() { return this; } + +CefRefPtr NWebHandlerDelegate::GetFormHandler() { + return this; +} /* CefClient methods end */ /* CefLifeSpanHandler methods begin */ @@ -1513,6 +1517,17 @@ bool NWebHandlerDelegate::OnSetFocus(CefRefPtr browser, } /* CefFocusHandler method end */ +/* CefFormHandler method begin */ +void NWebHandlerDelegate::OnFormEditingStateChanged(CefRefPtr browser, bool is_editing) { + LOG(INFO) << "NWebHandlerDelegate::OnFormEditingStateChanged, is_editing: " << is_editing << "nweb_id: " << nweb_id_; + if (nweb_handler_ != nullptr) { + FormState state = is_editing ? FormState::kHadInteraction : FormState::kNoInteraction; + nweb_handler_->OnActivityStateChanged(static_cast(state), ActivityType::FORM); + } +} +/* CefFormHandler method end */ + + /* CefPermissionRequest method begin */ void NWebHandlerDelegate::OnGeolocationShow(const CefString& origin) { if (nweb_handler_ != nullptr) { diff --git a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h index 9451226cd31d2f214a0320f603a657fa86544231..4aa95fe388adc8cc627b5fa4b98df96a8eb98185 100644 --- a/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h +++ b/ohos_nweb/src/cef_delegate/nweb_handler_delegate.h @@ -19,6 +19,7 @@ #include "cef/include/base/cef_lock.h" #include "cef/include/cef_client.h" #include "cef/include/cef_dialog_handler.h" +#include "cef/include/cef_form_handler.h" #include "cef/include/cef_jsdialog_handler.h" #include "cef/include/cef_media_handler.h" #include "cef/include/cef_permission_request.h" @@ -63,7 +64,8 @@ class NWebHandlerDelegate : public CefClient, public CefKeyboardHandler, public CefMediaHandler, public CefCookieAccessFilter, - public CefPrintHandler { + public CefPrintHandler, + public CefFormHandler { public: static CefRefPtr Create( std::shared_ptr preference_delegate, @@ -127,6 +129,7 @@ class NWebHandlerDelegate : public CefClient, const CefString& method, const CefString& object_name, CefRefPtr result) override; + CefRefPtr GetFormHandler() override; // #if defined(OHOS_NWEB_EX) void ShowPasswordDialog(bool is_update, const CefString& url) override; void OnShowAutofillPopup( @@ -329,6 +332,10 @@ class NWebHandlerDelegate : public CefClient, bool OnSetFocus(CefRefPtr browser, FocusSource source) override; /* CefFocusHandler method end */ + /* CefFormHandler method begin */ + void OnFormEditingStateChanged(CefRefPtr browser, bool is_editing) override; + /* CefFormHandler method end */ + /* CefPermissionRequest method begin */ void OnGeolocationShow(const CefString& origin) override;