clipboard_recent_content_impl_ios.h 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IMPL_IOS_H_
  5. #define COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IMPL_IOS_H_
  6. #import <Foundation/Foundation.h>
  7. #import <UIKit/UIKit.h>
  8. typedef NSString* ContentType NS_TYPED_ENUM;
  9. extern ContentType const ContentTypeURL;
  10. extern ContentType const ContentTypeText;
  11. extern ContentType const ContentTypeImage;
  12. // A protocol implemented by delegates to handle clipboard changes.
  13. @protocol ClipboardRecentContentDelegate<NSObject>
  14. - (void)onClipboardChanged;
  15. @end
  16. // Helper class returning a URL if the content of the clipboard can be turned
  17. // into a URL, and if it estimates that the content of the clipboard is not too
  18. // old.
  19. @interface ClipboardRecentContentImplIOS : NSObject
  20. // |delegate| is used for metrics logging and can be nil. |authorizedSchemes|
  21. // should contain all schemes considered valid. |groupUserDefaults| is the
  22. // NSUserDefaults used to store information on pasteboard entry expiration. This
  23. // information will be shared with other applications in the application group.
  24. - (instancetype)initWithMaxAge:(NSTimeInterval)maxAge
  25. authorizedSchemes:(NSSet<NSString*>*)authorizedSchemes
  26. userDefaults:(NSUserDefaults*)groupUserDefaults
  27. delegate:(id<ClipboardRecentContentDelegate>)delegate
  28. NS_DESIGNATED_INITIALIZER;
  29. - (instancetype)init NS_UNAVAILABLE;
  30. // Returns the copied URL if the clipboard contains a recent URL that has not
  31. // been suppressed and will not trigger a pasteboard access notification.
  32. // Otherwise, returns nil.
  33. - (NSURL*)recentURLFromClipboard;
  34. // Returns the copied string if the clipboard contains a recent string that has
  35. // not been suppresed and will not trigger a pasteboard access notification.
  36. // Otherwise, returns nil.
  37. - (NSString*)recentTextFromClipboard;
  38. // Returns the copied image if the clipboard contains a recent image that has
  39. // not been suppressed and will not trigger a pasteboard access notification.
  40. // Otherwise, returns nil.
  41. - (UIImage*)recentImageFromClipboard;
  42. // Returns the set of content types being currently used on the clipboard; will
  43. // be nil if the current pasteboard contents are unknown, or if the clipboard
  44. // content age is expired.
  45. - (NSSet<ContentType>*)cachedClipboardContentTypes;
  46. // Uses the new iOS 14 pasteboard detection pattern API to asynchronously detect
  47. // if the clipboard contains content (that has not been suppressed) of the
  48. // requested types without actually getting the contents.
  49. - (void)hasContentMatchingTypes:(NSSet<ContentType>*)types
  50. completionHandler:
  51. (void (^)(NSSet<ContentType>*))completionHandler;
  52. // Uses the new iOS 14 pasteboard detection pattern API to asynchronously get a
  53. // copied URL from the clipboard if it has not been suppressed. Passes nil to
  54. // the callback otherwise.
  55. - (void)recentURLFromClipboardAsync:(void (^)(NSURL*))callback;
  56. // Uses the new iOS 14 pasteboard detection pattern API to asynchronously get a
  57. // copied string from the clipboard if it has not been suppressed. Passes nil to
  58. // the callback otherwise.
  59. - (void)recentTextFromClipboardAsync:(void (^)(NSString*))callback;
  60. // Asynchronously gets an image from the clipboard if is has not been
  61. // suppressed. Passes nil to the callback otherwise. This does not actually use
  62. // any iOS 14 APIs and could be done synchronously, but is here for consistency.
  63. - (void)recentImageFromClipboardAsync:(void (^)(UIImage*))callback;
  64. // Returns how old the content of the clipboard is.
  65. - (NSTimeInterval)clipboardContentAge;
  66. // Prevents GetRecentURLFromClipboard from returning anything until the
  67. // clipboard's content changes.
  68. - (void)suppressClipboardContent;
  69. // Methods below are exposed for testing purposes.
  70. // Estimation of the date when the pasteboard changed.
  71. @property(nonatomic, copy) NSDate* lastPasteboardChangeDate;
  72. // Saves information to the user defaults about the latest pasteboard entry.
  73. - (void)saveToUserDefaults;
  74. @end
  75. #endif // COMPONENTS_OPEN_FROM_CLIPBOARD_CLIPBOARD_RECENT_CONTENT_IMPL_IOS_H_