diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-23 17:42:56 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-23 17:42:56 +0000 |
commit | f1d5c3ad84c8148cf8e0e36ef9622d865b682f34 (patch) | |
tree | 673bf62a1d8368f14154c962f5327a14167af9a9 | |
parent | 72fe5d96250af420959d173f86cf5e3330a8ddfd (diff) | |
download | chromium_src-f1d5c3ad84c8148cf8e0e36ef9622d865b682f34.zip chromium_src-f1d5c3ad84c8148cf8e0e36ef9622d865b682f34.tar.gz chromium_src-f1d5c3ad84c8148cf8e0e36ef9622d865b682f34.tar.bz2 |
keyboard: Simplify initialization and use in ash_shell.
After this change, executables that want to use the keyboard need to:
* add 'keyboard' and 'keyboard_resources' as dependencies. Repacking
keyboard_resources.pak is no longer necessary.
* call keyboard::InitializeKeyboard() during startup. This installs
the necessary pak file, and sets up a WebUIControllerFactory to
make sure the keyboard gets the correct WebUIController.
* create a KeyboardControllerProxy and a KeyboardController.
BUG=none
Review URL: https://codereview.chromium.org/14241037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195835 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/ash.gyp | 2 | ||||
-rw-r--r-- | ash/shell.cc | 7 | ||||
-rw-r--r-- | ash/shell.h | 3 | ||||
-rw-r--r-- | ash/shell/content_client/shell_browser_main_parts.cc | 7 | ||||
-rw-r--r-- | ash/shell/content_client/shell_main_delegate.cc | 3 | ||||
-rw-r--r-- | ash/shell/shell_delegate_impl.cc | 27 | ||||
-rw-r--r-- | chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc | 44 | ||||
-rw-r--r-- | chrome/browser/ui/ash/ash_keyboard_controller_proxy.h | 10 | ||||
-rw-r--r-- | chrome/chrome_repack_resources.gypi | 5 | ||||
-rw-r--r-- | ui/keyboard/keyboard.cc | 80 | ||||
-rw-r--r-- | ui/keyboard/keyboard.gyp | 13 | ||||
-rw-r--r-- | ui/keyboard/keyboard.h | 20 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller_proxy.cc | 77 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller_proxy.h | 32 | ||||
-rw-r--r-- | ui/keyboard/keyboard_controller_unittest.cc | 1 |
15 files changed, 284 insertions, 47 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index b46d9da..d53debc 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -593,6 +593,7 @@ '../ui/app_list/app_list.gyp:app_list', '../ui/compositor/compositor.gyp:compositor', '../ui/compositor/compositor.gyp:compositor_test_support', + '../ui/keyboard/keyboard.gyp:keyboard', '../ui/message_center/message_center.gyp:message_center', '../ui/ui.gyp:ui', '../ui/ui.gyp:ui_resources', @@ -755,6 +756,7 @@ '../ui/aura/aura.gyp:aura', '../ui/compositor/compositor.gyp:compositor', '../ui/compositor/compositor.gyp:compositor_test_support', + '../ui/keyboard/keyboard.gyp:keyboard', '../ui/message_center/message_center.gyp:message_center', '../ui/ui.gyp:ui', '../ui/ui.gyp:ui_resources', diff --git a/ash/shell.cc b/ash/shell.cc index 04be582..b302c07 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -85,6 +85,8 @@ #include "ui/gfx/image/image_skia.h" #include "ui/gfx/screen.h" #include "ui/gfx/size.h" +#include "ui/keyboard/keyboard.h" +#include "ui/keyboard/keyboard_util.h" #include "ui/message_center/message_center.h" #include "ui/views/corewm/compound_event_filter.h" #include "ui/views/corewm/corewm_switches.h" @@ -505,6 +507,11 @@ void Shell::Init() { capture_controller_.reset(new internal::CaptureController); + // The keyboard system must be initialized before the RootWindowController is + // created. + if (keyboard::IsKeyboardEnabled()) + keyboard::InitializeKeyboard(); + internal::RootWindowController* root_window_controller = new internal::RootWindowController(root_window); root_window_controller->CreateContainers(); diff --git a/ash/shell.h b/ash/shell.h index e8089c1..892b04a 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -274,6 +274,9 @@ class ASH_EXPORT Shell internal::DisplayManager* display_manager() { return display_manager_.get(); } + views::corewm::InputMethodEventFilter* input_method_filter() { + return input_method_filter_.get(); + } views::corewm::CompoundEventFilter* env_filter() { return env_filter_.get(); } diff --git a/ash/shell/content_client/shell_browser_main_parts.cc b/ash/shell/content_client/shell_browser_main_parts.cc index 53c35b69..c24b69d 100644 --- a/ash/shell/content_client/shell_browser_main_parts.cc +++ b/ash/shell/content_client/shell_browser_main_parts.cc @@ -135,7 +135,6 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() { } void ShellBrowserMainParts::PostMainMessageLoopRun() { - browser_context_.reset(); gfx::Screen* screen = Shell::GetInstance()->GetScreen(); screen->RemoveObserver(window_watcher_.get()); @@ -149,6 +148,12 @@ void ShellBrowserMainParts::PostMainMessageLoopRun() { message_center::MessageCenter::Shutdown(); #endif aura::Env::DeleteInstance(); + + // The keyboard may have created a WebContents. The WebContents is destroyed + // with the UI, and it needs the BrowserContext to be alive during its + // destruction. So destroy all of the UI elements before destroying the + // browser context. + browser_context_.reset(); } bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { diff --git a/ash/shell/content_client/shell_main_delegate.cc b/ash/shell/content_client/shell_main_delegate.cc index c356e45..014fae1 100644 --- a/ash/shell/content_client/shell_main_delegate.cc +++ b/ash/shell/content_client/shell_main_delegate.cc @@ -6,11 +6,8 @@ #include "ash/shell/content_client/shell_content_browser_client.h" #include "base/command_line.h" -#include "base/files/file_path.h" -#include "base/path_service.h" #include "content/public/common/content_switches.h" #include "ui/base/resource/resource_bundle.h" -#include "ui/base/ui_base_paths.h" namespace ash { namespace shell { diff --git a/ash/shell/shell_delegate_impl.cc b/ash/shell/shell_delegate_impl.cc index 69dec53c..264363d 100644 --- a/ash/shell/shell_delegate_impl.cc +++ b/ash/shell/shell_delegate_impl.cc @@ -18,8 +18,33 @@ #include "ash/wm/window_util.h" #include "base/message_loop.h" #include "ui/aura/window.h" +#include "ui/keyboard/keyboard_controller_proxy.h" +#include "ui/views/corewm/input_method_event_filter.h" namespace ash { + +namespace { + +class DummyKeyboardControllerProxy : public keyboard::KeyboardControllerProxy { + public: + DummyKeyboardControllerProxy() {} + virtual ~DummyKeyboardControllerProxy() {} + + private: + // Overridden from keyboard::KeyboardControllerProxy: + virtual content::BrowserContext* GetBrowserContext() OVERRIDE { + return Shell::GetInstance()->browser_context(); + } + + virtual ui::InputMethod* GetInputMethod() OVERRIDE { + return Shell::GetInstance()->input_method_filter()->input_method(); + } + + DISALLOW_COPY_AND_ASSIGN(DummyKeyboardControllerProxy); +}; + +} // namespace + namespace shell { ShellDelegateImpl::ShellDelegateImpl() @@ -99,7 +124,7 @@ void ShellDelegateImpl::ShowKeyboardOverlay() { keyboard::KeyboardControllerProxy* ShellDelegateImpl::CreateKeyboardControllerProxy() { - return NULL; + return new DummyKeyboardControllerProxy(); } void ShellDelegateImpl::ShowTaskManager() { diff --git a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc index 1fc05d9..61935ca 100644 --- a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc +++ b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.cc @@ -23,28 +23,14 @@ AshKeyboardControllerProxy::AshKeyboardControllerProxy() {} AshKeyboardControllerProxy::~AshKeyboardControllerProxy() {} -aura::Window* AshKeyboardControllerProxy::GetKeyboardWindow() { - if (!web_contents_) { - Profile* profile = ProfileManager::GetDefaultProfile(); - - extension_function_dispatcher_.reset( - new ExtensionFunctionDispatcher(profile, this)); - - GURL keyboard_url("chrome://keyboard/"); - web_contents_.reset(content::WebContents::Create( - content::WebContents::CreateParams( - profile, - content::SiteInstance::CreateForURL(profile, keyboard_url)))); - - content::WebContentsObserver::Observe(web_contents_.get()); +void AshKeyboardControllerProxy::OnRequest( + const ExtensionHostMsg_Request_Params& params) { + extension_function_dispatcher_->Dispatch( + params, web_contents()->GetRenderViewHost()); +} - web_contents_->GetController().LoadURL( - keyboard_url, - content::Referrer(), - content::PAGE_TRANSITION_AUTO_TOPLEVEL, - std::string()); - } - return web_contents_->GetView()->GetNativeView(); +content::BrowserContext* AshKeyboardControllerProxy::GetBrowserContext() { + return ProfileManager::GetDefaultProfile(); } ui::InputMethod* AshKeyboardControllerProxy::GetInputMethod() { @@ -53,6 +39,14 @@ ui::InputMethod* AshKeyboardControllerProxy::GetInputMethod() { return root_window->GetProperty(aura::client::kRootWindowInputMethodKey); } +void AshKeyboardControllerProxy::SetupWebContents( + content::WebContents* contents) { + extension_function_dispatcher_.reset( + new ExtensionFunctionDispatcher(ProfileManager::GetDefaultProfile(), + this)); + Observe(contents); +} + extensions::WindowController* AshKeyboardControllerProxy::GetExtensionWindowController() const { // The keyboard doesn't have a window controller. @@ -61,13 +55,7 @@ extensions::WindowController* content::WebContents* AshKeyboardControllerProxy::GetAssociatedWebContents() const { - return web_contents_.get(); -} - -void AshKeyboardControllerProxy::OnRequest( - const ExtensionHostMsg_Request_Params& params) { - extension_function_dispatcher_->Dispatch( - params, web_contents_->GetRenderViewHost()); + return web_contents(); } bool AshKeyboardControllerProxy::OnMessageReceived( diff --git a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h index 473b4bb..a0a1e5c 100644 --- a/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h +++ b/chrome/browser/ui/ash/ash_keyboard_controller_proxy.h @@ -33,23 +33,23 @@ class AshKeyboardControllerProxy AshKeyboardControllerProxy(); virtual ~AshKeyboardControllerProxy(); + private: + void OnRequest(const ExtensionHostMsg_Request_Params& params); + // keyboard::KeyboardControllerProxy overrides - virtual aura::Window* GetKeyboardWindow() OVERRIDE; + virtual content::BrowserContext* GetBrowserContext() OVERRIDE; virtual ui::InputMethod* GetInputMethod() OVERRIDE; + virtual void SetupWebContents(content::WebContents* contents) OVERRIDE; // ExtensionFunctionDispatcher::Delegate overrides virtual extensions::WindowController* GetExtensionWindowController() const OVERRIDE; virtual content::WebContents* GetAssociatedWebContents() const OVERRIDE; - private: - void OnRequest(const ExtensionHostMsg_Request_Params& params); - // content::WebContentsObserver overrides virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_; - scoped_ptr<content::WebContents> web_contents_; DISALLOW_COPY_AND_ASSIGN(AshKeyboardControllerProxy); }; diff --git a/chrome/chrome_repack_resources.gypi b/chrome/chrome_repack_resources.gypi index b045f70..35d91dc 100644 --- a/chrome/chrome_repack_resources.gypi +++ b/chrome/chrome_repack_resources.gypi @@ -27,11 +27,6 @@ '<(grit_out_dir)/devtools_discovery_page_resources.pak', ], }], - ['use_aura==1', { - 'pak_inputs': [ - '<(SHARED_INTERMEDIATE_DIR)/ui/keyboard/keyboard_resources.pak', - ], - }], ], }, 'inputs': [ diff --git a/ui/keyboard/keyboard.cc b/ui/keyboard/keyboard.cc new file mode 100644 index 0000000..d41f897 --- /dev/null +++ b/ui/keyboard/keyboard.cc @@ -0,0 +1,80 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/keyboard/keyboard.h" + +#include "base/files/file_path.h" +#include "base/memory/singleton.h" +#include "base/path_service.h" +#include "content/public/browser/browser_context.h" +#include "content/public/browser/web_ui_controller_factory.h" +#include "googleurl/src/gurl.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/keyboard/keyboard_constants.h" +#include "ui/keyboard/keyboard_ui_controller.h" + +namespace { + +using content::BrowserContext; +using content::WebUI; +using content::WebUIController; + +class KeyboardWebUIControllerFactory : public content::WebUIControllerFactory { + public: + // |WebUIControllerFactory| implementation: + virtual content::WebUI::TypeID GetWebUIType( + content::BrowserContext* browser_context, + const GURL& url) const OVERRIDE { + if (url == GURL(keyboard::kKeyboardWebUIURL)) + return const_cast<KeyboardWebUIControllerFactory*>(this); + + return WebUI::kNoWebUI; + } + virtual bool UseWebUIForURL(content::BrowserContext* browser_context, + const GURL& url) const OVERRIDE { + return GetWebUIType(browser_context, url) != WebUI::kNoWebUI; + } + virtual bool UseWebUIBindingsForURL(content::BrowserContext* browser_context, + const GURL& url) const OVERRIDE { + return UseWebUIForURL(browser_context, url); + } + virtual content::WebUIController* CreateWebUIControllerForURL( + content::WebUI* web_ui, + const GURL& url) const OVERRIDE { + if (url == GURL(keyboard::kKeyboardWebUIURL)) + return new keyboard::KeyboardUIController(web_ui); + return NULL; + } + + static KeyboardWebUIControllerFactory* GetInstance() { + return Singleton<KeyboardWebUIControllerFactory>::get(); + } + + protected: + KeyboardWebUIControllerFactory() {} + virtual ~KeyboardWebUIControllerFactory() {} + + private: + friend struct DefaultSingletonTraits<KeyboardWebUIControllerFactory>; + + DISALLOW_COPY_AND_ASSIGN(KeyboardWebUIControllerFactory); +}; + +} // namespace + +namespace keyboard { + +void InitializeKeyboard() { + base::FilePath pak_dir; + PathService::Get(base::DIR_MODULE, &pak_dir); + base::FilePath pak_file = pak_dir.Append( + FILE_PATH_LITERAL("keyboard_resources.pak")); + ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( + pak_file, ui::SCALE_FACTOR_100P); + + content::WebUIControllerFactory::RegisterFactory( + KeyboardWebUIControllerFactory::GetInstance()); +} + +} // namespace keyboard diff --git a/ui/keyboard/keyboard.gyp b/ui/keyboard/keyboard.gyp index 8d37845..749f9dd 100644 --- a/ui/keyboard/keyboard.gyp +++ b/ui/keyboard/keyboard.gyp @@ -23,12 +23,22 @@ }, ], 'includes': [ '../../build/grit_target.gypi' ], + 'copies': [ + { + 'destination': '<(PRODUCT_DIR)', + 'files': [ + '<(SHARED_INTERMEDIATE_DIR)/ui/keyboard/keyboard_resources.pak', + ], + }, + ], }, { 'target_name': 'keyboard', 'type': '<(component)', 'dependencies': [ '../../base/base.gyp:base', + '../../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', + '../../build/temp_gyp/googleurl.gyp:googleurl', '../../content/content.gyp:content_browser', '../../skia/skia.gyp:skia', '../aura/aura.gyp:aura', @@ -40,10 +50,13 @@ 'KEYBOARD_IMPLEMENTATION', ], 'sources': [ + 'keyboard.cc', + 'keyboard.h', 'keyboard_constants.cc', 'keyboard_constants.h', 'keyboard_controller.cc', 'keyboard_controller.h', + 'keyboard_controller_proxy.cc', 'keyboard_controller_proxy.h', 'keyboard_export.h', 'keyboard_switches.cc', diff --git a/ui/keyboard/keyboard.h b/ui/keyboard/keyboard.h new file mode 100644 index 0000000..83826d1 --- /dev/null +++ b/ui/keyboard/keyboard.h @@ -0,0 +1,20 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_KEYBOARD_KEYBOARD_H_ +#define UI_KEYBOARD_KEYBOARD_H_ + +#include "ui/keyboard/keyboard_export.h" + +namespace keyboard { + +// Initializes the keyboard module. This includes adding the necessary pak files +// for loading resources used in for the virtual keyboard, and registers +// a WebUIControllerFactory for creating a WebUIController necessary for the +// virtual keyboard. +KEYBOARD_EXPORT void InitializeKeyboard(); + +} // namespace keyboard + +#endif // UI_KEYBOARD_KEYBOARD_H_ diff --git a/ui/keyboard/keyboard_controller_proxy.cc b/ui/keyboard/keyboard_controller_proxy.cc new file mode 100644 index 0000000..be49005 --- /dev/null +++ b/ui/keyboard/keyboard_controller_proxy.cc @@ -0,0 +1,77 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/keyboard/keyboard_controller_proxy.h" + +#include "content/public/browser/site_instance.h" +#include "content/public/browser/web_contents.h" +#include "content/public/browser/web_contents_delegate.h" +#include "content/public/browser/web_contents_observer.h" +#include "content/public/browser/web_contents_view.h" +#include "ui/keyboard/keyboard_constants.h" + +namespace { + +// The WebContentsDelegate for the keyboard. +// The delegate deletes itself when the keyboard is destroyed. +class KeyboardContentsDelegate : public content::WebContentsDelegate, + public content::WebContentsObserver { + public: + KeyboardContentsDelegate() {} + virtual ~KeyboardContentsDelegate() {} + + private: + // Overridden from content::WebContentsDelegate: + virtual content::WebContents* OpenURLFromTab( + content::WebContents* source, + const content::OpenURLParams& params) OVERRIDE { + source->GetController().LoadURL( + params.url, params.referrer, params.transition, params.extra_headers); + Observe(source); + return source; + } + + // Overridden from content::WebContentsObserver: + virtual void WebContentsDestroyed(content::WebContents* contents) OVERRIDE { + delete this; + } + + DISALLOW_COPY_AND_ASSIGN(KeyboardContentsDelegate); +}; + +} // namespace + +namespace keyboard { + +KeyboardControllerProxy::KeyboardControllerProxy() { +} + +KeyboardControllerProxy::~KeyboardControllerProxy() { +} + +aura::Window* KeyboardControllerProxy::GetKeyboardWindow() { + if (!keyboard_contents_) { + content::BrowserContext* context = GetBrowserContext(); + GURL url(kKeyboardWebUIURL); + keyboard_contents_.reset(content::WebContents::Create( + content::WebContents::CreateParams(context, + content::SiteInstance::CreateForURL(context, url)))); + keyboard_contents_->SetDelegate(new KeyboardContentsDelegate); + SetupWebContents(keyboard_contents_.get()); + + content::OpenURLParams params(url, + content::Referrer(), + SINGLETON_TAB, + content::PAGE_TRANSITION_AUTO_TOPLEVEL, + false); + keyboard_contents_->OpenURL(params); + } + + return keyboard_contents_->GetView()->GetNativeView(); +} + +void KeyboardControllerProxy::SetupWebContents(content::WebContents* contents) { +} + +} // namespace keyboard diff --git a/ui/keyboard/keyboard_controller_proxy.h b/ui/keyboard/keyboard_controller_proxy.h index a656e06..985f573 100644 --- a/ui/keyboard/keyboard_controller_proxy.h +++ b/ui/keyboard/keyboard_controller_proxy.h @@ -5,12 +5,19 @@ #ifndef UI_KEYBOARD_KEYBOARD_CONTROLLER_PROXY_H_ #define UI_KEYBOARD_KEYBOARD_CONTROLLER_PROXY_H_ +#include "base/memory/scoped_ptr.h" #include "ui/keyboard/keyboard_export.h" namespace aura { class Window; } +namespace content { +class BrowserContext; +class SiteInstance; +class WebContents; +} + namespace ui { class InputMethod; } @@ -21,15 +28,32 @@ namespace keyboard { // keyboard window. class KEYBOARD_EXPORT KeyboardControllerProxy { public: - virtual ~KeyboardControllerProxy() {} + KeyboardControllerProxy(); + virtual ~KeyboardControllerProxy(); - // Get the virtual keyboard window. Ownership of the returned Window remains + // Gets the virtual keyboard window. Ownership of the returned Window remains // with the proxy. - virtual aura::Window* GetKeyboardWindow() = 0; + virtual aura::Window* GetKeyboardWindow(); - // Get the InputMethod that will provide notifications about changes in the + // Gets the InputMethod that will provide notifications about changes in the // text input context. virtual ui::InputMethod* GetInputMethod() = 0; + + protected: + // Gets the BrowserContext to use for creating the WebContents hosting the + // keyboard. + virtual content::BrowserContext* GetBrowserContext() = 0; + + // The implementation can choose to setup the WebContents before the virtual + // keyboard page is loaded (e.g. install a WebContentsObserver). + // SetupWebContents() is called right after creating the WebContents, before + // loading the keyboard page. + virtual void SetupWebContents(content::WebContents* contents); + + private: + scoped_ptr<content::WebContents> keyboard_contents_; + + DISALLOW_COPY_AND_ASSIGN(KeyboardControllerProxy); }; } // namespace keyboard diff --git a/ui/keyboard/keyboard_controller_unittest.cc b/ui/keyboard/keyboard_controller_unittest.cc index dd9eb60..6d39f62 100644 --- a/ui/keyboard/keyboard_controller_unittest.cc +++ b/ui/keyboard/keyboard_controller_unittest.cc @@ -66,6 +66,7 @@ class TestKeyboardControllerProxy : public KeyboardControllerProxy { // Overridden from KeyboardControllerProxy: virtual aura::Window* GetKeyboardWindow() OVERRIDE { return window_.get(); } + virtual content::BrowserContext* GetBrowserContext() OVERRIDE { return NULL; } virtual ui::InputMethod* GetInputMethod() OVERRIDE { return input_method_.get(); } |