| Index: components/spellcheck/renderer/spellcheck_provider.h
|
| diff --git a/components/spellcheck/renderer/spellcheck_provider.h b/components/spellcheck/renderer/spellcheck_provider.h
|
| index cead10758dccd52ad8765b733c2a450fd2270c8d..d0482a0c1fa7f6e6b151bb2ccffcedb4b01c9fec 100644
|
| --- a/components/spellcheck/renderer/spellcheck_provider.h
|
| +++ b/components/spellcheck/renderer/spellcheck_provider.h
|
| @@ -5,13 +5,11 @@
|
| #ifndef COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_H_
|
| #define COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_H_
|
|
|
| -#include <stddef.h>
|
| -#include <stdint.h>
|
| -
|
| #include <vector>
|
|
|
| #include "base/id_map.h"
|
| #include "base/macros.h"
|
| +#include "components/spellcheck/common/spellcheck.mojom.h"
|
| #include "components/spellcheck/spellcheck_build_features.h"
|
| #include "content/public/renderer/render_frame_observer.h"
|
| #include "content/public/renderer/render_frame_observer_tracker.h"
|
| @@ -25,8 +23,8 @@ class WebTextCheckingCompletion;
|
| struct WebTextCheckingResult;
|
| }
|
|
|
| -// This class deals with invoking browser-side spellcheck mechanism
|
| -// which is done asynchronously.
|
| +// This class deals with asynchronously invoking text spelling and grammar
|
| +// checking services provided by the browser process (host).
|
| class SpellCheckProvider
|
| : public content::RenderFrameObserver,
|
| public content::RenderFrameObserverTracker<SpellCheckProvider>,
|
| @@ -38,14 +36,14 @@ class SpellCheckProvider
|
| SpellCheck* spellcheck);
|
| ~SpellCheckProvider() override;
|
|
|
| - // Requests async spell and grammar checker to the platform text
|
| - // checker, which is available on the browser process. The function does not
|
| - // have special handling for partial words, as Blink guarantees that no
|
| - // request is made when typing in the middle of a word.
|
| + // Requests async spell and grammar checks from the platform text checker
|
| + // available in the browser process. The function does not have special
|
| + // handling for partial words, as Blink guarantees that no request is made
|
| + // when typing in the middle of a word.
|
| void RequestTextChecking(const base::string16& text,
|
| blink::WebTextCheckingCompletion* completion);
|
|
|
| - // The number of ongoing IPC requests.
|
| + // The number of ongoing spellcheck host requests.
|
| size_t pending_text_request_size() const {
|
| return text_check_completions_.size();
|
| }
|
| @@ -56,23 +54,31 @@ class SpellCheckProvider
|
| // Enables document-wide spellchecking.
|
| void EnableSpellcheck(bool enabled);
|
|
|
| - // RenderFrameObserver implementation.
|
| + // content::RenderFrameObserver:
|
| bool OnMessageReceived(const IPC::Message& message) override;
|
| void FocusedNodeChanged(const blink::WebNode& node) override;
|
|
|
| private:
|
| friend class TestingSpellCheckProvider;
|
|
|
| - // Tries to satisfy a spell check request from the cache in |last_request_|.
|
| + // Sets the SpellCheckHost (for unit tests).
|
| + void SetSpellCheckHostForTesting(spellcheck::mojom::SpellCheckHostPtr host) {
|
| + spellcheck_host_ = std::move(host);
|
| + }
|
| +
|
| + // Returns the SpellCheckHost.
|
| + spellcheck::mojom::SpellCheckHost& GetSpellCheckHost();
|
| +
|
| + // Tries to satisfy a spellcheck request from the cache in |last_request_|.
|
| // Returns true (and cancels/finishes the completion) if it can, false
|
| // if the provider should forward the query on.
|
| bool SatisfyRequestFromCache(const base::string16& text,
|
| blink::WebTextCheckingCompletion* completion);
|
|
|
| - // RenderFrameObserver implementation.
|
| + // content::RenderFrameObserver:
|
| void OnDestruct() override;
|
|
|
| - // blink::WebTextCheckClient implementation.
|
| + // blink::WebTextCheckClient:
|
| void CheckSpelling(
|
| const blink::WebString& text,
|
| int& offset,
|
| @@ -84,11 +90,10 @@ class SpellCheckProvider
|
| void CancelAllPendingRequests() override;
|
|
|
| #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
|
| - void OnRespondSpellingService(
|
| - int identifier,
|
| - bool succeeded,
|
| - const base::string16& text,
|
| - const std::vector<SpellCheckResult>& results);
|
| + void OnRespondSpellingService(int identifier,
|
| + const base::string16& text,
|
| + bool succeeded,
|
| + const std::vector<SpellCheckResult>& results);
|
| #endif
|
|
|
| // Returns whether |text| has word characters, i.e. whether a spellchecker
|
| @@ -102,17 +107,21 @@ class SpellCheckProvider
|
| const std::vector<SpellCheckResult>& results);
|
| #endif
|
|
|
| - // Holds ongoing spellchecking operations, assigns IDs for the IPC routing.
|
| + // Holds ongoing spellchecking operations.
|
| WebTextCheckCompletions text_check_completions_;
|
|
|
| - // The last text sent to the browser process to spellcheck it and its
|
| - // spellchecking results.
|
| + // The last text sent to the browser process for spellchecking, and its
|
| + // spellcheck results and WebTextCheckCompletions identifier.
|
| base::string16 last_request_;
|
| blink::WebVector<blink::WebTextCheckingResult> last_results_;
|
| + int last_identifier_;
|
|
|
| - // Weak pointer to shared (per RenderView) spellcheck data.
|
| + // Weak pointer to shared (per renderer) spellcheck data.
|
| SpellCheck* spellcheck_;
|
|
|
| + // Interface to the SpellCheckHost.
|
| + spellcheck::mojom::SpellCheckHostPtr spellcheck_host_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(SpellCheckProvider);
|
| };
|
|
|
|
|