diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-15 15:40:45 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-15 15:40:45 +0000 |
commit | 56f762c6574feac5c7bc6fb3f7c80ca140c73566 (patch) | |
tree | 9bb34b2f89605a042943a5c4a3fe9cf21aaa6da3 /chrome | |
parent | c1a547a74766412c821a757c624187d7f4223a79 (diff) | |
download | chromium_src-56f762c6574feac5c7bc6fb3f7c80ca140c73566.zip chromium_src-56f762c6574feac5c7bc6fb3f7c80ca140c73566.tar.gz chromium_src-56f762c6574feac5c7bc6fb3f7c80ca140c73566.tar.bz2 |
Move dependencies of download\base_file from chrome to content. These are all trivial file moves.
BUG=82782
Review URL: http://codereview.chromium.org/7388002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92695 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/mac/file_metadata.h | 29 | ||||
-rw-r--r-- | chrome/browser/mac/file_metadata.mm | 167 | ||||
-rw-r--r-- | chrome/browser/power_save_blocker.h | 42 | ||||
-rw-r--r-- | chrome/browser/power_save_blocker_common.cc | 57 | ||||
-rw-r--r-- | chrome/browser/power_save_blocker_mac.cc | 64 | ||||
-rw-r--r-- | chrome/browser/power_save_blocker_stub.cc | 11 | ||||
-rw-r--r-- | chrome/browser/power_save_blocker_win.cc | 21 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 7 | ||||
-rw-r--r-- | chrome/chrome_common.gypi | 2 | ||||
-rw-r--r-- | chrome/common/win_safe_util.cc | 155 | ||||
-rw-r--r-- | chrome/common/win_safe_util.h | 56 |
11 files changed, 0 insertions, 611 deletions
diff --git a/chrome/browser/mac/file_metadata.h b/chrome/browser/mac/file_metadata.h deleted file mode 100644 index 17a59e8..0000000 --- a/chrome/browser/mac/file_metadata.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_MAC_FILE_METADATA_H_ -#define CHROME_BROWSER_MAC_FILE_METADATA_H_ -#pragma once - -class FilePath; -class GURL; - -namespace file_metadata { - -// Adds origin metadata to the file. -// |source| should be the source URL for the download, and |referrer| should be -// the URL the user initiated the download from. -void AddOriginMetadataToFile(const FilePath& file, const GURL& source, - const GURL& referrer); - -// Adds quarantine metadata to the file, assuming it has already been -// quarantined by the OS. -// |source| should be the source URL for the download, and |referrer| should be -// the URL the user initiated the download from. -void AddQuarantineMetadataToFile(const FilePath& file, const GURL& source, - const GURL& referrer); - -} // namespace file_metadata - -#endif // CHROME_BROWSER_MAC_FILE_METADATA_H_ diff --git a/chrome/browser/mac/file_metadata.mm b/chrome/browser/mac/file_metadata.mm deleted file mode 100644 index 2775259..0000000 --- a/chrome/browser/mac/file_metadata.mm +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/mac/file_metadata.h" - -#include <ApplicationServices/ApplicationServices.h> -#include <Foundation/Foundation.h> - -#include "base/file_path.h" -#include "base/logging.h" -#include "base/mac/mac_util.h" -#include "base/mac/scoped_cftyperef.h" -#include "googleurl/src/gurl.h" - -namespace file_metadata { - -// As of Mac OS X 10.4 ("Tiger"), files can be tagged with metadata describing -// various attributes. Metadata is integrated with the system's Spotlight -// feature and is searchable. Ordinarily, metadata can only be set by -// Spotlight importers, which requires that the importer own the target file. -// However, there's an attribute intended to describe the origin of a -// file, that can store the source URL and referrer of a downloaded file. -// It's stored as a "com.apple.metadata:kMDItemWhereFroms" extended attribute, -// structured as a binary1-format plist containing a list of sources. This -// attribute can only be populated by the downloader, not a Spotlight importer. -// Safari on 10.4 and later populates this attribute. -// -// With this metadata set, you can locate downloads by performing a Spotlight -// search for their source or referrer URLs, either from within the Spotlight -// UI or from the command line: -// mdfind 'kMDItemWhereFroms == "http://releases.mozilla.org/*"' -// -// There is no documented API to set metadata on a file directly as of the -// 10.5 SDK. The MDSetItemAttribute function does exist to perform this task, -// but it's undocumented. -void AddOriginMetadataToFile(const FilePath& file, const GURL& source, - const GURL& referrer) { - // There's no declaration for MDItemSetAttribute in any known public SDK. - // It exists in the 10.4 and 10.5 runtimes. To play it safe, do the lookup - // at runtime instead of declaring it ourselves and linking against what's - // provided. This has two benefits: - // - If Apple relents and declares the function in a future SDK (it's - // happened before), our build won't break. - // - If Apple removes or renames the function in a future runtime, the - // loader won't refuse to let the application launch. Instead, we'll - // silently fail to set any metadata. - typedef OSStatus (*MDItemSetAttribute_type)(MDItemRef, CFStringRef, - CFTypeRef); - static MDItemSetAttribute_type md_item_set_attribute_func = NULL; - - static bool did_symbol_lookup = false; - if (!did_symbol_lookup) { - did_symbol_lookup = true; - CFBundleRef metadata_bundle = - CFBundleGetBundleWithIdentifier(CFSTR("com.apple.Metadata")); - if (!metadata_bundle) - return; - - md_item_set_attribute_func = (MDItemSetAttribute_type) - CFBundleGetFunctionPointerForName(metadata_bundle, - CFSTR("MDItemSetAttribute")); - } - if (!md_item_set_attribute_func) - return; - - NSString* file_path = - [NSString stringWithUTF8String:file.value().c_str()]; - if (!file_path) - return; - - base::mac::ScopedCFTypeRef<MDItemRef> md_item( - MDItemCreate(NULL, base::mac::NSToCFCast(file_path))); - if (!md_item) - return; - - // We won't put any more than 2 items into the attribute. - NSMutableArray* list = [NSMutableArray arrayWithCapacity:2]; - - // Follow Safari's lead: the first item in the list is the source URL of - // the downloaded file. If the referrer is known, store that, too. - NSString* origin_url = [NSString stringWithUTF8String:source.spec().c_str()]; - if (origin_url) - [list addObject:origin_url]; - NSString* referrer_url = - [NSString stringWithUTF8String:referrer.spec().c_str()]; - if (referrer_url) - [list addObject:referrer_url]; - - md_item_set_attribute_func(md_item, kMDItemWhereFroms, - base::mac::NSToCFCast(list)); -} - -// The OS will automatically quarantine files due to the -// LSFileQuarantineEnabled entry in our Info.plist, but it knows relatively -// little about the files. We add more information about the download to -// improve the UI shown by the OS when the users tries to open the file. -void AddQuarantineMetadataToFile(const FilePath& file, const GURL& source, - const GURL& referrer) { - FSRef file_ref; - if (!base::mac::FSRefFromPath(file.value(), &file_ref)) - return; - - NSMutableDictionary* quarantine_properties = nil; - CFTypeRef quarantine_properties_base = NULL; - if (LSCopyItemAttribute(&file_ref, kLSRolesAll, kLSItemQuarantineProperties, - &quarantine_properties_base) == noErr) { - if (CFGetTypeID(quarantine_properties_base) == - CFDictionaryGetTypeID()) { - // Quarantine properties will already exist if LSFileQuarantineEnabled - // is on and the file doesn't match an exclusion. - quarantine_properties = - [[(NSDictionary*)quarantine_properties_base mutableCopy] autorelease]; - } else { - LOG(WARNING) << "kLSItemQuarantineProperties is not a dictionary on file " - << file.value(); - } - CFRelease(quarantine_properties_base); - } - - if (!quarantine_properties) { - // If there are no quarantine properties, then the file isn't quarantined - // (e.g., because the user has set up exclusions for certain file types). - // We don't want to add any metadata, because that will cause the file to - // be quarantined against the user's wishes. - return; - } - - // kLSQuarantineAgentNameKey, kLSQuarantineAgentBundleIdentifierKey, and - // kLSQuarantineTimeStampKey are set for us (see LSQuarantine.h), so we only - // need to set the values that the OS can't infer. - - if (![quarantine_properties valueForKey:(NSString*)kLSQuarantineTypeKey]) { - CFStringRef type = (source.SchemeIs("http") || source.SchemeIs("https")) - ? kLSQuarantineTypeWebDownload - : kLSQuarantineTypeOtherDownload; - [quarantine_properties setValue:(NSString*)type - forKey:(NSString*)kLSQuarantineTypeKey]; - } - - if (![quarantine_properties - valueForKey:(NSString*)kLSQuarantineOriginURLKey] && - referrer.is_valid()) { - NSString* referrer_url = - [NSString stringWithUTF8String:referrer.spec().c_str()]; - [quarantine_properties setValue:referrer_url - forKey:(NSString*)kLSQuarantineOriginURLKey]; - } - - if (![quarantine_properties valueForKey:(NSString*)kLSQuarantineDataURLKey] && - source.is_valid()) { - NSString* origin_url = - [NSString stringWithUTF8String:source.spec().c_str()]; - [quarantine_properties setValue:origin_url - forKey:(NSString*)kLSQuarantineDataURLKey]; - } - - OSStatus os_error = LSSetItemAttribute(&file_ref, kLSRolesAll, - kLSItemQuarantineProperties, - quarantine_properties); - if (os_error != noErr) { - LOG(WARNING) << "Unable to set quarantine attributes on file " - << file.value(); - } -} - -} // namespace file_metadata diff --git a/chrome/browser/power_save_blocker.h b/chrome/browser/power_save_blocker.h deleted file mode 100644 index d8aa34c..0000000 --- a/chrome/browser/power_save_blocker.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_POWER_SAVE_BLOCKER_H_ -#define CHROME_BROWSER_POWER_SAVE_BLOCKER_H_ -#pragma once - -#include "base/basictypes.h" - -// A RAII-style class to block the system from entering low-power (sleep) mode. -class PowerSaveBlocker { - public: - explicit PowerSaveBlocker(bool enabled); - ~PowerSaveBlocker(); - - bool enabled() const { return enabled_; } - - // Puts the sleep mode block into effect. - void Enable(); - // Disables the sleep block. - void Disable(); - - private: - // Platform-specific function called when enable state is changed. - // Guaranteed to be called only from the UI thread. - static void ApplyBlock(bool blocked); - - // Called only from UI thread. - static void AdjustBlockCount(int delta); - - // Invokes AdjustBlockCount on the UI thread. - static void PostAdjustBlockCount(int delta); - - bool enabled_; - - static int blocker_count_; - - DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker); -}; - -#endif // CHROME_BROWSER_POWER_SAVE_BLOCKER_H_ diff --git a/chrome/browser/power_save_blocker_common.cc b/chrome/browser/power_save_blocker_common.cc deleted file mode 100644 index 9fcfd7e..0000000 --- a/chrome/browser/power_save_blocker_common.cc +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/power_save_blocker.h" -#include "content/browser/browser_thread.h" - -// Accessed only from the UI thread. -int PowerSaveBlocker::blocker_count_ = 0; - -PowerSaveBlocker::PowerSaveBlocker(bool enable) : enabled_(false) { - if (enable) - Enable(); -} - -PowerSaveBlocker::~PowerSaveBlocker(void) { - Disable(); -} - -void PowerSaveBlocker::Enable() { - if (enabled_) - return; - - enabled_ = true; - PostAdjustBlockCount(1); -} - -void PowerSaveBlocker::Disable() { - if (!enabled_) - return; - - enabled_ = false; - PostAdjustBlockCount(-1); -} - - -void PowerSaveBlocker::PostAdjustBlockCount(int delta) { - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - NewRunnableFunction(&PowerSaveBlocker::AdjustBlockCount, delta)); -} - -// Called only from UI thread. -void PowerSaveBlocker::AdjustBlockCount(int delta) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - bool was_blocking = (blocker_count_ != 0); - - blocker_count_ += delta; - - bool is_blocking = (blocker_count_ != 0); - - DCHECK_GE(blocker_count_, 0); - - if (is_blocking != was_blocking) - ApplyBlock(is_blocking); -} diff --git a/chrome/browser/power_save_blocker_mac.cc b/chrome/browser/power_save_blocker_mac.cc deleted file mode 100644 index da48052..0000000 --- a/chrome/browser/power_save_blocker_mac.cc +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/power_save_blocker.h" - -#include <IOKit/pwr_mgt/IOPMLib.h> - -#include "base/threading/platform_thread.h" -#include "base/threading/thread.h" -#include "content/browser/browser_thread.h" - -namespace { - -// Power management cannot be done on the UI thread. IOPMAssertionCreate does a -// synchronous MIG call to configd, so if it is called on the main thread the UI -// is at the mercy of another process. See http://crbug.com/79559 and -// http://www.opensource.apple.com/source/IOKitUser/IOKitUser-514.16.31/pwr_mgt.subproj/IOPMLibPrivate.c . -base::Thread* g_power_thread; -IOPMAssertionID g_power_assertion; - -void CreateSleepAssertion() { - DCHECK_EQ(base::PlatformThread::CurrentId(), g_power_thread->thread_id()); - IOReturn result; - DCHECK_EQ(g_power_assertion, kIOPMNullAssertionID); - - // Block just idle sleep; allow display sleep. - // See QA1340 <http://developer.apple.com/library/mac/#qa/qa2004/qa1340.html> - // for more details. - result = IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, - kIOPMAssertionLevelOn, - &g_power_assertion); - LOG_IF(ERROR, result != kIOReturnSuccess) - << "IOPMAssertionCreate: " << result; -} - -void ReleaseSleepAssertion() { - DCHECK_EQ(base::PlatformThread::CurrentId(), g_power_thread->thread_id()); - IOReturn result; - DCHECK_NE(g_power_assertion, kIOPMNullAssertionID); - result = IOPMAssertionRelease(g_power_assertion); - g_power_assertion = kIOPMNullAssertionID; - LOG_IF(ERROR, result != kIOReturnSuccess) - << "IOPMAssertionRelease: " << result; -} - -} // namespace - -// Called only from UI thread. -void PowerSaveBlocker::ApplyBlock(bool blocking) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - if (!g_power_thread) { - g_power_assertion = kIOPMNullAssertionID; - g_power_thread = new base::Thread("PowerSaveBlocker"); - g_power_thread->Start(); - } - - MessageLoop* loop = g_power_thread->message_loop(); - if (blocking) - loop->PostTask(FROM_HERE, NewRunnableFunction(CreateSleepAssertion)); - else - loop->PostTask(FROM_HERE, NewRunnableFunction(ReleaseSleepAssertion)); -} diff --git a/chrome/browser/power_save_blocker_stub.cc b/chrome/browser/power_save_blocker_stub.cc deleted file mode 100644 index 2c1a7e3..0000000 --- a/chrome/browser/power_save_blocker_stub.cc +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/power_save_blocker.h" - -// Default, stub implementation, for platforms that don't have their own yet. - -void PowerSaveBlocker::ApplyBlock(bool blocking) { - // http://code.google.com/p/chromium/issues/detail?id=33605 -} diff --git a/chrome/browser/power_save_blocker_win.cc b/chrome/browser/power_save_blocker_win.cc deleted file mode 100644 index 318aa99..0000000 --- a/chrome/browser/power_save_blocker_win.cc +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/power_save_blocker.h" - -#include <windows.h> - -#include "content/browser/browser_thread.h" - -// Runs on UI thread only. -void PowerSaveBlocker::ApplyBlock(bool blocking) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - DWORD flags = ES_CONTINUOUS; - - if (blocking) - flags |= ES_SYSTEM_REQUIRED; - - SetThreadExecutionState(flags); -} diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index e0671b8..afb8c08 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1347,8 +1347,6 @@ 'browser/language_order_table_model.h', 'browser/mac/authorization_util.h', 'browser/mac/authorization_util.mm', - 'browser/mac/file_metadata.h', - 'browser/mac/file_metadata.mm', 'browser/mac/install_from_dmg.h', 'browser/mac/install_from_dmg.mm', 'browser/mac/keystone_glue.h', @@ -1652,11 +1650,6 @@ '<(protoc_out_dir)/chrome/browser/policy/proto/device_management_local.pb.h', 'browser/possible_url_model.cc', 'browser/possible_url_model.h', - 'browser/power_save_blocker.h', - 'browser/power_save_blocker_common.cc', - 'browser/power_save_blocker_mac.cc', - 'browser/power_save_blocker_stub.cc', - 'browser/power_save_blocker_win.cc', 'browser/preferences_mac.cc', 'browser/preferences_mac.h', 'browser/prefs/browser_prefs.cc', diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 94b54b4..a6ddcd2 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -77,8 +77,6 @@ 'common/switch_utils.h', 'common/time_format.cc', 'common/time_format.h', - 'common/win_safe_util.cc', - 'common/win_safe_util.h', ], }], ], diff --git a/chrome/common/win_safe_util.cc b/chrome/common/win_safe_util.cc deleted file mode 100644 index 2a5813a..0000000 --- a/chrome/common/win_safe_util.cc +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <shlobj.h> -#include <shobjidl.h> - -#include "chrome/common/win_safe_util.h" - -#include "base/file_path.h" -#include "base/logging.h" -#include "base/path_service.h" -#include "base/string_util.h" -#include "base/win/scoped_comptr.h" -#include "ui/base/win/shell.h" - -namespace { - -// This GUID is associated with any 'don't ask me again' settings that the -// user can select for different file types. -// {2676A9A2-D919-4fee-9187-152100393AB2} -static const GUID kClientID = { 0x2676a9a2, 0xd919, 0x4fee, - { 0x91, 0x87, 0x15, 0x21, 0x0, 0x39, 0x3a, 0xb2 } }; - -// Directly writes the ZoneIdentifier stream, without using the -// IAttachmentExecute service. -bool SetInternetZoneIdentifierDirectly(const FilePath& full_path) { - const DWORD kShare = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; - std::wstring path = full_path.value() + L":Zone.Identifier"; - HANDLE file = CreateFile(path.c_str(), GENERIC_WRITE, kShare, NULL, - OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if (INVALID_HANDLE_VALUE == file) - return false; - - static const char kIdentifier[] = "[ZoneTransfer]\r\nZoneId=3\r\n"; - // Don't include trailing null in data written. - static const DWORD kIdentifierSize = arraysize(kIdentifier) - 1; - DWORD written = 0; - BOOL result = WriteFile(file, kIdentifier, kIdentifierSize, &written, - NULL); - BOOL flush_result = FlushFileBuffers(file); - CloseHandle(file); - - if (!result || !flush_result || written != kIdentifierSize) { - NOTREACHED(); - return false; - } - - return true; -} - -} - -namespace win_util { - -// This function implementation is based on the attachment execution -// services functionally deployed with IE6 or Service pack 2. This -// functionality is exposed in the IAttachmentExecute COM interface. -// more information at: -// http://msdn2.microsoft.com/en-us/library/ms647048.aspx -bool SaferOpenItemViaShell(HWND hwnd, const std::wstring& window_title, - const FilePath& full_path, - const std::wstring& source_url) { - base::win::ScopedComPtr<IAttachmentExecute> attachment_services; - HRESULT hr = attachment_services.CreateInstance(CLSID_AttachmentServices); - if (FAILED(hr)) { - // We don't have Attachment Execution Services, it must be a pre-XP.SP2 - // Windows installation, or the thread does not have COM initialized. - if (hr == CO_E_NOTINITIALIZED) { - NOTREACHED(); - return false; - } - return ui::win::OpenItemViaShell(full_path); - } - - attachment_services->SetClientGuid(kClientID); - - if (!window_title.empty()) - attachment_services->SetClientTitle(window_title.c_str()); - - // To help windows decide if the downloaded file is dangerous we can provide - // what the documentation calls evidence. Which we provide now: - // - // Set the file itself as evidence. - hr = attachment_services->SetLocalPath(full_path.value().c_str()); - if (FAILED(hr)) - return false; - // Set the origin URL as evidence. - hr = attachment_services->SetSource(source_url.c_str()); - if (FAILED(hr)) - return false; - - // Now check the windows policy. - if (attachment_services->CheckPolicy() != S_OK) { - // It is possible that the above call returns an undocumented result - // equal to 0x800c000e which seems to indicate that the URL failed the - // the security check. If you proceed with the Prompt() call the - // Shell might show a dialog that says: - // "windows found that this file is potentially harmful. To help protect - // your computer, Windows has blocked access to this file." - // Upon dismissal of the dialog windows will delete the file (!!). - // So, we can 'return' in that case but maybe is best to let it happen to - // fail on the safe side. - - ATTACHMENT_ACTION action; - // We cannot control what the prompt says or does directly but it - // is a pretty decent dialog; for example, if an executable is signed it can - // decode and show the publisher and the certificate. - hr = attachment_services->Prompt(hwnd, ATTACHMENT_PROMPT_EXEC, &action); - if (FAILED(hr) || (ATTACHMENT_ACTION_CANCEL == action)) { - // The user has declined opening the item. - return false; - } - } - return ui::win::OpenItemViaShellNoZoneCheck(full_path); -} - -bool SetInternetZoneIdentifier(const FilePath& full_path, - const std::wstring& source_url) { - base::win::ScopedComPtr<IAttachmentExecute> attachment_services; - HRESULT hr = attachment_services.CreateInstance(CLSID_AttachmentServices); - - if (FAILED(hr)) { - // We don't have Attachment Execution Services, it must be a pre-XP.SP2 - // Windows installation, or the thread does not have COM initialized. - if (hr == CO_E_NOTINITIALIZED) { - NOTREACHED(); - return false; - } - - // Write the ZoneIdentifier file directly. - return SetInternetZoneIdentifierDirectly(full_path); - } - - hr = attachment_services->SetClientGuid(kClientID); - if (FAILED(hr)) - return false; - - hr = attachment_services->SetLocalPath(full_path.value().c_str()); - if (FAILED(hr)) - return false; - - // Source is necessary for files ending in ".tmp" to avoid error 0x800c000e. - hr = attachment_services->SetSource(source_url.c_str()); - if (FAILED(hr)) - return false; - - hr = attachment_services->Save(); - if (FAILED(hr)) - return false; - - return true; -} - -} // namespace win_util diff --git a/chrome/common/win_safe_util.h b/chrome/common/win_safe_util.h deleted file mode 100644 index 424e8f8..0000000 --- a/chrome/common/win_safe_util.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_COMMON_WIN_SAFE_UTIL_H_ -#define CHROME_COMMON_WIN_SAFE_UTIL_H_ -#pragma once - -#include <string> -#include <windows.h> - -class FilePath; - -namespace win_util { - -// Open or run a downloaded file via the Windows shell, possibly showing first -// a consent dialog if the the file is deemed dangerous. This function is an -// enhancement over the OpenItemViaShell() function of win_util.h. -// -// The user consent dialog will be shown or not according to the windows -// execution policy defined in the registry which can be overridden per user. -// The mechanics of the policy are explained in the Microsoft Knowledge base -// number 883260: http://support.microsoft.com/kb/883260 -// -// The 'hwnd' is the handle to the parent window. In case a dialog is displayed -// the parent window will be disabled since the dialog is meant to be modal. -// The 'window_title' is the text displayed on the title bar of the dialog. If -// you pass an empty string the dialog will have a generic 'windows security' -// name on the title bar. -// -// You must provide a valid 'full_path' to the file to be opened and a well -// formed url in 'source_url'. The url should identify the source of the file -// but does not have to be network-reachable. If the url is malformed a -// dialog will be shown telling the user that the file will be blocked. -// -// In the event that there is no default application registered for the file -// specified by 'full_path' it ask the user, via the Windows "Open With" -// dialog. -// Returns 'true' on successful open, 'false' otherwise. -bool SaferOpenItemViaShell(HWND hwnd, const std::wstring& window_title, - const FilePath& full_path, - const std::wstring& source_url); - -// Sets the Zone Identifier on the file to "Internet" (3). Returns true if the -// function succeeds, false otherwise. A failure is expected on system where -// the Zone Identifier is not supported, like a machine with a FAT32 filesystem. -// It should not be considered fatal. -// -// |full_path| is the path to save the file to, and -// |source_url| is the URL where the file was downloaded from. -bool SetInternetZoneIdentifier(const FilePath& full_path, - const std::wstring& source_url); - -} // namespace win_util - -#endif // CHROME_COMMON_WIN_SAFE_UTIL_H_ |