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 "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 void ExtensionOmniboxEventRouter::OnInputCancelled( | 168 void ExtensionOmniboxEventRouter::OnInputCancelled( |
169 Profile* profile, const std::string& extension_id) { | 169 Profile* profile, const std::string& extension_id) { |
170 scoped_ptr<Event> event(new Event( | 170 scoped_ptr<Event> event(new Event( |
171 omnibox::OnInputCancelled::kEventName, | 171 omnibox::OnInputCancelled::kEventName, |
172 make_scoped_ptr(new base::ListValue()))); | 172 make_scoped_ptr(new base::ListValue()))); |
173 event->restrict_to_browser_context = profile; | 173 event->restrict_to_browser_context = profile; |
174 ExtensionSystem::Get(profile)->event_router()-> | 174 ExtensionSystem::Get(profile)->event_router()-> |
175 DispatchEventToExtension(extension_id, event.Pass()); | 175 DispatchEventToExtension(extension_id, event.Pass()); |
176 } | 176 } |
177 | 177 |
178 OmniboxAPI::OmniboxAPI(Profile* profile) | 178 OmniboxAPI::OmniboxAPI(content::BrowserContext* context) |
179 : profile_(profile), | 179 : profile_(Profile::FromBrowserContext(context)), |
180 url_service_(TemplateURLServiceFactory::GetForProfile(profile)) { | 180 url_service_(TemplateURLServiceFactory::GetForProfile(profile_)) { |
181 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 181 registrar_.Add(this, |
182 content::Source<Profile>(profile)); | 182 chrome::NOTIFICATION_EXTENSION_LOADED, |
183 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 183 content::Source<Profile>(profile_)); |
184 content::Source<Profile>(profile)); | 184 registrar_.Add(this, |
| 185 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 186 content::Source<Profile>(profile_)); |
185 if (url_service_) { | 187 if (url_service_) { |
186 template_url_sub_ = url_service_->RegisterOnLoadedCallback( | 188 template_url_sub_ = url_service_->RegisterOnLoadedCallback( |
187 base::Bind(&OmniboxAPI::OnTemplateURLsLoaded, | 189 base::Bind(&OmniboxAPI::OnTemplateURLsLoaded, |
188 base::Unretained(this))); | 190 base::Unretained(this))); |
189 } | 191 } |
190 | 192 |
191 // Use monochrome icons for Omnibox icons. | 193 // Use monochrome icons for Omnibox icons. |
192 omnibox_popup_icon_manager_.set_monochrome(true); | 194 omnibox_popup_icon_manager_.set_monochrome(true); |
193 omnibox_icon_manager_.set_monochrome(true); | 195 omnibox_icon_manager_.set_monochrome(true); |
194 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, | 196 omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, |
195 0, kOmniboxIconPaddingRight)); | 197 0, kOmniboxIconPaddingRight)); |
196 } | 198 } |
197 | 199 |
198 void OmniboxAPI::Shutdown() { | 200 void OmniboxAPI::Shutdown() { |
199 template_url_sub_.reset(); | 201 template_url_sub_.reset(); |
200 } | 202 } |
201 | 203 |
202 OmniboxAPI::~OmniboxAPI() { | 204 OmniboxAPI::~OmniboxAPI() { |
203 } | 205 } |
204 | 206 |
205 static base::LazyInstance<ProfileKeyedAPIFactory<OmniboxAPI> > | 207 static base::LazyInstance<ProfileKeyedAPIFactory<OmniboxAPI> > |
206 g_factory = LAZY_INSTANCE_INITIALIZER; | 208 g_factory = LAZY_INSTANCE_INITIALIZER; |
207 | 209 |
208 // static | 210 // static |
209 ProfileKeyedAPIFactory<OmniboxAPI>* OmniboxAPI::GetFactoryInstance() { | 211 ProfileKeyedAPIFactory<OmniboxAPI>* OmniboxAPI::GetFactoryInstance() { |
210 return g_factory.Pointer(); | 212 return g_factory.Pointer(); |
211 } | 213 } |
212 | 214 |
213 // static | 215 // static |
214 OmniboxAPI* OmniboxAPI::Get(Profile* profile) { | 216 OmniboxAPI* OmniboxAPI::Get(content::BrowserContext* context) { |
215 return ProfileKeyedAPIFactory<OmniboxAPI>::GetForProfile(profile); | 217 return ProfileKeyedAPIFactory<OmniboxAPI>::GetForProfile(context); |
216 } | 218 } |
217 | 219 |
218 void OmniboxAPI::Observe(int type, | 220 void OmniboxAPI::Observe(int type, |
219 const content::NotificationSource& source, | 221 const content::NotificationSource& source, |
220 const content::NotificationDetails& details) { | 222 const content::NotificationDetails& details) { |
221 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { | 223 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { |
222 const Extension* extension = | 224 const Extension* extension = |
223 content::Details<const Extension>(details).ptr(); | 225 content::Details<const Extension>(details).ptr(); |
224 const std::string& keyword = OmniboxInfo::GetKeyword(extension); | 226 const std::string& keyword = OmniboxInfo::GetKeyword(extension); |
225 if (!keyword.empty()) { | 227 if (!keyword.empty()) { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 for (size_t i = 0; i < description_styles.size(); ++i) { | 398 for (size_t i = 0; i < description_styles.size(); ++i) { |
397 if (description_styles[i].offset > placeholder) | 399 if (description_styles[i].offset > placeholder) |
398 description_styles[i].offset += replacement.length() - 2; | 400 description_styles[i].offset += replacement.length() - 2; |
399 } | 401 } |
400 } | 402 } |
401 | 403 |
402 match->contents.assign(description); | 404 match->contents.assign(description); |
403 } | 405 } |
404 | 406 |
405 } // namespace extensions | 407 } // namespace extensions |
OLD | NEW |