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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_SPELLCHECK_HOST_H_ 6 #define CHROME_BROWSER_SPELLCHECK_HOST_H_ 7 #pragma once 8 9 #include <string> 10 #include <vector> 11 12 #include "base/memory/ref_counted.h" 13 #include "base/platform_file.h" 14 #include "content/browser/browser_thread.h" 15 16 class Profile; 17 class SpellCheckHostObserver; 18 19 namespace net { 20 class URLRequestContextGetter; 21 } 22 23 // An abstract interface that provides operations that controls the spellchecker 24 // attached to the browser. This class provides the operations listed below: 25 // * Adding a word to the user dictionary; 26 // * Retrieving the dictionary file (if it has one); 27 // * Retrieving the list of words in the user dictionary; 28 // * Retrieving the language used by the spellchecker. 29 // * Listing available languages for a Profile object; 30 // * Accepting an observer to reacting the state change of the object. 31 // You can also remove the observer from the SpellCheckHost object. 32 // The object should implement SpellCheckHostObserver interface. 33 // 34 // The following snippet describes how to use this class, 35 // std::vector<std::string> languages; 36 // SpellCheckHost::GetSpellCheckLanguages(profile_, &languages); 37 // spellcheck_host_ = SpellCheckHost::Create( 38 // observer, languages[0], req_getter); 39 // 40 // The class is intended to be owned by ProfileImpl so users should 41 // retrieve the instance via Profile::GetSpellCheckHost(). 42 // Users should not hold the reference over the function scope because 43 // the instance can be invalidated during the browser's lifecycle. 44 class SpellCheckHost 45 : public base::RefCountedThreadSafe<SpellCheckHost, 46 BrowserThread::DeleteOnFileThread> { 47 public: ~SpellCheckHost()48 virtual ~SpellCheckHost() {} 49 50 // Creates the instance of SpellCheckHost implementation object. 51 static scoped_refptr<SpellCheckHost> Create( 52 SpellCheckHostObserver* observer, 53 const std::string& language, 54 net::URLRequestContextGetter* request_context_getter); 55 56 // Clears an observer which is set on creation. 57 // Used to prevent calling back to a deleted object. 58 virtual void UnsetObserver() = 0; 59 60 // Adds the given word to the custom words list and inform renderer of the 61 // update. 62 virtual void AddWord(const std::string& word) = 0; 63 64 virtual const base::PlatformFile& GetDictionaryFile() const = 0; 65 66 virtual const std::vector<std::string>& GetCustomWords() const = 0; 67 68 virtual const std::string& GetLastAddedFile() const = 0; 69 70 virtual const std::string& GetLanguage() const = 0; 71 72 virtual bool IsUsingPlatformChecker() const = 0; 73 74 // This function computes a vector of strings which are to be displayed in 75 // the context menu over a text area for changing spell check languages. It 76 // returns the index of the current spell check language in the vector. 77 // TODO(port): this should take a vector of string16, but the implementation 78 // has some dependencies in l10n util that need porting first. 79 static int GetSpellCheckLanguages(Profile* profile, 80 std::vector<std::string>* languages); 81 }; 82 83 #endif // CHROME_BROWSER_SPELLCHECK_HOST_H_ 84