blob: 61a2f8956c2a63acf3a32ec07f9c0021e26190eb [file] [log] [blame]
Ben Murdochc407dc52010-07-29 17:14:53 +01001// 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 Merrick3345a682010-10-19 14:37:37 +01007#pragma once
Ben Murdochc407dc52010-07-29 17:14:53 +01008
9#include "base/string16.h"
Ben Murdoch513209b2010-11-18 18:32:45 +000010#include "chrome/browser/autocomplete/autocomplete_match.h"
Ben Murdochc407dc52010-07-29 17:14:53 +010011#include "chrome/browser/extensions/extension_function.h"
12
13// Event router class for events related to the omnibox API.
14class 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
42class OmniboxSendSuggestionsFunction : public SyncExtensionFunction {
43 public:
44 virtual bool RunImpl();
Ben Murdoch4a5e2dc2010-11-25 19:40:10 +000045 DECLARE_EXTENSION_FUNCTION_NAME("omnibox.sendSuggestions");
Ben Murdochc407dc52010-07-29 17:14:53 +010046};
47
Ben Murdoch201ade22011-01-07 14:18:56 +000048class OmniboxSetDefaultSuggestionFunction : public SyncExtensionFunction {
49 public:
50 virtual bool RunImpl();
51 DECLARE_EXTENSION_FUNCTION_NAME("omnibox.setDefaultSuggestion");
52};
53
Ben Murdochc407dc52010-07-29 17:14:53 +010054struct ExtensionOmniboxSuggestion {
Iain Merrick731df972010-11-01 12:19:54 +000055 ExtensionOmniboxSuggestion();
56 ~ExtensionOmniboxSuggestion();
57
Ben Murdoch4a5e2dc2010-11-25 19:40:10 +000058 // 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 Murdochc407dc52010-07-29 17:14:53 +010062 // 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
72struct ExtensionOmniboxSuggestions {
Iain Merrick731df972010-11-01 12:19:54 +000073 ExtensionOmniboxSuggestions();
74 ~ExtensionOmniboxSuggestions();
75
Ben Murdochc407dc52010-07-29 17:14:53 +010076 int request_id;
77 std::vector<ExtensionOmniboxSuggestion> suggestions;
Iain Merrick731df972010-11-01 12:19:54 +000078
79 private:
80 // This class is passed around by pointer.
81 DISALLOW_COPY_AND_ASSIGN(ExtensionOmniboxSuggestions);
Ben Murdochc407dc52010-07-29 17:14:53 +010082};
83
Ben Murdoch201ade22011-01-07 14:18:56 +000084// If the extension has set a custom default suggestion via
85// omnibox.setDefaultSuggestion, apply that to |match|. Otherwise, do nothing.
86void ApplyDefaultSuggestionForExtensionKeyword(
87 Profile* profile,
88 const TemplateURL* keyword,
89 const string16& remaining_input,
90 AutocompleteMatch* match);
91
Ben Murdochc407dc52010-07-29 17:14:53 +010092#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_OMNIBOX_API_H_