| 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/strings/string16.h" | 13 #include "base/strings/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/api/profile_keyed_api_factory.h" |
| 16 #include "chrome/browser/extensions/extension_function.h" | 16 #include "chrome/browser/extensions/extension_function.h" |
| 17 #include "chrome/browser/extensions/extension_icon_manager.h" | 17 #include "chrome/browser/extensions/extension_icon_manager.h" |
| 18 #include "chrome/browser/search_engines/template_url_service.h" |
| 18 #include "chrome/common/extensions/api/omnibox.h" | 19 #include "chrome/common/extensions/api/omnibox.h" |
| 19 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
| 20 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
| 21 #include "ui/base/window_open_disposition.h" | 22 #include "ui/base/window_open_disposition.h" |
| 22 | 23 |
| 23 class Profile; | 24 class Profile; |
| 24 class TemplateURL; | 25 class TemplateURL; |
| 25 class TemplateURLService; | 26 class TemplateURLService; |
| 26 | 27 |
| 27 namespace base { | 28 namespace base { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 static ProfileKeyedAPIFactory<OmniboxAPI>* GetFactoryInstance(); | 92 static ProfileKeyedAPIFactory<OmniboxAPI>* GetFactoryInstance(); |
| 92 | 93 |
| 93 // Convenience method to get the OmniboxAPI for a profile. | 94 // Convenience method to get the OmniboxAPI for a profile. |
| 94 static OmniboxAPI* Get(Profile* profile); | 95 static OmniboxAPI* Get(Profile* profile); |
| 95 | 96 |
| 96 // content::NotificationObserver implementation. | 97 // content::NotificationObserver implementation. |
| 97 virtual void Observe(int type, | 98 virtual void Observe(int type, |
| 98 const content::NotificationSource& source, | 99 const content::NotificationSource& source, |
| 99 const content::NotificationDetails& details) OVERRIDE; | 100 const content::NotificationDetails& details) OVERRIDE; |
| 100 | 101 |
| 102 // BrowserContextKeyedService implementation. |
| 103 virtual void Shutdown() OVERRIDE; |
| 104 |
| 101 // Returns the icon to display in the omnibox for the given extension. | 105 // Returns the icon to display in the omnibox for the given extension. |
| 102 gfx::Image GetOmniboxIcon(const std::string& extension_id); | 106 gfx::Image GetOmniboxIcon(const std::string& extension_id); |
| 103 | 107 |
| 104 // Returns the icon to display in the omnibox popup window for the given | 108 // Returns the icon to display in the omnibox popup window for the given |
| 105 // extension. | 109 // extension. |
| 106 gfx::Image GetOmniboxPopupIcon(const std::string& extension_id); | 110 gfx::Image GetOmniboxPopupIcon(const std::string& extension_id); |
| 107 | 111 |
| 108 private: | 112 private: |
| 109 friend class ProfileKeyedAPIFactory<OmniboxAPI>; | 113 friend class ProfileKeyedAPIFactory<OmniboxAPI>; |
| 110 | 114 |
| 111 typedef std::set<const Extension*> PendingExtensions; | 115 typedef std::set<const Extension*> PendingExtensions; |
| 112 | 116 |
| 117 void OnTemplateURLsLoaded(); |
| 118 |
| 113 // ProfileKeyedAPI implementation. | 119 // ProfileKeyedAPI implementation. |
| 114 static const char* service_name() { | 120 static const char* service_name() { |
| 115 return "OmniboxAPI"; | 121 return "OmniboxAPI"; |
| 116 } | 122 } |
| 117 static const bool kServiceRedirectedInIncognito = true; | 123 static const bool kServiceRedirectedInIncognito = true; |
| 118 | 124 |
| 119 Profile* profile_; | 125 Profile* profile_; |
| 120 | 126 |
| 121 TemplateURLService* url_service_; | 127 TemplateURLService* url_service_; |
| 122 | 128 |
| 123 // List of extensions waiting for the TemplateURLService to Load to | 129 // List of extensions waiting for the TemplateURLService to Load to |
| 124 // have keywords registered. | 130 // have keywords registered. |
| 125 PendingExtensions pending_extensions_; | 131 PendingExtensions pending_extensions_; |
| 126 | 132 |
| 127 content::NotificationRegistrar registrar_; | 133 content::NotificationRegistrar registrar_; |
| 128 | 134 |
| 129 // Keeps track of favicon-sized omnibox icons for extensions. | 135 // Keeps track of favicon-sized omnibox icons for extensions. |
| 130 ExtensionIconManager omnibox_icon_manager_; | 136 ExtensionIconManager omnibox_icon_manager_; |
| 131 ExtensionIconManager omnibox_popup_icon_manager_; | 137 ExtensionIconManager omnibox_popup_icon_manager_; |
| 132 | 138 |
| 139 scoped_ptr<TemplateURLService::Subscription> template_url_sub_; |
| 140 |
| 133 DISALLOW_COPY_AND_ASSIGN(OmniboxAPI); | 141 DISALLOW_COPY_AND_ASSIGN(OmniboxAPI); |
| 134 }; | 142 }; |
| 135 | 143 |
| 136 template <> | 144 template <> |
| 137 void ProfileKeyedAPIFactory<OmniboxAPI>::DeclareFactoryDependencies(); | 145 void ProfileKeyedAPIFactory<OmniboxAPI>::DeclareFactoryDependencies(); |
| 138 | 146 |
| 139 class OmniboxSetDefaultSuggestionFunction : public SyncExtensionFunction { | 147 class OmniboxSetDefaultSuggestionFunction : public SyncExtensionFunction { |
| 140 public: | 148 public: |
| 141 DECLARE_EXTENSION_FUNCTION("omnibox.setDefaultSuggestion", | 149 DECLARE_EXTENSION_FUNCTION("omnibox.setDefaultSuggestion", |
| 142 OMNIBOX_SETDEFAULTSUGGESTION) | 150 OMNIBOX_SETDEFAULTSUGGESTION) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 157 AutocompleteMatch* match); | 165 AutocompleteMatch* match); |
| 158 | 166 |
| 159 // This function converts style information populated by the JSON schema | 167 // This function converts style information populated by the JSON schema |
| 160 // // compiler into an ACMatchClassifications object. | 168 // // compiler into an ACMatchClassifications object. |
| 161 ACMatchClassifications StyleTypesToACMatchClassifications( | 169 ACMatchClassifications StyleTypesToACMatchClassifications( |
| 162 const api::omnibox::SuggestResult &suggestion); | 170 const api::omnibox::SuggestResult &suggestion); |
| 163 | 171 |
| 164 } // namespace extensions | 172 } // namespace extensions |
| 165 | 173 |
| 166 #endif // CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_H_ | 174 #endif // CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_H_ |
| OLD | NEW |