Skip to content

Commit

Permalink
iwa: Move IWA installer to //c/b/ui/views/web_apps
Browse files Browse the repository at this point in the history
This moves the installer from //chrome/browser/ui/web_applications/...
to //chrome/browser/ui/views/web_apps/isolated_web_apps/... The UI
needs to use several other classes from //chrome/browser/ui/views,
which isn't allowed from outside that directory. This moves the UI
to live alongside other PWA-related Views UIs. Initially triggering the
UI is tricky because we can't reference //c/b/ui/views code from other
directories, so this also defines a free function in
web_app_ui_manager_impl.h that's implemented in
isolated_web_app_installer_coordinator.cc to bridge the ui/views gap.

Bug: 1479140
Change-Id: I22f06142105d69901024939a63ec6820655e50aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4942645
Reviewed-by: Zelin Liu <zelin@chromium.org>
Reviewed-by: Dibyajyoti Pal <dibyapal@chromium.org>
Commit-Queue: Robbie McElrath <rmcelrath@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1211606}
  • Loading branch information
robbiemc authored and Chromium LUCI CQ committed Oct 18, 2023
1 parent e925f69 commit a9fa38a
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 57 deletions.
16 changes: 8 additions & 8 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5854,6 +5854,14 @@ static_library("ui") {
"views/web_apps/frame_toolbar/web_app_toolbar_button_container.h",
"views/web_apps/frame_toolbar/window_controls_overlay_toggle_button.cc",
"views/web_apps/frame_toolbar/window_controls_overlay_toggle_button.h",
"views/web_apps/isolated_web_apps/isolated_web_app_installer_coordinator.cc",
"views/web_apps/isolated_web_apps/isolated_web_app_installer_coordinator.h",
"views/web_apps/isolated_web_apps/isolated_web_app_installer_model.cc",
"views/web_apps/isolated_web_apps/isolated_web_app_installer_model.h",
"views/web_apps/isolated_web_apps/isolated_web_app_installer_view.cc",
"views/web_apps/isolated_web_apps/isolated_web_app_installer_view.h",
"views/web_apps/isolated_web_apps/isolated_web_app_installer_view_controller.cc",
"views/web_apps/isolated_web_apps/isolated_web_app_installer_view_controller.h",
"views/web_apps/launch_app_user_choice_dialog_view.cc",
"views/web_apps/launch_app_user_choice_dialog_view.h",
"views/web_apps/protocol_handler_launch_dialog_view.cc",
Expand Down Expand Up @@ -6330,14 +6338,6 @@ static_library("ui") {
"web_applications/diagnostics/web_app_icon_health_checks.h",
"web_applications/draggable_region_host_impl.cc",
"web_applications/draggable_region_host_impl.h",
"web_applications/isolated_web_apps/isolated_web_app_installer_coordinator.cc",
"web_applications/isolated_web_apps/isolated_web_app_installer_coordinator.h",
"web_applications/isolated_web_apps/isolated_web_app_installer_model.cc",
"web_applications/isolated_web_apps/isolated_web_app_installer_model.h",
"web_applications/isolated_web_apps/isolated_web_app_installer_view.cc",
"web_applications/isolated_web_apps/isolated_web_app_installer_view.h",
"web_applications/isolated_web_apps/isolated_web_app_installer_view_controller.cc",
"web_applications/isolated_web_apps/isolated_web_app_installer_view_controller.h",
"web_applications/share_target_utils.cc",
"web_applications/share_target_utils.h",
"web_applications/sub_apps_install_dialog_controller.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,35 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/web_applications/isolated_web_apps/isolated_web_app_installer_coordinator.h"
#include "chrome/browser/ui/views/web_apps/isolated_web_apps/isolated_web_app_installer_coordinator.h"

#include <memory>

#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/task/single_thread_task_runner.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/web_applications/isolated_web_apps/isolated_web_app_installer_model.h"
#include "chrome/browser/ui/web_applications/isolated_web_apps/isolated_web_app_installer_view_controller.h"
#include "chrome/browser/ui/views/web_apps/isolated_web_apps/isolated_web_app_installer_model.h"
#include "chrome/browser/ui/views/web_apps/isolated_web_apps/isolated_web_app_installer_view_controller.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "components/webapps/common/web_app_id.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

namespace web_app {

void LaunchIsolatedWebAppInstaller(Profile* profile,
const base::FilePath& bundle_path) {
auto coordinator = std::make_unique<IsolatedWebAppInstallerCoordinator>(
profile, bundle_path);
IsolatedWebAppInstallerCoordinator* raw_coordinator = coordinator.get();
base::OnceClosure delete_callback =
base::DoNothingWithBoundArgs(std::move(coordinator));
raw_coordinator->Show(base::IgnoreArgs<absl::optional<webapps::AppId>>(
std::move(delete_callback)));
}

IsolatedWebAppInstallerCoordinator::IsolatedWebAppInstallerCoordinator(
Profile* profile,
const base::FilePath& bundle_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEB_APPLICATIONS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_COORDINATOR_H_
#define CHROME_BROWSER_UI_WEB_APPLICATIONS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_COORDINATOR_H_
#ifndef CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_COORDINATOR_H_
#define CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_COORDINATOR_H_

#include <memory>

Expand Down Expand Up @@ -41,4 +41,4 @@ class IsolatedWebAppInstallerCoordinator {

} // namespace web_app

#endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_COORDINATOR_H_
#endif // CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_COORDINATOR_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/web_applications/isolated_web_apps/isolated_web_app_installer_model.h"
#include "chrome/browser/ui/views/web_apps/isolated_web_apps/isolated_web_app_installer_model.h"

#include <string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEB_APPLICATIONS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_MODEL_H_
#define CHROME_BROWSER_UI_WEB_APPLICATIONS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_MODEL_H_
#ifndef CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_MODEL_H_
#define CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_MODEL_H_

#include <string>

Expand Down Expand Up @@ -54,4 +54,4 @@ class IsolatedWebAppInstallerModel {

} // namespace web_app

#endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_MODEL_H_
#endif // CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_MODEL_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/web_applications/isolated_web_apps/isolated_web_app_installer_view.h"
#include "chrome/browser/ui/views/web_apps/isolated_web_apps/isolated_web_app_installer_view.h"

#include "chrome/browser/ui/web_applications/isolated_web_apps/isolated_web_app_installer_model.h"
#include "chrome/browser/ui/views/web_apps/isolated_web_apps/isolated_web_app_installer_model.h"
#include "chrome/browser/web_applications/isolated_web_apps/signed_web_bundle_metadata.h"
#include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEB_APPLICATIONS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_VIEW_H_
#define CHROME_BROWSER_UI_WEB_APPLICATIONS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_VIEW_H_
#ifndef CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_VIEW_H_

#include "base/memory/raw_ptr.h"
#include "chrome/browser/ui/web_applications/isolated_web_apps/isolated_web_app_installer_model.h"
#include "chrome/browser/ui/views/web_apps/isolated_web_apps/isolated_web_app_installer_model.h"
#include "chrome/browser/web_applications/isolated_web_apps/signed_web_bundle_metadata.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/layout/box_layout_view.h"
Expand Down Expand Up @@ -62,4 +62,4 @@ class IsolatedWebAppInstallerView : public views::BoxLayoutView {

} // namespace web_app

#endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_VIEW_H_
#endif // CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_VIEW_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/web_applications/isolated_web_apps/isolated_web_app_installer_view_controller.h"
#include "chrome/browser/ui/views/web_apps/isolated_web_apps/isolated_web_app_installer_view_controller.h"

#include <memory>

#include "base/functional/callback.h"
#include "base/logging.h"
#include "chrome/browser/ui/web_applications/isolated_web_apps/isolated_web_app_installer_model.h"
#include "chrome/browser/ui/web_applications/isolated_web_apps/isolated_web_app_installer_view.h"
#include "chrome/browser/ui/views/web_apps/isolated_web_apps/isolated_web_app_installer_model.h"
#include "chrome/browser/ui/views/web_apps/isolated_web_apps/isolated_web_app_installer_view.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/grit/generated_resources.h"
#include "components/webapps/common/web_app_id.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_WEB_APPLICATIONS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_VIEW_CONTROLLER_H_
#define CHROME_BROWSER_UI_WEB_APPLICATIONS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_VIEW_CONTROLLER_H_
#ifndef CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_VIEW_CONTROLLER_H_
#define CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_VIEW_CONTROLLER_H_

#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/web_applications/isolated_web_apps/isolated_web_app_installer_view.h"
#include "chrome/browser/ui/views/web_apps/isolated_web_apps/isolated_web_app_installer_view.h"

namespace views {
class DialogDelegate;
Expand Down Expand Up @@ -58,4 +58,4 @@ class IsolatedWebAppInstallerViewController

} // namespace web_app

#endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_VIEW_CONTROLLER_H_
#endif // CHROME_BROWSER_UI_VIEWS_WEB_APPS_ISOLATED_WEB_APPS_ISOLATED_WEB_APP_INSTALLER_VIEW_CONTROLLER_H_
4 changes: 4 additions & 0 deletions chrome/browser/ui/web_applications/web_app_dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ void ShowWebAppDetailedInstallDialog(
// user interaction.
void SetAutoAcceptPWAInstallConfirmationForTesting(bool auto_accept);

// Shows the Isolated Web App manual install wizard.
void LaunchIsolatedWebAppInstaller(Profile* profile,
const base::FilePath& bundle_path);

} // namespace web_app

#endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_WEB_APP_DIALOGS_H_
17 changes: 1 addition & 16 deletions chrome/browser/ui/web_applications/web_app_ui_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/browser/ui/web_applications/commands/launch_web_app_command.h"
#include "chrome/browser/ui/web_applications/isolated_web_apps/isolated_web_app_installer_coordinator.h"
#include "chrome/browser/ui/web_applications/web_app_dialog_utils.h"
#include "chrome/browser/ui/web_applications/web_app_dialogs.h"
#include "chrome/browser/ui/web_applications/web_app_launch_utils.h"
Expand Down Expand Up @@ -466,21 +465,7 @@ void WebAppUiManagerImpl::PresentUserUninstallDialog(

void WebAppUiManagerImpl::LaunchIsolatedWebAppInstaller(
const base::FilePath& bundle_path) {
auto installer = std::make_unique<IsolatedWebAppInstallerCoordinator>(
profile_, bundle_path);
IsolatedWebAppInstallerCoordinator* installer_ptr = installer.get();
isolated_web_app_installers_.insert(std::move(installer));

installer_ptr->Show(base::BindOnce(
&WebAppUiManagerImpl::OnIsolatedWebAppInstallerClosed,
weak_ptr_factory_.GetWeakPtr(), base::Unretained(installer_ptr)));
}

void WebAppUiManagerImpl::OnIsolatedWebAppInstallerClosed(
IsolatedWebAppInstallerCoordinator* installer,
absl::optional<webapps::AppId> result) {
isolated_web_app_installers_.erase(
isolated_web_app_installers_.find(installer));
::web_app::LaunchIsolatedWebAppInstaller(profile_, bundle_path);
}

void WebAppUiManagerImpl::OnBrowserAdded(Browser* browser) {
Expand Down
10 changes: 0 additions & 10 deletions chrome/browser/ui/web_applications/web_app_ui_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
#include <stddef.h>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>

#include "base/containers/unique_ptr_adapters.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
Expand Down Expand Up @@ -52,7 +50,6 @@ enum class WebappUninstallSource;
namespace web_app {

class AppLock;
class IsolatedWebAppInstallerCoordinator;

// Implementation of WebAppUiManager that depends upon //c/b/ui.
// Allows //c/b/web_applications code to call into //c/b/ui without directly
Expand Down Expand Up @@ -188,17 +185,10 @@ class WebAppUiManagerImpl : public BrowserListObserver, public WebAppUiManager {
UninstallCompleteCallback uninstall_complete_callback,
webapps::UninstallResultCode uninstall_code);

void OnIsolatedWebAppInstallerClosed(
IsolatedWebAppInstallerCoordinator* installer,
absl::optional<webapps::AppId> result);

const raw_ptr<Profile> profile_;
std::map<webapps::AppId, std::vector<base::OnceClosure>>
windows_closed_requests_map_;
std::map<webapps::AppId, size_t> num_windows_for_apps_map_;
std::set<std::unique_ptr<IsolatedWebAppInstallerCoordinator>,
base::UniquePtrComparator>
isolated_web_app_installers_;
bool started_ = false;

base::WeakPtrFactory<WebAppUiManagerImpl> weak_ptr_factory_{this};
Expand Down

0 comments on commit a9fa38a

Please sign in to comment.