Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chromeos / ime / component_extension_ime_manager.h
index 2685ee8..ee00fb2 100644 (file)
@@ -5,6 +5,9 @@
 #ifndef CHROMEOS_IME_COMPONENT_EXTENSION_IME_MANAGER_H_
 #define CHROMEOS_IME_COMPONENT_EXTENSION_IME_MANAGER_H_
 
+#include <map>
+#include <set>
+
 #include "base/files/file_path.h"
 #include "base/memory/scoped_ptr.h"
 #include "base/observer_list.h"
@@ -22,10 +25,11 @@ struct CHROMEOS_EXPORT ComponentExtensionEngine {
   std::vector<std::string> language_codes;  // The engine's language(ex. "en").
   std::string description;  // The engine description.
   std::vector<std::string> layouts;  // The list of keyboard layout of engine.
+  GURL options_page_url; // an URL to option page.
+  GURL input_view_url; // an URL to input view page.
 };
 
 // Represents a component extension IME.
-// TODO(nona): Use GURL for |option_page_url| instead of string.
 struct CHROMEOS_EXPORT ComponentExtensionIME {
   ComponentExtensionIME();
   ~ComponentExtensionIME();
@@ -53,20 +57,13 @@ class CHROMEOS_EXPORT ComponentExtensionIMEManagerDelegate {
                     const base::FilePath& path) = 0;
 
   // Unloads component extension IME associated with |extension_id|.
-  // Returns false if it fails, otherwise returns true;
-  virtual bool Unload(const std::string& extension_id,
+  virtual void Unload(const std::string& extension_id,
                       const base::FilePath& path) = 0;
 };
 
 // This class manages component extension input method.
 class CHROMEOS_EXPORT ComponentExtensionIMEManager {
  public:
-  class Observer {
-   public:
-    // Called when the initialization is done.
-    virtual void OnInitialized() = 0;
-  };
-
   ComponentExtensionIMEManager();
   virtual ~ComponentExtensionIMEManager();
 
@@ -75,9 +72,6 @@ class CHROMEOS_EXPORT ComponentExtensionIMEManager {
   // be called before using any other function.
   void Initialize(scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate);
 
-  // Returns true if the initialization is done, otherwise returns false.
-  bool IsInitialized();
-
   // Loads |input_method_id| component extension IME. This function returns true
   // on success. This function is safe to call multiple times. Returns false if
   // already corresponding component extension is loaded.
@@ -88,12 +82,6 @@ class CHROMEOS_EXPORT ComponentExtensionIMEManager {
   // false if already corresponding component extension is unloaded.
   bool UnloadComponentExtensionIME(const std::string& input_method_id);
 
-  // Returns true if |input_method_id| is component extension ime id. Note that
-  // this function does not check the |input_method_id| is really whitelisted
-  // one or not. If you want to check |input_method_id| is whitelisted component
-  // extension ime, please use IsWhitelisted instead.
-  static bool IsComponentExtensionIMEId(const std::string& input_method_id);
-
   // Returns true if |input_method_id| is whitelisted component extension input
   // method.
   bool IsWhitelisted(const std::string& input_method_id);
@@ -101,48 +89,32 @@ class CHROMEOS_EXPORT ComponentExtensionIMEManager {
   // Returns true if |extension_id| is whitelisted component extension.
   bool IsWhitelistedExtension(const std::string& extension_id);
 
-  // Returns InputMethodId. This function returns empty string if |extension_id|
-  // and |engine_id| is not a whitelisted component extention IME.
-  std::string GetId(const std::string& extension_id,
-                    const std::string& engine_id);
-
-  // Returns localized name of |input_method_id|.
-  std::string GetName(const std::string& input_method_id);
-
-  // Returns localized description of |input_method_id|.
-  std::string GetDescription(const std::string& input_method_id);
-
-  // Returns list of input method id associated with |language|.
-  std::vector<std::string> ListIMEByLanguage(const std::string& language);
-
   // Returns all IME as InputMethodDescriptors.
   input_method::InputMethodDescriptors GetAllIMEAsInputMethodDescriptor();
 
-  void AddObserver(Observer* observer);
-  void RemoveObserver(Observer* observer);
-
- protected:
-  // Returns InputMethodId for |engine_id| in |extension_id|. This function does
-  // not check |extension_id| is component one or |engine_id| is really a member
-  // of |extension_id|. Do not use this function outside from this class, just
-  // for protected for unit testing.
-  static std::string GetComponentExtensionIMEId(const std::string& extension_id,
-                                                const std::string& engine_id);
+  // Returns all XKB keyboard IME as InputMethodDescriptors.
+  input_method::InputMethodDescriptors GetXkbIMEAsInputMethodDescriptor();
 
  private:
   // Finds ComponentExtensionIME and EngineDescription associated with
   // |input_method_id|. This function retruns true if it is found, otherwise
   // returns false. |out_extension| and |out_engine| can be NULL.
   bool FindEngineEntry(const std::string& input_method_id,
-                       ComponentExtensionIME* out_extension,
-                       ComponentExtensionEngine* out_engine);
+                       ComponentExtensionIME* out_extension);
+
+  bool IsInLoginLayoutWhitelist(const std::vector<std::string>& layouts);
+
   scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate_;
 
-  std::vector<ComponentExtensionIME> component_extension_imes_;
+  // The map of extension_id to ComponentExtensionIME instance.
+  // It's filled by Initialize() method and never changed during runtime.
+  std::map<std::string, ComponentExtensionIME> component_extension_imes_;
 
-  ObserverList<Observer> observers_;
+  // For quick check the validity of a given input method id.
+  // It's filled by Initialize() method and never changed during runtime.
+  std::set<std::string> input_method_id_set_;
 
-  bool is_initialized_;
+  std::set<std::string> login_layout_set_;
 
   DISALLOW_COPY_AND_ASSIGN(ComponentExtensionIMEManager);
 };