Ben Murdoch | c407dc5 | 2010-07-29 17:14:53 +0100 | [diff] [blame] | 1 | // Copyright (c) 2010 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. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_OMNIBOX_API_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_OMNIBOX_API_H_ |
Iain Merrick | 3345a68 | 2010-10-19 14:37:37 +0100 | [diff] [blame] | 7 | #pragma once |
Ben Murdoch | c407dc5 | 2010-07-29 17:14:53 +0100 | [diff] [blame] | 8 | |
| 9 | #include "base/string16.h" |
Ben Murdoch | 513209b | 2010-11-18 18:32:45 +0000 | [diff] [blame] | 10 | #include "chrome/browser/autocomplete/autocomplete_match.h" |
Ben Murdoch | c407dc5 | 2010-07-29 17:14:53 +0100 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_function.h" |
| 12 | |
| 13 | // Event router class for events related to the omnibox API. |
| 14 | class ExtensionOmniboxEventRouter { |
| 15 | public: |
| 16 | // The user has just typed the omnibox keyword. This is sent exactly once in |
| 17 | // a given input session, before any OnInputChanged events. |
| 18 | static void OnInputStarted( |
| 19 | Profile* profile, const std::string& extension_id); |
| 20 | |
| 21 | // The user has changed what is typed into the omnibox while in an extension |
| 22 | // keyword session. Returns true if someone is listening to this event, and |
| 23 | // thus we have some degree of confidence we'll get a response. |
| 24 | static bool OnInputChanged( |
| 25 | Profile* profile, const std::string& extension_id, |
| 26 | const std::string& input, int suggest_id); |
| 27 | |
| 28 | // The user has accepted the omnibox input. |
| 29 | static void OnInputEntered( |
| 30 | Profile* profile, const std::string& extension_id, |
| 31 | const std::string& input); |
| 32 | |
| 33 | // The user has cleared the keyword, or closed the omnibox popup. This is |
| 34 | // sent at most once in a give input session, after any OnInputChanged events. |
| 35 | static void OnInputCancelled( |
| 36 | Profile* profile, const std::string& extension_id); |
| 37 | |
| 38 | private: |
| 39 | DISALLOW_COPY_AND_ASSIGN(ExtensionOmniboxEventRouter); |
| 40 | }; |
| 41 | |
| 42 | class OmniboxSendSuggestionsFunction : public SyncExtensionFunction { |
| 43 | public: |
| 44 | virtual bool RunImpl(); |
Ben Murdoch | 4a5e2dc | 2010-11-25 19:40:10 +0000 | [diff] [blame] | 45 | DECLARE_EXTENSION_FUNCTION_NAME("omnibox.sendSuggestions"); |
Ben Murdoch | c407dc5 | 2010-07-29 17:14:53 +0100 | [diff] [blame] | 46 | }; |
| 47 | |
Ben Murdoch | 201ade2 | 2011-01-07 14:18:56 +0000 | [diff] [blame] | 48 | class OmniboxSetDefaultSuggestionFunction : public SyncExtensionFunction { |
| 49 | public: |
| 50 | virtual bool RunImpl(); |
| 51 | DECLARE_EXTENSION_FUNCTION_NAME("omnibox.setDefaultSuggestion"); |
| 52 | }; |
| 53 | |
Ben Murdoch | c407dc5 | 2010-07-29 17:14:53 +0100 | [diff] [blame] | 54 | struct ExtensionOmniboxSuggestion { |
Iain Merrick | 731df97 | 2010-11-01 12:19:54 +0000 | [diff] [blame] | 55 | ExtensionOmniboxSuggestion(); |
| 56 | ~ExtensionOmniboxSuggestion(); |
| 57 | |
Ben Murdoch | 4a5e2dc | 2010-11-25 19:40:10 +0000 | [diff] [blame] | 58 | // Converts a list of style ranges from the extension into the format expected |
| 59 | // by the autocomplete system. |
| 60 | bool ReadStylesFromValue(const ListValue& value); |
| 61 | |
Ben Murdoch | c407dc5 | 2010-07-29 17:14:53 +0100 | [diff] [blame] | 62 | // The text that gets put in the edit box. |
| 63 | string16 content; |
| 64 | |
| 65 | // The text that is displayed in the drop down. |
| 66 | string16 description; |
| 67 | |
| 68 | // Contains style ranges for the description. |
| 69 | ACMatchClassifications description_styles; |
| 70 | }; |
| 71 | |
| 72 | struct ExtensionOmniboxSuggestions { |
Iain Merrick | 731df97 | 2010-11-01 12:19:54 +0000 | [diff] [blame] | 73 | ExtensionOmniboxSuggestions(); |
| 74 | ~ExtensionOmniboxSuggestions(); |
| 75 | |
Ben Murdoch | c407dc5 | 2010-07-29 17:14:53 +0100 | [diff] [blame] | 76 | int request_id; |
| 77 | std::vector<ExtensionOmniboxSuggestion> suggestions; |
Iain Merrick | 731df97 | 2010-11-01 12:19:54 +0000 | [diff] [blame] | 78 | |
| 79 | private: |
| 80 | // This class is passed around by pointer. |
| 81 | DISALLOW_COPY_AND_ASSIGN(ExtensionOmniboxSuggestions); |
Ben Murdoch | c407dc5 | 2010-07-29 17:14:53 +0100 | [diff] [blame] | 82 | }; |
| 83 | |
Ben Murdoch | 201ade2 | 2011-01-07 14:18:56 +0000 | [diff] [blame] | 84 | // If the extension has set a custom default suggestion via |
| 85 | // omnibox.setDefaultSuggestion, apply that to |match|. Otherwise, do nothing. |
| 86 | void ApplyDefaultSuggestionForExtensionKeyword( |
| 87 | Profile* profile, |
| 88 | const TemplateURL* keyword, |
| 89 | const string16& remaining_input, |
| 90 | AutocompleteMatch* match); |
| 91 | |
Ben Murdoch | c407dc5 | 2010-07-29 17:14:53 +0100 | [diff] [blame] | 92 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_OMNIBOX_API_H_ |