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

Side by Side Diff: win8/metro_driver/winrt_utils.cc

Issue 10875008: Integrate the Windows 8 code into the Chromium tree. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove conflicting OWNERS file. Created 8 years, 3 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 | « win8/metro_driver/winrt_utils.h ('k') | win8/metro_driver/winrt_utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "stdafx.h"
6 #include "winrt_utils.h"
7
8 #include <shlobj.h>
9
10 #include "base/file_path.h"
11 #include "base/logging.h"
12 #include "base/win/scoped_com_initializer.h"
13 #include "base/win/scoped_comptr.h"
14
15 void CheckHR(HRESULT hr, const char* message) {
16 if (FAILED(hr)) {
17 if (message)
18 PLOG(DFATAL) << message << ", hr = " << std::hex << hr;
19 else
20 PLOG(DFATAL) << "COM ERROR" << ", hr = " << std::hex << hr;
21 }
22 }
23
24 HSTRING MakeHString(const string16& str) {
25 HSTRING hstr;
26 if (FAILED(::WindowsCreateString(str.c_str(), str.size(), &hstr))) {
27 PLOG(DFATAL) << "Hstring creation failed";
28 }
29 return hstr;
30 }
31
32 string16 MakeStdWString(HSTRING hstring) {
33 const wchar_t* str;
34 UINT32 size = 0;
35 str = ::WindowsGetStringRawBuffer(hstring, &size);
36 if (!size)
37 return string16();
38 return string16(str, size);
39 }
40
41 namespace {
42
43 #define IMPLEMENT_CREATE_PROPERTY(Name, Type) \
44 HRESULT Create ## Name ## Property(Type value, \
45 winfoundtn::IPropertyValue** prop) { \
46 mswr::ComPtr<winfoundtn::IPropertyValueStatics> property_value_statics; \
47 HRESULT hr = winrt_utils::CreateActivationFactory( \
48 RuntimeClass_Windows_Foundation_PropertyValue, \
49 property_value_statics.GetAddressOf()); \
50 CheckHR(hr, "Can't create IPropertyValueStatics"); \
51 hr = property_value_statics->Create ## Name ## ( \
52 value, \
53 reinterpret_cast<IInspectable**>(prop)); \
54 CheckHR(hr, "Failed to create Property"); \
55 return hr; \
56 }
57
58 #define COMPARE_ATOMIC_PROPERTY_VALUES(Name, Type) \
59 Type lhs_value; \
60 hr = lhs->Get ## Name ##(&lhs_value); \
61 CheckHR(hr, "Can't get value for lhs"); \
62 Type rhs_value; \
63 hr = rhs->Get ## Name ##(&rhs_value); \
64 CheckHR(hr, "Can't get value for rhs"); \
65 if (lhs_value < rhs_value) \
66 *result = -1; \
67 else if (lhs_value > rhs_value) \
68 *result = 1; \
69 else \
70 *result = 0; \
71 hr = S_OK
72
73 } // namespace
74
75 namespace winrt_utils {
76
77 IMPLEMENT_CREATE_PROPERTY(String, HSTRING);
78 IMPLEMENT_CREATE_PROPERTY(Int16, INT16);
79 IMPLEMENT_CREATE_PROPERTY(Int32, INT32);
80 IMPLEMENT_CREATE_PROPERTY(Int64, INT64);
81 IMPLEMENT_CREATE_PROPERTY(UInt8, UINT8);
82 IMPLEMENT_CREATE_PROPERTY(UInt16, UINT16);
83 IMPLEMENT_CREATE_PROPERTY(UInt32, UINT32);
84 IMPLEMENT_CREATE_PROPERTY(UInt64, UINT64);
85
86 HRESULT CompareProperties(winfoundtn::IPropertyValue* lhs,
87 winfoundtn::IPropertyValue* rhs,
88 INT32* result) {
89 if (result == nullptr) {
90 PLOG(DFATAL) << "Invalid argument to CompareProperties.";
91 return E_INVALIDARG;
92 }
93
94 if (lhs == rhs) {
95 *result = 0;
96 return S_OK;
97 }
98
99 winfoundtn::PropertyType lhs_property_type;
100 HRESULT hr = lhs->get_Type(&lhs_property_type);
101 if (FAILED(hr)) {
102 PLOG(DFATAL) << "Can't get property type for lhs, hr=" << std::hex << hr;
103 }
104
105 winfoundtn::PropertyType rhs_property_type;
106 hr = rhs->get_Type(&rhs_property_type);
107 CheckHR(hr, "Can't get property type for rhs");
108
109 if (lhs_property_type != rhs_property_type)
110 return E_INVALIDARG;
111
112 switch (lhs_property_type) {
113 case winfoundtn::PropertyType::PropertyType_String: {
114 mswrw::HString lhs_string;
115 hr = lhs->GetString(lhs_string.GetAddressOf());
116 CheckHR(hr, "Can't get string for lhs");
117
118 mswrw::HString rhs_string;
119 hr = rhs->GetString(rhs_string.GetAddressOf());
120 CheckHR(hr, "Can't get string for rhs");
121
122 hr = WindowsCompareStringOrdinal(
123 lhs_string.Get(), rhs_string.Get(), result);
124 break;
125 }
126 case winfoundtn::PropertyType::PropertyType_Char16: {
127 COMPARE_ATOMIC_PROPERTY_VALUES(Char16, wchar_t);
128 break;
129 }
130 case winfoundtn::PropertyType::PropertyType_Double: {
131 COMPARE_ATOMIC_PROPERTY_VALUES(Double, double);
132 break;
133 }
134 case winfoundtn::PropertyType::PropertyType_Int16: {
135 COMPARE_ATOMIC_PROPERTY_VALUES(Int16, INT16);
136 break;
137 }
138 case winfoundtn::PropertyType::PropertyType_Int32: {
139 COMPARE_ATOMIC_PROPERTY_VALUES(Int32, INT32);
140 break;
141 }
142 case winfoundtn::PropertyType::PropertyType_Int64: {
143 COMPARE_ATOMIC_PROPERTY_VALUES(Int64, INT64);
144 break;
145 }
146 case winfoundtn::PropertyType::PropertyType_UInt8: {
147 COMPARE_ATOMIC_PROPERTY_VALUES(UInt8, UINT8);
148 break;
149 }
150 case winfoundtn::PropertyType::PropertyType_UInt16: {
151 COMPARE_ATOMIC_PROPERTY_VALUES(UInt16, UINT16);
152 break;
153 }
154 case winfoundtn::PropertyType::PropertyType_UInt32: {
155 COMPARE_ATOMIC_PROPERTY_VALUES(UInt32, UINT32);
156 break;
157 }
158 case winfoundtn::PropertyType::PropertyType_UInt64: {
159 COMPARE_ATOMIC_PROPERTY_VALUES(UInt64, UINT64);
160 break;
161 }
162 default: {
163 hr = E_NOTIMPL;
164 }
165 }
166 return hr;
167 }
168
169 bool GetArgumentsFromShortcut(const FilePath& shortcut,
170 string16* arguments) {
171 HRESULT result;
172 base::win::ScopedComPtr<IShellLink> i_shell_link;
173 bool is_resolved = false;
174
175
176 base::win::ScopedCOMInitializer sta_com_initializer;
177
178 // Get pointer to the IShellLink interface
179 result = i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
180 CLSCTX_INPROC_SERVER);
181 if (SUCCEEDED(result)) {
182 base::win::ScopedComPtr<IPersistFile> persist;
183 // Query IShellLink for the IPersistFile interface
184 result = persist.QueryFrom(i_shell_link);
185 if (SUCCEEDED(result)) {
186 WCHAR temp_arguments[MAX_PATH];
187 // Load the shell link
188 result = persist->Load(shortcut.value().c_str(), STGM_READ);
189 if (SUCCEEDED(result)) {
190 result = i_shell_link->GetArguments(temp_arguments, MAX_PATH);
191 *arguments = temp_arguments;
192 is_resolved = true;
193 }
194 }
195 }
196
197 return is_resolved;
198 }
199
200 string16 ReadArgumentsFromPinnedTaskbarShortcut() {
201 wchar_t path_buffer[MAX_PATH] = {};
202
203 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL,
204 SHGFP_TYPE_CURRENT, path_buffer))) {
205 FilePath shortcut(path_buffer);
206 shortcut = shortcut.Append(
207 L"Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar");
208
209 // TODO(robertshield): Get this stuff from BrowserDistribution.
210 #if defined(GOOGLE_CHROME_BUILD)
211 shortcut = shortcut.Append(L"Google Chrome.lnk");
212 #else
213 shortcut = shortcut.Append(L"Chromium.lnk");
214 #endif
215
216 string16 arguments;
217 if (GetArgumentsFromShortcut(shortcut, &arguments)) {
218 return arguments;
219 }
220 }
221
222 return L"";
223 }
224
225 } // namespace winrt_utils
OLDNEW
« no previous file with comments | « win8/metro_driver/winrt_utils.h ('k') | win8/metro_driver/winrt_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698