OLD | NEW |
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_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "chrome/browser/autocomplete/autocomplete_match.h" | 14 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 15 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
15 #include "chrome/browser/extensions/extension_function.h" | 16 #include "chrome/browser/extensions/extension_function.h" |
16 #include "chrome/browser/extensions/extension_icon_manager.h" | 17 #include "chrome/browser/extensions/extension_icon_manager.h" |
17 #include "chrome/browser/profiles/profile_keyed_service.h" | |
18 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
20 | 20 |
21 class Profile; | 21 class Profile; |
22 class TemplateURL; | 22 class TemplateURL; |
23 class TemplateURLService; | 23 class TemplateURLService; |
24 | 24 |
25 namespace base { | 25 namespace base { |
26 class ListValue; | 26 class ListValue; |
27 } | 27 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 public: | 71 public: |
72 DECLARE_EXTENSION_FUNCTION_NAME("omnibox.sendSuggestions"); | 72 DECLARE_EXTENSION_FUNCTION_NAME("omnibox.sendSuggestions"); |
73 | 73 |
74 protected: | 74 protected: |
75 virtual ~OmniboxSendSuggestionsFunction() {} | 75 virtual ~OmniboxSendSuggestionsFunction() {} |
76 | 76 |
77 // ExtensionFunction: | 77 // ExtensionFunction: |
78 virtual bool RunImpl() OVERRIDE; | 78 virtual bool RunImpl() OVERRIDE; |
79 }; | 79 }; |
80 | 80 |
81 class OmniboxAPI : public ProfileKeyedService, | 81 class OmniboxAPI : public ProfileKeyedAPI, |
82 public content::NotificationObserver { | 82 public content::NotificationObserver { |
83 public: | 83 public: |
84 explicit OmniboxAPI(Profile* profile); | 84 explicit OmniboxAPI(Profile* profile); |
85 virtual ~OmniboxAPI(); | 85 virtual ~OmniboxAPI(); |
86 | 86 |
87 // ProfileKeyedService implementation. | 87 // ProfileKeyedAPI implementation. |
88 virtual void Shutdown() OVERRIDE; | 88 static ProfileKeyedAPIFactory<OmniboxAPI>* GetFactoryInstance(); |
89 | 89 |
90 // Convenience method to get the OmniboxAPI for a profile. | 90 // Convenience method to get the OmniboxAPI for a profile. |
91 static OmniboxAPI* Get(Profile* profile); | 91 static OmniboxAPI* Get(Profile* profile); |
92 | 92 |
93 // content::NotificationObserver implementation. | 93 // content::NotificationObserver implementation. |
94 virtual void Observe(int type, | 94 virtual void Observe(int type, |
95 const content::NotificationSource& source, | 95 const content::NotificationSource& source, |
96 const content::NotificationDetails& details) OVERRIDE; | 96 const content::NotificationDetails& details) OVERRIDE; |
97 | 97 |
98 // Returns the icon to display in the omnibox for the given extension. | 98 // Returns the icon to display in the omnibox for the given extension. |
99 gfx::Image GetOmniboxIcon(const std::string& extension_id); | 99 gfx::Image GetOmniboxIcon(const std::string& extension_id); |
100 | 100 |
101 // Returns the icon to display in the omnibox popup window for the given | 101 // Returns the icon to display in the omnibox popup window for the given |
102 // extension. | 102 // extension. |
103 gfx::Image GetOmniboxPopupIcon(const std::string& extension_id); | 103 gfx::Image GetOmniboxPopupIcon(const std::string& extension_id); |
104 | 104 |
105 private: | 105 private: |
| 106 friend class ProfileKeyedAPIFactory<OmniboxAPI>; |
| 107 |
106 typedef std::set<const Extension*> PendingExtensions; | 108 typedef std::set<const Extension*> PendingExtensions; |
107 | 109 |
| 110 // ProfileKeyedAPI implementation. |
| 111 static const char* service_name() { |
| 112 return "OmniboxAPI"; |
| 113 } |
| 114 static const bool kServiceRedirectedInIncognito = true; |
| 115 |
108 TemplateURLService* url_service_; | 116 TemplateURLService* url_service_; |
109 | 117 |
110 // List of extensions waiting for the TemplateURLService to Load to | 118 // List of extensions waiting for the TemplateURLService to Load to |
111 // have keywords registered. | 119 // have keywords registered. |
112 PendingExtensions pending_extensions_; | 120 PendingExtensions pending_extensions_; |
113 | 121 |
114 content::NotificationRegistrar registrar_; | 122 content::NotificationRegistrar registrar_; |
115 | 123 |
116 // Keeps track of favicon-sized omnibox icons for extensions. | 124 // Keeps track of favicon-sized omnibox icons for extensions. |
117 ExtensionIconManager omnibox_icon_manager_; | 125 ExtensionIconManager omnibox_icon_manager_; |
118 ExtensionIconManager omnibox_popup_icon_manager_; | 126 ExtensionIconManager omnibox_popup_icon_manager_; |
| 127 |
| 128 DISALLOW_COPY_AND_ASSIGN(OmniboxAPI); |
119 }; | 129 }; |
120 | 130 |
121 class OmniboxSetDefaultSuggestionFunction : public SyncExtensionFunction { | 131 class OmniboxSetDefaultSuggestionFunction : public SyncExtensionFunction { |
122 public: | 132 public: |
123 DECLARE_EXTENSION_FUNCTION_NAME("omnibox.setDefaultSuggestion"); | 133 DECLARE_EXTENSION_FUNCTION_NAME("omnibox.setDefaultSuggestion"); |
124 | 134 |
125 protected: | 135 protected: |
126 virtual ~OmniboxSetDefaultSuggestionFunction() {} | 136 virtual ~OmniboxSetDefaultSuggestionFunction() {} |
127 | 137 |
128 // ExtensionFunction: | 138 // ExtensionFunction: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 // omnibox.setDefaultSuggestion, apply that to |match|. Otherwise, do nothing. | 181 // omnibox.setDefaultSuggestion, apply that to |match|. Otherwise, do nothing. |
172 void ApplyDefaultSuggestionForExtensionKeyword( | 182 void ApplyDefaultSuggestionForExtensionKeyword( |
173 Profile* profile, | 183 Profile* profile, |
174 const TemplateURL* keyword, | 184 const TemplateURL* keyword, |
175 const string16& remaining_input, | 185 const string16& remaining_input, |
176 AutocompleteMatch* match); | 186 AutocompleteMatch* match); |
177 | 187 |
178 } // namespace extensions | 188 } // namespace extensions |
179 | 189 |
180 #endif // CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_H_ | 190 #endif // CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_H_ |
OLD | NEW |