Revert "Don't attempt to clone NSPasteboards."
This reverts commit 7b01a37f8c4b5fb80e084bd1174d12bf39fec3a6.
Reason for revert: crbug.com/932051
Original change's description:
> Don't attempt to clone NSPasteboards.
>
> It doesn't work, as any file promises will be called in, and the
> loop over all the flavors will not be equipped to handle it.
>
> The MacViews code wants to provide an OSExchangeDataProvider for
> drags that it didn't initiate, so wrap a provider around the
> pasteboard rather than clone it.
>
> This is a second, improved attempt to land this (previously attempted
> with e11a5a297736acdbc93609906facd5da04e7b6c0). This version wraps
> the pasteboard for drag initiations rather than try to add the
> pasteboard item from one pasteboard to the new one. (Spoiler: it
> doesn't work; see bug 928684.)
>
> BUG=908349, 928684
>
> Change-Id: I3d9631c446ccf77958009e494113aa9ec20705df
> Reviewed-on: https://chromium-review.googlesource.com/c/1459582
> Reviewed-by: Sidney San MartÃn <[email protected]>
> Commit-Queue: Avi Drissman <[email protected]>
> Cr-Commit-Position: refs/heads/master@{#631382}
[email protected],[email protected]
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: 908349, 928684
Change-Id: I0e4cc09667eb97b1ef59e41deb719af362bb7497
Reviewed-on: https://chromium-review.googlesource.com/c/1473350
Reviewed-by: Avi Drissman <[email protected]>
Commit-Queue: Avi Drissman <[email protected]>
Cr-Commit-Position: refs/heads/master@{#632249}
diff --git a/ui/base/dragdrop/os_exchange_data_provider_mac.h b/ui/base/dragdrop/os_exchange_data_provider_mac.h
index 0b61404..5ba2a69 100644
--- a/ui/base/dragdrop/os_exchange_data_provider_mac.h
+++ b/ui/base/dragdrop/os_exchange_data_provider_mac.h
@@ -5,9 +5,6 @@
#ifndef UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_MAC_H_
#define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_MAC_H_
-#include <memory>
-
-#include "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#import "ui/base/clipboard/clipboard_util_mac.h"
@@ -17,27 +14,21 @@
@class NSArray;
@class NSData;
-@class NSDraggingItem;
@class NSPasteboard;
@class NSString;
namespace ui {
+class UniquePasteboard;
// OSExchangeData::Provider implementation for Mac.
class UI_BASE_EXPORT OSExchangeDataProviderMac
: public OSExchangeData::Provider {
public:
+ OSExchangeDataProviderMac();
~OSExchangeDataProviderMac() override;
- // Creates a stand-alone OSExchangeDataProviderMac.
- static std::unique_ptr<OSExchangeDataProviderMac> CreateProvider();
-
- // Creates an OSExchangeDataProviderMac object wrapping the given NSPasteboard
- // object.
- static std::unique_ptr<OSExchangeDataProviderMac>
- CreateProviderWrappingPasteboard(NSPasteboard* pasteboard);
-
// Overridden from OSExchangeData::Provider:
+ std::unique_ptr<Provider> Clone() const override;
void MarkOriginatedFromRenderer() override;
bool DidOriginateFromRenderer() const override;
void SetString(const base::string16& data) override;
@@ -63,26 +54,33 @@
gfx::ImageSkia GetDragImage() const override;
gfx::Vector2d GetDragImageOffset() const override;
- // Gets the underlying pasteboard.
- virtual NSPasteboard* GetPasteboard() const = 0;
+ // Returns the data for the specified type in the pasteboard.
+ NSData* GetNSDataForType(NSString* type) const;
- // Returns an NSDraggingItem useful for initiating a drag. (Currently
- // OSExchangeDataProviderMac can only have one item.)
- NSDraggingItem* GetDraggingItem() const;
+ // Gets the underlying pasteboard.
+ NSPasteboard* GetPasteboard() const;
+
+ // Returns the union of SupportedPasteboardTypes() and the types in the
+ // current pasteboard.
+ NSArray* GetAvailableTypes() const;
+
+ // Creates an OSExchangeData object from the given NSPasteboard object.
+ static std::unique_ptr<OSExchangeData> CreateDataFromPasteboard(
+ NSPasteboard* pasteboard);
// Returns an array of pasteboard types that can be supported by
// OSExchangeData.
static NSArray* SupportedPasteboardTypes();
- protected:
- OSExchangeDataProviderMac();
- OSExchangeDataProviderMac(const OSExchangeDataProviderMac&);
- OSExchangeDataProviderMac& operator=(const OSExchangeDataProviderMac&);
-
private:
+ explicit OSExchangeDataProviderMac(scoped_refptr<ui::UniquePasteboard>);
+ scoped_refptr<ui::UniquePasteboard> pasteboard_;
+
// Drag image and offset data.
gfx::ImageSkia drag_image_;
gfx::Vector2d cursor_offset_;
+
+ DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderMac);
};
} // namespace ui