| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_match.h" | 13 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 14 #include "chrome/browser/extensions/extension_function.h" | 14 #include "chrome/browser/extensions/extension_function.h" |
| 15 #include "chrome/browser/extensions/extension_icon_manager.h" |
| 16 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 17 #include "content/public/browser/notification_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" |
| 15 | 19 |
| 20 class Profile; |
| 16 class TemplateURL; | 21 class TemplateURL; |
| 22 class TemplateURLService; |
| 17 | 23 |
| 18 namespace base { | 24 namespace base { |
| 19 class ListValue; | 25 class ListValue; |
| 20 } | 26 } |
| 21 | 27 |
| 22 namespace content { | 28 namespace content { |
| 23 class WebContents; | 29 class WebContents; |
| 24 } | 30 } |
| 25 | 31 |
| 32 namespace gfx { |
| 33 class Image; |
| 34 } |
| 35 |
| 26 namespace extensions { | 36 namespace extensions { |
| 27 | 37 |
| 28 // Event router class for events related to the omnibox API. | 38 // Event router class for events related to the omnibox API. |
| 29 class ExtensionOmniboxEventRouter { | 39 class ExtensionOmniboxEventRouter { |
| 30 public: | 40 public: |
| 31 // The user has just typed the omnibox keyword. This is sent exactly once in | 41 // The user has just typed the omnibox keyword. This is sent exactly once in |
| 32 // a given input session, before any OnInputChanged events. | 42 // a given input session, before any OnInputChanged events. |
| 33 static void OnInputStarted( | 43 static void OnInputStarted( |
| 34 Profile* profile, const std::string& extension_id); | 44 Profile* profile, const std::string& extension_id); |
| 35 | 45 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 60 public: | 70 public: |
| 61 DECLARE_EXTENSION_FUNCTION_NAME("omnibox.sendSuggestions"); | 71 DECLARE_EXTENSION_FUNCTION_NAME("omnibox.sendSuggestions"); |
| 62 | 72 |
| 63 protected: | 73 protected: |
| 64 virtual ~OmniboxSendSuggestionsFunction() {} | 74 virtual ~OmniboxSendSuggestionsFunction() {} |
| 65 | 75 |
| 66 // ExtensionFunction: | 76 // ExtensionFunction: |
| 67 virtual bool RunImpl() OVERRIDE; | 77 virtual bool RunImpl() OVERRIDE; |
| 68 }; | 78 }; |
| 69 | 79 |
| 80 class OmniboxAPI : public ProfileKeyedService, |
| 81 public content::NotificationObserver { |
| 82 public: |
| 83 explicit OmniboxAPI(Profile* profile); |
| 84 virtual ~OmniboxAPI(); |
| 85 |
| 86 // ProfileKeyedService implementation. |
| 87 virtual void Shutdown() OVERRIDE; |
| 88 |
| 89 // Convenience method to get the OmniboxAPI for a profile. |
| 90 static OmniboxAPI* Get(Profile* profile); |
| 91 |
| 92 // content::NotificationObserver implementation. |
| 93 virtual void Observe(int type, |
| 94 const content::NotificationSource& source, |
| 95 const content::NotificationDetails& details) OVERRIDE; |
| 96 |
| 97 // Returns the icon to display in the omnibox for the given extension. |
| 98 gfx::Image GetOmniboxIcon(const std::string& extension_id); |
| 99 |
| 100 // Returns the icon to display in the omnibox popup window for the given |
| 101 // extension. |
| 102 gfx::Image GetOmniboxPopupIcon(const std::string& extension_id); |
| 103 |
| 104 private: |
| 105 typedef std::list<const Extension*> PendingExtensions; |
| 106 |
| 107 TemplateURLService* url_service_; |
| 108 |
| 109 // List of extensions waiting for the TemplateURLService to Load to |
| 110 // have keywords registered. |
| 111 PendingExtensions pending_extensions_; |
| 112 |
| 113 content::NotificationRegistrar registrar_; |
| 114 |
| 115 // Keeps track of favicon-sized omnibox icons for extensions. |
| 116 ExtensionIconManager omnibox_icon_manager_; |
| 117 ExtensionIconManager omnibox_popup_icon_manager_; |
| 118 }; |
| 119 |
| 70 class OmniboxSetDefaultSuggestionFunction : public SyncExtensionFunction { | 120 class OmniboxSetDefaultSuggestionFunction : public SyncExtensionFunction { |
| 71 public: | 121 public: |
| 72 DECLARE_EXTENSION_FUNCTION_NAME("omnibox.setDefaultSuggestion"); | 122 DECLARE_EXTENSION_FUNCTION_NAME("omnibox.setDefaultSuggestion"); |
| 73 | 123 |
| 74 protected: | 124 protected: |
| 75 virtual ~OmniboxSetDefaultSuggestionFunction() {} | 125 virtual ~OmniboxSetDefaultSuggestionFunction() {} |
| 76 | 126 |
| 77 // ExtensionFunction: | 127 // ExtensionFunction: |
| 78 virtual bool RunImpl() OVERRIDE; | 128 virtual bool RunImpl() OVERRIDE; |
| 79 }; | 129 }; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // omnibox.setDefaultSuggestion, apply that to |match|. Otherwise, do nothing. | 170 // omnibox.setDefaultSuggestion, apply that to |match|. Otherwise, do nothing. |
| 121 void ApplyDefaultSuggestionForExtensionKeyword( | 171 void ApplyDefaultSuggestionForExtensionKeyword( |
| 122 Profile* profile, | 172 Profile* profile, |
| 123 const TemplateURL* keyword, | 173 const TemplateURL* keyword, |
| 124 const string16& remaining_input, | 174 const string16& remaining_input, |
| 125 AutocompleteMatch* match); | 175 AutocompleteMatch* match); |
| 126 | 176 |
| 127 } // namespace extensions | 177 } // namespace extensions |
| 128 | 178 |
| 129 #endif // CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_H_ | 179 #endif // CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_H_ |
| OLD | NEW |