Commit d6bd6d7c authored by Sebastien Lalancette's avatar Sebastien Lalancette Committed by Commit Bot

[iOS] Adding Share action to Recent Tabs Entry Context Menu

Bug: 1093302
Change-Id: I8103a36420b9f99b3d8428e56f57fd244eb9f33e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2351953
Commit-Queue: Sebastien Lalancette <seblalancette@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797241}
parent af7117b8
......@@ -15,8 +15,9 @@ enum class ActivityScenario {
ReadingListEntry = 3,
BookmarkEntry = 4,
MostVisitedEntry = 5,
RecentTabsEntry = 6,
// Highest enumerator. Recommended by Histogram metrics best practices.
kMaxValue = MostVisitedEntry
kMaxValue = RecentTabsEntry
};
#endif // IOS_CHROME_BROWSER_UI_ACTIVITY_SERVICES_ACTIVITY_SCENARIO_H_
......@@ -28,6 +28,8 @@ const char kShareBookmarkEntryActionsHistogram[] =
"Mobile.Share.BookmarkEntry.Actions";
const char kShareMostVisitedEntryActionsHistogram[] =
"Mobile.Share.MostVisitedEntry.Actions";
const char kShareRecentTabsEntryActionsHistogram[] =
"Mobile.Share.RecentTabsEntry.Actions";
// Enum representing an aggregation of the |ActivityType| enum values in a way
// that is relevant for metric collection. Current values should not
......@@ -148,6 +150,9 @@ void RecordActionForScenario(ShareActionType actionType,
case ActivityScenario::MostVisitedEntry:
histogramName = kShareMostVisitedEntryActionsHistogram;
break;
case ActivityScenario::RecentTabsEntry:
histogramName = kShareRecentTabsEntryActionsHistogram;
break;
}
base::UmaHistogramEnumeration(histogramName, actionType);
}
......
......@@ -176,7 +176,7 @@
UIAction* action =
[self actionWithTitle:l10n_util::GetNSString(
IDS_IOS_RECENT_TABS_HIDE_MENU_OPTION)
image:nil
image:[UIImage imageNamed:@"remove"]
type:MenuActionType::Hide
block:block];
action.attributes = UIMenuElementAttributesDestructive;
......
......@@ -284,6 +284,7 @@ TEST_F(ActionFactoryTest, hideAction) {
[[ActionFactory alloc] initWithBrowser:test_browser_.get()
scenario:kTestMenuScenario];
UIImage* expectedImage = [UIImage imageNamed:@"remove"];
NSString* expectedTitle =
l10n_util::GetNSString(IDS_IOS_RECENT_TABS_HIDE_MENU_OPTION);
......@@ -291,7 +292,7 @@ TEST_F(ActionFactoryTest, hideAction) {
}];
EXPECT_TRUE([expectedTitle isEqualToString:action.title]);
EXPECT_EQ(nil, action.image);
EXPECT_EQ(expectedImage, action.image);
}
}
......
......@@ -28,10 +28,12 @@ source_set("recent_tabs") {
"//ios/chrome/browser/sessions",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/sync",
"//ios/chrome/browser/ui/activity_services",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/menu",
"//ios/chrome/browser/ui/ntp",
"//ios/chrome/browser/ui/sharing",
"//ios/chrome/browser/ui/table_view",
"//ios/chrome/browser/ui/table_view:feature_flags",
"//ios/chrome/browser/ui/util",
......
......@@ -11,6 +11,7 @@
#include "base/metrics/user_metrics_action.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/ui/activity_services/activity_params.h"
#include "ios/chrome/browser/ui/commands/application_commands.h"
#include "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/menu/action_factory.h"
......@@ -21,6 +22,7 @@
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_table_view_controller.h"
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_transitioning_delegate.h"
#include "ios/chrome/browser/ui/recent_tabs/synced_sessions.h"
#import "ios/chrome/browser/ui/sharing/sharing_coordinator.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_url_item.h"
#import "ios/chrome/browser/ui/table_view/feature_flags.h"
#import "ios/chrome/browser/ui/table_view/table_view_navigation_controller.h"
......@@ -50,6 +52,8 @@
@property(nonatomic, strong)
RecentTabsTableViewController* recentTabsTableViewController;
@property(nonatomic, strong) SharingCoordinator* sharingCoordinator;
@end
@implementation RecentTabsCoordinator
......@@ -160,6 +164,23 @@
[self openAllTabsFromSession:session];
}
// Triggers the URL sharing flow for the given |URL| and |title|, with the
// origin |view| representing the UI component for that URL.
- (void)shareURL:(const GURL&)URL
title:(NSString*)title
fromView:(UIView*)view {
ActivityParams* params =
[[ActivityParams alloc] initWithURL:URL
title:title
scenario:ActivityScenario::RecentTabsEntry];
self.sharingCoordinator = [[SharingCoordinator alloc]
initWithBaseViewController:self.recentTabsTableViewController
browser:self.browser
params:params
originView:view];
[self.sharingCoordinator start];
}
#pragma mark - RecentTabsPresentationDelegate
- (void)openAllTabsFromSession:(const synced_sessions::DistantSession*)session {
......@@ -208,7 +229,9 @@
#pragma mark - RecentTabsMenuProvider
- (UIContextMenuConfiguration*)contextMenuConfigurationForItem:
(TableViewURLItem*)item API_AVAILABLE(ios(13.0)) {
(TableViewURLItem*)item
fromView:(UIView*)view
API_AVAILABLE(ios(13.0)) {
__weak __typeof(self) weakSelf = self;
UIContextMenuActionProvider actionProvider = ^(
......@@ -254,6 +277,12 @@
[menuElements addObject:[actionFactory actionToCopyURL:item.URL]];
[menuElements addObject:[actionFactory actionToShareWithBlock:^{
[strongSelf shareURL:item.URL
title:item.title
fromView:view];
}]];
return [UIMenu menuWithTitle:@"" children:menuElements];
};
......
......@@ -5,14 +5,19 @@
#ifndef IOS_CHROME_BROWSER_UI_RECENT_TABS_RECENT_TABS_MENU_PROVIDER_H_
#define IOS_CHROME_BROWSER_UI_RECENT_TABS_RECENT_TABS_MENU_PROVIDER_H_
#import <UIKit/UIKit.h>
@class TableViewURLItem;
// Protocol for instances that will provide menus to RecentTabs components.
@protocol RecentTabsMenuProvider
// Creates a context menu configuration instance for the given |item|.
// Creates a context menu configuration instance for the given |item| and its
// associated |view|.
- (UIContextMenuConfiguration*)contextMenuConfigurationForItem:
(TableViewURLItem*)item API_AVAILABLE(ios(13.0));
(TableViewURLItem*)item
fromView:(UIView*)view
API_AVAILABLE(ios(13.0));
// Creates a context menu configuration instance for the header of the given
// |sectionIdentifier|.
......
......@@ -929,7 +929,10 @@ const int kRecentlyClosedTabsSectionIndex = 0;
TableViewItem* item = [self.tableViewModel itemAtIndexPath:indexPath];
TableViewURLItem* URLItem = base::mac::ObjCCastStrict<TableViewURLItem>(item);
return [self.menuProvider contextMenuConfigurationForItem:URLItem];
return [self.menuProvider
contextMenuConfigurationForItem:URLItem
fromView:[tableView
cellForRowAtIndexPath:indexPath]];
}
#pragma mark - UIContextMenuInteractionDelegate
......
......@@ -37179,6 +37179,9 @@ Called by update_gpu_driver_bug_workaround_entries.py.-->
<int value="1" label="QR Code Image"/>
<int value="2" label="History Entry"/>
<int value="3" label="Reading List Entry"/>
<int value="4" label="Bookmarks Entry"/>
<int value="5" label="Most Visited Tile"/>
<int value="6" label="Recent Tabs Entry"/>
</enum>
<enum name="IOSContentSizeCategory">
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment