Commit 259f78e0 authored by Michael van Ouwerkerk's avatar Michael van Ouwerkerk Committed by Commit Bot

Add RemoteCopyMessageHandler.

Bug: 1018135
Change-Id: I3f7694d208ed1cdc5064c8af2a2b7de70a172a2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1893998Reviewed-by: default avatarRichard Knoll <knollr@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Commit-Queue: Michael van Ouwerkerk <mvanouwerkerk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712110}
parent a7778a2f
...@@ -3417,6 +3417,8 @@ jumbo_static_library("browser") { ...@@ -3417,6 +3417,8 @@ jumbo_static_library("browser") {
"sharing/click_to_call/click_to_call_ui_controller.h", "sharing/click_to_call/click_to_call_ui_controller.h",
"sharing/click_to_call/click_to_call_utils.cc", "sharing/click_to_call/click_to_call_utils.cc",
"sharing/click_to_call/click_to_call_utils.h", "sharing/click_to_call/click_to_call_utils.h",
"sharing/shared_clipboard/remote_copy_message_handler.cc",
"sharing/shared_clipboard/remote_copy_message_handler.h",
"sharing/shared_clipboard/shared_clipboard_context_menu_observer.cc", "sharing/shared_clipboard/shared_clipboard_context_menu_observer.cc",
"sharing/shared_clipboard/shared_clipboard_context_menu_observer.h", "sharing/shared_clipboard/shared_clipboard_context_menu_observer.h",
"sharing/shared_clipboard/shared_clipboard_message_handler_desktop.cc", "sharing/shared_clipboard/shared_clipboard_message_handler_desktop.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/sharing/shared_clipboard/remote_copy_message_handler.h"
#include <memory>
#include "base/guid.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/notifications/notification_display_service.h"
#include "chrome/grit/generated_resources.h"
#include "components/sync/protocol/sharing_message.pb.h"
#include "components/sync/protocol/sharing_remote_copy_message.pb.h"
#include "ui/base/clipboard/clipboard_buffer.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notification_types.h"
#include "ui/message_center/public/cpp/notifier_id.h"
#include "url/gurl.h"
RemoteCopyMessageHandler::RemoteCopyMessageHandler(
NotificationDisplayService* notification_display_service)
: notification_display_service_(notification_display_service) {}
RemoteCopyMessageHandler::~RemoteCopyMessageHandler() = default;
void RemoteCopyMessageHandler::OnMessage(
chrome_browser_sharing::SharingMessage message,
DoneCallback done_callback) {
DCHECK(message.has_remote_copy_message());
ui::ScopedClipboardWriter(ui::ClipboardBuffer::kCopyPaste)
.WriteText(base::UTF8ToUTF16(message.remote_copy_message().text()));
ShowNotification(message.sender_device_name());
std::move(done_callback).Run(/*response=*/nullptr);
}
void RemoteCopyMessageHandler::ShowNotification(
const std::string& device_name) {
DCHECK(notification_display_service_);
std::string notification_id = base::GenerateGUID();
// TODO(mvanouwerkerk): Adjust notification text and icon once we have mocks.
base::string16 notification_title =
device_name.empty()
? l10n_util::GetStringUTF16(
IDS_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_NOTIFICATION_TITLE_UNKNOWN_DEVICE)
: l10n_util::GetStringFUTF16(
IDS_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_NOTIFICATION_TITLE,
base::UTF8ToUTF16(device_name));
message_center::Notification notification(
message_center::NOTIFICATION_TYPE_SIMPLE, notification_id,
notification_title,
l10n_util::GetStringUTF16(
IDS_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_NOTIFICATION_DESCRIPTION),
/*icon=*/gfx::Image(),
/*display_source=*/base::string16(),
/*origin_url=*/GURL(), message_center::NotifierId(),
message_center::RichNotificationData(),
/*delegate=*/nullptr);
notification_display_service_->Display(NotificationHandler::Type::SHARING,
notification, /*metadata=*/nullptr);
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SHARING_SHARED_CLIPBOARD_REMOTE_COPY_MESSAGE_HANDLER_H_
#define CHROME_BROWSER_SHARING_SHARED_CLIPBOARD_REMOTE_COPY_MESSAGE_HANDLER_H_
#include <string>
#include "base/macros.h"
#include "chrome/browser/sharing/sharing_message_handler.h"
class NotificationDisplayService;
// Handles incoming messages for the remote copy feature.
class RemoteCopyMessageHandler : public SharingMessageHandler {
public:
explicit RemoteCopyMessageHandler(
NotificationDisplayService* notification_display_service);
~RemoteCopyMessageHandler() override;
// SharingMessageHandler implementation:
void OnMessage(chrome_browser_sharing::SharingMessage message,
DoneCallback done_callback) override;
private:
void ShowNotification(const std::string& device_name);
NotificationDisplayService* notification_display_service_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(RemoteCopyMessageHandler);
};
#endif // CHROME_BROWSER_SHARING_SHARED_CLIPBOARD_REMOTE_COPY_MESSAGE_HANDLER_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/sharing/shared_clipboard/remote_copy_message_handler.h"
#include "base/bind_helpers.h"
#include "base/guid.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/notifications/stub_notification_display_service.h"
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_test_base.h"
#include "chrome/grit/generated_resources.h"
#include "components/sync/protocol/sharing_message.pb.h"
#include "components/sync/protocol/sharing_remote_copy_message.pb.h"
#include "components/sync/protocol/sync_enums.pb.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
const char kText[] = "clipboard text";
const char kEmptyDeviceName[] = "";
const char kDeviceNameInMessage[] = "DeviceNameInMessage";
class RemoteCopyMessageHandlerTest : public SharedClipboardTestBase {
public:
RemoteCopyMessageHandlerTest() = default;
~RemoteCopyMessageHandlerTest() override = default;
void SetUp() override {
SharedClipboardTestBase::SetUp();
message_handler_ = std::make_unique<RemoteCopyMessageHandler>(
notification_display_service_.get());
}
chrome_browser_sharing::SharingMessage CreateMessage(std::string guid,
std::string device_name,
std::string text) {
chrome_browser_sharing::SharingMessage message =
SharedClipboardTestBase::CreateMessage(guid, device_name);
message.mutable_remote_copy_message()->set_text(text);
return message;
}
protected:
std::unique_ptr<RemoteCopyMessageHandler> message_handler_;
DISALLOW_COPY_AND_ASSIGN(RemoteCopyMessageHandlerTest);
};
} // namespace
TEST_F(RemoteCopyMessageHandlerTest, NotificationWithoutDeviceName) {
message_handler_->OnMessage(
CreateMessage(base::GenerateGUID(), kEmptyDeviceName, kText),
base::DoNothing());
EXPECT_EQ(GetClipboardText(), kText);
EXPECT_EQ(
l10n_util::GetStringUTF16(
IDS_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_NOTIFICATION_TITLE_UNKNOWN_DEVICE),
GetNotification().title());
}
TEST_F(RemoteCopyMessageHandlerTest, NotificationWithDeviceName) {
message_handler_->OnMessage(
CreateMessage(base::GenerateGUID(), kDeviceNameInMessage, kText),
base::DoNothing());
EXPECT_EQ(GetClipboardText(), kText);
EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_NOTIFICATION_TITLE,
base::ASCIIToUTF16(kDeviceNameInMessage)),
GetNotification().title());
}
...@@ -4,24 +4,17 @@ ...@@ -4,24 +4,17 @@
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_message_handler_desktop.h" #include "chrome/browser/sharing/shared_clipboard/shared_clipboard_message_handler_desktop.h"
#include <memory>
#include "base/guid.h" #include "base/guid.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/mock_callback.h" #include "base/test/mock_callback.h"
#include "chrome/browser/notifications/stub_notification_display_service.h" #include "chrome/browser/notifications/stub_notification_display_service.h"
#include "chrome/browser/sharing/mock_sharing_service.h" #include "chrome/browser/sharing/mock_sharing_service.h"
#include "chrome/browser/sharing/sharing_service_factory.h" #include "chrome/browser/sharing/shared_clipboard/shared_clipboard_test_base.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/test/base/testing_profile.h"
#include "components/sync/protocol/sharing_shared_clipboard_message.pb.h" #include "components/sync/protocol/sharing_shared_clipboard_message.pb.h"
#include "components/sync/protocol/sync_enums.pb.h" #include "components/sync/protocol/sync_enums.pb.h"
#include "components/sync_device_info/device_info.h" #include "components/sync_device_info/device_info.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/test/test_clipboard.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
namespace { namespace {
...@@ -31,58 +24,29 @@ const char kEmptyDeviceName[] = ""; ...@@ -31,58 +24,29 @@ const char kEmptyDeviceName[] = "";
const char kDeviceNameInDeviceInfo[] = "DeviceNameInDeviceInfo"; const char kDeviceNameInDeviceInfo[] = "DeviceNameInDeviceInfo";
const char kDeviceNameInMessage[] = "DeviceNameInMessage"; const char kDeviceNameInMessage[] = "DeviceNameInMessage";
class SharedClipboardMessageHandlerTest : public testing::Test { class SharedClipboardMessageHandlerTest : public SharedClipboardTestBase {
public: public:
SharedClipboardMessageHandlerTest() = default; SharedClipboardMessageHandlerTest() = default;
~SharedClipboardMessageHandlerTest() override = default;
void SetUp() override { void SetUp() override {
notification_display_service_ = SharedClipboardTestBase::SetUp();
std::make_unique<StubNotificationDisplayService>(&profile_);
sharing_service_ = std::make_unique<MockSharingService>();
message_handler_ = std::make_unique<SharedClipboardMessageHandlerDesktop>( message_handler_ = std::make_unique<SharedClipboardMessageHandlerDesktop>(
sharing_service_.get(), notification_display_service_.get()); sharing_service_.get(), notification_display_service_.get());
ui::TestClipboard::CreateForCurrentThread();
}
void TearDown() override {
ui::Clipboard::DestroyClipboardForCurrentThread();
} }
chrome_browser_sharing::SharingMessage CreateMessage( chrome_browser_sharing::SharingMessage CreateMessage(std::string guid,
std::string guid, std::string device_name,
std::string device_name) { std::string text) {
chrome_browser_sharing::SharingMessage message; chrome_browser_sharing::SharingMessage message =
message.set_sender_guid(guid); SharedClipboardTestBase::CreateMessage(guid, device_name);
message.mutable_shared_clipboard_message()->set_text(kText); message.mutable_shared_clipboard_message()->set_text(text);
message.set_sender_device_name(device_name);
return message; return message;
} }
std::string GetClipboardText() {
base::string16 text;
ui::Clipboard::GetForCurrentThread()->ReadText(
ui::ClipboardBuffer::kCopyPaste, &text);
return base::UTF16ToUTF8(text);
}
message_center::Notification GetNotification() {
auto notifications =
notification_display_service_->GetDisplayedNotificationsForType(
NotificationHandler::Type::SHARING);
EXPECT_EQ(notifications.size(), 1u);
const message_center::Notification& notification = notifications[0];
EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, notification.type());
return notification;
}
protected: protected:
content::BrowserTaskEnvironment task_environment_;
std::unique_ptr<StubNotificationDisplayService> notification_display_service_;
std::unique_ptr<MockSharingService> sharing_service_;
std::unique_ptr<SharedClipboardMessageHandlerDesktop> message_handler_; std::unique_ptr<SharedClipboardMessageHandlerDesktop> message_handler_;
TestingProfile profile_;
DISALLOW_COPY_AND_ASSIGN(SharedClipboardMessageHandlerTest); DISALLOW_COPY_AND_ASSIGN(SharedClipboardMessageHandlerTest);
}; };
...@@ -99,16 +63,14 @@ TEST_F(SharedClipboardMessageHandlerTest, NotificationWithoutDeviceName) { ...@@ -99,16 +63,14 @@ TEST_F(SharedClipboardMessageHandlerTest, NotificationWithoutDeviceName) {
}); });
base::MockCallback<SharingMessageHandler::DoneCallback> done_callback; base::MockCallback<SharingMessageHandler::DoneCallback> done_callback;
EXPECT_CALL(done_callback, Run(testing::Eq(nullptr))).Times(1); EXPECT_CALL(done_callback, Run(testing::Eq(nullptr))).Times(1);
message_handler_->OnMessage(CreateMessage(guid, kEmptyDeviceName), message_handler_->OnMessage(CreateMessage(guid, kEmptyDeviceName, kText),
done_callback.Get()); done_callback.Get());
} }
EXPECT_EQ(GetClipboardText(), kText); EXPECT_EQ(GetClipboardText(), kText);
message_center::Notification notification = GetNotification();
EXPECT_EQ( EXPECT_EQ(
l10n_util::GetStringUTF16( l10n_util::GetStringUTF16(
IDS_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_NOTIFICATION_TITLE_UNKNOWN_DEVICE), IDS_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_NOTIFICATION_TITLE_UNKNOWN_DEVICE),
notification.title()); GetNotification().title());
} }
TEST_F(SharedClipboardMessageHandlerTest, TEST_F(SharedClipboardMessageHandlerTest,
...@@ -130,14 +92,14 @@ TEST_F(SharedClipboardMessageHandlerTest, ...@@ -130,14 +92,14 @@ TEST_F(SharedClipboardMessageHandlerTest,
}); });
base::MockCallback<SharingMessageHandler::DoneCallback> done_callback; base::MockCallback<SharingMessageHandler::DoneCallback> done_callback;
EXPECT_CALL(done_callback, Run(testing::Eq(nullptr))).Times(1); EXPECT_CALL(done_callback, Run(testing::Eq(nullptr))).Times(1);
message_handler_->OnMessage(CreateMessage(guid, kEmptyDeviceName), message_handler_->OnMessage(CreateMessage(guid, kEmptyDeviceName, kText),
done_callback.Get()); done_callback.Get());
} }
message_center::Notification notification = GetNotification(); EXPECT_EQ(GetClipboardText(), kText);
EXPECT_EQ(l10n_util::GetStringFUTF16( EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_NOTIFICATION_TITLE, IDS_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_NOTIFICATION_TITLE,
base::ASCIIToUTF16(kDeviceNameInDeviceInfo)), base::ASCIIToUTF16(kDeviceNameInDeviceInfo)),
notification.title()); GetNotification().title());
} }
TEST_F(SharedClipboardMessageHandlerTest, TEST_F(SharedClipboardMessageHandlerTest,
...@@ -151,14 +113,12 @@ TEST_F(SharedClipboardMessageHandlerTest, ...@@ -151,14 +113,12 @@ TEST_F(SharedClipboardMessageHandlerTest,
}); });
base::MockCallback<SharingMessageHandler::DoneCallback> done_callback; base::MockCallback<SharingMessageHandler::DoneCallback> done_callback;
EXPECT_CALL(done_callback, Run(testing::Eq(nullptr))).Times(1); EXPECT_CALL(done_callback, Run(testing::Eq(nullptr))).Times(1);
message_handler_->OnMessage(CreateMessage(guid, kDeviceNameInMessage), message_handler_->OnMessage(
done_callback.Get()); CreateMessage(guid, kDeviceNameInMessage, kText), done_callback.Get());
} }
EXPECT_EQ(GetClipboardText(), kText); EXPECT_EQ(GetClipboardText(), kText);
message_center::Notification notification = GetNotification();
EXPECT_EQ(l10n_util::GetStringFUTF16( EXPECT_EQ(l10n_util::GetStringFUTF16(
IDS_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_NOTIFICATION_TITLE, IDS_CONTENT_CONTEXT_SHARING_SHARED_CLIPBOARD_NOTIFICATION_TITLE,
base::ASCIIToUTF16(kDeviceNameInMessage)), base::ASCIIToUTF16(kDeviceNameInMessage)),
notification.title()); GetNotification().title());
} }
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_test_base.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/notifications/stub_notification_display_service.h"
#include "chrome/browser/sharing/mock_sharing_service.h"
#include "components/sync/protocol/sharing_message.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/test/test_clipboard.h"
#include "ui/message_center/public/cpp/notification.h"
SharedClipboardTestBase::SharedClipboardTestBase() = default;
SharedClipboardTestBase::~SharedClipboardTestBase() = default;
void SharedClipboardTestBase::SetUp() {
notification_display_service_ =
std::make_unique<StubNotificationDisplayService>(&profile_);
sharing_service_ = std::make_unique<MockSharingService>();
ui::TestClipboard::CreateForCurrentThread();
}
void SharedClipboardTestBase::TearDown() {
ui::Clipboard::DestroyClipboardForCurrentThread();
}
chrome_browser_sharing::SharingMessage SharedClipboardTestBase::CreateMessage(
std::string guid,
std::string device_name) {
chrome_browser_sharing::SharingMessage message;
message.set_sender_guid(guid);
message.set_sender_device_name(device_name);
return message;
}
std::string SharedClipboardTestBase::GetClipboardText() {
base::string16 text;
ui::Clipboard::GetForCurrentThread()->ReadText(
ui::ClipboardBuffer::kCopyPaste, &text);
return base::UTF16ToUTF8(text);
}
message_center::Notification SharedClipboardTestBase::GetNotification() {
auto notifications =
notification_display_service_->GetDisplayedNotificationsForType(
NotificationHandler::Type::SHARING);
EXPECT_EQ(notifications.size(), 1u);
const message_center::Notification& notification = notifications[0];
EXPECT_EQ(message_center::NOTIFICATION_TYPE_SIMPLE, notification.type());
return notification;
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SHARING_SHARED_CLIPBOARD_SHARED_CLIPBOARD_TEST_BASE_H_
#define CHROME_BROWSER_SHARING_SHARED_CLIPBOARD_SHARED_CLIPBOARD_TEST_BASE_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
class MockSharingService;
class StubNotificationDisplayService;
namespace chrome_browser_sharing {
class SharingMessage;
} // namespace chrome_browser_sharing
namespace message_center {
class Notification;
} // namespace message_center
class SharedClipboardTestBase : public testing::Test {
public:
SharedClipboardTestBase();
~SharedClipboardTestBase() override;
void SetUp() override;
void TearDown() override;
chrome_browser_sharing::SharingMessage CreateMessage(std::string guid,
std::string device_name);
std::string GetClipboardText();
message_center::Notification GetNotification();
protected:
content::BrowserTaskEnvironment task_environment_;
std::unique_ptr<StubNotificationDisplayService> notification_display_service_;
std::unique_ptr<MockSharingService> sharing_service_;
TestingProfile profile_;
private:
DISALLOW_COPY_AND_ASSIGN(SharedClipboardTestBase);
};
#endif // CHROME_BROWSER_SHARING_SHARED_CLIPBOARD_SHARED_CLIPBOARD_TEST_BASE_H_
...@@ -202,6 +202,8 @@ SharingDeviceRegistration::GetEnabledFeatures() const { ...@@ -202,6 +202,8 @@ SharingDeviceRegistration::GetEnabledFeatures() const {
enabled_features.insert(SharingSpecificFields::SHARED_CLIPBOARD); enabled_features.insert(SharingSpecificFields::SHARED_CLIPBOARD);
if (IsSmsFetcherSupported()) if (IsSmsFetcherSupported())
enabled_features.insert(SharingSpecificFields::SMS_FETCHER); enabled_features.insert(SharingSpecificFields::SMS_FETCHER);
if (IsRemoteCopySupported())
enabled_features.insert(SharingSpecificFields::REMOTE_COPY);
return enabled_features; return enabled_features;
} }
...@@ -234,6 +236,15 @@ bool SharingDeviceRegistration::IsSmsFetcherSupported() const { ...@@ -234,6 +236,15 @@ bool SharingDeviceRegistration::IsSmsFetcherSupported() const {
return false; return false;
} }
bool SharingDeviceRegistration::IsRemoteCopySupported() const {
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
defined(OS_CHROMEOS)
return base::FeatureList::IsEnabled(kRemoteCopyReceiver);
#endif
return false;
}
void SharingDeviceRegistration::SetEnabledFeaturesForTesting( void SharingDeviceRegistration::SetEnabledFeaturesForTesting(
std::set<SharingSpecificFields::EnabledFeatures> enabled_features) { std::set<SharingSpecificFields::EnabledFeatures> enabled_features) {
enabled_features_testing_value_ = std::move(enabled_features); enabled_features_testing_value_ = std::move(enabled_features);
......
...@@ -54,6 +54,9 @@ class SharingDeviceRegistration { ...@@ -54,6 +54,9 @@ class SharingDeviceRegistration {
// Returns if device can handle receiving of sms fetcher requests. // Returns if device can handle receiving of sms fetcher requests.
virtual bool IsSmsFetcherSupported() const; virtual bool IsSmsFetcherSupported() const;
// Returns if device can handle receiving of remote copy contents.
virtual bool IsRemoteCopySupported() const;
// For testing // For testing
void SetEnabledFeaturesForTesting( void SetEnabledFeaturesForTesting(
std::set<sync_pb::SharingSpecificFields_EnabledFeatures> std::set<sync_pb::SharingSpecificFields_EnabledFeatures>
......
...@@ -44,6 +44,11 @@ ...@@ -44,6 +44,11 @@
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_message_handler_desktop.h" #include "chrome/browser/sharing/shared_clipboard/shared_clipboard_message_handler_desktop.h"
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
defined(OS_CHROMEOS)
#include "chrome/browser/sharing/shared_clipboard/remote_copy_message_handler.h"
#endif
namespace { namespace {
// Clones device with new device name. // Clones device with new device name.
std::unique_ptr<syncer::DeviceInfo> CloneDevice( std::unique_ptr<syncer::DeviceInfo> CloneDevice(
...@@ -134,6 +139,18 @@ SharingService::SharingService( ...@@ -134,6 +139,18 @@ SharingService::SharingService(
shared_clipboard_message_handler_.get()); shared_clipboard_message_handler_.get());
} }
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
defined(OS_CHROMEOS)
if (sharing_device_registration_->IsRemoteCopySupported()) {
remote_copy_message_handler_ = std::make_unique<RemoteCopyMessageHandler>(
notification_display_service);
fcm_handler_->AddSharingHandler(
chrome_browser_sharing::SharingMessage::kRemoteCopyMessage,
remote_copy_message_handler_.get());
}
#endif // defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) ||
// defined(OS_CHROMEOS)
// If device has already registered before, start listening to FCM right away // If device has already registered before, start listening to FCM right away
// to avoid missing messages. // to avoid missing messages.
if (sync_prefs_ && sync_prefs_->GetFCMRegistration()) if (sync_prefs_ && sync_prefs_->GetFCMRegistration())
......
...@@ -44,6 +44,7 @@ class SyncService; ...@@ -44,6 +44,7 @@ class SyncService;
} // namespace syncer } // namespace syncer
class NotificationDisplayService; class NotificationDisplayService;
class RemoteCopyMessageHandler;
class SharedClipboardMessageHandler; class SharedClipboardMessageHandler;
class SharingFCMHandler; class SharingFCMHandler;
class SharingFCMSender; class SharingFCMSender;
...@@ -209,13 +210,20 @@ class SharingService : public KeyedService, ...@@ -209,13 +210,20 @@ class SharingService : public KeyedService,
PingMessageHandler ping_message_handler_; PingMessageHandler ping_message_handler_;
std::unique_ptr<AckMessageHandler> ack_message_handler_; std::unique_ptr<AckMessageHandler> ack_message_handler_;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
ClickToCallMessageHandler click_to_call_message_handler_; ClickToCallMessageHandler click_to_call_message_handler_;
std::unique_ptr<SmsFetchRequestHandler> sms_fetch_request_handler_; std::unique_ptr<SmsFetchRequestHandler> sms_fetch_request_handler_;
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
std::unique_ptr<SharedClipboardMessageHandler> std::unique_ptr<SharedClipboardMessageHandler>
shared_clipboard_message_handler_; shared_clipboard_message_handler_;
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
defined(OS_CHROMEOS)
std::unique_ptr<RemoteCopyMessageHandler> remote_copy_message_handler_;
#endif
base::WeakPtrFactory<SharingService> weak_ptr_factory_{this}; base::WeakPtrFactory<SharingService> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(SharingService); DISALLOW_COPY_AND_ASSIGN(SharingService);
......
...@@ -4003,8 +4003,11 @@ test("unit_tests") { ...@@ -4003,8 +4003,11 @@ test("unit_tests") {
"../browser/sharing/click_to_call/click_to_call_context_menu_observer_unittest.cc", "../browser/sharing/click_to_call/click_to_call_context_menu_observer_unittest.cc",
"../browser/sharing/click_to_call/click_to_call_ui_controller_unittest.cc", "../browser/sharing/click_to_call/click_to_call_ui_controller_unittest.cc",
"../browser/sharing/click_to_call/click_to_call_utils_unittest.cc", "../browser/sharing/click_to_call/click_to_call_utils_unittest.cc",
"../browser/sharing/shared_clipboard/remote_copy_message_handler_unittest.cc",
"../browser/sharing/shared_clipboard/shared_clipboard_context_menu_observer_unittest.cc", "../browser/sharing/shared_clipboard/shared_clipboard_context_menu_observer_unittest.cc",
"../browser/sharing/shared_clipboard/shared_clipboard_message_handler_desktop_unittest.cc", "../browser/sharing/shared_clipboard/shared_clipboard_message_handler_desktop_unittest.cc",
"../browser/sharing/shared_clipboard/shared_clipboard_test_base.cc",
"../browser/sharing/shared_clipboard/shared_clipboard_test_base.h",
"../browser/sharing/shared_clipboard/shared_clipboard_ui_controller_unittest.cc", "../browser/sharing/shared_clipboard/shared_clipboard_ui_controller_unittest.cc",
"../browser/sharing/shared_clipboard/shared_clipboard_utils_unittest.cc", "../browser/sharing/shared_clipboard/shared_clipboard_utils_unittest.cc",
"../browser/ui/autofill/payments/local_card_migration_bubble_controller_impl_unittest.cc", "../browser/ui/autofill/payments/local_card_migration_bubble_controller_impl_unittest.cc",
......
...@@ -96,6 +96,7 @@ message SharingSpecificFields { ...@@ -96,6 +96,7 @@ message SharingSpecificFields {
CLICK_TO_CALL = 1; CLICK_TO_CALL = 1;
SHARED_CLIPBOARD = 2; SHARED_CLIPBOARD = 2;
SMS_FETCHER = 3; SMS_FETCHER = 3;
REMOTE_COPY = 4;
} }
// A list of enabled Sharing features. // A list of enabled Sharing features.
......
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