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