Commit bf1e5ed8 authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

WebApp: dialogs receive and forward unique_ptr

WebApplicationInfo is passed to and from dialogs
using unique_ptr.

Bug: 915043
Change-Id: Ic1b3ef961c5d0cddff7fd32af5fee9ac8123f063
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1604393
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659387}
parent 1d8dce28
...@@ -204,13 +204,14 @@ class BookmarkAppInstaller : public base::RefCounted<BookmarkAppInstaller>, ...@@ -204,13 +204,14 @@ class BookmarkAppInstaller : public base::RefCounted<BookmarkAppInstaller>,
} // namespace } // namespace
BookmarkAppHelper::BookmarkAppHelper(Profile* profile, BookmarkAppHelper::BookmarkAppHelper(
WebApplicationInfo web_app_info, Profile* profile,
content::WebContents* contents, std::unique_ptr<WebApplicationInfo> web_app_info,
WebappInstallSource install_source) content::WebContents* contents,
WebappInstallSource install_source)
: profile_(profile), : profile_(profile),
contents_(contents), contents_(contents),
web_app_info_(web_app_info), web_app_info_(*web_app_info),
crx_installer_(CrxInstaller::CreateSilent( crx_installer_(CrxInstaller::CreateSilent(
ExtensionSystem::Get(profile)->extension_service())), ExtensionSystem::Get(profile)->extension_service())),
for_installable_site_(web_app::ForInstallableSite::kUnknown), for_installable_site_(web_app::ForInstallableSite::kUnknown),
...@@ -361,18 +362,18 @@ void BookmarkAppHelper::OnIconsDownloaded( ...@@ -361,18 +362,18 @@ void BookmarkAppHelper::OnIconsDownloaded(
web_app_info_.open_as_window = true; web_app_info_.open_as_window = true;
if (install_source_ == WebappInstallSource::OMNIBOX_INSTALL_ICON) { if (install_source_ == WebappInstallSource::OMNIBOX_INSTALL_ICON) {
chrome::ShowPWAInstallBubble( chrome::ShowPWAInstallBubble(
contents_, web_app_info_, contents_, std::make_unique<WebApplicationInfo>(web_app_info_),
base::BindOnce(&BookmarkAppHelper::OnBubbleCompleted, base::BindOnce(&BookmarkAppHelper::OnBubbleCompleted,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} else { } else {
chrome::ShowPWAInstallDialog( chrome::ShowPWAInstallDialog(
contents_, web_app_info_, contents_, std::make_unique<WebApplicationInfo>(web_app_info_),
base::BindOnce(&BookmarkAppHelper::OnBubbleCompleted, base::BindOnce(&BookmarkAppHelper::OnBubbleCompleted,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
} else { } else {
chrome::ShowBookmarkAppDialog( chrome::ShowBookmarkAppDialog(
contents_, web_app_info_, contents_, std::make_unique<WebApplicationInfo>(web_app_info_),
base::BindOnce(&BookmarkAppHelper::OnBubbleCompleted, base::BindOnce(&BookmarkAppHelper::OnBubbleCompleted,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
......
...@@ -57,7 +57,7 @@ class BookmarkAppHelper : public content::NotificationObserver { ...@@ -57,7 +57,7 @@ class BookmarkAppHelper : public content::NotificationObserver {
// will have a chance to cancel the operation. // will have a chance to cancel the operation.
// |install_source| indicates how the installation was triggered. // |install_source| indicates how the installation was triggered.
BookmarkAppHelper(Profile* profile, BookmarkAppHelper(Profile* profile,
WebApplicationInfo web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
content::WebContents* contents, content::WebContents* contents,
WebappInstallSource install_source); WebappInstallSource install_source);
~BookmarkAppHelper() override; ~BookmarkAppHelper() override;
......
...@@ -37,11 +37,14 @@ namespace { ...@@ -37,11 +37,14 @@ namespace {
class TestBookmarkAppHelper : public BookmarkAppHelper { class TestBookmarkAppHelper : public BookmarkAppHelper {
public: public:
TestBookmarkAppHelper(Profile* profile, TestBookmarkAppHelper(Profile* profile,
WebApplicationInfo web_app_info, const WebApplicationInfo& web_app_info,
content::WebContents* contents, content::WebContents* contents,
base::Closure on_icons_downloaded_closure, base::Closure on_icons_downloaded_closure,
WebappInstallSource install_source) WebappInstallSource install_source)
: BookmarkAppHelper(profile, web_app_info, contents, install_source), : BookmarkAppHelper(profile,
std::make_unique<WebApplicationInfo>(web_app_info),
contents,
install_source),
on_icons_downloaded_closure_(on_icons_downloaded_closure) {} on_icons_downloaded_closure_(on_icons_downloaded_closure) {}
// TestBookmarkAppHelper: // TestBookmarkAppHelper:
......
...@@ -121,10 +121,10 @@ WebApplicationInfo::IconInfo CreateIconInfoWithBitmap(int size, SkColor color) { ...@@ -121,10 +121,10 @@ WebApplicationInfo::IconInfo CreateIconInfoWithBitmap(int size, SkColor color) {
class TestBookmarkAppHelper : public BookmarkAppHelper { class TestBookmarkAppHelper : public BookmarkAppHelper {
public: public:
TestBookmarkAppHelper(ExtensionService* service, TestBookmarkAppHelper(ExtensionService* service,
WebApplicationInfo web_app_info, const WebApplicationInfo& web_app_info,
content::WebContents* contents) content::WebContents* contents)
: BookmarkAppHelper(service->profile(), : BookmarkAppHelper(service->profile(),
web_app_info, std::make_unique<WebApplicationInfo>(web_app_info),
contents, contents,
WebappInstallSource::MENU_BROWSER_TAB), WebappInstallSource::MENU_BROWSER_TAB),
bitmap_(CreateSquareBitmapWithColor(32, SK_ColorRED)) {} bitmap_(CreateSquareBitmapWithColor(32, SK_ColorRED)) {}
......
...@@ -267,8 +267,6 @@ void TabHelper::OnDidGetWebApplicationInfo( ...@@ -267,8 +267,6 @@ void TabHelper::OnDidGetWebApplicationInfo(
chrome::mojom::ChromeRenderFrameAssociatedPtr chrome_render_frame, chrome::mojom::ChromeRenderFrameAssociatedPtr chrome_render_frame,
bool shortcut_app_requested, bool shortcut_app_requested,
const WebApplicationInfo& info) { const WebApplicationInfo& info) {
web_app_info_ = info;
content::WebContents* contents = web_contents(); content::WebContents* contents = web_contents();
NavigationEntry* entry = contents->GetController().GetLastCommittedEntry(); NavigationEntry* entry = contents->GetController().GetLastCommittedEntry();
if (!entry || last_committed_nav_entry_unique_id_ != entry->GetUniqueID()) if (!entry || last_committed_nav_entry_unique_id_ != entry->GetUniqueID())
...@@ -277,16 +275,17 @@ void TabHelper::OnDidGetWebApplicationInfo( ...@@ -277,16 +275,17 @@ void TabHelper::OnDidGetWebApplicationInfo(
switch (pending_web_app_action_) { switch (pending_web_app_action_) {
case CREATE_HOSTED_APP: { case CREATE_HOSTED_APP: {
if (web_app_info_.app_url.is_empty()) auto web_app_info = std::make_unique<WebApplicationInfo>(info);
web_app_info_.app_url = contents->GetLastCommittedURL(); if (web_app_info->app_url.is_empty())
web_app_info->app_url = contents->GetLastCommittedURL();
if (web_app_info_.title.empty()) if (web_app_info->title.empty())
web_app_info_.title = contents->GetTitle(); web_app_info->title = contents->GetTitle();
if (web_app_info_.title.empty()) if (web_app_info->title.empty())
web_app_info_.title = base::UTF8ToUTF16(web_app_info_.app_url.spec()); web_app_info->title = base::UTF8ToUTF16(web_app_info->app_url.spec());
bookmark_app_helper_.reset( bookmark_app_helper_.reset(
new BookmarkAppHelper(profile_, web_app_info_, contents, new BookmarkAppHelper(profile_, std::move(web_app_info), contents,
InstallableMetrics::GetInstallSource( InstallableMetrics::GetInstallSource(
contents, InstallTrigger::MENU))); contents, InstallTrigger::MENU)));
if (shortcut_app_requested) if (shortcut_app_requested)
......
...@@ -178,9 +178,6 @@ class TabHelper : public content::WebContentsObserver, ...@@ -178,9 +178,6 @@ class TabHelper : public content::WebContentsObserver,
// non-extension apps. // non-extension apps.
SkBitmap extension_app_icon_; SkBitmap extension_app_icon_;
// Cached web app info data.
WebApplicationInfo web_app_info_;
// Which deferred action to perform when OnDidGetWebApplicationInfo is // Which deferred action to perform when OnDidGetWebApplicationInfo is
// notified from a WebContents. // notified from a WebContents.
WebAppAction pending_web_app_action_; WebAppAction pending_web_app_action_;
......
...@@ -104,7 +104,7 @@ using AppInstallationAcceptanceCallback = ...@@ -104,7 +104,7 @@ using AppInstallationAcceptanceCallback =
// //
// |web_app_info| is the WebApplicationInfo being converted into an app. // |web_app_info| is the WebApplicationInfo being converted into an app.
void ShowBookmarkAppDialog(content::WebContents* web_contents, void ShowBookmarkAppDialog(content::WebContents* web_contents,
const WebApplicationInfo& web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
AppInstallationAcceptanceCallback callback); AppInstallationAcceptanceCallback callback);
// Sets whether |ShowBookmarkAppDialog| should accept immediately without any // Sets whether |ShowBookmarkAppDialog| should accept immediately without any
...@@ -115,7 +115,7 @@ void SetAutoAcceptBookmarkAppDialogForTesting(bool auto_accept); ...@@ -115,7 +115,7 @@ void SetAutoAcceptBookmarkAppDialogForTesting(bool auto_accept);
// //
// |web_app_info| is the WebApplicationInfo to be installed. // |web_app_info| is the WebApplicationInfo to be installed.
void ShowPWAInstallDialog(content::WebContents* web_contents, void ShowPWAInstallDialog(content::WebContents* web_contents,
const WebApplicationInfo& web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
AppInstallationAcceptanceCallback callback); AppInstallationAcceptanceCallback callback);
// Shows the PWA installation confirmation bubble anchored off the PWA install // Shows the PWA installation confirmation bubble anchored off the PWA install
...@@ -123,7 +123,7 @@ void ShowPWAInstallDialog(content::WebContents* web_contents, ...@@ -123,7 +123,7 @@ void ShowPWAInstallDialog(content::WebContents* web_contents,
// //
// |web_app_info| is the WebApplicationInfo to be installed. // |web_app_info| is the WebApplicationInfo to be installed.
void ShowPWAInstallBubble(content::WebContents* web_contents, void ShowPWAInstallBubble(content::WebContents* web_contents,
const WebApplicationInfo& web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
AppInstallationAcceptanceCallback callback); AppInstallationAcceptanceCallback callback);
// Sets whether |ShowPWAInstallDialog| and |ShowPWAInstallBubble| should accept // Sets whether |ShowPWAInstallDialog| and |ShowPWAInstallBubble| should accept
......
...@@ -39,12 +39,13 @@ bool g_auto_accept_bookmark_app_for_testing = false; ...@@ -39,12 +39,13 @@ bool g_auto_accept_bookmark_app_for_testing = false;
BookmarkAppConfirmationView::~BookmarkAppConfirmationView() {} BookmarkAppConfirmationView::~BookmarkAppConfirmationView() {}
BookmarkAppConfirmationView::BookmarkAppConfirmationView( BookmarkAppConfirmationView::BookmarkAppConfirmationView(
const WebApplicationInfo& web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
chrome::AppInstallationAcceptanceCallback callback) chrome::AppInstallationAcceptanceCallback callback)
: web_app_info_(web_app_info), : web_app_info_(std::move(web_app_info)),
callback_(std::move(callback)), callback_(std::move(callback)),
open_as_window_checkbox_(nullptr), open_as_window_checkbox_(nullptr),
title_tf_(nullptr) { title_tf_(nullptr) {
DCHECK(web_app_info_);
const ChromeLayoutProvider* layout_provider = ChromeLayoutProvider::Get(); const ChromeLayoutProvider* layout_provider = ChromeLayoutProvider::Get();
set_margins(layout_provider->GetDialogInsetsForContentType(views::CONTROL, set_margins(layout_provider->GetDialogInsetsForContentType(views::CONTROL,
views::TEXT)); views::TEXT));
...@@ -69,7 +70,7 @@ BookmarkAppConfirmationView::BookmarkAppConfirmationView( ...@@ -69,7 +70,7 @@ BookmarkAppConfirmationView::BookmarkAppConfirmationView(
extension_misc::EXTENSION_ICON_SMALL); extension_misc::EXTENSION_ICON_SMALL);
gfx::ImageSkia image( gfx::ImageSkia image(
std::make_unique<WebAppInfoImageSource>( std::make_unique<WebAppInfoImageSource>(
extension_misc::EXTENSION_ICON_SMALL, web_app_info_.icons), extension_misc::EXTENSION_ICON_SMALL, web_app_info_->icons),
image_size); image_size);
icon_image_view->SetImageSize(image_size); icon_image_view->SetImageSize(image_size);
icon_image_view->SetImage(image); icon_image_view->SetImage(image);
...@@ -77,7 +78,7 @@ BookmarkAppConfirmationView::BookmarkAppConfirmationView( ...@@ -77,7 +78,7 @@ BookmarkAppConfirmationView::BookmarkAppConfirmationView(
layout->AddView(icon_image_view); layout->AddView(icon_image_view);
title_tf_ = new views::Textfield(); title_tf_ = new views::Textfield();
title_tf_->SetText(web_app_info_.title); title_tf_->SetText(web_app_info_->title);
title_tf_->SetAccessibleName( title_tf_->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_BOOKMARK_APP_AX_BUBBLE_NAME_LABEL)); l10n_util::GetStringUTF16(IDS_BOOKMARK_APP_AX_BUBBLE_NAME_LABEL));
title_tf_->set_controller(this); title_tf_->set_controller(this);
...@@ -88,7 +89,7 @@ BookmarkAppConfirmationView::BookmarkAppConfirmationView( ...@@ -88,7 +89,7 @@ BookmarkAppConfirmationView::BookmarkAppConfirmationView(
layout_provider->GetDistanceMetric(DISTANCE_CONTROL_LIST_VERTICAL)); layout_provider->GetDistanceMetric(DISTANCE_CONTROL_LIST_VERTICAL));
open_as_window_checkbox_ = new views::Checkbox( open_as_window_checkbox_ = new views::Checkbox(
l10n_util::GetStringUTF16(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_WINDOW)); l10n_util::GetStringUTF16(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_WINDOW));
open_as_window_checkbox_->SetChecked(web_app_info_.open_as_window); open_as_window_checkbox_->SetChecked(web_app_info_->open_as_window);
layout->StartRow(views::GridLayout::kFixedSize, kColumnSetId); layout->StartRow(views::GridLayout::kFixedSize, kColumnSetId);
layout->SkipColumns(1); layout->SkipColumns(1);
layout->AddView(open_as_window_checkbox_); layout->AddView(open_as_window_checkbox_);
...@@ -119,17 +120,17 @@ bool BookmarkAppConfirmationView::ShouldShowCloseButton() const { ...@@ -119,17 +120,17 @@ bool BookmarkAppConfirmationView::ShouldShowCloseButton() const {
void BookmarkAppConfirmationView::WindowClosing() { void BookmarkAppConfirmationView::WindowClosing() {
if (callback_) { if (callback_) {
std::move(callback_).Run( DCHECK(web_app_info_);
false, std::make_unique<WebApplicationInfo>(web_app_info_)); std::move(callback_).Run(false, std::move(web_app_info_));
} }
} }
bool BookmarkAppConfirmationView::Accept() { bool BookmarkAppConfirmationView::Accept() {
web_app_info_.title = GetTrimmedTitle(); DCHECK(web_app_info_);
web_app_info_.open_as_window = web_app_info_->title = GetTrimmedTitle();
web_app_info_->open_as_window =
open_as_window_checkbox_ && open_as_window_checkbox_->GetChecked(); open_as_window_checkbox_ && open_as_window_checkbox_->GetChecked();
std::move(callback_).Run(true, std::move(callback_).Run(true, std::move(web_app_info_));
std::make_unique<WebApplicationInfo>(web_app_info_));
return true; return true;
} }
...@@ -161,10 +162,11 @@ base::string16 BookmarkAppConfirmationView::GetTrimmedTitle() const { ...@@ -161,10 +162,11 @@ base::string16 BookmarkAppConfirmationView::GetTrimmedTitle() const {
namespace chrome { namespace chrome {
void ShowBookmarkAppDialog(content::WebContents* web_contents, void ShowBookmarkAppDialog(content::WebContents* web_contents,
const WebApplicationInfo& web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
AppInstallationAcceptanceCallback callback) { AppInstallationAcceptanceCallback callback) {
constrained_window::ShowWebModalDialogViews( constrained_window::ShowWebModalDialogViews(
new BookmarkAppConfirmationView(web_app_info, std::move(callback)), new BookmarkAppConfirmationView(std::move(web_app_info),
std::move(callback)),
web_contents); web_contents);
} }
......
...@@ -23,7 +23,7 @@ class BookmarkAppConfirmationView : public views::DialogDelegateView, ...@@ -23,7 +23,7 @@ class BookmarkAppConfirmationView : public views::DialogDelegateView,
public views::TextfieldController { public views::TextfieldController {
public: public:
BookmarkAppConfirmationView( BookmarkAppConfirmationView(
const WebApplicationInfo& web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
chrome::AppInstallationAcceptanceCallback callback); chrome::AppInstallationAcceptanceCallback callback);
~BookmarkAppConfirmationView() override; ~BookmarkAppConfirmationView() override;
...@@ -48,7 +48,8 @@ class BookmarkAppConfirmationView : public views::DialogDelegateView, ...@@ -48,7 +48,8 @@ class BookmarkAppConfirmationView : public views::DialogDelegateView,
base::string16 GetTrimmedTitle() const; base::string16 GetTrimmedTitle() const;
// The WebApplicationInfo that the user is editing. // The WebApplicationInfo that the user is editing.
WebApplicationInfo web_app_info_; // Cleared when the dialog completes (Accept/WindowClosing).
std::unique_ptr<WebApplicationInfo> web_app_info_;
// The callback to be invoked when the dialog is completed. // The callback to be invoked when the dialog is completed.
chrome::AppInstallationAcceptanceCallback callback_; chrome::AppInstallationAcceptanceCallback callback_;
......
...@@ -94,15 +94,16 @@ void InitializeDialogView(views::DialogDelegateView* dialog, ...@@ -94,15 +94,16 @@ void InitializeDialogView(views::DialogDelegateView* dialog,
PWAConfirmation::PWAConfirmation( PWAConfirmation::PWAConfirmation(
views::DialogDelegateView* dialog, views::DialogDelegateView* dialog,
const WebApplicationInfo& web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
chrome::AppInstallationAcceptanceCallback callback) chrome::AppInstallationAcceptanceCallback callback)
: web_app_info_(web_app_info), callback_(std::move(callback)) { : web_app_info_(std::move(web_app_info)), callback_(std::move(callback)) {
base::TrimWhitespace(web_app_info_.title, base::TRIM_ALL, DCHECK(web_app_info_);
&web_app_info_.title); base::TrimWhitespace(web_app_info_->title, base::TRIM_ALL,
&web_app_info_->title);
// PWAs should always be configured to open in a window. // PWAs should always be configured to open in a window.
DCHECK(web_app_info_.open_as_window); DCHECK(web_app_info_->open_as_window);
InitializeDialogView(dialog, web_app_info_); InitializeDialogView(dialog, *web_app_info_);
chrome::RecordDialogCreation(chrome::DialogIdentifier::PWA_CONFIRMATION); chrome::RecordDialogCreation(chrome::DialogIdentifier::PWA_CONFIRMATION);
...@@ -124,14 +125,14 @@ base::string16 PWAConfirmation::GetDialogButtonLabel(ui::DialogButton button) { ...@@ -124,14 +125,14 @@ base::string16 PWAConfirmation::GetDialogButtonLabel(ui::DialogButton button) {
} }
void PWAConfirmation::Accept() { void PWAConfirmation::Accept() {
std::move(callback_).Run(true, DCHECK(web_app_info_);
std::make_unique<WebApplicationInfo>(web_app_info_)); std::move(callback_).Run(true, std::move(web_app_info_));
} }
void PWAConfirmation::WindowClosing() { void PWAConfirmation::WindowClosing() {
if (callback_) { if (callback_) {
std::move(callback_).Run( DCHECK(web_app_info_);
false, std::make_unique<WebApplicationInfo>(web_app_info_)); std::move(callback_).Run(false, std::move(web_app_info_));
} }
} }
......
...@@ -18,7 +18,7 @@ class PWAConfirmation { ...@@ -18,7 +18,7 @@ class PWAConfirmation {
static base::string16 GetDialogButtonLabel(ui::DialogButton button); static base::string16 GetDialogButtonLabel(ui::DialogButton button);
PWAConfirmation(views::DialogDelegateView* dialog, PWAConfirmation(views::DialogDelegateView* dialog,
const WebApplicationInfo& web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
chrome::AppInstallationAcceptanceCallback callback); chrome::AppInstallationAcceptanceCallback callback);
~PWAConfirmation(); ~PWAConfirmation();
...@@ -26,7 +26,9 @@ class PWAConfirmation { ...@@ -26,7 +26,9 @@ class PWAConfirmation {
void WindowClosing(); void WindowClosing();
private: private:
WebApplicationInfo web_app_info_; // The WebApplicationInfo that the user is confirming.
// Cleared when the dialog completes (Accept/WindowClosing).
std::unique_ptr<WebApplicationInfo> web_app_info_;
chrome::AppInstallationAcceptanceCallback callback_; chrome::AppInstallationAcceptanceCallback callback_;
DISALLOW_COPY_AND_ASSIGN(PWAConfirmation); DISALLOW_COPY_AND_ASSIGN(PWAConfirmation);
......
...@@ -22,10 +22,10 @@ PWAConfirmationBubbleView* g_bubble_ = nullptr; ...@@ -22,10 +22,10 @@ PWAConfirmationBubbleView* g_bubble_ = nullptr;
PWAConfirmationBubbleView::PWAConfirmationBubbleView( PWAConfirmationBubbleView::PWAConfirmationBubbleView(
views::View* anchor_view, views::View* anchor_view,
views::Button* highlight_button, views::Button* highlight_button,
const WebApplicationInfo& web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
chrome::AppInstallationAcceptanceCallback callback) chrome::AppInstallationAcceptanceCallback callback)
: LocationBarBubbleDelegateView(anchor_view, gfx::Point(), nullptr), : LocationBarBubbleDelegateView(anchor_view, gfx::Point(), nullptr),
pwa_confirmation_(this, web_app_info, std::move(callback)) { pwa_confirmation_(this, std::move(web_app_info), std::move(callback)) {
SetHighlightedButton(highlight_button); SetHighlightedButton(highlight_button);
} }
...@@ -56,7 +56,7 @@ bool PWAConfirmationBubbleView::Accept() { ...@@ -56,7 +56,7 @@ bool PWAConfirmationBubbleView::Accept() {
namespace chrome { namespace chrome {
void ShowPWAInstallBubble(content::WebContents* web_contents, void ShowPWAInstallBubble(content::WebContents* web_contents,
const WebApplicationInfo& web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
AppInstallationAcceptanceCallback callback) { AppInstallationAcceptanceCallback callback) {
if (g_bubble_) if (g_bubble_)
return; return;
...@@ -74,7 +74,8 @@ void ShowPWAInstallBubble(content::WebContents* web_contents, ...@@ -74,7 +74,8 @@ void ShowPWAInstallBubble(content::WebContents* web_contents,
->GetPageActionIconView(PageActionIconType::kPwaInstall); ->GetPageActionIconView(PageActionIconType::kPwaInstall);
g_bubble_ = new PWAConfirmationBubbleView(anchor_view, highlight_button, g_bubble_ = new PWAConfirmationBubbleView(anchor_view, highlight_button,
web_app_info, std::move(callback)); std::move(web_app_info),
std::move(callback));
views::BubbleDialogDelegateView::CreateBubble(g_bubble_)->Show(); views::BubbleDialogDelegateView::CreateBubble(g_bubble_)->Show();
} }
......
...@@ -17,7 +17,7 @@ class PWAConfirmationBubbleView : public LocationBarBubbleDelegateView { ...@@ -17,7 +17,7 @@ class PWAConfirmationBubbleView : public LocationBarBubbleDelegateView {
public: public:
PWAConfirmationBubbleView(views::View* anchor_view, PWAConfirmationBubbleView(views::View* anchor_view,
views::Button* highlight_button, views::Button* highlight_button,
const WebApplicationInfo& web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
chrome::AppInstallationAcceptanceCallback callback); chrome::AppInstallationAcceptanceCallback callback);
// LocationBarBubbleDelegateView: // LocationBarBubbleDelegateView:
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
#include "url/origin.h" #include "url/origin.h"
PWAConfirmationDialogView::PWAConfirmationDialogView( PWAConfirmationDialogView::PWAConfirmationDialogView(
const WebApplicationInfo& web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
chrome::AppInstallationAcceptanceCallback callback) chrome::AppInstallationAcceptanceCallback callback)
: pwa_confirmation_(this, web_app_info, std::move(callback)) {} : pwa_confirmation_(this, std::move(web_app_info), std::move(callback)) {}
PWAConfirmationDialogView::~PWAConfirmationDialogView() {} PWAConfirmationDialogView::~PWAConfirmationDialogView() {}
...@@ -58,10 +58,11 @@ base::string16 PWAConfirmationDialogView::GetDialogButtonLabel( ...@@ -58,10 +58,11 @@ base::string16 PWAConfirmationDialogView::GetDialogButtonLabel(
namespace chrome { namespace chrome {
void ShowPWAInstallDialog(content::WebContents* web_contents, void ShowPWAInstallDialog(content::WebContents* web_contents,
const WebApplicationInfo& web_app_info, std::unique_ptr<WebApplicationInfo> web_app_info,
AppInstallationAcceptanceCallback callback) { AppInstallationAcceptanceCallback callback) {
constrained_window::ShowWebModalDialogViews( constrained_window::ShowWebModalDialogViews(
new PWAConfirmationDialogView(web_app_info, std::move(callback)), new PWAConfirmationDialogView(std::move(web_app_info),
std::move(callback)),
web_contents); web_contents);
} }
......
...@@ -20,7 +20,7 @@ class PWAConfirmationDialogView : public views::DialogDelegateView { ...@@ -20,7 +20,7 @@ class PWAConfirmationDialogView : public views::DialogDelegateView {
public: public:
// Constructs a PWAConfirmationDialogView. |web_app_info| contains information // Constructs a PWAConfirmationDialogView. |web_app_info| contains information
// about a web app that has passed the PWA check. // about a web app that has passed the PWA check.
PWAConfirmationDialogView(const WebApplicationInfo& web_app_info, PWAConfirmationDialogView(std::unique_ptr<WebApplicationInfo> web_app_info,
chrome::AppInstallationAcceptanceCallback callback); chrome::AppInstallationAcceptanceCallback callback);
~PWAConfirmationDialogView() override; ~PWAConfirmationDialogView() override;
......
...@@ -28,27 +28,29 @@ class PWAConfirmationDialogViewTest : public DialogBrowserTest { ...@@ -28,27 +28,29 @@ class PWAConfirmationDialogViewTest : public DialogBrowserTest {
icon_info.width = kIconSize; icon_info.width = kIconSize;
icon_info.height = kIconSize; icon_info.height = kIconSize;
WebApplicationInfo web_app_info; std::unique_ptr<WebApplicationInfo> web_app_info =
web_app_info.icons.push_back(icon_info); std::make_unique<WebApplicationInfo>();
web_app_info.open_as_window = true; web_app_info->icons.push_back(icon_info);
web_app_info->open_as_window = true;
if (name == "short_text") { if (name == "short_text") {
web_app_info.title = base::ASCIIToUTF16("Title"); web_app_info->title = base::ASCIIToUTF16("Title");
web_app_info.app_url = GURL("https://www.example.com:9090/path"); web_app_info->app_url = GURL("https://www.example.com:9090/path");
} else if (name == "long_text") { } else if (name == "long_text") {
web_app_info.title = web_app_info->title =
base::ASCIIToUTF16("abcd\n1234567890123456789012345678901234567890"); base::ASCIIToUTF16("abcd\n1234567890123456789012345678901234567890");
web_app_info.app_url = GURL( web_app_info->app_url = GURL(
"https://www" "https://www"
".1234567890123456789012345678901234567890" ".1234567890123456789012345678901234567890"
".com:443/path"); ".com:443/path");
} else if (name == "rtl") { } else if (name == "rtl") {
web_app_info.title = base::UTF8ToUTF16("דוגמא"); web_app_info->title = base::UTF8ToUTF16("דוגמא");
web_app_info.app_url = GURL("https://דוגמא.דוגמא.דוגמא.אחד.example.com"); web_app_info->app_url = GURL("https://דוגמא.דוגמא.דוגמא.אחד.example.com");
} }
constrained_window::ShowWebModalDialogViews( constrained_window::ShowWebModalDialogViews(
new PWAConfirmationDialogView( new PWAConfirmationDialogView(
web_app_info, chrome::AppInstallationAcceptanceCallback()), std::move(web_app_info),
chrome::AppInstallationAcceptanceCallback()),
browser()->tab_strip_model()->GetActiveWebContents()); browser()->tab_strip_model()->GetActiveWebContents());
} }
......
...@@ -32,6 +32,7 @@ void WebAppInstallDialogCallback( ...@@ -32,6 +32,7 @@ void WebAppInstallDialogCallback(
ForInstallableSite for_installable_site, ForInstallableSite for_installable_site,
InstallManager::WebAppInstallationAcceptanceCallback InstallManager::WebAppInstallationAcceptanceCallback
web_app_acceptance_callback) { web_app_acceptance_callback) {
DCHECK(web_app_info);
// This is a copy paste of BookmarkAppHelper::OnIconsDownloaded(). // This is a copy paste of BookmarkAppHelper::OnIconsDownloaded().
// TODO(https://crbug.com/915043): Delete // TODO(https://crbug.com/915043): Delete
// BookmarkAppHelper::OnIconsDownloaded(). // BookmarkAppHelper::OnIconsDownloaded().
...@@ -39,14 +40,17 @@ void WebAppInstallDialogCallback( ...@@ -39,14 +40,17 @@ void WebAppInstallDialogCallback(
for_installable_site == ForInstallableSite::kYes) { for_installable_site == ForInstallableSite::kYes) {
web_app_info->open_as_window = true; web_app_info->open_as_window = true;
if (install_source == WebappInstallSource::OMNIBOX_INSTALL_ICON) { if (install_source == WebappInstallSource::OMNIBOX_INSTALL_ICON) {
chrome::ShowPWAInstallBubble(initiator_web_contents, *web_app_info, chrome::ShowPWAInstallBubble(initiator_web_contents,
std::move(web_app_info),
std::move(web_app_acceptance_callback)); std::move(web_app_acceptance_callback));
} else { } else {
chrome::ShowPWAInstallDialog(initiator_web_contents, *web_app_info, chrome::ShowPWAInstallDialog(initiator_web_contents,
std::move(web_app_info),
std::move(web_app_acceptance_callback)); std::move(web_app_acceptance_callback));
} }
} else { } else {
chrome::ShowBookmarkAppDialog(initiator_web_contents, *web_app_info, chrome::ShowBookmarkAppDialog(initiator_web_contents,
std::move(web_app_info),
std::move(web_app_acceptance_callback)); std::move(web_app_acceptance_callback));
} }
} }
......
...@@ -236,7 +236,7 @@ void OnGetWebApplicationInfo(const BookmarkAppInstallManager* install_manager, ...@@ -236,7 +236,7 @@ void OnGetWebApplicationInfo(const BookmarkAppInstallManager* install_manager,
DCHECK(profile); DCHECK(profile);
auto bookmark_app_helper = install_manager->bookmark_app_helper_factory().Run( auto bookmark_app_helper = install_manager->bookmark_app_helper_factory().Run(
profile, *web_app_info, install_task->web_contents(), profile, std::move(web_app_info), install_task->web_contents(),
metrics_install_source); metrics_install_source);
BookmarkAppHelper* helper_ptr = bookmark_app_helper.get(); BookmarkAppHelper* helper_ptr = bookmark_app_helper.get();
...@@ -256,11 +256,11 @@ BookmarkAppInstallManager::BookmarkAppInstallManager( ...@@ -256,11 +256,11 @@ BookmarkAppInstallManager::BookmarkAppInstallManager(
web_app::InstallFinalizer* finalizer) web_app::InstallFinalizer* finalizer)
: InstallManager(profile), finalizer_(finalizer) { : InstallManager(profile), finalizer_(finalizer) {
bookmark_app_helper_factory_ = base::BindRepeating( bookmark_app_helper_factory_ = base::BindRepeating(
[](Profile* profile, const WebApplicationInfo& web_app_info, [](Profile* profile, std::unique_ptr<WebApplicationInfo> web_app_info,
content::WebContents* web_contents, content::WebContents* web_contents,
WebappInstallSource install_source) { WebappInstallSource install_source) {
return std::make_unique<BookmarkAppHelper>( return std::make_unique<BookmarkAppHelper>(
profile, web_app_info, web_contents, install_source); profile, std::move(web_app_info), web_contents, install_source);
}); });
data_retriever_factory_ = base::BindRepeating( data_retriever_factory_ = base::BindRepeating(
...@@ -308,10 +308,10 @@ void BookmarkAppInstallManager::InstallWebAppFromManifest( ...@@ -308,10 +308,10 @@ void BookmarkAppInstallManager::InstallWebAppFromManifest(
Profile* profile = Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext()); Profile::FromBrowserContext(web_contents->GetBrowserContext());
WebApplicationInfo web_app_info;
auto bookmark_app_helper = std::make_unique<BookmarkAppHelper>( auto bookmark_app_helper = std::make_unique<BookmarkAppHelper>(
profile, web_app_info, web_contents, install_source); profile, std::make_unique<WebApplicationInfo>(), web_contents,
install_source);
BookmarkAppHelper* helper = bookmark_app_helper.get(); BookmarkAppHelper* helper = bookmark_app_helper.get();
...@@ -331,7 +331,7 @@ void BookmarkAppInstallManager::InstallWebAppFromInfo( ...@@ -331,7 +331,7 @@ void BookmarkAppInstallManager::InstallWebAppFromInfo(
WebappInstallSource install_source, WebappInstallSource install_source,
OnceInstallCallback callback) { OnceInstallCallback callback) {
auto bookmark_app_helper = std::make_unique<BookmarkAppHelper>( auto bookmark_app_helper = std::make_unique<BookmarkAppHelper>(
profile(), *web_application_info, /*web_contents=*/nullptr, profile(), std::move(web_application_info), /*web_contents=*/nullptr,
install_source); install_source);
if (no_network_install) { if (no_network_install) {
......
...@@ -67,7 +67,7 @@ class BookmarkAppInstallManager final : public web_app::InstallManager { ...@@ -67,7 +67,7 @@ class BookmarkAppInstallManager final : public web_app::InstallManager {
using BookmarkAppHelperFactory = using BookmarkAppHelperFactory =
base::RepeatingCallback<std::unique_ptr<BookmarkAppHelper>( base::RepeatingCallback<std::unique_ptr<BookmarkAppHelper>(
Profile*, Profile*,
const WebApplicationInfo&, std::unique_ptr<WebApplicationInfo>,
content::WebContents*, content::WebContents*,
WebappInstallSource)>; WebappInstallSource)>;
......
...@@ -186,15 +186,16 @@ TEST_F(BookmarkAppInstallManagerTest, ...@@ -186,15 +186,16 @@ TEST_F(BookmarkAppInstallManagerTest,
})); }));
install_manager_->SetBookmarkAppHelperFactoryForTesting( install_manager_->SetBookmarkAppHelperFactoryForTesting(
base::BindLambdaForTesting([&](Profile* profile, base::BindLambdaForTesting(
const WebApplicationInfo& web_app_info, [&](Profile* profile,
content::WebContents* web_contents, std::unique_ptr<WebApplicationInfo> web_app_info,
WebappInstallSource install_source) { content::WebContents* web_contents,
data_retrieval_passed = true; WebappInstallSource install_source) {
retrieval_run_loop.Quit(); data_retrieval_passed = true;
return std::make_unique<BookmarkAppHelper>( retrieval_run_loop.Quit();
profile, web_app_info, web_contents, install_source); return std::make_unique<BookmarkAppHelper>(
})); profile, std::move(web_app_info), web_contents, install_source);
}));
base::RunLoop install_run_loop; base::RunLoop install_run_loop;
bool callback_called = false; bool callback_called = false;
...@@ -278,15 +279,16 @@ TEST_F(BookmarkAppInstallManagerTest, ...@@ -278,15 +279,16 @@ TEST_F(BookmarkAppInstallManagerTest,
})); }));
install_manager_->SetBookmarkAppHelperFactoryForTesting( install_manager_->SetBookmarkAppHelperFactoryForTesting(
base::BindLambdaForTesting([&](Profile* profile, base::BindLambdaForTesting(
const WebApplicationInfo& web_app_info, [&](Profile* profile,
content::WebContents* web_contents, std::unique_ptr<WebApplicationInfo> web_app_info,
WebappInstallSource install_source) { content::WebContents* web_contents,
data_retrieval_passed = true; WebappInstallSource install_source) {
retrieval_run_loop.Quit(); data_retrieval_passed = true;
return std::make_unique<BookmarkAppHelper>( retrieval_run_loop.Quit();
profile, web_app_info, web_contents, install_source); return std::make_unique<BookmarkAppHelper>(
})); profile, std::move(web_app_info), web_contents, install_source);
}));
base::RunLoop install_run_loop; base::RunLoop install_run_loop;
bool callback_called = false; bool callback_called = false;
......
...@@ -70,11 +70,7 @@ bool IsPlaceholderApp(Profile* profile, const GURL& url) { ...@@ -70,11 +70,7 @@ bool IsPlaceholderApp(Profile* profile, const GURL& url) {
class TestBookmarkAppHelper : public BookmarkAppHelper { class TestBookmarkAppHelper : public BookmarkAppHelper {
public: public:
TestBookmarkAppHelper(Profile* profile, using BookmarkAppHelper::BookmarkAppHelper;
WebApplicationInfo web_app_info,
content::WebContents* contents,
WebappInstallSource install_source)
: BookmarkAppHelper(profile, web_app_info, contents, install_source) {}
~TestBookmarkAppHelper() override {} ~TestBookmarkAppHelper() override {}
void CompleteInstallation() { void CompleteInstallation() {
...@@ -288,11 +284,13 @@ class BookmarkAppInstallationTaskTest : public ChromeRenderViewHostTestHarness { ...@@ -288,11 +284,13 @@ class BookmarkAppInstallationTaskTest : public ChromeRenderViewHostTestHarness {
install_manager->SetBookmarkAppHelperFactoryForTesting( install_manager->SetBookmarkAppHelperFactoryForTesting(
base::BindLambdaForTesting( base::BindLambdaForTesting(
[this](Profile* profile, const WebApplicationInfo& web_app_info, [this](Profile* profile,
std::unique_ptr<WebApplicationInfo> web_app_info,
content::WebContents* web_contents, content::WebContents* web_contents,
WebappInstallSource install_source) { WebappInstallSource install_source) {
auto test_helper = std::make_unique<TestBookmarkAppHelper>( auto test_helper = std::make_unique<TestBookmarkAppHelper>(
profile, web_app_info, web_contents, install_source); profile, std::move(web_app_info), web_contents,
install_source);
test_helper_ = test_helper.get(); test_helper_ = test_helper.get();
return std::unique_ptr<BookmarkAppHelper>(std::move(test_helper)); return std::unique_ptr<BookmarkAppHelper>(std::move(test_helper));
......
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