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 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 5 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // This URL is not actually used for navigation. It holds the extension's ID. | 98 // This URL is not actually used for navigation. It holds the extension's ID. |
99 return std::string(extensions::kExtensionScheme) + "://" + | 99 return std::string(extensions::kExtensionScheme) + "://" + |
100 extension_id + "/?q={searchTerms}"; | 100 extension_id + "/?q={searchTerms}"; |
101 } | 101 } |
102 | 102 |
103 } // namespace | 103 } // namespace |
104 | 104 |
105 // static | 105 // static |
106 void ExtensionOmniboxEventRouter::OnInputStarted( | 106 void ExtensionOmniboxEventRouter::OnInputStarted( |
107 Profile* profile, const std::string& extension_id) { | 107 Profile* profile, const std::string& extension_id) { |
108 std::unique_ptr<Event> event(new Event( | 108 std::unique_ptr<Event> event = base::MakeUnique<Event>( |
109 events::OMNIBOX_ON_INPUT_STARTED, omnibox::OnInputStarted::kEventName, | 109 events::OMNIBOX_ON_INPUT_STARTED, omnibox::OnInputStarted::kEventName, |
110 base::WrapUnique(new base::ListValue()))); | 110 base::MakeUnique<base::ListValue>()); |
111 event->restrict_to_browser_context = profile; | 111 event->restrict_to_browser_context = profile; |
112 EventRouter::Get(profile) | 112 EventRouter::Get(profile) |
113 ->DispatchEventToExtension(extension_id, std::move(event)); | 113 ->DispatchEventToExtension(extension_id, std::move(event)); |
114 } | 114 } |
115 | 115 |
116 // static | 116 // static |
117 bool ExtensionOmniboxEventRouter::OnInputChanged( | 117 bool ExtensionOmniboxEventRouter::OnInputChanged( |
118 Profile* profile, const std::string& extension_id, | 118 Profile* profile, const std::string& extension_id, |
119 const std::string& input, int suggest_id) { | 119 const std::string& input, int suggest_id) { |
120 EventRouter* event_router = EventRouter::Get(profile); | 120 EventRouter* event_router = EventRouter::Get(profile); |
121 if (!event_router->ExtensionHasEventListener( | 121 if (!event_router->ExtensionHasEventListener( |
122 extension_id, omnibox::OnInputChanged::kEventName)) | 122 extension_id, omnibox::OnInputChanged::kEventName)) |
123 return false; | 123 return false; |
124 | 124 |
125 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 125 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
126 args->Set(0, new base::StringValue(input)); | 126 args->Set(0, new base::StringValue(input)); |
127 args->Set(1, new base::FundamentalValue(suggest_id)); | 127 args->Set(1, new base::FundamentalValue(suggest_id)); |
128 | 128 |
129 std::unique_ptr<Event> event(new Event(events::OMNIBOX_ON_INPUT_CHANGED, | 129 std::unique_ptr<Event> event = base::MakeUnique<Event>( |
130 omnibox::OnInputChanged::kEventName, | 130 events::OMNIBOX_ON_INPUT_CHANGED, omnibox::OnInputChanged::kEventName, |
131 std::move(args))); | 131 std::move(args)); |
132 event->restrict_to_browser_context = profile; | 132 event->restrict_to_browser_context = profile; |
133 event_router->DispatchEventToExtension(extension_id, std::move(event)); | 133 event_router->DispatchEventToExtension(extension_id, std::move(event)); |
134 return true; | 134 return true; |
135 } | 135 } |
136 | 136 |
137 // static | 137 // static |
138 void ExtensionOmniboxEventRouter::OnInputEntered( | 138 void ExtensionOmniboxEventRouter::OnInputEntered( |
139 content::WebContents* web_contents, | 139 content::WebContents* web_contents, |
140 const std::string& extension_id, | 140 const std::string& extension_id, |
141 const std::string& input, | 141 const std::string& input, |
(...skipping 10 matching lines...) Expand all Loading... |
152 | 152 |
153 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 153 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
154 args->Set(0, new base::StringValue(input)); | 154 args->Set(0, new base::StringValue(input)); |
155 if (disposition == NEW_FOREGROUND_TAB) | 155 if (disposition == NEW_FOREGROUND_TAB) |
156 args->Set(1, new base::StringValue(kForegroundTabDisposition)); | 156 args->Set(1, new base::StringValue(kForegroundTabDisposition)); |
157 else if (disposition == NEW_BACKGROUND_TAB) | 157 else if (disposition == NEW_BACKGROUND_TAB) |
158 args->Set(1, new base::StringValue(kBackgroundTabDisposition)); | 158 args->Set(1, new base::StringValue(kBackgroundTabDisposition)); |
159 else | 159 else |
160 args->Set(1, new base::StringValue(kCurrentTabDisposition)); | 160 args->Set(1, new base::StringValue(kCurrentTabDisposition)); |
161 | 161 |
162 std::unique_ptr<Event> event(new Event(events::OMNIBOX_ON_INPUT_ENTERED, | 162 std::unique_ptr<Event> event = base::MakeUnique<Event>( |
163 omnibox::OnInputEntered::kEventName, | 163 events::OMNIBOX_ON_INPUT_ENTERED, omnibox::OnInputEntered::kEventName, |
164 std::move(args))); | 164 std::move(args)); |
165 event->restrict_to_browser_context = profile; | 165 event->restrict_to_browser_context = profile; |
166 EventRouter::Get(profile) | 166 EventRouter::Get(profile) |
167 ->DispatchEventToExtension(extension_id, std::move(event)); | 167 ->DispatchEventToExtension(extension_id, std::move(event)); |
168 | 168 |
169 content::NotificationService::current()->Notify( | 169 content::NotificationService::current()->Notify( |
170 extensions::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, | 170 extensions::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, |
171 content::Source<Profile>(profile), | 171 content::Source<Profile>(profile), |
172 content::NotificationService::NoDetails()); | 172 content::NotificationService::NoDetails()); |
173 } | 173 } |
174 | 174 |
175 // static | 175 // static |
176 void ExtensionOmniboxEventRouter::OnInputCancelled( | 176 void ExtensionOmniboxEventRouter::OnInputCancelled( |
177 Profile* profile, const std::string& extension_id) { | 177 Profile* profile, const std::string& extension_id) { |
178 std::unique_ptr<Event> event(new Event( | 178 std::unique_ptr<Event> event = base::MakeUnique<Event>( |
179 events::OMNIBOX_ON_INPUT_CANCELLED, omnibox::OnInputCancelled::kEventName, | 179 events::OMNIBOX_ON_INPUT_CANCELLED, omnibox::OnInputCancelled::kEventName, |
180 base::WrapUnique(new base::ListValue()))); | 180 base::MakeUnique<base::ListValue>()); |
181 event->restrict_to_browser_context = profile; | 181 event->restrict_to_browser_context = profile; |
182 EventRouter::Get(profile) | 182 EventRouter::Get(profile) |
183 ->DispatchEventToExtension(extension_id, std::move(event)); | 183 ->DispatchEventToExtension(extension_id, std::move(event)); |
184 } | 184 } |
185 | 185 |
186 OmniboxAPI::OmniboxAPI(content::BrowserContext* context) | 186 OmniboxAPI::OmniboxAPI(content::BrowserContext* context) |
187 : profile_(Profile::FromBrowserContext(context)), | 187 : profile_(Profile::FromBrowserContext(context)), |
188 url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), | 188 url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), |
189 extension_registry_observer_(this) { | 189 extension_registry_observer_(this) { |
190 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); | 190 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 for (size_t i = 0; i < description_styles.size(); ++i) { | 393 for (size_t i = 0; i < description_styles.size(); ++i) { |
394 if (description_styles[i].offset > placeholder) | 394 if (description_styles[i].offset > placeholder) |
395 description_styles[i].offset += replacement.length() - 2; | 395 description_styles[i].offset += replacement.length() - 2; |
396 } | 396 } |
397 } | 397 } |
398 | 398 |
399 match->contents.assign(description); | 399 match->contents.assign(description); |
400 } | 400 } |
401 | 401 |
402 } // namespace extensions | 402 } // namespace extensions |
OLD | NEW |