alloy: Fix crash when downloading a modified PDF form (see issue #3169)

Create a CefFileSystemDelegate based on the ShellFileSystemDelegate placeholder
implementation. An actual implementation will still be required to properly
support this download functionality.
This commit is contained in:
Cristian Amarie
2021-08-19 22:05:52 +03:00
committed by Marshall Greenblatt
parent 318f46bf46
commit eac16430da
5 changed files with 142 additions and 0 deletions

View File

@ -0,0 +1,71 @@
// Copyright 2017 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/extensions/api/file_system/cef_file_system_delegate.h"
#include "apps/saved_files_service.h"
#include "base/callback.h"
#include "base/callback_forward.h"
#include "base/files/file_path.h"
#include "extensions/common/api/file_system.h"
#include "extensions/common/extension.h"
namespace extensions {
namespace cef {
CefFileSystemDelegate::CefFileSystemDelegate() = default;
CefFileSystemDelegate::~CefFileSystemDelegate() = default;
base::FilePath CefFileSystemDelegate::GetDefaultDirectory() {
return base::FilePath();
}
base::FilePath CefFileSystemDelegate::GetManagedSaveAsDirectory(
content::BrowserContext* browser_context,
const Extension& extension) {
return base::FilePath();
}
bool CefFileSystemDelegate::ShowSelectFileDialog(
scoped_refptr<ExtensionFunction> extension_function,
ui::SelectFileDialog::Type type,
const base::FilePath& default_path,
const ui::SelectFileDialog::FileTypeInfo* file_types,
FileSystemDelegate::FilesSelectedCallback files_selected_callback,
base::OnceClosure file_selection_canceled_callback) {
NOTIMPLEMENTED();
// Run the cancel callback by default.
std::move(file_selection_canceled_callback).Run();
// Return true since this isn't a disallowed call, just not implemented.
return true;
}
void CefFileSystemDelegate::ConfirmSensitiveDirectoryAccess(
bool has_write_permission,
const std::u16string& app_name,
content::WebContents* web_contents,
base::OnceClosure on_accept,
base::OnceClosure on_cancel) {
NOTIMPLEMENTED();
// Run the cancel callback by default.
std::move(on_cancel).Run();
}
int CefFileSystemDelegate::GetDescriptionIdForAcceptType(
const std::string& accept_type) {
NOTIMPLEMENTED();
return 0;
}
SavedFilesServiceInterface* CefFileSystemDelegate::GetSavedFilesService(
content::BrowserContext* browser_context) {
return apps::SavedFilesService::Get(browser_context);
}
} // namespace cef
} // namespace extensions

View File

@ -0,0 +1,58 @@
// Copyright (c) 2012 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 CEF_LIBCEF_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_DELEGATE_H_
#define CEF_LIBCEF_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_DELEGATE_H_
#include <memory>
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "extensions/browser/api/execute_code_function.h"
#include "extensions/browser/api/file_system/file_system_delegate.h"
#include "extensions/browser/extension_function.h"
namespace content {
class WebContents;
}
namespace extensions {
namespace cef {
class CefFileSystemDelegate : public FileSystemDelegate {
public:
CefFileSystemDelegate();
CefFileSystemDelegate(const CefFileSystemDelegate&) = delete;
CefFileSystemDelegate& operator=(const CefFileSystemDelegate&) = delete;
~CefFileSystemDelegate() override;
// FileSystemDelegate
base::FilePath GetDefaultDirectory() override;
base::FilePath GetManagedSaveAsDirectory(
content::BrowserContext* browser_context,
const Extension& extension) override;
bool ShowSelectFileDialog(
scoped_refptr<ExtensionFunction> extension_function,
ui::SelectFileDialog::Type type,
const base::FilePath& default_path,
const ui::SelectFileDialog::FileTypeInfo* file_types,
FileSystemDelegate::FilesSelectedCallback files_selected_callback,
base::OnceClosure file_selection_canceled_callback) override;
void ConfirmSensitiveDirectoryAccess(bool has_write_permission,
const std::u16string& app_name,
content::WebContents* web_contents,
base::OnceClosure on_accept,
base::OnceClosure on_cancel) override;
int GetDescriptionIdForAcceptType(const std::string& accept_type) override;
SavedFilesServiceInterface* GetSavedFilesService(
content::BrowserContext* browser_context) override;
};
} // namespace cef
} // namespace extensions
#endif // CEF_LIBCEF_BROWSER_EXTENSIONS_API_FILE_SYSTEM_FILE_SYSTEM_DELEGATE_H_