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

Side by Side Diff: ui/base/win/shell.cc

Issue 2909943003: Removing useless Win7 checks + standardize its use (Closed)
Patch Set: Various nits Created 3 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
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 "ui/base/win/shell.h" 5 #include "ui/base/win/shell.h"
6 6
7 #include <dwmapi.h> 7 #include <dwmapi.h>
8 #include <shlobj.h> // Must be before propkey. 8 #include <shlobj.h> // Must be before propkey.
9 #include <propkey.h> 9 #include <propkey.h>
10 #include <shellapi.h> 10 #include <shellapi.h>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/debug/alias.h" 13 #include "base/debug/alias.h"
14 #include "base/files/file.h" 14 #include "base/files/file.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/native_library.h" 16 #include "base/native_library.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/threading/thread_restrictions.h" 19 #include "base/threading/thread_restrictions.h"
20 #include "base/win/scoped_comptr.h" 20 #include "base/win/scoped_comptr.h"
21 #include "base/win/win_util.h" 21 #include "base/win/win_util.h"
22 #include "base/win/windows_version.h"
23 #include "ui/base/ui_base_switches.h" 22 #include "ui/base/ui_base_switches.h"
24 23
25 namespace ui { 24 namespace ui {
26 namespace win { 25 namespace win {
27 26
28 namespace { 27 namespace {
29 28
30 // Default ShellExecuteEx flags used with the "openas" verb. 29 // Default ShellExecuteEx flags used with the "openas" verb.
31 // 30 //
32 // SEE_MASK_NOASYNC is specified so that ShellExecuteEx can be invoked from a 31 // SEE_MASK_NOASYNC is specified so that ShellExecuteEx can be invoked from a
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // resulting error does not cause UI due to the SEE_MASK_FLAG_NO_UI flag in 91 // resulting error does not cause UI due to the SEE_MASK_FLAG_NO_UI flag in
93 // kDefaultOpenFlags. 92 // kDefaultOpenFlags.
94 return InvokeShellExecute(full_path.value(), full_path.value(), 93 return InvokeShellExecute(full_path.value(), full_path.value(),
95 base::string16(), L"explore", 94 base::string16(), L"explore",
96 kDefaultOpenFlags) == ERROR_SUCCESS; 95 kDefaultOpenFlags) == ERROR_SUCCESS;
97 } 96 }
98 97
99 bool PreventWindowFromPinning(HWND hwnd) { 98 bool PreventWindowFromPinning(HWND hwnd) {
100 DCHECK(hwnd); 99 DCHECK(hwnd);
101 100
102 // This functionality is only available on Win7+.
103 if (base::win::GetVersion() < base::win::VERSION_WIN7)
104 return false;
105
106 base::win::ScopedComPtr<IPropertyStore> pps; 101 base::win::ScopedComPtr<IPropertyStore> pps;
107 if (FAILED( 102 if (FAILED(
108 SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(pps.GetAddressOf())))) 103 SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(pps.GetAddressOf()))))
109 return false; 104 return false;
110 105
111 return base::win::SetBooleanValueForPropertyStore( 106 return base::win::SetBooleanValueForPropertyStore(
112 pps.Get(), PKEY_AppUserModel_PreventPinning, true); 107 pps.Get(), PKEY_AppUserModel_PreventPinning, true);
113 } 108 }
114 109
115 // TODO(calamity): investigate moving this out of the UI thread as COM 110 // TODO(calamity): investigate moving this out of the UI thread as COM
116 // operations may spawn nested run loops which can cause issues. 111 // operations may spawn nested run loops which can cause issues.
117 void SetAppDetailsForWindow(const base::string16& app_id, 112 void SetAppDetailsForWindow(const base::string16& app_id,
118 const base::FilePath& app_icon_path, 113 const base::FilePath& app_icon_path,
119 int app_icon_index, 114 int app_icon_index,
120 const base::string16& relaunch_command, 115 const base::string16& relaunch_command,
121 const base::string16& relaunch_display_name, 116 const base::string16& relaunch_display_name,
122 HWND hwnd) { 117 HWND hwnd) {
123 DCHECK(hwnd); 118 DCHECK(hwnd);
124 119
125 // This functionality is only available on Win7+.
126 if (base::win::GetVersion() < base::win::VERSION_WIN7)
127 return;
128
129 base::win::ScopedComPtr<IPropertyStore> pps; 120 base::win::ScopedComPtr<IPropertyStore> pps;
130 if (FAILED( 121 if (FAILED(
131 SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(pps.GetAddressOf())))) 122 SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(pps.GetAddressOf()))))
132 return; 123 return;
133 124
134 if (!app_id.empty()) 125 if (!app_id.empty())
135 base::win::SetAppIdForPropertyStore(pps.Get(), app_id.c_str()); 126 base::win::SetAppIdForPropertyStore(pps.Get(), app_id.c_str());
136 if (!app_icon_path.empty()) { 127 if (!app_icon_path.empty()) {
137 // Always add the icon index explicitly to prevent bad interaction with the 128 // Always add the icon index explicitly to prevent bad interaction with the
138 // index notation when file path has commas. 129 // index notation when file path has commas.
(...skipping 30 matching lines...) Expand all
169 void SetRelaunchDetailsForWindow(const base::string16& relaunch_command, 160 void SetRelaunchDetailsForWindow(const base::string16& relaunch_command,
170 const base::string16& display_name, 161 const base::string16& display_name,
171 HWND hwnd) { 162 HWND hwnd) {
172 SetAppDetailsForWindow(base::string16(), base::FilePath(), 0, 163 SetAppDetailsForWindow(base::string16(), base::FilePath(), 0,
173 relaunch_command, display_name, hwnd); 164 relaunch_command, display_name, hwnd);
174 } 165 }
175 166
176 void ClearWindowPropertyStore(HWND hwnd) { 167 void ClearWindowPropertyStore(HWND hwnd) {
177 DCHECK(hwnd); 168 DCHECK(hwnd);
178 169
179 // This functionality is only available on Win7+.
180 if (base::win::GetVersion() < base::win::VERSION_WIN7)
181 return;
182
183 base::win::ScopedComPtr<IPropertyStore> pps; 170 base::win::ScopedComPtr<IPropertyStore> pps;
184 if (FAILED( 171 if (FAILED(
185 SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(pps.GetAddressOf())))) 172 SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(pps.GetAddressOf()))))
186 return; 173 return;
187 174
188 DWORD property_count; 175 DWORD property_count;
189 if (FAILED(pps->GetCount(&property_count))) 176 if (FAILED(pps->GetCount(&property_count)))
190 return; 177 return;
191 178
192 PROPVARIANT empty_property_variant = {}; 179 PROPVARIANT empty_property_variant = {};
193 for (DWORD i = 0; i < property_count; i++) { 180 for (DWORD i = 0; i < property_count; i++) {
194 PROPERTYKEY key; 181 PROPERTYKEY key;
195 if (SUCCEEDED(pps->GetAt(i, &key))) 182 if (SUCCEEDED(pps->GetAt(i, &key)))
196 pps->SetValue(key, empty_property_variant); 183 pps->SetValue(key, empty_property_variant);
197 } 184 }
198 185
199 pps->Commit(); 186 pps->Commit();
200 } 187 }
201 188
202 bool IsAeroGlassEnabled() { 189 bool IsAeroGlassEnabled() {
203 // For testing in Win8 (where it is not possible to disable composition) the 190 // For testing in Win8 (where it is not possible to disable composition) the
204 // user can specify this command line switch to mimic the behavior. In this 191 // user can specify this command line switch to mimic the behavior. In this
205 // mode, cross-HWND transparency is not supported and various types of 192 // mode, cross-HWND transparency is not supported and various types of
206 // widgets fallback to more simplified rendering behavior. 193 // widgets fallback to more simplified rendering behavior.
207 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 194 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
208 switches::kDisableDwmComposition)) 195 switches::kDisableDwmComposition))
209 return false; 196 return false;
210 197
211 // Technically Aero glass works in Vista but we want to put XP and Vista
212 // at the same feature level. See bug 426573.
213 if (base::win::GetVersion() < base::win::VERSION_WIN7)
214 return false;
215 // If composition is not enabled, we behave like on XP. 198 // If composition is not enabled, we behave like on XP.
216 BOOL enabled = FALSE; 199 BOOL enabled = FALSE;
217 return SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled; 200 return SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled;
218 } 201 }
219 202
220 } // namespace win 203 } // namespace win
221 } // namespace ui 204 } // namespace ui
OLDNEW
« no previous file with comments | « sandbox/win/src/process_mitigations_test.cc ('k') | ui/events/blink/web_input_event_builders_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698