OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_HYPHENATOR_HYPHENATOR_MESSAGE_FILTER_H_ | |
6 #define CONTENT_BROWSER_HYPHENATOR_HYPHENATOR_MESSAGE_FILTER_H_ | |
7 | |
8 #include "base/compiler_specific.h" | |
9 #include "base/files/file_path.h" | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "base/platform_file.h" | |
12 #include "content/common/content_export.h" | |
13 #include "content/public/browser/browser_message_filter.h" | |
14 | |
15 namespace content { | |
16 class RenderProcessHost; | |
17 | |
18 // This class is a message filter that handles a HyphenatorHost message. When | |
19 // this class receives a HyphenatorHostMsg_OpenDictionary message, it opens the | |
20 // specified dictionary and sends its file handle. | |
21 class CONTENT_EXPORT HyphenatorMessageFilter : public BrowserMessageFilter { | |
22 public: | |
23 explicit HyphenatorMessageFilter(RenderProcessHost* render_process_host); | |
24 | |
25 // Changes the directory that includes dictionary files. This function | |
26 // provides a method that allows applications to change the directory | |
27 // containing hyphenation dictionaries. When a renderer requests a hyphnation | |
28 // dictionary, this class appends a file name (which consists of a locale, a | |
29 // version number, and an extension) and use it as a dictionary file. | |
30 void SetDictionaryBase(const base::FilePath& directory); | |
31 | |
32 // BrowserMessageFilter implementation. | |
33 virtual void OverrideThreadForMessage( | |
34 const IPC::Message& message, | |
35 BrowserThread::ID* thread) OVERRIDE; | |
36 virtual bool OnMessageReceived(const IPC::Message& message, | |
37 bool* message_was_ok) OVERRIDE; | |
38 | |
39 private: | |
40 friend class TestHyphenatorMessageFilter; | |
41 | |
42 virtual ~HyphenatorMessageFilter(); | |
43 | |
44 virtual void OnOpenDictionary(const string16& locale); | |
45 | |
46 // Opens a hyphenation dictionary for the specified locale. When this locale | |
47 // is an empty string, this function uses US English ("en-US"). | |
48 void OpenDictionary(const string16& locale); | |
49 | |
50 // Sends the hyphenation dictionary file to a renderer in response to its | |
51 // request. If this class cannot open the specified dictionary file, this | |
52 // function sends an IPC::InvalidPlatformFileForTransit value to tell the | |
53 // renderer that a browser cannot open the file. | |
54 void SendDictionary(); | |
55 | |
56 // The RenderProcessHost object that owns this filter. This class uses this | |
57 // object to retrieve the process handle used for creating | |
58 // PlatformFileForTransit objects. | |
59 RenderProcessHost* render_process_host_; | |
60 | |
61 // The directory that includes dictionary files. The default value is the | |
62 // directory containing the executable file. | |
63 base::FilePath dictionary_base_; | |
64 | |
65 // A cached dictionary file. | |
66 base::PlatformFile dictionary_file_; | |
67 | |
68 base::WeakPtrFactory<HyphenatorMessageFilter> weak_factory_; | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(HyphenatorMessageFilter); | |
71 }; | |
72 | |
73 } // namespace content | |
74 | |
75 #endif // CONTENT_BROWSER_HYPHENATOR_HYPHENATOR_MESSAGE_FILTER_H_ | |
OLD | NEW |