| 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/lazy_instance.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/extension_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 { |
| 19 const char kOnInputStarted[] = "omnibox.onInputStarted"; | 19 const char kOnInputStarted[] = "omnibox.onInputStarted"; |
| 20 const char kOnInputChanged[] = "omnibox.onInputChanged"; | 20 const char kOnInputChanged[] = "omnibox.onInputChanged"; |
| 21 const char kOnInputEntered[] = "omnibox.onInputEntered"; | 21 const char kOnInputEntered[] = "omnibox.onInputEntered"; |
| 22 const char kOnInputCancelled[] = "omnibox.onInputCancelled"; | 22 const char kOnInputCancelled[] = "omnibox.onInputCancelled"; |
| 23 }; // namespace events | 23 }; // namespace events |
| (...skipping 17 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 PropertyAccessor<ExtensionOmniboxSuggestion>& GetPropertyAccessor() { | 42 PropertyAccessor<ExtensionOmniboxSuggestion>& GetPropertyAccessor() { |
| 43 return g_extension_omnibox_suggestion_property_accessor.Get(); | 43 return g_extension_omnibox_suggestion_property_accessor.Get(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 // Returns the suggestion object set by the extension via the | 46 // Returns the suggestion object set by the extension via the |
| 47 // omnibox.setDefaultSuggestion call, or NULL if it was never set. | 47 // omnibox.setDefaultSuggestion call, or NULL if it was never set. |
| 48 const ExtensionOmniboxSuggestion* GetDefaultSuggestionForExtension( | 48 const ExtensionOmniboxSuggestion* GetDefaultSuggestionForExtension( |
| 49 Profile* profile, const std::string& extension_id) { | 49 Profile* profile, const std::string& extension_id) { |
| 50 const Extension* extension = | 50 const Extension* extension = |
| 51 profile->GetExtensionsService()->GetExtensionById(extension_id, false); | 51 profile->GetExtensionService()->GetExtensionById(extension_id, false); |
| 52 if (!extension) | 52 if (!extension) |
| 53 return NULL; | 53 return NULL; |
| 54 return GetPropertyAccessor().GetProperty( | 54 return GetPropertyAccessor().GetProperty( |
| 55 profile->GetExtensionsService()->GetPropertyBag(extension)); | 55 profile->GetExtensionService()->GetPropertyBag(extension)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 }; // namespace | 58 }; // namespace |
| 59 | 59 |
| 60 // static | 60 // static |
| 61 void ExtensionOmniboxEventRouter::OnInputStarted( | 61 void ExtensionOmniboxEventRouter::OnInputStarted( |
| 62 Profile* profile, const std::string& extension_id) { | 62 Profile* profile, const std::string& extension_id) { |
| 63 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 63 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
| 64 extension_id, events::kOnInputStarted, "[]", profile, GURL()); | 64 extension_id, events::kOnInputStarted, "[]", profile, GURL()); |
| 65 } | 65 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 suggestion_value->GetList(kSuggestionDescriptionStyles, &styles)); | 157 suggestion_value->GetList(kSuggestionDescriptionStyles, &styles)); |
| 158 EXTENSION_FUNCTION_VALIDATE(suggestion.ReadStylesFromValue(*styles)); | 158 EXTENSION_FUNCTION_VALIDATE(suggestion.ReadStylesFromValue(*styles)); |
| 159 } else { | 159 } else { |
| 160 suggestion.description_styles.clear(); | 160 suggestion.description_styles.clear(); |
| 161 suggestion.description_styles.push_back( | 161 suggestion.description_styles.push_back( |
| 162 ACMatchClassification(0, ACMatchClassification::NONE)); | 162 ACMatchClassification(0, ACMatchClassification::NONE)); |
| 163 } | 163 } |
| 164 | 164 |
| 165 // Store the suggestion in the extension's runtime data. | 165 // Store the suggestion in the extension's runtime data. |
| 166 GetPropertyAccessor().SetProperty( | 166 GetPropertyAccessor().SetProperty( |
| 167 profile_->GetExtensionsService()->GetPropertyBag(GetExtension()), | 167 profile_->GetExtensionService()->GetPropertyBag(GetExtension()), |
| 168 suggestion); | 168 suggestion); |
| 169 | 169 |
| 170 NotificationService::current()->Notify( | 170 NotificationService::current()->Notify( |
| 171 NotificationType::EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED, | 171 NotificationType::EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED, |
| 172 Source<Profile>(profile_), | 172 Source<Profile>(profile_), |
| 173 NotificationService::NoDetails()); | 173 NotificationService::NoDetails()); |
| 174 | 174 |
| 175 return true; | 175 return true; |
| 176 } | 176 } |
| 177 | 177 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 description.replace(placeholder, kPlaceholderText.length(), replacement); | 256 description.replace(placeholder, kPlaceholderText.length(), replacement); |
| 257 | 257 |
| 258 for (size_t i = 0; i < description_styles.size(); ++i) { | 258 for (size_t i = 0; i < description_styles.size(); ++i) { |
| 259 if (description_styles[i].offset > placeholder) | 259 if (description_styles[i].offset > placeholder) |
| 260 description_styles[i].offset += replacement.length() - 2; | 260 description_styles[i].offset += replacement.length() - 2; |
| 261 } | 261 } |
| 262 } | 262 } |
| 263 | 263 |
| 264 match->contents.assign(UTF16ToWide(description)); | 264 match->contents.assign(UTF16ToWide(description)); |
| 265 } | 265 } |
| OLD | NEW |