Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / omnibox / omnibox_ui_handler.h
index 8c18792..7e2583f 100644 (file)
 #include "base/memory/scoped_ptr.h"
 #include "base/time/time.h"
 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h"
-#include "chrome/browser/autocomplete/autocomplete_match.h"
-#include "content/public/browser/web_ui_message_handler.h"
+#include "chrome/browser/ui/webui/mojo_web_ui_handler.h"
+#include "chrome/browser/ui/webui/omnibox/omnibox.mojom.h"
+#include "components/omnibox/autocomplete_input.h"
+#include "components/omnibox/autocomplete_match.h"
 
 class AutocompleteController;
 class Profile;
 
-namespace base {
-class ListValue;
-}
-
-// UI Handler for chrome://omnibox/
-// It listens for calls from javascript to StartOmniboxQuery() and
-// passes those calls to its private AutocompleteController. It also
-// listens for updates from the AutocompleteController to OnResultChanged()
-// and passes those results on calling back into the Javascript to
-// update the page.
+// Implementation of OmniboxUIHandlerMojo.  StartOmniboxQuery() calls to a
+// private AutocompleteController. It also listens for updates from the
+// AutocompleteController to OnResultChanged() and passes those results to
+// the OmniboxPage.
 class OmniboxUIHandler : public AutocompleteControllerDelegate,
-                         public content::WebUIMessageHandler {
+                         public mojo::InterfaceImpl<OmniboxUIHandlerMojo>,
+                         public MojoWebUIHandler {
  public:
   explicit OmniboxUIHandler(Profile* profile);
   virtual ~OmniboxUIHandler();
 
-  // AutocompleteControllerDelegate implementation.
-  // Gets called when the result set of the AutocompleteController changes.
-  // We transform the AutocompleteResult into a Javascript object and
-  // call the Javascript function gotNewAutocompleteResult with it.
-  // |default_match_changed| is given to us by the AutocompleteController
-  // but we don't need it.  It's ignored.
+  // AutocompleteControllerDelegate overrides:
   virtual void OnResultChanged(bool default_match_changed) OVERRIDE;
 
- protected:
-  // WebUIMessageHandler implementation.
-  // Register our handler to get callbacks from javascript for
-  // startOmniboxQuery().
-  virtual void RegisterMessages() OVERRIDE;
-
- private:
-  // Gets called from the javascript when a user enters text into the
-  // chrome://omnibox/ text box and clicks submit or hits enter.
-  // |input| is expected to be a four-element list:
-  // - first element: input string.
-  // - second element: the cursor position.
-  // - third element: boolean indicating whether we should set
-  //   prevent_inline_autocomplete or not.
-  // - fourth element: boolean indicating whether we should set prefer_keyword
-  void StartOmniboxQuery(const base::ListValue* input);
+  // ErrorHandler overrides:
+  virtual void OnConnectionError() OVERRIDE {
+    // TODO(darin): How should we handle connection error?
+  }
 
-  // Helper function for OnResultChanged().
-  // Takes an iterator over AutocompleteMatches and packages them into
-  // the DictionaryValue output, all stored under the given prefix.
-  void AddResultToDictionary(const std::string& prefix,
-                             ACMatches::const_iterator result_it,
-                             ACMatches::const_iterator end,
-                             base::DictionaryValue* output);
+  // OmniboxUIHandlerMojo overrides:
+  virtual void StartOmniboxQuery(const mojo::String& input_string,
+                                 int32_t cursor_position,
+                                 bool prevent_inline_autocomplete,
+                                 bool prefer_keyword,
+                                 int32_t page_classification) OVERRIDE;
 
+ private:
   // Looks up whether the hostname is a typed host (i.e., has received
   // typed visits).  Return true if the lookup succeeded; if so, the
   // value of |is_typed_host| is set appropriately.
-  bool LookupIsTypedHost(const string16& host, bool* is_typed_host) const;
+  bool LookupIsTypedHost(const base::string16& host, bool* is_typed_host) const;
 
   // Re-initializes the AutocompleteController in preparation for the
   // next query.
@@ -83,6 +63,9 @@ class OmniboxUIHandler : public AutocompleteControllerDelegate,
   // hand back to the javascript.
   base::Time time_omnibox_started_;
 
+  // The input used when starting the AutocompleteController.
+  AutocompleteInput input_;
+
   // The Profile* handed to us in our constructor.
   Profile* profile_;