summaryrefslogtreecommitdiffstats
path: root/components/open_from_clipboard
diff options
context:
space:
mode:
authorolivierrobin <olivierrobin@chromium.org>2015-08-17 02:03:18 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-17 09:03:54 +0000
commit4f12d389f9b35a11a8ab36aedc2368b91735c32d (patch)
treeeb6d3cd143de1c99ce259a545b4cffe7b18ebac0 /components/open_from_clipboard
parentcb504e4ee211f69c57074efdbc9952d1f81a9fc1 (diff)
downloadchromium_src-4f12d389f9b35a11a8ab36aedc2368b91735c32d.zip
chromium_src-4f12d389f9b35a11a8ab36aedc2368b91735c32d.tar.gz
chromium_src-4f12d389f9b35a11a8ab36aedc2368b91735c32d.tar.bz2
Open from clipboard: Support nil clipboard
Starting with iOS9 beta 5, the clipboard string can be nil in some circonstances. Consider this as a temporary access error and not a pasteboard change. Review URL: https://codereview.chromium.org/1293693006 Cr-Commit-Position: refs/heads/master@{#343648}
Diffstat (limited to 'components/open_from_clipboard')
-rw-r--r--components/open_from_clipboard/clipboard_recent_content_ios.mm25
1 files changed, 15 insertions, 10 deletions
diff --git a/components/open_from_clipboard/clipboard_recent_content_ios.mm b/components/open_from_clipboard/clipboard_recent_content_ios.mm
index 7665e46..123c4aa 100644
--- a/components/open_from_clipboard/clipboard_recent_content_ios.mm
+++ b/components/open_from_clipboard/clipboard_recent_content_ios.mm
@@ -148,6 +148,9 @@ void ClipboardRecentContentIOS::SuppressClipboardContent() {
}
void ClipboardRecentContentIOS::PasteboardChanged() {
+ NSString* pasteboard_string = [[UIPasteboard generalPasteboard] string];
+ if (!pasteboard_string)
+ return;
url_from_pasteboard_cache_ = URLFromPasteboard();
if (!url_from_pasteboard_cache_.is_empty()) {
base::RecordAction(
@@ -155,10 +158,6 @@ void ClipboardRecentContentIOS::PasteboardChanged() {
}
last_pasteboard_change_date_.reset([[NSDate date] retain]);
last_pasteboard_change_count_ = [UIPasteboard generalPasteboard].changeCount;
- NSString* pasteboard_string = [[UIPasteboard generalPasteboard] string];
- if (!pasteboard_string) {
- pasteboard_string = @"";
- }
NSData* MD5 = WeakMD5FromNSString(pasteboard_string);
last_pasteboard_entry_md5_.reset([MD5 retain]);
SaveToUserDefaults();
@@ -181,6 +180,13 @@ ClipboardRecentContentIOS::ClipboardRecentContentIOS(
}
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
// copy since last time it was checked.
// If the pasteboard content is still the same but the device was not
@@ -196,10 +202,6 @@ bool ClipboardRecentContentIOS::HasPasteboardChanged(base::TimeDelta uptime) {
if (not_rebooted)
return change_count_changed;
- NSString* pasteboard_string = [[UIPasteboard generalPasteboard] string];
- if (!pasteboard_string) {
- pasteboard_string = @"";
- }
NSData* md5 = WeakMD5FromNSString(pasteboard_string);
BOOL md5_changed = ![md5 isEqualToData:last_pasteboard_entry_md5_];
@@ -225,8 +227,11 @@ ClipboardRecentContentIOS::~ClipboardRecentContentIOS() {
}
GURL ClipboardRecentContentIOS::URLFromPasteboard() {
- const std::string clipboard =
- base::SysNSStringToUTF8([[UIPasteboard generalPasteboard] string]);
+ NSString* clipboard_string = [[UIPasteboard generalPasteboard] string];
+ if (!clipboard_string) {
+ return GURL::EmptyGURL();
+ }
+ const std::string clipboard = base::SysNSStringToUTF8(clipboard_string);
GURL gurl = GURL(clipboard);
if (gurl.is_valid()) {
for (size_t i = 0; i < arraysize(kAuthorizedSchemes); ++i) {