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

Side by Side Diff: components/open_from_clipboard/clipboard_recent_content_ios.mm

Issue 1804143005: Reverts a temporary fix for UIPasteboard on iOS 9 beta 5. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added test Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "components/open_from_clipboard/clipboard_recent_content_ios.h" 5 #import "components/open_from_clipboard/clipboard_recent_content_ios.h"
6 6
7 #import <CommonCrypto/CommonDigest.h> 7 #import <CommonCrypto/CommonDigest.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #import <UIKit/UIKit.h> 10 #import <UIKit/UIKit.h>
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 void ClipboardRecentContentIOS::SuppressClipboardContent() { 142 void ClipboardRecentContentIOS::SuppressClipboardContent() {
143 // User cleared the user data. The pasteboard entry must be removed from the 143 // User cleared the user data. The pasteboard entry must be removed from the
144 // omnibox list. Force entry expiration by setting copy date to 1970. 144 // omnibox list. Force entry expiration by setting copy date to 1970.
145 last_pasteboard_change_date_.reset( 145 last_pasteboard_change_date_.reset(
146 [[NSDate alloc] initWithTimeIntervalSince1970:0]); 146 [[NSDate alloc] initWithTimeIntervalSince1970:0]);
147 SaveToUserDefaults(); 147 SaveToUserDefaults();
148 } 148 }
149 149
150 void ClipboardRecentContentIOS::PasteboardChanged() { 150 void ClipboardRecentContentIOS::PasteboardChanged() {
151 NSString* pasteboard_string = [[UIPasteboard generalPasteboard] string];
152 if (!pasteboard_string)
153 return;
154 url_from_pasteboard_cache_ = URLFromPasteboard(); 151 url_from_pasteboard_cache_ = URLFromPasteboard();
155 if (!url_from_pasteboard_cache_.is_empty()) { 152 if (!url_from_pasteboard_cache_.is_empty()) {
156 base::RecordAction( 153 base::RecordAction(
157 base::UserMetricsAction("MobileOmniboxClipboardChanged")); 154 base::UserMetricsAction("MobileOmniboxClipboardChanged"));
158 } 155 }
159 last_pasteboard_change_date_.reset([[NSDate date] retain]); 156 last_pasteboard_change_date_.reset([[NSDate date] retain]);
160 last_pasteboard_change_count_ = [UIPasteboard generalPasteboard].changeCount; 157 last_pasteboard_change_count_ = [UIPasteboard generalPasteboard].changeCount;
158 NSString* pasteboard_string = [[UIPasteboard generalPasteboard] string];
159 if (!pasteboard_string) {
160 pasteboard_string = @"";
161 }
161 NSData* MD5 = WeakMD5FromNSString(pasteboard_string); 162 NSData* MD5 = WeakMD5FromNSString(pasteboard_string);
162 last_pasteboard_entry_md5_.reset([MD5 retain]); 163 last_pasteboard_entry_md5_.reset([MD5 retain]);
163 SaveToUserDefaults(); 164 SaveToUserDefaults();
164 } 165 }
165 166
166 ClipboardRecentContentIOS::ClipboardRecentContentIOS( 167 ClipboardRecentContentIOS::ClipboardRecentContentIOS(
167 const std::string& application_scheme, 168 const std::string& application_scheme,
168 NSUserDefaults* group_user_defaults) 169 NSUserDefaults* group_user_defaults)
169 : application_scheme_(application_scheme), 170 : application_scheme_(application_scheme),
170 shared_user_defaults_([group_user_defaults retain]) { 171 shared_user_defaults_([group_user_defaults retain]) {
171 Init(base::SysInfo::Uptime()); 172 Init(base::SysInfo::Uptime());
172 } 173 }
173 174
174 ClipboardRecentContentIOS::ClipboardRecentContentIOS( 175 ClipboardRecentContentIOS::ClipboardRecentContentIOS(
175 const std::string& application_scheme, 176 const std::string& application_scheme,
176 base::TimeDelta uptime) 177 base::TimeDelta uptime)
177 : application_scheme_(application_scheme), 178 : application_scheme_(application_scheme),
178 shared_user_defaults_([[NSUserDefaults standardUserDefaults] retain]) { 179 shared_user_defaults_([[NSUserDefaults standardUserDefaults] retain]) {
179 Init(uptime); 180 Init(uptime);
180 } 181 }
181 182
182 bool ClipboardRecentContentIOS::HasPasteboardChanged(base::TimeDelta uptime) { 183 bool ClipboardRecentContentIOS::HasPasteboardChanged(base::TimeDelta uptime) {
183 // If [[UIPasteboard generalPasteboard] string] is nil, the content of the
184 // pasteboard cannot be accessed. This case should not be considered as a
185 // pasteboard change.
186 NSString* pasteboard_string = [[UIPasteboard generalPasteboard] string];
187 if (!pasteboard_string)
188 return NO;
189
190 // If |MD5Changed|, we know for sure there has been at least one pasteboard 184 // If |MD5Changed|, we know for sure there has been at least one pasteboard
191 // copy since last time it was checked. 185 // copy since last time it was checked.
192 // If the pasteboard content is still the same but the device was not 186 // If the pasteboard content is still the same but the device was not
193 // rebooted, the change count can be checked to see if it changed. 187 // rebooted, the change count can be checked to see if it changed.
194 // Note: due to a mismatch between the actual behavior and documentation, and 188 // Note: due to a mismatch between the actual behavior and documentation, and
195 // lack of consistency on different reboot scenarios, the change count cannot 189 // lack of consistency on different reboot scenarios, the change count cannot
196 // be checked after a reboot. 190 // be checked after a reboot.
197 // See radar://21833556 for more information. 191 // See radar://21833556 for more information.
198 NSInteger change_count = [UIPasteboard generalPasteboard].changeCount; 192 NSInteger change_count = [UIPasteboard generalPasteboard].changeCount;
199 bool change_count_changed = change_count != last_pasteboard_change_count_; 193 bool change_count_changed = change_count != last_pasteboard_change_count_;
200 194
201 bool not_rebooted = uptime > GetClipboardContentAge(); 195 bool not_rebooted = uptime > GetClipboardContentAge();
202 if (not_rebooted) 196 if (not_rebooted)
203 return change_count_changed; 197 return change_count_changed;
204 198
199 NSString* pasteboard_string = [[UIPasteboard generalPasteboard] string];
200 if (!pasteboard_string) {
201 pasteboard_string = @"";
202 }
205 NSData* md5 = WeakMD5FromNSString(pasteboard_string); 203 NSData* md5 = WeakMD5FromNSString(pasteboard_string);
206 BOOL md5_changed = ![md5 isEqualToData:last_pasteboard_entry_md5_]; 204 BOOL md5_changed = ![md5 isEqualToData:last_pasteboard_entry_md5_];
207 205
208 return md5_changed; 206 return md5_changed;
209 } 207 }
210 208
211 void ClipboardRecentContentIOS::Init(base::TimeDelta uptime) { 209 void ClipboardRecentContentIOS::Init(base::TimeDelta uptime) {
212 last_pasteboard_change_count_ = NSIntegerMax; 210 last_pasteboard_change_count_ = NSIntegerMax;
213 url_from_pasteboard_cache_ = URLFromPasteboard(); 211 url_from_pasteboard_cache_ = URLFromPasteboard();
214 LoadFromUserDefaults(); 212 LoadFromUserDefaults();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 void ClipboardRecentContentIOS::SaveToUserDefaults() { 272 void ClipboardRecentContentIOS::SaveToUserDefaults() {
275 [shared_user_defaults_ setInteger:last_pasteboard_change_count_ 273 [shared_user_defaults_ setInteger:last_pasteboard_change_count_
276 forKey:kPasteboardChangeCountKey]; 274 forKey:kPasteboardChangeCountKey];
277 [shared_user_defaults_ setObject:last_pasteboard_change_date_ 275 [shared_user_defaults_ setObject:last_pasteboard_change_date_
278 forKey:kPasteboardChangeDateKey]; 276 forKey:kPasteboardChangeDateKey];
279 [shared_user_defaults_ setObject:last_pasteboard_entry_md5_ 277 [shared_user_defaults_ setObject:last_pasteboard_entry_md5_
280 forKey:kPasteboardEntryMD5Key]; 278 forKey:kPasteboardEntryMD5Key];
281 [shared_user_defaults_ setObject:last_displayed_pasteboard_entry_ 279 [shared_user_defaults_ setObject:last_displayed_pasteboard_entry_
282 forKey:kLastDisplayedPasteboardEntryKey]; 280 forKey:kLastDisplayedPasteboardEntryKey];
283 } 281 }
OLDNEW
« no previous file with comments | « no previous file | components/open_from_clipboard/clipboard_recent_content_ios_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698