summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/input_method/candidate_window_main.cc
blob: a8bc0427f087d39f64cae2de9dd60130e5cfd57d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/input_method/candidate_window.h"

#include <gtk/gtk.h>

#include <string>

#include "app/app_paths.h"
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/process_util.h"
#include "chrome/browser/chromeos/cros/cros_library_loader.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "grit/app_locale_settings.h"
#include "third_party/cros/chromeos_cros_api.h"
#include "views/focus/accelerator_handler.h"

int main(int argc, char** argv) {
  // Initialize gtk stuff.
  g_thread_init(NULL);
  g_type_init();
  gtk_init(&argc, &argv);

  // Initialize Chrome stuff.
  base::AtExitManager exit_manager;
  base::EnableTerminationOnHeapCorruption();
  app::RegisterPathProvider();
  CommandLine::Init(argc, argv);

  // Check if the UI language code is passed from the command line,
  // otherwise, default to "en-US".
  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
  std::string ui_language_code =
      command_line.GetSwitchValueASCII(switches::kCandidateWindowLang);
  if (ui_language_code.empty()) {
    ui_language_code = "en-US";
  }
  ResourceBundle::InitSharedInstance(ui_language_code);

  // Change the UI font if needed.
  const std::string font_name =
      l10n_util::GetStringUTF8(IDS_UI_FONT_FAMILY_CROS);
  // The font name should not be empty here, but just in case.
  if (font_name != "default" && !font_name.empty()) {
    // Don't use gtk_util::SetGtkFont() in chrome/browser/gtk not to
    // introduce a dependency to it.
    g_object_set(gtk_settings_get_default(),
                 "gtk-font-name", font_name.c_str(), NULL);
  }

  // Load libcros.
  chrome::RegisterPathProvider();  // for libcros.so.
  chromeos::CrosLibraryLoader lib_loader;
  std::string error_string;
  CHECK(lib_loader.Load(&error_string))
      << "Failed to load libcros, " << error_string;

  // Create the main message loop.
  MessageLoop main_message_loop(MessageLoop::TYPE_UI);

  // Create the candidate window controller.
  chromeos::CandidateWindowController controller;
  if (!controller.Init()) {
    return 1;
  }

  // Start the main loop.
  views::AcceleratorHandler accelerator_handler;
  MessageLoopForUI::current()->Run(&accelerator_handler);

  return 0;
}