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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 const std::string& keyword = OmniboxInfo::GetKeyword(extension); | 212 const std::string& keyword = OmniboxInfo::GetKeyword(extension); |
213 if (!keyword.empty()) { | 213 if (!keyword.empty()) { |
214 // Load the omnibox icon so it will be ready to display in the URL bar. | 214 // Load the omnibox icon so it will be ready to display in the URL bar. |
215 omnibox_icon_manager_.LoadIcon(profile_, extension); | 215 omnibox_icon_manager_.LoadIcon(profile_, extension); |
216 | 216 |
217 if (url_service_) { | 217 if (url_service_) { |
218 url_service_->Load(); | 218 url_service_->Load(); |
219 if (url_service_->loaded()) { | 219 if (url_service_->loaded()) { |
220 url_service_->RegisterOmniboxKeyword( | 220 url_service_->RegisterOmniboxKeyword( |
221 extension->id(), extension->name(), keyword, | 221 extension->id(), extension->name(), keyword, |
222 GetTemplateURLStringForExtension(extension->id())); | 222 GetTemplateURLStringForExtension(extension->id()), |
223 ExtensionPrefs::Get(profile_)->GetInstallTime(extension->id())); | |
223 } else { | 224 } else { |
224 pending_extensions_.insert(extension); | 225 pending_extensions_.insert(extension); |
225 } | 226 } |
226 } | 227 } |
227 } | 228 } |
228 } | 229 } |
229 | 230 |
230 void OmniboxAPI::OnExtensionUnloaded(content::BrowserContext* browser_context, | 231 void OmniboxAPI::OnExtensionUnloaded(content::BrowserContext* browser_context, |
231 const Extension* extension, | 232 const Extension* extension, |
232 UnloadedExtensionInfo::Reason reason) { | 233 UnloadedExtensionInfo::Reason reason) { |
233 if (!OmniboxInfo::GetKeyword(extension).empty() && url_service_) { | 234 if (!OmniboxInfo::GetKeyword(extension).empty() && url_service_) { |
234 if (url_service_->loaded()) { | 235 if (url_service_->loaded()) { |
235 url_service_->RemoveExtensionControlledTURL( | 236 url_service_->RemoveExtensionControlledTURL( |
236 extension->id(), TemplateURL::OMNIBOX_API_EXTENSION); | 237 extension->id(), TemplateURL::OMNIBOX_API_EXTENSION); |
237 } else { | 238 } else { |
238 pending_extensions_.erase(extension); | 239 pending_extensions_.erase(extension); |
239 } | 240 } |
240 } | 241 } |
241 } | 242 } |
242 | 243 |
243 gfx::Image OmniboxAPI::GetOmniboxIcon(const std::string& extension_id) { | 244 gfx::Image OmniboxAPI::GetOmniboxIcon(const std::string& extension_id) { |
244 return omnibox_icon_manager_.GetIcon(extension_id); | 245 return omnibox_icon_manager_.GetIcon(extension_id); |
245 } | 246 } |
246 | 247 |
247 void OmniboxAPI::OnTemplateURLsLoaded() { | 248 void OmniboxAPI::OnTemplateURLsLoaded() { |
248 // Register keywords for pending extensions. | 249 // Register keywords for pending extensions. |
249 template_url_sub_.reset(); | 250 template_url_sub_.reset(); |
250 for (PendingExtensions::const_iterator i(pending_extensions_.begin()); | 251 for (const auto i : pending_extensions_) { |
Peter Kasting
2017/02/25 04:26:53
Nit: Should (I think) be const auto*
Alexander Yashkin
2017/02/25 11:34:06
Done.
| |
251 i != pending_extensions_.end(); ++i) { | |
252 url_service_->RegisterOmniboxKeyword( | 252 url_service_->RegisterOmniboxKeyword( |
253 (*i)->id(), (*i)->name(), OmniboxInfo::GetKeyword(*i), | 253 i->id(), i->name(), OmniboxInfo::GetKeyword(i), |
254 GetTemplateURLStringForExtension((*i)->id())); | 254 GetTemplateURLStringForExtension(i->id()), |
255 ExtensionPrefs::Get(profile_)->GetInstallTime(i->id())); | |
255 } | 256 } |
256 pending_extensions_.clear(); | 257 pending_extensions_.clear(); |
257 } | 258 } |
258 | 259 |
259 template <> | 260 template <> |
260 void BrowserContextKeyedAPIFactory<OmniboxAPI>::DeclareFactoryDependencies() { | 261 void BrowserContextKeyedAPIFactory<OmniboxAPI>::DeclareFactoryDependencies() { |
261 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); | 262 DependsOn(ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); |
262 DependsOn(ExtensionPrefsFactory::GetInstance()); | 263 DependsOn(ExtensionPrefsFactory::GetInstance()); |
263 DependsOn(TemplateURLServiceFactory::GetInstance()); | 264 DependsOn(TemplateURLServiceFactory::GetInstance()); |
264 } | 265 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 for (size_t i = 0; i < description_styles.size(); ++i) { | 375 for (size_t i = 0; i < description_styles.size(); ++i) { |
375 if (description_styles[i].offset > placeholder) | 376 if (description_styles[i].offset > placeholder) |
376 description_styles[i].offset += replacement.length() - 2; | 377 description_styles[i].offset += replacement.length() - 2; |
377 } | 378 } |
378 } | 379 } |
379 | 380 |
380 match->contents.assign(description); | 381 match->contents.assign(description); |
381 } | 382 } |
382 | 383 |
383 } // namespace extensions | 384 } // namespace extensions |
OLD | NEW |