Commit 8e600e58 authored by Daniel Murphy's avatar Daniel Murphy Committed by Commit Bot

[BMO] Migrate chrome://apps shortcut creation to BMO

This adds back the "Create Shortcut" functionality to chrome://apps for
the BMO system.

R=loyso@chromium.org

Bug: 1009302, 1069298
Fixed: 1069293
Change-Id: Ic14e71155a0eb7a6a02fb5a82aab9c3362f8b015
Tested: Manually, with BMO turned on and off
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2121421
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarccameron <ccameron@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758029}
parent 0aee62c2
...@@ -88,6 +88,14 @@ void ShowCreateChromeAppShortcutsDialog( ...@@ -88,6 +88,14 @@ void ShowCreateChromeAppShortcutsDialog(
const extensions::Extension* app, const extensions::Extension* app,
const base::Callback<void(bool /* created */)>& close_callback); const base::Callback<void(bool /* created */)>& close_callback);
// Shows the create chrome app shortcut dialog box. Same as above but for a
// WebApp instead of an Extension. |close_callback| may be null.
void ShowCreateChromeAppShortcutsDialog(
gfx::NativeWindow parent_window,
Profile* profile,
const std::string& web_app_id,
const base::Callback<void(bool /* created */)>& close_callback);
// Callback used to indicate whether a user has accepted the installation of a // Callback used to indicate whether a user has accepted the installation of a
// web app. The boolean parameter is true when the user accepts the dialog. The // web app. The boolean parameter is true when the user accepts the dialog. The
// WebApplicationInfo parameter contains the information about the app, // WebApplicationInfo parameter contains the information about the app,
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h" #include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/web_applications/components/app_shortcut_manager.h"
#include "chrome/browser/web_applications/extensions/web_app_extension_shortcut.h" #include "chrome/browser/web_applications/extensions/web_app_extension_shortcut.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/constrained_window/constrained_window_views.h" #include "components/constrained_window/constrained_window_views.h"
...@@ -38,6 +40,18 @@ void ShowCreateChromeAppShortcutsDialog( ...@@ -38,6 +40,18 @@ void ShowCreateChromeAppShortcutsDialog(
parent_window)->Show(); parent_window)->Show();
} }
void ShowCreateChromeAppShortcutsDialog(
gfx::NativeWindow parent_window,
Profile* profile,
const std::string& web_app_id,
const base::Callback<void(bool)>& close_callback) {
constrained_window::CreateBrowserModalDialogViews(
new CreateChromeApplicationShortcutView(profile, web_app_id,
close_callback),
parent_window)
->Show();
}
} // namespace chrome } // namespace chrome
CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView(
...@@ -61,6 +75,28 @@ CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( ...@@ -61,6 +75,28 @@ CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView(
chrome::DialogIdentifier::CREATE_CHROME_APPLICATION_SHORTCUT); chrome::DialogIdentifier::CREATE_CHROME_APPLICATION_SHORTCUT);
} }
CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView(
Profile* profile,
const std::string& web_app_id,
const base::Callback<void(bool)>& close_callback)
: profile_(profile), close_callback_(close_callback) {
DialogDelegate::SetButtonLabel(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_COMMIT));
set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
views::TEXT, views::TEXT));
InitControls();
web_app::WebAppProvider* provider = web_app::WebAppProvider::Get(profile);
provider->shortcut_manager().GetShortcutInfoForApp(
web_app_id,
base::Bind(&CreateChromeApplicationShortcutView::OnAppInfoLoaded,
weak_ptr_factory_.GetWeakPtr()));
chrome::RecordDialogCreation(
chrome::DialogIdentifier::CREATE_CHROME_APPLICATION_SHORTCUT);
}
CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {} CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {}
void CreateChromeApplicationShortcutView::InitControls() { void CreateChromeApplicationShortcutView::InitControls() {
......
...@@ -34,6 +34,10 @@ class CreateChromeApplicationShortcutView : public views::DialogDelegateView, ...@@ -34,6 +34,10 @@ class CreateChromeApplicationShortcutView : public views::DialogDelegateView,
Profile* profile, Profile* profile,
const extensions::Extension* app, const extensions::Extension* app,
const base::Callback<void(bool)>& close_callback); const base::Callback<void(bool)>& close_callback);
CreateChromeApplicationShortcutView(
Profile* profile,
const std::string& web_app_id,
const base::Callback<void(bool)>& close_callback);
~CreateChromeApplicationShortcutView() override; ~CreateChromeApplicationShortcutView() override;
// Initialize the controls on the dialog. // Initialize the controls on the dialog.
......
...@@ -921,29 +921,39 @@ void AppLauncherHandler::HandleUninstallApp(const base::ListValue* args) { ...@@ -921,29 +921,39 @@ void AppLauncherHandler::HandleUninstallApp(const base::ListValue* args) {
} }
void AppLauncherHandler::HandleCreateAppShortcut(const base::ListValue* args) { void AppLauncherHandler::HandleCreateAppShortcut(const base::ListValue* args) {
std::string extension_id; std::string app_id;
CHECK(args->GetString(0, &extension_id)); CHECK(args->GetString(0, &app_id));
if (DesktopPWAsWithoutExtensions() && if (web_app_provider_->registrar().IsInstalled(app_id)) {
web_app_provider_->registrar().IsInstalled(extension_id)) { Browser* browser =
NOTIMPLEMENTED(); chrome::FindBrowserWithWebContents(web_ui()->GetWebContents());
chrome::ShowCreateChromeAppShortcutsDialog(
browser->window()->GetNativeWindow(), browser->profile(), app_id,
base::BindRepeating([](bool success) {
LOCAL_HISTOGRAM_BOOLEAN(
"Apps.AppInfoDialog.CreateWebAppShortcutSuccess", success);
}));
return; return;
} }
const Extension* extension = const Extension* extension =
extensions::ExtensionRegistry::Get(extension_service_->profile()) extensions::ExtensionRegistry::Get(extension_service_->profile())
->GetExtensionById(extension_id, ->GetExtensionById(app_id,
extensions::ExtensionRegistry::ENABLED | extensions::ExtensionRegistry::ENABLED |
extensions::ExtensionRegistry::DISABLED | extensions::ExtensionRegistry::DISABLED |
extensions::ExtensionRegistry::TERMINATED); extensions::ExtensionRegistry::TERMINATED);
if (!extension) if (!extension)
return; return;
DCHECK(!extension->from_bookmark());
Browser* browser = chrome::FindBrowserWithWebContents( Browser* browser = chrome::FindBrowserWithWebContents(
web_ui()->GetWebContents()); web_ui()->GetWebContents());
chrome::ShowCreateChromeAppShortcutsDialog( chrome::ShowCreateChromeAppShortcutsDialog(
browser->window()->GetNativeWindow(), browser->profile(), extension, browser->window()->GetNativeWindow(), browser->profile(), extension,
base::Callback<void(bool)>()); base::BindRepeating([](bool success) {
LOCAL_HISTOGRAM_BOOLEAN(
"Apps.AppInfoDialog.CreateExtensionShortcutSuccess", success);
}));
} }
void AppLauncherHandler::HandleInstallAppLocally(const base::ListValue* args) { void AppLauncherHandler::HandleInstallAppLocally(const base::ListValue* args) {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "chrome/browser/extensions/extension_ui_util.h" #include "chrome/browser/extensions/extension_ui_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/web_applications/components/app_shortcut_manager.h"
#include "chrome/browser/web_applications/components/file_handler_manager.h" #include "chrome/browser/web_applications/components/file_handler_manager.h"
#include "chrome/browser/web_applications/components/web_app_id.h" #include "chrome/browser/web_applications/components/web_app_id.h"
#include "chrome/browser/web_applications/components/web_app_provider_base.h" #include "chrome/browser/web_applications/components/web_app_provider_base.h"
...@@ -241,6 +242,20 @@ void CreateShortcuts(ShortcutCreationReason reason, ...@@ -241,6 +242,20 @@ void CreateShortcuts(ShortcutCreationReason reason,
locations, std::move(callback))); locations, std::move(callback)));
} }
void CreateShortcutsForWebApp(ShortcutCreationReason reason,
const ShortcutLocations& locations,
Profile* profile,
const std::string& app_id,
CreateShortcutsCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
WebAppProviderBase::GetProviderBase(profile)
->shortcut_manager()
.GetShortcutInfoForApp(
app_id, base::BindOnce(&CreateShortcutsWithInfo, reason, locations,
std::move(callback)));
}
void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) { void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
......
...@@ -59,6 +59,15 @@ void CreateShortcuts(ShortcutCreationReason reason, ...@@ -59,6 +59,15 @@ void CreateShortcuts(ShortcutCreationReason reason,
const extensions::Extension* app, const extensions::Extension* app,
CreateShortcutsCallback callback); CreateShortcutsCallback callback);
// Creates shortcuts for a webapp. This loads the app's icon from disk, and
// calls CreateShortcutsWithInfo(). If you already have a ShortcutInfo with the
// app's icon loaded, you should use CreateShortcutsWithInfo() directly.
void CreateShortcutsForWebApp(ShortcutCreationReason reason,
const ShortcutLocations& locations,
Profile* profile,
const std::string& app_id,
CreateShortcutsCallback callback);
// Delete all shortcuts that have been created for the given profile and // Delete all shortcuts that have been created for the given profile and
// extension. // extension.
void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app); void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app);
......
...@@ -157,4 +157,18 @@ void ShowCreateChromeAppShortcutsDialog( ...@@ -157,4 +157,18 @@ void ShowCreateChromeAppShortcutsDialog(
close_callback.Run(true); close_callback.Run(true);
} }
void ShowCreateChromeAppShortcutsDialog(
gfx::NativeWindow /*parent_window*/,
Profile* profile,
const std::string& app_id,
const base::Callback<void(bool)>& close_callback) {
// On Mac, the Applications folder is the only option, so don't bother asking
// the user anything. Just create shortcuts.
CreateShortcutsForWebApp(web_app::SHORTCUT_CREATION_BY_USER,
web_app::ShortcutLocations(), profile, app_id,
base::DoNothing());
if (!close_callback.is_null())
close_callback.Run(true);
}
} // namespace chrome } // namespace chrome
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