1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBUI_OMNIBOX_OMNIBOX_UI_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OMNIBOX_OMNIBOX_UI_HANDLER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
12 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h"
13 #include "chrome/browser/ui/webui/mojo_web_ui_handler.h"
14 #include "chrome/browser/ui/webui/omnibox/omnibox.mojom.h"
15 #include "components/omnibox/autocomplete_input.h"
16 #include "components/omnibox/autocomplete_match.h"
18 class AutocompleteController
;
21 // Implementation of OmniboxUIHandlerMojo. StartOmniboxQuery() calls to a
22 // private AutocompleteController. It also listens for updates from the
23 // AutocompleteController to OnResultChanged() and passes those results to
25 class OmniboxUIHandler
: public AutocompleteControllerDelegate
,
26 public mojo::InterfaceImpl
<OmniboxUIHandlerMojo
>,
27 public MojoWebUIHandler
{
29 explicit OmniboxUIHandler(Profile
* profile
);
30 ~OmniboxUIHandler() override
;
32 // AutocompleteControllerDelegate overrides:
33 void OnResultChanged(bool default_match_changed
) override
;
35 // ErrorHandler overrides:
36 void OnConnectionError() override
{
37 // TODO(darin): How should we handle connection error?
40 // OmniboxUIHandlerMojo overrides:
41 void StartOmniboxQuery(const mojo::String
& input_string
,
42 int32_t cursor_position
,
43 bool prevent_inline_autocomplete
,
45 int32_t page_classification
,
46 OmniboxPagePtr page
) override
;
49 // Looks up whether the hostname is a typed host (i.e., has received
50 // typed visits). Return true if the lookup succeeded; if so, the
51 // value of |is_typed_host| is set appropriately.
52 bool LookupIsTypedHost(const base::string16
& host
, bool* is_typed_host
) const;
54 // Re-initializes the AutocompleteController in preparation for the
56 void ResetController();
58 // The omnibox AutocompleteController that collects/sorts/dup-
59 // eliminates the results as they come in.
60 scoped_ptr
<AutocompleteController
> controller_
;
62 // Time the user's input was sent to the omnibox to start searching.
63 // Needed because we also pass timing information in the object we
64 // hand back to the javascript.
65 base::Time time_omnibox_started_
;
67 // The input used when starting the AutocompleteController.
68 AutocompleteInput input_
;
70 // Handle back to the page by which we can pass results.
73 // The Profile* handed to us in our constructor.
76 DISALLOW_COPY_AND_ASSIGN(OmniboxUIHandler
);
79 #endif // CHROME_BROWSER_UI_WEBUI_OMNIBOX_OMNIBOX_UI_HANDLER_H_