1 // Copyright 2014 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 "content/public/browser/context_factory.h" 6 #include "content/shell/browser/shell_browser_context.h" 7 #include "ui/aura/test/test_screen.h" 8 #include "ui/aura/window.h" 9 #include "ui/gfx/screen.h" 10 #include "ui/views_content_client/views_content_client.h" 11 #include "ui/views_content_client/views_content_client_main_parts_aura.h" 12 #include "ui/wm/core/nested_accelerator_controller.h" 13 #include "ui/wm/core/nested_accelerator_delegate.h" 14 #include "ui/wm/test/wm_test_helper.h" 15 16 namespace ui { 17 18 namespace { 19 20 // A dummy version of the delegate usually provided by the Ash Shell. 21 class NestedAcceleratorDelegate : public ::wm::NestedAcceleratorDelegate { 22 public: 23 NestedAcceleratorDelegate() {} 24 virtual ~NestedAcceleratorDelegate() {} 25 26 // ::wm::NestedAcceleratorDelegate: 27 virtual Result ProcessAccelerator( 28 const ui::Accelerator& accelerator) OVERRIDE { 29 return RESULT_NOT_PROCESSED; 30 } 31 32 private: 33 DISALLOW_COPY_AND_ASSIGN(NestedAcceleratorDelegate); 34 }; 35 36 class ViewsContentClientMainPartsChromeOS 37 : public ViewsContentClientMainPartsAura { 38 public: 39 ViewsContentClientMainPartsChromeOS( 40 const content::MainFunctionParams& content_params, 41 ViewsContentClient* views_content_client); 42 virtual ~ViewsContentClientMainPartsChromeOS() {} 43 44 // content::BrowserMainParts: 45 virtual void PreMainMessageLoopRun() OVERRIDE; 46 virtual void PostMainMessageLoopRun() OVERRIDE; 47 48 private: 49 // Enable a minimal set of views::corewm to be initialized. 50 scoped_ptr<gfx::Screen> test_screen_; 51 scoped_ptr< ::wm::WMTestHelper> wm_test_helper_; 52 scoped_ptr< ::wm::NestedAcceleratorController> nested_accelerator_controller_; 53 54 DISALLOW_COPY_AND_ASSIGN(ViewsContentClientMainPartsChromeOS); 55 }; 56 57 ViewsContentClientMainPartsChromeOS::ViewsContentClientMainPartsChromeOS( 58 const content::MainFunctionParams& content_params, 59 ViewsContentClient* views_content_client) 60 : ViewsContentClientMainPartsAura(content_params, views_content_client) { 61 } 62 63 void ViewsContentClientMainPartsChromeOS::PreMainMessageLoopRun() { 64 ViewsContentClientMainPartsAura::PreMainMessageLoopRun(); 65 66 gfx::Size host_size(800, 600); 67 test_screen_.reset(aura::TestScreen::Create(host_size)); 68 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); 69 // Set up basic pieces of views::corewm. 70 wm_test_helper_.reset( 71 new ::wm::WMTestHelper(host_size, content::GetContextFactory())); 72 // Ensure the X window gets mapped. 73 wm_test_helper_->host()->Show(); 74 75 // Ensure Aura knows where to open new windows. 76 aura::Window* root_window = wm_test_helper_->host()->window(); 77 views_content_client()->task().Run(browser_context(), root_window); 78 79 nested_accelerator_controller_.reset( 80 new ::wm::NestedAcceleratorController(new NestedAcceleratorDelegate)); 81 aura::client::SetDispatcherClient(root_window, 82 nested_accelerator_controller_.get()); 83 } 84 85 void ViewsContentClientMainPartsChromeOS::PostMainMessageLoopRun() { 86 aura::client::SetDispatcherClient(wm_test_helper_->host()->window(), NULL); 87 nested_accelerator_controller_.reset(); 88 wm_test_helper_.reset(); 89 test_screen_.reset(); 90 91 ViewsContentClientMainPartsAura::PostMainMessageLoopRun(); 92 } 93 94 } // namespace 95 96 // static 97 ViewsContentClientMainParts* ViewsContentClientMainParts::Create( 98 const content::MainFunctionParams& content_params, 99 ViewsContentClient* views_content_client) { 100 return new ViewsContentClientMainPartsChromeOS( 101 content_params, views_content_client); 102 } 103 104 } // namespace ui 105