Skip to content

Commit

Permalink
Apply patch. rdar://problem/111258989
Browse files Browse the repository at this point in the history
Identifier: 259548.866@safari-7615-branch
  • Loading branch information
drobson1005 committed Jul 6, 2023
1 parent cb256ae commit a530db2
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Source/WebCore/editing/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ void Editor::clear()
if (m_compositionNode) {
m_compositionNode = nullptr;
if (EditorClient* client = this->client())
client->discardedComposition(m_document.frame());
client->discardedComposition(m_document);
}
m_customCompositionUnderlines.clear();
m_customCompositionHighlights.clear();
Expand Down Expand Up @@ -2051,7 +2051,7 @@ void Editor::confirmOrCancelCompositionAndNotifyClient()

if (auto editorClient = client()) {
editorClient->respondToChangedSelection(frame.get());
editorClient->discardedComposition(frame.get());
editorClient->discardedComposition(m_document);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/loader/EmptyClients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class EmptyEditorClient final : public EditorClient {
void respondToChangedContents() final { }
void respondToChangedSelection(Frame*) final { }
void updateEditorStateAfterLayoutIfEditabilityChanged() final { }
void discardedComposition(Frame*) final { }
void discardedComposition(const Document&) final { }
void canceledComposition() final { }
void didUpdateComposition() final { }
void didEndEditing() final { }
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/page/EditorClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum class DOMPasteAccessCategory : uint8_t;
enum class DOMPasteAccessResponse : uint8_t;

class SharedBuffer;
class Document;
class DocumentFragment;
class Element;
class Frame;
Expand Down Expand Up @@ -108,7 +109,7 @@ class EditorClient : public CanMakeWeakPtr<EditorClient> {

// Notify an input method that a composition was voluntarily discarded by WebCore, so that it could clean up too.
// This function is not called when a composition is closed per a request from an input method.
virtual void discardedComposition(Frame*) = 0;
virtual void discardedComposition(const Document&) = 0;
virtual void canceledComposition() = 0;
virtual void didUpdateComposition() = 0;

Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ void WebEditorClient::didUpdateComposition()
m_page->didUpdateComposition();
}

void WebEditorClient::discardedComposition(Frame*)
void WebEditorClient::discardedComposition(const Document& document)
{
m_page->discardedComposition();
m_page->discardedComposition(document);
}

void WebEditorClient::canceledComposition()
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/WebProcess/WebCoreSupport/WebEditorClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class WebEditorClient final : public WebCore::EditorClient, public WebCore::Text
void respondToChangedSelection(WebCore::Frame*) final;
void didEndUserTriggeredSelectionChanges() final;
void updateEditorStateAfterLayoutIfEditabilityChanged() final;
void discardedComposition(WebCore::Frame*) final;
void discardedComposition(const WebCore::Document&) final;
void canceledComposition() final;
void didUpdateComposition() final;
void didEndEditing() final;
Expand Down
8 changes: 6 additions & 2 deletions Source/WebKit/WebProcess/WebPage/WebPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6419,7 +6419,8 @@ void WebPage::didChangeSelectionOrOverflowScrollPosition()
// FIXME: We can't cancel composition when selection changes to NoSelection, but we probably should.
if (frame->editor().hasComposition() && !frame->editor().ignoreSelectionChanges() && !frame->selection().isNone()) {
frame->editor().cancelComposition();
discardedComposition();
if (RefPtr document = frame->document())
discardedComposition(*document);
return;
}
#endif // HAVE(TOUCH_BAR)
Expand Down Expand Up @@ -6563,9 +6564,12 @@ void WebPage::didEndUserTriggeredSelectionChanges()
sendEditorStateUpdate();
}

void WebPage::discardedComposition()
void WebPage::discardedComposition(const Document& document)
{
send(Messages::WebPageProxy::CompositionWasCanceled());
if (!document.hasLivingRenderTree())
return;

sendEditorStateUpdate();
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/WebProcess/WebPage/WebPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ class WebPage : public API::ObjectImpl<API::Object::Type::BundlePage>, public IP
void didChangeSelection(WebCore::Frame&);
void didChangeOverflowScrollPosition();
void didChangeContents();
void discardedComposition();
void discardedComposition(const WebCore::Document&);
void canceledComposition();
void didUpdateComposition();
void didEndUserTriggeredSelectionChanges();
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class WebEditorClient final : public WebCore::EditorClient, public WebCore::Text
void respondToChangedSelection(WebCore::Frame*) final;
void didEndUserTriggeredSelectionChanges() final { }
void updateEditorStateAfterLayoutIfEditabilityChanged() final;
void discardedComposition(WebCore::Frame*) final;
void discardedComposition(const WebCore::Document&) final;
void canceledComposition() final;
void didUpdateComposition() final { }

Expand Down
2 changes: 1 addition & 1 deletion Source/WebKitLegacy/mac/WebCoreSupport/WebEditorClient.mm
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ static void updateFontPanel(WebView *webView)
#endif
}

void WebEditorClient::discardedComposition(Frame*)
void WebEditorClient::discardedComposition(const Document&)
{
// The effects of this function are currently achieved via -[WebHTMLView _updateSelectionForInputManager].
}
Expand Down
32 changes: 32 additions & 0 deletions Tools/TestWebKitAPI/Tests/ios/KeyboardInputTestsIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,38 @@ static BOOL shouldSimulateKeyboardInputOnTextInsertionOverride(id, SEL)
EXPECT_TRUE(didStartInputSession);
}

TEST(KeyboardInputTests, NoCrashWhenDiscardingMarkedText)
{
auto processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
[processPoolConfiguration setProcessSwapsOnNavigation:YES];

auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
[configuration setProcessPool:processPool.get()];

auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]);
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration.get()]);
[webView setNavigationDelegate:navigationDelegate.get()];
[webView _setEditable:YES];

auto navigateAndSetMarkedText = [&](const String& urlString) {
auto request = [NSURLRequest requestWithURL:[NSURL URLWithString:(NSString *)urlString]];
[webView loadSimulatedRequest:request responseHTMLString:@"<body>Hello world</body>"];
[navigationDelegate waitForDidFinishNavigation];
[webView selectAll:nil];
[[webView textInputContentView] setMarkedText:@"Hello" selectedRange:NSMakeRange(0, 5)];
[webView waitForNextPresentationUpdate];
};

navigateAndSetMarkedText("https://foo.com"_s);
navigateAndSetMarkedText("https://bar.com"_s);
navigateAndSetMarkedText("https://baz.com"_s);
navigateAndSetMarkedText("https://foo.com"_s);
[webView _close];

Util::runFor(100_ms);
}

} // namespace TestWebKitAPI

#endif // PLATFORM(IOS_FAMILY)

0 comments on commit a530db2

Please sign in to comment.