cef/libcef/browser/download_manager_delegate_w...

43 lines
1.4 KiB
C++

// Copyright (c) 2012 The Chromium Embedded Framework Authors.
// Portions 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 "libcef/browser/download_manager_delegate.h"
#include <commdlg.h>
#include <windows.h>
#include "base/string_util.h"
#include "content/public/browser/web_contents.h"
// static
FilePath CefDownloadManagerDelegate::PlatformChooseDownloadPath(
content::WebContents* web_contents,
const FilePath& suggested_path) {
FilePath result;
std::wstring file_part = FilePath(suggested_path).BaseName().value();
wchar_t file_name[MAX_PATH];
base::wcslcpy(file_name, file_part.c_str(), arraysize(file_name));
OPENFILENAME save_as;
ZeroMemory(&save_as, sizeof(save_as));
save_as.lStructSize = sizeof(OPENFILENAME);
save_as.hwndOwner = web_contents->GetNativeView();
save_as.lpstrFile = file_name;
save_as.nMaxFile = arraysize(file_name);
std::wstring directory;
if (!suggested_path.empty())
directory = suggested_path.DirName().value();
save_as.lpstrInitialDir = directory.c_str();
save_as.Flags = OFN_OVERWRITEPROMPT | OFN_EXPLORER | OFN_ENABLESIZING |
OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST;
if (GetSaveFileName(&save_as))
result = FilePath(std::wstring(save_as.lpstrFile));
return result;
}