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

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

Issue 2898383002: [Extensions] Make Event::restrict_to_browser_context const. (Closed)
Patch Set: sync @tott Created 3 years, 6 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // This URL is not actually used for navigation. It holds the extension's ID. 89 // This URL is not actually used for navigation. It holds the extension's ID.
90 return std::string(extensions::kExtensionScheme) + "://" + 90 return std::string(extensions::kExtensionScheme) + "://" +
91 extension_id + "/?q={searchTerms}"; 91 extension_id + "/?q={searchTerms}";
92 } 92 }
93 93
94 } // namespace 94 } // namespace
95 95
96 // static 96 // static
97 void ExtensionOmniboxEventRouter::OnInputStarted( 97 void ExtensionOmniboxEventRouter::OnInputStarted(
98 Profile* profile, const std::string& extension_id) { 98 Profile* profile, const std::string& extension_id) {
99 std::unique_ptr<Event> event = base::MakeUnique<Event>( 99 auto event = base::MakeUnique<Event>(
100 events::OMNIBOX_ON_INPUT_STARTED, omnibox::OnInputStarted::kEventName, 100 events::OMNIBOX_ON_INPUT_STARTED, omnibox::OnInputStarted::kEventName,
101 base::MakeUnique<base::ListValue>()); 101 base::MakeUnique<base::ListValue>(), profile);
102 event->restrict_to_browser_context = profile;
103 EventRouter::Get(profile) 102 EventRouter::Get(profile)
104 ->DispatchEventToExtension(extension_id, std::move(event)); 103 ->DispatchEventToExtension(extension_id, std::move(event));
105 } 104 }
106 105
107 // static 106 // static
108 bool ExtensionOmniboxEventRouter::OnInputChanged( 107 bool ExtensionOmniboxEventRouter::OnInputChanged(
109 Profile* profile, const std::string& extension_id, 108 Profile* profile, const std::string& extension_id,
110 const std::string& input, int suggest_id) { 109 const std::string& input, int suggest_id) {
111 EventRouter* event_router = EventRouter::Get(profile); 110 EventRouter* event_router = EventRouter::Get(profile);
112 if (!event_router->ExtensionHasEventListener( 111 if (!event_router->ExtensionHasEventListener(
113 extension_id, omnibox::OnInputChanged::kEventName)) 112 extension_id, omnibox::OnInputChanged::kEventName))
114 return false; 113 return false;
115 114
116 std::unique_ptr<base::ListValue> args(new base::ListValue()); 115 std::unique_ptr<base::ListValue> args(new base::ListValue());
117 args->Set(0, base::MakeUnique<base::Value>(input)); 116 args->Set(0, base::MakeUnique<base::Value>(input));
118 args->Set(1, base::MakeUnique<base::Value>(suggest_id)); 117 args->Set(1, base::MakeUnique<base::Value>(suggest_id));
119 118
120 std::unique_ptr<Event> event = base::MakeUnique<Event>( 119 auto event = base::MakeUnique<Event>(events::OMNIBOX_ON_INPUT_CHANGED,
121 events::OMNIBOX_ON_INPUT_CHANGED, omnibox::OnInputChanged::kEventName, 120 omnibox::OnInputChanged::kEventName,
122 std::move(args)); 121 std::move(args), profile);
123 event->restrict_to_browser_context = profile;
124 event_router->DispatchEventToExtension(extension_id, std::move(event)); 122 event_router->DispatchEventToExtension(extension_id, std::move(event));
125 return true; 123 return true;
126 } 124 }
127 125
128 // static 126 // static
129 void ExtensionOmniboxEventRouter::OnInputEntered( 127 void ExtensionOmniboxEventRouter::OnInputEntered(
130 content::WebContents* web_contents, 128 content::WebContents* web_contents,
131 const std::string& extension_id, 129 const std::string& extension_id,
132 const std::string& input, 130 const std::string& input,
133 WindowOpenDisposition disposition) { 131 WindowOpenDisposition disposition) {
134 Profile* profile = 132 Profile* profile =
135 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 133 Profile::FromBrowserContext(web_contents->GetBrowserContext());
136 134
137 const Extension* extension = 135 const Extension* extension =
138 ExtensionRegistry::Get(profile)->enabled_extensions().GetByID( 136 ExtensionRegistry::Get(profile)->enabled_extensions().GetByID(
139 extension_id); 137 extension_id);
140 CHECK(extension); 138 CHECK(extension);
141 extensions::TabHelper::FromWebContents(web_contents)-> 139 extensions::TabHelper::FromWebContents(web_contents)->
142 active_tab_permission_granter()->GrantIfRequested(extension); 140 active_tab_permission_granter()->GrantIfRequested(extension);
143 141
144 std::unique_ptr<base::ListValue> args(new base::ListValue()); 142 std::unique_ptr<base::ListValue> args(new base::ListValue());
145 args->Set(0, base::MakeUnique<base::Value>(input)); 143 args->Set(0, base::MakeUnique<base::Value>(input));
146 if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) 144 if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB)
147 args->Set(1, base::MakeUnique<base::Value>(kForegroundTabDisposition)); 145 args->Set(1, base::MakeUnique<base::Value>(kForegroundTabDisposition));
148 else if (disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB) 146 else if (disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB)
149 args->Set(1, base::MakeUnique<base::Value>(kBackgroundTabDisposition)); 147 args->Set(1, base::MakeUnique<base::Value>(kBackgroundTabDisposition));
150 else 148 else
151 args->Set(1, base::MakeUnique<base::Value>(kCurrentTabDisposition)); 149 args->Set(1, base::MakeUnique<base::Value>(kCurrentTabDisposition));
152 150
153 std::unique_ptr<Event> event = base::MakeUnique<Event>( 151 auto event = base::MakeUnique<Event>(events::OMNIBOX_ON_INPUT_ENTERED,
154 events::OMNIBOX_ON_INPUT_ENTERED, omnibox::OnInputEntered::kEventName, 152 omnibox::OnInputEntered::kEventName,
155 std::move(args)); 153 std::move(args), profile);
156 event->restrict_to_browser_context = profile;
157 EventRouter::Get(profile) 154 EventRouter::Get(profile)
158 ->DispatchEventToExtension(extension_id, std::move(event)); 155 ->DispatchEventToExtension(extension_id, std::move(event));
159 156
160 content::NotificationService::current()->Notify( 157 content::NotificationService::current()->Notify(
161 extensions::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED, 158 extensions::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED,
162 content::Source<Profile>(profile), 159 content::Source<Profile>(profile),
163 content::NotificationService::NoDetails()); 160 content::NotificationService::NoDetails());
164 } 161 }
165 162
166 // static 163 // static
167 void ExtensionOmniboxEventRouter::OnInputCancelled( 164 void ExtensionOmniboxEventRouter::OnInputCancelled(
168 Profile* profile, const std::string& extension_id) { 165 Profile* profile, const std::string& extension_id) {
169 std::unique_ptr<Event> event = base::MakeUnique<Event>( 166 auto event = base::MakeUnique<Event>(
170 events::OMNIBOX_ON_INPUT_CANCELLED, omnibox::OnInputCancelled::kEventName, 167 events::OMNIBOX_ON_INPUT_CANCELLED, omnibox::OnInputCancelled::kEventName,
171 base::MakeUnique<base::ListValue>()); 168 base::MakeUnique<base::ListValue>(), profile);
172 event->restrict_to_browser_context = profile;
173 EventRouter::Get(profile) 169 EventRouter::Get(profile)
174 ->DispatchEventToExtension(extension_id, std::move(event)); 170 ->DispatchEventToExtension(extension_id, std::move(event));
175 } 171 }
176 172
177 OmniboxAPI::OmniboxAPI(content::BrowserContext* context) 173 OmniboxAPI::OmniboxAPI(content::BrowserContext* context)
178 : profile_(Profile::FromBrowserContext(context)), 174 : profile_(Profile::FromBrowserContext(context)),
179 url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), 175 url_service_(TemplateURLServiceFactory::GetForProfile(profile_)),
180 extension_registry_observer_(this) { 176 extension_registry_observer_(this) {
181 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); 177 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
182 if (url_service_) { 178 if (url_service_) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 for (size_t i = 0; i < description_styles.size(); ++i) { 374 for (size_t i = 0; i < description_styles.size(); ++i) {
379 if (description_styles[i].offset > placeholder) 375 if (description_styles[i].offset > placeholder)
380 description_styles[i].offset += replacement.length() - 2; 376 description_styles[i].offset += replacement.length() - 2;
381 } 377 }
382 } 378 }
383 379
384 match->contents.assign(description); 380 match->contents.assign(description);
385 } 381 }
386 382
387 } // namespace extensions 383 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/mdns/mdns_api.cc ('k') | chrome/browser/extensions/api/preference/preference_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698