Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / ash / ash_keyboard_controller_proxy.cc
blob0e486fd7f20383992620b0487db4583d3f9d6aad
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/media/media_capture_devices_dispatcher.h"
11 #include "content/public/browser/host_zoom_map.h"
12 #include "content/public/browser/render_process_host.h"
13 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/site_instance.h"
15 #include "content/public/browser/web_contents.h"
16 #include "extensions/browser/event_router.h"
17 #include "extensions/browser/extension_function_dispatcher.h"
18 #include "extensions/browser/extension_registry.h"
19 #include "extensions/browser/view_type_utils.h"
20 #include "extensions/common/api/virtual_keyboard_private.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 =
31 extensions::core_api::virtual_keyboard_private;
33 typedef virtual_keyboard_private::OnTextInputBoxFocused::Context Context;
35 namespace {
37 const char* kVirtualKeyboardExtensionID = "mppnpdlheglhdfmldimlhpnegondlapf";
39 Context::Type TextInputTypeToGeneratedInputTypeEnum(ui::TextInputType type) {
40 switch (type) {
41 case ui::TEXT_INPUT_TYPE_NONE:
42 return Context::TYPE_NONE;
43 case ui::TEXT_INPUT_TYPE_PASSWORD:
44 return Context::TYPE_PASSWORD;
45 case ui::TEXT_INPUT_TYPE_EMAIL:
46 return Context::TYPE_EMAIL;
47 case ui::TEXT_INPUT_TYPE_NUMBER:
48 return Context::TYPE_NUMBER;
49 case ui::TEXT_INPUT_TYPE_TELEPHONE:
50 return Context::TYPE_TEL;
51 case ui::TEXT_INPUT_TYPE_URL:
52 return Context::TYPE_URL;
53 case ui::TEXT_INPUT_TYPE_DATE:
54 return Context::TYPE_DATE;
55 case ui::TEXT_INPUT_TYPE_TEXT:
56 case ui::TEXT_INPUT_TYPE_SEARCH:
57 case ui::TEXT_INPUT_TYPE_DATE_TIME:
58 case ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL:
59 case ui::TEXT_INPUT_TYPE_MONTH:
60 case ui::TEXT_INPUT_TYPE_TIME:
61 case ui::TEXT_INPUT_TYPE_WEEK:
62 case ui::TEXT_INPUT_TYPE_TEXT_AREA:
63 case ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE:
64 case ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD:
65 return Context::TYPE_TEXT;
67 NOTREACHED();
68 return Context::TYPE_NONE;
71 } // namespace
73 AshKeyboardControllerProxy::AshKeyboardControllerProxy(
74 content::BrowserContext* context)
75 : keyboard::KeyboardControllerProxy(context) {
78 AshKeyboardControllerProxy::~AshKeyboardControllerProxy() {}
80 void AshKeyboardControllerProxy::OnRequest(
81 const ExtensionHostMsg_Request_Params& params) {
82 extension_function_dispatcher_->Dispatch(
83 params, web_contents()->GetRenderViewHost());
86 ui::InputMethod* AshKeyboardControllerProxy::GetInputMethod() {
87 aura::Window* root_window = ash::Shell::GetInstance()->GetPrimaryRootWindow();
88 DCHECK(root_window);
89 return root_window->GetProperty(aura::client::kRootWindowInputMethodKey);
92 void AshKeyboardControllerProxy::RequestAudioInput(
93 content::WebContents* web_contents,
94 const content::MediaStreamRequest& request,
95 const content::MediaResponseCallback& callback) {
96 const extensions::Extension* extension = NULL;
97 GURL origin(request.security_origin);
98 if (origin.SchemeIs(extensions::kExtensionScheme)) {
99 const extensions::ExtensionRegistry* registry =
100 extensions::ExtensionRegistry::Get(browser_context());
101 extension = registry->enabled_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(browser_context(), 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::RenderViewCreated(
141 content::RenderViewHost* render_view_host) {
142 content::HostZoomMap* zoom_map =
143 content::HostZoomMap::GetDefaultForBrowserContext(browser_context());
144 DCHECK(zoom_map);
145 int render_process_id = render_view_host->GetProcess()->GetID();
146 int render_view_id = render_view_host->GetRoutingID();
147 zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id, 0);
150 void AshKeyboardControllerProxy::ShowKeyboardContainer(
151 aura::Window* container) {
152 // TODO(bshe): Implement logic to decide which root window should display
153 // virtual keyboard. http://crbug.com/303429
154 if (container->GetRootWindow() != ash::Shell::GetPrimaryRootWindow())
155 NOTIMPLEMENTED();
157 KeyboardControllerProxy::ShowKeyboardContainer(container);
160 void AshKeyboardControllerProxy::SetUpdateInputType(ui::TextInputType type) {
161 // TODO(bshe): Need to check the affected window's profile once multi-profile
162 // is supported.
163 extensions::EventRouter* router =
164 extensions::EventRouter::Get(browser_context());
166 if (!router->HasEventListener(
167 virtual_keyboard_private::OnTextInputBoxFocused::kEventName)) {
168 return;
171 scoped_ptr<base::ListValue> event_args(new base::ListValue());
172 scoped_ptr<base::DictionaryValue> input_context(new base::DictionaryValue());
173 input_context->SetString("type",
174 Context::ToString(TextInputTypeToGeneratedInputTypeEnum(type)));
175 event_args->Append(input_context.release());
177 scoped_ptr<extensions::Event> event(new extensions::Event(
178 virtual_keyboard_private::OnTextInputBoxFocused::kEventName,
179 event_args.Pass()));
180 event->restrict_to_browser_context = browser_context();
181 router->DispatchEventToExtension(kVirtualKeyboardExtensionID, event.Pass());