OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 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 "chrome/browser/metro_viewer/chrome_metro_viewer_process_host_aurawin.h
" |
| 6 |
| 7 #include "ash/display/display_info.h" |
| 8 #include "ash/display/display_manager.h" |
| 9 #include "ash/host/ash_remote_window_tree_host_win.h" |
| 10 #include "ash/shell.h" |
| 11 #include "ash/wm/window_positioner.h" |
| 12 #include "base/logging.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/strings/stringprintf.h" |
| 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/browser_process_platform_part_aurawin.h" |
| 17 #include "chrome/browser/browser_shutdown.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/lifetime/application_lifetime.h" |
| 20 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 22 #include "chrome/browser/ui/ash/ash_init.h" |
| 23 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_list.h" |
| 25 #include "chrome/browser/ui/browser_navigator.h" |
| 26 #include "chrome/browser/ui/browser_navigator_params.h" |
| 27 #include "chrome/browser/ui/browser_window.h" |
| 28 #include "chrome/browser/ui/host_desktop.h" |
| 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 30 #include "chrome/common/env_vars.h" |
| 31 #include "components/search_engines/util.h" |
| 32 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/gpu_data_manager.h" |
| 34 #include "content/public/browser/notification_service.h" |
| 35 #include "content/public/browser/page_navigator.h" |
| 36 #include "content/public/browser/web_contents.h" |
| 37 #include "ui/aura/remote_window_tree_host_win.h" |
| 38 #include "ui/gfx/win/dpi.h" |
| 39 #include "ui/metro_viewer/metro_viewer_messages.h" |
| 40 #include "url/gurl.h" |
| 41 |
| 42 namespace { |
| 43 |
| 44 void CloseOpenAshBrowsers() { |
| 45 BrowserList* browser_list = |
| 46 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
| 47 if (browser_list) { |
| 48 for (BrowserList::const_iterator i = browser_list->begin(); |
| 49 i != browser_list->end(); ++i) { |
| 50 Browser* browser = *i; |
| 51 browser->window()->Close(); |
| 52 // If the attempt to Close the browser fails due to unload handlers on |
| 53 // the page or in progress downloads, etc, destroy all tabs on the page. |
| 54 while (browser->tab_strip_model()->count()) |
| 55 delete browser->tab_strip_model()->GetWebContentsAt(0); |
| 56 } |
| 57 } |
| 58 } |
| 59 |
| 60 void OpenURL(const GURL& url) { |
| 61 chrome::NavigateParams params( |
| 62 ProfileManager::GetActiveUserProfile(), |
| 63 GURL(url), |
| 64 ui::PAGE_TRANSITION_TYPED); |
| 65 params.disposition = NEW_FOREGROUND_TAB; |
| 66 params.host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH; |
| 67 chrome::Navigate(¶ms); |
| 68 } |
| 69 |
| 70 } // namespace |
| 71 |
| 72 ChromeMetroViewerProcessHost::ChromeMetroViewerProcessHost() |
| 73 : MetroViewerProcessHost( |
| 74 content::BrowserThread::GetMessageLoopProxyForThread( |
| 75 content::BrowserThread::IO)) { |
| 76 chrome::IncrementKeepAliveCount(); |
| 77 } |
| 78 |
| 79 ChromeMetroViewerProcessHost::~ChromeMetroViewerProcessHost() { |
| 80 } |
| 81 |
| 82 void ChromeMetroViewerProcessHost::OnChannelError() { |
| 83 // TODO(cpu): At some point we only close the browser. Right now this |
| 84 // is very convenient for developing. |
| 85 DVLOG(1) << "viewer channel error : Quitting browser"; |
| 86 |
| 87 // Unset environment variable to let breakpad know that metro process wasn't |
| 88 // connected. |
| 89 ::SetEnvironmentVariableA(env_vars::kMetroConnected, NULL); |
| 90 |
| 91 // It seems possible that channel is connected, but ASH desktop is not yet |
| 92 // created (instance is still NULL) and we receive channel error. |
| 93 if (aura::RemoteWindowTreeHostWin::Instance()) { |
| 94 aura::RemoteWindowTreeHostWin::Instance()->Disconnected(); |
| 95 |
| 96 chrome::DecrementKeepAliveCount(); |
| 97 |
| 98 // If browser is trying to quit, we shouldn't reenter the process. |
| 99 // TODO(shrikant): In general there seem to be issues with how AttemptExit |
| 100 // reentry works. In future release please clean up related code. |
| 101 if (!browser_shutdown::IsTryingToQuit()) { |
| 102 CloseOpenAshBrowsers(); |
| 103 chrome::CloseAsh(); |
| 104 } |
| 105 // Tell the rest of Chrome about it. |
| 106 content::NotificationService::current()->Notify( |
| 107 chrome::NOTIFICATION_ASH_SESSION_ENDED, |
| 108 content::NotificationService::AllSources(), |
| 109 content::NotificationService::NoDetails()); |
| 110 return; |
| 111 } |
| 112 |
| 113 chrome::DecrementKeepAliveCount(); |
| 114 |
| 115 // This will delete the MetroViewerProcessHost object. Don't access member |
| 116 // variables/functions after this call. |
| 117 g_browser_process->platform_part()->OnMetroViewerProcessTerminated(); |
| 118 } |
| 119 |
| 120 void ChromeMetroViewerProcessHost::OnChannelConnected(int32_t /*peer_pid*/) { |
| 121 DVLOG(1) << "ChromeMetroViewerProcessHost::OnChannelConnected: "; |
| 122 // Set environment variable to let breakpad know that metro process was |
| 123 // connected. |
| 124 ::SetEnvironmentVariableA(env_vars::kMetroConnected, "1"); |
| 125 } |
| 126 |
| 127 void ChromeMetroViewerProcessHost::OnSetTargetSurface( |
| 128 gfx::NativeViewId target_surface, |
| 129 float device_scale) { |
| 130 HWND hwnd = reinterpret_cast<HWND>(target_surface); |
| 131 |
| 132 gfx::SetDefaultDeviceScaleFactor(device_scale); |
| 133 chrome::OpenAsh(hwnd); |
| 134 DCHECK(aura::RemoteWindowTreeHostWin::Instance()); |
| 135 DCHECK_EQ(hwnd, aura::RemoteWindowTreeHostWin::Instance()->remote_window()); |
| 136 ash::Shell::GetInstance()->CreateShelf(); |
| 137 ash::Shell::GetInstance()->ShowShelf(); |
| 138 |
| 139 // Tell our root window host that the viewer has connected. |
| 140 aura::RemoteWindowTreeHostWin::Instance()->Connected(this); |
| 141 |
| 142 // On Windows 8 ASH we default to SHOW_STATE_MAXIMIZED for the browser |
| 143 // window. This is to ensure that we honor metro app conventions by default. |
| 144 ash::WindowPositioner::SetMaximizeFirstWindow(true); |
| 145 // Tell the rest of Chrome that Ash is running. |
| 146 content::NotificationService::current()->Notify( |
| 147 chrome::NOTIFICATION_ASH_SESSION_STARTED, |
| 148 content::NotificationService::AllSources(), |
| 149 content::NotificationService::NoDetails()); |
| 150 } |
| 151 |
| 152 void ChromeMetroViewerProcessHost::OnOpenURL(const base::string16& url) { |
| 153 OpenURL(GURL(url)); |
| 154 } |
| 155 |
| 156 void ChromeMetroViewerProcessHost::OnHandleSearchRequest( |
| 157 const base::string16& search_string) { |
| 158 GURL url(GetDefaultSearchURLForSearchTerms( |
| 159 TemplateURLServiceFactory::GetForProfile( |
| 160 ProfileManager::GetActiveUserProfile()), search_string)); |
| 161 if (url.is_valid()) |
| 162 OpenURL(url); |
| 163 } |
| 164 |
| 165 void ChromeMetroViewerProcessHost::OnWindowSizeChanged(uint32_t width, |
| 166 uint32_t height) { |
| 167 std::vector<ash::DisplayInfo> info_list; |
| 168 info_list.push_back(ash::DisplayInfo::CreateFromSpec( |
| 169 base::StringPrintf("%dx%d*%f", width, height, gfx::GetDPIScale()))); |
| 170 ash::Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged( |
| 171 info_list); |
| 172 aura::RemoteWindowTreeHostWin::Instance()->HandleWindowSizeChanged(width, |
| 173 height); |
| 174 } |
OLD | NEW |