Commit 2d3c75fd authored by Travis Skare's avatar Travis Skare Committed by Commit Bot

[QRCode Generator] Add image QR-share via context menu

Add user actions for page vs. image context menu.

Bug: 1106111
Change-Id: I95f99f9835b22336371a7c1f4da49c0faef28013
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2320419Reviewed-by: default avatarBrian White <bcwhite@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Travis Skare <skare@chromium.org>
Cr-Commit-Position: refs/heads/master@{#793636}
parent 588fb27f
......@@ -1216,6 +1216,10 @@ void RenderViewContextMenu::AppendLinkItems() {
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
// Place QR Generator close to send-tab-to-self feature for link images.
if (params_.has_image_contents)
AppendQRCodeGeneratorItem(/*for_image=*/true, /*draw_icon=*/true);
if (browser && send_tab_to_self::ShouldOfferFeatureForLink(
active_web_contents, params_.link_url)) {
if (send_tab_to_self::GetValidDeviceCount(GetBrowser()->profile()) == 1) {
......@@ -1353,6 +1357,10 @@ void RenderViewContextMenu::AppendImageItems() {
IDS_CONTENT_CONTEXT_COPYIMAGE);
menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGELOCATION,
IDS_CONTENT_CONTEXT_COPYIMAGELOCATION);
// Don't double-add for linked images, which also add the item.
if (params_.link_url.is_empty())
AppendQRCodeGeneratorItem(/*for_image=*/true, /*draw_icon=*/false);
}
void RenderViewContextMenu::AppendSearchWebForImageItems() {
......@@ -1497,15 +1505,7 @@ void RenderViewContextMenu::AppendPageItems() {
if (!send_tab_to_self_menu_present)
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
#if defined(OS_MAC)
menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_GENERATE_QR_CODE,
IDS_CONTEXT_MENU_GENERATE_QR_CODE_PAGE);
#else
menu_model_.AddItemWithStringIdAndIcon(
IDC_CONTENT_CONTEXT_GENERATE_QR_CODE,
IDS_CONTEXT_MENU_GENERATE_QR_CODE_PAGE,
ui::ImageModel::FromVectorIcon(kQrcodeGeneratorIcon));
#endif
AppendQRCodeGeneratorItem(/*for_image=*/false, /*draw_icon=*/true);
menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
} else if (send_tab_to_self_menu_present) {
......@@ -2265,9 +2265,17 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
GetBrowser()->tab_strip_model()->GetActiveWebContents();
auto* bubble_controller =
qrcode_generator::QRCodeGeneratorBubbleController::Get(web_contents);
NavigationEntry* entry =
embedder_web_contents_->GetController().GetLastCommittedEntry();
bubble_controller->ShowBubble(entry->GetURL());
if (params_.media_type == ContextMenuDataMediaType::kImage) {
base::RecordAction(
UserMetricsAction("SharingQRCode.DialogLaunched.ContextMenuImage"));
bubble_controller->ShowBubble(params_.src_url);
} else {
base::RecordAction(
UserMetricsAction("SharingQRCode.DialogLaunched.ContextMenuPage"));
NavigationEntry* entry =
embedder_web_contents_->GetController().GetLastCommittedEntry();
bubble_controller->ShowBubble(entry->GetURL());
}
break;
}
......@@ -2639,6 +2647,25 @@ bool RenderViewContextMenu::IsQRCodeGeneratorEnabled() const {
IsGeneratorAvailable(entry->GetURL(), incognito);
}
void RenderViewContextMenu::AppendQRCodeGeneratorItem(bool for_image,
bool draw_icon) {
if (!IsQRCodeGeneratorEnabled())
return;
auto string_id = for_image ? IDS_CONTEXT_MENU_GENERATE_QR_CODE_IMAGE
: IDS_CONTEXT_MENU_GENERATE_QR_CODE_PAGE;
#if defined(OS_MAC)
draw_icon = false;
#endif
if (draw_icon) {
menu_model_.AddItemWithStringIdAndIcon(
IDC_CONTENT_CONTEXT_GENERATE_QR_CODE, string_id,
ui::ImageModel::FromVectorIcon(kQrcodeGeneratorIcon));
} else {
menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_GENERATE_QR_CODE,
string_id);
}
}
bool RenderViewContextMenu::IsRouteMediaEnabled() const {
if (!media_router::MediaRouterEnabled(browser_context_))
return false;
......
......@@ -193,6 +193,7 @@ class RenderViewContextMenu : public RenderViewContextMenuBase {
void AppendSharingItems();
void AppendClickToCallItem();
void AppendSharedClipboardItem();
void AppendQRCodeGeneratorItem(bool for_image, bool draw_icon);
// Command enabled query functions.
bool IsReloadEnabled() const;
......
......@@ -20691,12 +20691,31 @@ should be able to be added at any place in this file.
</action>
<action name="SharingQRCode.DialogLaunched">
<owner>skare@chromium.org</owner>
<owner>src/components/send_tab_to_self/OWNERS</owner>
<description>
User launched the QR Generator dialog (desktop platforms).
</description>
</action>
<action name="SharingQRCode.DialogLaunched.ContextMenuImage">
<owner>skare@chromium.org</owner>
<owner>src/components/send_tab_to_self/OWNERS</owner>
<description>
User launched the QR Generator dialog for an image via the context menu on
desktop.
</description>
</action>
<action name="SharingQRCode.DialogLaunched.ContextMenuPage">
<owner>skare@chromium.org</owner>
<owner>src/components/send_tab_to_self/OWNERS</owner>
<description>
User launched the QR Generator dialog for a page via the context menu on
desktop.
</description>
</action>
<action name="SharingQRCode.DownloadQRCode">
<owner>tgupta@chromium.org</owner>
<owner>src/components/send_tab_to_self/OWNERS</owner>
......
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