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/input_ime/input_ime_api.h" | 5 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/common/extensions/api/input_ime.h" | 9 #include "chrome/common/extensions/api/input_ime.h" |
10 #include "content/public/browser/notification_registrar.h" | 10 #include "content/public/browser/notification_registrar.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 input_ime::OnSurroundingTextChanged::kEventName, std::move(args)); | 167 input_ime::OnSurroundingTextChanged::kEventName, std::move(args)); |
168 } | 168 } |
169 | 169 |
170 bool ImeObserver::ShouldForwardKeyEvent() const { | 170 bool ImeObserver::ShouldForwardKeyEvent() const { |
171 // Only forward key events to extension if there are non-lazy listeners | 171 // Only forward key events to extension if there are non-lazy listeners |
172 // for onKeyEvent. Because if something wrong with the lazy background | 172 // for onKeyEvent. Because if something wrong with the lazy background |
173 // page which doesn't register listener for onKeyEvent, it will not handle | 173 // page which doesn't register listener for onKeyEvent, it will not handle |
174 // the key events, and therefore, all key events will be eaten. | 174 // the key events, and therefore, all key events will be eaten. |
175 // This is for error-tolerance, and it means that onKeyEvent will never wake | 175 // This is for error-tolerance, and it means that onKeyEvent will never wake |
176 // up lazy background page. | 176 // up lazy background page. |
177 const extensions::EventListenerMap::ListenerList& listener_list = | 177 const extensions::EventListenerMap::ListenerList& listeners = |
178 extensions::EventRouter::Get(profile_) | 178 extensions::EventRouter::Get(profile_) |
179 ->listeners() | 179 ->listeners() |
180 .GetEventListenersByName(input_ime::OnKeyEvent::kEventName); | 180 .GetEventListenersByName(input_ime::OnKeyEvent::kEventName); |
181 for (extensions::EventListenerMap::ListenerList::const_iterator it = | 181 for (const std::unique_ptr<extensions::EventListener>& listener : listeners) { |
182 listener_list.begin(); | 182 if (listener->extension_id() == extension_id_ && !listener->IsLazy()) |
183 it != listener_list.end(); ++it) { | |
184 if ((*it)->extension_id() == extension_id_ && !(*it)->IsLazy()) | |
185 return true; | 183 return true; |
186 } | 184 } |
187 return false; | 185 return false; |
188 } | 186 } |
189 | 187 |
190 bool ImeObserver::HasListener(const std::string& event_name) const { | 188 bool ImeObserver::HasListener(const std::string& event_name) const { |
191 return extensions::EventRouter::Get(profile_)->HasEventListener(event_name); | 189 return extensions::EventRouter::Get(profile_)->HasEventListener(event_name); |
192 } | 190 } |
193 | 191 |
194 std::string ImeObserver::ConvertInputContextType( | 192 std::string ImeObserver::ConvertInputContextType( |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 InputImeEventRouter* GetInputImeEventRouter(Profile* profile) { | 410 InputImeEventRouter* GetInputImeEventRouter(Profile* profile) { |
413 if (!profile) | 411 if (!profile) |
414 return nullptr; | 412 return nullptr; |
415 if (profile->HasOffTheRecordProfile()) | 413 if (profile->HasOffTheRecordProfile()) |
416 profile = profile->GetOffTheRecordProfile(); | 414 profile = profile->GetOffTheRecordProfile(); |
417 return extensions::InputImeEventRouterFactory::GetInstance()->GetRouter( | 415 return extensions::InputImeEventRouterFactory::GetInstance()->GetRouter( |
418 profile); | 416 profile); |
419 } | 417 } |
420 | 418 |
421 } // namespace extensions | 419 } // namespace extensions |
OLD | NEW |