Skip to content

Commit

Permalink
Cherry-pick 266937@main (305367d). https://bugs.webkit.org/show_bug.c…
Browse files Browse the repository at this point in the history
…gi?id=260230

    WebValidationMessageClient should use WeakPtr to WebPage, not a raw reference
    https://bugs.webkit.org/show_bug.cgi?id=260230

    Reviewed by Wenson Hsieh.

    Deploy WeakPtr in WebValidationMessageClient.

    * Source/WebKit/WebProcess/WebCoreSupport/WebValidationMessageClient.cpp:
    (WebKit::WebValidationMessageClient::showValidationMessage):
    (WebKit::WebValidationMessageClient::hideValidationMessage):
    (WebKit::WebValidationMessageClient::hideAnyValidationMessage):
    * Source/WebKit/WebProcess/WebCoreSupport/WebValidationMessageClient.h:

    Canonical link: https://commits.webkit.org/266937@main
  • Loading branch information
rniwa authored and carlosgcampos committed Aug 18, 2023
1 parent 1eb41dc commit 37129e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,29 @@ void WebValidationMessageClient::showValidationMessage(const Element& anchor, co

m_currentAnchor = &anchor;
m_currentAnchorRect = anchor.boundingBoxInRootViewCoordinates();
m_page.send(Messages::WebPageProxy::ShowValidationMessage(m_currentAnchorRect, message));
Ref { *m_page }->send(Messages::WebPageProxy::ShowValidationMessage(m_currentAnchorRect, message));
}

void WebValidationMessageClient::hideValidationMessage(const Element& anchor)
{
if (!isValidationMessageVisible(anchor))
RefPtr page = m_page.get();
if (!isValidationMessageVisible(anchor) || !page)
return;

m_currentAnchor = nullptr;
m_currentAnchorRect = { };
m_page.send(Messages::WebPageProxy::HideValidationMessage());
page->send(Messages::WebPageProxy::HideValidationMessage());
}

void WebValidationMessageClient::hideAnyValidationMessage()
{
if (!m_currentAnchor)
RefPtr page = m_page.get();
if (!m_currentAnchor || !page)
return;

m_currentAnchor = nullptr;
m_currentAnchorRect = { };
m_page.send(Messages::WebPageProxy::HideValidationMessage());
page->send(Messages::WebPageProxy::HideValidationMessage());
}

bool WebValidationMessageClient::isValidationMessageVisible(const Element& anchor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <WebCore/IntRect.h>
#include <WebCore/ValidationMessageClient.h>
#include <wtf/WeakPtr.h>

namespace WebKit {

Expand All @@ -46,7 +47,7 @@ class WebValidationMessageClient final : public WebCore::ValidationMessageClient
void updateValidationBubbleStateIfNeeded() final;

private:
WebPage& m_page;
WeakPtr<WebPage> m_page;
const WebCore::Element* m_currentAnchor { nullptr };
WebCore::IntRect m_currentAnchorRect;
};
Expand Down

0 comments on commit 37129e2

Please sign in to comment.