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