OLD | NEW |
| (Empty) |
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. | |
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 <string> | |
10 #include <vector> | |
11 | |
12 #include "base/string16.h" | |
13 #include "chrome/browser/autocomplete/autocomplete_match.h" | |
14 #include "chrome/browser/extensions/extension_function.h" | |
15 #include "webkit/glue/window_open_disposition.h" | |
16 | |
17 class TemplateURL; | |
18 namespace base { | |
19 class ListValue; | |
20 } | |
21 | |
22 // Event router class for events related to the omnibox API. | |
23 class ExtensionOmniboxEventRouter { | |
24 public: | |
25 // The user has just typed the omnibox keyword. This is sent exactly once in | |
26 // a given input session, before any OnInputChanged events. | |
27 static void OnInputStarted( | |
28 Profile* profile, const std::string& extension_id); | |
29 | |
30 // The user has changed what is typed into the omnibox while in an extension | |
31 // keyword session. Returns true if someone is listening to this event, and | |
32 // thus we have some degree of confidence we'll get a response. | |
33 static bool OnInputChanged( | |
34 Profile* profile, const std::string& extension_id, | |
35 const std::string& input, int suggest_id); | |
36 | |
37 // The user has accepted the omnibox input. | |
38 static void OnInputEntered( | |
39 Profile* profile, const std::string& extension_id, | |
40 const std::string& input); | |
41 | |
42 // The user has cleared the keyword, or closed the omnibox popup. This is | |
43 // sent at most once in a give input session, after any OnInputChanged events. | |
44 static void OnInputCancelled( | |
45 Profile* profile, const std::string& extension_id); | |
46 | |
47 private: | |
48 DISALLOW_COPY_AND_ASSIGN(ExtensionOmniboxEventRouter); | |
49 }; | |
50 | |
51 class OmniboxSendSuggestionsFunction : public SyncExtensionFunction { | |
52 public: | |
53 DECLARE_EXTENSION_FUNCTION_NAME("omnibox.sendSuggestions"); | |
54 | |
55 protected: | |
56 virtual ~OmniboxSendSuggestionsFunction() {} | |
57 | |
58 // ExtensionFunction: | |
59 virtual bool RunImpl() OVERRIDE; | |
60 }; | |
61 | |
62 class OmniboxSetDefaultSuggestionFunction : public SyncExtensionFunction { | |
63 public: | |
64 DECLARE_EXTENSION_FUNCTION_NAME("omnibox.setDefaultSuggestion"); | |
65 | |
66 protected: | |
67 virtual ~OmniboxSetDefaultSuggestionFunction() {} | |
68 | |
69 // ExtensionFunction: | |
70 virtual bool RunImpl() OVERRIDE; | |
71 }; | |
72 | |
73 struct ExtensionOmniboxSuggestion { | |
74 ExtensionOmniboxSuggestion(); | |
75 ~ExtensionOmniboxSuggestion(); | |
76 | |
77 // Converts a list of style ranges from the extension into the format expected | |
78 // by the autocomplete system. | |
79 bool ReadStylesFromValue(const base::ListValue& value); | |
80 | |
81 // The text that gets put in the edit box. | |
82 string16 content; | |
83 | |
84 // The text that is displayed in the drop down. | |
85 string16 description; | |
86 | |
87 // Contains style ranges for the description. | |
88 ACMatchClassifications description_styles; | |
89 }; | |
90 | |
91 struct ExtensionOmniboxSuggestions { | |
92 ExtensionOmniboxSuggestions(); | |
93 ~ExtensionOmniboxSuggestions(); | |
94 | |
95 int request_id; | |
96 std::vector<ExtensionOmniboxSuggestion> suggestions; | |
97 | |
98 private: | |
99 // This class is passed around by pointer. | |
100 DISALLOW_COPY_AND_ASSIGN(ExtensionOmniboxSuggestions); | |
101 }; | |
102 | |
103 // If the extension has set a custom default suggestion via | |
104 // omnibox.setDefaultSuggestion, apply that to |match|. Otherwise, do nothing. | |
105 void ApplyDefaultSuggestionForExtensionKeyword( | |
106 Profile* profile, | |
107 const TemplateURL* keyword, | |
108 const string16& remaining_input, | |
109 AutocompleteMatch* match); | |
110 | |
111 // Launch an Extension App from |match| details provided by the Omnibox. If the | |
112 // application wants to launch as a window or panel, |disposition| is ignored; | |
113 // otherwise it's used to determine in which tab we'll launch the application. | |
114 void LaunchAppFromOmnibox(const AutocompleteMatch& match, | |
115 Profile* profile, | |
116 WindowOpenDisposition disposition); | |
117 | |
118 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_OMNIBOX_API_H_ | |
OLD | NEW |