Commit ac4c0f7c authored by Daniel Murphy's avatar Daniel Murphy Committed by Commit Bot

[BMO] Migrating AppLauncherHandler's app list, launch, setLaunch to BMO

This change starts the migration of the chrome://apps UI to support BMO.
1. Updates the 'population' logic to create items for WebApps fetched
   through the AppRegistrar for display in chrome://apps
2. Updates the 'launch' logic to correctly launch webapps populated
   through BMO.
3. Update the 'setLaunchType' event logic to set the display mode in the
   BMO system.
4. NOTIMPLEMENTED() calls on all methods where BMO is not supported (and
   it is turned on).

One nuance with this change is that the icons for the BMO web apps do
not display correctly in chrome://apps. This is because the icon is
pointing to the remote source of the icon, which violates the cross
origin policy of the chrome://apps page. It is currently unclear what
should be done here, so leaving that as broken for now.

A nuance on that nuance is that when BMO is not turned on, it still
serves the extensions-backed web apps through its abstraction layers.
This is good for us for testing, and allows most of the code in this
patch to be used & tested when chrome://apps is used. However, it also
means that icons for all webapps would no longer show up, given the
nuance above. So to prevent this breakage, this is special-cased (where
BMO is turned off but we are serving a web app) and the old extentions-
backed icon url is used. This allows the icon to still work when BMO is
off.

Doc:
https://docs.google.com/document/d/1BcDJHd0gEt5oImBsNbgRg7Fz9T3I-YO7KkUuSLHQSYg/edit

Bug: 1009302
Change-Id: Ib2f05e6be0b856fbe1d68adc8d1dc6ef0db6f11d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2090492Reviewed-by: default avatarcalamity <calamity@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Commit-Queue: Daniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756717}
parent 78ea531d
......@@ -18,6 +18,7 @@
#include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h"
#include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h"
#include "chrome/browser/ui/webui/theme_handler.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h"
......@@ -42,9 +43,13 @@ AppLauncherPageUI::AppLauncherPageUI(content::WebUI* web_ui)
if (!GetProfile()->IsOffTheRecord()) {
extensions::ExtensionService* service =
extensions::ExtensionSystem::Get(GetProfile())->extension_service();
// We should not be launched without an ExtensionService.
web_app::WebAppProvider* web_app_provider =
web_app::WebAppProvider::Get(GetProfile());
DCHECK(web_app_provider);
DCHECK(service);
web_ui->AddMessageHandler(std::make_unique<AppLauncherHandler>(service));
// We should not be launched without an ExtensionService or WebAppProvider.
web_ui->AddMessageHandler(
std::make_unique<AppLauncherHandler>(service, web_app_provider));
web_ui->AddMessageHandler(std::make_unique<CoreAppLauncherHandler>());
web_ui->AddMessageHandler(std::make_unique<AppIconWebUIHandler>());
web_ui->AddMessageHandler(std::make_unique<MetricsHandler>());
......@@ -146,4 +151,4 @@ std::string AppLauncherPageUI::HTMLSource::GetContentSecurityPolicyImgSrc() {
"data:;";
}
AppLauncherPageUI::HTMLSource::~HTMLSource() {}
AppLauncherPageUI::HTMLSource::~HTMLSource() = default;
......@@ -80,12 +80,17 @@ GURL ExtensionIconSource::GetIconURL(const Extension* extension,
int icon_size,
ExtensionIconSet::MatchType match,
bool grayscale) {
GURL icon_url(base::StringPrintf("%s%s/%d/%d%s",
chrome::kChromeUIExtensionIconURL,
extension->id().c_str(),
icon_size,
match,
grayscale ? "?grayscale=true" : ""));
return GetIconURL(extension->id(), icon_size, match, grayscale);
}
// static
GURL ExtensionIconSource::GetIconURL(const std::string& extension_id,
int icon_size,
ExtensionIconSet::MatchType match,
bool grayscale) {
GURL icon_url(base::StringPrintf(
"%s%s/%d/%d%s", chrome::kChromeUIExtensionIconURL, extension_id.c_str(),
icon_size, match, grayscale ? "?grayscale=true" : ""));
CHECK(icon_url.is_valid());
return icon_url;
}
......
......@@ -62,6 +62,10 @@ class ExtensionIconSource : public content::URLDataSource,
int icon_size,
ExtensionIconSet::MatchType match,
bool grayscale);
static GURL GetIconURL(const std::string& extension_id,
int icon_size,
ExtensionIconSet::MatchType match,
bool grayscale);
// A public utility function for accessing the bitmap of the image specified
// by |resource_id|.
......
......@@ -10,9 +10,13 @@
#include <string>
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/extensions/extension_uninstall_dialog.h"
#include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"
#include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/components/app_registrar_observer.h"
#include "chrome/browser/web_applications/components/web_app_id.h"
#include "chrome/common/extensions/extension_constants.h"
#include "components/favicon/core/favicon_service.h"
#include "components/prefs/pref_change_registrar.h"
......@@ -29,7 +33,7 @@ class Profile;
namespace extensions {
class ExtensionService;
}
} // namespace extensions
namespace favicon_base {
struct FaviconImageResult;
......@@ -39,25 +43,32 @@ namespace user_prefs {
class PrefRegistrySyncable;
}
namespace web_app {
class WebAppProvider;
} // namespace web_app
// The handler for Javascript messages related to the "apps" view.
class AppLauncherHandler
: public content::WebUIMessageHandler,
public extensions::ExtensionUninstallDialog::Delegate,
public ExtensionEnableFlowDelegate,
public content::NotificationObserver,
public web_app::AppRegistrarObserver,
public extensions::ExtensionRegistryObserver {
public:
explicit AppLauncherHandler(extensions::ExtensionService* extension_service);
AppLauncherHandler(extensions::ExtensionService* extension_service,
web_app::WebAppProvider* web_app_provider);
~AppLauncherHandler() override;
// Populate a dictionary with the information from an extension.
static void CreateAppInfo(const extensions::Extension* extension,
extensions::ExtensionService* service,
base::DictionaryValue* value);
void CreateWebAppInfo(const web_app::AppId& app_id,
base::DictionaryValue* value);
void CreateExtensionInfo(const extensions::Extension* extension,
base::DictionaryValue* value);
// Registers values (strings etc.) for the page.
static void GetLocalizedValues(Profile* profile,
base::DictionaryValue* values);
base::DictionaryValue* values);
// Register per-profile preferences.
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
......@@ -80,14 +91,23 @@ class AppLauncherHandler
const extensions::Extension* extension,
extensions::UninstallReason reason) override;
// web_app::AppRegistrarObserver:
void OnWebAppInstalled(const web_app::AppId& app_id) override;
void OnWebAppWillBeUninstalled(const web_app::AppId& app_id) override;
void OnAppRegistrarDestroyed() override;
// Populate the given dictionary with all installed app info.
void FillAppDictionary(base::DictionaryValue* value);
// Create a dictionary value for the given extension. May return null, e.g. if
// the given extension is not an app.
std::unique_ptr<base::DictionaryValue> GetAppInfo(
// Create a dictionary value for the given extension.
std::unique_ptr<base::DictionaryValue> GetExtensionInfo(
const extensions::Extension* extension);
// Create a dictionary value for the given web app.
std::unique_ptr<base::DictionaryValue> GetWebAppInfo(
const web_app::AppId& app_id,
const web_app::AppRegistrar& app_registrar);
// Populate the given dictionary with the web store promo content.
void FillPromoDictionary(base::DictionaryValue* value);
......@@ -181,8 +201,10 @@ class AppLauncherHandler
void OnExtensionPreferenceChanged();
// Called when an app is removed (unloaded or uninstalled). Updates the UI.
void AppRemoved(const extensions::Extension* extension, bool is_uninstall);
// Called when an extension is removed (unloaded or uninstalled). Updates the
// UI.
void ExtensionRemoved(const extensions::Extension* extension,
bool is_uninstall);
// True if the extension should be displayed.
bool ShouldShow(const extensions::Extension* extension) const;
......@@ -191,6 +213,14 @@ class AppLauncherHandler
// outlives us since it's owned by our containing profile.
extensions::ExtensionService* const extension_service_;
// The apps are represented in the web apps model, which outlives us since
// it's owned by our containing profile. Populated iff
// features::kDesktopPWAsWithoutExtensions is enabled.
web_app::WebAppProvider* const web_app_provider_;
ScopedObserver<web_app::AppRegistrar, web_app::AppRegistrarObserver>
web_apps_observer_{this};
// We monitor changes to the extension system so that we can reload the apps
// when necessary.
content::NotificationRegistrar registrar_;
......
......@@ -12,6 +12,7 @@
#include "chrome/common/chrome_features.h"
#include "chrome/common/extensions/api/url_handlers/url_handlers_parser.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
#include "content/public/browser/browser_context.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
......@@ -101,4 +102,27 @@ std::vector<SquareSizePx> GetBookmarkAppDownloadedIconSizes(
return icon_sizes_in_px;
}
LaunchContainerAndType GetLaunchContainerAndTypeFromDisplayMode(
web_app::DisplayMode display_mode) {
apps::mojom::LaunchContainer apps_launch_container =
web_app::ConvertDisplayModeToAppLaunchContainer(display_mode);
switch (apps_launch_container) {
case apps::mojom::LaunchContainer::kLaunchContainerNone:
return {extensions::LaunchContainer::kLaunchContainerNone,
extensions::LaunchType::LAUNCH_TYPE_DEFAULT};
case apps::mojom::LaunchContainer::kLaunchContainerPanelDeprecated:
return {extensions::LaunchContainer::kLaunchContainerPanelDeprecated,
extensions::LaunchType::LAUNCH_TYPE_REGULAR};
case apps::mojom::LaunchContainer::kLaunchContainerTab:
return {extensions::LaunchContainer::kLaunchContainerTab,
extensions::LaunchType::LAUNCH_TYPE_REGULAR};
case apps::mojom::LaunchContainer::kLaunchContainerWindow:
return {extensions::LaunchContainer::kLaunchContainerTab,
display_mode == web_app::DisplayMode::kFullscreen
? extensions::LaunchType::LAUNCH_TYPE_FULLSCREEN
: extensions::LaunchType::LAUNCH_TYPE_WINDOW};
}
NOTREACHED();
}
} // namespace extensions
......@@ -7,7 +7,9 @@
#include <vector>
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/common/web_application_info.h"
#include "extensions/common/constants.h"
namespace content {
class BrowserContext;
......@@ -49,6 +51,14 @@ int CountUserInstalledBookmarkApps(content::BrowserContext* browser_context);
std::vector<SquareSizePx> GetBookmarkAppDownloadedIconSizes(
const Extension* extension);
struct LaunchContainerAndType {
extensions::LaunchContainer launch_container;
extensions::LaunchType launch_type;
};
LaunchContainerAndType GetLaunchContainerAndTypeFromDisplayMode(
web_app::DisplayMode display_mode);
} // namespace extensions
#endif // CHROME_BROWSER_WEB_APPLICATIONS_EXTENSIONS_BOOKMARK_APP_UTIL_H_
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