Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / metro_utils / metro_chrome_win.cc
blob30aeca58eebd2e4eed60c0958a84a1c621605189
1 // Copyright 2013 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.
5 #include "chrome/browser/metro_utils/metro_chrome_win.h"
7 #include <windows.h>
8 #include <shobjidl.h>
10 #include "base/files/file_path.h"
11 #include "base/path_service.h"
12 #include "base/win/metro.h"
13 #include "base/win/scoped_com_initializer.h"
14 #include "base/win/scoped_comptr.h"
15 #include "chrome/installer/util/browser_distribution.h"
16 #include "chrome/installer/util/install_util.h"
17 #include "chrome/installer/util/shell_util.h"
19 namespace chrome {
21 bool ActivateMetroChrome() {
22 base::FilePath chrome_exe;
23 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
24 NOTREACHED() << "Failed to get chrome exe path";
25 return false;
28 base::string16 app_id = ShellUtil::GetBrowserModelId(
29 BrowserDistribution::GetDistribution(),
30 InstallUtil::IsPerUserInstall(chrome_exe.value().c_str()));
31 if (app_id.empty()) {
32 NOTREACHED() << "Failed to get chrome app user model id.";
33 return false;
36 base::win::ScopedComPtr<IApplicationActivationManager> activation_manager;
37 HRESULT hr = activation_manager.CreateInstance(
38 CLSID_ApplicationActivationManager);
39 if (!activation_manager) {
40 NOTREACHED() << "Failed to cocreate activation manager. Error: "
41 << std::showbase << std::hex << hr;
42 return false;
45 unsigned long pid = 0;
46 hr = activation_manager->ActivateApplication(app_id.c_str(),
47 L"open",
48 AO_NONE,
49 &pid);
50 if (FAILED(hr)) {
51 NOTREACHED() << "Failed to activate metro chrome. Error: "
52 << std::showbase << std::hex << hr;
53 return false;
56 return true;
59 Win8Environment GetWin8Environment(HostDesktopType desktop) {
60 #if defined(USE_AURA) && defined(USE_ASH)
61 if (desktop == chrome::HOST_DESKTOP_TYPE_ASH)
62 return WIN_8_ENVIRONMENT_METRO_AURA;
63 else
64 return WIN_8_ENVIRONMENT_DESKTOP_AURA;
65 #else
66 if (base::win::IsProcessImmersive(::GetCurrentProcess()))
67 return WIN_8_ENVIRONMENT_METRO;
68 else
69 return WIN_8_ENVIRONMENT_DESKTOP;
70 #endif
74 } // namespace chrome