| 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..e7ac5c60e2489cd53b3c5364080f4d729cd2da5d 100644
|
| --- a/ios/chrome/browser/content_suggestions/content_suggestions_coordinator.mm
|
| +++ b/ios/chrome/browser/content_suggestions/content_suggestions_coordinator.mm
|
| @@ -5,27 +5,43 @@
|
| #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;
|
| +
|
| +- (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;
|
|
|
| - (void)start {
|
| @@ -41,16 +57,15 @@
|
| initWithContentService:IOSChromeContentSuggestionsServiceFactory::
|
| GetForBrowserState(self.browserState)];
|
|
|
| - ContentSuggestionsViewController* suggestionsViewController =
|
| - [[ContentSuggestionsViewController alloc]
|
| - initWithStyle:CollectionViewControllerStyleDefault
|
| - dataSource:_contentSuggestionsMediator];
|
| + self.suggestionsViewController = [[ContentSuggestionsViewController alloc]
|
| + initWithStyle:CollectionViewControllerStyleDefault
|
| + dataSource:_contentSuggestionsMediator];
|
|
|
| - suggestionsViewController.suggestionCommandHandler = self;
|
| + self.suggestionsViewController.suggestionCommandHandler = self;
|
| _navigationController = [[UINavigationController alloc]
|
| - initWithRootViewController:suggestionsViewController];
|
| + initWithRootViewController:self.suggestionsViewController];
|
|
|
| - suggestionsViewController.navigationItem.leftBarButtonItem =
|
| + self.suggestionsViewController.navigationItem.leftBarButtonItem =
|
| [[UIBarButtonItem alloc]
|
| initWithTitle:l10n_util::GetNSString(IDS_IOS_SUGGESTIONS_DONE)
|
| style:UIBarButtonItemStylePlain
|
| @@ -63,10 +78,10 @@
|
| }
|
|
|
| - (void)stop {
|
| - [[_navigationController presentingViewController]
|
| + [[self.navigationController presentingViewController]
|
| dismissViewControllerAnimated:YES
|
| completion:nil];
|
| - _navigationController = nil;
|
| + self.navigationController = nil;
|
| _visible = NO;
|
| }
|
|
|
| @@ -84,7 +99,86 @@
|
| - (void)openFaviconAtIndex:(NSInteger)index {
|
| }
|
|
|
| -- (void)openURL:(const GURL&)url {
|
| +- (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* deleteTitle =
|
| + l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_DELETE);
|
| + [self.alertCoordinator addItemWithTitle:deleteTitle
|
| + 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
|
|
|