OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/spellchecker/spellcheck_host_impl.h" | 5 #include "chrome/browser/spellchecker/spellcheck_host_impl.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/string_split.h" | 13 #include "base/string_split.h" |
14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" | 18 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
19 #include "chrome/browser/spellchecker/spellcheck_profile_provider.h" | 19 #include "chrome/browser/spellchecker/spellcheck_profile_provider.h" |
20 #include "chrome/browser/spellchecker/spellchecker_platform_engine.h" | 20 #include "chrome/browser/spellchecker/spellchecker_platform_engine.h" |
21 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
24 #include "chrome/common/spellcheck_common.h" | 24 #include "chrome/common/spellcheck_common.h" |
25 #include "chrome/common/spellcheck_messages.h" | 25 #include "chrome/common/spellcheck_messages.h" |
26 #include "content/browser/renderer_host/render_process_host.h" | |
27 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
28 #include "content/public/browser/notification_types.h" | 27 #include "content/public/browser/notification_types.h" |
| 28 #include "content/public/browser/render_process_host.h" |
29 #include "content/public/common/url_fetcher.h" | 29 #include "content/public/common/url_fetcher.h" |
30 #include "googleurl/src/gurl.h" | 30 #include "googleurl/src/gurl.h" |
31 #include "net/url_request/url_request_context_getter.h" | 31 #include "net/url_request/url_request_context_getter.h" |
32 #include "third_party/hunspell/google/bdict.h" | 32 #include "third_party/hunspell/google/bdict.h" |
33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
34 #if defined(OS_MACOSX) | 34 #if defined(OS_MACOSX) |
35 #include "base/metrics/histogram.h" | 35 #include "base/metrics/histogram.h" |
36 #endif | 36 #endif |
37 | 37 |
38 using content::BrowserThread; | 38 using content::BrowserThread; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 void SpellCheckHostImpl::UnsetProfile() { | 156 void SpellCheckHostImpl::UnsetProfile() { |
157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
158 | 158 |
159 profile_ = NULL; | 159 profile_ = NULL; |
160 request_context_getter_ = NULL; | 160 request_context_getter_ = NULL; |
161 fetcher_.reset(); | 161 fetcher_.reset(); |
162 registrar_.RemoveAll(); | 162 registrar_.RemoveAll(); |
163 } | 163 } |
164 | 164 |
165 void SpellCheckHostImpl::InitForRenderer(RenderProcessHost* process) { | 165 void SpellCheckHostImpl::InitForRenderer(content::RenderProcessHost* process) { |
166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
167 | 167 |
168 // Bug 103693: SpellCheckHostImpl and SpellCheckProfile should not | 168 // Bug 103693: SpellCheckHostImpl and SpellCheckProfile should not |
169 // depend on Profile interface. | 169 // depend on Profile interface. |
170 Profile* profile = Profile::FromBrowserContext(process->browser_context()); | 170 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
171 if (profile->GetSpellCheckHost() != this) | 171 if (profile->GetSpellCheckHost() != this) |
172 return; | 172 return; |
173 | 173 |
174 PrefService* prefs = profile->GetPrefs(); | 174 PrefService* prefs = profile->GetPrefs(); |
175 IPC::PlatformFileForTransit file = IPC::InvalidPlatformFileForTransit(); | 175 IPC::PlatformFileForTransit file = IPC::InvalidPlatformFileForTransit(); |
176 | 176 |
177 if (GetDictionaryFile() != base::kInvalidPlatformFileValue) { | 177 if (GetDictionaryFile() != base::kInvalidPlatformFileValue) { |
178 #if defined(OS_POSIX) | 178 #if defined(OS_POSIX) |
179 file = base::FileDescriptor(GetDictionaryFile(), false); | 179 file = base::FileDescriptor(GetDictionaryFile(), false); |
180 #elif defined(OS_WIN) | 180 #elif defined(OS_WIN) |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 void SpellCheckHostImpl::InformProfileOfInitializationWithCustomWords( | 283 void SpellCheckHostImpl::InformProfileOfInitializationWithCustomWords( |
284 CustomWordList* custom_words) { | 284 CustomWordList* custom_words) { |
285 // Non-null |custom_words| should be given only if the profile is available | 285 // Non-null |custom_words| should be given only if the profile is available |
286 // for simplifying the life-cycle management of the word list. | 286 // for simplifying the life-cycle management of the word list. |
287 DCHECK(profile_ || !custom_words); | 287 DCHECK(profile_ || !custom_words); |
288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
289 | 289 |
290 if (profile_) | 290 if (profile_) |
291 profile_->SpellCheckHostInitialized(custom_words); | 291 profile_->SpellCheckHostInitialized(custom_words); |
292 | 292 |
293 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 293 for (content::RenderProcessHost::iterator i( |
| 294 content::RenderProcessHost::AllHostsIterator()); |
294 !i.IsAtEnd(); i.Advance()) { | 295 !i.IsAtEnd(); i.Advance()) { |
295 RenderProcessHost* process = i.GetCurrentValue(); | 296 content::RenderProcessHost* process = i.GetCurrentValue(); |
296 if (process) | 297 if (process) |
297 InitForRenderer(process); | 298 InitForRenderer(process); |
298 } | 299 } |
299 } | 300 } |
300 | 301 |
301 void SpellCheckHostImpl::DownloadDictionary() { | 302 void SpellCheckHostImpl::DownloadDictionary() { |
302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
303 DCHECK(request_context_getter_); | 304 DCHECK(request_context_getter_); |
304 | 305 |
305 // Determine URL of file to download. | 306 // Determine URL of file to download. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 base::Bind(&SpellCheckHostImpl::SaveDictionaryData, | 378 base::Bind(&SpellCheckHostImpl::SaveDictionaryData, |
378 base::Unretained(this)), | 379 base::Unretained(this)), |
379 base::Bind(&SpellCheckHostImpl::SaveDictionaryDataComplete, | 380 base::Bind(&SpellCheckHostImpl::SaveDictionaryDataComplete, |
380 weak_ptr_factory_.GetWeakPtr())); | 381 weak_ptr_factory_.GetWeakPtr())); |
381 } | 382 } |
382 | 383 |
383 void SpellCheckHostImpl::Observe(int type, | 384 void SpellCheckHostImpl::Observe(int type, |
384 const content::NotificationSource& source, | 385 const content::NotificationSource& source, |
385 const content::NotificationDetails& details) { | 386 const content::NotificationDetails& details) { |
386 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_CREATED); | 387 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_CREATED); |
387 RenderProcessHost* process = content::Source<RenderProcessHost>(source).ptr(); | 388 content::RenderProcessHost* process = |
| 389 content::Source<content::RenderProcessHost>(source).ptr(); |
388 InitForRenderer(process); | 390 InitForRenderer(process); |
389 } | 391 } |
390 | 392 |
391 void SpellCheckHostImpl::SaveDictionaryData() { | 393 void SpellCheckHostImpl::SaveDictionaryData() { |
392 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
393 | 395 |
394 // To prevent corrupted dictionary data from causing a renderer crash, scan | 396 // To prevent corrupted dictionary data from causing a renderer crash, scan |
395 // the dictionary data and verify it is sane before save it to a file. | 397 // the dictionary data and verify it is sane before save it to a file. |
396 bool verified = hunspell::BDict::Verify(data_.data(), data_.size()); | 398 bool verified = hunspell::BDict::Verify(data_.data(), data_.size()); |
397 if (metrics_) | 399 if (metrics_) |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 return language_; | 473 return language_; |
472 } | 474 } |
473 | 475 |
474 bool SpellCheckHostImpl::IsUsingPlatformChecker() const { | 476 bool SpellCheckHostImpl::IsUsingPlatformChecker() const { |
475 return use_platform_spellchecker_; | 477 return use_platform_spellchecker_; |
476 } | 478 } |
477 | 479 |
478 void SpellCheckHostImpl::AddWordComplete(const std::string& word) { | 480 void SpellCheckHostImpl::AddWordComplete(const std::string& word) { |
479 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
480 | 482 |
481 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 483 for (content::RenderProcessHost::iterator i( |
| 484 content::RenderProcessHost::AllHostsIterator()); |
482 !i.IsAtEnd(); i.Advance()) { | 485 !i.IsAtEnd(); i.Advance()) { |
483 i.GetCurrentValue()->Send(new SpellCheckMsg_WordAdded(word)); | 486 i.GetCurrentValue()->Send(new SpellCheckMsg_WordAdded(word)); |
484 } | 487 } |
485 } | 488 } |
OLD | NEW |