Chromium Code Reviews| 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 | 29 |
| 30 namespace { | 30 namespace { |
| 31 const char kDescriptionStylesOrderError[] = | 31 const char kDescriptionStylesOrderError[] = |
| 32 "Suggestion descriptionStyles must be in increasing non-overlapping order."; | 32 "Suggestion descriptionStyles must be in increasing non-overlapping order."; |
| 33 const char kDescriptionStylesLengthError[] = | 33 const char kDescriptionStylesLengthError[] = |
| 34 "Suggestion descriptionStyles contains an offset longer than the" | 34 "Suggestion descriptionStyles contains an offset longer than the" |
| 35 " description text"; | 35 " description text"; |
| 36 | 36 |
| 37 const char kSuggestionContent[] = "content"; | 37 const char kSuggestionContent[] = "content"; |
| 38 const char kSuggestionDescription[] = "description"; | 38 const char kSuggestionDescription[] = "description"; |
| 39 const char kSuggestionDescriptionStyles[] = "descriptionStyles"; | 39 const char kSuggestionDescriptionStyles[] = "descriptionStyles"; |
| 40 const char kDescriptionStylesType[] = "type"; | 40 const char kDescriptionStylesType[] = "type"; |
| 41 const char kDescriptionStylesOffset[] = "offset"; | 41 const char kDescriptionStylesOffset[] = "offset"; |
| 42 const char kDescriptionStylesLength[] = "length"; | 42 const char kDescriptionStylesLength[] = "length"; |
| 43 | 43 |
| 44 static base::LazyInstance<base::PropertyAccessor<ExtensionOmniboxSuggestion> > | 44 static base::LazyInstance<base::PropertyAccessor< |
| 45 extensions::ExtensionOmniboxSuggestion> > | |
| 45 g_extension_omnibox_suggestion_property_accessor = | 46 g_extension_omnibox_suggestion_property_accessor = |
| 46 LAZY_INSTANCE_INITIALIZER; | 47 LAZY_INSTANCE_INITIALIZER; |
| 47 | 48 |
| 48 base::PropertyAccessor<ExtensionOmniboxSuggestion>& GetPropertyAccessor() { | 49 base::PropertyAccessor<extensions::ExtensionOmniboxSuggestion>& |
| 50 GetPropertyAccessor() { | |
| 49 return g_extension_omnibox_suggestion_property_accessor.Get(); | 51 return g_extension_omnibox_suggestion_property_accessor.Get(); |
| 50 } | 52 } |
| 51 | 53 |
| 52 // Returns the suggestion object set by the extension via the | 54 // Returns the suggestion object set by the extension via the |
| 53 // omnibox.setDefaultSuggestion call, or NULL if it was never set. | 55 // omnibox.setDefaultSuggestion call, or NULL if it was never set. |
| 54 const ExtensionOmniboxSuggestion* GetDefaultSuggestionForExtension( | 56 const extensions::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 |
| 67 | |
| 68 namespace extensions { | |
|
Matt Perry
2012/05/01 01:23:21
Move this to right after the #include statements.
vabr (Chromium)
2012/05/01 02:06:50
Done.
| |
| 65 | 69 |
| 66 // static | 70 // static |
| 67 void ExtensionOmniboxEventRouter::OnInputStarted( | 71 void ExtensionOmniboxEventRouter::OnInputStarted( |
| 68 Profile* profile, const std::string& extension_id) { | 72 Profile* profile, const std::string& extension_id) { |
| 69 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 73 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
| 70 extension_id, events::kOnInputStarted, "[]", profile, GURL()); | 74 extension_id, events::kOnInputStarted, "[]", profile, GURL()); |
| 71 } | 75 } |
| 72 | 76 |
| 73 // static | 77 // static |
| 74 bool ExtensionOmniboxEventRouter::OnInputChanged( | 78 bool ExtensionOmniboxEventRouter::OnInputChanged( |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 | 292 |
| 289 // Look at the preferences to find the right launch container. If no | 293 // Look at the preferences to find the right launch container. If no |
| 290 // preference is set, launch as a regular tab. | 294 // preference is set, launch as a regular tab. |
| 291 extension_misc::LaunchContainer launch_container = | 295 extension_misc::LaunchContainer launch_container = |
| 292 service->extension_prefs()->GetLaunchContainer( | 296 service->extension_prefs()->GetLaunchContainer( |
| 293 extension, ExtensionPrefs::LAUNCH_REGULAR); | 297 extension, ExtensionPrefs::LAUNCH_REGULAR); |
| 294 | 298 |
| 295 Browser::OpenApplication(profile, extension, launch_container, GURL(), | 299 Browser::OpenApplication(profile, extension, launch_container, GURL(), |
| 296 disposition); | 300 disposition); |
| 297 } | 301 } |
| 302 | |
| 303 } // namespace extensions | |
| OLD | NEW |