Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: base/win/metro.cc

Issue 10560015: Implement base::win::IsMetroProcess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Ananta's comments. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/win/metro.h ('k') | chrome/browser/bookmarks/bookmark_manager_extension_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/win/metro.h" 5 #include "base/win/metro.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 8
9 namespace base { 9 namespace base {
10 namespace win { 10 namespace win {
11 11
12 const char kActivateApplication[] = "ActivateApplication"; 12 const char kActivateApplication[] = "ActivateApplication";
13 13
14 HMODULE GetMetroModule() { 14 HMODULE GetMetroModule() {
15 return GetModuleHandleA("metro_driver.dll"); 15 return GetModuleHandleA("metro_driver.dll");
16 } 16 }
17 17
18 bool InMetroMode() {
19 enum ImmersiveState {
20 kImmersiveUnknown,
21 kImmersiveTrue,
22 kImmersiveFalse
23 };
24 typedef BOOL (WINAPI* IsImmersiveProcessFunc)(HANDLE process);
25
26 // Since the immersive state of a process can never change, we look it
27 // up once and then cache it here.
28 static ImmersiveState state = kImmersiveUnknown;
29
30 if (state == kImmersiveUnknown) {
31 // We didn't look it up yet. Note that the code below here is idempotent,
32 // so it doesn't matter if it races to assignment on multiple threads.
33 HMODULE user32 = ::GetModuleHandleA("user32.dll");
34 DCHECK(user32 != NULL);
35
36 IsImmersiveProcessFunc is_immersive_process =
37 reinterpret_cast<IsImmersiveProcessFunc>(
38 ::GetProcAddress(user32, "IsImmersiveProcess"));
39
40 if (is_immersive_process != NULL) {
41 if (is_immersive_process(::GetCurrentProcess())) {
42 DCHECK(GetMetroModule() != NULL);
Sigurður Ásgeirsson 2012/06/18 13:54:15 This assert is apparently firing inside the render
43
44 state = kImmersiveTrue;
45 } else {
46 state = kImmersiveFalse;
47 }
48 } else {
49 // No "IsImmersiveProcess" export on user32.dll, so we're pre-windows8
50 // and therefore not immersive.
51 state = kImmersiveFalse;
52 }
53 }
54 DCHECK_NE(kImmersiveUnknown, state);
55
56 return state == kImmersiveTrue;
57 }
58
18 wchar_t* LocalAllocAndCopyString(const string16& src) { 59 wchar_t* LocalAllocAndCopyString(const string16& src) {
19 size_t dest_size = (src.length() + 1) * sizeof(wchar_t); 60 size_t dest_size = (src.length() + 1) * sizeof(wchar_t);
20 wchar_t* dest = reinterpret_cast<wchar_t*>(LocalAlloc(LPTR, dest_size)); 61 wchar_t* dest = reinterpret_cast<wchar_t*>(LocalAlloc(LPTR, dest_size));
21 base::wcslcpy(dest, src.c_str(), dest_size); 62 base::wcslcpy(dest, src.c_str(), dest_size);
22 return dest; 63 return dest;
23 } 64 }
24 65
25 } // namespace win 66 } // namespace win
26 } // namespace base 67 } // namespace base
OLDNEW
« no previous file with comments | « base/win/metro.h ('k') | chrome/browser/bookmarks/bookmark_manager_extension_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698