| 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/objc_property_releaser.h" | 8 #include "base/mac/objc_release_properties.h" |
| 9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #include "net/base/mac/url_conversions.h" | 10 #include "net/base/mac/url_conversions.h" |
| 11 | 11 |
| 12 #if defined(OS_IOS) | 12 #if defined(OS_IOS) |
| 13 #include "base/ios/ios_util.h" | 13 #include "base/ios/ios_util.h" |
| 14 #include "components/handoff/pref_names_ios.h" | 14 #include "components/handoff/pref_names_ios.h" |
| 15 #include "components/pref_registry/pref_registry_syncable.h" // nogncheck | 15 #include "components/pref_registry/pref_registry_syncable.h" // nogncheck |
| 16 #endif | 16 #endif |
| 17 | 17 |
| 18 #if defined(OS_MACOSX) && !defined(OS_IOS) | 18 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 19 #include "base/mac/mac_util.h" | 19 #include "base/mac/mac_util.h" |
| 20 #include "base/mac/sdk_forward_declarations.h" | 20 #include "base/mac/sdk_forward_declarations.h" |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 @interface HandoffManager () | 23 @interface HandoffManager () |
| 24 | 24 |
| 25 // The active user activity. | 25 // The active user activity. |
| 26 @property(nonatomic, retain) NSUserActivity* userActivity; | 26 @property(nonatomic, retain) NSUserActivity* userActivity; |
| 27 | 27 |
| 28 // Whether the URL of the current tab should be exposed for Handoff. | 28 // Whether the URL of the current tab should be exposed for Handoff. |
| 29 - (BOOL)shouldUseActiveURL; | 29 - (BOOL)shouldUseActiveURL; |
| 30 | 30 |
| 31 // Updates the active NSUserActivity. | 31 // Updates the active NSUserActivity. |
| 32 - (void)updateUserActivity; | 32 - (void)updateUserActivity; |
| 33 | 33 |
| 34 @end | 34 @end |
| 35 | 35 |
| 36 @implementation HandoffManager { | 36 @implementation HandoffManager { |
| 37 base::mac::ObjCPropertyReleaser _propertyReleaser_HandoffManager; | |
| 38 GURL _activeURL; | 37 GURL _activeURL; |
| 39 NSUserActivity* _userActivity; | 38 NSUserActivity* _userActivity; |
| 40 handoff::Origin _origin; | 39 handoff::Origin _origin; |
| 41 } | 40 } |
| 42 | 41 |
| 43 @synthesize userActivity = _userActivity; | 42 @synthesize userActivity = _userActivity; |
| 44 | 43 |
| 45 #if defined(OS_IOS) | 44 #if defined(OS_IOS) |
| 46 + (void)registerBrowserStatePrefs:(user_prefs::PrefRegistrySyncable*)registry { | 45 + (void)registerBrowserStatePrefs:(user_prefs::PrefRegistrySyncable*)registry { |
| 47 registry->RegisterBooleanPref( | 46 registry->RegisterBooleanPref( |
| 48 prefs::kIosHandoffToOtherDevices, true, | 47 prefs::kIosHandoffToOtherDevices, true, |
| 49 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 48 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 50 } | 49 } |
| 51 #endif | 50 #endif |
| 52 | 51 |
| 53 - (instancetype)init { | 52 - (instancetype)init { |
| 54 self = [super init]; | 53 self = [super init]; |
| 55 if (self) { | 54 if (self) { |
| 56 _propertyReleaser_HandoffManager.Init(self, [HandoffManager class]); | |
| 57 #if defined(OS_MACOSX) && !defined(OS_IOS) | 55 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 58 _origin = handoff::ORIGIN_MAC; | 56 _origin = handoff::ORIGIN_MAC; |
| 59 #elif defined(OS_IOS) | 57 #elif defined(OS_IOS) |
| 60 _origin = handoff::ORIGIN_IOS; | 58 _origin = handoff::ORIGIN_IOS; |
| 61 #else | 59 #else |
| 62 NOTREACHED(); | 60 NOTREACHED(); |
| 63 #endif | 61 #endif |
| 64 } | 62 } |
| 65 return self; | 63 return self; |
| 66 } | 64 } |
| 67 | 65 |
| 66 - (void)dealloc { |
| 67 base::mac::ReleaseProperties(self); |
| 68 [super dealloc]; |
| 69 } |
| 70 |
| 68 - (void)updateActiveURL:(const GURL&)url { | 71 - (void)updateActiveURL:(const GURL&)url { |
| 69 #if defined(OS_MACOSX) && !defined(OS_IOS) | 72 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 70 // Handoff is only available on OSX 10.10+. | 73 // Handoff is only available on OSX 10.10+. |
| 71 DCHECK(base::mac::IsAtLeastOS10_10()); | 74 DCHECK(base::mac::IsAtLeastOS10_10()); |
| 72 #endif | 75 #endif |
| 73 | 76 |
| 74 _activeURL = url; | 77 _activeURL = url; |
| 75 [self updateUserActivity]; | 78 [self updateUserActivity]; |
| 76 } | 79 } |
| 77 | 80 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 112 |
| 110 @end | 113 @end |
| 111 | 114 |
| 112 @implementation HandoffManager (TestingOnly) | 115 @implementation HandoffManager (TestingOnly) |
| 113 | 116 |
| 114 - (NSURL*)userActivityWebpageURL { | 117 - (NSURL*)userActivityWebpageURL { |
| 115 return self.userActivity.webpageURL; | 118 return self.userActivity.webpageURL; |
| 116 } | 119 } |
| 117 | 120 |
| 118 @end | 121 @end |
| OLD | NEW |