OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/extensions/extension_event_router.h" | 13 #include "chrome/browser/extensions/extension_event_router.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/search_engines/template_url.h" | 16 #include "chrome/browser/search_engines/template_url.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
19 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
20 #include "content/common/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
21 | 21 |
22 namespace events { | 22 namespace events { |
23 const char kOnInputStarted[] = "omnibox.onInputStarted"; | 23 const char kOnInputStarted[] = "omnibox.onInputStarted"; |
24 const char kOnInputChanged[] = "omnibox.onInputChanged"; | 24 const char kOnInputChanged[] = "omnibox.onInputChanged"; |
25 const char kOnInputEntered[] = "omnibox.onInputEntered"; | 25 const char kOnInputEntered[] = "omnibox.onInputEntered"; |
26 const char kOnInputCancelled[] = "omnibox.onInputCancelled"; | 26 const char kOnInputCancelled[] = "omnibox.onInputCancelled"; |
27 }; // namespace events | 27 }; // namespace events |
28 | 28 |
29 namespace { | 29 namespace { |
30 const char kDescriptionStylesOrderError[] = | 30 const char kDescriptionStylesOrderError[] = |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 Profile* profile, const std::string& extension_id, | 92 Profile* profile, const std::string& extension_id, |
93 const std::string& input) { | 93 const std::string& input) { |
94 ListValue args; | 94 ListValue args; |
95 args.Set(0, Value::CreateStringValue(input)); | 95 args.Set(0, Value::CreateStringValue(input)); |
96 std::string json_args; | 96 std::string json_args; |
97 base::JSONWriter::Write(&args, false, &json_args); | 97 base::JSONWriter::Write(&args, false, &json_args); |
98 | 98 |
99 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 99 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
100 extension_id, events::kOnInputEntered, json_args, profile, GURL()); | 100 extension_id, events::kOnInputEntered, json_args, profile, GURL()); |
101 | 101 |
102 NotificationService::current()->Notify( | 102 content::NotificationService::current()->Notify( |
103 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, | 103 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, |
104 content::Source<Profile>(profile), NotificationService::NoDetails()); | 104 content::Source<Profile>(profile), |
| 105 content::NotificationService::NoDetails()); |
105 } | 106 } |
106 | 107 |
107 // static | 108 // static |
108 void ExtensionOmniboxEventRouter::OnInputCancelled( | 109 void ExtensionOmniboxEventRouter::OnInputCancelled( |
109 Profile* profile, const std::string& extension_id) { | 110 Profile* profile, const std::string& extension_id) { |
110 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 111 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
111 extension_id, events::kOnInputCancelled, "[]", profile, GURL()); | 112 extension_id, events::kOnInputCancelled, "[]", profile, GURL()); |
112 } | 113 } |
113 | 114 |
114 bool OmniboxSendSuggestionsFunction::RunImpl() { | 115 bool OmniboxSendSuggestionsFunction::RunImpl() { |
(...skipping 18 matching lines...) Expand all Loading... |
133 EXTENSION_FUNCTION_VALIDATE( | 134 EXTENSION_FUNCTION_VALIDATE( |
134 suggestion_value->GetList(kSuggestionDescriptionStyles, &styles)); | 135 suggestion_value->GetList(kSuggestionDescriptionStyles, &styles)); |
135 EXTENSION_FUNCTION_VALIDATE(suggestion.ReadStylesFromValue(*styles)); | 136 EXTENSION_FUNCTION_VALIDATE(suggestion.ReadStylesFromValue(*styles)); |
136 } else { | 137 } else { |
137 suggestion.description_styles.clear(); | 138 suggestion.description_styles.clear(); |
138 suggestion.description_styles.push_back( | 139 suggestion.description_styles.push_back( |
139 ACMatchClassification(0, ACMatchClassification::NONE)); | 140 ACMatchClassification(0, ACMatchClassification::NONE)); |
140 } | 141 } |
141 } | 142 } |
142 | 143 |
143 NotificationService::current()->Notify( | 144 content::NotificationService::current()->Notify( |
144 chrome::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY, | 145 chrome::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY, |
145 content::Source<Profile>(profile_), | 146 content::Source<Profile>(profile_), |
146 content::Details<ExtensionOmniboxSuggestions>(&suggestions)); | 147 content::Details<ExtensionOmniboxSuggestions>(&suggestions)); |
147 | 148 |
148 return true; | 149 return true; |
149 } | 150 } |
150 | 151 |
151 bool OmniboxSetDefaultSuggestionFunction::RunImpl() { | 152 bool OmniboxSetDefaultSuggestionFunction::RunImpl() { |
152 ExtensionOmniboxSuggestion suggestion; | 153 ExtensionOmniboxSuggestion suggestion; |
153 DictionaryValue* suggestion_value; | 154 DictionaryValue* suggestion_value; |
(...skipping 10 matching lines...) Expand all Loading... |
164 suggestion.description_styles.clear(); | 165 suggestion.description_styles.clear(); |
165 suggestion.description_styles.push_back( | 166 suggestion.description_styles.push_back( |
166 ACMatchClassification(0, ACMatchClassification::NONE)); | 167 ACMatchClassification(0, ACMatchClassification::NONE)); |
167 } | 168 } |
168 | 169 |
169 // Store the suggestion in the extension's runtime data. | 170 // Store the suggestion in the extension's runtime data. |
170 GetPropertyAccessor().SetProperty( | 171 GetPropertyAccessor().SetProperty( |
171 profile_->GetExtensionService()->GetPropertyBag(GetExtension()), | 172 profile_->GetExtensionService()->GetPropertyBag(GetExtension()), |
172 suggestion); | 173 suggestion); |
173 | 174 |
174 NotificationService::current()->Notify( | 175 content::NotificationService::current()->Notify( |
175 chrome::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED, | 176 chrome::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED, |
176 content::Source<Profile>(profile_), | 177 content::Source<Profile>(profile_), |
177 NotificationService::NoDetails()); | 178 content::NotificationService::NoDetails()); |
178 | 179 |
179 return true; | 180 return true; |
180 } | 181 } |
181 | 182 |
182 ExtensionOmniboxSuggestion::ExtensionOmniboxSuggestion() {} | 183 ExtensionOmniboxSuggestion::ExtensionOmniboxSuggestion() {} |
183 | 184 |
184 ExtensionOmniboxSuggestion::~ExtensionOmniboxSuggestion() {} | 185 ExtensionOmniboxSuggestion::~ExtensionOmniboxSuggestion() {} |
185 | 186 |
186 bool ExtensionOmniboxSuggestion::ReadStylesFromValue( | 187 bool ExtensionOmniboxSuggestion::ReadStylesFromValue( |
187 const ListValue& styles_value) { | 188 const ListValue& styles_value) { |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); | 286 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); |
286 | 287 |
287 // Look at the preferences to find the right launch container. If no | 288 // Look at the preferences to find the right launch container. If no |
288 // preference is set, launch as a regular tab. | 289 // preference is set, launch as a regular tab. |
289 extension_misc::LaunchContainer launch_container = | 290 extension_misc::LaunchContainer launch_container = |
290 service->extension_prefs()->GetLaunchContainer( | 291 service->extension_prefs()->GetLaunchContainer( |
291 extension, ExtensionPrefs::LAUNCH_REGULAR); | 292 extension, ExtensionPrefs::LAUNCH_REGULAR); |
292 | 293 |
293 Browser::OpenApplication(profile, extension, launch_container, disposition); | 294 Browser::OpenApplication(profile, extension, launch_container, disposition); |
294 } | 295 } |
OLD | NEW |