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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 const char kDescriptionStylesType[] = "type"; | 45 const char kDescriptionStylesType[] = "type"; |
46 const char kDescriptionStylesOffset[] = "offset"; | 46 const char kDescriptionStylesOffset[] = "offset"; |
47 const char kDescriptionStylesLength[] = "length"; | 47 const char kDescriptionStylesLength[] = "length"; |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 // static | 51 // static |
52 void ExtensionOmniboxEventRouter::OnInputStarted( | 52 void ExtensionOmniboxEventRouter::OnInputStarted( |
53 Profile* profile, const std::string& extension_id) { | 53 Profile* profile, const std::string& extension_id) { |
54 scoped_ptr<ListValue> event_args(new ListValue()); | 54 scoped_ptr<ListValue> event_args(new ListValue()); |
55 profile->GetExtensionEventRouter()->DispatchEventToExtension(extension_id, | 55 extensions::ExtensionSystem::Get(profile)->event_router()-> |
56 events::kOnInputStarted, event_args.Pass(), profile, GURL()); | 56 DispatchEventToExtension(extension_id, events::kOnInputStarted, |
| 57 event_args.Pass(), profile, GURL()); |
57 } | 58 } |
58 | 59 |
59 // static | 60 // static |
60 bool ExtensionOmniboxEventRouter::OnInputChanged( | 61 bool ExtensionOmniboxEventRouter::OnInputChanged( |
61 Profile* profile, const std::string& extension_id, | 62 Profile* profile, const std::string& extension_id, |
62 const std::string& input, int suggest_id) { | 63 const std::string& input, int suggest_id) { |
63 if (!profile->GetExtensionEventRouter()->ExtensionHasEventListener( | 64 if (!extensions::ExtensionSystem::Get(profile)->event_router()-> |
64 extension_id, events::kOnInputChanged)) | 65 ExtensionHasEventListener(extension_id, events::kOnInputChanged)) |
65 return false; | 66 return false; |
66 | 67 |
67 scoped_ptr<ListValue> args(new ListValue()); | 68 scoped_ptr<ListValue> args(new ListValue()); |
68 args->Set(0, Value::CreateStringValue(input)); | 69 args->Set(0, Value::CreateStringValue(input)); |
69 args->Set(1, Value::CreateIntegerValue(suggest_id)); | 70 args->Set(1, Value::CreateIntegerValue(suggest_id)); |
70 | 71 |
71 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 72 extensions::ExtensionSystem::Get(profile)->event_router()-> |
72 extension_id, events::kOnInputChanged, args.Pass(), profile, GURL()); | 73 DispatchEventToExtension(extension_id, events::kOnInputChanged, |
| 74 args.Pass(), profile, GURL()); |
73 return true; | 75 return true; |
74 } | 76 } |
75 | 77 |
76 // static | 78 // static |
77 void ExtensionOmniboxEventRouter::OnInputEntered( | 79 void ExtensionOmniboxEventRouter::OnInputEntered( |
78 TabContents* tab_contents, | 80 TabContents* tab_contents, |
79 const std::string& extension_id, | 81 const std::string& extension_id, |
80 const std::string& input) { | 82 const std::string& input) { |
81 Profile* profile = tab_contents->profile(); | 83 Profile* profile = tab_contents->profile(); |
82 | 84 |
83 const Extension* extension = | 85 const Extension* extension = |
84 ExtensionSystem::Get(profile)->extension_service()->extensions()-> | 86 ExtensionSystem::Get(profile)->extension_service()->extensions()-> |
85 GetByID(extension_id); | 87 GetByID(extension_id); |
86 CHECK(extension); | 88 CHECK(extension); |
87 extensions::TabHelper::FromWebContents(tab_contents->web_contents())-> | 89 extensions::TabHelper::FromWebContents(tab_contents->web_contents())-> |
88 active_tab_permission_granter()->GrantIfRequested(extension); | 90 active_tab_permission_granter()->GrantIfRequested(extension); |
89 | 91 |
90 scoped_ptr<ListValue> args(new ListValue()); | 92 scoped_ptr<ListValue> args(new ListValue()); |
91 args->Set(0, Value::CreateStringValue(input)); | 93 args->Set(0, Value::CreateStringValue(input)); |
92 | 94 |
93 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 95 extensions::ExtensionSystem::Get(profile)->event_router()-> |
94 extension_id, events::kOnInputEntered, args.Pass(), profile, GURL()); | 96 DispatchEventToExtension(extension_id, events::kOnInputEntered, |
| 97 args.Pass(), profile, GURL()); |
95 | 98 |
96 content::NotificationService::current()->Notify( | 99 content::NotificationService::current()->Notify( |
97 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, | 100 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, |
98 content::Source<Profile>(profile), | 101 content::Source<Profile>(profile), |
99 content::NotificationService::NoDetails()); | 102 content::NotificationService::NoDetails()); |
100 } | 103 } |
101 | 104 |
102 // static | 105 // static |
103 void ExtensionOmniboxEventRouter::OnInputCancelled( | 106 void ExtensionOmniboxEventRouter::OnInputCancelled( |
104 Profile* profile, const std::string& extension_id) { | 107 Profile* profile, const std::string& extension_id) { |
105 scoped_ptr<ListValue> args(new ListValue()); | 108 scoped_ptr<ListValue> args(new ListValue()); |
106 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 109 extensions::ExtensionSystem::Get(profile)->event_router()-> |
107 extension_id, events::kOnInputCancelled, args.Pass(), profile, GURL()); | 110 DispatchEventToExtension(extension_id, events::kOnInputCancelled, |
| 111 args.Pass(), profile, GURL()); |
108 } | 112 } |
109 | 113 |
110 bool OmniboxSendSuggestionsFunction::RunImpl() { | 114 bool OmniboxSendSuggestionsFunction::RunImpl() { |
111 ExtensionOmniboxSuggestions suggestions; | 115 ExtensionOmniboxSuggestions suggestions; |
112 ListValue* suggestions_value; | 116 ListValue* suggestions_value; |
113 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id)); | 117 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &suggestions.request_id)); |
114 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value)); | 118 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &suggestions_value)); |
115 | 119 |
116 suggestions.suggestions.resize(suggestions_value->GetSize()); | 120 suggestions.suggestions.resize(suggestions_value->GetSize()); |
117 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) { | 121 for (size_t i = 0; i < suggestions_value->GetSize(); ++i) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 for (size_t i = 0; i < description_styles.size(); ++i) { | 305 for (size_t i = 0; i < description_styles.size(); ++i) { |
302 if (description_styles[i].offset > placeholder) | 306 if (description_styles[i].offset > placeholder) |
303 description_styles[i].offset += replacement.length() - 2; | 307 description_styles[i].offset += replacement.length() - 2; |
304 } | 308 } |
305 } | 309 } |
306 | 310 |
307 match->contents.assign(description); | 311 match->contents.assign(description); |
308 } | 312 } |
309 | 313 |
310 } // namespace extensions | 314 } // namespace extensions |
OLD | NEW |