| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_H_ | 5 #ifndef COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_H_ |
| 6 #define COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_H_ | 6 #define COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/id_map.h" | 13 #include "base/id_map.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "components/spellcheck/spellcheck_build_features.h" | 15 #include "components/spellcheck/spellcheck_build_features.h" |
| 16 #include "content/public/renderer/render_view_observer.h" | 16 #include "content/public/renderer/render_frame_observer.h" |
| 17 #include "content/public/renderer/render_view_observer_tracker.h" | 17 #include "content/public/renderer/render_frame_observer_tracker.h" |
| 18 #include "third_party/WebKit/public/web/WebTextCheckClient.h" | 18 #include "third_party/WebKit/public/web/WebTextCheckClient.h" |
| 19 | 19 |
| 20 class SpellCheck; | 20 class SpellCheck; |
| 21 struct SpellCheckResult; | 21 struct SpellCheckResult; |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 class WebTextCheckingCompletion; | 24 class WebTextCheckingCompletion; |
| 25 struct WebTextCheckingResult; | 25 struct WebTextCheckingResult; |
| 26 } | 26 } |
| 27 | 27 |
| 28 // TODO(xiaochengh): Make SpellCheckProvider a RenderFrameObserver. | |
| 29 // This class deals with invoking browser-side spellcheck mechanism | 28 // This class deals with invoking browser-side spellcheck mechanism |
| 30 // which is done asynchronously. | 29 // which is done asynchronously. |
| 31 class SpellCheckProvider | 30 class SpellCheckProvider |
| 32 : public content::RenderViewObserver, | 31 : public content::RenderFrameObserver, |
| 33 public content::RenderViewObserverTracker<SpellCheckProvider>, | 32 public content::RenderFrameObserverTracker<SpellCheckProvider>, |
| 34 public blink::WebTextCheckClient { | 33 public blink::WebTextCheckClient { |
| 35 public: | 34 public: |
| 36 using WebTextCheckCompletions = IDMap<blink::WebTextCheckingCompletion*>; | 35 using WebTextCheckCompletions = IDMap<blink::WebTextCheckingCompletion*>; |
| 37 | 36 |
| 38 SpellCheckProvider(content::RenderView* render_view, | 37 SpellCheckProvider(content::RenderFrame* render_frame, |
| 39 SpellCheck* spellcheck); | 38 SpellCheck* spellcheck); |
| 40 ~SpellCheckProvider() override; | 39 ~SpellCheckProvider() override; |
| 41 | 40 |
| 42 // Requests async spell and grammar checker to the platform text | 41 // Requests async spell and grammar checker to the platform text |
| 43 // checker, which is available on the browser process. The function does not | 42 // checker, which is available on the browser process. The function does not |
| 44 // have special handling for partial words, as Blink guarantees that no | 43 // have special handling for partial words, as Blink guarantees that no |
| 45 // request is made when typing in the middle of a word. | 44 // request is made when typing in the middle of a word. |
| 46 void RequestTextChecking(const base::string16& text, | 45 void RequestTextChecking(const base::string16& text, |
| 47 blink::WebTextCheckingCompletion* completion); | 46 blink::WebTextCheckingCompletion* completion); |
| 48 | 47 |
| 49 // The number of ongoing IPC requests. | 48 // The number of ongoing IPC requests. |
| 50 size_t pending_text_request_size() const { | 49 size_t pending_text_request_size() const { |
| 51 return text_check_completions_.size(); | 50 return text_check_completions_.size(); |
| 52 } | 51 } |
| 53 | 52 |
| 54 // Replace shared spellcheck data. | 53 // Replace shared spellcheck data. |
| 55 void set_spellcheck(SpellCheck* spellcheck) { spellcheck_ = spellcheck; } | 54 void set_spellcheck(SpellCheck* spellcheck) { spellcheck_ = spellcheck; } |
| 56 | 55 |
| 57 // Enables document-wide spellchecking. | 56 // Enables document-wide spellchecking. |
| 58 void EnableSpellcheck(bool enabled); | 57 void EnableSpellcheck(bool enabled); |
| 59 | 58 |
| 60 // RenderViewObserver implementation. | 59 // RenderFrameObserver implementation. |
| 61 bool OnMessageReceived(const IPC::Message& message) override; | 60 bool OnMessageReceived(const IPC::Message& message) override; |
| 62 void FocusedNodeChanged(const blink::WebNode& node) override; | 61 void FocusedNodeChanged(const blink::WebNode& node) override; |
| 63 | 62 |
| 64 private: | 63 private: |
| 65 friend class TestingSpellCheckProvider; | 64 friend class TestingSpellCheckProvider; |
| 66 | 65 |
| 67 // Tries to satisfy a spell check request from the cache in |last_request_|. | 66 // Tries to satisfy a spell check request from the cache in |last_request_|. |
| 68 // Returns true (and cancels/finishes the completion) if it can, false | 67 // Returns true (and cancels/finishes the completion) if it can, false |
| 69 // if the provider should forward the query on. | 68 // if the provider should forward the query on. |
| 70 bool SatisfyRequestFromCache(const base::string16& text, | 69 bool SatisfyRequestFromCache(const base::string16& text, |
| 71 blink::WebTextCheckingCompletion* completion); | 70 blink::WebTextCheckingCompletion* completion); |
| 72 | 71 |
| 73 // RenderViewObserver implementation. | 72 // RenderFrameObserver implementation. |
| 74 void OnDestruct() override; | 73 void OnDestruct() override; |
| 75 | 74 |
| 76 // blink::WebTextCheckClient implementation. | 75 // blink::WebTextCheckClient implementation. |
| 77 void CheckSpelling( | 76 void CheckSpelling( |
| 78 const blink::WebString& text, | 77 const blink::WebString& text, |
| 79 int& offset, | 78 int& offset, |
| 80 int& length, | 79 int& length, |
| 81 blink::WebVector<blink::WebString>* optional_suggestions) override; | 80 blink::WebVector<blink::WebString>* optional_suggestions) override; |
| 82 void RequestCheckingOfText( | 81 void RequestCheckingOfText( |
| 83 const blink::WebString& text, | 82 const blink::WebString& text, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 111 base::string16 last_request_; | 110 base::string16 last_request_; |
| 112 blink::WebVector<blink::WebTextCheckingResult> last_results_; | 111 blink::WebVector<blink::WebTextCheckingResult> last_results_; |
| 113 | 112 |
| 114 // Weak pointer to shared (per RenderView) spellcheck data. | 113 // Weak pointer to shared (per RenderView) spellcheck data. |
| 115 SpellCheck* spellcheck_; | 114 SpellCheck* spellcheck_; |
| 116 | 115 |
| 117 DISALLOW_COPY_AND_ASSIGN(SpellCheckProvider); | 116 DISALLOW_COPY_AND_ASSIGN(SpellCheckProvider); |
| 118 }; | 117 }; |
| 119 | 118 |
| 120 #endif // COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_H_ | 119 #endif // COMPONENTS_SPELLCHECK_RENDERER_SPELLCHECK_PROVIDER_H_ |
| OLD | NEW |