diff options
20 files changed, 292 insertions, 83 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 934e528..92a4707 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -686,8 +686,10 @@ void BrowserProcessImpl::RegisterPrefs(PrefRegistrySimple* registry) { registry->RegisterBooleanPref(prefs::kEulaAccepted, false); #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) || defined(OS_IOS) #if defined(OS_WIN) - if (base::win::GetVersion() >= base::win::VERSION_WIN8) - registry->RegisterBooleanPref(prefs::kRestartSwitchMode, false); + if (base::win::GetVersion() >= base::win::VERSION_WIN8) { + registry->RegisterStringPref(prefs::kRelaunchMode, + upgrade_util::kRelaunchModeDefault); + } #endif // TODO(brettw,*): this comment about ResourceBundle was here since diff --git a/chrome/browser/browser_shutdown.cc b/chrome/browser/browser_shutdown.cc index a315c93..0169746 100644 --- a/chrome/browser/browser_shutdown.cc +++ b/chrome/browser/browser_shutdown.cc @@ -64,9 +64,8 @@ bool g_trying_to_quit = false; bool g_shutting_down_without_closing_browsers = false; #if defined(OS_WIN) -// Whether the next restart should happen in the opposite mode; desktop or -// metro mode. Windows 8 only. -bool g_mode_switch = false; +upgrade_util::RelaunchMode g_relaunch_mode = + upgrade_util::RELAUNCH_MODE_DEFAULT; #endif Time* shutdown_started_ = NULL; @@ -159,9 +158,10 @@ bool ShutdownPreThreadsStop() { prefs->ClearPref(prefs::kRestartLastSessionOnShutdown); #if defined(OS_WIN) if (restart_last_session) { - if (prefs->HasPrefPath(prefs::kRestartSwitchMode)) { - g_mode_switch = prefs->GetBoolean(prefs::kRestartSwitchMode); - prefs->SetBoolean(prefs::kRestartSwitchMode, false); + if (prefs->HasPrefPath(prefs::kRelaunchMode)) { + g_relaunch_mode = upgrade_util::RelaunchModeStringToEnum( + prefs->GetString(prefs::kRelaunchMode)); + prefs->ClearPref(prefs::kRelaunchMode); } } #endif @@ -230,11 +230,7 @@ void ShutdownPostThreadsStop(bool restart_last_session) { } #if defined(OS_WIN) - // On Windows 8 we can relaunch in metro or desktop mode. - if (g_mode_switch) - upgrade_util::RelaunchChromeWithModeSwitch(*new_cl.get()); - else - upgrade_util::RelaunchChromeBrowser(*new_cl.get()); + upgrade_util::RelaunchChromeWithMode(*new_cl.get(), g_relaunch_mode); #else upgrade_util::RelaunchChromeBrowser(*new_cl.get()); #endif // defined(OS_WIN) diff --git a/chrome/browser/first_run/upgrade_util.h b/chrome/browser/first_run/upgrade_util.h index d2ecd3b..ec8a1ce 100644 --- a/chrome/browser/first_run/upgrade_util.h +++ b/chrome/browser/first_run/upgrade_util.h @@ -7,6 +7,10 @@ #include "build/build_config.h" +#if defined(OS_WIN) +#include <string> +#endif + #if !defined(OS_CHROMEOS) class CommandLine; @@ -19,9 +23,25 @@ bool RelaunchChromeBrowser(const CommandLine& command_line); #if defined(OS_WIN) -// Like RelaunchChromeBrowser() but for Windows 8 if chrome is in desktop mode -// it launches chrome in metro mode, and vice-versa. -bool RelaunchChromeWithModeSwitch(const CommandLine& command_line); +extern const char kRelaunchModeMetro[]; +extern const char kRelaunchModeDesktop[]; +extern const char kRelaunchModeDefault[]; + +enum RelaunchMode { + RELAUNCH_MODE_METRO = 0, + RELAUNCH_MODE_DESKTOP = 1, + // Default mode indicates caller is not sure which mode to launch. + RELAUNCH_MODE_DEFAULT = 2, +}; + +std::string RelaunchModeEnumToString(const RelaunchMode& relaunch_mode); + +RelaunchMode RelaunchModeStringToEnum(const std::string& relaunch_mode); + +// Like RelaunchChromeBrowser() but for Windows 8 it will read pref and restart +// chrome accordingly in desktop or metro mode. +bool RelaunchChromeWithMode(const CommandLine& command_line, + const RelaunchMode& relaunch_mode); #endif diff --git a/chrome/browser/first_run/upgrade_util_win.cc b/chrome/browser/first_run/upgrade_util_win.cc index 5361146..729bfcb 100644 --- a/chrome/browser/first_run/upgrade_util_win.cc +++ b/chrome/browser/first_run/upgrade_util_win.cc @@ -85,7 +85,35 @@ base::FilePath GetMetroRelauncherPath(const base::FilePath& chrome_exe, namespace upgrade_util { -bool RelaunchChromeHelper(const CommandLine& command_line, bool mode_switch) { +const char kRelaunchModeMetro[] = "relaunch.mode.metro"; +const char kRelaunchModeDesktop[] = "relaunch.mode.desktop"; +const char kRelaunchModeDefault[] = "relaunch.mode.default"; + +// TODO(shrikant): Have a map/array to quickly map enum to strings. +std::string RelaunchModeEnumToString(const RelaunchMode relaunch_mode) { + if (relaunch_mode == RELAUNCH_MODE_METRO) + return kRelaunchModeMetro; + + if (relaunch_mode == RELAUNCH_MODE_DESKTOP) + return kRelaunchModeDesktop; + + // For the purpose of code flow, even in case of wrong value we will + // return default re-launch mode. + return kRelaunchModeDefault; +} + +RelaunchMode RelaunchModeStringToEnum(const std::string& relaunch_mode) { + if (relaunch_mode == kRelaunchModeMetro) + return RELAUNCH_MODE_METRO; + + if (relaunch_mode == kRelaunchModeDesktop) + return RELAUNCH_MODE_DESKTOP; + + return RELAUNCH_MODE_DEFAULT; +} + +bool RelaunchChromeHelper(const CommandLine& command_line, + const RelaunchMode& relaunch_mode) { scoped_ptr<base::Environment> env(base::Environment::Create()); std::string version_str; @@ -133,9 +161,9 @@ bool RelaunchChromeHelper(const CommandLine& command_line, bool mode_switch) { ShellIntegration::GetStartMenuShortcut(chrome_exe)); relaunch_cmd.AppendSwitchNative(switches::kWaitForMutex, mutex_name); - if (mode_switch) { - relaunch_cmd.AppendSwitch(base::win::IsMetroProcess() ? - switches::kForceDesktop : switches::kForceImmersive); + if (relaunch_mode != RELAUNCH_MODE_DEFAULT) { + relaunch_cmd.AppendSwitch(relaunch_mode == RELAUNCH_MODE_METRO? + switches::kForceImmersive : switches::kForceDesktop); } string16 params(relaunch_cmd.GetCommandLineString()); @@ -164,11 +192,12 @@ bool RelaunchChromeHelper(const CommandLine& command_line, bool mode_switch) { } bool RelaunchChromeBrowser(const CommandLine& command_line) { - return RelaunchChromeHelper(command_line, false); + return RelaunchChromeHelper(command_line, RELAUNCH_MODE_DEFAULT); } -bool RelaunchChromeWithModeSwitch(const CommandLine& command_line) { - return RelaunchChromeHelper(command_line, true); +bool RelaunchChromeWithMode(const CommandLine& command_line, + const RelaunchMode& relaunch_mode) { + return RelaunchChromeHelper(command_line, relaunch_mode); } bool IsUpdatePendingRestart() { diff --git a/chrome/browser/lifetime/application_lifetime.cc b/chrome/browser/lifetime/application_lifetime.cc index a7a7df6..aad24b1 100644 --- a/chrome/browser/lifetime/application_lifetime.cc +++ b/chrome/browser/lifetime/application_lifetime.cc @@ -208,16 +208,6 @@ void AttemptRestart() { } #endif -#if defined(OS_WIN) -void AttemptRestartWithModeSwitch() { - // The kRestartSwitchMode preference does not exists for Windows 7 and older - // operating systems so there is no need for OS version check. - PrefService* prefs = g_browser_process->local_state(); - prefs->SetBoolean(prefs::kRestartSwitchMode, true); - AttemptRestart(); -} -#endif - void AttemptExit() { // If we know that all browsers can be closed without blocking, // don't notify users of crashes beyond this point. diff --git a/chrome/browser/lifetime/application_lifetime.h b/chrome/browser/lifetime/application_lifetime.h index 08afcd6..59c0d4a 100644 --- a/chrome/browser/lifetime/application_lifetime.h +++ b/chrome/browser/lifetime/application_lifetime.h @@ -33,6 +33,8 @@ void AttemptRestart(); // in desktop mode it starts in metro mode and vice-versa. The switching like // the restarting is controlled by a preference. void AttemptRestartWithModeSwitch(); +void AttemptRestartToDesktopMode(); +void AttemptRestartToMetroMode(); #endif // Attempt to exit by closing all browsers. This is equivalent to diff --git a/chrome/browser/lifetime/application_lifetime_win.cc b/chrome/browser/lifetime/application_lifetime_win.cc index 97e01fb..3f40a4a 100644 --- a/chrome/browser/lifetime/application_lifetime_win.cc +++ b/chrome/browser/lifetime/application_lifetime_win.cc @@ -4,12 +4,122 @@ #include "chrome/browser/lifetime/application_lifetime.h" +#include "base/bind.h" +#include "base/prefs/pref_service.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/first_run/upgrade_util.h" +#include "chrome/common/pref_names.h" +#include "content/public/browser/browser_thread.h" #include "ui/views/widget/widget.h" +#if defined(USE_AURA) +#include "base/environment.h" +#include "base/files/file_path.h" +#include "base/path_service.h" +#include "base/win/metro.h" +#include "chrome/browser/metro_utils/metro_chrome_win.h" +#include "chrome/browser/shell_integration.h" +#include "chrome/common/chrome_constants.h" +#include "chrome/installer/util/util_constants.h" +#include "content/public/browser/web_contents.h" +#include "ui/aura/remote_root_window_host_win.h" +#endif + namespace chrome { +#if !defined(USE_AURA) void HandleAppExitingForPlatform() { views::Widget::CloseAllSecondaryWidgets(); } +#endif + +// Following set of functions, which are used to switch chrome mode after +// restart are used for in places where either user explicitly wants to switch +// mode or some functionality is not available in either mode and we ask user +// to switch mode. +// Here mode refers to Windows 8 modes such as Metro (also called immersive) +// and desktop mode (Classic or traditional). + +// Mode switch based on current mode which is devised from current process. +void AttemptRestartWithModeSwitch() { +#if defined(USE_AURA) + // This function should be called only from non aura code path. + // In aura/ash windows world browser process is always non metro. + CHECK(false); + return; +#endif + // The kRestartSwitchMode preference does not exists for Windows 7 and older + // operating systems so there is no need for OS version check. + PrefService* prefs = g_browser_process->local_state(); + if (base::win::IsMetroProcess()) { + prefs->SetString(prefs::kRelaunchMode, + upgrade_util::kRelaunchModeDesktop); + } else { + prefs->SetString(prefs::kRelaunchMode, + upgrade_util::kRelaunchModeMetro); + } + AttemptRestart(); +} + +#if defined(USE_AURA) +void ActivateDesktopHelperReply() { + AttemptRestart(); +} + +void ActivateDesktopHelper() { + scoped_ptr<base::Environment> env(base::Environment::Create()); + std::string version_str; + + // Get the version variable and remove it from the environment. + if (env->GetVar(chrome::kChromeVersionEnvVar, &version_str)) + env->UnSetVar(chrome::kChromeVersionEnvVar); + else + version_str.clear(); + + base::FilePath exe_path; + if (!PathService::Get(base::FILE_EXE, &exe_path)) + return; + + base::FilePath path(exe_path.DirName()); + + // The relauncher is ordinarily in the version directory. When running in a + // build tree however (where CHROME_VERSION is not set in the environment) + // look for it in Chrome's directory. + if (!version_str.empty()) + path = path.AppendASCII(version_str); + + path = path.Append(installer::kDelegateExecuteExe); + + // Actually launching the process needs to happen in the metro viewer, + // otherwise it won't automatically transition to desktop. So we have + // to send an IPC to the viewer to do the ShellExecute. + aura::HandleActivateDesktop(path, + base::Bind(ActivateDesktopHelperReply)); +} +#endif + +void AttemptRestartToDesktopMode() { + PrefService* prefs = g_browser_process->local_state(); + prefs->SetString(prefs::kRelaunchMode, + upgrade_util::kRelaunchModeDesktop); + +#if defined(USE_AURA) + + // We need to PostTask as there is some IO involved. + content::BrowserThread::PostTask( + content::BrowserThread::PROCESS_LAUNCHER, FROM_HERE, + base::Bind(&ActivateDesktopHelper)); + +#else + AttemptRestart(); +#endif +} + +void AttemptRestartToMetroMode() { + PrefService* prefs = g_browser_process->local_state(); + prefs->SetString(prefs::kRelaunchMode, + upgrade_util::kRelaunchModeMetro); + AttemptRestart(); +} } // namespace chrome diff --git a/chrome/browser/sessions/better_session_restore_browsertest.cc b/chrome/browser/sessions/better_session_restore_browsertest.cc index 40c6103..46f1dfe 100644 --- a/chrome/browser/sessions/better_session_restore_browsertest.cc +++ b/chrome/browser/sessions/better_session_restore_browsertest.cc @@ -581,8 +581,8 @@ class RestartTest : public BetterSessionRestoreTest { PrefService* pref_service = g_browser_process->local_state(); pref_service->SetBoolean(prefs::kWasRestarted, true); #if defined(OS_WIN) - if (pref_service->HasPrefPath(prefs::kRestartSwitchMode)) - pref_service->SetBoolean(prefs::kRestartSwitchMode, false); + if (pref_service->HasPrefPath(prefs::kRelaunchMode)) + pref_service->ClearPref(prefs::kRelaunchMode); #endif } diff --git a/chrome/browser/ui/apps/app_metro_infobar_delegate_win.cc b/chrome/browser/ui/apps/app_metro_infobar_delegate_win.cc index 27c53d2..46dbfba 100644 --- a/chrome/browser/ui/apps/app_metro_infobar_delegate_win.cc +++ b/chrome/browser/ui/apps/app_metro_infobar_delegate_win.cc @@ -95,7 +95,7 @@ bool AppMetroInfoBarDelegateWin::Accept() { } web_contents()->Close(); // Note: deletes |this|. - chrome::AttemptRestartWithModeSwitch(); + chrome::AttemptRestartToDesktopMode(); return false; } diff --git a/chrome/browser/ui/browser_command_controller.cc b/chrome/browser/ui/browser_command_controller.cc index b44e8e0..2860eb8 100644 --- a/chrome/browser/ui/browser_command_controller.cc +++ b/chrome/browser/ui/browser_command_controller.cc @@ -132,7 +132,7 @@ class SwitchToMetroUIHandler case ShellIntegration::STATE_UNKNOWN : break; case ShellIntegration::STATE_IS_DEFAULT: - chrome::AttemptRestartWithModeSwitch(); + chrome::AttemptRestartToMetroMode(); break; case ShellIntegration::STATE_NOT_DEFAULT: if (first_check_) { @@ -483,7 +483,7 @@ void BrowserCommandController::ExecuteCommandWithDisposition( browser_->SetMetroSnapMode(false); break; case IDC_WIN8_DESKTOP_RESTART: - chrome::AttemptRestartWithModeSwitch(); + chrome::AttemptRestartToDesktopMode(); content::RecordAction(content::UserMetricsAction("Win8DesktopRestart")); break; case IDC_WIN8_METRO_RESTART: @@ -965,7 +965,13 @@ void BrowserCommandController::InitCommandState() { command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window); command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window); #if defined(OS_WIN) +#if !defined(USE_AURA) const bool metro_mode = base::win::IsMetroProcess(); +#else + const bool metro_mode = + browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? + true : false; +#endif command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE, metro_mode); command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE, metro_mode); int restart_mode = metro_mode ? diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.cc b/chrome/browser/ui/toolbar/wrench_menu_model.cc index c24ba59..ab2f12f 100644 --- a/chrome/browser/ui/toolbar/wrench_menu_model.cc +++ b/chrome/browser/ui/toolbar/wrench_menu_model.cc @@ -533,15 +533,24 @@ void WrenchMenuModel::Build(bool is_new_menu) { recent_tabs_sub_menu_model_.get()); } -#if defined(OS_WIN) && !defined(USE_ASH) - if (base::win::IsMetroProcess()) { - // Metro mode, add the 'Relaunch Chrome in desktop mode'. - AddSeparator(ui::SPACING_SEPARATOR); - AddItemWithStringId(IDC_WIN8_DESKTOP_RESTART, IDS_WIN8_DESKTOP_RESTART); - } else if (base::win::GetVersion() >= base::win::VERSION_WIN8) { - // In Windows 8 desktop, add the 'Relaunch Chrome in Windows 8 mode'. - AddSeparator(ui::SPACING_SEPARATOR); - AddItemWithStringId(IDC_WIN8_METRO_RESTART, IDS_WIN8_METRO_RESTART); +#if defined(OS_WIN) + if (base::win::GetVersion() >= base::win::VERSION_WIN8) { +#if defined(USE_AURA) + bool in_desktop_mode = + browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? + false : true; +#else + bool in_desktop_mode = !base::win::IsMetroProcess(); +#endif + if (!in_desktop_mode) { + // Metro mode, add the 'Relaunch Chrome in desktop mode'. + AddSeparator(ui::NORMAL_SEPARATOR); + AddItemWithStringId(IDC_WIN8_DESKTOP_RESTART, IDS_WIN8_DESKTOP_RESTART); + } else { + // In Windows 8 desktop, add the 'Relaunch Chrome in Windows 8 mode'. + AddSeparator(ui::NORMAL_SEPARATOR); + AddItemWithStringId(IDC_WIN8_METRO_RESTART, IDS_WIN8_METRO_RESTART); + } } #endif diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index e9270c3..f9cfc8b 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3048,7 +3048,6 @@ 'sources/': [ ['exclude', '^browser/automation/automation_provider_aura.cc'], ['exclude', '^browser/background/background_mode_manager_aura.cc'], - ['exclude', '^browser/lifetime/application_lifetime_win.cc'], ], 'dependencies': [ 'launcher_support', diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 3bbb690..a4e95ca 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -1644,8 +1644,10 @@ const char kRestartLastSessionOnShutdown[] = "restart.last.session.on.shutdown"; const char kWasRestarted[] = "was.restarted"; #if defined(OS_WIN) -// On Windows 8 chrome can restart in desktop or in metro mode. -const char kRestartSwitchMode[] = "restart.switch_mode"; +// Preference to be used while relaunching Chrome. This preference dictates if +// Chrome should be launched in Metro or Desktop mode. +// For more info take a look at ChromeRelaunchMode enum. +const char kRelaunchMode[] = "relaunch.mode"; #endif // Placeholder preference for disabling voice / video chat if it is ever added. diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index e766126..4a4bc05 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -546,7 +546,7 @@ extern const char kShutdownNumProcessesSlow[]; extern const char kRestartLastSessionOnShutdown[]; extern const char kWasRestarted[]; #if defined(OS_WIN) -extern const char kRestartSwitchMode[]; +extern const char kRelaunchMode[]; #endif extern const char kDisableVideoAndChat[]; diff --git a/ui/aura/remote_root_window_host_win.cc b/ui/aura/remote_root_window_host_win.cc index e3578c8..3e7837b 100644 --- a/ui/aura/remote_root_window_host_win.cc +++ b/ui/aura/remote_root_window_host_win.cc @@ -109,6 +109,13 @@ void HandleSelectFolder(const base::string16& title, on_failure); } +void HandleActivateDesktop(const base::FilePath& shortcut, + const ActivateDesktopCompleted& on_success) { + DCHECK(aura::RemoteRootWindowHostWin::Instance()); + aura::RemoteRootWindowHostWin::Instance()->HandleActivateDesktop(shortcut, + on_success); +} + RemoteRootWindowHostWin* g_instance = NULL; RemoteRootWindowHostWin* RemoteRootWindowHostWin::Instance() { @@ -176,6 +183,8 @@ bool RemoteRootWindowHostWin::OnMessageReceived(const IPC::Message& message) { OnSetCursorPosAck) IPC_MESSAGE_HANDLER(MetroViewerHostMsg_WindowSizeChanged, OnWindowSizeChanged) + IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ActivateDesktopDone, + OnDesktopActivated) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -189,6 +198,16 @@ void RemoteRootWindowHostWin::HandleOpenURLOnDesktop( host_->Send(new MetroViewerHostMsg_OpenURLOnDesktop(shortcut, url)); } +void RemoteRootWindowHostWin::HandleActivateDesktop( + const base::FilePath& shortcut, + const ActivateDesktopCompleted& on_success) { + if (!host_) + return; + DCHECK(activate_completed_callback_.is_null()); + activate_completed_callback_ = on_success; + host_->Send(new MetroViewerHostMsg_ActivateDesktop(shortcut)); +} + void RemoteRootWindowHostWin::HandleOpenFile( const base::string16& title, const base::FilePath& default_path, @@ -560,6 +579,12 @@ void RemoteRootWindowHostWin::OnWindowSizeChanged(uint32 width, uint32 height) { SetBounds(gfx::Rect(0, 0, width, height)); } +void RemoteRootWindowHostWin::OnDesktopActivated() { + ActivateDesktopCompleted temp = activate_completed_callback_; + activate_completed_callback_.Reset(); + temp.Run(); +} + void RemoteRootWindowHostWin::DispatchKeyboardMessage(ui::EventType type, uint32 vkey, uint32 repeat_count, diff --git a/ui/aura/remote_root_window_host_win.h b/ui/aura/remote_root_window_host_win.h index c4e238a..d0c5910 100644 --- a/ui/aura/remote_root_window_host_win.h +++ b/ui/aura/remote_root_window_host_win.h @@ -44,6 +44,8 @@ typedef base::Callback<void(const base::FilePath&, int, void*)> typedef base::Callback<void(void*)> FileSelectionCanceled; +typedef base::Callback<void()> ActivateDesktopCompleted; + // Handles the open file operation for Metro Chrome Ash. The on_success // callback passed in is invoked when we receive the opened file name from // the metro viewer. The on failure callback is invoked on failure. @@ -81,6 +83,12 @@ AURA_EXPORT void HandleSelectFolder(const base::string16& title, const SelectFolderCompletion& on_success, const FileSelectionCanceled& on_failure); +// Handles the activate desktop command for Metro Chrome Ash. The on_success +// callback passed in is invoked when activation is completed. +AURA_EXPORT void HandleActivateDesktop( + const base::FilePath& shortcut, + const ActivateDesktopCompleted& on_success); + // RootWindowHost implementaton that receives events from a different // process. In the case of Windows this is the Windows 8 (aka Metro) // frontend process, which forwards input events to this class. @@ -104,6 +112,9 @@ class AURA_EXPORT RemoteRootWindowHostWin : public RootWindowHost { void HandleOpenURLOnDesktop(const base::FilePath& shortcut, const base::string16& url); + void HandleActivateDesktop(const base::FilePath& shortcut, + const ActivateDesktopCompleted& on_success); + void HandleOpenFile(const base::string16& title, const base::FilePath& default_path, const base::string16& filter, @@ -167,6 +178,7 @@ class AURA_EXPORT RemoteRootWindowHostWin : public RootWindowHost { void OnSelectFolderDone(bool success, const base::FilePath& folder); void OnSetCursorPosAck(); void OnWindowSizeChanged(uint32 width, uint32 height); + void OnDesktopActivated(); // RootWindowHost overrides: virtual void SetDelegate(RootWindowHostDelegate* delegate) OVERRIDE; @@ -234,6 +246,10 @@ class AURA_EXPORT RemoteRootWindowHostWin : public RootWindowHost { SelectFolderCompletion select_folder_completion_callback_; FileSelectionCanceled failure_callback_; + // Saved callback which informs caller about successful completion of desktop + // activation. + ActivateDesktopCompleted activate_completed_callback_; + // Set to true if we need to ignore mouse messages until the SetCursorPos // operation is acked by the viewer. bool ignore_mouse_moves_until_set_cursor_ack_; diff --git a/ui/metro_viewer/metro_viewer_messages.h b/ui/metro_viewer/metro_viewer_messages.h index 069436c..e670e49 100644 --- a/ui/metro_viewer/metro_viewer_messages.h +++ b/ui/metro_viewer/metro_viewer_messages.h @@ -89,8 +89,16 @@ IPC_MESSAGE_CONTROL2(MetroViewerHostMsg_SelectFolderDone, bool, /* success */ base::FilePath) /* filepath*/ +// Informs the browser of the result of a activate desktop (shellexecute) +// operation. +IPC_MESSAGE_CONTROL0(MetroViewerHostMsg_ActivateDesktopDone) + // Messages sent from the browser to the viewer: +// Requests the viewer to activate desktop mode. +IPC_MESSAGE_CONTROL1(MetroViewerHostMsg_ActivateDesktop, + base::FilePath /* shortcut */); + // Requests the viewer to open a URL in desktop mode. IPC_MESSAGE_CONTROL2(MetroViewerHostMsg_OpenURLOnDesktop, base::FilePath, /* shortcut */ diff --git a/win8/delegate_execute/command_execute_impl.cc b/win8/delegate_execute/command_execute_impl.cc index 463bbb7..0a9fbcc 100644 --- a/win8/delegate_execute/command_execute_impl.cc +++ b/win8/delegate_execute/command_execute_impl.cc @@ -529,38 +529,6 @@ EC_HOST_UI_MODE CommandExecuteImpl::GetLaunchMode() { parameters_ = CommandLine(CommandLine::NO_PROGRAM); } -#if defined(USE_AURA) - if (launch_mode_determined) - return launch_mode; - - CComPtr<IExecuteCommandHost> host; - CComQIPtr<IServiceProvider> service_provider = m_spUnkSite; - if (service_provider) { - service_provider->QueryService(IID_IExecuteCommandHost, &host); - if (host) { - host->GetUIMode(&launch_mode); - } - } - - // According to 'developing metro style enabled desktop browser' document - // ECHUIM_SYSTEM_LAUNCHER – Start menu launch (includes Tile activation, - // typing a URL into the search box in Start, etc.) - // In non aura world we apparently used ECHUIM_SYSTEM_LAUNCHER to mean - // launch on desktop. For Aura we are changing ECHUIM_SYSTEM to mean - // immersive mode. - if (launch_mode == ECHUIM_SYSTEM_LAUNCHER) - launch_mode = ECHUIM_IMMERSIVE; - else if (launch_mode > ECHUIM_SYSTEM_LAUNCHER) { - // At the end if launch mode is not proper apply heuristics. - launch_mode = base::win::IsTouchEnabledDevice() ? - ECHUIM_IMMERSIVE : ECHUIM_DESKTOP; - } - - AtlTrace("Launching mode is %d\n", launch_mode); - launch_mode_determined = true; - return launch_mode; -#endif - base::win::RegKey reg_key; LONG key_result = reg_key.Create(HKEY_CURRENT_USER, chrome::kMetroRegistryPath, diff --git a/win8/metro_driver/chrome_app_view_ash.cc b/win8/metro_driver/chrome_app_view_ash.cc index b795b92..7dd7d39 100644 --- a/win8/metro_driver/chrome_app_view_ash.cc +++ b/win8/metro_driver/chrome_app_view_ash.cc @@ -81,6 +81,8 @@ class ChromeChannelListener : public IPC::Listener { virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { IPC_BEGIN_MESSAGE_MAP(ChromeChannelListener, message) + IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ActivateDesktop, + OnActivateDesktop) IPC_MESSAGE_HANDLER(MetroViewerHostMsg_OpenURLOnDesktop, OnOpenURLOnDesktop) IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursor, OnSetCursor) @@ -102,6 +104,13 @@ class ChromeChannelListener : public IPC::Listener { } private: + void OnActivateDesktop(const base::FilePath& shortcut) { + ui_proxy_->PostTask(FROM_HERE, + base::Bind(&ChromeAppViewAsh::OnActivateDesktop, + base::Unretained(app_view_), + shortcut)); + } + void OnOpenURLOnDesktop(const base::FilePath& shortcut, const string16& url) { ui_proxy_->PostTask(FROM_HERE, @@ -524,6 +533,23 @@ HRESULT ChromeAppViewAsh::Unsnap() { return hr; } +void ChromeAppViewAsh::OnActivateDesktop(const base::FilePath& file_path) { + DLOG(INFO) << "ChannelAppViewAsh::OnActivateDesktop\n"; + // We are just executing delegate_execute here without parameters. Assumption + // here is that this process will be reused by shell when asking for + // IExecuteCommand interface. + + // TODO(shrikant): Consolidate ShellExecuteEx with SEE_MASK_FLAG_LOG_USAGE + // and place it metro.h or similar accessible file from all code code paths + // using this function. + SHELLEXECUTEINFO sei = { sizeof(sei) }; + sei.fMask = SEE_MASK_FLAG_LOG_USAGE; + sei.nShow = SW_SHOWNORMAL; + sei.lpFile = file_path.value().c_str(); + sei.lpParameters = NULL; + ::ShellExecuteExW(&sei); + ui_channel_->Send(new MetroViewerHostMsg_ActivateDesktopDone()); +} void ChromeAppViewAsh::OnOpenURLOnDesktop(const base::FilePath& shortcut, const string16& url) { diff --git a/win8/metro_driver/chrome_app_view_ash.h b/win8/metro_driver/chrome_app_view_ash.h index 0f9a14a..b301b3a 100644 --- a/win8/metro_driver/chrome_app_view_ash.h +++ b/win8/metro_driver/chrome_app_view_ash.h @@ -49,6 +49,7 @@ class ChromeAppViewAsh // Returns S_OK on success. static HRESULT Unsnap(); + void OnActivateDesktop(const base::FilePath& file_path); void OnOpenURLOnDesktop(const base::FilePath& shortcut, const string16& url); void OnSetCursor(HCURSOR cursor); void OnDisplayFileOpenDialog(const string16& title, |