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. 4 5 #include "ui/keyboard/keyboard_controller_proxy.h" 6 7 #include "content/public/browser/site_instance.h" 8 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents_delegate.h" 10 #include "content/public/browser/web_contents_observer.h" 11 #include "content/public/browser/web_contents_view.h" 12 #include "ui/aura/window.h" 13 #include "ui/keyboard/keyboard_constants.h" 14 15 namespace { 16 17 // The WebContentsDelegate for the keyboard. 18 // The delegate deletes itself when the keyboard is destroyed. 19 class KeyboardContentsDelegate : public content::WebContentsDelegate, 20 public content::WebContentsObserver { 21 public: 22 KeyboardContentsDelegate(keyboard::KeyboardControllerProxy* proxy) 23 : proxy_(proxy) {} 24 virtual ~KeyboardContentsDelegate() {} 25 26 private: 27 // Overridden from content::WebContentsDelegate: 28 virtual content::WebContents* OpenURLFromTab( 29 content::WebContents* source, 30 const content::OpenURLParams& params) OVERRIDE { 31 source->GetController().LoadURL( 32 params.url, params.referrer, params.transition, params.extra_headers); 33 Observe(source); 34 return source; 35 } 36 37 // Overridden from content::WebContentsDelegate: 38 virtual void RequestMediaAccessPermission(content::WebContents* web_contents, 39 const content::MediaStreamRequest& request, 40 const content::MediaResponseCallback& callback) OVERRIDE { 41 proxy_->RequestAudioInput(web_contents, request, callback); 42 } 43 44 45 // Overridden from content::WebContentsObserver: 46 virtual void WebContentsDestroyed(content::WebContents* contents) OVERRIDE { 47 delete this; 48 } 49 50 keyboard::KeyboardControllerProxy* proxy_; 51 52 DISALLOW_COPY_AND_ASSIGN(KeyboardContentsDelegate); 53 }; 54 55 } // namespace 56 57 namespace keyboard { 58 59 KeyboardControllerProxy::KeyboardControllerProxy() { 60 } 61 62 KeyboardControllerProxy::~KeyboardControllerProxy() { 63 } 64 65 aura::Window* KeyboardControllerProxy::GetKeyboardWindow() { 66 if (!keyboard_contents_) { 67 content::BrowserContext* context = GetBrowserContext(); 68 GURL url(kKeyboardWebUIURL); 69 keyboard_contents_.reset(content::WebContents::Create( 70 content::WebContents::CreateParams(context, 71 content::SiteInstance::CreateForURL(context, url)))); 72 keyboard_contents_->SetDelegate(new KeyboardContentsDelegate(this)); 73 SetupWebContents(keyboard_contents_.get()); 74 75 content::OpenURLParams params(url, 76 content::Referrer(), 77 SINGLETON_TAB, 78 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 79 false); 80 keyboard_contents_->OpenURL(params); 81 } 82 83 return keyboard_contents_->GetView()->GetNativeView(); 84 } 85 86 void KeyboardControllerProxy::ShowKeyboardContainer(aura::Window* container) { 87 container->Show(); 88 } 89 90 void KeyboardControllerProxy::HideKeyboardContainer(aura::Window* container) { 91 container->Hide(); 92 } 93 94 void KeyboardControllerProxy::SetupWebContents(content::WebContents* contents) { 95 } 96 97 } // namespace keyboard 98