diff options
author | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-10 22:41:00 +0000 |
---|---|---|
committer | ananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-10 22:41:00 +0000 |
commit | 92637b676c297764b261837d2a7a89a81104a533 (patch) | |
tree | 510d923f5b2ffda9a7012a651c4888d1f232514b | |
parent | 9243f16e4b6cb242765a82ac4ac6c770472fe297 (diff) | |
download | chromium_src-92637b676c297764b261837d2a7a89a81104a533.zip chromium_src-92637b676c297764b261837d2a7a89a81104a533.tar.gz chromium_src-92637b676c297764b261837d2a7a89a81104a533.tar.bz2 |
Merge 160436 - Desktop Chrome on Windows 8 should attempt to relaunch into immersive mode if the previous run was immersive
or if the machine is a tablet.
This is in line with the expectations of the Windows 8 Chrome Singleton approach where we have one of Chrome
desktop/Chrome Windows 8 immersive mode running at any given time.
Fixes bug http://code.google.com/p/chromium/issues/detail?id=153318
BUG=153318
R=sky
Relaunch Chrome on Windows 8 into immersive mode if the previous run was
Review URL: https://codereview.chromium.org/11026053
TBR=ananta@chromium.org
Review URL: https://codereview.chromium.org/11093058
git-svn-id: svn://svn.chromium.org/chrome/branches/1271/src@161219 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/process_singleton_win.cc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/chrome/browser/process_singleton_win.cc b/chrome/browser/process_singleton_win.cc index 54731ca..5e0920e 100644 --- a/chrome/browser/process_singleton_win.cc +++ b/chrome/browser/process_singleton_win.cc @@ -15,13 +15,17 @@ #include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "base/win/metro.h" +#include "base/win/registry.h" #include "base/win/scoped_com_initializer.h" #include "base/win/scoped_comptr.h" #include "base/win/scoped_handle.h" +#include "base/win/win_util.h" #include "base/win/windows_version.h" #include "base/win/wrapped_window_proc.h" #include "chrome/browser/ui/simple_message_box.h" #include "chrome/common/chrome_constants.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/common/chrome_paths_internal.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/shell_util.h" #include "chrome/installer/util/wmi.h" @@ -39,6 +43,8 @@ const char kLockfile[] = "lockfile"; const char kSearchUrl[] = "http://www.google.com/search?q=%s&sourceid=chrome&ie=UTF-8"; +const int kImmersiveChromeInitTimeout = 500; + // Checks the visibility of the enumerated window and signals once a visible // window has been found. BOOL CALLBACK BrowserWindowEnumeration(HWND window, LPARAM param) { @@ -159,6 +165,54 @@ bool ActivateMetroChrome() { return true; } +// Returns true if Chrome needs to be relaunched into Windows 8 immersive mode. +// Following conditions apply:- +// 1. Windows 8 or greater. +// 2. Not in Windows 8 immersive mode. +// 3. Process integrity level is not high. +// 4. The profile data directory is the default directory . +// 5. Last used mode was immersive/machine is a tablet. +// TODO(ananta) +// Move this function to a common place as the Windows 8 delegate_execute +// handler can possibly use this. +bool ShouldLaunchInWindows8ImmersiveMode(const FilePath& user_data_dir) { +#if defined(USE_AURA) + return false; +#endif + + if (base::win::GetVersion() < base::win::VERSION_WIN8) + return false; + + if (base::win::IsProcessImmersive(base::GetCurrentProcessHandle())) + return false; + + base::IntegrityLevel integrity_level = base::INTEGRITY_UNKNOWN; + base::GetProcessIntegrityLevel(base::GetCurrentProcessHandle(), + &integrity_level); + if (integrity_level == base::HIGH_INTEGRITY) + return false; + + FilePath default_user_data_dir; + if (!chrome::GetDefaultUserDataDirectory(&default_user_data_dir)) + return false; + + if (default_user_data_dir != user_data_dir) + return false; + + base::win::RegKey reg_key; + LONG key_result = reg_key.Create(HKEY_CURRENT_USER, + chrome::kMetroRegistryPath, + KEY_READ); + if (key_result == ERROR_SUCCESS) { + DWORD reg_value = 0; + reg_key.ReadValueDW(chrome::kLaunchModeValue, + ®_value); + if (reg_value == 1) + return true; + } + return base::win::IsMachineATablet(); +} + } // namespace // Microsoft's Softricity virtualization breaks the sandbox processes. @@ -198,6 +252,19 @@ bool ProcessSingleton::EscapeVirtualization(const FilePath& user_data_dir) { ProcessSingleton::ProcessSingleton(const FilePath& user_data_dir) : window_(NULL), locked_(false), foreground_window_(NULL), is_virtualized_(false), lock_file_(INVALID_HANDLE_VALUE) { + FilePath default_user_data_dir; + // For Windows 8 and above check if we need to relaunch into Windows 8 + // immersive mode. + if (ShouldLaunchInWindows8ImmersiveMode(user_data_dir)) { + bool immersive_chrome_launched = ActivateMetroChrome(); + if (!immersive_chrome_launched) { + LOG(WARNING) << "Failed to launch immersive chrome"; + } else { + // Sleep to allow the immersive chrome process to create its initial + // message window. + SleepEx(kImmersiveChromeInitTimeout, FALSE); + } + } remote_window_ = FindWindowEx(HWND_MESSAGE, NULL, chrome::kMessageWindowClass, user_data_dir.value().c_str()); |