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