Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Unified Diff: components/open_from_clipboard/clipboard_recent_content_ios.mm

Issue 1293693006: Open from clipboard: Support nil clipboard (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: killed blank line Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698