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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_COMMON_WIN_SAFE_UTIL_H__ 6 #define CHROME_COMMON_WIN_SAFE_UTIL_H__ 7 #pragma once 8 9 #include <string> 10 #include <windows.h> 11 12 class FilePath; 13 14 namespace win_util { 15 16 // Open or run a downloaded file via the Windows shell, possibly showing first 17 // a consent dialog if the the file is deemed dangerous. This function is an 18 // enhancement over the OpenItemViaShell() function of win_util.h. 19 // 20 // The user consent dialog will be shown or not according to the windows 21 // execution policy defined in the registry which can be overridden per user. 22 // The mechanics of the policy are explained in the Microsoft Knowledge base 23 // number 883260: http://support.microsoft.com/kb/883260 24 // 25 // The 'hwnd' is the handle to the parent window. In case a dialog is displayed 26 // the parent window will be disabled since the dialog is meant to be modal. 27 // The 'window_title' is the text displayed on the title bar of the dialog. If 28 // you pass an empty string the dialog will have a generic 'windows security' 29 // name on the title bar. 30 // 31 // You must provide a valid 'full_path' to the file to be opened and a well 32 // formed url in 'source_url'. The url should identify the source of the file 33 // but does not have to be network-reachable. If the url is malformed a 34 // dialog will be shown telling the user that the file will be blocked. 35 // 36 // In the event that there is no default application registered for the file 37 // specified by 'full_path' it ask the user, via the Windows "Open With" 38 // dialog. 39 // Returns 'true' on successful open, 'false' otherwise. 40 bool SaferOpenItemViaShell(HWND hwnd, const std::wstring& window_title, 41 const FilePath& full_path, 42 const std::wstring& source_url); 43 44 // Sets the Zone Identifier on the file to "Internet" (3). Returns true if the 45 // function succeeds, false otherwise. A failure is expected on system where 46 // the Zone Identifier is not supported, like a machine with a FAT32 filesystem. 47 // It should not be considered fatal. 48 bool SetInternetZoneIdentifier(const FilePath& full_path); 49 50 } // namespace win_util 51 52 #endif // CHROME_COMMON_WIN_SAFE_UTIL_H_ 53