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

Side by Side Diff: chrome/browser/extensions/api/input_ime/input_ime_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/input_ime/input_ime_api.h" 5 #include "chrome/browser/extensions/api/input_ime/input_ime_api.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/chromeos/profiles/profile_helper.h" 10 #include "chrome/browser/chromeos/profiles/profile_helper.h"
11 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/common/extensions/api/input_ime.h" 12 #include "chrome/common/extensions/api/input_ime.h"
13 #include "chrome/common/extensions/api/input_ime/input_components_handler.h" 13 #include "chrome/common/extensions/api/input_ime/input_components_handler.h"
14 #include "content/public/browser/notification_details.h" 14 #include "content/public/browser/notification_details.h"
15 #include "content/public/browser/notification_source.h" 15 #include "content/public/browser/notification_source.h"
16 #include "extensions/browser/event_router.h" 16 #include "extensions/browser/event_router.h"
17 #include "extensions/browser/extension_function_registry.h" 17 #include "extensions/browser/extension_function_registry.h"
18 #include "extensions/browser/extension_system.h"
19 18
20 #if defined(USE_X11) 19 #if defined(USE_X11)
21 #include "chrome/browser/chromeos/input_method/input_method_engine.h" 20 #include "chrome/browser/chromeos/input_method/input_method_engine.h"
22 #endif 21 #endif
23 22
24 namespace input_ime = extensions::api::input_ime; 23 namespace input_ime = extensions::api::input_ime;
25 namespace KeyEventHandled = extensions::api::input_ime::KeyEventHandled; 24 namespace KeyEventHandled = extensions::api::input_ime::KeyEventHandled;
26 namespace DeleteSurroundingText = 25 namespace DeleteSurroundingText =
27 extensions::api::input_ime::DeleteSurroundingText; 26 extensions::api::input_ime::DeleteSurroundingText;
28 namespace UpdateMenuItems = extensions::api::input_ime::UpdateMenuItems; 27 namespace UpdateMenuItems = extensions::api::input_ime::UpdateMenuItems;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 out->enabled = input.enabled ? *input.enabled : true; 71 out->enabled = input.enabled ? *input.enabled : true;
73 } 72 }
74 73
75 static void DispatchEventToExtension(Profile* profile, 74 static void DispatchEventToExtension(Profile* profile,
76 const std::string& extension_id, 75 const std::string& extension_id,
77 const std::string& event_name, 76 const std::string& event_name,
78 scoped_ptr<base::ListValue> args) { 77 scoped_ptr<base::ListValue> args) {
79 scoped_ptr<extensions::Event> event(new extensions::Event( 78 scoped_ptr<extensions::Event> event(new extensions::Event(
80 event_name, args.Pass())); 79 event_name, args.Pass()));
81 event->restrict_to_browser_context = profile; 80 event->restrict_to_browser_context = profile;
82 extensions::ExtensionSystem::Get(profile)->event_router()-> 81 extensions::EventRouter::Get(profile)
83 DispatchEventToExtension(extension_id, event.Pass()); 82 ->DispatchEventToExtension(extension_id, event.Pass());
84 } 83 }
85 84
86 } // namespace 85 } // namespace
87 86
88 namespace chromeos { 87 namespace chromeos {
89 class ImeObserver : public InputMethodEngineInterface::Observer { 88 class ImeObserver : public InputMethodEngineInterface::Observer {
90 public: 89 public:
91 ImeObserver(Profile* profile, const std::string& extension_id) 90 ImeObserver(Profile* profile, const std::string& extension_id)
92 : profile_(profile), extension_id_(extension_id) {} 91 : profile_(profile), extension_id_(extension_id) {}
93 92
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 scoped_ptr<base::ListValue> args(input_ime::OnReset::Create(engine_id)); 272 scoped_ptr<base::ListValue> args(input_ime::OnReset::Create(engine_id));
274 273
275 DispatchEventToExtension(profile_, 274 DispatchEventToExtension(profile_,
276 extension_id_, 275 extension_id_,
277 input_ime::OnReset::kEventName, 276 input_ime::OnReset::kEventName,
278 args.Pass()); 277 args.Pass());
279 } 278 }
280 279
281 private: 280 private:
282 bool HasKeyEventListener() const { 281 bool HasKeyEventListener() const {
283 return extensions::ExtensionSystem::Get(profile_) 282 return extensions::EventRouter::Get(profile_)
284 ->event_router()
285 ->ExtensionHasEventListener(extension_id_, 283 ->ExtensionHasEventListener(extension_id_,
286 input_ime::OnKeyEvent::kEventName); 284 input_ime::OnKeyEvent::kEventName);
287 } 285 }
288 286
289 Profile* profile_; 287 Profile* profile_;
290 std::string extension_id_; 288 std::string extension_id_;
291 289
292 DISALLOW_COPY_AND_ASSIGN(ImeObserver); 290 DISALLOW_COPY_AND_ASSIGN(ImeObserver);
293 }; 291 };
294 292
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 777
780 InputImeAPI::InputImeAPI(content::BrowserContext* context) 778 InputImeAPI::InputImeAPI(content::BrowserContext* context)
781 : profile_(Profile::FromBrowserContext(context)) { 779 : profile_(Profile::FromBrowserContext(context)) {
782 registrar_.Add(this, 780 registrar_.Add(this,
783 chrome::NOTIFICATION_EXTENSION_LOADED, 781 chrome::NOTIFICATION_EXTENSION_LOADED,
784 content::Source<Profile>(profile_)); 782 content::Source<Profile>(profile_));
785 registrar_.Add(this, 783 registrar_.Add(this,
786 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, 784 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
787 content::Source<Profile>(profile_)); 785 content::Source<Profile>(profile_));
788 786
789 EventRouter* event_router = ExtensionSystem::Get(profile_)->event_router(); 787 EventRouter* event_router = EventRouter::Get(profile_);
790 event_router->RegisterObserver(this, input_ime::OnActivate::kEventName); 788 event_router->RegisterObserver(this, input_ime::OnActivate::kEventName);
791 event_router->RegisterObserver(this, input_ime::OnFocus::kEventName); 789 event_router->RegisterObserver(this, input_ime::OnFocus::kEventName);
792 } 790 }
793 791
794 InputImeAPI::~InputImeAPI() { 792 InputImeAPI::~InputImeAPI() {
795 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); 793 EventRouter::Get(profile_)->UnregisterObserver(this);
796 } 794 }
797 795
798 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputImeAPI> > 796 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputImeAPI> >
799 g_factory = LAZY_INSTANCE_INITIALIZER; 797 g_factory = LAZY_INSTANCE_INITIALIZER;
800 798
801 // static 799 // static
802 BrowserContextKeyedAPIFactory<InputImeAPI>* InputImeAPI::GetFactoryInstance() { 800 BrowserContextKeyedAPIFactory<InputImeAPI>* InputImeAPI::GetFactoryInstance() {
803 return g_factory.Pointer(); 801 return g_factory.Pointer();
804 } 802 }
805 803
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 input_ime_event_router()->GetActiveEngine(details.extension_id); 842 input_ime_event_router()->GetActiveEngine(details.extension_id);
845 if (engine) 843 if (engine)
846 engine->NotifyImeReady(); 844 engine->NotifyImeReady();
847 } 845 }
848 846
849 InputImeEventRouter* InputImeAPI::input_ime_event_router() { 847 InputImeEventRouter* InputImeAPI::input_ime_event_router() {
850 return InputImeEventRouter::GetInstance(); 848 return InputImeEventRouter::GetInstance();
851 } 849 }
852 850
853 } // namespace extensions 851 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698