Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: chrome/browser/extensions/api/omnibox/omnibox_api.cc

Issue 238633009: cleanup: Use EventRouter instead of ExtensionSystem::Get->event_router() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile error for chromeos build. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/extensions/tab_helper.h" 14 #include "chrome/browser/extensions/tab_helper.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/search_engines/template_url_service.h" 17 #include "chrome/browser/search_engines/template_url_service.h"
18 #include "chrome/browser/search_engines/template_url_service_factory.h" 18 #include "chrome/browser/search_engines/template_url_service_factory.h"
19 #include "chrome/common/extensions/api/omnibox.h" 19 #include "chrome/common/extensions/api/omnibox.h"
20 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h" 20 #include "chrome/common/extensions/api/omnibox/omnibox_handler.h"
21 #include "content/public/browser/notification_details.h" 21 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
23 #include "extensions/browser/event_router.h" 23 #include "extensions/browser/event_router.h"
24 #include "extensions/browser/extension_prefs.h" 24 #include "extensions/browser/extension_prefs.h"
25 #include "extensions/browser/extension_prefs_factory.h" 25 #include "extensions/browser/extension_prefs_factory.h"
26 #include "extensions/browser/extension_registry.h" 26 #include "extensions/browser/extension_registry.h"
27 #include "extensions/browser/extension_system.h"
28 #include "extensions/browser/extension_system_provider.h" 27 #include "extensions/browser/extension_system_provider.h"
29 #include "extensions/browser/extensions_browser_client.h" 28 #include "extensions/browser/extensions_browser_client.h"
30 #include "extensions/common/extension.h" 29 #include "extensions/common/extension.h"
31 #include "ui/gfx/image/image.h" 30 #include "ui/gfx/image/image.h"
32 31
33 namespace extensions { 32 namespace extensions {
34 33
35 namespace omnibox = api::omnibox; 34 namespace omnibox = api::omnibox;
36 namespace SendSuggestions = omnibox::SendSuggestions; 35 namespace SendSuggestions = omnibox::SendSuggestions;
37 namespace SetDefaultSuggestion = omnibox::SetDefaultSuggestion; 36 namespace SetDefaultSuggestion = omnibox::SetDefaultSuggestion;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 95
97 } // namespace 96 } // namespace
98 97
99 // static 98 // static
100 void ExtensionOmniboxEventRouter::OnInputStarted( 99 void ExtensionOmniboxEventRouter::OnInputStarted(
101 Profile* profile, const std::string& extension_id) { 100 Profile* profile, const std::string& extension_id) {
102 scoped_ptr<Event> event(new Event( 101 scoped_ptr<Event> event(new Event(
103 omnibox::OnInputStarted::kEventName, 102 omnibox::OnInputStarted::kEventName,
104 make_scoped_ptr(new base::ListValue()))); 103 make_scoped_ptr(new base::ListValue())));
105 event->restrict_to_browser_context = profile; 104 event->restrict_to_browser_context = profile;
106 ExtensionSystem::Get(profile)->event_router()-> 105 EventRouter::Get(profile)
107 DispatchEventToExtension(extension_id, event.Pass()); 106 ->DispatchEventToExtension(extension_id, event.Pass());
108 } 107 }
109 108
110 // static 109 // static
111 bool ExtensionOmniboxEventRouter::OnInputChanged( 110 bool ExtensionOmniboxEventRouter::OnInputChanged(
112 Profile* profile, const std::string& extension_id, 111 Profile* profile, const std::string& extension_id,
113 const std::string& input, int suggest_id) { 112 const std::string& input, int suggest_id) {
114 if (!ExtensionSystem::Get(profile)->event_router()->ExtensionHasEventListener( 113 EventRouter* event_router = EventRouter::Get(profile);
115 extension_id, omnibox::OnInputChanged::kEventName)) 114 if (!event_router->ExtensionHasEventListener(
115 extension_id, omnibox::OnInputChanged::kEventName))
116 return false; 116 return false;
117 117
118 scoped_ptr<base::ListValue> args(new base::ListValue()); 118 scoped_ptr<base::ListValue> args(new base::ListValue());
119 args->Set(0, new base::StringValue(input)); 119 args->Set(0, new base::StringValue(input));
120 args->Set(1, new base::FundamentalValue(suggest_id)); 120 args->Set(1, new base::FundamentalValue(suggest_id));
121 121
122 scoped_ptr<Event> event(new Event(omnibox::OnInputChanged::kEventName, 122 scoped_ptr<Event> event(new Event(omnibox::OnInputChanged::kEventName,
123 args.Pass())); 123 args.Pass()));
124 event->restrict_to_browser_context = profile; 124 event->restrict_to_browser_context = profile;
125 ExtensionSystem::Get(profile)->event_router()-> 125 event_router->DispatchEventToExtension(extension_id, event.Pass());
126 DispatchEventToExtension(extension_id, event.Pass());
127 return true; 126 return true;
128 } 127 }
129 128
130 // static 129 // static
131 void ExtensionOmniboxEventRouter::OnInputEntered( 130 void ExtensionOmniboxEventRouter::OnInputEntered(
132 content::WebContents* web_contents, 131 content::WebContents* web_contents,
133 const std::string& extension_id, 132 const std::string& extension_id,
134 const std::string& input, 133 const std::string& input,
135 WindowOpenDisposition disposition) { 134 WindowOpenDisposition disposition) {
136 Profile* profile = 135 Profile* profile =
(...skipping 11 matching lines...) Expand all
148 if (disposition == NEW_FOREGROUND_TAB) 147 if (disposition == NEW_FOREGROUND_TAB)
149 args->Set(1, new base::StringValue(kForegroundTabDisposition)); 148 args->Set(1, new base::StringValue(kForegroundTabDisposition));
150 else if (disposition == NEW_BACKGROUND_TAB) 149 else if (disposition == NEW_BACKGROUND_TAB)
151 args->Set(1, new base::StringValue(kBackgroundTabDisposition)); 150 args->Set(1, new base::StringValue(kBackgroundTabDisposition));
152 else 151 else
153 args->Set(1, new base::StringValue(kCurrentTabDisposition)); 152 args->Set(1, new base::StringValue(kCurrentTabDisposition));
154 153
155 scoped_ptr<Event> event(new Event(omnibox::OnInputEntered::kEventName, 154 scoped_ptr<Event> event(new Event(omnibox::OnInputEntered::kEventName,
156 args.Pass())); 155 args.Pass()));
157 event->restrict_to_browser_context = profile; 156 event->restrict_to_browser_context = profile;
158 ExtensionSystem::Get(profile)->event_router()-> 157 EventRouter::Get(profile)
159 DispatchEventToExtension(extension_id, event.Pass()); 158 ->DispatchEventToExtension(extension_id, event.Pass());
160 159
161 content::NotificationService::current()->Notify( 160 content::NotificationService::current()->Notify(
162 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, 161 chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED,
163 content::Source<Profile>(profile), 162 content::Source<Profile>(profile),
164 content::NotificationService::NoDetails()); 163 content::NotificationService::NoDetails());
165 } 164 }
166 165
167 // static 166 // static
168 void ExtensionOmniboxEventRouter::OnInputCancelled( 167 void ExtensionOmniboxEventRouter::OnInputCancelled(
169 Profile* profile, const std::string& extension_id) { 168 Profile* profile, const std::string& extension_id) {
170 scoped_ptr<Event> event(new Event( 169 scoped_ptr<Event> event(new Event(
171 omnibox::OnInputCancelled::kEventName, 170 omnibox::OnInputCancelled::kEventName,
172 make_scoped_ptr(new base::ListValue()))); 171 make_scoped_ptr(new base::ListValue())));
173 event->restrict_to_browser_context = profile; 172 event->restrict_to_browser_context = profile;
174 ExtensionSystem::Get(profile)->event_router()-> 173 EventRouter::Get(profile)
175 DispatchEventToExtension(extension_id, event.Pass()); 174 ->DispatchEventToExtension(extension_id, event.Pass());
176 } 175 }
177 176
178 OmniboxAPI::OmniboxAPI(content::BrowserContext* context) 177 OmniboxAPI::OmniboxAPI(content::BrowserContext* context)
179 : profile_(Profile::FromBrowserContext(context)), 178 : profile_(Profile::FromBrowserContext(context)),
180 url_service_(TemplateURLServiceFactory::GetForProfile(profile_)) { 179 url_service_(TemplateURLServiceFactory::GetForProfile(profile_)) {
181 registrar_.Add(this, 180 registrar_.Add(this,
182 chrome::NOTIFICATION_EXTENSION_LOADED, 181 chrome::NOTIFICATION_EXTENSION_LOADED,
183 content::Source<Profile>(profile_)); 182 content::Source<Profile>(profile_));
184 registrar_.Add(this, 183 registrar_.Add(this,
185 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, 184 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 for (size_t i = 0; i < description_styles.size(); ++i) { 397 for (size_t i = 0; i < description_styles.size(); ++i) {
399 if (description_styles[i].offset > placeholder) 398 if (description_styles[i].offset > placeholder)
400 description_styles[i].offset += replacement.length() - 2; 399 description_styles[i].offset += replacement.length() - 2;
401 } 400 }
402 } 401 }
403 402
404 match->contents.assign(description); 403 match->contents.assign(description);
405 } 404 }
406 405
407 } // namespace extensions 406 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698