/
cherry-pick-1234009.patch
138 lines (123 loc) · 5.92 KB
/
cherry-pick-1234009.patch
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Sam McNally <sammc@chromium.org>
Date: Tue, 10 Aug 2021 02:14:43 +0000
Subject: Defer looking up the WebContents for the directory confirmation
dialog.
Look up the WebContents to use for the sensitive directory confirmation
dialog immediately before it's used instead of before performing some
blocking file access to determine whether it's necessary.
(cherry picked from commit 18236a0db8341302120c60781ae3129e94fbaf1c)
Bug: 1234009
Change-Id: I5e00c7fa199b3da522e1fdb73242891d7f5f7423
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3063743
Reviewed-by: Alex Danilo <adanilo@chromium.org>
Reviewed-by: Ben Wells <benwells@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#907467}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3083204
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/4577@{#648}
Cr-Branched-From: 761ddde228655e313424edec06497d0c56b0f3c4-refs/heads/master@{#902210}
diff --git a/extensions/browser/api/file_system/file_system_api.cc b/extensions/browser/api/file_system/file_system_api.cc
index a128893387beac06fb1256416ae234af251378db..870298116be17a2bb0874f8b32c8926ec19ed0d4 100644
--- a/extensions/browser/api/file_system/file_system_api.cc
+++ b/extensions/browser/api/file_system/file_system_api.cc
@@ -196,6 +196,9 @@ void PassFileInfoToUIThread(FileInfoOptCallback callback,
content::WebContents* GetWebContentsForRenderFrameHost(
content::BrowserContext* browser_context,
content::RenderFrameHost* render_frame_host) {
+ if (!render_frame_host)
+ return nullptr;
+
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host);
// Check if there is an app window associated with the web contents; if not,
@@ -508,15 +511,6 @@ void FileSystemChooseEntryFunction::FilesSelected(
}
if (is_directory_) {
- // Get the WebContents for the app window to be the parent window of the
- // confirmation dialog if necessary.
- content::WebContents* const web_contents = GetWebContentsForRenderFrameHost(
- browser_context(), render_frame_host());
- if (!web_contents) {
- Respond(Error(kInvalidCallingPage));
- return;
- }
-
DCHECK_EQ(paths.size(), 1u);
bool non_native_path = false;
#if defined(OS_CHROMEOS)
@@ -530,7 +524,7 @@ void FileSystemChooseEntryFunction::FilesSelected(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(
&FileSystemChooseEntryFunction::ConfirmDirectoryAccessAsync, this,
- non_native_path, paths, web_contents));
+ non_native_path, paths));
return;
}
@@ -543,8 +537,7 @@ void FileSystemChooseEntryFunction::FileSelectionCanceled() {
void FileSystemChooseEntryFunction::ConfirmDirectoryAccessAsync(
bool non_native_path,
- const std::vector<base::FilePath>& paths,
- content::WebContents* web_contents) {
+ const std::vector<base::FilePath>& paths) {
const base::FilePath check_path =
non_native_path ? paths[0] : base::MakeAbsoluteFilePath(paths[0]);
if (check_path.empty()) {
@@ -576,7 +569,7 @@ void FileSystemChooseEntryFunction::ConfirmDirectoryAccessAsync(
FROM_HERE,
base::BindOnce(
&FileSystemChooseEntryFunction::ConfirmSensitiveDirectoryAccess,
- this, paths, web_contents));
+ this, paths));
return;
}
@@ -587,8 +580,7 @@ void FileSystemChooseEntryFunction::ConfirmDirectoryAccessAsync(
}
void FileSystemChooseEntryFunction::ConfirmSensitiveDirectoryAccess(
- const std::vector<base::FilePath>& paths,
- content::WebContents* web_contents) {
+ const std::vector<base::FilePath>& paths) {
if (ExtensionsBrowserClient::Get()->IsShuttingDown()) {
FileSelectionCanceled();
return;
@@ -601,6 +593,13 @@ void FileSystemChooseEntryFunction::ConfirmSensitiveDirectoryAccess(
return;
}
+ content::WebContents* const web_contents =
+ GetWebContentsForRenderFrameHost(browser_context(), render_frame_host());
+ if (!web_contents) {
+ Respond(Error(kInvalidCallingPage));
+ return;
+ }
+
delegate->ConfirmSensitiveDirectoryAccess(
app_file_handler_util::HasFileSystemWritePermission(extension_.get()),
base::UTF8ToUTF16(extension_->name()), web_contents,
diff --git a/extensions/browser/api/file_system/file_system_api.h b/extensions/browser/api/file_system/file_system_api.h
index 2a95c4d89fd2746aec0792f231bd20eac1b82d63..95ae48b3338ca90c25c098cd23655a84236aa6e6 100644
--- a/extensions/browser/api/file_system/file_system_api.h
+++ b/extensions/browser/api/file_system/file_system_api.h
@@ -18,10 +18,6 @@
#include "extensions/common/api/file_system.h"
#include "ui/shell_dialogs/select_file_dialog.h"
-namespace content {
-class WebContents;
-} // namespace content
-
namespace extensions {
class ExtensionPrefs;
@@ -167,13 +163,12 @@ class FileSystemChooseEntryFunction : public FileSystemEntryFunction {
// directory. If so, calls ConfirmSensitiveDirectoryAccess. Otherwise, calls
// OnDirectoryAccessConfirmed.
void ConfirmDirectoryAccessAsync(bool non_native_path,
- const std::vector<base::FilePath>& paths,
- content::WebContents* web_contents);
+ const std::vector<base::FilePath>& paths);
// Shows a dialog to confirm whether the user wants to open the directory.
// Calls OnDirectoryAccessConfirmed or FileSelectionCanceled.
- void ConfirmSensitiveDirectoryAccess(const std::vector<base::FilePath>& paths,
- content::WebContents* web_contents);
+ void ConfirmSensitiveDirectoryAccess(
+ const std::vector<base::FilePath>& paths);
void OnDirectoryAccessConfirmed(const std::vector<base::FilePath>& paths);