// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.h"
#import "base/check.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/most_visited_tiles_commands.h"
#import "ios/chrome/common/ui/favicon/favicon_attributes.h"
#import "ios/chrome/common/ui/favicon/favicon_view.h"
#import "ios/chrome/grit/ios_strings.h"
#import "ui/base/l10n/l10n_util.h"
#import "url/gurl.h"
@implementation ContentSuggestionsMostVisitedItem
#pragma mark - AccessibilityCustomAction
// Custom action for a cell configured with this item.
- (NSArray<UIAccessibilityCustomAction*>*)customActions {
UIAccessibilityCustomAction* openInNewTab =
[[UIAccessibilityCustomAction alloc]
initWithName:l10n_util::GetNSString(
IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB)
target:self
selector:@selector(openInNewTab)];
UIAccessibilityCustomAction* openInNewIncognitoTab =
[[UIAccessibilityCustomAction alloc]
initWithName:l10n_util::GetNSString(
IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB)
target:self
selector:@selector(openInNewIncognitoTab)];
UIAccessibilityCustomAction* removeMostVisited = [
[UIAccessibilityCustomAction alloc]
initWithName:l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_REMOVE)
target:self
selector:@selector(removeMostVisited)];
if (self.incognitoAvailable) {
return [NSArray arrayWithObjects:openInNewTab, openInNewIncognitoTab,
removeMostVisited, nil];
} else {
return [NSArray arrayWithObjects:openInNewTab, removeMostVisited, nil];
}
}
// Target for custom action.
- (BOOL)openInNewTab {
DCHECK(self.commandHandler);
[self.commandHandler openNewTabWithMostVisitedItem:self incognito:NO];
return YES;
}
// Target for custom action.
- (BOOL)openInNewIncognitoTab {
DCHECK(self.commandHandler);
[self.commandHandler openNewTabWithMostVisitedItem:self incognito:YES];
return YES;
}
// Target for custom action.
- (BOOL)removeMostVisited {
DCHECK(self.commandHandler);
[self.commandHandler removeMostVisited:self];
return YES;
}
@end