| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/api/omnibox/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/browser/ui/webui/ntp/app_launcher_handler.h" | 18 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 22 | 22 |
| 23 namespace events { | 23 namespace events { |
| 24 const char kOnInputStarted[] = "omnibox.onInputStarted"; | 24 const char kOnInputStarted[] = "omnibox.onInputStarted"; |
| 25 const char kOnInputChanged[] = "omnibox.onInputChanged"; | 25 const char kOnInputChanged[] = "omnibox.onInputChanged"; |
| 26 const char kOnInputEntered[] = "omnibox.onInputEntered"; | 26 const char kOnInputEntered[] = "omnibox.onInputEntered"; |
| 27 const char kOnInputCancelled[] = "omnibox.onInputCancelled"; | 27 const char kOnInputCancelled[] = "omnibox.onInputCancelled"; |
| 28 }; // namespace events | 28 } // namespace events |
| 29 |
| 30 namespace extensions { |
| 29 | 31 |
| 30 namespace { | 32 namespace { |
| 31 const char kDescriptionStylesOrderError[] = | 33 const char kDescriptionStylesOrderError[] = |
| 32 "Suggestion descriptionStyles must be in increasing non-overlapping order."; | 34 "Suggestion descriptionStyles must be in increasing non-overlapping order."; |
| 33 const char kDescriptionStylesLengthError[] = | 35 const char kDescriptionStylesLengthError[] = |
| 34 "Suggestion descriptionStyles contains an offset longer than the" | 36 "Suggestion descriptionStyles contains an offset longer than the" |
| 35 " description text"; | 37 " description text"; |
| 36 | 38 |
| 37 const char kSuggestionContent[] = "content"; | 39 const char kSuggestionContent[] = "content"; |
| 38 const char kSuggestionDescription[] = "description"; | 40 const char kSuggestionDescription[] = "description"; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 54 const ExtensionOmniboxSuggestion* GetDefaultSuggestionForExtension( | 56 const ExtensionOmniboxSuggestion* GetDefaultSuggestionForExtension( |
| 55 Profile* profile, const std::string& extension_id) { | 57 Profile* profile, const std::string& extension_id) { |
| 56 const Extension* extension = | 58 const Extension* extension = |
| 57 profile->GetExtensionService()->GetExtensionById(extension_id, false); | 59 profile->GetExtensionService()->GetExtensionById(extension_id, false); |
| 58 if (!extension) | 60 if (!extension) |
| 59 return NULL; | 61 return NULL; |
| 60 return GetPropertyAccessor().GetProperty( | 62 return GetPropertyAccessor().GetProperty( |
| 61 profile->GetExtensionService()->GetPropertyBag(extension)); | 63 profile->GetExtensionService()->GetPropertyBag(extension)); |
| 62 } | 64 } |
| 63 | 65 |
| 64 }; // namespace | 66 } // namespace |
| 65 | 67 |
| 66 // static | 68 // static |
| 67 void ExtensionOmniboxEventRouter::OnInputStarted( | 69 void ExtensionOmniboxEventRouter::OnInputStarted( |
| 68 Profile* profile, const std::string& extension_id) { | 70 Profile* profile, const std::string& extension_id) { |
| 69 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 71 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
| 70 extension_id, events::kOnInputStarted, "[]", profile, GURL()); | 72 extension_id, events::kOnInputStarted, "[]", profile, GURL()); |
| 71 } | 73 } |
| 72 | 74 |
| 73 // static | 75 // static |
| 74 bool ExtensionOmniboxEventRouter::OnInputChanged( | 76 bool ExtensionOmniboxEventRouter::OnInputChanged( |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 | 290 |
| 289 // Look at the preferences to find the right launch container. If no | 291 // Look at the preferences to find the right launch container. If no |
| 290 // preference is set, launch as a regular tab. | 292 // preference is set, launch as a regular tab. |
| 291 extension_misc::LaunchContainer launch_container = | 293 extension_misc::LaunchContainer launch_container = |
| 292 service->extension_prefs()->GetLaunchContainer( | 294 service->extension_prefs()->GetLaunchContainer( |
| 293 extension, ExtensionPrefs::LAUNCH_REGULAR); | 295 extension, ExtensionPrefs::LAUNCH_REGULAR); |
| 294 | 296 |
| 295 Browser::OpenApplication(profile, extension, launch_container, GURL(), | 297 Browser::OpenApplication(profile, extension, launch_container, GURL(), |
| 296 disposition); | 298 disposition); |
| 297 } | 299 } |
| 300 |
| 301 } // namespace extensions |
| OLD | NEW |