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

Side by Side Diff: content/browser/safe_util_win.cc

Issue 21355004: [Downloads] Move client guid for AV scanning of downloaded files to chrome/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: base updates Created 7 years, 4 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
« base/file_util.h ('K') | « content/browser/safe_util_win.h ('k') | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 7
8 #include "content/browser/safe_util_win.h" 8 #include "content/browser/safe_util_win.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/path_service.h"
13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "base/win/scoped_comptr.h" 12 #include "base/win/scoped_comptr.h"
16 #include "ui/base/win/shell.h" 13 #include "ui/base/win/shell.h"
17 #include "url/gurl.h"
18 14
19 namespace content { 15 namespace content {
20 namespace { 16 namespace {
21 17
22 // This GUID is associated with any 'don't ask me again' settings that the 18 // This GUID is associated with any 'don't ask me again' settings that the
23 // user can select for different file types. 19 // user can select for different file types.
24 // {2676A9A2-D919-4fee-9187-152100393AB2} 20 // {2676A9A2-D919-4fee-9187-152100393AB2}
25 static const GUID kClientID = { 0x2676a9a2, 0xd919, 0x4fee, 21 const GUID kClientID = { 0x2676a9a2, 0xd919, 0x4fee,
26 { 0x91, 0x87, 0x15, 0x21, 0x0, 0x39, 0x3a, 0xb2 } }; 22 { 0x91, 0x87, 0x15, 0x21, 0x0, 0x39, 0x3a, 0xb2 } };
27 23
28 // Sets the Zone Identifier on the file to "Internet" (3). Returns true if the
29 // function succeeds, false otherwise. A failure is expected on system where
30 // the Zone Identifier is not supported, like a machine with a FAT32 filesystem.
31 // This function does not invoke Windows Attachment Execution Services.
32 //
33 // |full_path| is the path to the downloaded file.
34 bool SetInternetZoneIdentifierDirectly(const base::FilePath& full_path) {
35 const DWORD kShare = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
36 std::wstring path = full_path.value() + L":Zone.Identifier";
37 HANDLE file = CreateFile(path.c_str(), GENERIC_WRITE, kShare, NULL,
38 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
39 if (INVALID_HANDLE_VALUE == file)
40 return false;
41
42 static const char kIdentifier[] = "[ZoneTransfer]\r\nZoneId=3\r\n";
43 // Don't include trailing null in data written.
44 static const DWORD kIdentifierSize = arraysize(kIdentifier) - 1;
45 DWORD written = 0;
46 BOOL result = WriteFile(file, kIdentifier, kIdentifierSize, &written, NULL);
47 BOOL flush_result = FlushFileBuffers(file);
48 CloseHandle(file);
49
50 if (!result || !flush_result || written != kIdentifierSize) {
51 NOTREACHED();
52 return false;
53 }
54
55 return true;
56 }
57
58 } 24 }
59 25
60 // This function implementation is based on the attachment execution 26 // This function implementation is based on the attachment execution
61 // services functionally deployed with IE6 or Service pack 2. This 27 // services functionally deployed with IE6 or Service pack 2. This
62 // functionality is exposed in the IAttachmentExecute COM interface. 28 // functionality is exposed in the IAttachmentExecute COM interface.
63 // more information at: 29 // more information at:
64 // http://msdn2.microsoft.com/en-us/library/ms647048.aspx 30 // http://msdn2.microsoft.com/en-us/library/ms647048.aspx
65 bool SaferOpenItemViaShell(HWND hwnd, const std::wstring& window_title, 31 bool SaferOpenItemViaShell(HWND hwnd, const std::wstring& window_title,
jam 2013/08/06 17:32:31 btw this isn't used anywhere. so just delete this
Greg Billock 2013/08/06 22:07:21 OK, sounds good.
66 const base::FilePath& full_path, 32 const base::FilePath& full_path,
67 const std::wstring& source_url) { 33 const std::wstring& source_url) {
68 base::win::ScopedComPtr<IAttachmentExecute> attachment_services; 34 base::win::ScopedComPtr<IAttachmentExecute> attachment_services;
69 HRESULT hr = attachment_services.CreateInstance(CLSID_AttachmentServices); 35 HRESULT hr = attachment_services.CreateInstance(CLSID_AttachmentServices);
70 if (FAILED(hr)) { 36 if (FAILED(hr)) {
71 // We don't have Attachment Execution Services, it must be a pre-XP.SP2 37 // We don't have Attachment Execution Services, it must be a pre-XP.SP2
72 // Windows installation, or the thread does not have COM initialized. 38 // Windows installation, or the thread does not have COM initialized.
73 if (hr == CO_E_NOTINITIALIZED) { 39 if (hr == CO_E_NOTINITIALIZED) {
74 NOTREACHED(); 40 NOTREACHED();
75 return false; 41 return false;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // decode and show the publisher and the certificate. 78 // decode and show the publisher and the certificate.
113 hr = attachment_services->Prompt(hwnd, ATTACHMENT_PROMPT_EXEC, &action); 79 hr = attachment_services->Prompt(hwnd, ATTACHMENT_PROMPT_EXEC, &action);
114 if (FAILED(hr) || (ATTACHMENT_ACTION_CANCEL == action)) { 80 if (FAILED(hr) || (ATTACHMENT_ACTION_CANCEL == action)) {
115 // The user has declined opening the item. 81 // The user has declined opening the item.
116 return false; 82 return false;
117 } 83 }
118 } 84 }
119 return ui::win::OpenItemViaShellNoZoneCheck(full_path); 85 return ui::win::OpenItemViaShellNoZoneCheck(full_path);
120 } 86 }
121 87
122 HRESULT ScanAndSaveDownloadedFile(const base::FilePath& full_path,
123 const GURL& source_url) {
124 base::win::ScopedComPtr<IAttachmentExecute> attachment_services;
125 HRESULT hr = attachment_services.CreateInstance(CLSID_AttachmentServices);
126
127 if (FAILED(hr)) {
128 // The thread must have COM initialized.
129 DCHECK_NE(CO_E_NOTINITIALIZED, hr);
130
131 // We don't have Attachment Execution Services, it must be a pre-XP.SP2
132 // Windows installation, or the thread does not have COM initialized. Try to
133 // set the zone information directly. Failure is not considered an error.
134 SetInternetZoneIdentifierDirectly(full_path);
135 return hr;
136 }
137
138 hr = attachment_services->SetClientGuid(kClientID);
139 if (FAILED(hr))
140 return hr;
141
142 hr = attachment_services->SetLocalPath(full_path.value().c_str());
143 if (FAILED(hr))
144 return hr;
145
146 hr = attachment_services->SetSource(UTF8ToWide(source_url.spec()).c_str());
147 if (FAILED(hr))
148 return hr;
149
150 // A failure in the Save() call below could result in the downloaded file
151 // being deleted.
152 return attachment_services->Save();
153 }
154
155 } // namespace content 88 } // namespace content
OLDNEW
« base/file_util.h ('K') | « content/browser/safe_util_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698