Skip to content

Commit

Permalink
WebShare: Share implementation for Windows
Browse files Browse the repository at this point in the history
Finishing the implementation for navigator.share() on Windows.

Updating the existing tests for basic exercising of this functionality
and adding new tests for the Windows-specific functionality checks.

Bug: 1035527
Change-Id: Ibc2c50e85109fd1739124c40966b353c5db2c00f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2443757
Commit-Queue: Hoch Hochkeppel <mhochk@microsoft.com>
Reviewed-by: Alex Gough <ajgo@chromium.org>
Reviewed-by: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815706}
  • Loading branch information
mhochk authored and Commit Bot committed Oct 9, 2020
1 parent 2bea32f commit 32b6222
Show file tree
Hide file tree
Showing 13 changed files with 1,434 additions and 44 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4496,6 +4496,8 @@ static_library("browser") {
"themes/theme_helper_win.cc",
"themes/theme_helper_win.h",
"upgrade_detector/get_installed_version_win.cc",
"webshare/win/share_operation.cc",
"webshare/win/share_operation.h",
"webshare/win/show_share_ui_for_window_operation.cc",
"webshare/win/show_share_ui_for_window_operation.h",
"win/app_icon.cc",
Expand Down
31 changes: 31 additions & 0 deletions chrome/browser/webshare/share_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,48 @@
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"

#if defined(OS_WIN)
#include "chrome/browser/webshare/win/scoped_fake_data_transfer_manager_interop.h"
#endif

class ShareServiceBrowserTest : public InProcessBrowserTest {
public:
ShareServiceBrowserTest() {
feature_list_.InitAndEnableFeature(features::kWebShare);
}

#if defined(OS_WIN)
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();
if (IsSupportedEnvironment()) {
scoped_interop_ =
std::make_unique<webshare::ScopedFakeDataTransferManagerInterop>();
}
}
#endif

protected:
#if defined(OS_WIN)
bool IsSupportedEnvironment() {
return webshare::ScopedFakeDataTransferManagerInterop::
IsSupportedEnvironment();
}
#endif

private:
base::test::ScopedFeatureList feature_list_;
#if defined(OS_WIN)
std::unique_ptr<webshare::ScopedFakeDataTransferManagerInterop>
scoped_interop_;
#endif
};

IN_PROC_BROWSER_TEST_F(ShareServiceBrowserTest, Text) {
#if defined(OS_WIN)
if (!IsSupportedEnvironment())
return;
#endif

ASSERT_TRUE(embedded_test_server()->Start());
ui_test_utils::NavigateToURL(
browser(), embedded_test_server()->GetURL("/webshare/index.html"));
Expand Down
18 changes: 15 additions & 3 deletions chrome/browser/webshare/share_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chrome/browser/webshare/share_service_impl.h"

#include <algorithm>
#include <memory>

#include "base/feature_list.h"
#include "base/strings/string_piece.h"
Expand All @@ -13,6 +14,10 @@
#include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"

#if defined(OS_WIN)
#include "chrome/browser/webshare/win/share_operation.h"
#endif

// IsDangerousFilename() and IsDangerousMimeType() should be kept in sync with
// //third_party/blink/renderer/modules/webshare/FILE_TYPES.md
// //components/browser_ui/webshare/android/java/src/org/chromium/components/browser_ui/webshare/ShareServiceImpl.java
Expand Down Expand Up @@ -165,10 +170,17 @@ void ShareServiceImpl::Share(const std::string& title,
#if defined(OS_CHROMEOS)
sharesheet_client_.Share(title, text, share_url, std::move(files),
std::move(callback));
#elif defined(OS_WIN)
auto share_operation = std::make_unique<webshare::ShareOperation>(
title, text, share_url, std::move(files), web_contents);
share_operation->Run(base::BindOnce(
[](std::unique_ptr<webshare::ShareOperation> share_operation,
ShareCallback callback,
blink::mojom::ShareError result) { std::move(callback).Run(result); },
std::move(share_operation), std::move(callback)));
#else
// TODO(crbug.com/1035527): Add implementation for OS_WIN
NOTIMPLEMENTED();
std::move(callback).Run(blink::mojom::ShareError::OK);
NOTREACHED();
std::move(callback).Run(blink::mojom::ShareError::INTERNAL_ERROR);
#endif
}

Expand Down
30 changes: 30 additions & 0 deletions chrome/browser/webshare/share_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ using blink::mojom::ShareError;
#include "chrome/browser/sharesheet/sharesheet_types.h"
#include "chrome/browser/webshare/chromeos/sharesheet_client.h"
#endif
#if defined(OS_WIN)
#include "chrome/browser/webshare/win/scoped_fake_data_transfer_manager_interop.h"
#endif

class ShareServiceUnitTest : public ChromeRenderViewHostTestHarness {
public:
Expand All @@ -44,9 +47,22 @@ class ShareServiceUnitTest : public ChromeRenderViewHostTestHarness {
#if defined(OS_CHROMEOS)
webshare::SharesheetClient::SetSharesheetCallbackForTesting(
base::BindRepeating(&ShareServiceUnitTest::AcceptShareRequest));
#endif
#if defined(OS_WIN)
if (IsSupportedEnvironment()) {
scoped_interop_ =
std::make_unique<webshare::ScopedFakeDataTransferManagerInterop>();
}
#endif
}

#if defined(OS_WIN)
bool IsSupportedEnvironment() {
return webshare::ScopedFakeDataTransferManagerInterop::
IsSupportedEnvironment();
}
#endif

ShareError ShareGeneratedFileData(const std::string& extension,
const std::string& content_type,
unsigned file_length = 100,
Expand Down Expand Up @@ -123,11 +139,20 @@ class ShareServiceUnitTest : public ChromeRenderViewHostTestHarness {
}
#endif

#if defined(OS_WIN)
std::unique_ptr<webshare::ScopedFakeDataTransferManagerInterop>
scoped_interop_;
#endif
base::test::ScopedFeatureList feature_list_;
std::unique_ptr<ShareServiceImpl> share_service_;
};

TEST_F(ShareServiceUnitTest, FileCount) {
#if defined(OS_WIN)
if (!IsSupportedEnvironment())
return;
#endif

EXPECT_EQ(ShareError::OK, ShareGeneratedFileData(".txt", "text/plain", 1234,
kMaxSharedFileCount));
EXPECT_EQ(ShareError::PERMISSION_DENIED,
Expand Down Expand Up @@ -172,6 +197,11 @@ TEST_F(ShareServiceUnitTest, Multimedia) {
}

TEST_F(ShareServiceUnitTest, PortableDocumentFormat) {
#if defined(OS_WIN)
if (!IsSupportedEnvironment())
return;
#endif

// TODO(crbug.com/1006055): Support sharing of pdf files.
// The URL will be checked using Safe Browsing.
EXPECT_EQ(ShareError::PERMISSION_DENIED,
Expand Down
Loading

0 comments on commit 32b6222

Please sign in to comment.