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 /ui/keyboard/keyboard.cc | |
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
Diffstat (limited to 'ui/keyboard/keyboard.cc')
-rw-r--r-- | ui/keyboard/keyboard.cc | 80 |
1 files changed, 80 insertions, 0 deletions
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 |