1 // Copyright 2010-2018, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 //     * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 //     * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 //     * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 #ifdef OS_WIN
31 #include <windows.h>
32 #elif defined(ENABLE_GTK_RENDERER)
33 #include <gtk/gtk.h>
34 #endif  // OS_WIN, ENABLE_GTK_RENDERER
35 
36 #include "base/crash_report_handler.h"
37 #include "base/flags.h"
38 #include "base/init_mozc.h"
39 #include "base/run_level.h"
40 #include "base/system_util.h"
41 #include "base/util.h"
42 #include "config/stats_config_util.h"
43 
44 #ifdef OS_WIN
45 #include "base/win_util.h"
46 #include "base/winmain.h"
47 #include "renderer/win32/win32_server.h"
48 #elif defined(OS_MACOSX)
49 #include "renderer/mac/CandidateController.h"
50 #include "renderer/mac/mac_server.h"
51 #include "renderer/mac/mac_server_send_command.h"
52 #elif defined(ENABLE_GTK_RENDERER)
53 #include "renderer/renderer_client.h"
54 #include "renderer/table_layout.h"
55 #include "renderer/unix/cairo_factory.h"
56 #include "renderer/unix/candidate_window.h"
57 #include "renderer/unix/draw_tool.h"
58 #include "renderer/unix/font_spec.h"
59 #include "renderer/unix/gtk_wrapper.h"
60 #include "renderer/unix/infolist_window.h"
61 #include "renderer/unix/text_renderer.h"
62 #include "renderer/unix/unix_renderer.h"
63 #include "renderer/unix/unix_server.h"
64 #include "renderer/unix/window_manager.h"
65 #endif  // OS_WIN, OS_MACOSX, ENABLE_GTK_RENDERER
66 
67 DECLARE_bool(restricted);
68 
main(int argc,char * argv[])69 int main(int argc, char *argv[]) {
70   const mozc::RunLevel::RunLevelType run_level =
71       mozc::RunLevel::GetRunLevel(mozc::RunLevel::RENDERER);
72 
73   if (run_level >= mozc::RunLevel::DENY) {
74     return -1;
75   }
76 
77 #ifdef OS_WIN
78   mozc::ScopedCOMInitializer com_initializer;
79 #elif defined(ENABLE_GTK_RENDERER)
80   gtk_set_locale();
81 #if !GLIB_CHECK_VERSION(2, 31, 0)
82   // There are not g_thread_init function in glib>=2.31.0.
83   //http://developer.gnome.org/glib/2.31/glib-Deprecated-Thread-APIs.html#g-thread-init
84   g_thread_init(NULL);
85 #endif  // GLIB>=2.31.0
86   gdk_threads_init();
87   gtk_init(&argc, &argv);
88 #endif  // OS_WIN, ENABLE_GTK_RENDERER
89 
90   mozc::SystemUtil::DisableIME();
91 
92   // restricted mode
93   if (run_level == mozc::RunLevel::RESTRICTED) {
94     FLAGS_restricted = true;
95   }
96 
97   if (mozc::config::StatsConfigUtil::IsEnabled()) {
98     mozc::CrashReportHandler::Initialize(false);
99   }
100   mozc::InitMozc(argv[0], &argc, &argv, false);
101 
102   int result_code = 0;
103 
104   {
105 #ifdef OS_WIN
106     mozc::renderer::win32::Win32Server server;
107     server.SetRendererInterface(&server);
108     result_code = server.StartServer();
109 #elif defined(OS_MACOSX)
110     mozc::renderer::mac::MacServer::Init();
111     mozc::renderer::mac::MacServer server(argc, (const char **)argv);
112     mozc::renderer::mac::CandidateController renderer;
113     mozc::renderer::mac::MacServerSendCommand send_command;
114     server.SetRendererInterface(&renderer);
115     renderer.SetSendCommandInterface(&send_command);
116     result_code = server.StartServer();
117 #elif defined(ENABLE_GTK_RENDERER)
118     mozc::renderer::gtk::UnixRenderer renderer(
119         new mozc::renderer::gtk::WindowManager(
120             new mozc::renderer::gtk::CandidateWindow(
121                 new mozc::renderer::TableLayout(),
122                 new mozc::renderer::gtk::TextRenderer(
123                     new mozc::renderer::gtk::FontSpec(
124                         new mozc::renderer::gtk::GtkWrapper())),
125                 new mozc::renderer::gtk::DrawTool(),
126                 new mozc::renderer::gtk::GtkWrapper(),
127                 new mozc::renderer::gtk::CairoFactory()),
128             new mozc::renderer::gtk::InfolistWindow(
129                 new mozc::renderer::gtk::TextRenderer(
130                     new mozc::renderer::gtk::FontSpec(
131                         new mozc::renderer::gtk::GtkWrapper())),
132                 new mozc::renderer::gtk::DrawTool(),
133                 new mozc::renderer::gtk::GtkWrapper(),
134                 new mozc::renderer::gtk::CairoFactory()),
135             new mozc::renderer::gtk::GtkWrapper()));
136     mozc::renderer::gtk::UnixServer server(
137         new mozc::renderer::gtk::GtkWrapper());
138     server.OpenPipe();
139     renderer.Initialize();
140     server.SetRendererInterface(&renderer);
141     result_code = server.StartServer();
142 #endif  // OS_WIN, OS_MACOSX, ENABLE_GTK_RENDERER
143   }
144 
145   return result_code;
146 }
147