Commit 36603cc6 authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

desktop-pwas: Only add a scope for installable sites i.e. PWAs

Also changes Installable to an enum class to avoid accidental
implicit casts to bools.

Bug: 801940
Change-Id: I186d878b338375e339b3b5eb24fa5f2abd6c975a
Reviewed-on: https://chromium-review.googlesource.com/981835Reviewed-by: default avatarMatt Giuca <mgiuca@chromium.org>
Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550502}
parent 93212b6e
......@@ -339,7 +339,8 @@ namespace extensions {
// static
void BookmarkAppHelper::UpdateWebAppInfoFromManifest(
const content::Manifest& manifest,
WebApplicationInfo* web_app_info) {
WebApplicationInfo* web_app_info,
ForInstallableSite for_installable_site) {
if (!manifest.short_name.is_null())
web_app_info->title = manifest.short_name.string();
......@@ -351,13 +352,15 @@ void BookmarkAppHelper::UpdateWebAppInfoFromManifest(
if (manifest.start_url.is_valid())
web_app_info->app_url = manifest.start_url;
// If there is no scope present, use 'start_url' without the filename as the
// scope. This does not match the spec but it matches what we do on Android.
// See: https://github.com/w3c/manifest/issues/550
if (!manifest.scope.is_empty())
web_app_info->scope = manifest.scope;
else if (manifest.start_url.is_valid())
web_app_info->scope = manifest.start_url.Resolve(".");
if (for_installable_site == ForInstallableSite::kYes) {
// If there is no scope present, use 'start_url' without the filename as the
// scope. This does not match the spec but it matches what we do on Android.
// See: https://github.com/w3c/manifest/issues/550
if (!manifest.scope.is_empty())
web_app_info->scope = manifest.scope;
else if (manifest.start_url.is_valid())
web_app_info->scope = manifest.start_url.Resolve(".");
}
if (manifest.theme_color != content::Manifest::kInvalidOrMissingColor)
web_app_info->theme_color = static_cast<SkColor>(manifest.theme_color);
......@@ -595,7 +598,7 @@ void BookmarkAppHelper::Create(const CreateBookmarkAppCallback& callback) {
weak_factory_.GetWeakPtr()));
}
} else {
installable_ = INSTALLABLE_NO;
for_installable_site_ = ForInstallableSite::kNo;
OnIconsDownloaded(true, std::map<GURL, std::vector<SkBitmap>>());
}
}
......@@ -607,10 +610,12 @@ void BookmarkAppHelper::OnDidPerformInstallableCheck(
if (contents_->IsBeingDestroyed())
return;
installable_ =
data.error_code == NO_ERROR_DETECTED ? INSTALLABLE_YES : INSTALLABLE_NO;
for_installable_site_ = data.error_code == NO_ERROR_DETECTED
? ForInstallableSite::kYes
: ForInstallableSite::kNo;
UpdateWebAppInfoFromManifest(*data.manifest, &web_app_info_);
UpdateWebAppInfoFromManifest(*data.manifest, &web_app_info_,
for_installable_site_);
// TODO(mgiuca): Web Share Target should have its own flag, rather than using
// the experimental-web-platform-features flag. https://crbug.com/736178.
......@@ -716,7 +721,7 @@ void BookmarkAppHelper::OnIconsDownloaded(
}
if (base::FeatureList::IsEnabled(features::kDesktopPWAWindowing) &&
installable_ == INSTALLABLE_YES) {
for_installable_site_ == ForInstallableSite::kYes) {
web_app_info_.open_as_window = true;
chrome::ShowPWAInstallDialog(
contents_, web_app_info_,
......@@ -738,7 +743,7 @@ void BookmarkAppHelper::OnBubbleCompleted(
crx_installer_->InstallWebApp(web_app_info_);
if (InstallableMetrics::IsReportableInstallSource(install_source_) &&
installable_ == INSTALLABLE_YES) {
for_installable_site_ == ForInstallableSite::kYes) {
InstallableMetrics::TrackInstallEvent(install_source_);
}
} else {
......@@ -754,8 +759,8 @@ void BookmarkAppHelper::FinishInstallation(const Extension* extension) {
: extensions::LAUNCH_TYPE_REGULAR;
if (base::FeatureList::IsEnabled(features::kDesktopPWAWindowing)) {
DCHECK_NE(INSTALLABLE_UNKNOWN, installable_);
launch_type = installable_ == INSTALLABLE_YES
DCHECK_NE(ForInstallableSite::kUnknown, for_installable_site_);
launch_type = for_installable_site_ == ForInstallableSite::kYes
? extensions::LAUNCH_TYPE_WINDOW
: extensions::LAUNCH_TYPE_REGULAR;
}
......
......@@ -39,6 +39,12 @@ class Extension;
// A helper class for creating bookmark apps from a WebContents.
class BookmarkAppHelper : public content::NotificationObserver {
public:
enum class ForInstallableSite {
kYes,
kNo,
kUnknown,
};
struct BitmapAndSource {
BitmapAndSource();
BitmapAndSource(const GURL& source_url_p, const SkBitmap& bitmap_p);
......@@ -66,7 +72,8 @@ class BookmarkAppHelper : public content::NotificationObserver {
// Update the given WebApplicationInfo with information from the manifest.
static void UpdateWebAppInfoFromManifest(const content::Manifest& manifest,
WebApplicationInfo* web_app_info);
WebApplicationInfo* web_app_info,
ForInstallableSite installable_site);
// This finds the closest not-smaller bitmap in |bitmaps| for each size in
// |sizes| and resizes it to that size. This returns a map of sizes to bitmaps
......@@ -131,12 +138,6 @@ class BookmarkAppHelper : public content::NotificationObserver {
FRIEND_TEST_ALL_PREFIXES(BookmarkAppHelperTest,
CreateWindowedPWAIntoAppWindow);
enum Installable {
INSTALLABLE_YES,
INSTALLABLE_NO,
INSTALLABLE_UNKNOWN,
};
// Called after the bubble has been shown, and the user has either accepted or
// the dialog was dismissed.
void OnBubbleCompleted(bool user_accepted,
......@@ -170,7 +171,7 @@ class BookmarkAppHelper : public content::NotificationObserver {
InstallableManager* installable_manager_;
Installable installable_ = INSTALLABLE_UNKNOWN;
ForInstallableSite for_installable_site_ = ForInstallableSite::kUnknown;
// The mechanism via which the app creation was triggered.
WebappInstallSource install_source_;
......
......@@ -22,7 +22,7 @@ struct FaviconURL;
}
namespace extensions {
FORWARD_DECLARE_TEST(BookmarkAppHelperExtensionServiceTest,
FORWARD_DECLARE_TEST(BookmarkAppHelperExtensionServiceInstallableSiteTest,
CreateBookmarkAppWithManifestIcons);
}
......@@ -55,8 +55,9 @@ class FaviconDownloader : public content::WebContentsObserver {
private:
friend class TestFaviconDownloader;
FRIEND_TEST_ALL_PREFIXES(extensions::BookmarkAppHelperExtensionServiceTest,
CreateBookmarkAppWithManifestIcons);
FRIEND_TEST_ALL_PREFIXES(
extensions::BookmarkAppHelperExtensionServiceInstallableSiteTest,
CreateBookmarkAppWithManifestIcons);
// Initiates a download of the image at |url| and returns the download id.
// This is overridden in testing.
......
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