Commit 2837464c authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Change ButtonPressed overrides to callbacks: .../qrcode_generator/

Bug: 772945
Change-Id: Ie22085a74d30b42b135365f72f1e6fe6dd02a926
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2469228
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Kyle Milka <kmilka@chromium.org>
Reviewed-by: default avatarKyle Milka <kmilka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817058}
parent 72a89f7d
...@@ -346,11 +346,12 @@ void QRCodeGeneratorBubble::Init() { ...@@ -346,11 +346,12 @@ void QRCodeGeneratorBubble::Init() {
tooltip_icon_ = layout->AddView(std::move(tooltip_icon)); tooltip_icon_ = layout->AddView(std::move(tooltip_icon));
// Download button. // Download button.
auto download_button = std::make_unique<views::MdTextButton>( download_button_ = layout->AddView(std::make_unique<views::MdTextButton>(
this, l10n_util::GetStringUTF16( base::BindRepeating(&QRCodeGeneratorBubble::DownloadButtonPressed,
IDS_BROWSER_SHARING_QR_CODE_DIALOG_DOWNLOAD_BUTTON_LABEL)); base::Unretained(this)),
download_button->SetHorizontalAlignment(gfx::ALIGN_RIGHT); l10n_util::GetStringUTF16(
download_button_ = layout->AddView(std::move(download_button)); IDS_BROWSER_SHARING_QR_CODE_DIALOG_DOWNLOAD_BUTTON_LABEL)));
download_button_->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
// End controls row // End controls row
// Initialize Service // Initialize Service
...@@ -394,53 +395,49 @@ const base::string16 QRCodeGeneratorBubble::GetQRCodeFilenameForURL( ...@@ -394,53 +395,49 @@ const base::string16 QRCodeGeneratorBubble::GetQRCodeFilenameForURL(
return base::ASCIIToUTF16(base::StrCat({"qrcode_", url.host(), ".png"})); return base::ASCIIToUTF16(base::StrCat({"qrcode_", url.host(), ".png"}));
} }
void QRCodeGeneratorBubble::ButtonPressed(views::Button* sender, void QRCodeGeneratorBubble::DownloadButtonPressed() {
const ui::Event& event) { const gfx::ImageSkia& image_ref = qr_code_image_->GetImage();
DCHECK_EQ(sender, download_button_); // Returns closest scaling to parameter (1.0).
if (sender == download_button_) { // Should be exact since we generated the bitmap.
const gfx::ImageSkia& image_ref = qr_code_image_->GetImage(); const gfx::ImageSkiaRep& image_rep = image_ref.GetRepresentation(1.0f);
// Returns closest scaling to parameter (1.0). const SkBitmap& bitmap = image_rep.GetBitmap();
// Should be exact since we generated the bitmap. const GURL data_url = GURL(webui::GetBitmapDataUrl(bitmap));
const gfx::ImageSkiaRep& image_rep = image_ref.GetRepresentation(1.0f);
const SkBitmap& bitmap = image_rep.GetBitmap(); Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
const GURL data_url = GURL(webui::GetBitmapDataUrl(bitmap)); content::DownloadManager* download_manager =
content::BrowserContext::GetDownloadManager(browser->profile());
Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); net::NetworkTrafficAnnotationTag traffic_annotation =
content::DownloadManager* download_manager = net::DefineNetworkTrafficAnnotation("qr_code_save", R"(
content::BrowserContext::GetDownloadManager(browser->profile()); semantics {
net::NetworkTrafficAnnotationTag traffic_annotation = sender: "QR Code Generator"
net::DefineNetworkTrafficAnnotation("qr_code_save", R"( description:
semantics { "The user may generate a QR code linking to the current page or "
sender: "QR Code Generator" "image. This bubble view has a download button to save the generated "
description: "image to disk. "
"The user may generate a QR code linking to the current page or " "The image is generated via a Mojo service, but locally, so this "
"image. This bubble view has a download button to save the " "request never contacts the network. "
"generated image to disk. " trigger: "User clicks 'download' in a bubble view launched from the "
"The image is generated via a Mojo service, but locally, so " "omnibox, right-click menu, or share dialog."
"this request never contacts the network. " data: "QR Code image based on the current page's URL."
trigger: "User clicks 'download' in a bubble view launched from the " destination: LOCAL
"omnibox, right-click menu, or share dialog." }
data: "QR Code image based on the current page's URL." policy {
destination: LOCAL cookies_allowed: NO
} setting:
policy { "No user-visible setting for this feature. Experiment and rollout to "
cookies_allowed: NO "be coordinated via Finch. Access point to be combined with other "
setting: "sharing features later in 2020."
"No user-visible setting for this feature. Experiment and rollout " policy_exception_justification:
"to be coordinated via Finch. Access point to be combined with " "Not implemented, considered not required."
"other sharing features later in 2020." })");
policy_exception_justification: std::unique_ptr<download::DownloadUrlParameters> params =
"Not implemented, considered not required." content::DownloadRequestUtils::CreateDownloadForWebContentsMainFrame(
})"); web_contents_, data_url, traffic_annotation);
std::unique_ptr<download::DownloadUrlParameters> params( // Suggest a name incorporating the hostname. Protocol, TLD, etc are
content::DownloadRequestUtils::CreateDownloadForWebContentsMainFrame( // not taken into consideration. Duplicate names get automatic suffixes.
web_contents_, data_url, traffic_annotation)); params->set_suggested_name(GetQRCodeFilenameForURL(url_));
// Suggest a name incorporating the hostname. Protocol, TLD, etc are download_manager->DownloadUrl(std::move(params));
// not taken into consideration. Duplicate names get automatic suffixes. base::RecordAction(base::UserMetricsAction("SharingQRCode.DownloadQRCode"));
params->set_suggested_name(GetQRCodeFilenameForURL(url_));
download_manager->DownloadUrl(std::move(params));
base::RecordAction(base::UserMetricsAction("SharingQRCode.DownloadQRCode"));
}
} }
} // namespace qrcode_generator } // namespace qrcode_generator
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "chrome/browser/ui/qrcode_generator/qrcode_generator_bubble_view.h" #include "chrome/browser/ui/qrcode_generator/qrcode_generator_bubble_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_bubble_delegate_view.h" #include "chrome/browser/ui/views/location_bar/location_bar_bubble_delegate_view.h"
#include "chrome/services/qrcode_generator/public/cpp/qrcode_generator_service.h" #include "chrome/services/qrcode_generator/public/cpp/qrcode_generator_service.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/controls/textfield/textfield_controller.h" #include "ui/views/controls/textfield/textfield_controller.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -39,8 +38,7 @@ class QRCodeGeneratorBubbleController; ...@@ -39,8 +38,7 @@ class QRCodeGeneratorBubbleController;
// Dialog that displays a QR code used to share a page or image. // Dialog that displays a QR code used to share a page or image.
class QRCodeGeneratorBubble : public QRCodeGeneratorBubbleView, class QRCodeGeneratorBubble : public QRCodeGeneratorBubbleView,
public LocationBarBubbleDelegateView, public LocationBarBubbleDelegateView,
public views::TextfieldController, public views::TextfieldController {
public views::ButtonListener {
public: public:
QRCodeGeneratorBubble(views::View* anchor_view, QRCodeGeneratorBubble(views::View* anchor_view,
content::WebContents* web_contents, content::WebContents* web_contents,
...@@ -90,8 +88,7 @@ class QRCodeGeneratorBubble : public QRCodeGeneratorBubbleView, ...@@ -90,8 +88,7 @@ class QRCodeGeneratorBubble : public QRCodeGeneratorBubbleView,
bool HandleMouseEvent(views::Textfield* sender, bool HandleMouseEvent(views::Textfield* sender,
const ui::MouseEvent& mouse_event) override; const ui::MouseEvent& mouse_event) override;
// ButtonListener: void DownloadButtonPressed();
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Callback for the request to the OOP service to generate a new image. // Callback for the request to the OOP service to generate a new image.
void OnCodeGeneratorResponse(const mojom::GenerateQRCodeResponsePtr response); void OnCodeGeneratorResponse(const mojom::GenerateQRCodeResponsePtr response);
......
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