Chromium Code Reviews| 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) |
|
satorux1
2011/01/11 07:04:18
Having #ifdef is not desirable. What about filing
| |
| 11 #include <dbus/dbus-glib-lowlevel.h> // for dbus_g_connection_get_connection. | 11 #include <dbus/dbus-glib-lowlevel.h> // for dbus_g_connection_get_connection. |
| 12 #endif | 12 #endif |
| 13 #include <ibus.h> | 13 #include <ibus.h> |
| 14 | 14 |
| 15 #include <algorithm> // for std::reverse. | 15 #include <algorithm> // for std::reverse. |
| 16 #include <cstdio> | 16 #include <cstdio> |
| 17 #include <cstring> // for std::strcmp. | 17 #include <cstring> // for std::strcmp. |
| 18 #include <set> | 18 #include <set> |
| 19 #include <sstream> | 19 #include <sstream> |
| 20 #include <stack> | 20 #include <stack> |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 | 453 |
| 454 // Restores IBus and DBus connections if they are not ready. | 454 // Restores IBus and DBus connections if they are not ready. |
| 455 void MaybeRestoreConnections() { | 455 void MaybeRestoreConnections() { |
| 456 MaybeCreateIBus(); | 456 MaybeCreateIBus(); |
| 457 MaybeRestoreIBusConfig(); | 457 MaybeRestoreIBusConfig(); |
| 458 #if !IBUS_CHECK_VERSION(1, 3, 99) | 458 #if !IBUS_CHECK_VERSION(1, 3, 99) |
| 459 MaybeRestoreDBus(); | 459 MaybeRestoreDBus(); |
| 460 #endif | 460 #endif |
| 461 } | 461 } |
| 462 | 462 |
| 463 // Called by cros API ChromeOSStopInputMethodProcess(). | |
| 464 bool StopInputMethodProcess() { | |
| 465 #if IBUS_CHECK_VERSION(1, 3, 99) | |
| 466 if (!IBusConnectionIsAlive()) { | |
| 467 LOG(ERROR) << "StopInputMethodProcess: IBus connection is not alive"; | |
| 468 return false; | |
| 469 } | |
| 470 ibus_bus_exit(ibus_, FALSE /* do not restart */); | |
| 471 if (ibus_config_) { | |
| 472 // Release |ibus_config_| to make sure next IBusConnectionIsAlive() call | |
| 473 // will return false. | |
| 474 g_object_unref(ibus_config_); | |
| 475 ibus_config_ = NULL; | |
| 476 } | |
| 477 return true; | |
| 478 #else | |
| 479 // For ibus-1.3, we don't implement the API and just return false since | |
| 480 // libcros's ibus-1.3 support will be removed soon. Chrome will use the | |
| 481 // kill system call to terminate the daemon. | |
| 482 return false; | |
| 483 #endif | |
| 484 } | |
| 485 | |
| 463 // InputMethodType is used for GetInputMethods(). | 486 // InputMethodType is used for GetInputMethods(). |
| 464 enum InputMethodType { | 487 enum InputMethodType { |
| 465 kActiveInputMethods, // Get active input methods. | 488 kActiveInputMethods, // Get active input methods. |
| 466 kSupportedInputMethods, // Get supported input methods. | 489 kSupportedInputMethods, // Get supported input methods. |
| 467 }; | 490 }; |
| 468 | 491 |
| 469 // Called by cros API ChromeOSGet(Active|Supported)InputMethods(). | 492 // Called by cros API ChromeOSGet(Active|Supported)InputMethods(). |
| 470 // Returns a list of input methods that are currently active or supported | 493 // Returns a list of input methods that are currently active or supported |
| 471 // depending on |mode|. Returns NULL on error. | 494 // depending on |mode|. Returns NULL on error. |
| 472 InputMethodDescriptors* GetInputMethods(InputMethodType type) { | 495 InputMethodDescriptors* GetInputMethods(InputMethodType type) { |
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1624 } | 1647 } |
| 1625 | 1648 |
| 1626 // TODO(yusukes): remove the function. | 1649 // TODO(yusukes): remove the function. |
| 1627 extern "C" | 1650 extern "C" |
| 1628 void ChromeOSDisconnectInputMethodStatus( | 1651 void ChromeOSDisconnectInputMethodStatus( |
| 1629 InputMethodStatusConnection* connection) { | 1652 InputMethodStatusConnection* connection) { |
| 1630 LOG(INFO) << "DisconnectInputMethodStatus (NOP)"; | 1653 LOG(INFO) << "DisconnectInputMethodStatus (NOP)"; |
| 1631 } | 1654 } |
| 1632 | 1655 |
| 1633 extern "C" | 1656 extern "C" |
| 1657 bool ChromeOSStopInputMethodProcess(InputMethodStatusConnection* connection) { | |
| 1658 g_return_val_if_fail(connection, false); | |
| 1659 return connection->StopInputMethodProcess(); | |
| 1660 } | |
| 1661 | |
| 1662 extern "C" | |
| 1634 InputMethodDescriptors* ChromeOSGetActiveInputMethods( | 1663 InputMethodDescriptors* ChromeOSGetActiveInputMethods( |
| 1635 InputMethodStatusConnection* connection) { | 1664 InputMethodStatusConnection* connection) { |
| 1636 g_return_val_if_fail(connection, NULL); | 1665 g_return_val_if_fail(connection, NULL); |
| 1637 connection->MaybeRestoreConnections(); | 1666 connection->MaybeRestoreConnections(); |
| 1638 // Pass ownership to a caller. Note: GetInputMethods() might return NULL. | 1667 // Pass ownership to a caller. Note: GetInputMethods() might return NULL. |
| 1639 return connection->GetInputMethods( | 1668 return connection->GetInputMethods( |
| 1640 InputMethodStatusConnection::kActiveInputMethods); | 1669 InputMethodStatusConnection::kActiveInputMethods); |
| 1641 } | 1670 } |
| 1642 | 1671 |
| 1643 extern "C" | 1672 extern "C" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1714 InputMethodStatusConnection* connection) { | 1743 InputMethodStatusConnection* connection) { |
| 1715 g_return_val_if_fail(connection, false); | 1744 g_return_val_if_fail(connection, false); |
| 1716 const bool is_connected = connection->IBusConnectionIsAlive(); | 1745 const bool is_connected = connection->IBusConnectionIsAlive(); |
| 1717 if (!is_connected) { | 1746 if (!is_connected) { |
| 1718 LOG(WARNING) << "ChromeOSInputMethodStatusConnectionIsAlive: NOT alive"; | 1747 LOG(WARNING) << "ChromeOSInputMethodStatusConnectionIsAlive: NOT alive"; |
| 1719 } | 1748 } |
| 1720 return is_connected; | 1749 return is_connected; |
| 1721 } | 1750 } |
| 1722 | 1751 |
| 1723 } // namespace chromeos | 1752 } // namespace chromeos |
| OLD | NEW |