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_ 7 #pragma once 8 9 #include "base/string16.h" 10 #include "chrome/browser/autocomplete/autocomplete_match.h" 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(); 45 DECLARE_EXTENSION_FUNCTION_NAME("omnibox.sendSuggestions"); 46 }; 47 48 class OmniboxSetDefaultSuggestionFunction : public SyncExtensionFunction { 49 public: 50 virtual bool RunImpl(); 51 DECLARE_EXTENSION_FUNCTION_NAME("omnibox.setDefaultSuggestion"); 52 }; 53 54 struct ExtensionOmniboxSuggestion { 55 ExtensionOmniboxSuggestion(); 56 ~ExtensionOmniboxSuggestion(); 57 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 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 { 73 ExtensionOmniboxSuggestions(); 74 ~ExtensionOmniboxSuggestions(); 75 76 int request_id; 77 std::vector<ExtensionOmniboxSuggestion> suggestions; 78 79 private: 80 // This class is passed around by pointer. 81 DISALLOW_COPY_AND_ASSIGN(ExtensionOmniboxSuggestions); 82 }; 83 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 92 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_OMNIBOX_API_H_ 93