Commit 4b14237f authored by stkhapugin's avatar stkhapugin Committed by Commit bot

Reverts a temporary fix for UIPasteboard on iOS 9 beta 5.

Reverted CL: https://codereview.chromium.org/1293693006.
In iOS 9 (release) and later, the pasteboard bug was fixed.

BUG=588715

Review URL: https://codereview.chromium.org/1804143005

Cr-Commit-Position: refs/heads/master@{#381706}
parent 90cbedb3
...@@ -148,9 +148,6 @@ void ClipboardRecentContentIOS::SuppressClipboardContent() { ...@@ -148,9 +148,6 @@ void ClipboardRecentContentIOS::SuppressClipboardContent() {
} }
void ClipboardRecentContentIOS::PasteboardChanged() { void ClipboardRecentContentIOS::PasteboardChanged() {
NSString* pasteboard_string = [[UIPasteboard generalPasteboard] string];
if (!pasteboard_string)
return;
url_from_pasteboard_cache_ = URLFromPasteboard(); url_from_pasteboard_cache_ = URLFromPasteboard();
if (!url_from_pasteboard_cache_.is_empty()) { if (!url_from_pasteboard_cache_.is_empty()) {
base::RecordAction( base::RecordAction(
...@@ -158,6 +155,10 @@ void ClipboardRecentContentIOS::PasteboardChanged() { ...@@ -158,6 +155,10 @@ void ClipboardRecentContentIOS::PasteboardChanged() {
} }
last_pasteboard_change_date_.reset([[NSDate date] retain]); last_pasteboard_change_date_.reset([[NSDate date] retain]);
last_pasteboard_change_count_ = [UIPasteboard generalPasteboard].changeCount; last_pasteboard_change_count_ = [UIPasteboard generalPasteboard].changeCount;
NSString* pasteboard_string = [[UIPasteboard generalPasteboard] string];
if (!pasteboard_string) {
pasteboard_string = @"";
}
NSData* MD5 = WeakMD5FromNSString(pasteboard_string); NSData* MD5 = WeakMD5FromNSString(pasteboard_string);
last_pasteboard_entry_md5_.reset([MD5 retain]); last_pasteboard_entry_md5_.reset([MD5 retain]);
SaveToUserDefaults(); SaveToUserDefaults();
...@@ -180,13 +181,6 @@ ClipboardRecentContentIOS::ClipboardRecentContentIOS( ...@@ -180,13 +181,6 @@ ClipboardRecentContentIOS::ClipboardRecentContentIOS(
} }
bool ClipboardRecentContentIOS::HasPasteboardChanged(base::TimeDelta uptime) { bool ClipboardRecentContentIOS::HasPasteboardChanged(base::TimeDelta uptime) {
// If [[UIPasteboard generalPasteboard] string] is nil, the content of the
// pasteboard cannot be accessed. This case should not be considered as a
// pasteboard change.
NSString* pasteboard_string = [[UIPasteboard generalPasteboard] string];
if (!pasteboard_string)
return NO;
// If |MD5Changed|, we know for sure there has been at least one pasteboard // If |MD5Changed|, we know for sure there has been at least one pasteboard
// copy since last time it was checked. // copy since last time it was checked.
// If the pasteboard content is still the same but the device was not // If the pasteboard content is still the same but the device was not
...@@ -202,6 +196,10 @@ bool ClipboardRecentContentIOS::HasPasteboardChanged(base::TimeDelta uptime) { ...@@ -202,6 +196,10 @@ bool ClipboardRecentContentIOS::HasPasteboardChanged(base::TimeDelta uptime) {
if (not_rebooted) if (not_rebooted)
return change_count_changed; return change_count_changed;
NSString* pasteboard_string = [[UIPasteboard generalPasteboard] string];
if (!pasteboard_string) {
pasteboard_string = @"";
}
NSData* md5 = WeakMD5FromNSString(pasteboard_string); NSData* md5 = WeakMD5FromNSString(pasteboard_string);
BOOL md5_changed = ![md5 isEqualToData:last_pasteboard_entry_md5_]; BOOL md5_changed = ![md5 isEqualToData:last_pasteboard_entry_md5_];
......
...@@ -12,6 +12,11 @@ ...@@ -12,6 +12,11 @@
#include "testing/platform_test.h" #include "testing/platform_test.h"
namespace { namespace {
void SetPasteboardImage(UIImage* image) {
[[UIPasteboard generalPasteboard] setImage:image];
}
void SetPasteboardContent(const char* data) { void SetPasteboardContent(const char* data) {
[[UIPasteboard generalPasteboard] [[UIPasteboard generalPasteboard]
setValue:[NSString stringWithUTF8String:data] setValue:[NSString stringWithUTF8String:data]
...@@ -144,3 +149,26 @@ TEST_F(ClipboardRecentContentIOSTest, SupressedPasteboard) { ...@@ -144,3 +149,26 @@ TEST_F(ClipboardRecentContentIOSTest, SupressedPasteboard) {
SetPasteboardContent(kRecognizedURL); SetPasteboardContent(kRecognizedURL);
EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl)); EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl));
} }
// Checks that if user copies something other than a string we don't cache the
// string in pasteboard.
TEST_F(ClipboardRecentContentIOSTest, AddingNonStringRemovesCachedString) {
GURL gurl;
SetPasteboardContent(kRecognizedURL);
// Test that recent pasteboard data is provided.
EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl));
EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str());
// Overwrite pasteboard with an image.
base::scoped_nsobject<UIImage> image([[UIImage alloc] init]);
SetPasteboardImage(image);
// Pasteboard should appear empty.
EXPECT_FALSE(clipboard_content_->GetRecentURLFromClipboard(&gurl));
// Tests that if URL is added again, pasteboard provides it normally.
SetPasteboardContent(kRecognizedURL);
EXPECT_TRUE(clipboard_content_->GetRecentURLFromClipboard(&gurl));
EXPECT_STREQ(kRecognizedURL, gurl.spec().c_str());
}
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