| OLD | NEW |
| 1 // Copyright (c) 2012 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 "ash/shell/content_client/shell_browser_main_parts.h" | 5 #include "wm/shell/content_client/shell_browser_main_parts.h" |
| 6 | 6 |
| 7 #include "ash/desktop_background/desktop_background_controller.h" | 7 #include "ash/desktop_background/desktop_background_controller.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell/shell_delegate_impl.h" | |
| 10 #include "ash/shell/window_watcher.h" | 9 #include "ash/shell/window_watcher.h" |
| 11 #include "base/bind.h" | |
| 12 #include "base/command_line.h" | |
| 13 #include "base/i18n/icu_util.h" | |
| 14 #include "base/message_loop.h" | |
| 15 #include "base/string_number_conversions.h" | |
| 16 #include "base/threading/thread.h" | |
| 17 #include "base/threading/thread_restrictions.h" | |
| 18 #include "content/public/common/content_switches.h" | |
| 19 #include "content/shell/shell_browser_context.h" | 10 #include "content/shell/shell_browser_context.h" |
| 20 #include "googleurl/src/gurl.h" | |
| 21 #include "net/base/net_module.h" | |
| 22 #include "ui/aura/client/stacking_client.h" | |
| 23 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
| 24 #include "ui/aura/root_window.h" | 12 #include "ui/aura/root_window.h" |
| 25 #include "ui/aura/window.h" | |
| 26 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/base/ui_base_paths.h" | |
| 28 #include "ui/compositor/compositor.h" | |
| 29 #include "ui/compositor/test/compositor_test_support.h" | |
| 30 #include "ui/gfx/screen.h" | |
| 31 #include "ui/views/focus/accelerator_handler.h" | |
| 32 #include "ui/views/test/test_views_delegate.h" | 14 #include "ui/views/test/test_views_delegate.h" |
| 15 #include "wm/foreign_test_window.h" |
| 16 #include "wm/gpu/foreign_window_texture_factory.h" |
| 17 #include "wm/shell/shell_delegate_impl.h" |
| 33 | 18 |
| 34 #if defined(OS_LINUX) | 19 #if defined(OS_LINUX) |
| 35 #include "ui/base/touch/touch_factory.h" | 20 #include "ui/base/touch/touch_factory.h" |
| 36 #endif | 21 #endif |
| 37 | 22 |
| 38 #if defined(OS_CHROMEOS) | 23 #if defined(OS_CHROMEOS) |
| 39 #include "chromeos/dbus/dbus_thread_manager.h" | 24 #include "chromeos/dbus/dbus_thread_manager.h" |
| 40 #endif | 25 #endif |
| 41 | 26 |
| 42 namespace ash { | 27 namespace ash { |
| 43 namespace shell { | 28 namespace shell { |
| 44 void InitWindowTypeLauncher(); | 29 void InitWindowTypeLauncher(); |
| 30 } // namespace shell |
| 31 } // namespace ash |
| 32 |
| 33 namespace wm { |
| 34 namespace shell { |
| 45 | 35 |
| 46 namespace { | 36 namespace { |
| 47 class ShellViewsDelegate : public views::TestViewsDelegate { | 37 class ShellViewsDelegate : public views::TestViewsDelegate { |
| 48 public: | 38 public: |
| 49 ShellViewsDelegate() {} | 39 ShellViewsDelegate() {} |
| 50 virtual ~ShellViewsDelegate() {} | 40 virtual ~ShellViewsDelegate() {} |
| 51 | 41 |
| 52 // Overridden from views::TestViewsDelegate: | 42 // Overridden from views::TestViewsDelegate: |
| 53 virtual views::NonClientFrameView* CreateDefaultNonClientFrameView( | 43 virtual views::NonClientFrameView* CreateDefaultNonClientFrameView( |
| 54 views::Widget* widget) OVERRIDE { | 44 views::Widget* widget) OVERRIDE { |
| 55 return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(widget); | 45 return ash::Shell::GetInstance()->CreateDefaultNonClientFrameView(widget); |
| 56 } | 46 } |
| 57 virtual bool UseTransparentWindows() const OVERRIDE { | 47 bool UseTransparentWindows() const OVERRIDE { |
| 58 // Ash uses transparent window frames. | 48 // Ash uses transparent window frames. |
| 59 return true; | 49 return true; |
| 60 } | 50 } |
| 61 virtual void OnBeforeWidgetInit( | |
| 62 views::Widget::InitParams* params, | |
| 63 views::internal::NativeWidgetDelegate* delegate) OVERRIDE { | |
| 64 if (params->native_widget) | |
| 65 return; | |
| 66 | |
| 67 if (!params->parent && !params->context && params->top_level) | |
| 68 params->context = Shell::GetPrimaryRootWindow(); | |
| 69 } | |
| 70 | 51 |
| 71 private: | 52 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegate); | 53 DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegate); |
| 73 }; | 54 }; |
| 74 | 55 |
| 75 } // namespace | 56 } // namespace |
| 76 | 57 |
| 77 ShellBrowserMainParts::ShellBrowserMainParts( | 58 ShellBrowserMainParts::ShellBrowserMainParts( |
| 78 const content::MainFunctionParams& parameters) | 59 const content::MainFunctionParams& parameters) |
| 79 : BrowserMainParts(), | 60 : BrowserMainParts() { |
| 80 delegate_(NULL) { | |
| 81 } | 61 } |
| 82 | 62 |
| 83 ShellBrowserMainParts::~ShellBrowserMainParts() { | 63 ShellBrowserMainParts::~ShellBrowserMainParts() { |
| 84 } | 64 } |
| 85 | 65 |
| 86 #if !defined(OS_MACOSX) | |
| 87 void ShellBrowserMainParts::PreMainMessageLoopStart() { | 66 void ShellBrowserMainParts::PreMainMessageLoopStart() { |
| 88 #if defined(OS_LINUX) | 67 #if defined(OS_LINUX) |
| 89 ui::TouchFactory::SetTouchDeviceListFromCommandLine(); | 68 ui::TouchFactory::SetTouchDeviceListFromCommandLine(); |
| 90 #endif | 69 #endif |
| 91 } | 70 } |
| 92 #endif | |
| 93 | 71 |
| 94 void ShellBrowserMainParts::PostMainMessageLoopStart() { | 72 void ShellBrowserMainParts::PostMainMessageLoopStart() { |
| 95 #if defined(OS_CHROMEOS) | 73 #if defined(OS_CHROMEOS) |
| 96 chromeos::DBusThreadManager::Initialize(); | 74 chromeos::DBusThreadManager::Initialize(); |
| 97 #endif | 75 #endif |
| 98 } | 76 } |
| 99 | 77 |
| 100 void ShellBrowserMainParts::PreMainMessageLoopRun() { | 78 void ShellBrowserMainParts::PreMainMessageLoopRun() { |
| 79 ForeignWindowTextureFactory::Initialize(); |
| 80 |
| 101 browser_context_.reset(new content::ShellBrowserContext(false)); | 81 browser_context_.reset(new content::ShellBrowserContext(false)); |
| 102 | 82 |
| 103 // A ViewsDelegate is required. | 83 // A ViewsDelegate is required. |
| 104 if (!views::ViewsDelegate::views_delegate) | 84 if (!views::ViewsDelegate::views_delegate) |
| 105 views::ViewsDelegate::views_delegate = new ShellViewsDelegate; | 85 views::ViewsDelegate::views_delegate = new ShellViewsDelegate; |
| 106 | 86 |
| 107 delegate_ = new ash::shell::ShellDelegateImpl; | 87 wm::shell::ShellDelegateImpl* delegate = new wm::shell::ShellDelegateImpl; |
| 108 ash::Shell::CreateInstance(delegate_); | 88 ash::Shell::CreateInstance(delegate); |
| 109 ash::Shell::GetInstance()->set_browser_context(browser_context_.get()); | 89 ash::Shell::GetInstance()->set_browser_context(browser_context_.get()); |
| 110 | 90 |
| 111 window_watcher_.reset(new ash::shell::WindowWatcher); | 91 window_watcher_.reset(new ash::shell::WindowWatcher); |
| 112 gfx::Screen* screen = Shell::GetInstance()->GetScreen(); | 92 delegate->SetWatcher(window_watcher_.get()); |
| 113 screen->AddObserver(window_watcher_.get()); | |
| 114 delegate_->SetWatcher(window_watcher_.get()); | |
| 115 | 93 |
| 116 ash::shell::InitWindowTypeLauncher(); | 94 ash::shell::InitWindowTypeLauncher(); |
| 117 | 95 |
| 118 DesktopBackgroundController* controller = | 96 ash::DesktopBackgroundController* controller = |
| 119 Shell::GetInstance()->desktop_background_controller(); | 97 ash::Shell::GetInstance()->desktop_background_controller(); |
| 120 if (controller->GetAppropriateResolution() == WALLPAPER_RESOLUTION_LARGE) | 98 if (controller->GetAppropriateResolution() == ash::WALLPAPER_RESOLUTION_LARGE) |
| 121 controller->SetDefaultWallpaper(kDefaultLargeWallpaper); | 99 controller->SetDefaultWallpaper(ash::kDefaultLargeWallpaper); |
| 122 else | 100 else |
| 123 controller->SetDefaultWallpaper(kDefaultSmallWallpaper); | 101 controller->SetDefaultWallpaper(ash::kDefaultSmallWallpaper); |
| 102 |
| 103 ForeignTestWindow::CreateParams params( |
| 104 ash::Shell::GetPrimaryRootWindow()->GetAcceleratedWidget()); |
| 105 foreign_test_window_.reset(new ForeignTestWindow(params)); |
| 106 foreign_test_window_->Show(); |
| 124 | 107 |
| 125 ash::Shell::GetPrimaryRootWindow()->ShowRootWindow(); | 108 ash::Shell::GetPrimaryRootWindow()->ShowRootWindow(); |
| 126 } | 109 } |
| 127 | 110 |
| 128 void ShellBrowserMainParts::PostMainMessageLoopRun() { | 111 void ShellBrowserMainParts::PostMainMessageLoopRun() { |
| 129 browser_context_.reset(); | 112 browser_context_.reset(); |
| 130 gfx::Screen* screen = Shell::GetInstance()->GetScreen(); | |
| 131 screen->RemoveObserver(window_watcher_.get()); | |
| 132 | |
| 133 window_watcher_.reset(); | 113 window_watcher_.reset(); |
| 134 delegate_->SetWatcher(NULL); | |
| 135 delegate_ = NULL; | |
| 136 ash::Shell::DeleteInstance(); | 114 ash::Shell::DeleteInstance(); |
| 137 aura::Env::DeleteInstance(); | 115 aura::Env::DeleteInstance(); |
| 116 ForeignWindowTextureFactory::Terminate(); |
| 138 } | 117 } |
| 139 | 118 |
| 140 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { | 119 bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { |
| 141 MessageLoopForUI::current()->Run(); | 120 MessageLoopForUI::current()->Run(); |
| 142 return true; | 121 return true; |
| 143 } | 122 } |
| 144 | 123 |
| 145 } // namespace shell | 124 } // namespace shell |
| 146 } // namespace ash | 125 } // namespace wm |
| OLD | NEW |