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/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" | |
10 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
12 #include "chrome/common/extensions/api/input_ime.h" | 11 #include "chrome/common/extensions/api/input_ime.h" |
13 #include "chrome/common/extensions/api/input_ime/input_components_handler.h" | 12 #include "chrome/common/extensions/api/input_ime/input_components_handler.h" |
14 #include "content/public/browser/notification_details.h" | |
15 #include "content/public/browser/notification_source.h" | |
16 #include "extensions/browser/event_router.h" | 13 #include "extensions/browser/event_router.h" |
17 #include "extensions/browser/extension_function_registry.h" | 14 #include "extensions/browser/extension_function_registry.h" |
| 15 #include "extensions/browser/extension_registry.h" |
18 | 16 |
19 #if defined(USE_X11) | 17 #if defined(USE_X11) |
20 #include "chrome/browser/chromeos/input_method/input_method_engine.h" | 18 #include "chrome/browser/chromeos/input_method/input_method_engine.h" |
21 #endif | 19 #endif |
22 | 20 |
23 namespace input_ime = extensions::api::input_ime; | 21 namespace input_ime = extensions::api::input_ime; |
24 namespace KeyEventHandled = extensions::api::input_ime::KeyEventHandled; | 22 namespace KeyEventHandled = extensions::api::input_ime::KeyEventHandled; |
25 namespace DeleteSurroundingText = | 23 namespace DeleteSurroundingText = |
26 extensions::api::input_ime::DeleteSurroundingText; | 24 extensions::api::input_ime::DeleteSurroundingText; |
27 namespace UpdateMenuItems = extensions::api::input_ime::UpdateMenuItems; | 25 namespace UpdateMenuItems = extensions::api::input_ime::UpdateMenuItems; |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 | 767 |
770 bool InputImeKeyEventHandledFunction::RunImpl() { | 768 bool InputImeKeyEventHandledFunction::RunImpl() { |
771 scoped_ptr<KeyEventHandled::Params> params( | 769 scoped_ptr<KeyEventHandled::Params> params( |
772 KeyEventHandled::Params::Create(*args_)); | 770 KeyEventHandled::Params::Create(*args_)); |
773 InputImeEventRouter::GetInstance()->OnKeyEventHandled( | 771 InputImeEventRouter::GetInstance()->OnKeyEventHandled( |
774 extension_id(), params->request_id, params->response); | 772 extension_id(), params->request_id, params->response); |
775 return true; | 773 return true; |
776 } | 774 } |
777 | 775 |
778 InputImeAPI::InputImeAPI(content::BrowserContext* context) | 776 InputImeAPI::InputImeAPI(content::BrowserContext* context) |
779 : profile_(Profile::FromBrowserContext(context)) { | 777 : browser_context_(context), extension_registry_observer_(this) { |
780 registrar_.Add(this, | 778 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); |
781 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | |
782 content::Source<Profile>(profile_)); | |
783 registrar_.Add(this, | |
784 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | |
785 content::Source<Profile>(profile_)); | |
786 | 779 |
787 EventRouter* event_router = EventRouter::Get(profile_); | 780 EventRouter* event_router = EventRouter::Get(browser_context_); |
788 event_router->RegisterObserver(this, input_ime::OnActivate::kEventName); | 781 event_router->RegisterObserver(this, input_ime::OnActivate::kEventName); |
789 event_router->RegisterObserver(this, input_ime::OnFocus::kEventName); | 782 event_router->RegisterObserver(this, input_ime::OnFocus::kEventName); |
790 } | 783 } |
791 | 784 |
792 InputImeAPI::~InputImeAPI() { | 785 InputImeAPI::~InputImeAPI() { |
793 EventRouter::Get(profile_)->UnregisterObserver(this); | 786 EventRouter::Get(browser_context_)->UnregisterObserver(this); |
794 } | 787 } |
795 | 788 |
796 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputImeAPI> > | 789 static base::LazyInstance<BrowserContextKeyedAPIFactory<InputImeAPI> > |
797 g_factory = LAZY_INSTANCE_INITIALIZER; | 790 g_factory = LAZY_INSTANCE_INITIALIZER; |
798 | 791 |
799 // static | 792 // static |
800 BrowserContextKeyedAPIFactory<InputImeAPI>* InputImeAPI::GetFactoryInstance() { | 793 BrowserContextKeyedAPIFactory<InputImeAPI>* InputImeAPI::GetFactoryInstance() { |
801 return g_factory.Pointer(); | 794 return g_factory.Pointer(); |
802 } | 795 } |
803 | 796 |
804 void InputImeAPI::Observe(int type, | 797 void InputImeAPI::OnExtensionLoaded(content::BrowserContext* browser_context, |
805 const content::NotificationSource& source, | 798 const Extension* extension) { |
806 const content::NotificationDetails& details) { | 799 const std::vector<InputComponentInfo>* input_components = |
807 if (type == chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED) { | 800 extensions::InputComponents::GetInputComponents(extension); |
808 const Extension* extension = | 801 if (!input_components) |
809 content::Details<const Extension>(details).ptr(); | 802 return; |
810 const std::vector<InputComponentInfo>* input_components = | 803 for (std::vector<extensions::InputComponentInfo>::const_iterator component = |
811 extensions::InputComponents::GetInputComponents(extension); | 804 input_components->begin(); |
812 if (!input_components) | 805 component != input_components->end(); |
813 return; | 806 ++component) { |
814 for (std::vector<extensions::InputComponentInfo>::const_iterator component = | 807 if (component->type == extensions::INPUT_COMPONENT_TYPE_IME) { |
815 input_components->begin(); component != input_components->end(); | 808 // Don't pass profile_ to register ime, instead always use |
816 ++component) { | 809 // GetActiveUserProfile. It is because: |
817 if (component->type == extensions::INPUT_COMPONENT_TYPE_IME) { | 810 // The original profile for login screen is called signin profile. |
818 // Don't pass profile_ to register ime, instead always use | 811 // And the active profile is the incognito profile based on signin |
819 // GetActiveUserProfile. It is because: | 812 // profile. So if |profile_| is signin profile, we need to make sure |
820 // The original profile for login screen is called signin profile. | 813 // the router/observer runs under its incognito profile, because the |
821 // And the active profile is the incognito profile based on signin | 814 // component extensions were installed under its incognito profile. |
822 // profile. So if |profile_| is signin profile, we need to make sure | 815 input_ime_event_router()->RegisterIme(extension->id(), *component); |
823 // the router/observer runs under its incognito profile, because the | |
824 // component extensions were installed under its incognito profile. | |
825 input_ime_event_router()->RegisterIme(extension->id(), *component); | |
826 } | |
827 } | 816 } |
828 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { | |
829 const Extension* extension = | |
830 content::Details<const UnloadedExtensionInfo>(details)->extension; | |
831 const std::vector<InputComponentInfo>* input_components = | |
832 extensions::InputComponents::GetInputComponents(extension); | |
833 if (!input_components) | |
834 return; | |
835 if (input_components->size() > 0) | |
836 input_ime_event_router()->UnregisterAllImes(extension->id()); | |
837 } | 817 } |
838 } | 818 } |
839 | 819 |
| 820 void InputImeAPI::OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 821 const Extension* extension, |
| 822 UnloadedExtensionInfo::Reason reason) { |
| 823 const std::vector<InputComponentInfo>* input_components = |
| 824 extensions::InputComponents::GetInputComponents(extension); |
| 825 if (!input_components) |
| 826 return; |
| 827 if (input_components->size() > 0) |
| 828 input_ime_event_router()->UnregisterAllImes(extension->id()); |
| 829 } |
| 830 |
840 void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) { | 831 void InputImeAPI::OnListenerAdded(const EventListenerInfo& details) { |
841 InputMethodEngineInterface* engine = | 832 InputMethodEngineInterface* engine = |
842 input_ime_event_router()->GetActiveEngine(details.extension_id); | 833 input_ime_event_router()->GetActiveEngine(details.extension_id); |
843 if (engine) | 834 if (engine) |
844 engine->NotifyImeReady(); | 835 engine->NotifyImeReady(); |
845 } | 836 } |
846 | 837 |
847 InputImeEventRouter* InputImeAPI::input_ime_event_router() { | 838 InputImeEventRouter* InputImeAPI::input_ime_event_router() { |
848 return InputImeEventRouter::GetInstance(); | 839 return InputImeEventRouter::GetInstance(); |
849 } | 840 } |
850 | 841 |
851 } // namespace extensions | 842 } // namespace extensions |
OLD | NEW |