| 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/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_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/extension_tab_helper.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/search_engines/template_url.h" | 19 #include "chrome/browser/search_engines/template_url.h" |
| 20 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" | 22 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 22 | 24 |
| 23 namespace events { | 25 namespace events { |
| 24 const char kOnInputStarted[] = "omnibox.onInputStarted"; | 26 const char kOnInputStarted[] = "omnibox.onInputStarted"; |
| 25 const char kOnInputChanged[] = "omnibox.onInputChanged"; | 27 const char kOnInputChanged[] = "omnibox.onInputChanged"; |
| 26 const char kOnInputEntered[] = "omnibox.onInputEntered"; | 28 const char kOnInputEntered[] = "omnibox.onInputEntered"; |
| 27 const char kOnInputCancelled[] = "omnibox.onInputCancelled"; | 29 const char kOnInputCancelled[] = "omnibox.onInputCancelled"; |
| 28 } // namespace events | 30 } // namespace events |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 std::string json_args; | 69 std::string json_args; |
| 68 base::JSONWriter::Write(&args, &json_args); | 70 base::JSONWriter::Write(&args, &json_args); |
| 69 | 71 |
| 70 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 72 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
| 71 extension_id, events::kOnInputChanged, json_args, profile, GURL()); | 73 extension_id, events::kOnInputChanged, json_args, profile, GURL()); |
| 72 return true; | 74 return true; |
| 73 } | 75 } |
| 74 | 76 |
| 75 // static | 77 // static |
| 76 void ExtensionOmniboxEventRouter::OnInputEntered( | 78 void ExtensionOmniboxEventRouter::OnInputEntered( |
| 77 Profile* profile, const std::string& extension_id, | 79 TabContents* tab_contents, |
| 80 const std::string& extension_id, |
| 78 const std::string& input) { | 81 const std::string& input) { |
| 79 ListValue args; | 82 ListValue args; |
| 80 args.Set(0, Value::CreateStringValue(input)); | 83 args.Set(0, Value::CreateStringValue(input)); |
| 81 std::string json_args; | 84 std::string json_args; |
| 82 base::JSONWriter::Write(&args, &json_args); | 85 base::JSONWriter::Write(&args, &json_args); |
| 83 | 86 |
| 87 tab_contents->extension_tab_helper()->active_tab_permission_manager()-> |
| 88 GrantIfRequested(extension_id); |
| 89 |
| 90 Profile* profile = tab_contents->profile(); |
| 91 |
| 84 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 92 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
| 85 extension_id, events::kOnInputEntered, json_args, profile, GURL()); | 93 extension_id, events::kOnInputEntered, json_args, profile, GURL()); |
| 86 | 94 |
| 87 content::NotificationService::current()->Notify( | 95 content::NotificationService::current()->Notify( |
| 88 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, | 96 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, |
| 89 content::Source<Profile>(profile), | 97 content::Source<Profile>(profile), |
| 90 content::NotificationService::NoDetails()); | 98 content::NotificationService::NoDetails()); |
| 91 } | 99 } |
| 92 | 100 |
| 93 // static | 101 // static |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 for (size_t i = 0; i < description_styles.size(); ++i) { | 299 for (size_t i = 0; i < description_styles.size(); ++i) { |
| 292 if (description_styles[i].offset > placeholder) | 300 if (description_styles[i].offset > placeholder) |
| 293 description_styles[i].offset += replacement.length() - 2; | 301 description_styles[i].offset += replacement.length() - 2; |
| 294 } | 302 } |
| 295 } | 303 } |
| 296 | 304 |
| 297 match->contents.assign(description); | 305 match->contents.assign(description); |
| 298 } | 306 } |
| 299 | 307 |
| 300 } // namespace extensions | 308 } // namespace extensions |
| OLD | NEW |