| OLD | NEW |
| 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 "stdafx.h" | 5 #include "stdafx.h" |
| 6 #include "winrt_utils.h" | 6 #include "winrt_utils.h" |
| 7 | 7 |
| 8 #include <shlobj.h> | 8 #include <shlobj.h> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/win/scoped_com_initializer.h" | 12 #include "base/win/scoped_com_initializer.h" |
| 13 #include "base/win/scoped_comptr.h" | 13 #include "base/win/scoped_comptr.h" |
| 14 #include "chrome/installer/util/browser_distribution.h" | 14 #include "chrome/installer/util/browser_distribution.h" |
| 15 #include "chrome/installer/util/install_util.h" | 15 #include "chrome/installer/util/install_util.h" |
| 16 | 16 |
| 17 void CheckHR(HRESULT hr, const char* message) { | 17 void CheckHR(HRESULT hr, const char* message) { |
| 18 if (FAILED(hr)) { | 18 if (FAILED(hr)) { |
| 19 if (message) | 19 if (message) |
| 20 PLOG(DFATAL) << message << ", hr = " << std::hex << hr; | 20 PLOG(DFATAL) << message << ", hr = " << std::hex << hr; |
| 21 else | 21 else |
| 22 PLOG(DFATAL) << "COM ERROR" << ", hr = " << std::hex << hr; | 22 PLOG(DFATAL) << "COM ERROR" << ", hr = " << std::hex << hr; |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 HSTRING MakeHString(const string16& str) { | 26 HSTRING MakeHString(const base::string16& str) { |
| 27 HSTRING hstr; | 27 HSTRING hstr; |
| 28 if (FAILED(::WindowsCreateString(str.c_str(), static_cast<UINT32>(str.size()), | 28 if (FAILED(::WindowsCreateString(str.c_str(), static_cast<UINT32>(str.size()), |
| 29 &hstr))) { | 29 &hstr))) { |
| 30 PLOG(DFATAL) << "Hstring creation failed"; | 30 PLOG(DFATAL) << "Hstring creation failed"; |
| 31 } | 31 } |
| 32 return hstr; | 32 return hstr; |
| 33 } | 33 } |
| 34 | 34 |
| 35 string16 MakeStdWString(HSTRING hstring) { | 35 base::string16 MakeStdWString(HSTRING hstring) { |
| 36 const wchar_t* str; | 36 const wchar_t* str; |
| 37 UINT32 size = 0; | 37 UINT32 size = 0; |
| 38 str = ::WindowsGetStringRawBuffer(hstring, &size); | 38 str = ::WindowsGetStringRawBuffer(hstring, &size); |
| 39 if (!size) | 39 if (!size) |
| 40 return string16(); | 40 return base::string16(); |
| 41 return string16(str, size); | 41 return base::string16(str, size); |
| 42 } | 42 } |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 #define IMPLEMENT_CREATE_PROPERTY(Name, Type) \ | 46 #define IMPLEMENT_CREATE_PROPERTY(Name, Type) \ |
| 47 HRESULT Create ## Name ## Property(Type value, \ | 47 HRESULT Create ## Name ## Property(Type value, \ |
| 48 winfoundtn::IPropertyValue** prop) { \ | 48 winfoundtn::IPropertyValue** prop) { \ |
| 49 mswr::ComPtr<winfoundtn::IPropertyValueStatics> property_value_statics; \ | 49 mswr::ComPtr<winfoundtn::IPropertyValueStatics> property_value_statics; \ |
| 50 HRESULT hr = winrt_utils::CreateActivationFactory( \ | 50 HRESULT hr = winrt_utils::CreateActivationFactory( \ |
| 51 RuntimeClass_Windows_Foundation_PropertyValue, \ | 51 RuntimeClass_Windows_Foundation_PropertyValue, \ |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 break; | 163 break; |
| 164 } | 164 } |
| 165 default: { | 165 default: { |
| 166 hr = E_NOTIMPL; | 166 hr = E_NOTIMPL; |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 return hr; | 169 return hr; |
| 170 } | 170 } |
| 171 | 171 |
| 172 bool GetArgumentsFromShortcut(const base::FilePath& shortcut, | 172 bool GetArgumentsFromShortcut(const base::FilePath& shortcut, |
| 173 string16* arguments) { | 173 base::string16* arguments) { |
| 174 HRESULT result; | 174 HRESULT result; |
| 175 base::win::ScopedComPtr<IShellLink> i_shell_link; | 175 base::win::ScopedComPtr<IShellLink> i_shell_link; |
| 176 bool is_resolved = false; | 176 bool is_resolved = false; |
| 177 | 177 |
| 178 | 178 |
| 179 base::win::ScopedCOMInitializer sta_com_initializer; | 179 base::win::ScopedCOMInitializer sta_com_initializer; |
| 180 | 180 |
| 181 // Get pointer to the IShellLink interface | 181 // Get pointer to the IShellLink interface |
| 182 result = i_shell_link.CreateInstance(CLSID_ShellLink, NULL, | 182 result = i_shell_link.CreateInstance(CLSID_ShellLink, NULL, |
| 183 CLSCTX_INPROC_SERVER); | 183 CLSCTX_INPROC_SERVER); |
| 184 if (SUCCEEDED(result)) { | 184 if (SUCCEEDED(result)) { |
| 185 base::win::ScopedComPtr<IPersistFile> persist; | 185 base::win::ScopedComPtr<IPersistFile> persist; |
| 186 // Query IShellLink for the IPersistFile interface | 186 // Query IShellLink for the IPersistFile interface |
| 187 result = persist.QueryFrom(i_shell_link); | 187 result = persist.QueryFrom(i_shell_link); |
| 188 if (SUCCEEDED(result)) { | 188 if (SUCCEEDED(result)) { |
| 189 WCHAR temp_arguments[MAX_PATH]; | 189 WCHAR temp_arguments[MAX_PATH]; |
| 190 // Load the shell link | 190 // Load the shell link |
| 191 result = persist->Load(shortcut.value().c_str(), STGM_READ); | 191 result = persist->Load(shortcut.value().c_str(), STGM_READ); |
| 192 if (SUCCEEDED(result)) { | 192 if (SUCCEEDED(result)) { |
| 193 result = i_shell_link->GetArguments(temp_arguments, MAX_PATH); | 193 result = i_shell_link->GetArguments(temp_arguments, MAX_PATH); |
| 194 *arguments = temp_arguments; | 194 *arguments = temp_arguments; |
| 195 is_resolved = true; | 195 is_resolved = true; |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 return is_resolved; | 200 return is_resolved; |
| 201 } | 201 } |
| 202 | 202 |
| 203 string16 ReadArgumentsFromPinnedTaskbarShortcut() { | 203 base::string16 ReadArgumentsFromPinnedTaskbarShortcut() { |
| 204 wchar_t path_buffer[MAX_PATH] = {}; | 204 wchar_t path_buffer[MAX_PATH] = {}; |
| 205 | 205 |
| 206 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, | 206 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, |
| 207 SHGFP_TYPE_CURRENT, path_buffer))) { | 207 SHGFP_TYPE_CURRENT, path_buffer))) { |
| 208 base::FilePath shortcut(path_buffer); | 208 base::FilePath shortcut(path_buffer); |
| 209 shortcut = shortcut.Append( | 209 shortcut = shortcut.Append( |
| 210 L"Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar"); | 210 L"Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar"); |
| 211 | 211 |
| 212 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 212 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 213 base::string16 link_name = dist->GetShortcutName( | 213 base::string16 link_name = dist->GetShortcutName( |
| 214 BrowserDistribution::SHORTCUT_CHROME) + installer::kLnkExt; | 214 BrowserDistribution::SHORTCUT_CHROME) + installer::kLnkExt; |
| 215 shortcut = shortcut.Append(link_name); | 215 shortcut = shortcut.Append(link_name); |
| 216 | 216 |
| 217 string16 arguments; | 217 base::string16 arguments; |
| 218 if (GetArgumentsFromShortcut(shortcut, &arguments)) { | 218 if (GetArgumentsFromShortcut(shortcut, &arguments)) { |
| 219 return arguments; | 219 return arguments; |
| 220 } | 220 } |
| 221 } | 221 } |
| 222 | 222 |
| 223 return L""; | 223 return L""; |
| 224 } | 224 } |
| 225 | 225 |
| 226 } // namespace winrt_utils | 226 } // namespace winrt_utils |
| OLD | NEW |