OLD | NEW |
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> |
11 | 11 |
12 #import "base/ios/ios_util.h" | 12 #import "base/ios/ios_util.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/metrics/user_metrics.h" | 15 #include "base/metrics/user_metrics.h" |
16 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
17 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
19 #include "url/url_constants.h" | |
20 | 19 |
21 // Bridge that forwards UIApplicationDidBecomeActiveNotification notifications | 20 // Bridge that forwards UIApplicationDidBecomeActiveNotification notifications |
22 // to its delegate. | 21 // to its delegate. |
23 @interface ApplicationDidBecomeActiveNotificationListenerBridge : NSObject | 22 @interface ApplicationDidBecomeActiveNotificationListenerBridge : NSObject |
24 | 23 |
25 // Initialize the ApplicationDidBecomeActiveNotificationListenerBridge with | 24 // Initialize the ApplicationDidBecomeActiveNotificationListenerBridge with |
26 // |delegate| which must not be null. | 25 // |delegate| which must not be null. |
27 - (instancetype)initWithDelegate:(ClipboardRecentContentIOS*)delegate | 26 - (instancetype)initWithDelegate:(ClipboardRecentContentIOS*)delegate |
28 NS_DESIGNATED_INITIALIZER; | 27 NS_DESIGNATED_INITIALIZER; |
29 | 28 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // Key used to store the pasteboard's current change count. If when resuming | 75 // Key used to store the pasteboard's current change count. If when resuming |
77 // chrome the pasteboard's change count is different from the stored one, then | 76 // chrome the pasteboard's change count is different from the stored one, then |
78 // it means that the pasteboard's content has changed. | 77 // it means that the pasteboard's content has changed. |
79 NSString* kPasteboardChangeCountKey = @"PasteboardChangeCount"; | 78 NSString* kPasteboardChangeCountKey = @"PasteboardChangeCount"; |
80 // Key used to store the last date at which it was detected that the pasteboard | 79 // Key used to store the last date at which it was detected that the pasteboard |
81 // changed. It is used to evaluate the age of the pasteboard's content. | 80 // changed. It is used to evaluate the age of the pasteboard's content. |
82 NSString* kPasteboardChangeDateKey = @"PasteboardChangeDate"; | 81 NSString* kPasteboardChangeDateKey = @"PasteboardChangeDate"; |
83 // Key used to store the hash of the content of the pasteboard. Whenever the | 82 // Key used to store the hash of the content of the pasteboard. Whenever the |
84 // hash changed, the pasteboard content is considered to have changed. | 83 // hash changed, the pasteboard content is considered to have changed. |
85 NSString* kPasteboardEntryMD5Key = @"PasteboardEntryMD5"; | 84 NSString* kPasteboardEntryMD5Key = @"PasteboardEntryMD5"; |
86 base::TimeDelta kMaximumAgeOfClipboard = base::TimeDelta::FromHours(3); | |
87 // Schemes accepted by the ClipboardRecentContentIOS. | |
88 const char* kAuthorizedSchemes[] = { | |
89 url::kHttpScheme, | |
90 url::kHttpsScheme, | |
91 url::kDataScheme, | |
92 url::kAboutScheme, | |
93 }; | |
94 | 85 |
95 // Compute a hash consisting of the first 4 bytes of the MD5 hash of |string|. | 86 // Compute a hash consisting of the first 4 bytes of the MD5 hash of |string|. |
96 // This value is used to detect pasteboard content change. Keeping only 4 bytes | 87 // This value is used to detect pasteboard content change. Keeping only 4 bytes |
97 // is a privacy requirement to introduce collision and allow deniability of | 88 // is a privacy requirement to introduce collision and allow deniability of |
98 // having copied a given string. | 89 // having copied a given string. |
99 NSData* WeakMD5FromNSString(NSString* string) { | 90 NSData* WeakMD5FromNSString(NSString* string) { |
100 unsigned char hash[CC_MD5_DIGEST_LENGTH]; | 91 unsigned char hash[CC_MD5_DIGEST_LENGTH]; |
101 const std::string clipboard = base::SysNSStringToUTF8(string); | 92 const std::string clipboard = base::SysNSStringToUTF8(string); |
102 const char* c_string = clipboard.c_str(); | 93 const char* c_string = clipboard.c_str(); |
103 CC_MD5(c_string, strlen(c_string), hash); | 94 CC_MD5(c_string, strlen(c_string), hash); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 192 } |
202 | 193 |
203 GURL ClipboardRecentContentIOS::URLFromPasteboard() { | 194 GURL ClipboardRecentContentIOS::URLFromPasteboard() { |
204 NSString* clipboard_string = [[UIPasteboard generalPasteboard] string]; | 195 NSString* clipboard_string = [[UIPasteboard generalPasteboard] string]; |
205 if (!clipboard_string) { | 196 if (!clipboard_string) { |
206 return GURL::EmptyGURL(); | 197 return GURL::EmptyGURL(); |
207 } | 198 } |
208 const std::string clipboard = base::SysNSStringToUTF8(clipboard_string); | 199 const std::string clipboard = base::SysNSStringToUTF8(clipboard_string); |
209 GURL gurl = GURL(clipboard); | 200 GURL gurl = GURL(clipboard); |
210 if (gurl.is_valid()) { | 201 if (gurl.is_valid()) { |
211 for (size_t i = 0; i < arraysize(kAuthorizedSchemes); ++i) { | 202 if (IsAppropriateSuggestion(gurl)) |
212 if (gurl.SchemeIs(kAuthorizedSchemes[i])) { | 203 return gurl; |
213 return gurl; | |
214 } | |
215 } | |
216 if (!application_scheme_.empty() && | 204 if (!application_scheme_.empty() && |
217 gurl.SchemeIs(application_scheme_.c_str())) { | 205 gurl.SchemeIs(application_scheme_.c_str())) { |
218 return gurl; | 206 return gurl; |
219 } | 207 } |
220 } | 208 } |
221 return GURL::EmptyGURL(); | 209 return GURL::EmptyGURL(); |
222 } | 210 } |
223 | 211 |
224 void ClipboardRecentContentIOS::LoadFromUserDefaults() { | 212 void ClipboardRecentContentIOS::LoadFromUserDefaults() { |
225 last_pasteboard_change_count_ = | 213 last_pasteboard_change_count_ = |
(...skipping 12 matching lines...) Expand all Loading... |
238 forKey:kPasteboardChangeCountKey]; | 226 forKey:kPasteboardChangeCountKey]; |
239 [shared_user_defaults_ setObject:last_pasteboard_change_date_ | 227 [shared_user_defaults_ setObject:last_pasteboard_change_date_ |
240 forKey:kPasteboardChangeDateKey]; | 228 forKey:kPasteboardChangeDateKey]; |
241 [shared_user_defaults_ setObject:last_pasteboard_entry_md5_ | 229 [shared_user_defaults_ setObject:last_pasteboard_entry_md5_ |
242 forKey:kPasteboardEntryMD5Key]; | 230 forKey:kPasteboardEntryMD5Key]; |
243 } | 231 } |
244 | 232 |
245 base::TimeDelta ClipboardRecentContentIOS::Uptime() const { | 233 base::TimeDelta ClipboardRecentContentIOS::Uptime() const { |
246 return base::SysInfo::Uptime(); | 234 return base::SysInfo::Uptime(); |
247 } | 235 } |
OLD | NEW |