| 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 #include "components/spellcheck/renderer/spellcheck.h" | 5 #include "components/spellcheck/renderer/spellcheck.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "components/spellcheck/common/spellcheck_common.h" | 21 #include "components/spellcheck/common/spellcheck_common.h" |
| 22 #include "components/spellcheck/common/spellcheck_features.h" | 22 #include "components/spellcheck/common/spellcheck_features.h" |
| 23 #include "components/spellcheck/common/spellcheck_messages.h" | 23 #include "components/spellcheck/common/spellcheck_messages.h" |
| 24 #include "components/spellcheck/common/spellcheck_result.h" | 24 #include "components/spellcheck/common/spellcheck_result.h" |
| 25 #include "components/spellcheck/common/spellcheck_switches.h" | 25 #include "components/spellcheck/common/spellcheck_switches.h" |
| 26 #include "components/spellcheck/renderer/spellcheck_language.h" | 26 #include "components/spellcheck/renderer/spellcheck_language.h" |
| 27 #include "components/spellcheck/renderer/spellcheck_provider.h" | 27 #include "components/spellcheck/renderer/spellcheck_provider.h" |
| 28 #include "components/spellcheck/spellcheck_build_features.h" | 28 #include "components/spellcheck/spellcheck_build_features.h" |
| 29 #include "content/public/renderer/render_frame.h" |
| 30 #include "content/public/renderer/render_frame_visitor.h" |
| 29 #include "content/public/renderer/render_thread.h" | 31 #include "content/public/renderer/render_thread.h" |
| 30 #include "content/public/renderer/render_view.h" | 32 #include "content/public/renderer/render_view.h" |
| 31 #include "content/public/renderer/render_view_visitor.h" | 33 #include "content/public/renderer/render_view_visitor.h" |
| 32 #include "ipc/ipc_platform_file.h" | 34 #include "ipc/ipc_platform_file.h" |
| 33 #include "third_party/WebKit/public/platform/WebString.h" | 35 #include "third_party/WebKit/public/platform/WebString.h" |
| 34 #include "third_party/WebKit/public/platform/WebVector.h" | 36 #include "third_party/WebKit/public/platform/WebVector.h" |
| 35 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" | 37 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" |
| 36 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" | 38 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" |
| 37 #include "third_party/WebKit/public/web/WebTextDecorationType.h" | 39 #include "third_party/WebKit/public/web/WebTextDecorationType.h" |
| 38 #include "third_party/WebKit/public/web/WebView.h" | 40 #include "third_party/WebKit/public/web/WebView.h" |
| 39 | 41 |
| 40 using blink::WebVector; | 42 using blink::WebVector; |
| 41 using blink::WebString; | 43 using blink::WebString; |
| 42 using blink::WebTextCheckingResult; | 44 using blink::WebTextCheckingResult; |
| 43 using blink::WebTextDecorationType; | 45 using blink::WebTextDecorationType; |
| 44 | 46 |
| 45 namespace { | 47 namespace { |
| 46 const int kNoOffset = 0; | 48 const int kNoOffset = 0; |
| 47 const int kNoTag = 0; | 49 const int kNoTag = 0; |
| 48 | 50 |
| 49 class UpdateSpellcheckEnabled : public content::RenderViewVisitor { | 51 class UpdateSpellcheckEnabled : public content::RenderFrameVisitor { |
| 50 public: | 52 public: |
| 51 explicit UpdateSpellcheckEnabled(bool enabled) : enabled_(enabled) {} | 53 explicit UpdateSpellcheckEnabled(bool enabled) : enabled_(enabled) {} |
| 52 bool Visit(content::RenderView* render_view) override; | 54 bool Visit(content::RenderFrame* render_frame) override; |
| 53 | 55 |
| 54 private: | 56 private: |
| 55 bool enabled_; // New spellcheck-enabled state. | 57 bool enabled_; // New spellcheck-enabled state. |
| 56 DISALLOW_COPY_AND_ASSIGN(UpdateSpellcheckEnabled); | 58 DISALLOW_COPY_AND_ASSIGN(UpdateSpellcheckEnabled); |
| 57 }; | 59 }; |
| 58 | 60 |
| 59 bool UpdateSpellcheckEnabled::Visit(content::RenderView* render_view) { | 61 bool UpdateSpellcheckEnabled::Visit(content::RenderFrame* render_frame) { |
| 60 SpellCheckProvider* provider = SpellCheckProvider::Get(render_view); | 62 SpellCheckProvider* provider = SpellCheckProvider::Get(render_frame); |
| 61 DCHECK(provider); | 63 DCHECK(provider); |
| 62 provider->EnableSpellcheck(enabled_); | 64 provider->EnableSpellcheck(enabled_); |
| 63 return true; | 65 return true; |
| 64 } | 66 } |
| 65 | 67 |
| 66 class DocumentMarkersRemover : public content::RenderViewVisitor { | 68 class DocumentMarkersRemover : public content::RenderViewVisitor { |
| 67 public: | 69 public: |
| 68 explicit DocumentMarkersRemover(const std::set<std::string>& words); | 70 explicit DocumentMarkersRemover(const std::set<std::string>& words); |
| 69 ~DocumentMarkersRemover() override {} | 71 ~DocumentMarkersRemover() override {} |
| 70 bool Visit(content::RenderView* render_view) override; | 72 bool Visit(content::RenderView* render_view) override; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 custom_dictionary_.OnCustomDictionaryChanged(words_added, words_removed); | 219 custom_dictionary_.OnCustomDictionaryChanged(words_added, words_removed); |
| 218 if (words_added.empty()) | 220 if (words_added.empty()) |
| 219 return; | 221 return; |
| 220 DocumentMarkersRemover markersRemover(words_added); | 222 DocumentMarkersRemover markersRemover(words_added); |
| 221 content::RenderView::ForEach(&markersRemover); | 223 content::RenderView::ForEach(&markersRemover); |
| 222 } | 224 } |
| 223 | 225 |
| 224 void SpellCheck::OnEnableSpellCheck(bool enable) { | 226 void SpellCheck::OnEnableSpellCheck(bool enable) { |
| 225 spellcheck_enabled_ = enable; | 227 spellcheck_enabled_ = enable; |
| 226 UpdateSpellcheckEnabled updater(enable); | 228 UpdateSpellcheckEnabled updater(enable); |
| 227 content::RenderView::ForEach(&updater); | 229 content::RenderFrame::ForEach(&updater); |
| 228 } | 230 } |
| 229 | 231 |
| 230 // TODO(groby): Make sure we always have a spelling engine, even before | 232 // TODO(groby): Make sure we always have a spelling engine, even before |
| 231 // AddSpellcheckLanguage() is called. | 233 // AddSpellcheckLanguage() is called. |
| 232 void SpellCheck::AddSpellcheckLanguage(base::File file, | 234 void SpellCheck::AddSpellcheckLanguage(base::File file, |
| 233 const std::string& language) { | 235 const std::string& language) { |
| 234 languages_.push_back(base::MakeUnique<SpellcheckLanguage>()); | 236 languages_.push_back(base::MakeUnique<SpellcheckLanguage>()); |
| 235 languages_.back()->Init(std::move(file), language); | 237 languages_.back()->Init(std::move(file), language); |
| 236 } | 238 } |
| 237 | 239 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 | 501 |
| 500 textcheck_results->Assign(results); | 502 textcheck_results->Assign(results); |
| 501 } | 503 } |
| 502 | 504 |
| 503 bool SpellCheck::IsSpellcheckEnabled() { | 505 bool SpellCheck::IsSpellcheckEnabled() { |
| 504 #if defined(OS_ANDROID) | 506 #if defined(OS_ANDROID) |
| 505 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; | 507 if (!spellcheck::IsAndroidSpellCheckFeatureEnabled()) return false; |
| 506 #endif | 508 #endif |
| 507 return spellcheck_enabled_; | 509 return spellcheck_enabled_; |
| 508 } | 510 } |
| OLD | NEW |