OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #import "ios/chrome/widget_extension/widget_view_controller.h" | 5 #import "ios/chrome/search_widget_extension/search_widget_view_controller.h" |
6 | 6 |
7 #import <NotificationCenter/NotificationCenter.h> | 7 #import <NotificationCenter/NotificationCenter.h> |
8 | 8 |
9 #include "base/ios/ios_util.h" | 9 #include "base/ios/ios_util.h" |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "components/open_from_clipboard/clipboard_recent_content_impl_ios.h" | 12 #include "components/open_from_clipboard/clipboard_recent_content_impl_ios.h" |
13 #include "ios/chrome/common/app_group/app_group_constants.h" | 13 #include "ios/chrome/common/app_group/app_group_constants.h" |
14 #import "ios/chrome/widget_extension/widget_view.h" | 14 #import "ios/chrome/search_widget_extension/search_widget_view.h" |
15 | 15 |
16 #if !defined(__has_feature) || !__has_feature(objc_arc) | 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
17 #error "This file requires ARC support." | 17 #error "This file requires ARC support." |
18 #endif | 18 #endif |
19 | 19 |
20 namespace { | 20 namespace { |
21 // Using GURL in the extension is not wanted as it includes ICU which makes the | 21 // Using GURL in the extension is not wanted as it includes ICU which makes the |
22 // extension binary much larger; therefore, ios/chrome/common/x_callback_url.h | 22 // extension binary much larger; therefore, ios/chrome/common/x_callback_url.h |
23 // cannot be used. This class makes a very basic use of x-callback-url, so no | 23 // cannot be used. This class makes a very basic use of x-callback-url, so no |
24 // full implementation is required. | 24 // full implementation is required. |
25 NSString* const kXCallbackURLHost = @"x-callback-url"; | 25 NSString* const kXCallbackURLHost = @"x-callback-url"; |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 @interface WidgetViewController ()<WidgetViewActionTarget> | 28 @interface SearchWidgetViewController ()<SearchWidgetViewActionTarget> |
29 @property(nonatomic, weak) WidgetView* widgetView; | 29 @property(nonatomic, weak) SearchWidgetView* widgetView; |
30 @property(nonatomic, strong) NSURL* copiedURL; | 30 @property(nonatomic, strong) NSURL* copiedURL; |
31 @property(nonatomic, strong) | 31 @property(nonatomic, strong) |
32 ClipboardRecentContentImplIOS* clipboardRecentContent; | 32 ClipboardRecentContentImplIOS* clipboardRecentContent; |
33 | 33 |
34 // Updates the widget with latest data from the clipboard. Returns whether any | 34 // Updates the widget with latest data from the clipboard. Returns whether any |
35 // visual updates occured. | 35 // visual updates occured. |
36 - (BOOL)updateWidget; | 36 - (BOOL)updateWidget; |
37 // Opens the main application with the given |command|. | 37 // Opens the main application with the given |command|. |
38 - (void)openAppWithCommand:(NSString*)command; | 38 - (void)openAppWithCommand:(NSString*)command; |
39 // Opens the main application with the given |command| and |parameter|. | 39 // Opens the main application with the given |command| and |parameter|. |
40 - (void)openAppWithCommand:(NSString*)command parameter:(NSString*)parameter; | 40 - (void)openAppWithCommand:(NSString*)command parameter:(NSString*)parameter; |
41 // Returns the dictionary of commands to pass via user defaults to open the main | 41 // Returns the dictionary of commands to pass via user defaults to open the main |
42 // application for a given |command| and |parameter|. | 42 // application for a given |command| and |parameter|. |
43 + (NSDictionary*)dictForCommand:(NSString*)command | 43 + (NSDictionary*)dictForCommand:(NSString*)command |
44 parameter:(NSString*)parameter; | 44 parameter:(NSString*)parameter; |
45 | 45 |
46 @end | 46 @end |
47 | 47 |
48 @implementation WidgetViewController | 48 @implementation SearchWidgetViewController |
49 | 49 |
50 @synthesize widgetView = _widgetView; | 50 @synthesize widgetView = _widgetView; |
51 @synthesize copiedURL = _copiedURL; | 51 @synthesize copiedURL = _copiedURL; |
52 @synthesize clipboardRecentContent = _clipboardRecentContent; | 52 @synthesize clipboardRecentContent = _clipboardRecentContent; |
53 | 53 |
54 - (instancetype)init { | 54 - (instancetype)init { |
55 self = [super init]; | 55 self = [super init]; |
56 if (self) { | 56 if (self) { |
57 _clipboardRecentContent = [[ClipboardRecentContentImplIOS alloc] | 57 _clipboardRecentContent = [[ClipboardRecentContentImplIOS alloc] |
58 initWithMaxAge:1 * 60 * 60 | 58 initWithMaxAge:1 * 60 * 60 |
59 authorizedSchemes:[NSSet setWithObjects:@"http", @"https", nil] | 59 authorizedSchemes:[NSSet setWithObjects:@"http", @"https", nil] |
60 userDefaults:app_group::GetGroupUserDefaults() | 60 userDefaults:app_group::GetGroupUserDefaults() |
61 delegate:nil]; | 61 delegate:nil]; |
62 } | 62 } |
63 return self; | 63 return self; |
64 } | 64 } |
65 | 65 |
66 #pragma mark - UIViewController | 66 #pragma mark - UIViewController |
67 | 67 |
68 - (void)viewDidLoad { | 68 - (void)viewDidLoad { |
69 [super viewDidLoad]; | 69 [super viewDidLoad]; |
70 | 70 |
71 // A local variable is necessary here as the property is declared weak and the | 71 // A local variable is necessary here as the property is declared weak and the |
72 // object would be deallocated before being retained by the addSubview call. | 72 // object would be deallocated before being retained by the addSubview call. |
73 WidgetView* widgetView = [[WidgetView alloc] initWithActionTarget:self]; | 73 SearchWidgetView* widgetView = |
| 74 [[SearchWidgetView alloc] initWithActionTarget:self]; |
74 self.widgetView = widgetView; | 75 self.widgetView = widgetView; |
75 [self.view addSubview:self.widgetView]; | 76 [self.view addSubview:self.widgetView]; |
76 | 77 |
77 if (base::ios::IsRunningOnIOS10OrLater()) { | 78 if (base::ios::IsRunningOnIOS10OrLater()) { |
78 self.extensionContext.widgetLargestAvailableDisplayMode = | 79 self.extensionContext.widgetLargestAvailableDisplayMode = |
79 NCWidgetDisplayModeExpanded; | 80 NCWidgetDisplayModeExpanded; |
80 } | 81 } |
81 | 82 |
82 self.widgetView.translatesAutoresizingMaskIntoConstraints = NO; | 83 self.widgetView.translatesAutoresizingMaskIntoConstraints = NO; |
83 | 84 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 166 |
166 - (void)openAppWithCommand:(NSString*)command { | 167 - (void)openAppWithCommand:(NSString*)command { |
167 return [self openAppWithCommand:command parameter:nil]; | 168 return [self openAppWithCommand:command parameter:nil]; |
168 } | 169 } |
169 | 170 |
170 - (void)openAppWithCommand:(NSString*)command parameter:(NSString*)parameter { | 171 - (void)openAppWithCommand:(NSString*)command parameter:(NSString*)parameter { |
171 NSUserDefaults* sharedDefaults = | 172 NSUserDefaults* sharedDefaults = |
172 [[NSUserDefaults alloc] initWithSuiteName:app_group::ApplicationGroup()]; | 173 [[NSUserDefaults alloc] initWithSuiteName:app_group::ApplicationGroup()]; |
173 NSString* defaultsKey = | 174 NSString* defaultsKey = |
174 base::SysUTF8ToNSString(app_group::kChromeAppGroupCommandPreference); | 175 base::SysUTF8ToNSString(app_group::kChromeAppGroupCommandPreference); |
175 [sharedDefaults setObject:[WidgetViewController dictForCommand:command | 176 [sharedDefaults |
176 parameter:parameter] | 177 setObject:[SearchWidgetViewController dictForCommand:command |
177 forKey:defaultsKey]; | 178 parameter:parameter] |
| 179 forKey:defaultsKey]; |
178 [sharedDefaults synchronize]; | 180 [sharedDefaults synchronize]; |
179 | 181 |
180 NSString* scheme = base::mac::ObjCCast<NSString>([[NSBundle mainBundle] | 182 NSString* scheme = base::mac::ObjCCast<NSString>([[NSBundle mainBundle] |
181 objectForInfoDictionaryKey:@"KSChannelChromeScheme"]); | 183 objectForInfoDictionaryKey:@"KSChannelChromeScheme"]); |
182 if (!scheme) | 184 if (!scheme) |
183 return; | 185 return; |
184 | 186 |
185 NSURLComponents* urlComponents = [NSURLComponents new]; | 187 NSURLComponents* urlComponents = [NSURLComponents new]; |
186 urlComponents.scheme = scheme; | 188 urlComponents.scheme = scheme; |
187 urlComponents.host = kXCallbackURLHost; | 189 urlComponents.host = kXCallbackURLHost; |
(...skipping 25 matching lines...) Expand all Loading... |
213 }; | 215 }; |
214 } | 216 } |
215 return @{ | 217 return @{ |
216 timePrefKey : [NSDate date], | 218 timePrefKey : [NSDate date], |
217 appPrefKey : @"TodayExtension", | 219 appPrefKey : @"TodayExtension", |
218 commandPrefKey : command, | 220 commandPrefKey : command, |
219 }; | 221 }; |
220 } | 222 } |
221 | 223 |
222 @end | 224 @end |
OLD | NEW |