Index: components/open_from_clipboard/clipboard_recent_content_ios.mm |
diff --git a/components/open_from_clipboard/clipboard_recent_content_ios.mm b/components/open_from_clipboard/clipboard_recent_content_ios.mm |
index 7665e46731dd30992369991cabd68b0035c3ae39..123c4aa5afd4287356e2bec0c02aec567884d80c 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); |
droger
2015/08/17 08:27:39
It seems this change does not affect the behavior
Olivier
2015/08/17 08:33:19
The result is the same.
But adding the early retur
|
GURL gurl = GURL(clipboard); |
if (gurl.is_valid()) { |
for (size_t i = 0; i < arraysize(kAuthorizedSchemes); ++i) { |