| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 "chromeos_input_method.h" | 5 #include "chromeos_input_method.h" | 
| 6 #include "chromeos_input_method_whitelist.h" | 6 #include "chromeos_input_method_whitelist.h" | 
| 7 | 7 | 
| 8 #include <ibusversion.h> | 8 #include <ibusversion.h> | 
| 9 | 9 | 
| 10 #if !IBUS_CHECK_VERSION(1, 3, 99) | 10 #if !IBUS_CHECK_VERSION(1, 3, 99) | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
| 23 #include "base/singleton.h" | 23 #include "base/singleton.h" | 
| 24 #if !IBUS_CHECK_VERSION(1, 3, 99) | 24 #if !IBUS_CHECK_VERSION(1, 3, 99) | 
| 25 #include "chromeos/dbus/dbus.h" | 25 #include "chromeos/dbus/dbus.h" | 
| 26 #include "chromeos/glib/object.h" | 26 #include "chromeos/glib/object.h" | 
| 27 #endif | 27 #endif | 
| 28 #include "ibus_input_methods.h" | 28 #include "ibus_input_methods.h" | 
| 29 | 29 | 
| 30 namespace { | 30 namespace { | 
| 31 | 31 | 
| 32 // TODO(yusukes): Remove all code for ibus-1.3 once we finish migrating to 1.4. | 32 // TODO(yusukes): Remove all code for ibus-1.3 once we finish migrating to 1.4. | 
|  | 33 // http://crosbug.com/10838 | 
| 33 #if !IBUS_CHECK_VERSION(1, 3, 99) | 34 #if !IBUS_CHECK_VERSION(1, 3, 99) | 
| 34 #define ibus_engine_desc_get_name(d) ((d)->name) | 35 #define ibus_engine_desc_get_name(d) ((d)->name) | 
| 35 #define ibus_engine_desc_get_longname(d) ((d)->longname) | 36 #define ibus_engine_desc_get_longname(d) ((d)->longname) | 
| 36 #define ibus_engine_desc_get_layout(d) ((d)->layout) | 37 #define ibus_engine_desc_get_layout(d) ((d)->layout) | 
| 37 #define ibus_engine_desc_get_language(d) ((d)->language) | 38 #define ibus_engine_desc_get_language(d) ((d)->language) | 
| 38 | 39 | 
| 39 const char kCandidateWindowService[] = "org.freedesktop.IBus.Panel"; | 40 const char kCandidateWindowService[] = "org.freedesktop.IBus.Panel"; | 
| 40 const char kCandidateWindowObjectPath[] = "/org/chromium/Chrome/LanguageBar"; | 41 const char kCandidateWindowObjectPath[] = "/org/chromium/Chrome/LanguageBar"; | 
| 41 const char kCandidateWindowInterface[] = "org.freedesktop.IBus.Panel"; | 42 const char kCandidateWindowInterface[] = "org.freedesktop.IBus.Panel"; | 
| 42 #endif | 43 #endif | 
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 453 | 454 | 
| 454   // Restores IBus and DBus connections if they are not ready. | 455   // Restores IBus and DBus connections if they are not ready. | 
| 455   void MaybeRestoreConnections() { | 456   void MaybeRestoreConnections() { | 
| 456     MaybeCreateIBus(); | 457     MaybeCreateIBus(); | 
| 457     MaybeRestoreIBusConfig(); | 458     MaybeRestoreIBusConfig(); | 
| 458 #if !IBUS_CHECK_VERSION(1, 3, 99) | 459 #if !IBUS_CHECK_VERSION(1, 3, 99) | 
| 459     MaybeRestoreDBus(); | 460     MaybeRestoreDBus(); | 
| 460 #endif | 461 #endif | 
| 461   } | 462   } | 
| 462 | 463 | 
|  | 464   // Called by cros API ChromeOSStopInputMethodProcess(). | 
|  | 465   bool StopInputMethodProcess() { | 
|  | 466 #if IBUS_CHECK_VERSION(1, 3, 99) | 
|  | 467     if (!IBusConnectionIsAlive()) { | 
|  | 468       LOG(ERROR) << "StopInputMethodProcess: IBus connection is not alive"; | 
|  | 469       return false; | 
|  | 470     } | 
|  | 471     ibus_bus_exit(ibus_, FALSE /* do not restart */); | 
|  | 472     if (ibus_config_) { | 
|  | 473       // Release |ibus_config_| to make sure next IBusConnectionIsAlive() call | 
|  | 474       // will return false. | 
|  | 475       g_object_unref(ibus_config_); | 
|  | 476       ibus_config_ = NULL; | 
|  | 477     } | 
|  | 478     return true; | 
|  | 479 #else | 
|  | 480     // For ibus-1.3, we don't implement the API and just return false since | 
|  | 481     // libcros's ibus-1.3 support will be removed soon. Chrome will use the | 
|  | 482     // kill system call to terminate the daemon. | 
|  | 483     return false; | 
|  | 484 #endif | 
|  | 485   } | 
|  | 486 | 
| 463   // InputMethodType is used for GetInputMethods(). | 487   // InputMethodType is used for GetInputMethods(). | 
| 464   enum InputMethodType { | 488   enum InputMethodType { | 
| 465     kActiveInputMethods,  // Get active input methods. | 489     kActiveInputMethods,  // Get active input methods. | 
| 466     kSupportedInputMethods,  // Get supported input methods. | 490     kSupportedInputMethods,  // Get supported input methods. | 
| 467   }; | 491   }; | 
| 468 | 492 | 
| 469   // Called by cros API ChromeOSGet(Active|Supported)InputMethods(). | 493   // Called by cros API ChromeOSGet(Active|Supported)InputMethods(). | 
| 470   // Returns a list of input methods that are currently active or supported | 494   // Returns a list of input methods that are currently active or supported | 
| 471   // depending on |mode|. Returns NULL on error. | 495   // depending on |mode|. Returns NULL on error. | 
| 472   InputMethodDescriptors* GetInputMethods(InputMethodType type) { | 496   InputMethodDescriptors* GetInputMethods(InputMethodType type) { | 
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1624 } | 1648 } | 
| 1625 | 1649 | 
| 1626 // TODO(yusukes): remove the function. | 1650 // TODO(yusukes): remove the function. | 
| 1627 extern "C" | 1651 extern "C" | 
| 1628 void ChromeOSDisconnectInputMethodStatus( | 1652 void ChromeOSDisconnectInputMethodStatus( | 
| 1629     InputMethodStatusConnection* connection) { | 1653     InputMethodStatusConnection* connection) { | 
| 1630   LOG(INFO) << "DisconnectInputMethodStatus (NOP)"; | 1654   LOG(INFO) << "DisconnectInputMethodStatus (NOP)"; | 
| 1631 } | 1655 } | 
| 1632 | 1656 | 
| 1633 extern "C" | 1657 extern "C" | 
|  | 1658 bool ChromeOSStopInputMethodProcess(InputMethodStatusConnection* connection) { | 
|  | 1659   g_return_val_if_fail(connection, false); | 
|  | 1660   return connection->StopInputMethodProcess(); | 
|  | 1661 } | 
|  | 1662 | 
|  | 1663 extern "C" | 
| 1634 InputMethodDescriptors* ChromeOSGetActiveInputMethods( | 1664 InputMethodDescriptors* ChromeOSGetActiveInputMethods( | 
| 1635     InputMethodStatusConnection* connection) { | 1665     InputMethodStatusConnection* connection) { | 
| 1636   g_return_val_if_fail(connection, NULL); | 1666   g_return_val_if_fail(connection, NULL); | 
| 1637   connection->MaybeRestoreConnections(); | 1667   connection->MaybeRestoreConnections(); | 
| 1638   // Pass ownership to a caller. Note: GetInputMethods() might return NULL. | 1668   // Pass ownership to a caller. Note: GetInputMethods() might return NULL. | 
| 1639   return connection->GetInputMethods( | 1669   return connection->GetInputMethods( | 
| 1640       InputMethodStatusConnection::kActiveInputMethods); | 1670       InputMethodStatusConnection::kActiveInputMethods); | 
| 1641 } | 1671 } | 
| 1642 | 1672 | 
| 1643 extern "C" | 1673 extern "C" | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1714     InputMethodStatusConnection* connection) { | 1744     InputMethodStatusConnection* connection) { | 
| 1715   g_return_val_if_fail(connection, false); | 1745   g_return_val_if_fail(connection, false); | 
| 1716   const bool is_connected = connection->IBusConnectionIsAlive(); | 1746   const bool is_connected = connection->IBusConnectionIsAlive(); | 
| 1717   if (!is_connected) { | 1747   if (!is_connected) { | 
| 1718     LOG(WARNING) << "ChromeOSInputMethodStatusConnectionIsAlive: NOT alive"; | 1748     LOG(WARNING) << "ChromeOSInputMethodStatusConnectionIsAlive: NOT alive"; | 
| 1719   } | 1749   } | 
| 1720   return is_connected; | 1750   return is_connected; | 
| 1721 } | 1751 } | 
| 1722 | 1752 | 
| 1723 }  // namespace chromeos | 1753 }  // namespace chromeos | 
| OLD | NEW | 
|---|