| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <shlobj.h> | 5 #include <shlobj.h> |
| 6 #include <shobjidl.h> | 6 #include <shobjidl.h> |
| 7 #include <atlcomcli.h> | 7 #include <atlcomcli.h> |
| 8 | 8 |
| 9 #include "chrome/common/win_safe_util.h" | 9 #include "chrome/common/win_safe_util.h" |
| 10 | 10 |
| 11 #include "app/win_util.h" | 11 #include "app/win_util.h" |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 | 16 |
| 17 namespace win_util { | 17 namespace win_util { |
| 18 | 18 |
| 19 // This function implementation is based on the attachment execution | 19 // This function implementation is based on the attachment execution |
| 20 // services functionally deployed with IE6 or Service pack 2. This | 20 // services functionally deployed with IE6 or Service pack 2. This |
| 21 // functionality is exposed in the IAttachmentExecute COM interface. | 21 // functionality is exposed in the IAttachmentExecute COM interface. |
| 22 // more information at: | 22 // more information at: |
| 23 // http://msdn2.microsoft.com/en-us/library/ms647048.aspx | 23 // http://msdn2.microsoft.com/en-us/library/ms647048.aspx |
| 24 bool SaferOpenItemViaShell(HWND hwnd, const std::wstring& window_title, | 24 bool SaferOpenItemViaShell(HWND hwnd, const std::wstring& window_title, |
| 25 const FilePath& full_path, | 25 const FilePath& full_path, |
| 26 const std::wstring& source_url, | 26 const std::wstring& source_url) { |
| 27 bool ask_for_app) { | |
| 28 ATL::CComPtr<IAttachmentExecute> attachment_services; | 27 ATL::CComPtr<IAttachmentExecute> attachment_services; |
| 29 HRESULT hr = attachment_services.CoCreateInstance(CLSID_AttachmentServices); | 28 HRESULT hr = attachment_services.CoCreateInstance(CLSID_AttachmentServices); |
| 30 if (FAILED(hr)) { | 29 if (FAILED(hr)) { |
| 31 // We don't have Attachment Execution Services, it must be a pre-XP.SP2 | 30 // We don't have Attachment Execution Services, it must be a pre-XP.SP2 |
| 32 // Windows installation, or the thread does not have COM initialized. | 31 // Windows installation, or the thread does not have COM initialized. |
| 33 if (hr == CO_E_NOTINITIALIZED) { | 32 if (hr == CO_E_NOTINITIALIZED) { |
| 34 NOTREACHED(); | 33 NOTREACHED(); |
| 35 return false; | 34 return false; |
| 36 } | 35 } |
| 37 return OpenItemViaShell(full_path, ask_for_app); | 36 return OpenItemViaShell(full_path); |
| 38 } | 37 } |
| 39 | 38 |
| 40 // This GUID is associated with any 'don't ask me again' settings that the | 39 // This GUID is associated with any 'don't ask me again' settings that the |
| 41 // user can select for different file types. | 40 // user can select for different file types. |
| 42 // {2676A9A2-D919-4fee-9187-152100393AB2} | 41 // {2676A9A2-D919-4fee-9187-152100393AB2} |
| 43 static const GUID kClientID = { 0x2676a9a2, 0xd919, 0x4fee, | 42 static const GUID kClientID = { 0x2676a9a2, 0xd919, 0x4fee, |
| 44 { 0x91, 0x87, 0x15, 0x21, 0x0, 0x39, 0x3a, 0xb2 } }; | 43 { 0x91, 0x87, 0x15, 0x21, 0x0, 0x39, 0x3a, 0xb2 } }; |
| 45 | 44 |
| 46 attachment_services->SetClientGuid(kClientID); | 45 attachment_services->SetClientGuid(kClientID); |
| 47 | 46 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // We cannot control what the prompt says or does directly but it | 84 // We cannot control what the prompt says or does directly but it |
| 86 // is a pretty decent dialog; for example, if an excutable is signed it can | 85 // is a pretty decent dialog; for example, if an excutable is signed it can |
| 87 // decode and show the publisher and the certificate. | 86 // decode and show the publisher and the certificate. |
| 88 hr = attachment_services->Prompt(hwnd, ATTACHMENT_PROMPT_EXEC, &action); | 87 hr = attachment_services->Prompt(hwnd, ATTACHMENT_PROMPT_EXEC, &action); |
| 89 if (FAILED(hr) || (ATTACHMENT_ACTION_CANCEL == action)) | 88 if (FAILED(hr) || (ATTACHMENT_ACTION_CANCEL == action)) |
| 90 { | 89 { |
| 91 // The user has declined opening the item. | 90 // The user has declined opening the item. |
| 92 return false; | 91 return false; |
| 93 } | 92 } |
| 94 } | 93 } |
| 95 return OpenItemViaShellNoZoneCheck(full_path, ask_for_app); | 94 return OpenItemViaShellNoZoneCheck(full_path); |
| 96 } | 95 } |
| 97 | 96 |
| 98 bool SetInternetZoneIdentifier(const FilePath& full_path) { | 97 bool SetInternetZoneIdentifier(const FilePath& full_path) { |
| 99 const DWORD kShare = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; | 98 const DWORD kShare = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; |
| 100 std::wstring path = full_path.value() + L":Zone.Identifier"; | 99 std::wstring path = full_path.value() + L":Zone.Identifier"; |
| 101 HANDLE file = CreateFile(path.c_str(), GENERIC_WRITE, kShare, NULL, | 100 HANDLE file = CreateFile(path.c_str(), GENERIC_WRITE, kShare, NULL, |
| 102 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | 101 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); |
| 103 if (INVALID_HANDLE_VALUE == file) | 102 if (INVALID_HANDLE_VALUE == file) |
| 104 return false; | 103 return false; |
| 105 | 104 |
| 106 const char kIdentifier[] = "[ZoneTransfer]\nZoneId=3"; | 105 const char kIdentifier[] = "[ZoneTransfer]\nZoneId=3"; |
| 107 DWORD written = 0; | 106 DWORD written = 0; |
| 108 BOOL result = WriteFile(file, kIdentifier, arraysize(kIdentifier), &written, | 107 BOOL result = WriteFile(file, kIdentifier, arraysize(kIdentifier), &written, |
| 109 NULL); | 108 NULL); |
| 110 CloseHandle(file); | 109 CloseHandle(file); |
| 111 | 110 |
| 112 if (!result || written != arraysize(kIdentifier)) { | 111 if (!result || written != arraysize(kIdentifier)) { |
| 113 DCHECK(FALSE); | 112 DCHECK(FALSE); |
| 114 return false; | 113 return false; |
| 115 } | 114 } |
| 116 | 115 |
| 117 return true; | 116 return true; |
| 118 } | 117 } |
| 119 | 118 |
| 120 } // namespace win_util | 119 } // namespace win_util |
| OLD | NEW |