Commit 75e9c9f1 authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

WebApp: Move out ReparentTab util to WebAppUiManager.

Delegate CanReparentAppTabToWindow/ReparentAppTabToWindow to
WebAppUiManager since this is UI-related business.

In next CLs:
We will get rid of chrome/browser/extensions/bookmark_app_extension_util.cc
completely. That's the last bookmark_app* prefixed file in extensions/.

TBR=ortuno@chromium.org

Bug: 901226
Change-Id: I1fb9658d0671d9ca9509280625911371aed95fd1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1732670Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683468}
parent 1d7d96a9
...@@ -4,56 +4,18 @@ ...@@ -4,56 +4,18 @@
#include "chrome/browser/extensions/bookmark_app_extension_util.h" #include "chrome/browser/extensions/bookmark_app_extension_util.h"
#include <utility>
#include "base/callback.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/extensions/application_launch.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/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/common/extension.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
#include "chrome/browser/web_applications/extensions/web_app_extension_shortcut_mac.h" #include "chrome/browser/web_applications/extensions/web_app_extension_shortcut_mac.h"
#include "chrome/common/chrome_switches.h"
#endif
#if defined(OS_CHROMEOS)
// gn check complains on Linux Ozone.
#include "ash/public/cpp/shelf_model.h" // nogncheck
#endif #endif
namespace extensions { namespace extensions {
bool CanBookmarkAppReparentTab(Profile* profile,
const Extension* extension,
bool shortcut_created) {
// Reparent the web contents into its own window only if that is the
// extension's launch type.
if (!extension ||
extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile),
extension) != extensions::LAUNCH_TYPE_WINDOW) {
return false;
}
#if defined(OS_MACOSX)
// On macOS it is only possible to reparent the window when the shortcut (app
// shim) was created. See https://crbug.com/915571.
return shortcut_created;
#else
return true;
#endif
}
void BookmarkAppReparentTab(content::WebContents* contents,
const std::string& app_id) {
// Reparent the tab into an app window immediately when opening as a window.
ReparentWebContentsIntoAppBrowser(contents, app_id);
}
bool CanBookmarkAppRevealAppShim() { bool CanBookmarkAppRevealAppShim() {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
return true; return true;
......
...@@ -5,26 +5,12 @@ ...@@ -5,26 +5,12 @@
#ifndef CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_EXTENSION_UTIL_H_ #ifndef CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_EXTENSION_UTIL_H_
#define CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_EXTENSION_UTIL_H_ #define CHROME_BROWSER_EXTENSIONS_BOOKMARK_APP_EXTENSION_UTIL_H_
#include <string>
#include "base/callback_forward.h"
class Profile; class Profile;
namespace content {
class WebContents;
}
namespace extensions { namespace extensions {
class Extension; class Extension;
bool CanBookmarkAppReparentTab(Profile* profile,
const Extension* extension,
bool shortcut_created);
void BookmarkAppReparentTab(content::WebContents* contents,
const std::string& app_id);
bool CanBookmarkAppRevealAppShim(); bool CanBookmarkAppRevealAppShim();
void BookmarkAppRevealAppShim(Profile* profile, const Extension* extension); void BookmarkAppRevealAppShim(Profile* profile, const Extension* extension);
......
...@@ -7,8 +7,10 @@ ...@@ -7,8 +7,10 @@
#include <utility> #include <utility>
#include "base/callback.h" #include "base/callback.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h" #include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/browser/ui/web_applications/web_app_dialog_manager.h" #include "chrome/browser/ui/web_applications/web_app_dialog_manager.h"
#include "chrome/browser/web_applications/system_web_app_manager.h" #include "chrome/browser/web_applications/system_web_app_manager.h"
...@@ -107,6 +109,26 @@ void WebAppUiManagerImpl::AddAppToQuickLaunchBar(const AppId& app_id) { ...@@ -107,6 +109,26 @@ void WebAppUiManagerImpl::AddAppToQuickLaunchBar(const AppId& app_id) {
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
} }
bool WebAppUiManagerImpl::CanReparentAppTabToWindow(
const AppId& app_id,
bool shortcut_created) const {
#if defined(OS_MACOSX)
// On macOS it is only possible to reparent the window when the shortcut (app
// shim) was created. See https://crbug.com/915571.
return shortcut_created;
#else
return true;
#endif
}
void WebAppUiManagerImpl::ReparentAppTabToWindow(content::WebContents* contents,
const AppId& app_id,
bool shortcut_created) {
DCHECK(CanReparentAppTabToWindow(app_id, shortcut_created));
// Reparent the tab into an app window immediately.
ReparentWebContentsIntoAppBrowser(contents, app_id);
}
void WebAppUiManagerImpl::OnBrowserAdded(Browser* browser) { void WebAppUiManagerImpl::OnBrowserAdded(Browser* browser) {
base::Optional<AppId> app_id = GetAppIdForBrowser(browser); base::Optional<AppId> app_id = GetAppIdForBrowser(browser);
if (!app_id.has_value()) if (!app_id.has_value())
......
...@@ -42,6 +42,11 @@ class WebAppUiManagerImpl : public BrowserListObserver, public WebAppUiManager { ...@@ -42,6 +42,11 @@ class WebAppUiManagerImpl : public BrowserListObserver, public WebAppUiManager {
void MigrateOSAttributes(const AppId& from, const AppId& to) override; void MigrateOSAttributes(const AppId& from, const AppId& to) override;
bool CanAddAppToQuickLaunchBar() const override; bool CanAddAppToQuickLaunchBar() const override;
void AddAppToQuickLaunchBar(const AppId& app_id) override; void AddAppToQuickLaunchBar(const AppId& app_id) override;
bool CanReparentAppTabToWindow(const AppId& app_id,
bool shortcut_created) const override;
void ReparentAppTabToWindow(content::WebContents* contents,
const AppId& app_id,
bool shortcut_created) override;
// BrowserListObserver: // BrowserListObserver:
void OnBrowserAdded(Browser* browser) override; void OnBrowserAdded(Browser* browser) override;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/web_applications/components/install_finalizer.h" #include "chrome/browser/web_applications/components/install_finalizer.h"
#include "base/logging.h"
#include "chrome/browser/web_applications/components/web_app_ui_manager.h" #include "chrome/browser/web_applications/components/web_app_ui_manager.h"
namespace web_app { namespace web_app {
...@@ -20,4 +21,17 @@ void InstallFinalizer::AddAppToQuickLaunchBar(const AppId& app_id) { ...@@ -20,4 +21,17 @@ void InstallFinalizer::AddAppToQuickLaunchBar(const AppId& app_id) {
ui_manager().AddAppToQuickLaunchBar(app_id); ui_manager().AddAppToQuickLaunchBar(app_id);
} }
bool InstallFinalizer::CanReparentTab(const AppId& app_id,
bool shortcut_created) const {
return ui_manager().CanReparentAppTabToWindow(app_id, shortcut_created);
}
void InstallFinalizer::ReparentTab(const AppId& app_id,
bool shortcut_created,
content::WebContents* web_contents) {
DCHECK(web_contents);
return ui_manager().ReparentAppTabToWindow(web_contents, app_id,
shortcut_created);
}
} // namespace web_app } // namespace web_app
...@@ -64,10 +64,10 @@ class InstallFinalizer { ...@@ -64,10 +64,10 @@ class InstallFinalizer {
virtual bool CanAddAppToQuickLaunchBar() const; virtual bool CanAddAppToQuickLaunchBar() const;
virtual void AddAppToQuickLaunchBar(const AppId& app_id); virtual void AddAppToQuickLaunchBar(const AppId& app_id);
virtual bool CanReparentTab(const AppId& app_id, virtual bool CanReparentTab(const AppId& app_id, bool shortcut_created) const;
bool shortcut_created) const = 0;
virtual void ReparentTab(const AppId& app_id, virtual void ReparentTab(const AppId& app_id,
content::WebContents* web_contents) = 0; bool shortcut_created,
content::WebContents* web_contents);
virtual bool CanRevealAppShim() const = 0; virtual bool CanRevealAppShim() const = 0;
virtual void RevealAppShim(const AppId& app_id) = 0; virtual void RevealAppShim(const AppId& app_id) = 0;
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
class Profile; class Profile;
namespace content {
class WebContents;
}
namespace web_app { namespace web_app {
// WebAppUiManagerImpl can be used only in UI code. // WebAppUiManagerImpl can be used only in UI code.
...@@ -37,6 +41,12 @@ class WebAppUiManager { ...@@ -37,6 +41,12 @@ class WebAppUiManager {
virtual bool CanAddAppToQuickLaunchBar() const = 0; virtual bool CanAddAppToQuickLaunchBar() const = 0;
virtual void AddAppToQuickLaunchBar(const AppId& app_id) = 0; virtual void AddAppToQuickLaunchBar(const AppId& app_id) = 0;
virtual bool CanReparentAppTabToWindow(const AppId& app_id,
bool shortcut_created) const = 0;
virtual void ReparentAppTabToWindow(content::WebContents* contents,
const AppId& app_id,
bool shortcut_created) = 0;
}; };
} // namespace web_app } // namespace web_app
......
...@@ -208,15 +208,15 @@ void BookmarkAppInstallFinalizer::CreateOsShortcuts( ...@@ -208,15 +208,15 @@ void BookmarkAppInstallFinalizer::CreateOsShortcuts(
bool BookmarkAppInstallFinalizer::CanReparentTab(const web_app::AppId& app_id, bool BookmarkAppInstallFinalizer::CanReparentTab(const web_app::AppId& app_id,
bool shortcut_created) const { bool shortcut_created) const {
const Extension* app = GetExtensionById(profile_, app_id); const Extension* app = GetExtensionById(profile_, app_id);
return CanBookmarkAppReparentTab(profile_, app, shortcut_created); // Reparent the web contents into its own window only if that is the
} // app's launch type.
if (!app ||
extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile_),
app) != extensions::LAUNCH_TYPE_WINDOW) {
return false;
}
void BookmarkAppInstallFinalizer::ReparentTab( return InstallFinalizer::CanReparentTab(app_id, shortcut_created);
const web_app::AppId& app_id,
content::WebContents* web_contents) {
DCHECK(web_contents);
DCHECK(!profile_->IsOffTheRecord());
BookmarkAppReparentTab(web_contents, app_id);
} }
bool BookmarkAppInstallFinalizer::CanRevealAppShim() const { bool BookmarkAppInstallFinalizer::CanRevealAppShim() const {
......
...@@ -39,8 +39,6 @@ class BookmarkAppInstallFinalizer : public web_app::InstallFinalizer { ...@@ -39,8 +39,6 @@ class BookmarkAppInstallFinalizer : public web_app::InstallFinalizer {
CreateOsShortcutsCallback callback) override; CreateOsShortcutsCallback callback) override;
bool CanReparentTab(const web_app::AppId& app_id, bool CanReparentTab(const web_app::AppId& app_id,
bool shortcut_created) const override; bool shortcut_created) const override;
void ReparentTab(const web_app::AppId& app_id,
content::WebContents* web_contents) override;
bool CanRevealAppShim() const override; bool CanRevealAppShim() const override;
void RevealAppShim(const web_app::AppId& app_id) override; void RevealAppShim(const web_app::AppId& app_id) override;
bool CanSkipAppUpdateForSync( bool CanSkipAppUpdateForSync(
......
...@@ -108,6 +108,7 @@ class BookmarkAppInstallFinalizerInstallOnly ...@@ -108,6 +108,7 @@ class BookmarkAppInstallFinalizerInstallOnly
} }
void AddAppToQuickLaunchBar(const web_app::AppId& app_id) override {} void AddAppToQuickLaunchBar(const web_app::AppId& app_id) override {}
void ReparentTab(const web_app::AppId& app_id, void ReparentTab(const web_app::AppId& app_id,
bool shortcut_created,
content::WebContents* web_contents) override {} content::WebContents* web_contents) override {}
void RevealAppShim(const web_app::AppId& app_id) override {} void RevealAppShim(const web_app::AppId& app_id) override {}
}; };
......
...@@ -218,6 +218,7 @@ class TestPendingAppInstallFinalizer : public InstallFinalizer { ...@@ -218,6 +218,7 @@ class TestPendingAppInstallFinalizer : public InstallFinalizer {
} }
void ReparentTab(const AppId& app_id, void ReparentTab(const AppId& app_id,
bool shortcut_created,
content::WebContents* web_contents) override { content::WebContents* web_contents) override {
++num_reparent_tab_calls_; ++num_reparent_tab_calls_;
} }
......
...@@ -93,6 +93,7 @@ bool TestInstallFinalizer::CanReparentTab(const AppId& app_id, ...@@ -93,6 +93,7 @@ bool TestInstallFinalizer::CanReparentTab(const AppId& app_id,
} }
void TestInstallFinalizer::ReparentTab(const AppId& app_id, void TestInstallFinalizer::ReparentTab(const AppId& app_id,
bool shortcut_created,
content::WebContents* web_contents) { content::WebContents* web_contents) {
++num_reparent_tab_calls_; ++num_reparent_tab_calls_;
} }
......
...@@ -40,6 +40,7 @@ class TestInstallFinalizer final : public InstallFinalizer { ...@@ -40,6 +40,7 @@ class TestInstallFinalizer final : public InstallFinalizer {
bool CanReparentTab(const AppId& app_id, bool CanReparentTab(const AppId& app_id,
bool shortcut_created) const override; bool shortcut_created) const override;
void ReparentTab(const AppId& app_id, void ReparentTab(const AppId& app_id,
bool shortcut_created,
content::WebContents* web_contents) override; content::WebContents* web_contents) override;
bool CanRevealAppShim() const override; bool CanRevealAppShim() const override;
void RevealAppShim(const AppId& app_id) override; void RevealAppShim(const AppId& app_id) override;
......
...@@ -51,4 +51,14 @@ bool TestWebAppUiManager::CanAddAppToQuickLaunchBar() const { ...@@ -51,4 +51,14 @@ bool TestWebAppUiManager::CanAddAppToQuickLaunchBar() const {
void TestWebAppUiManager::AddAppToQuickLaunchBar(const AppId& app_id) {} void TestWebAppUiManager::AddAppToQuickLaunchBar(const AppId& app_id) {}
bool TestWebAppUiManager::CanReparentAppTabToWindow(
const AppId& app_id,
bool shortcut_created) const {
return false;
}
void TestWebAppUiManager::ReparentAppTabToWindow(content::WebContents* contents,
const AppId& app_id,
bool shortcut_created) {}
} // namespace web_app } // namespace web_app
...@@ -27,6 +27,11 @@ class TestWebAppUiManager : public WebAppUiManager { ...@@ -27,6 +27,11 @@ class TestWebAppUiManager : public WebAppUiManager {
void MigrateOSAttributes(const AppId& from, const AppId& to) override; void MigrateOSAttributes(const AppId& from, const AppId& to) override;
bool CanAddAppToQuickLaunchBar() const override; bool CanAddAppToQuickLaunchBar() const override;
void AddAppToQuickLaunchBar(const AppId& app_id) override; void AddAppToQuickLaunchBar(const AppId& app_id) override;
bool CanReparentAppTabToWindow(const AppId& app_id,
bool shortcut_created) const override;
void ReparentAppTabToWindow(content::WebContents* contents,
const AppId& app_id,
bool shortcut_created) override;
private: private:
std::map<AppId, size_t> app_id_to_num_windows_map_; std::map<AppId, size_t> app_id_to_num_windows_map_;
......
...@@ -122,15 +122,9 @@ void WebAppInstallFinalizer::CreateOsShortcuts( ...@@ -122,15 +122,9 @@ void WebAppInstallFinalizer::CreateOsShortcuts(
bool WebAppInstallFinalizer::CanReparentTab(const AppId& app_id, bool WebAppInstallFinalizer::CanReparentTab(const AppId& app_id,
bool shortcut_created) const { bool shortcut_created) const {
// TODO(loyso): Implement it. // TODO(loyso): Return false here if the app's launch container is not
NOTIMPLEMENTED(); // kWindow.
return true; return InstallFinalizer::CanReparentTab(app_id, shortcut_created);
}
void WebAppInstallFinalizer::ReparentTab(const AppId& app_id,
content::WebContents* web_contents) {
// TODO(loyso): Implement it.
NOTIMPLEMENTED();
} }
bool WebAppInstallFinalizer::CanRevealAppShim() const { bool WebAppInstallFinalizer::CanRevealAppShim() const {
......
...@@ -38,8 +38,6 @@ class WebAppInstallFinalizer final : public InstallFinalizer { ...@@ -38,8 +38,6 @@ class WebAppInstallFinalizer final : public InstallFinalizer {
CreateOsShortcutsCallback callback) override; CreateOsShortcutsCallback callback) override;
bool CanReparentTab(const AppId& app_id, bool CanReparentTab(const AppId& app_id,
bool shortcut_created) const override; bool shortcut_created) const override;
void ReparentTab(const AppId& app_id,
content::WebContents* web_contents) override;
bool CanRevealAppShim() const override; bool CanRevealAppShim() const override;
void RevealAppShim(const AppId& app_id) override; void RevealAppShim(const AppId& app_id) override;
bool CanSkipAppUpdateForSync( bool CanSkipAppUpdateForSync(
......
...@@ -547,16 +547,16 @@ void WebAppInstallTask::OnShortcutsCreated( ...@@ -547,16 +547,16 @@ void WebAppInstallTask::OnShortcutsCreated(
add_to_quick_launch_bar = install_params_->add_to_quick_launch_bar; add_to_quick_launch_bar = install_params_->add_to_quick_launch_bar;
if (add_to_quick_launch_bar && if (add_to_quick_launch_bar &&
install_finalizer_->CanAddAppToQuickLaunchBar()) install_finalizer_->CanAddAppToQuickLaunchBar()) {
install_finalizer_->AddAppToQuickLaunchBar(app_id); install_finalizer_->AddAppToQuickLaunchBar(app_id);
}
// TODO(loyso): Reparenting must be implemented in
// chrome/browser/ui/web_applications/ UI layer as a post-install step.
if (!background_installation_) { if (!background_installation_) {
const bool can_reparent_tab = const bool can_reparent_tab =
install_finalizer_->CanReparentTab(app_id, shortcut_created); install_finalizer_->CanReparentTab(app_id, shortcut_created);
if (can_reparent_tab && web_app_info->open_as_window) if (can_reparent_tab && web_app_info->open_as_window)
install_finalizer_->ReparentTab(app_id, web_contents()); install_finalizer_->ReparentTab(app_id, shortcut_created, web_contents());
// TODO(loyso): Make revealing app shim independent from CanReparentTab. // TODO(loyso): Make revealing app shim independent from CanReparentTab.
if (can_reparent_tab && install_finalizer_->CanRevealAppShim()) if (can_reparent_tab && install_finalizer_->CanRevealAppShim())
......
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