Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/handoff/handoff_manager.h" | 5 #include "components/handoff/handoff_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "components/handoff/handoff_utility.h" | |
| 10 #include "net/base/mac/url_conversions.h" | 9 #include "net/base/mac/url_conversions.h" |
| 11 | 10 |
| 12 #if defined(OS_IOS) | 11 #if defined(OS_IOS) |
| 13 #include "base/ios/ios_util.h" | 12 #include "base/ios/ios_util.h" |
| 14 #endif | 13 #endif |
| 15 | 14 |
| 16 #if defined(OS_MACOSX) && !defined(OS_IOS) | 15 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 17 #include "base/mac/mac_util.h" | 16 #include "base/mac/mac_util.h" |
| 18 #include "base/mac/sdk_forward_declarations.h" | 17 #include "base/mac/sdk_forward_declarations.h" |
| 19 #endif | 18 #endif |
| 20 | 19 |
| 21 @interface HandoffManager () | 20 @interface HandoffManager () |
| 22 | 21 |
| 23 // The active user activity. | 22 // The active user activity. |
| 24 @property(nonatomic, retain) NSUserActivity* userActivity; | 23 @property(nonatomic, retain) NSUserActivity* userActivity; |
| 25 | 24 |
| 26 // Whether the URL of the current tab should be exposed for Handoff. | 25 // Whether the URL of the current tab should be exposed for Handoff. |
| 27 - (BOOL)shouldUseActiveURL; | 26 - (BOOL)shouldUseActiveURL; |
| 28 | 27 |
| 29 // Updates the active NSUserActivity. | 28 // Updates the active NSUserActivity. |
| 30 - (void)updateUserActivity; | 29 - (void)updateUserActivity; |
| 31 | 30 |
| 32 @end | 31 @end |
| 33 | 32 |
| 34 @implementation HandoffManager | 33 @implementation HandoffManager |
| 35 | 34 |
| 36 @synthesize userActivity = _userActivity; | 35 @synthesize userActivity = _userActivity; |
| 37 | 36 |
| 38 - (instancetype)init { | 37 - (instancetype)init { |
| 38 NOTREACHED(); | |
| 39 return nil; | |
| 40 } | |
| 41 | |
| 42 - (instancetype)initWithOrigin:(handoff::Origin)origin { | |
| 43 DCHECK(origin == handoff::ORIGIN_IOS || origin == handoff::ORIGIN_MAC); | |
| 39 self = [super init]; | 44 self = [super init]; |
|
Avi (use Gerrit)
2015/03/26 18:14:04
Can we #ifdef so that if this is built for iOS we
erikchen
2015/03/26 18:22:36
Good suggestion, done.
| |
| 40 if (self) { | 45 if (self) { |
| 41 _propertyReleaser_HandoffManager.Init(self, [HandoffManager class]); | 46 _propertyReleaser_HandoffManager.Init(self, [HandoffManager class]); |
| 47 _origin = origin; | |
| 42 } | 48 } |
| 43 return self; | 49 return self; |
| 44 } | 50 } |
| 45 | 51 |
| 46 - (void)updateActiveURL:(const GURL&)url { | 52 - (void)updateActiveURL:(const GURL&)url { |
| 47 #if defined(OS_IOS) | 53 #if defined(OS_IOS) |
| 48 // Handoff is only available on iOS 8+. | 54 // Handoff is only available on iOS 8+. |
| 49 DCHECK(base::ios::IsRunningOnIOS8OrLater()); | 55 DCHECK(base::ios::IsRunningOnIOS8OrLater()); |
| 50 #endif | 56 #endif |
| 51 | 57 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 77 | 83 |
| 78 // Invalidate the old user activity and make a new one. | 84 // Invalidate the old user activity and make a new one. |
| 79 [self.userActivity invalidate]; | 85 [self.userActivity invalidate]; |
| 80 | 86 |
| 81 Class aClass = NSClassFromString(@"NSUserActivity"); | 87 Class aClass = NSClassFromString(@"NSUserActivity"); |
| 82 NSUserActivity* userActivity = [[aClass performSelector:@selector(alloc)] | 88 NSUserActivity* userActivity = [[aClass performSelector:@selector(alloc)] |
| 83 performSelector:@selector(initWithActivityType:) | 89 performSelector:@selector(initWithActivityType:) |
| 84 withObject:handoff::kChromeHandoffActivityType]; | 90 withObject:handoff::kChromeHandoffActivityType]; |
| 85 self.userActivity = base::scoped_nsobject<NSUserActivity>(userActivity); | 91 self.userActivity = base::scoped_nsobject<NSUserActivity>(userActivity); |
| 86 self.userActivity.webpageURL = net::NSURLWithGURL(_activeURL); | 92 self.userActivity.webpageURL = net::NSURLWithGURL(_activeURL); |
| 87 self.userActivity.userInfo = @{ handoff::kOriginKey : handoff::kOriginiOS }; | 93 NSString* origin = handoff::StringFromOrigin(_origin); |
| 94 DCHECK(origin); | |
| 95 self.userActivity.userInfo = @{ handoff::kOriginKey : origin }; | |
| 88 [self.userActivity becomeCurrent]; | 96 [self.userActivity becomeCurrent]; |
| 89 } | 97 } |
| 90 | 98 |
| 91 @end | 99 @end |
| OLD | NEW |