Commit b4a21666 authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

Web Share: Add log messages to explain errors

When navigator.share() fails with NotAllowedError, developers
may find log messages useful to understand the failures.

Change-Id: Ife338df5c8e97cc60de98ef4480d45ba8cdfa229
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2533215
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarGlen Robertson <glenrob@chromium.org>
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827695}
parent 2c4f8090
...@@ -47,6 +47,8 @@ base::File::Error PrepareDirectoryTask::PrepareDirectory( ...@@ -47,6 +47,8 @@ base::File::Error PrepareDirectoryTask::PrepareDirectory(
void PrepareDirectoryTask::OnPrepareDirectory(base::File::Error result) { void PrepareDirectoryTask::OnPrepareDirectory(base::File::Error result) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (result != base::File::FILE_OK)
VLOG(1) << "Could not create directory for shared files";
std::move(callback_).Run((result == base::File::FILE_OK) std::move(callback_).Run((result == base::File::FILE_OK)
? blink::mojom::ShareError::OK ? blink::mojom::ShareError::OK
: blink::mojom::ShareError::PERMISSION_DENIED); : blink::mojom::ShareError::PERMISSION_DENIED);
......
...@@ -85,6 +85,8 @@ void SharesheetClient::Share( ...@@ -85,6 +85,8 @@ void SharesheetClient::Share(
// The SharesheetClient only shows one share sheet at a time. // The SharesheetClient only shows one share sheet at a time.
if (current_share_.has_value() || !web_contents()) { if (current_share_.has_value() || !web_contents()) {
VLOG(1) << "Cannot share when an existing share is in progress, or after "
"navigating away";
std::move(callback).Run(blink::mojom::ShareError::PERMISSION_DENIED); std::move(callback).Run(blink::mojom::ShareError::PERMISSION_DENIED);
return; return;
} }
......
...@@ -109,6 +109,7 @@ void StoreFileTask::OnCalculatedSize(uint64_t total_size, ...@@ -109,6 +109,7 @@ void StoreFileTask::OnCalculatedSize(uint64_t total_size,
DCHECK_EQ(total_size, expected_content_size); DCHECK_EQ(total_size, expected_content_size);
if (expected_content_size > available_space_) { if (expected_content_size > available_space_) {
VLOG(1) << "Share too large: " << expected_content_size << " bytes";
std::move(callback_).Run(blink::mojom::ShareError::PERMISSION_DENIED); std::move(callback_).Run(blink::mojom::ShareError::PERMISSION_DENIED);
return; return;
} }
......
...@@ -139,11 +139,13 @@ void ShareServiceImpl::Share(const std::string& title, ...@@ -139,11 +139,13 @@ void ShareServiceImpl::Share(const std::string& title,
content::WebContents* const web_contents = content::WebContents* const web_contents =
content::WebContents::FromRenderFrameHost(render_frame_host_); content::WebContents::FromRenderFrameHost(render_frame_host_);
if (!web_contents) { if (!web_contents) {
VLOG(1) << "Cannot share after navigating away";
std::move(callback).Run(blink::mojom::ShareError::PERMISSION_DENIED); std::move(callback).Run(blink::mojom::ShareError::PERMISSION_DENIED);
return; return;
} }
if (files.size() > kMaxSharedFileCount) { if (files.size() > kMaxSharedFileCount) {
VLOG(1) << "Share too large: " << files.size() << " files";
std::move(callback).Run(blink::mojom::ShareError::PERMISSION_DENIED); std::move(callback).Run(blink::mojom::ShareError::PERMISSION_DENIED);
return; return;
} }
...@@ -156,6 +158,8 @@ void ShareServiceImpl::Share(const std::string& title, ...@@ -156,6 +158,8 @@ void ShareServiceImpl::Share(const std::string& title,
if (IsDangerousFilename(file->name) || if (IsDangerousFilename(file->name) ||
IsDangerousMimeType(file->blob->content_type)) { IsDangerousMimeType(file->blob->content_type)) {
VLOG(1) << "File type is not supported: " << file->name
<< " has mime type " << file->blob->content_type;
std::move(callback).Run(blink::mojom::ShareError::PERMISSION_DENIED); std::move(callback).Run(blink::mojom::ShareError::PERMISSION_DENIED);
return; return;
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <utility> #include <utility>
#include "third_party/blink/public/common/browser_interface_broker_proxy.h" #include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/public/mojom/devtools/console_message.mojom-blink.h"
#include "third_party/blink/public/mojom/feature_policy/feature_policy_feature.mojom-blink.h" #include "third_party/blink/public/mojom/feature_policy/feature_policy_feature.mojom-blink.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_share_data.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_share_data.h"
...@@ -207,13 +208,15 @@ ScriptPromise NavigatorShare::share(ScriptState* script_state, ...@@ -207,13 +208,15 @@ ScriptPromise NavigatorShare::share(ScriptState* script_state,
return ScriptPromise(); return ScriptPromise();
} }
ExecutionContext* const execution_context =
ExecutionContext::From(script_state);
// The feature policy is currently not enforced. // The feature policy is currently not enforced.
LocalDOMWindow* const window = LocalDOMWindow::From(script_state); LocalDOMWindow* const window = LocalDOMWindow::From(script_state);
window->CountUse( window->CountUse(execution_context->IsFeatureEnabled(
ExecutionContext::From(script_state) mojom::blink::FeaturePolicyFeature::kWebShare)
->IsFeatureEnabled(mojom::blink::FeaturePolicyFeature::kWebShare) ? WebFeature::kWebSharePolicyAllow
? WebFeature::kWebSharePolicyAllow : WebFeature::kWebSharePolicyDisallow);
: WebFeature::kWebSharePolicyDisallow);
if (client_) { if (client_) {
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError, exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
...@@ -222,6 +225,7 @@ ScriptPromise NavigatorShare::share(ScriptState* script_state, ...@@ -222,6 +225,7 @@ ScriptPromise NavigatorShare::share(ScriptState* script_state,
} }
if (!LocalFrame::ConsumeTransientUserActivation(window->GetFrame())) { if (!LocalFrame::ConsumeTransientUserActivation(window->GetFrame())) {
VLOG(1) << "Share without transient activation (user gesture)";
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kNotAllowedError, DOMExceptionCode::kNotAllowedError,
"Must be handling a user gesture to perform a share request."); "Must be handling a user gesture to perform a share request.");
...@@ -257,6 +261,9 @@ ScriptPromise NavigatorShare::share(ScriptState* script_state, ...@@ -257,6 +261,9 @@ ScriptPromise NavigatorShare::share(ScriptState* script_state,
if (files.size() > kMaxSharedFileCount || if (files.size() > kMaxSharedFileCount ||
total_bytes > kMaxSharedFileBytes) { total_bytes > kMaxSharedFileBytes) {
execution_context->AddConsoleMessage(
mojom::blink::ConsoleMessageSource::kJavaScript,
mojom::blink::ConsoleMessageLevel::kWarning, "Share too large");
exception_state.ThrowDOMException(DOMExceptionCode::kNotAllowedError, exception_state.ThrowDOMException(DOMExceptionCode::kNotAllowedError,
"Permission denied"); "Permission denied");
return ScriptPromise(); return ScriptPromise();
......
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