This source file includes following definitions.
- CloseOpenAshBrowsers
- OpenURL
- OnChannelError
- OnChannelConnected
- OnSetTargetSurface
- OnOpenURL
- OnHandleSearchRequest
- OnWindowSizeChanged
#include "chrome/browser/metro_viewer/chrome_metro_viewer_process_host_aurawin.h"
#include "ash/display/display_info.h"
#include "ash/display/display_manager.h"
#include "ash/shell.h"
#include "ash/wm/window_positioner.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part_aurawin.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/search_engines/util.h"
#include "chrome/browser/ui/ash/ash_init.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/env_vars.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/web_contents.h"
#include "ui/aura/remote_window_tree_host_win.h"
#include "ui/gfx/win/dpi.h"
#include "url/gurl.h"
namespace {
void CloseOpenAshBrowsers() {
BrowserList* browser_list =
BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
if (browser_list) {
for (BrowserList::const_iterator i = browser_list->begin();
i != browser_list->end(); ++i) {
Browser* browser = *i;
browser->window()->Close();
while (browser->tab_strip_model()->count())
delete browser->tab_strip_model()->GetWebContentsAt(0);
}
}
}
void OpenURL(const GURL& url) {
chrome::NavigateParams params(
ProfileManager::GetActiveUserProfile(),
GURL(url),
content::PAGE_TRANSITION_TYPED);
params.disposition = NEW_FOREGROUND_TAB;
params.host_desktop_type = chrome::HOST_DESKTOP_TYPE_ASH;
chrome::Navigate(¶ms);
}
}
ChromeMetroViewerProcessHost::ChromeMetroViewerProcessHost()
: MetroViewerProcessHost(
content::BrowserThread::GetMessageLoopProxyForThread(
content::BrowserThread::IO)) {
g_browser_process->AddRefModule();
}
void ChromeMetroViewerProcessHost::OnChannelError() {
DVLOG(1) << "viewer channel error : Quitting browser";
::SetEnvironmentVariableA(env_vars::kMetroConnected, NULL);
aura::RemoteWindowTreeHostWin::Instance()->Disconnected();
g_browser_process->ReleaseModule();
if (!browser_shutdown::IsTryingToQuit()) {
CloseOpenAshBrowsers();
chrome::CloseAsh();
}
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_ASH_SESSION_ENDED,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
g_browser_process->platform_part()->OnMetroViewerProcessTerminated();
}
void ChromeMetroViewerProcessHost::OnChannelConnected(int32 ) {
DVLOG(1) << "ChromeMetroViewerProcessHost::OnChannelConnected: ";
::SetEnvironmentVariableA(env_vars::kMetroConnected, "1");
if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) {
DVLOG(1) << "No GPU access, attempting to restart in Desktop\n";
chrome::AttemptRestartToDesktopMode();
}
}
void ChromeMetroViewerProcessHost::OnSetTargetSurface(
gfx::NativeViewId target_surface) {
HWND hwnd = reinterpret_cast<HWND>(target_surface);
aura::RemoteWindowTreeHostWin::Instance()->SetRemoteWindowHandle(hwnd);
chrome::OpenAsh();
ash::Shell::GetInstance()->CreateShelf();
ash::Shell::GetInstance()->ShowShelf();
aura::RemoteWindowTreeHostWin::Instance()->Connected(this);
ash::WindowPositioner::SetMaximizeFirstWindow(true);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_ASH_SESSION_STARTED,
content::NotificationService::AllSources(),
content::NotificationService::NoDetails());
}
void ChromeMetroViewerProcessHost::OnOpenURL(const base::string16& url) {
OpenURL(GURL(url));
}
void ChromeMetroViewerProcessHost::OnHandleSearchRequest(
const base::string16& search_string) {
GURL url(GetDefaultSearchURLForSearchTerms(
ProfileManager::GetActiveUserProfile(), search_string));
if (url.is_valid())
OpenURL(url);
}
void ChromeMetroViewerProcessHost::OnWindowSizeChanged(uint32 width,
uint32 height) {
std::vector<ash::DisplayInfo> info_list;
info_list.push_back(ash::DisplayInfo::CreateFromSpec(
base::StringPrintf("%dx%d*%f", width, height, gfx::GetModernUIScale())));
ash::Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(
info_list);
aura::RemoteWindowTreeHostWin::Instance()->HandleWindowSizeChanged(width,
height);
}