| 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/hunspell_engine.h" | 5 #include "components/spellcheck/renderer/hunspell_engine.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/files/memory_mapped_file.h" | 12 #include "base/files/memory_mapped_file.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "components/spellcheck/common/spellcheck.mojom.h" |
| 14 #include "components/spellcheck/common/spellcheck_common.h" | 15 #include "components/spellcheck/common/spellcheck_common.h" |
| 15 #include "components/spellcheck/common/spellcheck_messages.h" | 16 #include "components/spellcheck/common/spellcheck_messages.h" |
| 16 #include "components/spellcheck/spellcheck_build_features.h" | 17 #include "components/spellcheck/spellcheck_build_features.h" |
| 18 #include "content/public/common/service_names.mojom.h" |
| 17 #include "content/public/renderer/render_thread.h" | 19 #include "content/public/renderer/render_thread.h" |
| 20 #include "services/service_manager/public/cpp/connector.h" |
| 18 #include "third_party/hunspell/src/hunspell/hunspell.hxx" | 21 #include "third_party/hunspell/src/hunspell/hunspell.hxx" |
| 19 | 22 |
| 20 using content::RenderThread; | 23 using content::RenderThread; |
| 21 | 24 |
| 22 namespace { | 25 namespace { |
| 23 // Maximum length of words we actually check. | 26 // Maximum length of words we actually check. |
| 24 // 64 is the observed limits for OSX system checker. | 27 // 64 is the observed limits for OSX system checker. |
| 25 const size_t kMaxCheckedLen = 64; | 28 const size_t kMaxCheckedLen = 64; |
| 26 | 29 |
| 27 // Maximum length of words we provide suggestions for. | 30 // Maximum length of words we provide suggestions for. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // Populate the vector of WideStrings. | 115 // Populate the vector of WideStrings. |
| 113 for (size_t i = 0; i < suggestions.size(); ++i) { | 116 for (size_t i = 0; i < suggestions.size(); ++i) { |
| 114 if (i < spellcheck::kMaxSuggestions) | 117 if (i < spellcheck::kMaxSuggestions) |
| 115 optional_suggestions->push_back(base::UTF8ToUTF16(suggestions[i])); | 118 optional_suggestions->push_back(base::UTF8ToUTF16(suggestions[i])); |
| 116 } | 119 } |
| 117 } | 120 } |
| 118 | 121 |
| 119 bool HunspellEngine::InitializeIfNeeded() { | 122 bool HunspellEngine::InitializeIfNeeded() { |
| 120 if (!initialized_ && !dictionary_requested_) { | 123 if (!initialized_ && !dictionary_requested_) { |
| 121 // RenderThread will not exist in test. | 124 // RenderThread will not exist in test. |
| 122 if (RenderThread::Get()) | 125 if (RenderThread::Get()) { |
| 123 RenderThread::Get()->Send(new SpellCheckHostMsg_RequestDictionary); | 126 spellcheck::mojom::SpellCheckHostPtr spellcheck_host; |
| 127 RenderThread::Get()->GetConnector()->BindInterface( |
| 128 content::mojom::kBrowserServiceName, &spellcheck_host); |
| 129 spellcheck_host->RequestDictionary(); |
| 130 } |
| 124 dictionary_requested_ = true; | 131 dictionary_requested_ = true; |
| 125 return true; | 132 return true; |
| 126 } | 133 } |
| 127 | 134 |
| 128 // Don't initialize if hunspell is disabled. | 135 // Don't initialize if hunspell is disabled. |
| 129 if (file_.IsValid()) | 136 if (file_.IsValid()) |
| 130 InitializeHunspell(); | 137 InitializeHunspell(); |
| 131 | 138 |
| 132 return !initialized_; | 139 return !initialized_; |
| 133 } | 140 } |
| 134 | 141 |
| 135 bool HunspellEngine::IsEnabled() { | 142 bool HunspellEngine::IsEnabled() { |
| 136 return hunspell_enabled_; | 143 return hunspell_enabled_; |
| 137 } | 144 } |
| OLD | NEW |