Skip to content

Commit

Permalink
[M90-LTS] Defer looking up the WebContents for the directory confirma…
Browse files Browse the repository at this point in the history
…tion 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 18236a0)

Bug: 1234009
Change-Id: I5e00c7fa199b3da522e1fdb73242891d7f5f7423
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3063743
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/+/3097732
Reviewed-by: Sam McNally <sammc@chromium.org>
Reviewed-by: Jana Grill <janagrill@google.com>
Reviewed-by: Artem Sumaneev <asumaneev@google.com>
Owners-Override: Artem Sumaneev <asumaneev@google.com>
Commit-Queue: Roger Felipe Zanoni da Silva <rzanoni@google.com>
Cr-Commit-Position: refs/branch-heads/4430@{#1569}
Cr-Branched-From: e5ce7dc-refs/heads/master@{#857950}
  • Loading branch information
sammc authored and Chromium LUCI CQ committed Aug 20, 2021
1 parent ba7a4d0 commit d8f7a22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
29 changes: 14 additions & 15 deletions extensions/browser/api/file_system/file_system_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,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,
Expand Down Expand Up @@ -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 BUILDFLAG(IS_CHROMEOS_ASH)
Expand All @@ -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;
}

Expand All @@ -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()) {
Expand Down Expand Up @@ -576,7 +569,7 @@ void FileSystemChooseEntryFunction::ConfirmDirectoryAccessAsync(
FROM_HERE,
base::BindOnce(
&FileSystemChooseEntryFunction::ConfirmSensitiveDirectoryAccess,
this, paths, web_contents));
this, paths));
return;
}

Expand All @@ -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;
Expand All @@ -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,
Expand Down
11 changes: 3 additions & 8 deletions extensions/browser/api/file_system/file_system_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,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;

Expand Down Expand Up @@ -168,13 +164,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);

Expand Down

0 comments on commit d8f7a22

Please sign in to comment.