Chromium Code Reviews| Index: ios/chrome/browser/content_suggestions/content_suggestions_coordinator.mm |
| diff --git a/ios/chrome/browser/content_suggestions/content_suggestions_coordinator.mm b/ios/chrome/browser/content_suggestions/content_suggestions_coordinator.mm |
| index 21272d819e4c7a0cbe7c86826151000666af5cc3..17b6554b5df2f01a08aaec6cf42e91fd8ff95c49 100644 |
| --- a/ios/chrome/browser/content_suggestions/content_suggestions_coordinator.mm |
| +++ b/ios/chrome/browser/content_suggestions/content_suggestions_coordinator.mm |
| @@ -5,29 +5,55 @@ |
| #import "ios/chrome/browser/content_suggestions/content_suggestions_coordinator.h" |
| #include "base/mac/scoped_nsobject.h" |
| +#include "base/strings/sys_string_conversions.h" |
| #import "ios/chrome/browser/content_suggestions/content_suggestions_mediator.h" |
| #include "ios/chrome/browser/ntp_snippets/ios_chrome_content_suggestions_service_factory.h" |
| +#import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h" |
| +#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_article_item.h" |
| #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands.h" |
| #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.h" |
| +#import "ios/chrome/browser/ui/url_loader.h" |
| #include "ios/chrome/grit/ios_strings.h" |
| +#include "ios/web/public/referrer.h" |
| #include "ui/base/l10n/l10n_util.h" |
| +#include "ui/strings/grit/ui_strings.h" |
| #if !defined(__has_feature) || !__has_feature(objc_arc) |
| #error "This file requires ARC support." |
| #endif |
| @interface ContentSuggestionsCoordinator ()<ContentSuggestionsCommands> { |
| - UINavigationController* _navigationController; |
| ContentSuggestionsMediator* _contentSuggestionsMediator; |
| } |
| +@property(nonatomic, strong) AlertCoordinator* alertCoordinator; |
| +@property(nonatomic, strong) UINavigationController* navigationController; |
| +@property(nonatomic, strong) |
| + ContentSuggestionsViewController* suggestionsViewController; |
| +@property(nonatomic, weak, readonly) id<UrlLoader> UrlLoader; |
|
lpromero
2017/02/14 16:18:17
This should be URLLoader. Consider renaming the pr
gambard
2017/02/15 10:37:56
It is widely used. I think renaming all url/URL/Ur
|
| + |
| +- (void)openNewTabWithURL:(const GURL&)URL incognito:(BOOL)incognito; |
| + |
| @end |
| @implementation ContentSuggestionsCoordinator |
| +@synthesize alertCoordinator = _alertCoordinator; |
| @synthesize browserState = _browserState; |
| +@synthesize navigationController = _navigationController; |
| +@synthesize suggestionsViewController = _suggestionsViewController; |
| +@synthesize UrlLoader = _UrlLoader; |
| @synthesize visible = _visible; |
| +- (instancetype)initWithBaseViewController:(UIViewController*)viewController |
| + loader:(id<UrlLoader>)loader { |
| + self = [super initWithBaseViewController:viewController]; |
| + if (self) { |
| + _UrlLoader = loader; |
| + } |
| + return self; |
| +} |
| + |
| - (void)start { |
| if (self.visible || !self.browserState) { |
| // Prevent this coordinator from being started twice in a row or without a |
| @@ -41,16 +67,15 @@ |
| initWithContentService:IOSChromeContentSuggestionsServiceFactory:: |
| GetForBrowserState(self.browserState)]; |
| - ContentSuggestionsViewController* suggestionsViewController = |
| - [[ContentSuggestionsViewController alloc] |
| - initWithStyle:CollectionViewControllerStyleDefault |
| - dataSource:_contentSuggestionsMediator]; |
| + _suggestionsViewController = [[ContentSuggestionsViewController alloc] |
| + initWithStyle:CollectionViewControllerStyleDefault |
| + dataSource:_contentSuggestionsMediator]; |
| - suggestionsViewController.suggestionCommandHandler = self; |
| + _suggestionsViewController.suggestionCommandHandler = self; |
| _navigationController = [[UINavigationController alloc] |
| - initWithRootViewController:suggestionsViewController]; |
| + initWithRootViewController:_suggestionsViewController]; |
| - suggestionsViewController.navigationItem.leftBarButtonItem = |
| + _suggestionsViewController.navigationItem.leftBarButtonItem = |
| [[UIBarButtonItem alloc] |
| initWithTitle:l10n_util::GetNSString(IDS_IOS_SUGGESTIONS_DONE) |
| style:UIBarButtonItemStylePlain |
| @@ -63,10 +88,10 @@ |
| } |
| - (void)stop { |
| - [[_navigationController presentingViewController] |
| + [[self.navigationController presentingViewController] |
| dismissViewControllerAnimated:YES |
| completion:nil]; |
| - _navigationController = nil; |
| + self.navigationController = nil; |
| _visible = NO; |
| } |
| @@ -85,6 +110,85 @@ |
| } |
| - (void)openURL:(const GURL&)url { |
| + // TODO(crbug.com/691979): Add metrics. |
| + |
| + [self.UrlLoader loadURL:url |
| + referrer:web::Referrer() |
| + transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK |
| + rendererInitiated:NO]; |
| + |
| + [self stop]; |
| +} |
| + |
| +- (void)displayContextMenuForArticle:(ContentSuggestionsArticleItem*)articleItem |
| + atPoint:(CGPoint)touchLocation { |
| + NSString* urlString = base::SysUTF8ToNSString(articleItem.articleURL.spec()); |
| + self.alertCoordinator = [[ActionSheetCoordinator alloc] |
| + initWithBaseViewController:self.navigationController |
| + title:articleItem.title |
| + message:urlString |
| + rect:CGRectMake(touchLocation.x, touchLocation.y, 0, |
| + 0) |
| + view:self.suggestionsViewController.collectionView]; |
| + |
| + __weak ContentSuggestionsCoordinator* weakSelf = self; |
| + GURL articleURL = articleItem.articleURL; |
| + |
| + NSString* openInNewTabTitle = |
| + l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB); |
| + [self.alertCoordinator |
| + addItemWithTitle:openInNewTabTitle |
| + action:^{ |
| + // TODO(crbug.com/691979): Add metrics. |
| + [weakSelf openNewTabWithURL:articleURL incognito:NO]; |
| + } |
| + style:UIAlertActionStyleDefault]; |
| + |
| + NSString* openInNewTabIncognitoTitle = |
| + l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB); |
| + [self.alertCoordinator |
| + addItemWithTitle:openInNewTabIncognitoTitle |
| + action:^{ |
| + // TODO(crbug.com/691979): Add metrics. |
| + [weakSelf openNewTabWithURL:articleURL incognito:YES]; |
| + } |
| + style:UIAlertActionStyleDefault]; |
| + |
| + NSString* copyLinkTitle = |
| + l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_DELETE); |
| + [self.alertCoordinator addItemWithTitle:copyLinkTitle |
| + action:^{ |
| + // TODO(crbug.com/691979): Add metrics. |
| + [weakSelf removeEntry]; |
| + } |
| + style:UIAlertActionStyleDefault]; |
| + |
| + [self.alertCoordinator addItemWithTitle:l10n_util::GetNSString(IDS_APP_CANCEL) |
| + action:^{ |
| + // TODO(crbug.com/691979): Add metrics. |
| + } |
| + style:UIAlertActionStyleCancel]; |
| + |
| + [self.alertCoordinator start]; |
| +} |
| + |
| +#pragma mark - Private |
| + |
| +- (void)openNewTabWithURL:(const GURL&)URL incognito:(BOOL)incognito { |
| + // TODO(crbug.com/691979): Add metrics. |
| + |
| + [self.UrlLoader webPageOrderedOpen:URL |
| + referrer:web::Referrer() |
| + windowName:nil |
| + inIncognito:incognito |
| + inBackground:NO |
| + appendTo:kLastTab]; |
| + |
| + [self stop]; |
| +} |
| + |
| +- (void)removeEntry { |
| + // TODO(crbug.com/691979): Add metrics. |
| } |
| @end |