Commit 39ef5bad authored by xiaochengh's avatar xiaochengh Committed by Commit bot

Let IdleSpellCheckCallback take full control over SpellCheckRequester

With idle time spell checker, all spell check requests should be managed
solely by IdleSpellCheckCallback. This patch ensures that all access
to spell check requests are via IdleSpellCheckCallback when runtime feature
IdleTimeSpellChecking is enabled, with SpellChecker::cancelCheck being the
only exception. SpellChecker::cancelCheck is only used by unit tests, and
will be changed when unit tests are modified to cope with idle time spell
checker.

BUG=517298

Review-Url: https://codereview.chromium.org/2580773002
Cr-Commit-Position: refs/heads/master@{#439076}
parent 6fa168c3
......@@ -11,7 +11,7 @@
namespace blink {
class IdleRequestCallback
class CORE_EXPORT IdleRequestCallback
: public GarbageCollectedFinalized<IdleRequestCallback> {
public:
DEFINE_INLINE_VIRTUAL_TRACE() {}
......
......@@ -49,11 +49,22 @@ IdleSpellCheckCallback::IdleSpellCheckCallback(LocalFrame& frame)
m_frame(frame),
m_coldModeTimer(this, &IdleSpellCheckCallback::coldModeTimerFired) {}
SpellCheckRequester& IdleSpellCheckCallback::spellCheckRequester() const {
// TODO(xiaochengh): decouple with SpellChecker after SpellCheckRequester is
// moved to IdleSpellCheckCallback.
return frame().spellChecker().spellCheckRequester();
}
bool IdleSpellCheckCallback::isSpellCheckingEnabled() const {
// TODO(xiaochengh): decouple with SpellChecker.
return frame().spellChecker().isSpellCheckingEnabled();
}
void IdleSpellCheckCallback::prepareForLeakDetection() {
if (RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled())
spellCheckRequester().prepareForLeakDetection();
}
void IdleSpellCheckCallback::requestInvocation() {
IdleRequestOptions options;
options.setTimeout(kRequestTimeoutMS);
......
......@@ -6,13 +6,15 @@
#define IdleSpellCheckCallback_h
#include "core/dom/IdleRequestCallback.h"
#include "core/frame/LocalFrame.h"
#include "platform/Timer.h"
namespace blink {
class LocalFrame;
class SpellCheckRequester;
// Main class for the implementation of idle time spell checker.
class IdleSpellCheckCallback final : public IdleRequestCallback {
class CORE_EXPORT IdleSpellCheckCallback final : public IdleRequestCallback {
public:
static IdleSpellCheckCallback* create(LocalFrame&);
~IdleSpellCheckCallback() override;
......@@ -32,6 +34,17 @@ class IdleSpellCheckCallback final : public IdleRequestCallback {
// TODO(xiaochengh): Add proper call sites.
void deactivate();
// Exposed for testing only.
SpellCheckRequester& spellCheckRequester() const;
// The leak detector will report leaks should queued requests be posted
// while it GCs repeatedly, as the requests keep their associated element
// alive.
//
// Hence allow the leak detector to effectively stop the spell checker to
// ensure leak reporting stability.
void prepareForLeakDetection();
DECLARE_VIRTUAL_TRACE();
private:
......
......@@ -798,7 +798,8 @@ void SpellChecker::didEndEditingOnTextField(Element* e) {
// Remove markers when deactivating a selection in an <input type="text"/>.
// Prevent new ones from appearing too.
m_spellCheckRequester->cancelCheck();
if (!RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled())
m_spellCheckRequester->cancelCheck();
TextControlElement* textControlElement = toTextControlElement(e);
HTMLElement* innerEditor = textControlElement->innerEditorElement();
DocumentMarker::MarkerTypes markerTypes(DocumentMarker::Spelling);
......@@ -1034,6 +1035,9 @@ void SpellChecker::removeMarkers(const VisibleSelection& selection,
frame().document()->markers().removeMarkers(range, markerTypes);
}
// TODO(xiaochengh): This function is only used by unit tests. We should move it
// to IdleSpellCheckCallback and modify unit tests to cope with idle time spell
// checker.
void SpellChecker::cancelCheck() {
m_spellCheckRequester->cancelCheck();
}
......@@ -1044,7 +1048,8 @@ DEFINE_TRACE(SpellChecker) {
}
void SpellChecker::prepareForLeakDetection() {
m_spellCheckRequester->prepareForLeakDetection();
if (!RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled())
m_spellCheckRequester->prepareForLeakDetection();
}
Vector<TextCheckingResult> SpellChecker::findMisspellings(const String& text) {
......
......@@ -84,7 +84,7 @@ class CORE_EXPORT SpellChecker final : public GarbageCollected<SpellChecker> {
bool onlyHandleWordsContainingSelection);
void cancelCheck();
// Exposed for testing only
// Exposed for testing and idle time spell checker
SpellCheckRequester& spellCheckRequester() const {
return *m_spellCheckRequester;
}
......@@ -124,6 +124,9 @@ class CORE_EXPORT SpellChecker final : public GarbageCollected<SpellChecker> {
const VisibleSelection& newAdjacentWords);
Member<LocalFrame> m_frame;
// TODO(xiaochengh): Move it to IdleSpellCheckCallback after idle time spell
// checking reaches status=stable.
const Member<SpellCheckRequester> m_spellCheckRequester;
};
......
......@@ -67,6 +67,7 @@
#include "core/editing/markers/DocumentMarker.h"
#include "core/editing/markers/DocumentMarkerController.h"
#include "core/editing/serializers/Serialization.h"
#include "core/editing/spellcheck/IdleSpellCheckCallback.h"
#include "core/editing/spellcheck/SpellCheckRequester.h"
#include "core/editing/spellcheck/SpellChecker.h"
#include "core/fetch/MemoryCache.h"
......@@ -197,7 +198,9 @@ static WTF::Optional<DocumentMarker::MarkerTypes> markerTypesFrom(
static SpellCheckRequester* spellCheckRequester(Document* document) {
if (!document || !document->frame())
return 0;
return &document->frame()->spellChecker().spellCheckRequester();
if (!RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled())
return &document->frame()->spellChecker().spellCheckRequester();
return &document->frame()->idleSpellCheckCallback().spellCheckRequester();
}
static ScrollableArea* scrollableAreaForNode(Node* node) {
......
......@@ -31,6 +31,7 @@
#include "public/web/WebLeakDetector.h"
#include "bindings/core/v8/V8GCController.h"
#include "core/editing/spellcheck/IdleSpellCheckCallback.h"
#include "core/editing/spellcheck/SpellChecker.h"
#include "core/fetch/MemoryCache.h"
#include "core/workers/InProcessWorkerMessagingProxy.h"
......@@ -94,8 +95,10 @@ void WebLeakDetectorImpl::prepareForLeakDetection(WebFrame* frame) {
// Stop the spellchecker to prevent this.
if (frame->isWebLocalFrame()) {
WebLocalFrameImpl* localFrame = toWebLocalFrameImpl(frame);
SpellChecker& spellChecker = localFrame->frame()->spellChecker();
spellChecker.prepareForLeakDetection();
if (RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled())
localFrame->frame()->idleSpellCheckCallback().prepareForLeakDetection();
else
localFrame->frame()->spellChecker().prepareForLeakDetection();
}
// FIXME: HTML5 Notification should be closed because notification affects the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment