No longer register app window placement preference keys on
[chromium-blink-merge.git] / chrome / browser / ui / ash / ash_keyboard_controller_proxy.cc
blob29bad75539dc16726eedb3db8ad2e56fea67b739
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h"
7 #include "ash/display/display_controller.h"
8 #include "ash/shell.h"
9 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/common/extensions/api/virtual_keyboard_private.h"
15 #include "content/public/browser/site_instance.h"
16 #include "content/public/browser/web_contents.h"
17 #include "extensions/browser/event_router.h"
18 #include "extensions/browser/extension_function_dispatcher.h"
19 #include "extensions/browser/extension_system.h"
20 #include "extensions/browser/view_type_utils.h"
21 #include "extensions/common/constants.h"
22 #include "extensions/common/extension_messages.h"
23 #include "ipc/ipc_message_macros.h"
24 #include "ui/aura/client/aura_constants.h"
25 #include "ui/aura/window.h"
26 #include "ui/aura/window_event_dispatcher.h"
27 #include "ui/compositor/scoped_layer_animation_settings.h"
28 #include "ui/keyboard/keyboard_controller.h"
30 namespace virtual_keyboard_private = extensions::api::virtual_keyboard_private;
31 typedef virtual_keyboard_private::OnTextInputBoxFocused::Context Context;
33 namespace {
35 const char* kVirtualKeyboardExtensionID = "mppnpdlheglhdfmldimlhpnegondlapf";
37 Context::Type TextInputTypeToGeneratedInputTypeEnum(ui::TextInputType type) {
38 switch (type) {
39 case ui::TEXT_INPUT_TYPE_NONE:
40 return Context::TYPE_NONE;
41 case ui::TEXT_INPUT_TYPE_PASSWORD:
42 return Context::TYPE_PASSWORD;
43 case ui::TEXT_INPUT_TYPE_EMAIL:
44 return Context::TYPE_EMAIL;
45 case ui::TEXT_INPUT_TYPE_NUMBER:
46 return Context::TYPE_NUMBER;
47 case ui::TEXT_INPUT_TYPE_TELEPHONE:
48 return Context::TYPE_TEL;
49 case ui::TEXT_INPUT_TYPE_URL:
50 return Context::TYPE_URL;
51 case ui::TEXT_INPUT_TYPE_DATE:
52 return Context::TYPE_DATE;
53 case ui::TEXT_INPUT_TYPE_TEXT:
54 case ui::TEXT_INPUT_TYPE_SEARCH:
55 case ui::TEXT_INPUT_TYPE_DATE_TIME:
56 case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL:
57 case ui::TEXT_INPUT_TYPE_MONTH:
58 case ui::TEXT_INPUT_TYPE_TIME:
59 case ui::TEXT_INPUT_TYPE_WEEK:
60 case ui::TEXT_INPUT_TYPE_TEXT_AREA:
61 case ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE:
62 case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD:
63 return Context::TYPE_TEXT;
65 NOTREACHED();
66 return Context::TYPE_NONE;
69 } // namespace
71 AshKeyboardControllerProxy::AshKeyboardControllerProxy() {}
73 AshKeyboardControllerProxy::~AshKeyboardControllerProxy() {}
75 void AshKeyboardControllerProxy::OnRequest(
76 const ExtensionHostMsg_Request_Params& params) {
77 extension_function_dispatcher_->Dispatch(
78 params, web_contents()->GetRenderViewHost());
81 content::BrowserContext* AshKeyboardControllerProxy::GetBrowserContext() {
82 return ProfileManager::GetActiveUserProfile();
85 ui::InputMethod* AshKeyboardControllerProxy::GetInputMethod() {
86 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow();
87 DCHECK(root_window);
88 return root_window->GetProperty(aura::client::kRootWindowInputMethodKey);
91 void AshKeyboardControllerProxy::RequestAudioInput(
92 content::WebContents* web_contents,
93 const content::MediaStreamRequest& request,
94 const content::MediaResponseCallback& callback) {
95 const extensions::Extension* extension = NULL;
96 GURL origin(request.security_origin);
97 if (origin.SchemeIs(extensions::kExtensionScheme)) {
98 ExtensionService* extensions_service =
99 extensions::ExtensionSystem::Get(
100 GetBrowserContext())->extension_service();
101 extension = extensions_service->extensions()->GetByID(origin.host());
102 DCHECK(extension);
105 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest(
106 web_contents, request, callback, extension);
109 void AshKeyboardControllerProxy::SetupWebContents(
110 content::WebContents* contents) {
111 extension_function_dispatcher_.reset(
112 new extensions::ExtensionFunctionDispatcher(GetBrowserContext(), this));
113 extensions::SetViewType(contents, extensions::VIEW_TYPE_VIRTUAL_KEYBOARD);
114 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
115 contents);
116 Observe(contents);
119 extensions::WindowController*
120 AshKeyboardControllerProxy::GetExtensionWindowController() const {
121 // The keyboard doesn't have a window controller.
122 return NULL;
125 content::WebContents*
126 AshKeyboardControllerProxy::GetAssociatedWebContents() const {
127 return web_contents();
130 bool AshKeyboardControllerProxy::OnMessageReceived(
131 const IPC::Message& message) {
132 bool handled = true;
133 IPC_BEGIN_MESSAGE_MAP(AshKeyboardControllerProxy, message)
134 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest)
135 IPC_MESSAGE_UNHANDLED(handled = false)
136 IPC_END_MESSAGE_MAP()
137 return handled;
140 void AshKeyboardControllerProxy::ShowKeyboardContainer(
141 aura::Window* container) {
142 // TODO(bshe): Implement logic to decide which root window should display
143 // virtual keyboard. http://crbug.com/303429
144 if (container->GetRootWindow() != ash::Shell::GetPrimaryRootWindow())
145 NOTIMPLEMENTED();
147 KeyboardControllerProxy::ShowKeyboardContainer(container);
150 void AshKeyboardControllerProxy::SetUpdateInputType(ui::TextInputType type) {
151 // TODO(bshe): Need to check the affected window's profile once multi-profile
152 // is supported.
153 content::BrowserContext* context = GetBrowserContext();
154 extensions::EventRouter* router = extensions::EventRouter::Get(context);
156 if (!router->HasEventListener(
157 virtual_keyboard_private::OnTextInputBoxFocused::kEventName)) {
158 return;
161 scoped_ptr<base::ListValue> event_args(new base::ListValue());
162 scoped_ptr<base::DictionaryValue> input_context(new base::DictionaryValue());
163 input_context->SetString("type",
164 Context::ToString(TextInputTypeToGeneratedInputTypeEnum(type)));
165 event_args->Append(input_context.release());
167 scoped_ptr<extensions::Event> event(new extensions::Event(
168 virtual_keyboard_private::OnTextInputBoxFocused::kEventName,
169 event_args.Pass()));
170 event->restrict_to_browser_context = context;
171 router->DispatchEventToExtension(kVirtualKeyboardExtensionID, event.Pass());