Commit 14466364 authored by Olivier Yiptong's avatar Olivier Yiptong Committed by Commit Bot

[Native File System] Record User Activation at FileWriter Creation

One of the features SafeBrowsing requires for checks is whether or
not there was user activation for the payload being scrutinized.

This implements the retrieval of the User Activation Status at the
time a FileWriter creation is requested from the renderer.

Bug: 995974
Change-Id: I403723261f24787f7bd86aba2e54ad1bc088f323
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1771949
Commit-Queue: Olivier Yiptong <oyiptong@chromium.org>
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Auto-Submit: Olivier Yiptong <oyiptong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691852}
parent 4d6222a3
......@@ -75,13 +75,15 @@ NativeFileSystemFileWriterImpl::NativeFileSystemFileWriterImpl(
const BindingContext& context,
const storage::FileSystemURL& url,
const storage::FileSystemURL& swap_url,
const SharedHandleState& handle_state)
const SharedHandleState& handle_state,
bool has_transient_user_activation)
: NativeFileSystemHandleBase(manager,
context,
url,
handle_state,
/*is_directory=*/false),
swap_url_(swap_url) {
swap_url_(swap_url),
has_transient_user_activation_(has_transient_user_activation) {
DCHECK_EQ(swap_url.type(), url.type());
}
......
......@@ -41,7 +41,8 @@ class CONTENT_EXPORT NativeFileSystemFileWriterImpl
const BindingContext& context,
const storage::FileSystemURL& url,
const storage::FileSystemURL& swap_url,
const SharedHandleState& handle_state);
const SharedHandleState& handle_state,
bool has_transient_user_activation);
~NativeFileSystemFileWriterImpl() override;
const storage::FileSystemURL& swap_url() const { return swap_url_; }
......@@ -65,6 +66,9 @@ class CONTENT_EXPORT NativeFileSystemFileWriterImpl
void ComputeHashForSwapFileForTesting(HashCallback callback) {
ComputeHashForSwapFile(std::move(callback));
}
bool HasTransientUserActivationForTesting() const {
return has_transient_user_activation_;
}
private:
// State that is kept for the duration of a write operation, to keep track of
......@@ -128,6 +132,10 @@ class CONTENT_EXPORT NativeFileSystemFileWriterImpl
bool skip_quarantine_service_for_testing_ = false;
// Keeps track of user activation state at creation time for SafeBrowsing
// checks.
bool has_transient_user_activation_ = false;
base::WeakPtr<NativeFileSystemHandleBase> AsWeakPtr() override;
base::WeakPtrFactory<NativeFileSystemFileWriterImpl> weak_factory_{this};
......
......@@ -93,7 +93,8 @@ class NativeFileSystemFileWriterImplTest : public testing::Test {
/*frame_id=*/MSG_ROUTING_NONE),
test_file_url_, test_swap_url_,
NativeFileSystemManagerImpl::SharedHandleState(
permission_grant_, permission_grant_, std::move(fs)));
permission_grant_, permission_grant_, std::move(fs)),
/*has_transient_user_activation=*/false);
handle_->set_skip_quarantine_service_for_testing();
}
......
......@@ -95,6 +95,16 @@ void ShowFilePickerOnUIThread(const url::Origin& requesting_origin,
std::move(callback_runner));
}
bool HasTransientUserActivation(int render_process_id, int frame_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
RenderFrameHost* rfh = RenderFrameHost::FromID(render_process_id, frame_id);
if (!rfh)
return false;
return rfh->HasTransientUserActivation();
}
} // namespace
NativeFileSystemManagerImpl::SharedHandleState::SharedHandleState(
......@@ -318,10 +328,16 @@ NativeFileSystemManagerImpl::CreateFileWriter(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
mojo::PendingRemote<blink::mojom::NativeFileSystemFileWriter> result;
writer_receivers_.Add(std::make_unique<NativeFileSystemFileWriterImpl>(
this, binding_context, url, swap_url, handle_state),
result.InitWithNewPipeAndPassReceiver());
mojo::PendingReceiver<blink::mojom::NativeFileSystemFileWriter>
writer_receiver = result.InitWithNewPipeAndPassReceiver();
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(&HasTransientUserActivation, binding_context.process_id,
binding_context.frame_id),
base::BindOnce(&NativeFileSystemManagerImpl::CreateFileWriterImpl,
weak_factory_.GetWeakPtr(), binding_context, url, swap_url,
handle_state, std::move(writer_receiver)));
return result;
}
......@@ -602,4 +618,18 @@ NativeFileSystemManagerImpl::CreateFileEntryFromPathImpl(
url.base_name);
}
void NativeFileSystemManagerImpl::CreateFileWriterImpl(
const BindingContext& binding_context,
const storage::FileSystemURL& url,
const storage::FileSystemURL& swap_url,
const SharedHandleState& handle_state,
mojo::PendingReceiver<blink::mojom::NativeFileSystemFileWriter>
writer_receiver,
bool has_transient_user_activation) {
writer_receivers_.Add(std::make_unique<NativeFileSystemFileWriterImpl>(
this, binding_context, url, swap_url, handle_state,
has_transient_user_activation),
std::move(writer_receiver));
}
} // namespace content
......@@ -227,6 +227,15 @@ class CONTENT_EXPORT NativeFileSystemManagerImpl
const base::FilePath& file_path,
NativeFileSystemPermissionContext::UserAction user_action);
void CreateFileWriterImpl(
const BindingContext& binding_context,
const storage::FileSystemURL& url,
const storage::FileSystemURL& swap_url,
const SharedHandleState& handle_state,
mojo::PendingReceiver<blink::mojom::NativeFileSystemFileWriter>
writer_receiver,
bool has_transient_user_activation);
const scoped_refptr<storage::FileSystemContext> context_;
const scoped_refptr<ChromeBlobStorageContext> blob_context_;
std::unique_ptr<storage::FileSystemOperationRunner> operation_runner_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment