Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: chrome/browser/ui/webui/omnibox/omnibox_ui_handler.h

Issue 222543004: Makes chrome://omnibox use mojo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #ifndef CHROME_BROWSER_UI_WEBUI_OMNIBOX_OMNIBOX_UI_HANDLER_H_ 5 #ifndef CHROME_BROWSER_UI_WEBUI_OMNIBOX_OMNIBOX_UI_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OMNIBOX_OMNIBOX_UI_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_OMNIBOX_OMNIBOX_UI_HANDLER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" 12 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h"
13 #include "chrome/browser/autocomplete/autocomplete_match.h" 13 #include "chrome/browser/autocomplete/autocomplete_match.h"
14 #include "content/public/browser/web_ui_message_handler.h" 14 #include "chrome/browser/ui/webui/mojo_web_ui_handler.h"
15 #include "chrome/browser/ui/webui/omnibox/omnibox.mojom.h"
16 #include "mojo/public/cpp/bindings/remote_ptr.h"
15 17
16 class AutocompleteController; 18 class AutocompleteController;
17 class Profile; 19 class Profile;
18 20
19 namespace base { 21 // Implementation of OmniboxUIHandlerMojo. StartOmniboxQuery() calls to a
20 class ListValue; 22 // private AutocompleteController. It also listens for updates from the
21 } 23 // AutocompleteController to OnResultChanged() and passes those results to
22 24 // the OmniboxPage.
23 // UI Handler for chrome://omnibox/
24 // It listens for calls from javascript to StartOmniboxQuery() and
25 // passes those calls to its private AutocompleteController. It also
26 // listens for updates from the AutocompleteController to OnResultChanged()
27 // and passes those results on calling back into the Javascript to
28 // update the page.
29 class OmniboxUIHandler : public AutocompleteControllerDelegate, 25 class OmniboxUIHandler : public AutocompleteControllerDelegate,
30 public content::WebUIMessageHandler { 26 public chrome::OmniboxUIHandlerMojo,
27 public MojoWebUIHandler {
31 public: 28 public:
32 explicit OmniboxUIHandler(Profile* profile); 29 OmniboxUIHandler(chrome::ScopedOmniboxPageHandle handle, Profile* profile);
33 virtual ~OmniboxUIHandler(); 30 virtual ~OmniboxUIHandler();
34 31
35 // AutocompleteControllerDelegate implementation. 32 // AutocompleteControllerDelegate overrides:
36 // Gets called when the result set of the AutocompleteController changes.
37 // We transform the AutocompleteResult into a Javascript object and
38 // call the Javascript function gotNewAutocompleteResult with it.
39 // |default_match_changed| is given to us by the AutocompleteController
40 // but we don't need it. It's ignored.
41 virtual void OnResultChanged(bool default_match_changed) OVERRIDE; 33 virtual void OnResultChanged(bool default_match_changed) OVERRIDE;
42 34
43 protected: 35 // OmniboxUIHandlerMojo overrides:
44 // WebUIMessageHandler implementation. 36 virtual void StartOmniboxQuery(const mojo::String& input_string,
45 // Register our handler to get callbacks from javascript for 37 int32_t cursor_position,
46 // startOmniboxQuery(). 38 bool prevent_inline_autocomplete,
47 virtual void RegisterMessages() OVERRIDE; 39 bool prefer_keyword,
40 int32_t page_classification) OVERRIDE;
48 41
49 private: 42 private:
50 // Gets called from the javascript when a user enters text into the
51 // chrome://omnibox/ text box and clicks submit or hits enter.
52 // |input| is expected to be a four-element list:
53 // - first element: input string.
54 // - second element: the cursor position.
55 // - third element: boolean indicating whether we should set
56 // prevent_inline_autocomplete or not.
57 // - fourth element: boolean indicating whether we should set prefer_keyword
58 // - fifth element: current page classification value (enum
59 // PageClassification from omnibox_event.proto)
60 void StartOmniboxQuery(const base::ListValue* input);
61
62 // Helper function for OnResultChanged().
63 // Takes an iterator over AutocompleteMatches and packages them into
64 // the DictionaryValue output, all stored under the given prefix.
65 void AddResultToDictionary(const std::string& prefix,
66 ACMatches::const_iterator result_it,
67 ACMatches::const_iterator end,
68 base::DictionaryValue* output);
69
70 // Looks up whether the hostname is a typed host (i.e., has received 43 // Looks up whether the hostname is a typed host (i.e., has received
71 // typed visits). Return true if the lookup succeeded; if so, the 44 // typed visits). Return true if the lookup succeeded; if so, the
72 // value of |is_typed_host| is set appropriately. 45 // value of |is_typed_host| is set appropriately.
73 bool LookupIsTypedHost(const base::string16& host, bool* is_typed_host) const; 46 bool LookupIsTypedHost(const base::string16& host, bool* is_typed_host) const;
74 47
75 // Re-initializes the AutocompleteController in preparation for the 48 // Re-initializes the AutocompleteController in preparation for the
76 // next query. 49 // next query.
77 void ResetController(); 50 void ResetController();
78 51
52 mojo::RemotePtr<chrome::OmniboxPage> page_;
53
79 // The omnibox AutocompleteController that collects/sorts/dup- 54 // The omnibox AutocompleteController that collects/sorts/dup-
80 // eliminates the results as they come in. 55 // eliminates the results as they come in.
81 scoped_ptr<AutocompleteController> controller_; 56 scoped_ptr<AutocompleteController> controller_;
82 57
83 // Time the user's input was sent to the omnibox to start searching. 58 // Time the user's input was sent to the omnibox to start searching.
84 // Needed because we also pass timing information in the object we 59 // Needed because we also pass timing information in the object we
85 // hand back to the javascript. 60 // hand back to the javascript.
86 base::Time time_omnibox_started_; 61 base::Time time_omnibox_started_;
87 62
88 // The Profile* handed to us in our constructor. 63 // The Profile* handed to us in our constructor.
89 Profile* profile_; 64 Profile* profile_;
90 65
91 DISALLOW_COPY_AND_ASSIGN(OmniboxUIHandler); 66 DISALLOW_COPY_AND_ASSIGN(OmniboxUIHandler);
92 }; 67 };
93 68
94 #endif // CHROME_BROWSER_UI_WEBUI_OMNIBOX_OMNIBOX_UI_HANDLER_H_ 69 #endif // CHROME_BROWSER_UI_WEBUI_OMNIBOX_OMNIBOX_UI_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698