| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/extension_omnibox_api.h" | 5 #include "chrome/browser/extensions/extension_omnibox_api.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/singleton.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/extension_event_router.h" | 12 #include "chrome/browser/extensions/extension_event_router.h" |
| 13 #include "chrome/browser/extensions/extensions_service.h" | 13 #include "chrome/browser/extensions/extensions_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/search_engines/template_url.h" | 15 #include "chrome/browser/search_engines/template_url.h" |
| 16 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
| 17 | 17 |
| 18 namespace events { | 18 namespace events { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 29 "Suggestion descriptionStyles contains an offset longer than the" | 29 "Suggestion descriptionStyles contains an offset longer than the" |
| 30 " description text"; | 30 " description text"; |
| 31 | 31 |
| 32 const char kSuggestionContent[] = "content"; | 32 const char kSuggestionContent[] = "content"; |
| 33 const char kSuggestionDescription[] = "description"; | 33 const char kSuggestionDescription[] = "description"; |
| 34 const char kSuggestionDescriptionStyles[] = "descriptionStyles"; | 34 const char kSuggestionDescriptionStyles[] = "descriptionStyles"; |
| 35 const char kDescriptionStylesType[] = "type"; | 35 const char kDescriptionStylesType[] = "type"; |
| 36 const char kDescriptionStylesOffset[] = "offset"; | 36 const char kDescriptionStylesOffset[] = "offset"; |
| 37 const char kDescriptionStylesLength[] = "length"; | 37 const char kDescriptionStylesLength[] = "length"; |
| 38 | 38 |
| 39 static base::LazyInstance<PropertyAccessor<ExtensionOmniboxSuggestion> > |
| 40 g_extension_omnibox_suggestion_property_accessor(base::LINKER_INITIALIZED); |
| 41 |
| 39 PropertyAccessor<ExtensionOmniboxSuggestion>& GetPropertyAccessor() { | 42 PropertyAccessor<ExtensionOmniboxSuggestion>& GetPropertyAccessor() { |
| 40 return *Singleton< PropertyAccessor<ExtensionOmniboxSuggestion> >::get(); | 43 return g_extension_omnibox_suggestion_property_accessor.Get(); |
| 41 } | 44 } |
| 42 | 45 |
| 43 // Returns the suggestion object set by the extension via the | 46 // Returns the suggestion object set by the extension via the |
| 44 // omnibox.setDefaultSuggestion call, or NULL if it was never set. | 47 // omnibox.setDefaultSuggestion call, or NULL if it was never set. |
| 45 const ExtensionOmniboxSuggestion* GetDefaultSuggestionForExtension( | 48 const ExtensionOmniboxSuggestion* GetDefaultSuggestionForExtension( |
| 46 Profile* profile, const std::string& extension_id) { | 49 Profile* profile, const std::string& extension_id) { |
| 47 const Extension* extension = | 50 const Extension* extension = |
| 48 profile->GetExtensionsService()->GetExtensionById(extension_id, false); | 51 profile->GetExtensionsService()->GetExtensionById(extension_id, false); |
| 49 if (!extension) | 52 if (!extension) |
| 50 return NULL; | 53 return NULL; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 description.replace(placeholder, kPlaceholderText.length(), replacement); | 256 description.replace(placeholder, kPlaceholderText.length(), replacement); |
| 254 | 257 |
| 255 for (size_t i = 0; i < description_styles.size(); ++i) { | 258 for (size_t i = 0; i < description_styles.size(); ++i) { |
| 256 if (description_styles[i].offset > placeholder) | 259 if (description_styles[i].offset > placeholder) |
| 257 description_styles[i].offset += replacement.length() - 2; | 260 description_styles[i].offset += replacement.length() - 2; |
| 258 } | 261 } |
| 259 } | 262 } |
| 260 | 263 |
| 261 match->contents.assign(UTF16ToWide(description)); | 264 match->contents.assign(UTF16ToWide(description)); |
| 262 } | 265 } |
| OLD | NEW |