Commit fc74af31 authored by Peter Collingbourne's avatar Peter Collingbourne Committed by Commit Bot

Use @available and availability in AppController and HandoffManager.

An upcoming version of clang removes the ability to suppress
availability warnings by redeclaring functions. The new way
to suppress warnings is to either annotate the caller with an
availability attribute or enclose the function reference in an "if
(@available)" block.

The functions willContinueUserActivityWithType and continueUserActivity
are called only by the operating system, so we can use availability
attributes. The function passURLToHandoffManager, however, may
be called or overridden from the test suite even before 10.10 (see
SetUpInProcessBrowserTestFixture in app_controller_mac_browsertest.mm),
so we need to use a runtime check.

Any references to NSUserActivity must have availability attributes
because that type was introduced in 10.10. The test-only parts
of HandoffManager are only used in an iOS-specific test, so for
simplicity we disable that code under non-iOS.

Bug: 735328
Change-Id: Ide1dd1cdec9f8a2c286ddd09d6e4ca6da2117e6a
Reviewed-on: https://chromium-review.googlesource.com/564226
Commit-Queue: Peter Collingbourne <pcc@chromium.org>
Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485379}
parent 861c78b3
...@@ -1557,13 +1557,15 @@ class AppControllerProfileObserver : public ProfileAttributesStorage::Observer { ...@@ -1557,13 +1557,15 @@ class AppControllerProfileObserver : public ProfileAttributesStorage::Observer {
} }
- (BOOL)application:(NSApplication*)application - (BOOL)application:(NSApplication*)application
willContinueUserActivityWithType:(NSString*)userActivityType { willContinueUserActivityWithType:(NSString*)userActivityType
__attribute__((availability(macos, introduced = 10.10))) {
return [userActivityType isEqualToString:NSUserActivityTypeBrowsingWeb]; return [userActivityType isEqualToString:NSUserActivityTypeBrowsingWeb];
} }
- (BOOL)application:(NSApplication*)application - (BOOL)application:(NSApplication*)application
continueUserActivity:(NSUserActivity*)userActivity continueUserActivity:(NSUserActivity*)userActivity
restorationHandler:(void (^)(NSArray*))restorationHandler { restorationHandler:(void (^)(NSArray*))restorationHandler
__attribute__((availability(macos, introduced = 10.10))) {
if (![userActivity.activityType if (![userActivity.activityType
isEqualToString:NSUserActivityTypeBrowsingWeb]) { isEqualToString:NSUserActivityTypeBrowsingWeb]) {
return NO; return NO;
...@@ -1599,7 +1601,14 @@ class AppControllerProfileObserver : public ProfileAttributesStorage::Observer { ...@@ -1599,7 +1601,14 @@ class AppControllerProfileObserver : public ProfileAttributesStorage::Observer {
} }
- (void)passURLToHandoffManager:(const GURL&)handoffURL { - (void)passURLToHandoffManager:(const GURL&)handoffURL {
[handoffManager_ updateActiveURL:handoffURL]; if (@available(macOS 10.10, *)) {
[handoffManager_ updateActiveURL:handoffURL];
} else {
// Only ends up being called in 10.10+, i.e. if shouldUseHandoff returns
// true. Some tests override shouldUseHandoff to always return true, but
// then they also override this function to do something else.
NOTREACHED();
}
} }
- (void)updateHandoffManager:(content::WebContents*)webContents { - (void)updateHandoffManager:(content::WebContents*)webContents {
......
...@@ -31,12 +31,15 @@ class PrefRegistrySyncable; ...@@ -31,12 +31,15 @@ class PrefRegistrySyncable;
// The active URL is defined as the URL of the most recently accessed tab. This // The active URL is defined as the URL of the most recently accessed tab. This
// method should be called any time the active URL might have changed. This // method should be called any time the active URL might have changed. This
// method is idempotent. // method is idempotent.
- (void)updateActiveURL:(const GURL&)url; - (void)updateActiveURL:(const GURL&)url
__attribute__((availability(macos, introduced = 10.10)));
@end @end
#if defined(OS_IOS)
@interface HandoffManager (TestingOnly) @interface HandoffManager (TestingOnly)
- (NSURL*)userActivityWebpageURL; - (NSURL*)userActivityWebpageURL;
@end @end
#endif
#endif // COMPONENTS_HANDOFF_HANDOFF_MANAGER_H_ #endif // COMPONENTS_HANDOFF_HANDOFF_MANAGER_H_
...@@ -23,20 +23,23 @@ ...@@ -23,20 +23,23 @@
@interface HandoffManager () @interface HandoffManager ()
// The active user activity. // The active user activity.
@property(nonatomic, retain) NSUserActivity* userActivity; @property(nonatomic, retain) NSUserActivity* userActivity
__attribute__((availability(macos, introduced=10.10)));
// Whether the URL of the current tab should be exposed for Handoff. // Whether the URL of the current tab should be exposed for Handoff.
- (BOOL)shouldUseActiveURL; - (BOOL)shouldUseActiveURL;
// Updates the active NSUserActivity. // Updates the active NSUserActivity.
- (void)updateUserActivity; - (void)updateUserActivity
__attribute__((availability(macos, introduced = 10.10)));
@end @end
@implementation HandoffManager { @implementation HandoffManager {
base::mac::ObjCPropertyReleaser _propertyReleaser_HandoffManager; base::mac::ObjCPropertyReleaser _propertyReleaser_HandoffManager;
GURL _activeURL; GURL _activeURL;
NSUserActivity* _userActivity; NSUserActivity* _userActivity
__attribute__((availability(macos, introduced = 10.10)));
handoff::Origin _origin; handoff::Origin _origin;
} }
...@@ -95,11 +98,8 @@ ...@@ -95,11 +98,8 @@
// Invalidate the old user activity and make a new one. // Invalidate the old user activity and make a new one.
[self.userActivity invalidate]; [self.userActivity invalidate];
Class aClass = NSClassFromString(@"NSUserActivity"); base::scoped_nsobject<NSUserActivity> userActivity([[NSUserActivity alloc]
base::scoped_nsobject<NSUserActivity> userActivity( initWithActivityType:handoff::kChromeHandoffActivityType]);
[[aClass performSelector:@selector(alloc)]
performSelector:@selector(initWithActivityType:)
withObject:handoff::kChromeHandoffActivityType]);
self.userActivity = userActivity; self.userActivity = userActivity;
self.userActivity.webpageURL = net::NSURLWithGURL(_activeURL); self.userActivity.webpageURL = net::NSURLWithGURL(_activeURL);
NSString* origin = handoff::StringFromOrigin(_origin); NSString* origin = handoff::StringFromOrigin(_origin);
...@@ -110,6 +110,7 @@ ...@@ -110,6 +110,7 @@
@end @end
#if defined(OS_IOS)
@implementation HandoffManager (TestingOnly) @implementation HandoffManager (TestingOnly)
- (NSURL*)userActivityWebpageURL { - (NSURL*)userActivityWebpageURL {
...@@ -117,3 +118,4 @@ ...@@ -117,3 +118,4 @@
} }
@end @end
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment