Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: components/handoff/handoff_manager.mm

Issue 2484703003: [ios] Adds code to support the iOS Handoff feature. (Closed)
Patch Set: Fix GN. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "build/build_config.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"
13 #include "components/handoff/pref_names_ios.h"
14 #include "components/pref_registry/pref_registry_syncable.h" // nogncheck
erikchen 2016/11/08 18:13:55 why do you need nogncheck?
rohitrao (ping after 24h) 2016/11/08 19:57:35 I added the components/pref_registry dependency on
14 #endif 15 #endif
15 16
16 #if defined(OS_MACOSX) && !defined(OS_IOS) 17 #if defined(OS_MACOSX) && !defined(OS_IOS)
17 #include "base/mac/mac_util.h" 18 #include "base/mac/mac_util.h"
18 #include "base/mac/sdk_forward_declarations.h" 19 #include "base/mac/sdk_forward_declarations.h"
19 #endif 20 #endif
20 21
21 @interface HandoffManager () 22 @interface HandoffManager ()
22 23
23 // The active user activity. 24 // The active user activity.
24 @property(nonatomic, retain) NSUserActivity* userActivity; 25 @property(nonatomic, retain) NSUserActivity* userActivity;
25 26
26 // Whether the URL of the current tab should be exposed for Handoff. 27 // Whether the URL of the current tab should be exposed for Handoff.
27 - (BOOL)shouldUseActiveURL; 28 - (BOOL)shouldUseActiveURL;
28 29
29 // Updates the active NSUserActivity. 30 // Updates the active NSUserActivity.
30 - (void)updateUserActivity; 31 - (void)updateUserActivity;
31 32
32 @end 33 @end
33 34
34 @implementation HandoffManager 35 @implementation HandoffManager
35 36
36 @synthesize userActivity = _userActivity; 37 @synthesize userActivity = _userActivity;
37 38
39 #if defined(OS_IOS)
40 + (void)registerBrowserStatePrefs:(user_prefs::PrefRegistrySyncable*)registry {
41 registry->RegisterBooleanPref(
42 prefs::kIosHandoffToOtherDevices, true,
43 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
44 }
45 #endif
46
38 - (instancetype)init { 47 - (instancetype)init {
39 self = [super init]; 48 self = [super init];
40 if (self) { 49 if (self) {
41 _propertyReleaser_HandoffManager.Init(self, [HandoffManager class]); 50 _propertyReleaser_HandoffManager.Init(self, [HandoffManager class]);
42 #if defined(OS_MACOSX) && !defined(OS_IOS) 51 #if defined(OS_MACOSX) && !defined(OS_IOS)
43 _origin = handoff::ORIGIN_MAC; 52 _origin = handoff::ORIGIN_MAC;
44 #elif defined(OS_IOS) 53 #elif defined(OS_IOS)
45 _origin = handoff::ORIGIN_IOS; 54 _origin = handoff::ORIGIN_IOS;
46 #else 55 #else
47 NOTREACHED(); 56 NOTREACHED();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 withObject:handoff::kChromeHandoffActivityType]; 100 withObject:handoff::kChromeHandoffActivityType];
92 self.userActivity = base::scoped_nsobject<NSUserActivity>(userActivity); 101 self.userActivity = base::scoped_nsobject<NSUserActivity>(userActivity);
93 self.userActivity.webpageURL = net::NSURLWithGURL(_activeURL); 102 self.userActivity.webpageURL = net::NSURLWithGURL(_activeURL);
94 NSString* origin = handoff::StringFromOrigin(_origin); 103 NSString* origin = handoff::StringFromOrigin(_origin);
95 DCHECK(origin); 104 DCHECK(origin);
96 self.userActivity.userInfo = @{ handoff::kOriginKey : origin }; 105 self.userActivity.userInfo = @{ handoff::kOriginKey : origin };
97 [self.userActivity becomeCurrent]; 106 [self.userActivity becomeCurrent];
98 } 107 }
99 108
100 @end 109 @end
110
111 @implementation HandoffManager (TestingOnly)
112
113 - (NSURL*)userActivityWebpageURL {
114 return self.userActivity.webpageURL;
115 }
116
117 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698