| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h" | 5 #include "chrome/browser/ui/ash/chrome_keyboard_ui.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 8 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
| 9 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 9 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 10 #include "content/public/browser/host_zoom_map.h" | 10 #include "content/public/browser/host_zoom_map.h" |
| 11 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
| 12 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
| 13 #include "content/public/browser/site_instance.h" | 13 #include "content/public/browser/site_instance.h" |
| 14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "extensions/browser/event_router.h" | 15 #include "extensions/browser/event_router.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 100 } |
| 101 | 101 |
| 102 private: | 102 private: |
| 103 content::BrowserContext* context_; | 103 content::BrowserContext* context_; |
| 104 | 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(AshKeyboardControllerObserver); | 105 DISALLOW_COPY_AND_ASSIGN(AshKeyboardControllerObserver); |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 } // namespace | 108 } // namespace |
| 109 | 109 |
| 110 AshKeyboardControllerProxy::AshKeyboardControllerProxy( | 110 ChromeKeyboardUI::ChromeKeyboardUI(content::BrowserContext* context) |
| 111 content::BrowserContext* context) | 111 : keyboard::KeyboardUIContent(context) {} |
| 112 : keyboard::KeyboardControllerProxy(context) { | |
| 113 } | |
| 114 | 112 |
| 115 AshKeyboardControllerProxy::~AshKeyboardControllerProxy() { | 113 ChromeKeyboardUI::~ChromeKeyboardUI() { |
| 116 DCHECK(!keyboard_controller()); | 114 DCHECK(!keyboard_controller()); |
| 117 } | 115 } |
| 118 | 116 |
| 119 ui::InputMethod* AshKeyboardControllerProxy::GetInputMethod() { | 117 ui::InputMethod* ChromeKeyboardUI::GetInputMethod() { |
| 120 aura::Window* root_window = ash::Shell::GetTargetRootWindow(); | 118 aura::Window* root_window = ash::Shell::GetTargetRootWindow(); |
| 121 DCHECK(root_window); | 119 DCHECK(root_window); |
| 122 return root_window->GetHost()->GetInputMethod(); | 120 return root_window->GetHost()->GetInputMethod(); |
| 123 } | 121 } |
| 124 | 122 |
| 125 void AshKeyboardControllerProxy::RequestAudioInput( | 123 void ChromeKeyboardUI::RequestAudioInput( |
| 126 content::WebContents* web_contents, | 124 content::WebContents* web_contents, |
| 127 const content::MediaStreamRequest& request, | 125 const content::MediaStreamRequest& request, |
| 128 const content::MediaResponseCallback& callback) { | 126 const content::MediaResponseCallback& callback) { |
| 129 const extensions::Extension* extension = NULL; | 127 const extensions::Extension* extension = NULL; |
| 130 GURL origin(request.security_origin); | 128 GURL origin(request.security_origin); |
| 131 if (origin.SchemeIs(extensions::kExtensionScheme)) { | 129 if (origin.SchemeIs(extensions::kExtensionScheme)) { |
| 132 const extensions::ExtensionRegistry* registry = | 130 const extensions::ExtensionRegistry* registry = |
| 133 extensions::ExtensionRegistry::Get(browser_context()); | 131 extensions::ExtensionRegistry::Get(browser_context()); |
| 134 extension = registry->enabled_extensions().GetByID(origin.host()); | 132 extension = registry->enabled_extensions().GetByID(origin.host()); |
| 135 DCHECK(extension); | 133 DCHECK(extension); |
| 136 } | 134 } |
| 137 | 135 |
| 138 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( | 136 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( |
| 139 web_contents, request, callback, extension); | 137 web_contents, request, callback, extension); |
| 140 } | 138 } |
| 141 | 139 |
| 142 void AshKeyboardControllerProxy::SetupWebContents( | 140 void ChromeKeyboardUI::SetupWebContents(content::WebContents* contents) { |
| 143 content::WebContents* contents) { | |
| 144 extensions::SetViewType(contents, extensions::VIEW_TYPE_VIRTUAL_KEYBOARD); | 141 extensions::SetViewType(contents, extensions::VIEW_TYPE_VIRTUAL_KEYBOARD); |
| 145 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | 142 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
| 146 contents); | 143 contents); |
| 147 Observe(contents); | 144 Observe(contents); |
| 148 } | 145 } |
| 149 | 146 |
| 150 void AshKeyboardControllerProxy::SetController( | 147 void ChromeKeyboardUI::SetController(keyboard::KeyboardController* controller) { |
| 151 keyboard::KeyboardController* controller) { | |
| 152 // During KeyboardController destruction, controller can be set to null. | 148 // During KeyboardController destruction, controller can be set to null. |
| 153 if (!controller) { | 149 if (!controller) { |
| 154 DCHECK(keyboard_controller()); | 150 DCHECK(keyboard_controller()); |
| 155 keyboard_controller()->RemoveObserver(observer_.get()); | 151 keyboard_controller()->RemoveObserver(observer_.get()); |
| 156 KeyboardControllerProxy::SetController(nullptr); | 152 KeyboardUIContent::SetController(nullptr); |
| 157 return; | 153 return; |
| 158 } | 154 } |
| 159 KeyboardControllerProxy::SetController(controller); | 155 KeyboardUIContent::SetController(controller); |
| 160 observer_.reset(new AshKeyboardControllerObserver(browser_context())); | 156 observer_.reset(new AshKeyboardControllerObserver(browser_context())); |
| 161 keyboard_controller()->AddObserver(observer_.get()); | 157 keyboard_controller()->AddObserver(observer_.get()); |
| 162 } | 158 } |
| 163 | 159 |
| 164 void AshKeyboardControllerProxy::RenderViewCreated( | 160 void ChromeKeyboardUI::RenderViewCreated( |
| 165 content::RenderViewHost* render_view_host) { | 161 content::RenderViewHost* render_view_host) { |
| 166 content::HostZoomMap* zoom_map = | 162 content::HostZoomMap* zoom_map = |
| 167 content::HostZoomMap::GetDefaultForBrowserContext(browser_context()); | 163 content::HostZoomMap::GetDefaultForBrowserContext(browser_context()); |
| 168 DCHECK(zoom_map); | 164 DCHECK(zoom_map); |
| 169 int render_process_id = render_view_host->GetProcess()->GetID(); | 165 int render_process_id = render_view_host->GetProcess()->GetID(); |
| 170 int render_view_id = render_view_host->GetRoutingID(); | 166 int render_view_id = render_view_host->GetRoutingID(); |
| 171 zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id, 0); | 167 zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id, 0); |
| 172 } | 168 } |
| 173 | 169 |
| 174 void AshKeyboardControllerProxy::ShowKeyboardContainer( | 170 void ChromeKeyboardUI::ShowKeyboardContainer(aura::Window* container) { |
| 175 aura::Window* container) { | |
| 176 // TODO(bshe): Implement logic to decide which root window should display | 171 // TODO(bshe): Implement logic to decide which root window should display |
| 177 // virtual keyboard. http://crbug.com/303429 | 172 // virtual keyboard. http://crbug.com/303429 |
| 178 if (container->GetRootWindow() != ash::Shell::GetPrimaryRootWindow()) | 173 if (container->GetRootWindow() != ash::Shell::GetPrimaryRootWindow()) |
| 179 NOTIMPLEMENTED(); | 174 NOTIMPLEMENTED(); |
| 180 | 175 |
| 181 KeyboardControllerProxy::ShowKeyboardContainer(container); | 176 KeyboardUIContent::ShowKeyboardContainer(container); |
| 182 } | 177 } |
| 183 | 178 |
| 184 void AshKeyboardControllerProxy::SetUpdateInputType(ui::TextInputType type) { | 179 void ChromeKeyboardUI::SetUpdateInputType(ui::TextInputType type) { |
| 185 // TODO(bshe): Need to check the affected window's profile once multi-profile | 180 // TODO(bshe): Need to check the affected window's profile once multi-profile |
| 186 // is supported. | 181 // is supported. |
| 187 extensions::EventRouter* router = | 182 extensions::EventRouter* router = |
| 188 extensions::EventRouter::Get(browser_context()); | 183 extensions::EventRouter::Get(browser_context()); |
| 189 | 184 |
| 190 if (!router->HasEventListener( | 185 if (!router->HasEventListener( |
| 191 virtual_keyboard_private::OnTextInputBoxFocused::kEventName)) { | 186 virtual_keyboard_private::OnTextInputBoxFocused::kEventName)) { |
| 192 return; | 187 return; |
| 193 } | 188 } |
| 194 | 189 |
| 195 scoped_ptr<base::ListValue> event_args(new base::ListValue()); | 190 scoped_ptr<base::ListValue> event_args(new base::ListValue()); |
| 196 scoped_ptr<base::DictionaryValue> input_context(new base::DictionaryValue()); | 191 scoped_ptr<base::DictionaryValue> input_context(new base::DictionaryValue()); |
| 197 input_context->SetString("type", | 192 input_context->SetString("type", |
| 198 virtual_keyboard_private::ToString( | 193 virtual_keyboard_private::ToString( |
| 199 TextInputTypeToGeneratedInputTypeEnum(type))); | 194 TextInputTypeToGeneratedInputTypeEnum(type))); |
| 200 event_args->Append(input_context.release()); | 195 event_args->Append(input_context.release()); |
| 201 | 196 |
| 202 scoped_ptr<extensions::Event> event(new extensions::Event( | 197 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 203 extensions::events::VIRTUAL_KEYBOARD_PRIVATE_ON_TEXT_INPUT_BOX_FOCUSED, | 198 extensions::events::VIRTUAL_KEYBOARD_PRIVATE_ON_TEXT_INPUT_BOX_FOCUSED, |
| 204 virtual_keyboard_private::OnTextInputBoxFocused::kEventName, | 199 virtual_keyboard_private::OnTextInputBoxFocused::kEventName, |
| 205 event_args.Pass())); | 200 event_args.Pass())); |
| 206 event->restrict_to_browser_context = browser_context(); | 201 event->restrict_to_browser_context = browser_context(); |
| 207 router->DispatchEventToExtension(kVirtualKeyboardExtensionID, event.Pass()); | 202 router->DispatchEventToExtension(kVirtualKeyboardExtensionID, event.Pass()); |
| 208 } | 203 } |
| OLD | NEW |