diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-06 10:55:11 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-06 10:55:11 +0000 |
commit | eae6aa4eb65e2d844164a7919d7a39255a2abee1 (patch) | |
tree | 52fe6ebae0f33907ee23f5c5c0901e8272293791 | |
parent | 82dcd1c4bf0d0d857d303ee86638738ee0bea42a (diff) | |
download | chromium_src-eae6aa4eb65e2d844164a7919d7a39255a2abee1.zip chromium_src-eae6aa4eb65e2d844164a7919d7a39255a2abee1.tar.gz chromium_src-eae6aa4eb65e2d844164a7919d7a39255a2abee1.tar.bz2 |
athena: Use mojo to provide the bindings for the virtual keyboard.
Remove the gin/v8 based bindings, in favour of bindings provided by mojo. Use
the same mechanism as chrome://omnibox to provide the bindings for the virtual
keyboard when the VK extension API is not available.
BUG=380215, 387276
R=sky@chromium.org
Review URL: https://codereview.chromium.org/328303008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287755 0039d316-1c4b-4281-b951-d872f2087c98
23 files changed, 436 insertions, 400 deletions
diff --git a/athena/athena.gyp b/athena/athena.gyp index 4f78923..1cbeaad 100644 --- a/athena/athena.gyp +++ b/athena/athena.gyp @@ -103,14 +103,8 @@ 'content/app_activity.cc', 'content/web_activity.h', 'content/web_activity.cc', - 'virtual_keyboard/public/virtual_keyboard_bindings.h', 'virtual_keyboard/public/virtual_keyboard_manager.h', - 'virtual_keyboard/virtual_keyboard_bindings_impl.cc', 'virtual_keyboard/virtual_keyboard_manager_impl.cc', - 'virtual_keyboard/vk_message_handler.cc', - 'virtual_keyboard/vk_message_handler.h', - 'virtual_keyboard/vk_webui_controller.cc', - 'virtual_keyboard/vk_webui_controller.h', ], }, { diff --git a/athena/main/athena_main.cc b/athena/main/athena_main.cc index 321b647..911776a 100644 --- a/athena/main/athena_main.cc +++ b/athena/main/athena_main.cc @@ -11,7 +11,6 @@ #include "athena/main/placeholder.h" #include "athena/main/url_search_provider.h" #include "athena/screen/public/screen_manager.h" -#include "athena/virtual_keyboard/public/virtual_keyboard_bindings.h" #include "athena/virtual_keyboard/public/virtual_keyboard_manager.h" #include "base/command_line.h" #include "base/file_util.h" @@ -165,7 +164,6 @@ class AthenaRendererMainDelegate virtual void OnThreadStarted(content::RenderThread* thread) OVERRIDE {} virtual void OnViewCreated(content::RenderView* render_view) OVERRIDE { - athena::VirtualKeyboardBindings::Create(render_view); } DISALLOW_COPY_AND_ASSIGN(AthenaRendererMainDelegate); diff --git a/athena/virtual_keyboard/DEPS b/athena/virtual_keyboard/DEPS index 371e353..da0e14d 100644 --- a/athena/virtual_keyboard/DEPS +++ b/athena/virtual_keyboard/DEPS @@ -1,9 +1,6 @@ include_rules = [ "+athena/screen", "+content/public", - "+gin", - "+grit", "+ui/aura", "+ui/keyboard", - "+third_party/WebKit", ] diff --git a/athena/virtual_keyboard/public/virtual_keyboard_bindings.h b/athena/virtual_keyboard/public/virtual_keyboard_bindings.h deleted file mode 100644 index 921699f..0000000 --- a/athena/virtual_keyboard/public/virtual_keyboard_bindings.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2014 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 ATHENA_VIRTUAL_KEYBOARD_PUBLIC_VIRTUAL_KEYBOARD_BINDINGS_H_ -#define ATHENA_VIRTUAL_KEYBOARD_PUBLIC_VIRTUAL_KEYBOARD_BINDINGS_H_ - -#include "athena/athena_export.h" - -namespace content { -class RenderView; -} - -namespace athena { - -// This provides the necessary bindings for the virtualKeyboardPrivate API. -class ATHENA_EXPORT VirtualKeyboardBindings { - public: - // Creates the bindings for |render_view|. - static VirtualKeyboardBindings* Create(content::RenderView* render_view); -}; - -} // namespace athena - -#endif // ATHENA_VIRTUAL_KEYBOARD_PUBLIC_VIRTUAL_KEYBOARD_BINDINGS_H_ diff --git a/athena/virtual_keyboard/virtual_keyboard_bindings_impl.cc b/athena/virtual_keyboard/virtual_keyboard_bindings_impl.cc deleted file mode 100644 index 85fe5f5..0000000 --- a/athena/virtual_keyboard/virtual_keyboard_bindings_impl.cc +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright 2014 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 "athena/virtual_keyboard/public/virtual_keyboard_bindings.h" - -#include "base/json/json_string_value_serializer.h" -#include "base/logging.h" -#include "base/macros.h" -#include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" -#include "base/values.h" -#include "content/public/common/bindings_policy.h" -#include "content/public/renderer/render_frame.h" -#include "content/public/renderer/render_view.h" -#include "content/public/renderer/render_view_observer.h" -#include "gin/handle.h" -#include "gin/object_template_builder.h" -#include "gin/wrappable.h" -#include "third_party/WebKit/public/web/WebKit.h" -#include "third_party/WebKit/public/web/WebLocalFrame.h" -#include "ui/keyboard/keyboard_constants.h" - -namespace { - -struct VKEvent { - std::string event_type; - int char_value; - int key_code; - std::string key_name; - int modifiers; -}; - -} // namespace - -namespace gin { - -template <> -struct Converter<VKEvent> { - static bool FromV8(v8::Isolate* isolate, - v8::Handle<v8::Value> val, - VKEvent* event) { - if (!val->IsObject()) - return false; - v8::Handle<v8::Object> dict(v8::Handle<v8::Object>::Cast(val)); - - if (!Converter<std::string>::FromV8( - isolate, - dict->Get(v8::String::NewFromUtf8(isolate, "type")), - &event->event_type)) - return false; - if (!Converter<int32_t>::FromV8( - isolate, - dict->Get(v8::String::NewFromUtf8(isolate, "charValue")), - &event->char_value)) - return false; - if (!Converter<int32_t>::FromV8( - isolate, - dict->Get(v8::String::NewFromUtf8(isolate, "keyCode")), - &event->key_code)) - return false; - if (!Converter<std::string>::FromV8( - isolate, - dict->Get(v8::String::NewFromUtf8(isolate, "keyName")), - &event->key_name)) - return false; - if (!Converter<int32_t>::FromV8( - isolate, - dict->Get(v8::String::NewFromUtf8(isolate, "modifiers")), - &event->modifiers)) - return false; - - return true; - } -}; - -} // namespace gin - -namespace athena { - -namespace { - -class VKBindings : public gin::Wrappable<VKBindings> { - public: - static gin::WrapperInfo kWrapperInfo; - - static void Install(content::RenderView* render_view) { - blink::WebFrame* web_frame = - render_view->GetMainRenderFrame()->GetWebFrame(); - v8::Isolate* isolate = blink::mainThreadIsolate(); - v8::HandleScope handle_scope(isolate); - v8::Handle<v8::Context> context = web_frame->mainWorldScriptContext(); - if (context.IsEmpty()) - return; - - v8::Context::Scope context_scope(context); - - v8::Handle<v8::Object> global = context->Global(); - v8::Handle<v8::Object> chrome = - global->Get(gin::StringToV8(isolate, "chrome"))->ToObject(); - CHECK(!chrome.IsEmpty()); - - gin::Handle<VKBindings> controller = - gin::CreateHandle(isolate, new VKBindings(render_view)); - if (controller.IsEmpty()) - return; - chrome->Set(gin::StringToSymbol(isolate, "virtualKeyboardPrivate"), - controller.ToV8()); - - const std::string kInputBoxFocusedEvent = - "chrome.virtualKeyboardPrivate.onTextInputBoxFocused = {};" - "chrome.virtualKeyboardPrivate.onTextInputBoxFocused.addListener = " - " function(callback) { " - " window.setTimeout(function() {" - " callback({type: 'text'});" - " }, 100);" - " };"; - render_view->GetMainRenderFrame()->ExecuteJavaScript( - base::UTF8ToUTF16(kInputBoxFocusedEvent)); - } - - private: - explicit VKBindings(content::RenderView* render_view) - : render_view_(render_view) {} - virtual ~VKBindings() {} - - // gin::WrappableBase - virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( - v8::Isolate* isolate) OVERRIDE { - return gin::Wrappable<VKBindings>::GetObjectTemplateBuilder(isolate) - .SetMethod("moveCursor", &VKBindings::NotImplemented) - .SetMethod("sendKeyEvent", &VKBindings::SendKeyEvent) - .SetMethod("hideKeyboard", &VKBindings::HideKeyboard) - .SetMethod("lockKeyboard", &VKBindings::NotImplemented) - .SetMethod("keyboardLoaded", &VKBindings::NotImplemented) - .SetMethod("getKeyboardConfig", &VKBindings::NotImplemented); - } - - void SendKeyEvent(gin::Arguments* args) { - VKEvent event; - if (!args->GetNext(&event)) { - LOG(ERROR) << "Failed to get the type"; - return; - } - base::ListValue params; - params.Set(0, new base::StringValue(event.event_type)); - params.Set(1, new base::FundamentalValue(event.char_value)); - params.Set(2, new base::FundamentalValue(event.key_code)); - params.Set(3, new base::StringValue(event.key_name)); - params.Set(4, new base::FundamentalValue(event.modifiers)); - - std::string params_json; - JSONStringValueSerializer serializer(¶ms_json); - if (!serializer.Serialize(params)) - return; - - render_view_->GetMainRenderFrame()->ExecuteJavaScript( - base::UTF8ToUTF16("chrome.send('sendKeyEvent', " + params_json + ")")); - } - - void HideKeyboard() { - render_view_->GetMainRenderFrame()->ExecuteJavaScript( - base::UTF8ToUTF16("chrome.send('hideKeyboard', [])")); - } - - void NotImplemented(gin::Arguments* args) { NOTIMPLEMENTED(); } - - content::RenderView* render_view_; - - DISALLOW_COPY_AND_ASSIGN(VKBindings); -}; - -gin::WrapperInfo VKBindings::kWrapperInfo = {gin::kEmbedderNativeGin}; - -class VirtualKeyboardBindingsImpl : public VirtualKeyboardBindings, - public content::RenderViewObserver { - public: - explicit VirtualKeyboardBindingsImpl(content::RenderView* render_view) - : content::RenderViewObserver(render_view) {} - - virtual ~VirtualKeyboardBindingsImpl() {} - - private: - // content::RenderViewObserver: - virtual void Navigate(const GURL& url) OVERRIDE { - bool enabled_bindings = render_view()->GetEnabledBindings(); - if (!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI)) - return; - if (url.GetOrigin() == GURL(keyboard::kKeyboardURL)) - VKBindings::Install(render_view()); - } - DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardBindingsImpl); -}; - -} // namespace - -VirtualKeyboardBindings* VirtualKeyboardBindings::Create( - content::RenderView* render_view) { - return new VirtualKeyboardBindingsImpl(render_view); -} - -} // namespace athena diff --git a/athena/virtual_keyboard/virtual_keyboard_manager_impl.cc b/athena/virtual_keyboard/virtual_keyboard_manager_impl.cc index 69d9187..1de68ee 100644 --- a/athena/virtual_keyboard/virtual_keyboard_manager_impl.cc +++ b/athena/virtual_keyboard/virtual_keyboard_manager_impl.cc @@ -7,7 +7,6 @@ #include "athena/common/container_priorities.h" #include "athena/common/fill_layout_manager.h" #include "athena/screen/public/screen_manager.h" -#include "athena/virtual_keyboard/vk_webui_controller.h" #include "base/bind.h" #include "base/memory/singleton.h" #include "base/values.h" @@ -51,6 +50,8 @@ class BasicKeyboardControllerProxy : public keyboard::KeyboardControllerProxy { return browser_context_; } + virtual void SetUpdateInputType(ui::TextInputType type) OVERRIDE {} + private: content::BrowserContext* browser_context_; aura::Window* root_window_; @@ -81,7 +82,6 @@ class VirtualKeyboardManagerImpl : public VirtualKeyboardManager { CP_VIRTUAL_KEYBOARD); container_ = athena::ScreenManager::Get()->CreateContainer(params); container_->SetLayoutManager(new FillLayoutManager(container_)); - keyboard::SetOverrideContentUrl(GURL(keyboard::kKeyboardURL)); keyboard_controller_.reset(new keyboard::KeyboardController( new BasicKeyboardControllerProxy(browser_context_, @@ -90,9 +90,6 @@ class VirtualKeyboardManagerImpl : public VirtualKeyboardManager { aura::Window* kb_container = keyboard_controller_->GetContainerWindow(); container_->AddChild(kb_container); kb_container->Show(); - - content::WebUIControllerFactory::RegisterFactory( - VKWebUIControllerFactory::GetInstance()); } content::BrowserContext* browser_context_; @@ -110,6 +107,8 @@ VirtualKeyboardManager* VirtualKeyboardManager::Create( CHECK(!instance); keyboard::InitializeKeyboard(); keyboard::SetTouchKeyboardEnabled(true); + keyboard::InitializeWebUIBindings(); + new VirtualKeyboardManagerImpl(browser_context); CHECK(instance); return instance; diff --git a/athena/virtual_keyboard/vk_message_handler.cc b/athena/virtual_keyboard/vk_message_handler.cc deleted file mode 100644 index fbd1e79..0000000 --- a/athena/virtual_keyboard/vk_message_handler.cc +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2014 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 "athena/virtual_keyboard/vk_message_handler.h" - -#include "athena/screen/public/screen_manager.h" -#include "base/bind.h" -#include "base/values.h" -#include "content/public/browser/web_ui.h" -#include "ui/keyboard/keyboard_controller.h" -#include "ui/keyboard/keyboard_util.h" - -namespace athena { - -VKMessageHandler::VKMessageHandler() { -} -VKMessageHandler::~VKMessageHandler() { -} - -void VKMessageHandler::RegisterMessages() { - web_ui()->RegisterMessageCallback( - "sendKeyEvent", - base::Bind(&VKMessageHandler::SendKeyEvent, base::Unretained(this))); - web_ui()->RegisterMessageCallback( - "hideKeyboard", - base::Bind(&VKMessageHandler::HideKeyboard, base::Unretained(this))); -} - -void VKMessageHandler::SendKeyEvent(const base::ListValue* params) { - std::string type; - int char_value; - int key_code; - std::string key_name; - int modifiers; - if (!params->GetString(0, &type)) - return; - if (!params->GetInteger(1, &char_value)) - return; - if (!params->GetInteger(2, &key_code)) - return; - if (!params->GetString(3, &key_name)) - return; - if (!params->GetInteger(4, &modifiers)) - return; - - aura::Window* window = ScreenManager::Get()->GetContext(); - keyboard::SendKeyEvent( - type, char_value, key_code, key_name, modifiers, window->GetHost()); -} - -void VKMessageHandler::HideKeyboard(const base::ListValue* params) { - keyboard::KeyboardController::GetInstance()->HideKeyboard( - keyboard::KeyboardController::HIDE_REASON_MANUAL); -} - -} // namespace athena diff --git a/athena/virtual_keyboard/vk_message_handler.h b/athena/virtual_keyboard/vk_message_handler.h deleted file mode 100644 index 1fc6c7f3..0000000 --- a/athena/virtual_keyboard/vk_message_handler.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2014 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 ATHENA_VIRTUAL_KEYBOARD_VK_MESSAGE_HANDLER_H_ -#define ATHENA_VIRTUAL_KEYBOARD_VK_MESSAGE_HANDLER_H_ - -#include "base/macros.h" -#include "content/public/browser/web_ui_message_handler.h" - -namespace base { -class ListValue; -} - -namespace athena { - -// Processes WebUI messages for chrome://keyboard. -class VKMessageHandler : public content::WebUIMessageHandler { - public: - VKMessageHandler(); - virtual ~VKMessageHandler(); - - private: - // WebUI message callbacks. - void SendKeyEvent(const base::ListValue* params); - void HideKeyboard(const base::ListValue* params); - - // content::WebUIMessageHandler: - virtual void RegisterMessages() OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(VKMessageHandler); -}; - -} // namespace athena - -#endif // ATHENA_VIRTUAL_KEYBOARD_VK_MESSAGE_HANDLER_H_ diff --git a/ui/keyboard/BUILD.gn b/ui/keyboard/BUILD.gn index 8c1c2a2..8321077 100644 --- a/ui/keyboard/BUILD.gn +++ b/ui/keyboard/BUILD.gn @@ -52,6 +52,16 @@ grit("resources_grit") { "keyboard_resources.pak", "keyboard_resources.rc", ] + + keyboard_mojom_gen_js = "$root_gen_dir/ui/keyboard/webui/keyboard.mojom.js" + grit_flags = [ + "-E", "keyboard_mojom_gen_js=" + + rebase_path(keyboard_mojom_gen_js, root_build_dir), + ] + + deps = [ + "webui:mojo_bindings" + ] } copy("resources") { diff --git a/ui/keyboard/keyboard.cc b/ui/keyboard/keyboard.cc index 436b935..2d4de13 100644 --- a/ui/keyboard/keyboard.cc +++ b/ui/keyboard/keyboard.cc @@ -7,6 +7,7 @@ #include "base/files/file_path.h" #include "base/path_service.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/keyboard/webui/vk_webui_controller.h" namespace keyboard { @@ -29,4 +30,17 @@ void InitializeKeyboard() { pak_file, ui::SCALE_FACTOR_100P); } +void InitializeWebUIBindings() { + CHECK(initialized); + base::FilePath content_resources; + DCHECK(PathService::Get(base::DIR_MODULE, &content_resources)); + content_resources = + content_resources.Append(FILE_PATH_LITERAL("content_resources.pak")); + ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( + content_resources, ui::SCALE_FACTOR_100P); + + content::WebUIControllerFactory::RegisterFactory( + VKWebUIControllerFactory::GetInstance()); +} + } // namespace keyboard diff --git a/ui/keyboard/keyboard.gyp b/ui/keyboard/keyboard.gyp index 34c265d..05bfc86 100644 --- a/ui/keyboard/keyboard.gyp +++ b/ui/keyboard/keyboard.gyp @@ -5,11 +5,21 @@ { 'variables': { 'chromium_code': 1, + 'keyboard_mojom_gen_js': '<(SHARED_INTERMEDIATE_DIR)/ui/keyboard/webui/keyboard.mojom.js', }, 'targets': [ { + 'target_name': 'keyboard_mojom_bindings', + 'type': 'none', + 'sources': [ + 'webui/keyboard.mojom', + ], + 'includes': [ '../../mojo/public/tools/bindings/mojom_bindings_generator.gypi' ], + }, + { # GN version: //ui/keyboard:resources 'target_name': 'keyboard_resources', + 'dependencies': [ 'keyboard_mojom_bindings', ], 'type': 'none', 'variables': { 'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/ui/keyboard', @@ -19,6 +29,9 @@ 'action_name': 'keyboard_resources', 'variables': { 'grit_grd_file': 'keyboard_resources.grd', + 'grit_additional_defines': [ + '-E', 'keyboard_mojom_gen_js=<(keyboard_mojom_gen_js)', + ], }, 'includes': [ '../../build/grit_action.gypi' ], }, @@ -41,7 +54,12 @@ '../../base/base.gyp:base', '../../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', '../../content/content.gyp:content_browser', + '../../content/content_resources.gyp:content_resources', '../../ipc/ipc.gyp:ipc', + '../../mojo/mojo_base.gyp:mojo_cpp_bindings', + '../../mojo/mojo_base.gyp:mojo_environment_chromium', + '../../mojo/mojo_base.gyp:mojo_js_bindings', + '../../mojo/mojo_base.gyp:mojo_system_impl', '../../skia/skia.gyp:skia', '../../url/url.gyp:url_lib', '../aura/aura.gyp:aura', @@ -51,6 +69,7 @@ '../gfx/gfx.gyp:gfx', '../gfx/gfx.gyp:gfx_geometry', '../wm/wm.gyp:wm', + 'keyboard_mojom_bindings', 'keyboard_resources', ], 'defines': [ @@ -73,6 +92,11 @@ 'keyboard_switches.h', 'keyboard_util.cc', 'keyboard_util.h', + 'webui/vk_mojo_handler.cc', + 'webui/vk_mojo_handler.h', + 'webui/vk_webui_controller.cc', + 'webui/vk_webui_controller.h', + '<(SHARED_INTERMEDIATE_DIR)/ui/keyboard/webui/keyboard.mojom.cc', ] }, { diff --git a/ui/keyboard/keyboard.h b/ui/keyboard/keyboard.h index a0aed8a..a13cac4 100644 --- a/ui/keyboard/keyboard.h +++ b/ui/keyboard/keyboard.h @@ -13,6 +13,7 @@ namespace keyboard { // for loading resources used in for the virtual keyboard. This becomes a no-op // after the first call. KEYBOARD_EXPORT void InitializeKeyboard(); +KEYBOARD_EXPORT void InitializeWebUIBindings(); // Resets the keyboard to an uninitialized state. Required for // BrowserWithTestWindowTest tests as they tear down the controller factory diff --git a/ui/keyboard/keyboard_resources.grd b/ui/keyboard/keyboard_resources.grd index ffcbda5..d290932 100644 --- a/ui/keyboard/keyboard_resources.grd +++ b/ui/keyboard/keyboard_resources.grd @@ -41,6 +41,8 @@ <include name="IDR_KEYBOARD_IMAGES_VOLUME_DOWN" file="resources/images/volume-down.svg" type="BINDATA" /> <include name="IDR_KEYBOARD_IMAGES_VOLUME_UP" file="resources/images/volume-up.svg" type="BINDATA" /> <include name="IDR_KEYBOARD_INDEX" file="resources/index.html" allowexternalscript="true" flattenhtml="true" type="BINDATA" /> + <include name="IDR_KEYBOARD_MOJO_JS" file="resources/keyboard_mojo.js" flattenhtml="true" type="BINDATA" /> + <include name="IDR_KEYBOARD_MOJO_GEN_JS" file="${keyboard_mojom_gen_js}" use_base_dir="false" type="BINDATA" /> <include name="IDR_KEYBOARD_JS" file="resources/keyboard.js" flattenhtml="true" type="BINDATA" /> <include name="IDR_KEYBOARD_LAYOUTS_NUMERIC" file="resources/layouts/numeric.html" type="BINDATA" /> <include name="IDR_KEYBOARD_LAYOUTS_QWERTY" file="resources/layouts/qwerty.html" type="BINDATA" /> diff --git a/ui/keyboard/keyboard_util.cc b/ui/keyboard/keyboard_util.cc index 0be99e2..438b99c 100644 --- a/ui/keyboard/keyboard_util.cc +++ b/ui/keyboard/keyboard_util.cc @@ -315,51 +315,53 @@ const GritResourceMap* GetKeyboardExtensionResources(size_t* size) { // necessary to have a custom path for the extension path, so the resource // map cannot be used directly. static const GritResourceMap kKeyboardResources[] = { - {"keyboard/layouts/function-key-row.html", IDR_KEYBOARD_FUNCTION_KEY_ROW}, - {"keyboard/images/back.svg", IDR_KEYBOARD_IMAGES_BACK}, - {"keyboard/images/backspace.png", IDR_KEYBOARD_IMAGES_BACKSPACE}, - {"keyboard/images/brightness-down.svg", - IDR_KEYBOARD_IMAGES_BRIGHTNESS_DOWN}, - {"keyboard/images/brightness-up.svg", IDR_KEYBOARD_IMAGES_BRIGHTNESS_UP}, - {"keyboard/images/change-window.svg", IDR_KEYBOARD_IMAGES_CHANGE_WINDOW}, - {"keyboard/images/down.svg", IDR_KEYBOARD_IMAGES_DOWN}, - {"keyboard/images/forward.svg", IDR_KEYBOARD_IMAGES_FORWARD}, - {"keyboard/images/fullscreen.svg", IDR_KEYBOARD_IMAGES_FULLSCREEN}, - {"keyboard/images/hide-keyboard.png", IDR_KEYBOARD_IMAGES_HIDE_KEYBOARD}, - {"keyboard/images/keyboard.svg", IDR_KEYBOARD_IMAGES_KEYBOARD}, - {"keyboard/images/left.svg", IDR_KEYBOARD_IMAGES_LEFT}, - {"keyboard/images/microphone.svg", IDR_KEYBOARD_IMAGES_MICROPHONE}, - {"keyboard/images/microphone-green.svg", - IDR_KEYBOARD_IMAGES_MICROPHONE_GREEN}, - {"keyboard/images/mute.svg", IDR_KEYBOARD_IMAGES_MUTE}, - {"keyboard/images/reload.svg", IDR_KEYBOARD_IMAGES_RELOAD}, - {"keyboard/images/return.png", IDR_KEYBOARD_IMAGES_RETURN}, - {"keyboard/images/right.svg", IDR_KEYBOARD_IMAGES_RIGHT}, - {"keyboard/images/search.png", IDR_KEYBOARD_IMAGES_SEARCH}, - {"keyboard/images/shift.png", IDR_KEYBOARD_IMAGES_SHIFT}, - {"keyboard/images/shutdown.svg", IDR_KEYBOARD_IMAGES_SHUTDOWN}, - {"keyboard/images/tab.png", IDR_KEYBOARD_IMAGES_TAB}, - {"keyboard/images/up.svg", IDR_KEYBOARD_IMAGES_UP}, - {"keyboard/images/volume-down.svg", IDR_KEYBOARD_IMAGES_VOLUME_DOWN}, - {"keyboard/images/volume-up.svg", IDR_KEYBOARD_IMAGES_VOLUME_UP}, - {"keyboard/index.html", IDR_KEYBOARD_INDEX}, - {"keyboard/keyboard.js", IDR_KEYBOARD_JS}, - {"keyboard/layouts/numeric.html", IDR_KEYBOARD_LAYOUTS_NUMERIC}, - {"keyboard/layouts/qwerty.html", IDR_KEYBOARD_LAYOUTS_QWERTY}, - {"keyboard/layouts/system-qwerty.html", IDR_KEYBOARD_LAYOUTS_SYSTEM_QWERTY}, - {"keyboard/layouts/spacebar-row.html", IDR_KEYBOARD_SPACEBAR_ROW}, - {"keyboard/manifest.json", IDR_KEYBOARD_MANIFEST}, - {"keyboard/main.css", IDR_KEYBOARD_MAIN_CSS}, - {"keyboard/polymer_loader.js", IDR_KEYBOARD_POLYMER_LOADER}, - {"keyboard/roboto_bold.ttf", IDR_KEYBOARD_ROBOTO_BOLD_TTF}, - {"keyboard/sounds/keypress-delete.wav", - IDR_KEYBOARD_SOUNDS_KEYPRESS_DELETE}, - {"keyboard/sounds/keypress-return.wav", - IDR_KEYBOARD_SOUNDS_KEYPRESS_RETURN}, - {"keyboard/sounds/keypress-spacebar.wav", - IDR_KEYBOARD_SOUNDS_KEYPRESS_SPACEBAR}, - {"keyboard/sounds/keypress-standard.wav", - IDR_KEYBOARD_SOUNDS_KEYPRESS_STANDARD}, + {"keyboard/layouts/function-key-row.html", IDR_KEYBOARD_FUNCTION_KEY_ROW}, + {"keyboard/images/back.svg", IDR_KEYBOARD_IMAGES_BACK}, + {"keyboard/images/backspace.png", IDR_KEYBOARD_IMAGES_BACKSPACE}, + {"keyboard/images/brightness-down.svg", + IDR_KEYBOARD_IMAGES_BRIGHTNESS_DOWN}, + {"keyboard/images/brightness-up.svg", IDR_KEYBOARD_IMAGES_BRIGHTNESS_UP}, + {"keyboard/images/change-window.svg", IDR_KEYBOARD_IMAGES_CHANGE_WINDOW}, + {"keyboard/images/down.svg", IDR_KEYBOARD_IMAGES_DOWN}, + {"keyboard/images/forward.svg", IDR_KEYBOARD_IMAGES_FORWARD}, + {"keyboard/images/fullscreen.svg", IDR_KEYBOARD_IMAGES_FULLSCREEN}, + {"keyboard/images/hide-keyboard.png", IDR_KEYBOARD_IMAGES_HIDE_KEYBOARD}, + {"keyboard/images/keyboard.svg", IDR_KEYBOARD_IMAGES_KEYBOARD}, + {"keyboard/images/left.svg", IDR_KEYBOARD_IMAGES_LEFT}, + {"keyboard/images/microphone.svg", IDR_KEYBOARD_IMAGES_MICROPHONE}, + {"keyboard/images/microphone-green.svg", + IDR_KEYBOARD_IMAGES_MICROPHONE_GREEN}, + {"keyboard/images/mute.svg", IDR_KEYBOARD_IMAGES_MUTE}, + {"keyboard/images/reload.svg", IDR_KEYBOARD_IMAGES_RELOAD}, + {"keyboard/images/return.png", IDR_KEYBOARD_IMAGES_RETURN}, + {"keyboard/images/right.svg", IDR_KEYBOARD_IMAGES_RIGHT}, + {"keyboard/images/search.png", IDR_KEYBOARD_IMAGES_SEARCH}, + {"keyboard/images/shift.png", IDR_KEYBOARD_IMAGES_SHIFT}, + {"keyboard/images/shutdown.svg", IDR_KEYBOARD_IMAGES_SHUTDOWN}, + {"keyboard/images/tab.png", IDR_KEYBOARD_IMAGES_TAB}, + {"keyboard/images/up.svg", IDR_KEYBOARD_IMAGES_UP}, + {"keyboard/images/volume-down.svg", IDR_KEYBOARD_IMAGES_VOLUME_DOWN}, + {"keyboard/images/volume-up.svg", IDR_KEYBOARD_IMAGES_VOLUME_UP}, + {"keyboard/index.html", IDR_KEYBOARD_INDEX}, + {"keyboard/keyboard.js", IDR_KEYBOARD_JS}, + {"keyboard/keyboard_mojo.js", IDR_KEYBOARD_MOJO_JS}, + {"keyboard/layouts/numeric.html", IDR_KEYBOARD_LAYOUTS_NUMERIC}, + {"keyboard/layouts/qwerty.html", IDR_KEYBOARD_LAYOUTS_QWERTY}, + {"keyboard/layouts/system-qwerty.html", + IDR_KEYBOARD_LAYOUTS_SYSTEM_QWERTY}, + {"keyboard/layouts/spacebar-row.html", IDR_KEYBOARD_SPACEBAR_ROW}, + {"keyboard/manifest.json", IDR_KEYBOARD_MANIFEST}, + {"keyboard/main.css", IDR_KEYBOARD_MAIN_CSS}, + {"keyboard/polymer_loader.js", IDR_KEYBOARD_POLYMER_LOADER}, + {"keyboard/roboto_bold.ttf", IDR_KEYBOARD_ROBOTO_BOLD_TTF}, + {"keyboard/sounds/keypress-delete.wav", + IDR_KEYBOARD_SOUNDS_KEYPRESS_DELETE}, + {"keyboard/sounds/keypress-return.wav", + IDR_KEYBOARD_SOUNDS_KEYPRESS_RETURN}, + {"keyboard/sounds/keypress-spacebar.wav", + IDR_KEYBOARD_SOUNDS_KEYPRESS_SPACEBAR}, + {"keyboard/sounds/keypress-standard.wav", + IDR_KEYBOARD_SOUNDS_KEYPRESS_STANDARD}, }; static const size_t kKeyboardResourcesSize = arraysize(kKeyboardResources); *size = kKeyboardResourcesSize; diff --git a/ui/keyboard/resources/index.html b/ui/keyboard/resources/index.html index d441600..0c9007c 100644 --- a/ui/keyboard/resources/index.html +++ b/ui/keyboard/resources/index.html @@ -9,6 +9,7 @@ <head> <meta charset="UTF-8"> <link rel="stylesheet" href="main.css"> + <script src="keyboard_mojo.js"></script> <script src="polymer_loader.js"></script> <script src="keyboard.js"></script> <include src="elements/kb-altkey-container.html"> diff --git a/ui/keyboard/resources/keyboard_mojo.js b/ui/keyboard/resources/keyboard_mojo.js new file mode 100644 index 0000000..eddf866 --- /dev/null +++ b/ui/keyboard/resources/keyboard_mojo.js @@ -0,0 +1,75 @@ +// Copyright 2014 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. +var connection; +var mojo_api; +var input_focused_event; + +if (!chrome.virtualKeyboardPrivate) { + define('main', [ + 'mojo/public/js/bindings/connection', + 'ui/keyboard/webui/keyboard.mojom', + 'content/public/renderer/service_provider', + ], function(connector, keyboard, serviceProvider) { + 'use strict'; + function KeyboardImpl(kbd) { + console.log('Creating KeyboardImpl'); + this.keyboard_ = kbd; + mojo_api = this; + } + + KeyboardImpl.prototype = Object.create(keyboard.KeyboardAPIStub.prototype); + + KeyboardImpl.prototype.onTextInputTypeChanged = function(input_type) { + console.log('Text input changed: ' + input_type); + input_focused_event.forEach(function(listener) { + listener({type: input_type}); + }); + }; + + return function() { + connection = new connector.Connection( + serviceProvider.connectToService( + keyboard.KeyboardUIHandlerMojoProxy.NAME_), + KeyboardImpl, + keyboard.KeyboardUIHandlerMojoProxy); + }; + }); + + chrome.virtualKeyboardPrivate = {}; + chrome.virtualKeyboardPrivate.sendKeyEvent = function(event) { + if (!mojo_api) + return; + console.log('sending key event: ' + event.type); + mojo_api.keyboard_.sendKeyEvent(event.type, + event.charValue, + event.keyCode, + event.keyName, + event.modifiers); + }; + chrome.virtualKeyboardPrivate.hideKeyboard = function() { + if (!mojo_api) + return; + mojo_api.keyboard_.hideKeyboard(); + }; + chrome.virtualKeyboardPrivate.moveCursor = function() {}; + chrome.virtualKeyboardPrivate.lockKeyboard = function() {}; + chrome.virtualKeyboardPrivate.keyboardLoaded = function() {}; + chrome.virtualKeyboardPrivate.getKeyboardConfig = function() {}; + + function BrowserEvent() { + this.listeners_ = []; + }; + + BrowserEvent.prototype.addListener = function(callback) { + this.listeners_.push(callback); + }; + + BrowserEvent.prototype.forEach = function(callback) { + for (var i = 0; i < this.listeners_.length; ++i) + callback(this.listeners_[i]); + }; + + input_focused_event = new BrowserEvent; + chrome.virtualKeyboardPrivate.onTextInputBoxFocused = input_focused_event; +} diff --git a/ui/keyboard/webui/BUILD.gn b/ui/keyboard/webui/BUILD.gn new file mode 100644 index 0000000..84bde19 --- /dev/null +++ b/ui/keyboard/webui/BUILD.gn @@ -0,0 +1,12 @@ +# Copyright 2014 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. + +import("//mojo/public/tools/bindings/mojom.gni") + +# GYP version: ui/keyboard/keyboard.gyp:keyboard_mojom_bindings +mojom("mojo_bindings") { + sources = [ + "keyboard.mojom", + ] +} diff --git a/ui/keyboard/webui/DEPS b/ui/keyboard/webui/DEPS new file mode 100644 index 0000000..ef8ad28 --- /dev/null +++ b/ui/keyboard/webui/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+mojo/public", +] diff --git a/ui/keyboard/webui/keyboard.mojom b/ui/keyboard/webui/keyboard.mojom new file mode 100644 index 0000000..9b05dc2 --- /dev/null +++ b/ui/keyboard/webui/keyboard.mojom @@ -0,0 +1,14 @@ +[Client=KeyboardAPI] +interface KeyboardUIHandlerMojo { + SendKeyEvent(string event_type, + int32 char_value, + int32 key_code, + string key_name, + int32 modifiers); + + HideKeyboard(); +}; + +interface KeyboardAPI { + OnTextInputTypeChanged(string input_type); +}; diff --git a/ui/keyboard/webui/vk_mojo_handler.cc b/ui/keyboard/webui/vk_mojo_handler.cc new file mode 100644 index 0000000..48e6dcc --- /dev/null +++ b/ui/keyboard/webui/vk_mojo_handler.cc @@ -0,0 +1,120 @@ +// Copyright 2014 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/webui/vk_mojo_handler.h" + +#include "ui/aura/window.h" +#include "ui/base/ime/input_method.h" +#include "ui/base/ime/text_input_client.h" +#include "ui/keyboard/keyboard_controller.h" +#include "ui/keyboard/keyboard_controller_proxy.h" +#include "ui/keyboard/keyboard_util.h" +#include "ui/keyboard/webui/keyboard.mojom.h" + +namespace keyboard { + +VKMojoHandler::VKMojoHandler() { + GetInputMethod()->AddObserver(this); +} + +VKMojoHandler::~VKMojoHandler() { + GetInputMethod()->RemoveObserver(this); +} + +ui::InputMethod* VKMojoHandler::GetInputMethod() { + return KeyboardController::GetInstance()->proxy()->GetInputMethod(); +} + +void VKMojoHandler::OnConnectionEstablished() { + OnTextInputStateChanged(GetInputMethod()->GetTextInputClient()); +} + +void VKMojoHandler::SendKeyEvent(const mojo::String& event_type, + int32_t char_value, + int32_t key_code, + const mojo::String& key_name, + int32_t modifiers) { + aura::Window* window = + KeyboardController::GetInstance()->GetContainerWindow(); + std::string type = event_type.To<std::string>(); + std::string name = key_name.To<std::string>(); + keyboard::SendKeyEvent( + type, char_value, key_code, name, modifiers, window->GetHost()); +} + +void VKMojoHandler::HideKeyboard() { + KeyboardController::GetInstance()->HideKeyboard( + KeyboardController::HIDE_REASON_MANUAL); +} + +void VKMojoHandler::OnTextInputTypeChanged(const ui::TextInputClient* client) { +} + +void VKMojoHandler::OnFocus() { +} + +void VKMojoHandler::OnBlur() { +} + +void VKMojoHandler::OnCaretBoundsChanged(const ui::TextInputClient* client) { +} + +void VKMojoHandler::OnTextInputStateChanged( + const ui::TextInputClient* text_client) { + ui::TextInputType type = + text_client ? text_client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; + std::string type_name = "none"; + switch (type) { + case ui::TEXT_INPUT_TYPE_NONE: + type_name = "none"; + break; + + case ui::TEXT_INPUT_TYPE_PASSWORD: + type_name = "password"; + break; + + case ui::TEXT_INPUT_TYPE_EMAIL: + type_name = "email"; + break; + + case ui::TEXT_INPUT_TYPE_NUMBER: + type_name = "number"; + break; + + case ui::TEXT_INPUT_TYPE_TELEPHONE: + type_name = "tel"; + break; + + case ui::TEXT_INPUT_TYPE_URL: + type_name = "url"; + break; + + case ui::TEXT_INPUT_TYPE_DATE: + type_name = "date"; + break; + + case ui::TEXT_INPUT_TYPE_TEXT: + case ui::TEXT_INPUT_TYPE_SEARCH: + case ui::TEXT_INPUT_TYPE_DATE_TIME: + case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL: + case ui::TEXT_INPUT_TYPE_MONTH: + case ui::TEXT_INPUT_TYPE_TIME: + case ui::TEXT_INPUT_TYPE_WEEK: + case ui::TEXT_INPUT_TYPE_TEXT_AREA: + case ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE: + case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD: + type_name = "text"; + break; + } + client()->OnTextInputTypeChanged(type_name); +} + +void VKMojoHandler::OnInputMethodDestroyed( + const ui::InputMethod* input_method) { +} + +void VKMojoHandler::OnShowImeIfNeeded() { +} + +} // namespace keyboard diff --git a/ui/keyboard/webui/vk_mojo_handler.h b/ui/keyboard/webui/vk_mojo_handler.h new file mode 100644 index 0000000..7ee3c9d --- /dev/null +++ b/ui/keyboard/webui/vk_mojo_handler.h @@ -0,0 +1,51 @@ +// Copyright 2014 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_WEBUI_VK_MOJO_HANDLER_H_ +#define UI_KEYBOARD_WEBUI_VK_MOJO_HANDLER_H_ + +#include "base/macros.h" +#include "ui/base/ime/input_method_observer.h" +#include "ui/keyboard/webui/keyboard.mojom.h" + +namespace keyboard { + +class VKMojoHandler : public mojo::InterfaceImpl<KeyboardUIHandlerMojo>, + public ui::InputMethodObserver { + public: + VKMojoHandler(); + virtual ~VKMojoHandler(); + + private: + ui::InputMethod* GetInputMethod(); + + // mojo::InterfaceImpl<>: + virtual void OnConnectionEstablished() OVERRIDE; + + // KeyboardUIHandlerMojo: + virtual void SendKeyEvent(const mojo::String& event_type, + int32_t char_value, + int32_t key_code, + const mojo::String& key_name, + int32_t modifiers) OVERRIDE; + virtual void HideKeyboard() OVERRIDE; + + // ui::InputMethodObserver: + virtual void OnTextInputTypeChanged( + const ui::TextInputClient* client) OVERRIDE; + virtual void OnFocus() OVERRIDE; + virtual void OnBlur() OVERRIDE; + virtual void OnCaretBoundsChanged(const ui::TextInputClient* client) OVERRIDE; + virtual void OnTextInputStateChanged( + const ui::TextInputClient* text_client) OVERRIDE; + virtual void OnInputMethodDestroyed( + const ui::InputMethod* input_method) OVERRIDE; + virtual void OnShowImeIfNeeded() OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(VKMojoHandler); +}; + +} // namespace keyboard + +#endif // UI_KEYBOARD_WEBUI_VK_MOJO_HANDLER_H_ diff --git a/athena/virtual_keyboard/vk_webui_controller.cc b/ui/keyboard/webui/vk_webui_controller.cc index d26b2c9..2e0138b 100644 --- a/athena/virtual_keyboard/vk_webui_controller.cc +++ b/ui/keyboard/webui/vk_webui_controller.cc @@ -2,35 +2,40 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "athena/virtual_keyboard/vk_webui_controller.h" +#include "ui/keyboard/webui/vk_webui_controller.h" -#include "athena/virtual_keyboard/vk_message_handler.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" +#include "content/public/browser/render_frame_host.h" +#include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui_data_source.h" +#include "content/public/common/service_registry.h" #include "grit/keyboard_resources.h" #include "grit/keyboard_resources_map.h" +#include "mojo/public/cpp/bindings/interface_impl.h" +#include "mojo/public/cpp/system/core.h" #include "ui/keyboard/keyboard_constants.h" #include "ui/keyboard/keyboard_util.h" +#include "ui/keyboard/webui/vk_mojo_handler.h" -namespace athena { +namespace keyboard { namespace { content::WebUIDataSource* CreateKeyboardUIDataSource() { content::WebUIDataSource* source = - content::WebUIDataSource::Create(keyboard::kKeyboardHost); + content::WebUIDataSource::Create(kKeyboardHost); size_t count = 0; - const GritResourceMap* resources = - keyboard::GetKeyboardExtensionResources(&count); + const GritResourceMap* resources = GetKeyboardExtensionResources(&count); source->SetDefaultResource(IDR_KEYBOARD_INDEX); - const std::string keyboard_host = - base::StringPrintf("%s/", keyboard::kKeyboardHost); + const std::string keyboard_host = base::StringPrintf("%s/", kKeyboardHost); for (size_t i = 0; i < count; ++i) { size_t offset = 0; + // The webui URL needs to skip the 'keyboard/' at the front of the resource + // names, since it is part of the data-source name. if (StartsWithASCII(std::string(resources[i].name), keyboard_host, false)) offset = keyboard_host.length(); source->AddResourcePath(resources[i].name + offset, resources[i].value); @@ -44,23 +49,36 @@ content::WebUIDataSource* CreateKeyboardUIDataSource() { // VKWebUIController: VKWebUIController::VKWebUIController(content::WebUI* web_ui) - : WebUIController(web_ui) { + : WebUIController(web_ui), weak_factory_(this) { content::BrowserContext* browser_context = web_ui->GetWebContents()->GetBrowserContext(); - web_ui->AddMessageHandler(new VKMessageHandler()); content::WebUIDataSource::Add(browser_context, CreateKeyboardUIDataSource()); + content::WebUIDataSource::AddMojoDataSource(browser_context)->AddResourcePath( + "ui/keyboard/webui/keyboard.mojom", IDR_KEYBOARD_MOJO_GEN_JS); } VKWebUIController::~VKWebUIController() { } +void VKWebUIController::RenderViewCreated(content::RenderViewHost* host) { + host->GetMainFrame()->GetServiceRegistry()->AddService<KeyboardUIHandlerMojo>( + base::Bind(&VKWebUIController::CreateAndStoreUIHandler, + weak_factory_.GetWeakPtr())); +} + +void VKWebUIController::CreateAndStoreUIHandler( + mojo::InterfaceRequest<KeyboardUIHandlerMojo> request) { + ui_handler_ = scoped_ptr<VKMojoHandler>( + mojo::WeakBindToRequest(new VKMojoHandler(), &request)); +} + //////////////////////////////////////////////////////////////////////////////// // VKWebUIControllerFactory: content::WebUI::TypeID VKWebUIControllerFactory::GetWebUIType( content::BrowserContext* browser_context, const GURL& url) const { - if (url == GURL(keyboard::kKeyboardURL)) + if (url == GURL(kKeyboardURL)) return const_cast<VKWebUIControllerFactory*>(this); return content::WebUI::kNoWebUI; @@ -81,7 +99,7 @@ bool VKWebUIControllerFactory::UseWebUIBindingsForURL( content::WebUIController* VKWebUIControllerFactory::CreateWebUIControllerForURL( content::WebUI* web_ui, const GURL& url) const { - if (url == GURL(keyboard::kKeyboardURL)) + if (url == GURL(kKeyboardURL)) return new VKWebUIController(web_ui); return NULL; } @@ -98,4 +116,4 @@ VKWebUIControllerFactory::VKWebUIControllerFactory() { VKWebUIControllerFactory::~VKWebUIControllerFactory() { } -} // namespace athena +} // namespace keyboard diff --git a/athena/virtual_keyboard/vk_webui_controller.h b/ui/keyboard/webui/vk_webui_controller.h index c2c6ecc..d701c63 100644 --- a/athena/virtual_keyboard/vk_webui_controller.h +++ b/ui/keyboard/webui/vk_webui_controller.h @@ -2,15 +2,26 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef ATHENA_VIRTUAL_KEYBOARD_VK_WEBUI_CONTROLLER_H_ -#define ATHENA_VIRTUAL_KEYBOARD_VK_WEBUI_CONTROLLER_H_ +#ifndef UI_KEYBOARD_WEBUI_VK_WEBUI_CONTROLLER_H_ +#define UI_KEYBOARD_WEBUI_VK_WEBUI_CONTROLLER_H_ #include "base/macros.h" #include "base/memory/singleton.h" +#include "base/memory/weak_ptr.h" #include "content/public/browser/web_ui_controller.h" #include "content/public/browser/web_ui_controller_factory.h" +#include "mojo/public/cpp/bindings/interface_request.h" +#include "mojo/public/cpp/system/core.h" +#include "ui/keyboard/keyboard_export.h" +#include "ui/keyboard/webui/keyboard.mojom.h" -namespace athena { +namespace content { +class WebUIDataSource; +} + +namespace keyboard { + +class VKMojoHandler; class VKWebUIController : public content::WebUIController { public: @@ -18,10 +29,20 @@ class VKWebUIController : public content::WebUIController { virtual ~VKWebUIController(); private: + void CreateAndStoreUIHandler( + mojo::InterfaceRequest<KeyboardUIHandlerMojo> request); + + // content::WebUIController: + virtual void RenderViewCreated(content::RenderViewHost* host) OVERRIDE; + + scoped_ptr<VKMojoHandler> ui_handler_; + base::WeakPtrFactory<VKWebUIController> weak_factory_; + DISALLOW_COPY_AND_ASSIGN(VKWebUIController); }; -class VKWebUIControllerFactory : public content::WebUIControllerFactory { +class KEYBOARD_EXPORT VKWebUIControllerFactory + : public content::WebUIControllerFactory { public: // WebUIControllerFactory: virtual content::WebUI::TypeID GetWebUIType( @@ -47,6 +68,6 @@ class VKWebUIControllerFactory : public content::WebUIControllerFactory { DISALLOW_COPY_AND_ASSIGN(VKWebUIControllerFactory); }; -} // namespace athena +} // namespace keyboard -#endif // ATHENA_VIRTUAL_KEYBOARD_VK_WEBUI_CONTROLLER_H_ +#endif // UI_KEYBOARD_WEBUI_VK_WEBUI_CONTROLLER_H_ |