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