Skip to content
Permalink
Browse files
Use an ObjectIdentifier<> for text checker requests
https://bugs.webkit.org/show_bug.cgi?id=229302

Reviewed by Wenson Hsieh.

Introduce TextCheckerRequestID and use it to identify text checker requests in a type-safe
way.

* Scripts/webkit/messages.py:
(types_that_cannot_be_forward_declared):
(headers_for_type):
* Shared/IdentifierTypes.h:
* UIProcess/TextCheckerCompletion.cpp:
(WebKit::TextCheckerCompletion::create):
(WebKit::TextCheckerCompletion::TextCheckerCompletion):
* UIProcess/TextCheckerCompletion.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::requestCheckingOfString):
(WebKit::WebPageProxy::didFinishCheckingText):
(WebKit::WebPageProxy::didCancelCheckingText):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::requestCheckingOfString):
(WebKit::generateTextCheckingRequestID): Deleted.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::addTextCheckingRequest):
(WebKit::WebPage::didFinishCheckingText):
(WebKit::WebPage::didCancelCheckingText):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:


Canonical link: https://commits.webkit.org/240714@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281290 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
smfr committed Aug 20, 2021
1 parent d98053f commit 5c7e1aca2bb945106f67ad614bfc7281b1bf1c32
Showing 12 changed files with 62 additions and 28 deletions.
@@ -1,3 +1,37 @@
2021-08-19 Simon Fraser <simon.fraser@apple.com>

Use an ObjectIdentifier<> for text checker requests
https://bugs.webkit.org/show_bug.cgi?id=229302

Reviewed by Wenson Hsieh.

Introduce TextCheckerRequestID and use it to identify text checker requests in a type-safe
way.

* Scripts/webkit/messages.py:
(types_that_cannot_be_forward_declared):
(headers_for_type):
* Shared/IdentifierTypes.h:
* UIProcess/TextCheckerCompletion.cpp:
(WebKit::TextCheckerCompletion::create):
(WebKit::TextCheckerCompletion::TextCheckerCompletion):
* UIProcess/TextCheckerCompletion.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::requestCheckingOfString):
(WebKit::WebPageProxy::didFinishCheckingText):
(WebKit::WebPageProxy::didCancelCheckingText):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::requestCheckingOfString):
(WebKit::generateTextCheckingRequestID): Deleted.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::addTextCheckingRequest):
(WebKit::WebPage::didFinishCheckingText):
(WebKit::WebPage::didCancelCheckingText):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

2021-08-19 Wenson Hsieh <wenson_hsieh@apple.com>

Fix the apple internal build after r281277
@@ -343,6 +343,7 @@ def types_that_cannot_be_forward_declared():
'WebKit::StorageAreaImplIdentifier',
'WebKit::StorageNamespaceIdentifier',
'WebKit::TapIdentifier',
'WebKit::TextCheckerRequestID',
'WebKit::TrackPrivateRemoteIdentifier',
'WebKit::TransactionID',
'WebKit::UserContentControllerIdentifier',
@@ -780,6 +781,7 @@ def headers_for_type(type):
'WebKit::SelectionFlags': ['"GestureTypes.h"'],
'WebKit::SelectionTouch': ['"GestureTypes.h"'],
'WebKit::TapIdentifier': ['"IdentifierTypes.h"'],
'WebKit::TextCheckerRequestID': ['"IdentifierTypes.h"'],
'WebCore::MediaEngineSupportParameters': ['<WebCore/MediaPlayer.h>'],
'WebCore::ISOWebVTTCue': ['<WebCore/ISOVTTCue.h>'],
'struct WebCore::Cookie': ['<WebCore/Cookie.h>'],
@@ -32,4 +32,7 @@ namespace WebKit {
enum TapIdentifierType { };
using TapIdentifier = ObjectIdentifier<TapIdentifierType>;

enum TextCheckerRequestType { };
using TextCheckerRequestID = ObjectIdentifier<TextCheckerRequestType>;

} // namespace WebKit
@@ -31,12 +31,12 @@
namespace WebKit {
using namespace WebCore;

Ref<TextCheckerCompletion> TextCheckerCompletion::create(uint64_t requestID, const TextCheckingRequestData& requestData, WebPageProxy* page)
Ref<TextCheckerCompletion> TextCheckerCompletion::create(TextCheckerRequestID requestID, const TextCheckingRequestData& requestData, WebPageProxy* page)
{
return adoptRef(*new TextCheckerCompletion(requestID, requestData, page));
}

TextCheckerCompletion::TextCheckerCompletion(uint64_t requestID, const TextCheckingRequestData& requestData, WebPageProxy* page)
TextCheckerCompletion::TextCheckerCompletion(TextCheckerRequestID requestID, const TextCheckingRequestData& requestData, WebPageProxy* page)
: m_requestID(requestID)
, m_requestData(requestData)
, m_page(page)
@@ -25,6 +25,7 @@

#pragma once

#include "IdentifierTypes.h"
#include <WebCore/TextChecking.h>
#include <wtf/Forward.h>

@@ -36,17 +37,17 @@ class WebPageProxy;

class TextCheckerCompletion : public RefCounted<TextCheckerCompletion> {
public:
static Ref<TextCheckerCompletion> create(uint64_t requestID, const WebCore::TextCheckingRequestData&, WebPageProxy*);
static Ref<TextCheckerCompletion> create(TextCheckerRequestID, const WebCore::TextCheckingRequestData&, WebPageProxy*);

const WebCore::TextCheckingRequestData& textCheckingRequestData() const;
SpellDocumentTag spellDocumentTag();
void didFinishCheckingText(const Vector<WebCore::TextCheckingResult>&) const;
void didCancelCheckingText() const;

private:
TextCheckerCompletion(uint64_t requestID, const WebCore::TextCheckingRequestData&, WebPageProxy*);
TextCheckerCompletion(TextCheckerRequestID, const WebCore::TextCheckingRequestData&, WebPageProxy*);

const uint64_t m_requestID;
const TextCheckerRequestID m_requestID;
const WebCore::TextCheckingRequestData m_requestData;
WebPageProxy* m_page;
};
@@ -7225,17 +7225,17 @@ void WebPageProxy::ignoreWord(const String& word)
TextChecker::ignoreWord(spellDocumentTag(), word);
}

void WebPageProxy::requestCheckingOfString(uint64_t requestID, const TextCheckingRequestData& request, int32_t insertionPoint)
void WebPageProxy::requestCheckingOfString(TextCheckerRequestID requestID, const TextCheckingRequestData& request, int32_t insertionPoint)
{
TextChecker::requestCheckingOfString(TextCheckerCompletion::create(requestID, request, this), insertionPoint);
}

void WebPageProxy::didFinishCheckingText(uint64_t requestID, const Vector<WebCore::TextCheckingResult>& result)
void WebPageProxy::didFinishCheckingText(TextCheckerRequestID requestID, const Vector<WebCore::TextCheckingResult>& result)
{
send(Messages::WebPage::DidFinishCheckingText(requestID, result));
}

void WebPageProxy::didCancelCheckingText(uint64_t requestID)
void WebPageProxy::didCancelCheckingText(TextCheckerRequestID requestID)
{
send(Messages::WebPage::DidCancelCheckingText(requestID));
}
@@ -1455,8 +1455,8 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>

SpellDocumentTag spellDocumentTag();

void didFinishCheckingText(uint64_t requestID, const Vector<WebCore::TextCheckingResult>&);
void didCancelCheckingText(uint64_t requestID);
void didFinishCheckingText(TextCheckerRequestID, const Vector<WebCore::TextCheckingResult>&);
void didCancelCheckingText(TextCheckerRequestID);

void setScrollPinningBehavior(WebCore::ScrollPinningBehavior);
WebCore::ScrollPinningBehavior scrollPinningBehavior() const { return m_scrollPinningBehavior; }
@@ -2277,7 +2277,7 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>
void updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const WebCore::GrammarDetail&);
void learnWord(const String& word);
void ignoreWord(const String& word);
void requestCheckingOfString(uint64_t requestID, const WebCore::TextCheckingRequestData&, int32_t insertionPoint);
void requestCheckingOfString(TextCheckerRequestID, const WebCore::TextCheckingRequestData&, int32_t insertionPoint);

void takeFocus(uint8_t direction);
void setToolTip(const String&);
@@ -297,7 +297,7 @@ messages -> WebPageProxy {
GetGuessesForWord(String word, String context, int32_t insertionPoint) -> (Vector<String> guesses) Synchronous
LearnWord(String word)
IgnoreWord(String word)
RequestCheckingOfString(uint64_t requestID, WebCore::TextCheckingRequestData request, int32_t insertionPoint)
RequestCheckingOfString(WebKit::TextCheckerRequestID requestID, WebCore::TextCheckingRequestData request, int32_t insertionPoint)

# Drag and drop messages
#if ENABLE(DRAG_SUPPORT)
@@ -69,12 +69,6 @@ namespace WebKit {
using namespace WebCore;
using namespace HTMLNames;

static uint64_t generateTextCheckingRequestID()
{
static uint64_t uniqueTextCheckingRequestID = 1;
return uniqueTextCheckingRequestID++;
}

bool WebEditorClient::shouldDeleteRange(const std::optional<SimpleRange>& range)
{
return m_page->injectedBundleEditorClient().shouldDeleteRange(*m_page, range);
@@ -581,7 +575,7 @@ void WebEditorClient::getGuessesForWord(const String& word, const String& contex

void WebEditorClient::requestCheckingOfString(TextCheckingRequest& request, const WebCore::VisibleSelection& currentSelection)
{
uint64_t requestID = generateTextCheckingRequestID();
auto requestID = TextCheckerRequestID::generate();
m_page->addTextCheckingRequest(requestID, request);

m_page->send(Messages::WebPageProxy::RequestCheckingOfString(requestID, request.data(), insertionPointFromCurrentSelection(currentSelection)));
@@ -6241,12 +6241,12 @@ bool WebPage::canShowMIMEType(const String& mimeType, const Function<bool(const
return false;
}

void WebPage::addTextCheckingRequest(uint64_t requestID, Ref<TextCheckingRequest>&& request)
void WebPage::addTextCheckingRequest(TextCheckerRequestID requestID, Ref<TextCheckingRequest>&& request)
{
m_pendingTextCheckingRequestMap.add(requestID, WTFMove(request));
}

void WebPage::didFinishCheckingText(uint64_t requestID, const Vector<TextCheckingResult>& result)
void WebPage::didFinishCheckingText(TextCheckerRequestID requestID, const Vector<TextCheckingResult>& result)
{
RefPtr<TextCheckingRequest> request = m_pendingTextCheckingRequestMap.take(requestID);
if (!request)
@@ -6255,7 +6255,7 @@ void WebPage::didFinishCheckingText(uint64_t requestID, const Vector<TextCheckin
request->didSucceed(result);
}

void WebPage::didCancelCheckingText(uint64_t requestID)
void WebPage::didCancelCheckingText(TextCheckerRequestID requestID)
{
RefPtr<TextCheckingRequest> request = m_pendingTextCheckingRequestMap.take(requestID);
if (!request)
@@ -1154,9 +1154,9 @@ class WebPage : public API::ObjectImpl<API::Object::Type::BundlePage>, public IP
bool canShowMIMEType(const String& MIMEType) const;
bool canShowResponse(const WebCore::ResourceResponse&) const;

void addTextCheckingRequest(uint64_t requestID, Ref<WebCore::TextCheckingRequest>&&);
void didFinishCheckingText(uint64_t requestID, const Vector<WebCore::TextCheckingResult>&);
void didCancelCheckingText(uint64_t requestID);
void addTextCheckingRequest(TextCheckerRequestID, Ref<WebCore::TextCheckingRequest>&&);
void didFinishCheckingText(TextCheckerRequestID, const Vector<WebCore::TextCheckingResult>&);
void didCancelCheckingText(TextCheckerRequestID);

#if ENABLE(DATA_DETECTION)
void setDataDetectionResults(NSArray *);
@@ -1935,7 +1935,7 @@ class WebPage : public API::ObjectImpl<API::Object::Type::BundlePage>, public IP
HashSet<PluginView*> m_pluginViews;
bool m_hasSeenPlugin { false };

HashMap<uint64_t, RefPtr<WebCore::TextCheckingRequest>> m_pendingTextCheckingRequestMap;
HashMap<TextCheckerRequestID, RefPtr<WebCore::TextCheckingRequest>> m_pendingTextCheckingRequestMap;

bool m_useFixedLayout { false };

@@ -359,8 +359,8 @@ GenerateSyntheticEditingCommand(enum:uint8_t WebKit::SyntheticEditingCommandType
# Spelling and grammar.
AdvanceToNextMisspelling(bool startBeforeSelection)
ChangeSpellingToWord(String word)
DidFinishCheckingText(uint64_t requestID, Vector<WebCore::TextCheckingResult> result)
DidCancelCheckingText(uint64_t requestID)
DidFinishCheckingText(WebKit::TextCheckerRequestID requestID, Vector<WebCore::TextCheckingResult> result)
DidCancelCheckingText(WebKit::TextCheckerRequestID requestID)
#if USE(APPKIT)
UppercaseWord()
LowercaseWord()

0 comments on commit 5c7e1ac

Please sign in to comment.