Commit 6dcbe653 authored by Ben Wells's avatar Ben Wells Committed by Commit Bot

Force bookmark apps that weren't locally installed to open in tabs.

This change causes all bookmark apps (including PWAs) which are not
marked as locally installed to always open in tabs. Apps are marked as
locally installed when they were not created on the machine but were
synced to the machine, unless the device is Chrome OS - where all apps
are marked as locally installed.

This change does not affect hosted apps.

Bug: 874841
Change-Id: Ia3936bb57e0fec94097fbf2925f676c97b703dc3
Reviewed-on: https://chromium-review.googlesource.com/1185336
Commit-Queue: Ben Wells <benwells@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585813}
parent 38b08485
......@@ -419,6 +419,18 @@ TEST_F(BookmarkAppHelperExtensionServiceTest,
EXPECT_TRUE(extension);
EXPECT_EQ(LAUNCH_CONTAINER_WINDOW,
GetLaunchContainer(ExtensionPrefs::Get(profile()), extension));
// Mark the app as not locally installed and check that it now opens in a
// tab.
SetBookmarkAppIsLocallyInstalled(profile(), extension, false);
EXPECT_EQ(LAUNCH_CONTAINER_TAB,
GetLaunchContainer(ExtensionPrefs::Get(profile()), extension));
// Mark the app as locally installed and check that it now opens in a
// window.
SetBookmarkAppIsLocallyInstalled(profile(), extension, true);
EXPECT_EQ(LAUNCH_CONTAINER_WINDOW,
GetLaunchContainer(ExtensionPrefs::Get(profile()), extension));
}
{
TestBookmarkAppHelper helper(service_, web_app_info, web_contents());
......
......@@ -11,6 +11,7 @@
#include "chrome/browser/extensions/extension_sync_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/extensions/bookmark_app_util.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "components/pref_registry/pref_registry_syncable.h"
......@@ -46,6 +47,12 @@ LaunchType GetLaunchType(const ExtensionPrefs* prefs,
if (value >= LAUNCH_TYPE_FIRST && value < NUM_LAUNCH_TYPES)
result = static_cast<LaunchType>(value);
// Force hosted apps that are not locally installed to open in tabs.
if (extension->is_hosted_app() &&
!BookmarkAppIsLocallyInstalled(prefs, extension)) {
result = LAUNCH_TYPE_REGULAR;
}
#if defined(OS_MACOSX)
// Disable opening as window on Mac if:
// 1. the extension isn't a platform app, AND
......
......@@ -34,9 +34,14 @@ void SetBookmarkAppIsLocallyInstalled(content::BrowserContext* context,
bool BookmarkAppIsLocallyInstalled(content::BrowserContext* context,
const Extension* extension) {
return BookmarkAppIsLocallyInstalled(ExtensionPrefs::Get(context), extension);
}
bool BookmarkAppIsLocallyInstalled(const ExtensionPrefs* prefs,
const Extension* extension) {
bool locally_installed;
if (ExtensionPrefs::Get(context)->ReadPrefAsBoolean(
extension->id(), kPrefLocallyInstalled, &locally_installed)) {
if (prefs->ReadPrefAsBoolean(extension->id(), kPrefLocallyInstalled,
&locally_installed)) {
return locally_installed;
}
......
......@@ -9,11 +9,13 @@ namespace content {
class BrowserContext;
}
class Extension;
class GURL;
namespace extensions {
class Extension;
class ExtensionPrefs;
// Sets an extension pref to indicate whether the hosted app is locally
// installed or not. When apps are not locally installed they will appear in the
// app launcher, but will act like normal web pages when launched. For example
......@@ -29,6 +31,8 @@ void SetBookmarkAppIsLocallyInstalled(content::BrowserContext* context,
// Note this can be called for hosted apps which should use the default.
bool BookmarkAppIsLocallyInstalled(content::BrowserContext* context,
const Extension* extension);
bool BookmarkAppIsLocallyInstalled(const ExtensionPrefs* prefs,
const Extension* extension);
// Returns true if a bookmark or hosted app from a given URL is already
// installed and enabled.
......
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