diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/core/clipboard')
21 files changed, 228 insertions, 80 deletions
diff --git a/chromium/third_party/blink/renderer/core/clipboard/BUILD.gn b/chromium/third_party/blink/renderer/core/clipboard/BUILD.gn index ac9cff9c19a..42ebb6d6fc5 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/BUILD.gn +++ b/chromium/third_party/blink/renderer/core/clipboard/BUILD.gn @@ -24,6 +24,8 @@ blink_core_sources("clipboard") { "dragged_isolated_file_system.cc", "dragged_isolated_file_system.h", "paste_mode.h", + "raw_system_clipboard.cc", + "raw_system_clipboard.h", "system_clipboard.cc", "system_clipboard.h", ] diff --git a/chromium/third_party/blink/renderer/core/clipboard/clipboard_utilities.cc b/chromium/third_party/blink/renderer/core/clipboard/clipboard_utilities.cc index b7628cf5dcd..45e0b1b4327 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/clipboard_utilities.cc +++ b/chromium/third_party/blink/renderer/core/clipboard/clipboard_utilities.cc @@ -31,10 +31,13 @@ #include "third_party/blink/renderer/core/clipboard/clipboard_utilities.h" #include "net/base/escape.h" +#include "third_party/blink/renderer/platform/image-encoders/image_encoder.h" #include "third_party/blink/renderer/platform/weborigin/kurl.h" +#include "third_party/blink/renderer/platform/wtf/text/base64.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h" #include "third_party/blink/renderer/platform/wtf/text/string_utf8_adaptor.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" +#include "third_party/skia/include/encode/SkPngEncoder.h" namespace blink { @@ -90,4 +93,28 @@ String URLToImageMarkup(const KURL& url, const String& title) { return builder.ToString(); } +String BitmapToImageMarkup(const SkBitmap& bitmap) { + if (bitmap.isNull()) + return String(); + + // Encode bitmap to Vector<uint8_t> on the main thread. + SkPixmap pixmap; + bitmap.peekPixels(&pixmap); + + // Set encoding options to favor speed over size. + SkPngEncoder::Options options; + options.fZLibLevel = 1; + options.fFilterFlags = SkPngEncoder::FilterFlag::kNone; + + Vector<uint8_t> png_data; + if (!ImageEncoder::Encode(&png_data, pixmap, options)) + return String(); + + StringBuilder markup; + markup.Append("<img src=\"data:image/png;base64,"); + markup.Append(Base64Encode(png_data)); + markup.Append("\" alt=\"\"/>"); + return markup.ToString(); +} + } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/clipboard/clipboard_utilities.h b/chromium/third_party/blink/renderer/core/clipboard/clipboard_utilities.h index 623c77322ac..25709b7664c 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/clipboard_utilities.h +++ b/chromium/third_party/blink/renderer/core/clipboard/clipboard_utilities.h @@ -35,6 +35,7 @@ #include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/platform/weborigin/kurl.h" #include "third_party/blink/renderer/platform/wtf/forward.h" +#include "third_party/skia/include/core/SkBitmap.h" namespace blink { @@ -44,6 +45,7 @@ CORE_EXPORT void ReplaceNewlinesWithWindowsStyleNewlines(String&); CORE_EXPORT void ReplaceNBSPWithSpace(String&); CORE_EXPORT String ConvertURIListToURL(const String& uri_list); CORE_EXPORT String URLToImageMarkup(const KURL&, const String& title); +CORE_EXPORT String BitmapToImageMarkup(const SkBitmap& bitmap); } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/clipboard/clipboard_utilities_test.cc b/chromium/third_party/blink/renderer/core/clipboard/clipboard_utilities_test.cc index a0338751287..4aabc435c74 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/clipboard_utilities_test.cc +++ b/chromium/third_party/blink/renderer/core/clipboard/clipboard_utilities_test.cc @@ -43,4 +43,17 @@ TEST(ClipboardUtilitiesTest, URLToImageMarkupEmbeddedNull) { String(kTitleWithNull, sizeof(kTitleWithNull) - 1))); } +TEST(ClipboardUtilitiesTest, BitmapToImageMarkupEmpty) { + SkBitmap bitmap; + EXPECT_TRUE(BitmapToImageMarkup(bitmap).IsNull()); +} + +TEST(ClipboardUtilitiesTest, BitmapToImageMarkup) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(10, 5)); + EXPECT_EQ( + R"HTML(<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAFCAYAAAB8ZH1oAAAADElEQVQYGWNgGEYAAADNAAGVVebMAAAAAElFTkSuQmCC" alt=""/>)HTML", + BitmapToImageMarkup(bitmap)); +} + } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/clipboard/data_object.cc b/chromium/third_party/blink/renderer/core/clipboard/data_object.cc index ecdb6e3c740..c285880a76f 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/data_object.cc +++ b/chromium/third_party/blink/renderer/core/clipboard/data_object.cc @@ -42,18 +42,19 @@ namespace blink { -DataObject* DataObject::CreateFromClipboard(PasteMode paste_mode) { +// static +DataObject* DataObject::CreateFromClipboard(SystemClipboard* system_clipboard, + PasteMode paste_mode) { DataObject* data_object = Create(); #if DCHECK_IS_ON() HashSet<String> types_seen; #endif - uint64_t sequence_number = SystemClipboard::GetInstance().SequenceNumber(); - for (const String& type : - SystemClipboard::GetInstance().ReadAvailableTypes()) { + uint64_t sequence_number = system_clipboard->SequenceNumber(); + for (const String& type : system_clipboard->ReadAvailableTypes()) { if (paste_mode == PasteMode::kPlainTextOnly && type != kMimeTypeTextPlain) continue; - data_object->item_list_.push_back( - DataObjectItem::CreateFromClipboard(type, sequence_number)); + data_object->item_list_.push_back(DataObjectItem::CreateFromClipboard( + system_clipboard, type, sequence_number)); #if DCHECK_IS_ON() DCHECK(types_seen.insert(type).is_new_entry); #endif @@ -61,12 +62,14 @@ DataObject* DataObject::CreateFromClipboard(PasteMode paste_mode) { return data_object; } +// static DataObject* DataObject::CreateFromString(const String& data) { DataObject* data_object = Create(); data_object->Add(data, kMimeTypeTextPlain); return data_object; } +// static DataObject* DataObject::Create() { return MakeGarbageCollected<DataObject>(); } @@ -276,12 +279,13 @@ void DataObject::NotifyItemListChanged() const { observer->OnItemListChanged(); } -void DataObject::Trace(blink::Visitor* visitor) { +void DataObject::Trace(Visitor* visitor) { visitor->Trace(item_list_); visitor->Trace(observers_); Supplementable<DataObject>::Trace(visitor); } +// static DataObject* DataObject::Create(WebDragData data) { DataObject* data_object = Create(); bool has_file_system = false; diff --git a/chromium/third_party/blink/renderer/core/clipboard/data_object.h b/chromium/third_party/blink/renderer/core/clipboard/data_object.h index 3e666e2eee1..aabc378fefa 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/data_object.h +++ b/chromium/third_party/blink/renderer/core/clipboard/data_object.h @@ -43,6 +43,7 @@ namespace blink { class KURL; +class SystemClipboard; class WebDragData; enum class PasteMode; @@ -62,7 +63,7 @@ class CORE_EXPORT DataObject : public GarbageCollected<DataObject>, virtual void OnItemListChanged() = 0; }; - static DataObject* CreateFromClipboard(PasteMode); + static DataObject* CreateFromClipboard(SystemClipboard*, PasteMode); static DataObject* CreateFromString(const String&); static DataObject* Create(); static DataObject* Create(WebDragData); @@ -123,7 +124,7 @@ class CORE_EXPORT DataObject : public GarbageCollected<DataObject>, // whenever the underlying item_list_ changes. void AddObserver(Observer*); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; WebDragData ToWebDragData(); diff --git a/chromium/third_party/blink/renderer/core/clipboard/data_object_item.cc b/chromium/third_party/blink/renderer/core/clipboard/data_object_item.cc index 5016284659b..8445a955220 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/data_object_item.cc +++ b/chromium/third_party/blink/renderer/core/clipboard/data_object_item.cc @@ -41,6 +41,7 @@ namespace blink { +// static DataObjectItem* DataObjectItem::CreateFromString(const String& type, const String& data) { DataObjectItem* item = @@ -49,6 +50,7 @@ DataObjectItem* DataObjectItem::CreateFromString(const String& type, return item; } +// static DataObjectItem* DataObjectItem::CreateFromFile(File* file) { DataObjectItem* item = MakeGarbageCollected<DataObjectItem>(kFileKind, file->type()); @@ -56,6 +58,7 @@ DataObjectItem* DataObjectItem::CreateFromFile(File* file) { return item; } +// static DataObjectItem* DataObjectItem::CreateFromFileWithFileSystemId( File* file, const String& file_system_id) { @@ -66,6 +69,7 @@ DataObjectItem* DataObjectItem::CreateFromFileWithFileSystemId( return item; } +// static DataObjectItem* DataObjectItem::CreateFromURL(const String& url, const String& title) { DataObjectItem* item = @@ -75,6 +79,7 @@ DataObjectItem* DataObjectItem::CreateFromURL(const String& url, return item; } +// static DataObjectItem* DataObjectItem::CreateFromHTML(const String& html, const KURL& base_url) { DataObjectItem* item = @@ -84,6 +89,7 @@ DataObjectItem* DataObjectItem::CreateFromHTML(const String& html, return item; } +// static DataObjectItem* DataObjectItem::CreateFromSharedBuffer( scoped_refptr<SharedBuffer> buffer, const KURL& source_url, @@ -100,26 +106,37 @@ DataObjectItem* DataObjectItem::CreateFromSharedBuffer( return item; } -DataObjectItem* DataObjectItem::CreateFromClipboard(const String& type, - uint64_t sequence_number) { +// static +DataObjectItem* DataObjectItem::CreateFromClipboard( + SystemClipboard* system_clipboard, + const String& type, + uint64_t sequence_number) { if (type == kMimeTypeImagePng) { - return MakeGarbageCollected<DataObjectItem>(kFileKind, type, - sequence_number); + return MakeGarbageCollected<DataObjectItem>( + kFileKind, type, sequence_number, system_clipboard); } - return MakeGarbageCollected<DataObjectItem>(kStringKind, type, - sequence_number); + return MakeGarbageCollected<DataObjectItem>( + kStringKind, type, sequence_number, system_clipboard); } DataObjectItem::DataObjectItem(ItemKind kind, const String& type) - : source_(kInternalSource), kind_(kind), type_(type), sequence_number_(0) {} + : source_(kInternalSource), + kind_(kind), + type_(type), + sequence_number_(0), + system_clipboard_(nullptr) {} DataObjectItem::DataObjectItem(ItemKind kind, const String& type, - uint64_t sequence_number) + uint64_t sequence_number, + SystemClipboard* system_clipboard) : source_(kClipboardSource), kind_(kind), type_(type), - sequence_number_(sequence_number) {} + sequence_number_(sequence_number), + system_clipboard_(system_clipboard) { + DCHECK(system_clipboard_); +} File* DataObjectItem::GetAsFile() const { if (Kind() != kFileKind) @@ -137,8 +154,8 @@ File* DataObjectItem::GetAsFile() const { DCHECK_EQ(source_, kClipboardSource); if (GetType() == kMimeTypeImagePng) { - SkBitmap bitmap = SystemClipboard::GetInstance().ReadImage( - mojom::ClipboardBuffer::kStandard); + SkBitmap bitmap = + system_clipboard_->ReadImage(mojom::ClipboardBuffer::kStandard); SkPixmap pixmap; bitmap.peekPixels(&pixmap); @@ -175,21 +192,19 @@ String DataObjectItem::GetAsString() const { String data; // This is ugly but there's no real alternative. if (type_ == kMimeTypeTextPlain) { - data = SystemClipboard::GetInstance().ReadPlainText(); + data = system_clipboard_->ReadPlainText(); } else if (type_ == kMimeTypeTextRTF) { - data = SystemClipboard::GetInstance().ReadRTF(); + data = system_clipboard_->ReadRTF(); } else if (type_ == kMimeTypeTextHTML) { KURL ignored_source_url; unsigned ignored; - data = SystemClipboard::GetInstance().ReadHTML(ignored_source_url, ignored, - ignored); + data = system_clipboard_->ReadHTML(ignored_source_url, ignored, ignored); } else { - data = SystemClipboard::GetInstance().ReadCustomData(type_); + data = system_clipboard_->ReadCustomData(type_); } - return SystemClipboard::GetInstance().SequenceNumber() == sequence_number_ - ? data - : String(); + return system_clipboard_->SequenceNumber() == sequence_number_ ? data + : String(); } bool DataObjectItem::IsFilename() const { @@ -207,8 +222,9 @@ String DataObjectItem::FileSystemId() const { return file_system_id_; } -void DataObjectItem::Trace(blink::Visitor* visitor) { +void DataObjectItem::Trace(Visitor* visitor) { visitor->Trace(file_); + visitor->Trace(system_clipboard_); } } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/clipboard/data_object_item.h b/chromium/third_party/blink/renderer/core/clipboard/data_object_item.h index 07f92814f06..69843abb6d2 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/data_object_item.h +++ b/chromium/third_party/blink/renderer/core/clipboard/data_object_item.h @@ -40,6 +40,8 @@ namespace blink { +class SystemClipboard; + class CORE_EXPORT DataObjectItem final : public GarbageCollected<DataObjectItem> { public: @@ -61,13 +63,15 @@ class CORE_EXPORT DataObjectItem final const KURL&, const String& file_extension, const AtomicString& content_disposition); - static DataObjectItem* CreateFromClipboard(const String& type, + static DataObjectItem* CreateFromClipboard(SystemClipboard* system_clipboard, + const String& type, uint64_t sequence_number); - explicit DataObjectItem(ItemKind, const String& type); - explicit DataObjectItem(ItemKind, - const String& type, - uint64_t sequence_number); + DataObjectItem(ItemKind kind, const String& type); + DataObjectItem(ItemKind, + const String& type, + uint64_t sequence_number, + SystemClipboard* system_clipboard); ItemKind Kind() const { return kind_; } String GetType() const { return type_; } @@ -85,7 +89,7 @@ class CORE_EXPORT DataObjectItem final bool HasFileSystemId() const; String FileSystemId() const; - void Trace(blink::Visitor*); + void Trace(Visitor*); private: enum DataSource { @@ -107,6 +111,9 @@ class CORE_EXPORT DataObjectItem final uint64_t sequence_number_; // Only valid when |source_| == PasteboardSource. String file_system_id_; // Only valid when |file_| is backed by FileEntry. + + // Access to the global system clipboard. + Member<SystemClipboard> system_clipboard_; }; } // namespace blink diff --git a/chromium/third_party/blink/renderer/core/clipboard/data_object_test.cc b/chromium/third_party/blink/renderer/core/clipboard/data_object_test.cc index f1a313a129f..455adfabf87 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/data_object_test.cc +++ b/chromium/third_party/blink/renderer/core/clipboard/data_object_test.cc @@ -128,8 +128,10 @@ TEST_F(DataObjectTest, fileSystemId) { data_object_->AddFilename(file_path, String(), String()); data_object_->AddFilename(file_path, String(), "fileSystemIdForFilename"); + FileMetadata metadata; + metadata.length = 0; data_object_->Add( - File::CreateForFileSystemFile(url, FileMetadata(), File::kIsUserVisible), + File::CreateForFileSystemFile(url, metadata, File::kIsUserVisible), "fileSystemIdForFileSystemFile"); ASSERT_EQ(3U, data_object_->length()); diff --git a/chromium/third_party/blink/renderer/core/clipboard/data_transfer.cc b/chromium/third_party/blink/renderer/core/clipboard/data_transfer.cc index 907a8628443..047fb1945e0 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/data_transfer.cc +++ b/chromium/third_party/blink/renderer/core/clipboard/data_transfer.cc @@ -93,7 +93,8 @@ class DraggedNodeImageBuilder { DCHECK_EQ(dom_tree_version_, node_->GetDocument().DomTreeVersion()); #endif // Construct layout object for |node_| with pseudo class "-webkit-drag" - local_frame_->View()->UpdateAllLifecyclePhasesExceptPaint(); + local_frame_->View()->UpdateAllLifecyclePhasesExceptPaint( + DocumentUpdateReason::kDragImage); LayoutObject* const dragged_layout_object = node_->GetLayoutObject(); if (!dragged_layout_object) return nullptr; @@ -148,8 +149,8 @@ class DraggedNodeImageBuilder { } private: - const Member<LocalFrame> local_frame_; - const Member<Node> node_; + LocalFrame* const local_frame_; + Node* const node_; #if DCHECK_IS_ON() const uint64_t dom_tree_version_; #endif @@ -203,11 +204,11 @@ static String ConvertDragOperationToEffectAllowed(DragOperation op) { } // We provide the IE clipboard types (URL and Text), and the clipboard types -// specified in the WHATWG Web Applications 1.0 draft see -// http://www.whatwg.org/specs/web-apps/current-work/ Section 6.3.5.3 +// specified in the HTML spec. See +// https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface static String NormalizeType(const String& type, bool* convert_to_url = nullptr) { - String clean_type = type.StripWhiteSpace().DeprecatedLower(); + String clean_type = type.StripWhiteSpace().LowerASCII(); if (clean_type == kMimeTypeText || clean_type.StartsWith(kMimeTypeTextPlainEtc)) return kMimeTypeTextPlain; @@ -219,6 +220,7 @@ static String NormalizeType(const String& type, return clean_type; } +// static DataTransfer* DataTransfer::Create() { DataTransfer* data = Create( kCopyAndPaste, DataTransferAccessPolicy::kWritable, DataObject::Create()); @@ -227,6 +229,7 @@ DataTransfer* DataTransfer::Create() { return data; } +// static DataTransfer* DataTransfer::Create(DataTransferType type, DataTransferAccessPolicy policy, DataObject* data_object) { @@ -677,7 +680,7 @@ String ConvertDragOperationToDropZoneOperation(DragOperation operation) { } } -void DataTransfer::Trace(blink::Visitor* visitor) { +void DataTransfer::Trace(Visitor* visitor) { visitor->Trace(data_object_); visitor->Trace(drag_image_); visitor->Trace(drag_image_element_); diff --git a/chromium/third_party/blink/renderer/core/clipboard/data_transfer.h b/chromium/third_party/blink/renderer/core/clipboard/data_transfer.h index 67d3be7239a..06c596b39e7 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/data_transfer.h +++ b/chromium/third_party/blink/renderer/core/clipboard/data_transfer.h @@ -72,9 +72,7 @@ class CORE_EXPORT DataTransfer final : public ScriptWrappable, DataTransferAccessPolicy, DataObject*); - explicit DataTransfer(DataTransferType, - DataTransferAccessPolicy, - DataObject*); + DataTransfer(DataTransferType, DataTransferAccessPolicy, DataObject*); ~DataTransfer() override; bool IsForCopyAndPaste() const { return transfer_type_ == kCopyAndPaste; } @@ -158,7 +156,7 @@ class CORE_EXPORT DataTransfer final : public ScriptWrappable, const PropertyTreeState&); static std::unique_ptr<DragImage> NodeImage(LocalFrame&, Node&); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void setDragImage(ImageResourceContent*, Node*, const IntPoint&); diff --git a/chromium/third_party/blink/renderer/core/clipboard/data_transfer.idl b/chromium/third_party/blink/renderer/core/clipboard/data_transfer.idl index 96b269f04ec..7209dd85b96 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/data_transfer.idl +++ b/chromium/third_party/blink/renderer/core/clipboard/data_transfer.idl @@ -29,9 +29,9 @@ // https://html.spec.whatwg.org/C/#the-datatransfer-interface [ - Constructor, Exposed=Window ] interface DataTransfer { + constructor(); attribute DOMString dropEffect; attribute DOMString effectAllowed; diff --git a/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item.cc b/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item.cc index 3d7b7a108f4..459ace940b3 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item.cc +++ b/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item.cc @@ -106,7 +106,7 @@ void DataTransferItem::RunGetAsStringTask( callback->InvokeAndReportException(nullptr, data); } -void DataTransferItem::Trace(blink::Visitor* visitor) { +void DataTransferItem::Trace(Visitor* visitor) { visitor->Trace(data_transfer_); visitor->Trace(item_); ScriptWrappable::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item.h b/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item.h index 8e0fd0fd9ec..eb8bb1372dc 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item.h +++ b/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item.h @@ -65,7 +65,7 @@ class CORE_EXPORT DataTransferItem final : public ScriptWrappable { DataTransfer* GetDataTransfer() { return data_transfer_.Get(); } DataObjectItem* GetDataObjectItem() { return item_.Get(); } - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: void RunGetAsStringTask(ExecutionContext*, diff --git a/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item_list.cc b/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item_list.cc index 9645ec71863..b7e0bbfcc3c 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item_list.cc +++ b/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item_list.cc @@ -93,7 +93,7 @@ DataTransferItemList::DataTransferItemList(DataTransfer* data_transfer, DataObject* data_object) : data_transfer_(data_transfer), data_object_(data_object) {} -void DataTransferItemList::Trace(blink::Visitor* visitor) { +void DataTransferItemList::Trace(Visitor* visitor) { visitor->Trace(data_transfer_); visitor->Trace(data_object_); ScriptWrappable::Trace(visitor); diff --git a/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item_list.h b/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item_list.h index 0c0df5f7832..40619a675b9 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item_list.h +++ b/chromium/third_party/blink/renderer/core/clipboard/data_transfer_item_list.h @@ -60,7 +60,7 @@ class CORE_EXPORT DataTransferItemList final : public ScriptWrappable { ExceptionState&); DataTransferItem* add(File*); - void Trace(blink::Visitor*) override; + void Trace(Visitor*) override; private: Member<DataTransfer> data_transfer_; diff --git a/chromium/third_party/blink/renderer/core/clipboard/data_transfer_test.cc b/chromium/third_party/blink/renderer/core/clipboard/data_transfer_test.cc index 4674a8ab9c3..57627202f37 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/data_transfer_test.cc +++ b/chromium/third_party/blink/renderer/core/clipboard/data_transfer_test.cc @@ -135,8 +135,8 @@ TEST_F(DataTransferTest, NodeImageUnderScrollOffset) { const int scroll_amount = 10; LocalFrameView* frame_view = GetDocument().View(); - frame_view->LayoutViewport()->SetScrollOffset(ScrollOffset(0, scroll_amount), - kProgrammaticScroll); + frame_view->LayoutViewport()->SetScrollOffset( + ScrollOffset(0, scroll_amount), mojom::blink::ScrollType::kProgrammatic); // The first div should be offset by the scroll offset. Element& first = *GetDocument().getElementById("first"); @@ -176,8 +176,8 @@ TEST_F(DataTransferTest, NodeImageSizeWithPageScaleFactor) { // page scale factor. const int scroll_amount = 10; LocalFrameView* frame_view = GetDocument().View(); - frame_view->LayoutViewport()->SetScrollOffset(ScrollOffset(0, scroll_amount), - kProgrammaticScroll); + frame_view->LayoutViewport()->SetScrollOffset( + ScrollOffset(0, scroll_amount), mojom::blink::ScrollType::kProgrammatic); const auto image_with_offset = DataTransfer::NodeImage(GetFrame(), node); EXPECT_EQ( IntSize(node_width * page_scale_factor, node_height * page_scale_factor), @@ -207,8 +207,8 @@ TEST_F(DataTransferTest, NodeImageSizeWithPageScaleFactorTooLarge) { // page scale factor. const int scroll_amount = 10; LocalFrameView* frame_view = GetDocument().View(); - frame_view->LayoutViewport()->SetScrollOffset(ScrollOffset(0, scroll_amount), - kProgrammaticScroll); + frame_view->LayoutViewport()->SetScrollOffset( + ScrollOffset(0, scroll_amount), mojom::blink::ScrollType::kProgrammatic); const auto image_with_offset = DataTransfer::NodeImage(GetFrame(), node); EXPECT_EQ(IntSize(node_width * page_scale_factor, (node_height - scroll_amount) * page_scale_factor), @@ -272,8 +272,8 @@ TEST_F(DataTransferTest, NodeImageFullyOffscreen) { const int scroll_amount = 800; LocalFrameView* frame_view = GetDocument().View(); - frame_view->LayoutViewport()->SetScrollOffset(ScrollOffset(0, scroll_amount), - kProgrammaticScroll); + frame_view->LayoutViewport()->SetScrollOffset( + ScrollOffset(0, scroll_amount), mojom::blink::ScrollType::kProgrammatic); Element& target = *GetDocument().getElementById("target"); const auto image = DataTransfer::NodeImage(GetFrame(), target); diff --git a/chromium/third_party/blink/renderer/core/clipboard/raw_system_clipboard.cc b/chromium/third_party/blink/renderer/core/clipboard/raw_system_clipboard.cc new file mode 100644 index 00000000000..0e1d95a0252 --- /dev/null +++ b/chromium/third_party/blink/renderer/core/clipboard/raw_system_clipboard.cc @@ -0,0 +1,25 @@ +// Copyright 2020 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 "third_party/blink/renderer/core/clipboard/raw_system_clipboard.h" + +#include "third_party/blink/public/common/browser_interface_broker_proxy.h" +#include "third_party/blink/renderer/core/frame/local_frame.h" + +namespace blink { + +RawSystemClipboard::RawSystemClipboard(LocalFrame* frame) { + frame->GetBrowserInterfaceBroker().GetInterface( + clipboard_.BindNewPipeAndPassReceiver()); +} + +void RawSystemClipboard::Write(const String& type, mojo_base::BigBuffer data) { + clipboard_->Write(type, std::move(data)); +} + +void RawSystemClipboard::CommitWrite() { + clipboard_->CommitWrite(); +} + +} // namespace blink diff --git a/chromium/third_party/blink/renderer/core/clipboard/raw_system_clipboard.h b/chromium/third_party/blink/renderer/core/clipboard/raw_system_clipboard.h new file mode 100644 index 00000000000..eba190f4673 --- /dev/null +++ b/chromium/third_party/blink/renderer/core/clipboard/raw_system_clipboard.h @@ -0,0 +1,41 @@ +// Copyright 2020 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 THIRD_PARTY_BLINK_RENDERER_CORE_CLIPBOARD_RAW_SYSTEM_CLIPBOARD_H_ +#define THIRD_PARTY_BLINK_RENDERER_CORE_CLIPBOARD_RAW_SYSTEM_CLIPBOARD_H_ + +#include "mojo/public/cpp/bindings/remote.h" // For mojo::Remote<T> +#include "third_party/blink/public/mojom/clipboard/raw_clipboard.mojom-blink.h" +#include "third_party/blink/renderer/core/core_export.h" +#include "third_party/blink/renderer/platform/heap/heap.h" + +// RawSystemClipboard: +// - is a singleton. +// - provides read/write access of unsanitized, platform-specific data. +// - mediates between async clipboard and mojom::RawClipboardHost. +// +// All calls to Write() must be followed by a call to CommitWrite(). +namespace blink { + +class LocalFrame; + +class CORE_EXPORT RawSystemClipboard final + : public GarbageCollected<RawSystemClipboard> { + public: + explicit RawSystemClipboard(LocalFrame* frame); + + RawSystemClipboard(const RawSystemClipboard&) = delete; + RawSystemClipboard& operator=(const RawSystemClipboard&) = delete; + + void Write(const String& type, mojo_base::BigBuffer data); + void CommitWrite(); + void Trace(Visitor*) {} + + private: + mojo::Remote<mojom::blink::RawClipboardHost> clipboard_; +}; + +} // namespace blink + +#endif // THIRD_PARTY_BLINK_RENDERER_CORE_CLIPBOARD_RAW_SYSTEM_CLIPBOARD_H_ diff --git a/chromium/third_party/blink/renderer/core/clipboard/system_clipboard.cc b/chromium/third_party/blink/renderer/core/clipboard/system_clipboard.cc index 601ec0d8971..905739a4b40 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/system_clipboard.cc +++ b/chromium/third_party/blink/renderer/core/clipboard/system_clipboard.cc @@ -7,13 +7,15 @@ #include "base/memory/scoped_refptr.h" #include "build/build_config.h" #include "mojo/public/cpp/system/platform_handle.h" -#include "third_party/blink/public/platform/interface_provider.h" +#include "third_party/blink/public/common/browser_interface_broker_proxy.h" +#include "third_party/blink/public/common/thread_safe_browser_interface_broker_proxy.h" #include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/web_drag_data.h" #include "third_party/blink/public/platform/web_string.h" #include "third_party/blink/renderer/core/clipboard/clipboard_mime_types.h" #include "third_party/blink/renderer/core/clipboard/clipboard_utilities.h" #include "third_party/blink/renderer/core/clipboard/data_object.h" +#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/platform/graphics/image.h" #include "third_party/blink/renderer/platform/weborigin/kurl.h" #include "third_party/blink/renderer/platform/wtf/std_lib_extras.h" @@ -29,14 +31,8 @@ String NonNullString(const String& string) { } // namespace -// static -SystemClipboard& SystemClipboard::GetInstance() { - DEFINE_STATIC_LOCAL(SystemClipboard, clipboard, ()); - return clipboard; -} - -SystemClipboard::SystemClipboard() { - Platform::Current()->GetInterfaceProvider()->GetInterface( +SystemClipboard::SystemClipboard(LocalFrame* frame) { + frame->GetBrowserInterfaceBroker().GetInterface( clipboard_.BindNewPipeAndPassReceiver()); } @@ -156,6 +152,12 @@ SkBitmap SystemClipboard::ReadImage(mojom::ClipboardBuffer buffer) { return image; } +String SystemClipboard::ReadImageAsImageMarkup( + mojom::blink::ClipboardBuffer buffer) { + SkBitmap bitmap = ReadImage(buffer); + return BitmapToImageMarkup(bitmap); +} + void SystemClipboard::WriteImageWithTag(Image* image, const KURL& url, const String& title) { @@ -213,11 +215,11 @@ void SystemClipboard::WriteDataObject(DataObject* data_object) { WebDragData data = data_object->ToWebDragData(); for (const WebDragData::Item& item : data.Items()) { if (item.storage_type == WebDragData::Item::kStorageTypeString) { - if (item.string_type == blink::kMimeTypeTextPlain) { + if (item.string_type == kMimeTypeTextPlain) { clipboard_->WriteText(NonNullString(item.string_data)); - } else if (item.string_type == blink::kMimeTypeTextHTML) { + } else if (item.string_type == kMimeTypeTextHTML) { clipboard_->WriteHtml(NonNullString(item.string_data), KURL()); - } else if (item.string_type != blink::kMimeTypeDownloadURL) { + } else if (item.string_type != kMimeTypeDownloadURL) { custom_data.insert(item.string_type, NonNullString(item.string_data)); } } diff --git a/chromium/third_party/blink/renderer/core/clipboard/system_clipboard.h b/chromium/third_party/blink/renderer/core/clipboard/system_clipboard.h index 5b9e6cd3656..71a11cb6ffa 100644 --- a/chromium/third_party/blink/renderer/core/clipboard/system_clipboard.h +++ b/chromium/third_party/blink/renderer/core/clipboard/system_clipboard.h @@ -8,6 +8,7 @@ #include "mojo/public/cpp/bindings/remote.h" #include "third_party/blink/public/mojom/clipboard/clipboard.mojom-blink.h" #include "third_party/blink/renderer/core/core_export.h" +#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" #include "third_party/blink/renderer/platform/wtf/forward.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" @@ -17,18 +18,20 @@ namespace blink { class DataObject; class Image; class KURL; +class LocalFrame; -// This singleton provides read/write access to the system clipboard, -// mediating between core classes and mojom::ClipboardHost. +// SystemClipboard: +// - is a singleton. +// - provides sanitized, platform-neutral read/write access to the clipboard. +// - mediates between core classes and mojom::ClipboardHost. +// // All calls to write functions must be followed by a call to CommitWrite(). -class CORE_EXPORT SystemClipboard { - USING_FAST_MALLOC(SystemClipboard); - +class CORE_EXPORT SystemClipboard final + : public GarbageCollected<SystemClipboard> { public: - static SystemClipboard& GetInstance(); - enum SmartReplaceOption { kCanSmartReplace, kCannotSmartReplace }; + explicit SystemClipboard(LocalFrame* frame); uint64_t SequenceNumber(); bool IsSelectionMode() const; void SetSelectionMode(bool); @@ -55,6 +58,7 @@ class CORE_EXPORT SystemClipboard { String ReadRTF(); SkBitmap ReadImage(mojom::ClipboardBuffer); + String ReadImageAsImageMarkup(mojom::blink::ClipboardBuffer); // Write the image and its associated tag (bookmark/HTML types). void WriteImageWithTag(Image*, const KURL&, const String& title); @@ -68,8 +72,9 @@ class CORE_EXPORT SystemClipboard { // the OS clipboard. void CommitWrite(); + void Trace(Visitor*) {} + private: - SystemClipboard(); bool IsValidBufferType(mojom::ClipboardBuffer); mojo::Remote<mojom::blink::ClipboardHost> clipboard_; |