| 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/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/extension_message_service.h" | 10 #include "chrome/browser/extensions/extension_message_service.h" |
| 11 #include "chrome/browser/profile.h" | 11 #include "chrome/browser/profile.h" |
| 12 #include "chrome/common/notification_service.h" | 12 #include "chrome/common/notification_service.h" |
| 13 | 13 |
| 14 namespace events { | 14 namespace events { |
| 15 const char kOnInputStarted[] = "experimental.omnibox.onInputStarted"; | 15 const char kOnInputStarted[] = "experimental.omnibox.onInputStarted"; |
| 16 const char kOnInputChanged[] = "experimental.omnibox.onInputChanged"; | 16 const char kOnInputChanged[] = "experimental.omnibox.onInputChanged"; |
| 17 const char kOnInputEntered[] = "experimental.omnibox.onInputEntered"; | 17 const char kOnInputEntered[] = "experimental.omnibox.onInputEntered"; |
| 18 const char kOnInputCancelled[] = "experimental.omnibox.onInputCancelled"; | 18 const char kOnInputCancelled[] = "experimental.omnibox.onInputCancelled"; |
| 19 }; // namespace events | 19 }; // namespace events |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 const char kDescriptionStylesOrderError[] = | 22 const char kDescriptionStylesOrderError[] = |
| 23 "Suggestion descriptionStyles must be in increasing non-overlapping order."; | 23 "Suggestion descriptionStyles must be in increasing non-overlapping order."; |
| 24 const char kDescriptionStylesLengthError[] = | 24 const char kDescriptionStylesLengthError[] = |
| 25 "Suggestion descriptionStyles contains an offset longer than the" | 25 "Suggestion descriptionStyles contains an offset longer than the" |
| 26 " description text"; | 26 " description text"; |
| 27 | 27 |
| 28 const wchar_t kSuggestionContent[] = L"content"; | 28 const char kSuggestionContent[] = "content"; |
| 29 const wchar_t kSuggestionDescription[] = L"description"; | 29 const char kSuggestionDescription[] = "description"; |
| 30 const wchar_t kSuggestionDescriptionStyles[] = L"descriptionStyles"; | 30 const char kSuggestionDescriptionStyles[] = "descriptionStyles"; |
| 31 const wchar_t kDescriptionStylesType[] = L"type"; | 31 const char kDescriptionStylesType[] = "type"; |
| 32 const wchar_t kDescriptionStylesOffset[] = L"offset"; | 32 const char kDescriptionStylesOffset[] = "offset"; |
| 33 }; // namespace | 33 }; // namespace |
| 34 | 34 |
| 35 // static | 35 // static |
| 36 void ExtensionOmniboxEventRouter::OnInputStarted( | 36 void ExtensionOmniboxEventRouter::OnInputStarted( |
| 37 Profile* profile, const std::string& extension_id) { | 37 Profile* profile, const std::string& extension_id) { |
| 38 profile->GetExtensionMessageService()->DispatchEventToExtension( | 38 profile->GetExtensionMessageService()->DispatchEventToExtension( |
| 39 extension_id, events::kOnInputStarted, "[]", profile->IsOffTheRecord(), | 39 extension_id, events::kOnInputStarted, "[]", profile->IsOffTheRecord(), |
| 40 GURL()); | 40 GURL()); |
| 41 } | 41 } |
| 42 | 42 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 ListValue* suggestions_value; | 94 ListValue* suggestions_value; |
| 95 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id)); | 95 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id)); |
| 96 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value)); | 96 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value)); |
| 97 | 97 |
| 98 suggestions.suggestions.resize(suggestions_value->GetSize()); | 98 suggestions.suggestions.resize(suggestions_value->GetSize()); |
| 99 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) { | 99 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) { |
| 100 ExtensionOmniboxSuggestion& suggestion = suggestions.suggestions[i]; | 100 ExtensionOmniboxSuggestion& suggestion = suggestions.suggestions[i]; |
| 101 DictionaryValue* suggestion_value; | 101 DictionaryValue* suggestion_value; |
| 102 EXTENSION_FUNCTION_VALIDATE(suggestions_value->GetDictionary( | 102 EXTENSION_FUNCTION_VALIDATE(suggestions_value->GetDictionary( |
| 103 i, &suggestion_value)); | 103 i, &suggestion_value)); |
| 104 EXTENSION_FUNCTION_VALIDATE(suggestion_value->GetStringAsUTF16( | 104 EXTENSION_FUNCTION_VALIDATE(suggestion_value->GetString( |
| 105 kSuggestionContent, &suggestion.content)); | 105 kSuggestionContent, &suggestion.content)); |
| 106 EXTENSION_FUNCTION_VALIDATE(suggestion_value->GetStringAsUTF16( | 106 EXTENSION_FUNCTION_VALIDATE(suggestion_value->GetString( |
| 107 kSuggestionDescription, &suggestion.description)); | 107 kSuggestionDescription, &suggestion.description)); |
| 108 | 108 |
| 109 if (suggestion_value->HasKey(kSuggestionDescriptionStyles)) { | 109 if (suggestion_value->HasKey(kSuggestionDescriptionStyles)) { |
| 110 ListValue* styles; | 110 ListValue* styles; |
| 111 EXTENSION_FUNCTION_VALIDATE( | 111 EXTENSION_FUNCTION_VALIDATE( |
| 112 suggestion_value->GetList(kSuggestionDescriptionStyles, &styles)); | 112 suggestion_value->GetList(kSuggestionDescriptionStyles, &styles)); |
| 113 | 113 |
| 114 suggestion.description_styles.clear(); | 114 suggestion.description_styles.clear(); |
| 115 | 115 |
| 116 int last_offset = -1; | 116 int last_offset = -1; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 NotificationService::current()->Notify( | 158 NotificationService::current()->Notify( |
| 159 NotificationType::EXTENSION_OMNIBOX_SUGGESTIONS_READY, | 159 NotificationType::EXTENSION_OMNIBOX_SUGGESTIONS_READY, |
| 160 Source<Profile>(profile_), | 160 Source<Profile>(profile_), |
| 161 Details<ExtensionOmniboxSuggestions>(&suggestions)); | 161 Details<ExtensionOmniboxSuggestions>(&suggestions)); |
| 162 | 162 |
| 163 return true; | 163 return true; |
| 164 } | 164 } |
| OLD | NEW |