| 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/api/omnibox/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/string16.h" | 10 #include "base/string16.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/event_router.h" | 13 #include "chrome/browser/extensions/event_router.h" |
| 14 #include "chrome/browser/extensions/extension_prefs.h" | 14 #include "chrome/browser/extensions/extension_prefs.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/extension_system.h" | 16 #include "chrome/browser/extensions/extension_system.h" |
| 17 #include "chrome/browser/extensions/tab_helper.h" | 17 #include "chrome/browser/extensions/tab_helper.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/search_engines/template_url.h" | 19 #include "chrome/browser/search_engines/template_url.h" |
| 20 #include "chrome/browser/search_engines/template_url_service.h" | 20 #include "chrome/browser/search_engines/template_url_service.h" |
| 21 #include "chrome/browser/search_engines/template_url_service_factory.h" | 21 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h" | 23 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h" |
| 24 #include "chrome/common/extensions/extension.h" | 24 #include "chrome/common/extensions/extension.h" |
| 25 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 26 #include "chrome/common/extensions/manifest_handler.h" | |
| 27 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
| 28 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 29 #include "ui/gfx/image/image.h" | 27 #include "ui/gfx/image/image.h" |
| 30 | 28 |
| 31 namespace events { | 29 namespace events { |
| 32 const char kOnInputStarted[] = "omnibox.onInputStarted"; | 30 const char kOnInputStarted[] = "omnibox.onInputStarted"; |
| 33 const char kOnInputChanged[] = "omnibox.onInputChanged"; | 31 const char kOnInputChanged[] = "omnibox.onInputChanged"; |
| 34 const char kOnInputEntered[] = "omnibox.onInputEntered"; | 32 const char kOnInputEntered[] = "omnibox.onInputEntered"; |
| 35 const char kOnInputCancelled[] = "omnibox.onInputCancelled"; | 33 const char kOnInputCancelled[] = "omnibox.onInputCancelled"; |
| 36 } // namespace events | 34 } // namespace events |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 scoped_ptr<Event> event(new Event( | 122 scoped_ptr<Event> event(new Event( |
| 125 events::kOnInputCancelled, make_scoped_ptr(new ListValue()))); | 123 events::kOnInputCancelled, make_scoped_ptr(new ListValue()))); |
| 126 event->restrict_to_profile = profile; | 124 event->restrict_to_profile = profile; |
| 127 ExtensionSystem::Get(profile)->event_router()-> | 125 ExtensionSystem::Get(profile)->event_router()-> |
| 128 DispatchEventToExtension(extension_id, event.Pass()); | 126 DispatchEventToExtension(extension_id, event.Pass()); |
| 129 } | 127 } |
| 130 | 128 |
| 131 OmniboxAPI::OmniboxAPI(Profile* profile) | 129 OmniboxAPI::OmniboxAPI(Profile* profile) |
| 132 : profile_(profile), | 130 : profile_(profile), |
| 133 url_service_(TemplateURLServiceFactory::GetForProfile(profile)) { | 131 url_service_(TemplateURLServiceFactory::GetForProfile(profile)) { |
| 134 ManifestHandler::Register(extension_manifest_keys::kOmnibox, | 132 (new OmniboxHandler)->Register(); |
| 135 make_linked_ptr(new OmniboxHandler)); | |
| 136 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 133 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 137 content::Source<Profile>(profile)); | 134 content::Source<Profile>(profile)); |
| 138 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 135 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 139 content::Source<Profile>(profile)); | 136 content::Source<Profile>(profile)); |
| 140 if (url_service_) { | 137 if (url_service_) { |
| 141 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | 138 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
| 142 content::Source<TemplateURLService>(url_service_)); | 139 content::Source<TemplateURLService>(url_service_)); |
| 143 } | 140 } |
| 144 | 141 |
| 145 // Use monochrome icons for Omnibox icons. | 142 // Use monochrome icons for Omnibox icons. |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 for (size_t i = 0; i < description_styles.size(); ++i) { | 413 for (size_t i = 0; i < description_styles.size(); ++i) { |
| 417 if (description_styles[i].offset > placeholder) | 414 if (description_styles[i].offset > placeholder) |
| 418 description_styles[i].offset += replacement.length() - 2; | 415 description_styles[i].offset += replacement.length() - 2; |
| 419 } | 416 } |
| 420 } | 417 } |
| 421 | 418 |
| 422 match->contents.assign(description); | 419 match->contents.assign(description); |
| 423 } | 420 } |
| 424 | 421 |
| 425 } // namespace extensions | 422 } // namespace extensions |
| OLD | NEW |