#include "chrome/browser/sharing/shared_clipboard/remote_copy_message_handler.h"
#include <algorithm>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/thread_pool.h"
#include "base/trace_event/trace_event.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/notifications/notification_display_service.h"
#include "chrome/browser/notifications/notification_display_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/grit/generated_resources.h"
#include "components/sharing_message/proto/remote_copy_message.pb.h"
#include "components/sharing_message/proto/sharing_message.pb.h"
#include "components/sharing_message/sharing_metrics.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "net/base/load_flags.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/is_potentially_trustworthy.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "ui/base/accelerators/accelerator.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/events/event_constants.h"
#include "ui/events/keycodes/keyboard_codes.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"
namespace {
constexpr char kRemoteCopyAllowedOrigin[] = …;
constexpr size_t kMaxImageDownloadSize = …;
const net::NetworkTrafficAnnotationTag kTrafficAnnotation = …;
std::u16string GetTextNotificationTitle(const std::string& device_name) { … }
std::u16string GetImageNotificationTitle(const std::string& device_name) { … }
}
RemoteCopyMessageHandler::RemoteCopyMessageHandler(Profile* profile)
: … { … }
RemoteCopyMessageHandler::~RemoteCopyMessageHandler() = default;
void RemoteCopyMessageHandler::OnMessage(
components_sharing_message::SharingMessage message,
DoneCallback done_callback) { … }
void RemoteCopyMessageHandler::HandleText(const std::string& text) { … }
void RemoteCopyMessageHandler::HandleImage(const std::string& image_url) { … }
bool RemoteCopyMessageHandler::IsImageSourceAllowed(const GURL& image_url) { … }
void RemoteCopyMessageHandler::OnURLLoadComplete(
std::unique_ptr<std::string> content) { … }
void RemoteCopyMessageHandler::OnImageDecoded(const SkBitmap& image) { … }
void RemoteCopyMessageHandler::OnDecodeImageFailed() { … }
void RemoteCopyMessageHandler::WriteImageAndShowNotification(
const SkBitmap& image) { … }
void RemoteCopyMessageHandler::ShowNotification(const std::u16string& title,
const SkBitmap& image) { … }
void RemoteCopyMessageHandler::Finish(RemoteCopyHandleMessageResult result) { … }
void RemoteCopyMessageHandler::CancelAsyncTasks() { … }