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

Side by Side Diff: ios/chrome/browser/device_sharing/handoff_manager.mm

Issue 2484703003: [ios] Adds code to support the iOS Handoff feature. (Closed)
Patch Set: Fixes. 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/device_sharing/handoff_manager.h"
6
7 #include "base/logging.h"
8 #include "base/mac/objc_property_releaser.h"
9 #import "base/mac/scoped_nsobject.h"
10 #include "components/handoff/handoff_utility.h"
11 #include "components/pref_registry/pref_registry_syncable.h"
12 #include "ios/chrome/browser/pref_names.h"
13 #import "net/base/mac/url_conversions.h"
14 #include "url/gurl.h"
15
16 @interface HandoffManager () {
17 base::mac::ObjCPropertyReleaser _propertyReleaser_HandoffManager;
18 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
19 }
20
21 // The active URL is exposed via the Handoff API. It is defined as the URL of
22 // the most recently accessed tab.
23 @property(nonatomic, assign) const GURL& activeURL;
24
25 // The active user activity.
26 @property(nonatomic, retain) NSUserActivity* userActivity;
27
28 // Whether the URL of the current tab should be exposed for Handoff.
29 - (BOOL)shouldUseActiveURL;
30
31 // Updates the active NSUserActivity.
32 - (void)updateUserActivity;
33
34 @end
35
36 @implementation HandoffManager
37
38 @synthesize userActivity = _userActivity;
39
40 + (void)registerBrowserStatePrefs:(user_prefs::PrefRegistrySyncable*)registry {
41 registry->RegisterBooleanPref(
42 prefs::kIosHandoffToOtherDevices, true,
43 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
44 }
45
46 - (instancetype)init {
47 self = [super init];
48 if (self) {
49 _propertyReleaser_HandoffManager.Init(self, [HandoffManager class]);
50 }
51 return self;
52 }
53
54 - (void)updateActiveURL:(const GURL&)url {
55 self.activeURL = url;
56 [self updateUserActivity];
57 }
58
59 - (void)setActiveURL:(const GURL&)url {
60 _activeURL = url;
61 }
62
63 - (const GURL&)activeURL {
64 return _activeURL;
65 }
66
67 - (BOOL)shouldUseActiveURL {
68 return self.activeURL.SchemeIsHTTPOrHTTPS();
69 }
70
71 - (void)updateUserActivity {
72 // Clear the user activity.
73 if (![self shouldUseActiveURL]) {
74 [self.userActivity invalidate];
75 self.userActivity = nil;
76 return;
77 }
78
79 // No change to the user activity.
80 const GURL userActivityURL(net::GURLWithNSURL(self.userActivity.webpageURL));
81 if (userActivityURL == self.activeURL)
82 return;
83
84 // Invalidate the old user activity and make a new one.
85 [self.userActivity invalidate];
86 self.userActivity =
87 base::scoped_nsobject<NSUserActivity>([[NSUserActivity alloc]
88 initWithActivityType:handoff::kChromeHandoffActivityType]);
89 self.userActivity.webpageURL = net::NSURLWithGURL(self.activeURL);
90 self.userActivity.userInfo = @{handoff::kOriginKey : handoff::kOriginiOS};
91 [self.userActivity becomeCurrent];
92 }
93
94 @end
95
96 @implementation HandoffManager (TestingOnly)
97
98 - (NSURL*)userActivityWebpageURL {
99 return self.userActivity.webpageURL;
100 }
101
102 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698