Chromium Code Reviews| Index: ios/chrome/browser/device_sharing/handoff_manager.mm |
| diff --git a/ios/chrome/browser/device_sharing/handoff_manager.mm b/ios/chrome/browser/device_sharing/handoff_manager.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..80e3c17a6ea894b0fadbed7ddbc94ed6663c6f67 |
| --- /dev/null |
| +++ b/ios/chrome/browser/device_sharing/handoff_manager.mm |
| @@ -0,0 +1,102 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/chrome/browser/device_sharing/handoff_manager.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/mac/objc_property_releaser.h" |
| +#import "base/mac/scoped_nsobject.h" |
| +#include "components/handoff/handoff_utility.h" |
| +#include "components/pref_registry/pref_registry_syncable.h" |
| +#include "ios/chrome/browser/pref_names.h" |
| +#import "net/base/mac/url_conversions.h" |
| +#include "url/gurl.h" |
| + |
| +@interface HandoffManager () { |
| + base::mac::ObjCPropertyReleaser _propertyReleaser_HandoffManager; |
| + GURL _activeURL; |
|
erikchen
2016/11/07 22:02:08
I think you should remove this line and add an exp
rohitrao (ping after 24h)
2016/11/08 02:19:42
No longer relevant, this file has been deleted fro
|
| +} |
| + |
| +// The active URL is exposed via the Handoff API. It is defined as the URL of |
| +// the most recently accessed tab. |
| +@property(nonatomic, assign) const GURL& activeURL; |
| + |
| +// The active user activity. |
| +@property(nonatomic, retain) NSUserActivity* userActivity; |
| + |
| +// Whether the URL of the current tab should be exposed for Handoff. |
| +- (BOOL)shouldUseActiveURL; |
| + |
| +// Updates the active NSUserActivity. |
| +- (void)updateUserActivity; |
| + |
| +@end |
| + |
| +@implementation HandoffManager |
| + |
| +@synthesize userActivity = _userActivity; |
| + |
| ++ (void)registerBrowserStatePrefs:(user_prefs::PrefRegistrySyncable*)registry { |
| + registry->RegisterBooleanPref( |
| + prefs::kIosHandoffToOtherDevices, true, |
| + user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| +} |
| + |
| +- (instancetype)init { |
| + self = [super init]; |
| + if (self) { |
| + _propertyReleaser_HandoffManager.Init(self, [HandoffManager class]); |
| + } |
| + return self; |
| +} |
| + |
| +- (void)updateActiveURL:(const GURL&)url { |
| + self.activeURL = url; |
| + [self updateUserActivity]; |
| +} |
| + |
| +- (void)setActiveURL:(const GURL&)url { |
| + _activeURL = url; |
| +} |
| + |
| +- (const GURL&)activeURL { |
| + return _activeURL; |
| +} |
| + |
| +- (BOOL)shouldUseActiveURL { |
| + return self.activeURL.SchemeIsHTTPOrHTTPS(); |
| +} |
| + |
| +- (void)updateUserActivity { |
| + // Clear the user activity. |
| + if (![self shouldUseActiveURL]) { |
| + [self.userActivity invalidate]; |
| + self.userActivity = nil; |
| + return; |
| + } |
| + |
| + // No change to the user activity. |
| + const GURL userActivityURL(net::GURLWithNSURL(self.userActivity.webpageURL)); |
| + if (userActivityURL == self.activeURL) |
| + return; |
| + |
| + // Invalidate the old user activity and make a new one. |
| + [self.userActivity invalidate]; |
| + self.userActivity = |
| + base::scoped_nsobject<NSUserActivity>([[NSUserActivity alloc] |
| + initWithActivityType:handoff::kChromeHandoffActivityType]); |
| + self.userActivity.webpageURL = net::NSURLWithGURL(self.activeURL); |
| + self.userActivity.userInfo = @{handoff::kOriginKey : handoff::kOriginiOS}; |
| + [self.userActivity becomeCurrent]; |
| +} |
| + |
| +@end |
| + |
| +@implementation HandoffManager (TestingOnly) |
| + |
| +- (NSURL*)userActivityWebpageURL { |
| + return self.userActivity.webpageURL; |
| +} |
| + |
| +@end |