Commit 6ab8f6f2 authored by Robbie Gibson's avatar Robbie Gibson Committed by Commit Bot

[iOS] Migrate popup menu to use new async clipboard APIs

Accessing the clipboard should now use the new async APIs so all
clipboard accesses go through the same path.

Bug: 1110849
Change-Id: I36fbad6807a75bc72c50aba1fdcd9b8ce94b1ae4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346434Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Cr-Commit-Position: refs/heads/master@{#796785}
parent c37f70db
......@@ -162,21 +162,6 @@ const char kManagementPageURL[] = "chrome://management";
// No metrics for this item.
[self.commandHandler navigateToPageForItem:item];
break;
case PopupMenuActionPasteAndGo: {
RecordAction(UserMetricsAction("MobileMenuPasteAndGo"));
NSString* query;
ClipboardRecentContent* clipboardRecentContent =
ClipboardRecentContent::GetInstance();
if (base::Optional<GURL> optional_url =
clipboardRecentContent->GetRecentURLFromClipboard()) {
query = base::SysUTF8ToNSString(optional_url.value().spec());
} else if (base::Optional<base::string16> optional_text =
clipboardRecentContent->GetRecentTextFromClipboard()) {
query = base::SysUTF16ToNSString(optional_text.value());
}
[self.dispatcher loadQuery:query immediately:YES];
break;
}
case PopupMenuActionVoiceSearch:
RecordAction(UserMetricsAction("MobileMenuVoiceSearch"));
[self.dispatcher startVoiceSearch];
......@@ -209,6 +194,36 @@ const char kManagementPageURL[] = "chrome://management";
}));
break;
}
case PopupMenuActionSearchCopiedText: {
RecordAction(UserMetricsAction("MobileMenuPasteAndGo"));
ClipboardRecentContent* clipboardRecentContent =
ClipboardRecentContent::GetInstance();
clipboardRecentContent->GetRecentTextFromClipboard(
base::BindOnce(^(base::Optional<base::string16> optional_text) {
if (!optional_text) {
return;
}
[self.dispatcher
loadQuery:base::SysUTF16ToNSString(optional_text.value())
immediately:YES];
}));
break;
}
case PopupMenuActionVisitCopiedLink: {
RecordAction(UserMetricsAction("MobileMenuPasteAndGo"));
ClipboardRecentContent* clipboardRecentContent =
ClipboardRecentContent::GetInstance();
clipboardRecentContent->GetRecentURLFromClipboard(
base::BindOnce(^(base::Optional<GURL> optional_url) {
if (!optional_url) {
return;
}
[self.dispatcher
loadQuery:base::SysUTF8ToNSString(optional_url.value().spec())
immediately:YES];
}));
break;
}
case PopupMenuActionEnterpriseInfoMessage:
[self.dispatcher
openURLInNewTab:[OpenNewTabCommand commandWithURLFromChrome:
......
......@@ -799,13 +799,15 @@ PopupMenuTextItem* CreateEnterpriseInfoItem(NSString* imageName,
} else if (matched_types.find(ClipboardContentType::URL) !=
matched_types.end()) {
copiedContentItem = CreateTableViewItem(
IDS_IOS_TOOLS_MENU_VISIT_COPIED_LINK, PopupMenuActionPasteAndGo,
@"popup_menu_paste_and_go", kToolsMenuPasteAndGo);
IDS_IOS_TOOLS_MENU_VISIT_COPIED_LINK,
PopupMenuActionVisitCopiedLink, @"popup_menu_paste_and_go",
kToolsMenuPasteAndGo);
} else if (matched_types.find(ClipboardContentType::Text) !=
matched_types.end()) {
copiedContentItem = CreateTableViewItem(
IDS_IOS_TOOLS_MENU_SEARCH_COPIED_TEXT, PopupMenuActionPasteAndGo,
@"popup_menu_paste_and_go", kToolsMenuPasteAndGo);
IDS_IOS_TOOLS_MENU_SEARCH_COPIED_TEXT,
PopupMenuActionSearchCopiedText, @"popup_menu_paste_and_go",
kToolsMenuPasteAndGo);
}
if (copiedContentItem) {
[items addObject:@[ copiedContentItem ]];
......
......@@ -35,12 +35,13 @@ typedef NS_ENUM(NSInteger, PopupMenuAction) {
PopupMenuActionSettings,
PopupMenuActionCloseTab,
PopupMenuActionNavigate,
PopupMenuActionPasteAndGo,
PopupMenuActionVoiceSearch,
PopupMenuActionSearch,
PopupMenuActionIncognitoSearch,
PopupMenuActionQRCodeSearch,
PopupMenuActionSearchCopiedImage,
PopupMenuActionSearchCopiedText,
PopupMenuActionVisitCopiedLink,
// Language selection popup menu
PopupMenuActionSelectLanguage,
// Translate option selection popup menu
......
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