Commit 0285a44e authored by sammc's avatar sammc Committed by Commit bot

Don't expose webshare from the browser when the origin trial disables it.

BUG=645004
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_site_isolation

Review-Url: https://codereview.chromium.org/2314573002
Cr-Commit-Position: refs/heads/master@{#422983}
parent 3314001d
......@@ -116,6 +116,20 @@ public class WebShareTest extends ChromeActivityTestCaseBase<ChromeActivity> {
mUpdateWaiter.waitForUpdate());
}
/**
* Verify that WebShare fails if the origin trial is disabled.
* @throws Exception
*/
@MediumTest
@CommandLineFlags.Add({
"enable-blink-features=WebShare", "origin-trial-disabled-features=WebShare"})
@Feature({"WebShare"})
public void testWebShareOriginTrialDisabled() throws Exception {
loadUrl(mUrl);
singleClickView(mTab.getView());
assertEquals("Fail: SecurityError: WebShare is disabled.", mUpdateWaiter.waitForUpdate());
}
/**
* Verify WebShare fails if share is called from a user gesture, and canceled.
* @throws Exception
......
......@@ -103,6 +103,7 @@
#include "chrome/common/env_vars.h"
#include "chrome/common/features.h"
#include "chrome/common/logging_chrome.h"
#include "chrome/common/origin_trials/chrome_origin_trial_policy.h"
#include "chrome/common/pepper_permission_util.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h"
......@@ -1473,6 +1474,18 @@ void MaybeAppendBlinkSettingsSwitchForFieldTrial(
base::JoinString(blink_settings, ","));
}
#if BUILDFLAG(ANDROID_JAVA_UI)
void ForwardShareServiceRequest(
base::WeakPtr<shell::InterfaceProvider> interface_provider,
blink::mojom::ShareServiceRequest request) {
if (!interface_provider ||
ChromeOriginTrialPolicy().IsFeatureDisabled("WebShare")) {
return;
}
interface_provider->GetInterface(std::move(request));
}
#endif
} // namespace
void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
......@@ -2995,8 +3008,8 @@ void ChromeContentBrowserClient::RegisterRenderFrameMojoInterfaces(
web_contents->GetJavaInterfaces()
->CreateInterfaceFactory<blink::mojom::PaymentRequest>());
registry->AddInterface(
web_contents->GetJavaInterfaces()
->CreateInterfaceFactory<blink::mojom::ShareService>());
base::Bind(&ForwardShareServiceRequest,
web_contents->GetJavaInterfaces()->GetWeakPtr()));
}
#endif
......
......@@ -24,6 +24,8 @@ class NavigatorShare::ShareClientImpl final
void callback(const String& error);
void onConnectionError();
DEFINE_INLINE_TRACE() {
visitor->trace(m_navigator);
visitor->trace(m_resolver);
......@@ -51,6 +53,11 @@ void NavigatorShare::ShareClientImpl::callback(const String& error) {
}
}
void NavigatorShare::ShareClientImpl::onConnectionError() {
m_resolver->reject(
DOMException::create(SecurityError, "WebShare is disabled."));
}
NavigatorShare::~NavigatorShare() = default;
NavigatorShare& NavigatorShare::from(Navigator& navigator) {
......@@ -94,6 +101,8 @@ ScriptPromise NavigatorShare::share(ScriptState* scriptState,
LocalFrame* frame = doc->frame();
DCHECK(frame);
frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_service));
m_service.set_connection_error_handler(convertToBaseCallback(WTF::bind(
&NavigatorShare::onConnectionError, wrapWeakPersistent(this))));
DCHECK(m_service);
}
......@@ -117,4 +126,12 @@ ScriptPromise NavigatorShare::share(ScriptState* scriptState,
return from(navigator).share(scriptState, shareData);
}
void NavigatorShare::onConnectionError() {
for (auto& client : m_clients) {
client->onConnectionError();
}
m_clients.clear();
m_service.reset();
}
} // namespace blink
......@@ -43,6 +43,8 @@ class NavigatorShare final : public GarbageCollectedFinalized<NavigatorShare>,
NavigatorShare();
static const char* supplementName();
void onConnectionError();
blink::mojom::blink::ShareServicePtr m_service;
HeapHashSet<Member<ShareClientImpl>> m_clients;
......
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