1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// This file is based on chrome/browser/file_system_access/chrome_file_system_access_permission_context.h:
// Copyright 2019 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 FILE_SYSTEM_ACCESS_PERMISSION_CONTEXT_QT_H
#define FILE_SYSTEM_ACCESS_PERMISSION_CONTEXT_QT_H
#include "base/files/file_path.h"
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/file_system_access_permission_context.h"
#include "content/public/browser/global_routing_id.h"
namespace content {
class BrowserContext;
}
namespace QtWebEngineCore {
class FileSystemAccessPermissionContextQt : public content::FileSystemAccessPermissionContext,
public KeyedService
{
public:
explicit FileSystemAccessPermissionContextQt(content::BrowserContext *context);
~FileSystemAccessPermissionContextQt() override;
enum class GrantType { kRead, kWrite };
// content::FileSystemAccessPermissionContext:
scoped_refptr<content::FileSystemAccessPermissionGrant>
GetReadPermissionGrant(const url::Origin &origin, const base::FilePath &path,
HandleType handle_type, UserAction user_action) override;
scoped_refptr<content::FileSystemAccessPermissionGrant>
GetWritePermissionGrant(const url::Origin &origin, const base::FilePath &path,
HandleType handle_type, UserAction user_action) override;
void ConfirmSensitiveEntryAccess(
const url::Origin &origin, PathType path_type, const base::FilePath &path,
HandleType handle_type, UserAction user_action,
content::GlobalRenderFrameHostId frame_id,
base::OnceCallback<void(SensitiveEntryResult)> callback) override;
void PerformAfterWriteChecks(std::unique_ptr<content::FileSystemAccessWriteItem> item,
content::GlobalRenderFrameHostId frame_id,
base::OnceCallback<void(AfterWriteCheckResult)> callback) override;
bool CanObtainReadPermission(const url::Origin &origin) override;
bool CanObtainWritePermission(const url::Origin &origin) override;
void SetLastPickedDirectory(const url::Origin &origin, const std::string &id,
const base::FilePath &path, const PathType type) override;
FileSystemAccessPermissionContextQt::PathInfo
GetLastPickedDirectory(const url::Origin &origin, const std::string &id) override;
base::FilePath GetWellKnownDirectoryPath(blink::mojom::WellKnownDirectory directory, const url::Origin &origin) override;
std::u16string GetPickerTitle(const blink::mojom::FilePickerOptionsPtr &) override;
void NavigatedAwayFromOrigin(const url::Origin &origin);
content::BrowserContext *profile() const { return m_profile; }
private:
class PermissionGrantImpl;
void DidConfirmSensitiveDirectoryAccess(
const url::Origin &origin, const base::FilePath &path, HandleType handle_type,
UserAction user_action, content::GlobalRenderFrameHostId frame_id,
base::OnceCallback<void(SensitiveEntryResult)> callback, bool should_block);
content::BrowserContext *m_profile;
// Permission state per origin.
struct OriginState;
std::map<url::Origin, OriginState> m_origins;
std::map<std::string, FileSystemAccessPermissionContextQt::PathInfo> m_lastPickedDirectories;
base::WeakPtrFactory<FileSystemAccessPermissionContextQt> m_weakFactory { this };
};
} // namespace QtWebEngineCore
#endif // FILE_SYSTEM_ACCESS_PERMISSION_CONTEXT_QT_H
|