Commit ad7f9d20 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

MacPWAs BMO: Remove some uses of extensions::Extension

The general plan here is to make ExtensionAppShimHandler not know
about extensions, but be able to interact with either apps or
extensions via its ExtensionAppShimHandler::Delegate interface.

To this end, start changing the interface to take app ids instead of
extensions::Extensions. Most of this is mechanical, but a few
aren't quite:
* The Delegate::GetWindows method can't return an extensions type
  anymore, so inline its usage into new ShowAppWindows and
  CloseAppWindows methods (which, internally, will be able to).
* Remove RequestUserAttentionForWindow, and have the caller (which
  is extensions-based app code) make the appropriate calls.

Update tests to behave reasonably.

Bug: 1057195
Change-Id: Ife8f37b608a9a601eafd38da44c2ad50b99f41c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2080487Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarccameron <ccameron@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746502}
parent 346ef5e4
...@@ -35,7 +35,6 @@ class BrowserContext; ...@@ -35,7 +35,6 @@ class BrowserContext;
} // namespace content } // namespace content
namespace extensions { namespace extensions {
class AppWindow;
class Extension; class Extension;
} // namespace extensions } // namespace extensions
...@@ -65,10 +64,12 @@ class ExtensionAppShimHandler : public AppShimHostBootstrap::Client, ...@@ -65,10 +64,12 @@ class ExtensionAppShimHandler : public AppShimHostBootstrap::Client,
// locked. // locked.
virtual bool IsProfileLockedForPath(const base::FilePath& path); virtual bool IsProfileLockedForPath(const base::FilePath& path);
// Return the app windows (not browser windows) for a legacy app. // Show all app windows (for non-PWA apps). Return true if there existed any
virtual extensions::AppWindowRegistry::AppWindowList GetWindows( // windows.
Profile* profile, virtual bool ShowAppWindows(Profile* profile, const std::string& app_id);
const std::string& extension_id);
// Close all app windows (for non-PWA apps).
virtual void CloseAppWindows(Profile* profile, const std::string& app_id);
// Look up an extension from its id. // Look up an extension from its id.
virtual const extensions::Extension* MaybeGetAppExtension( virtual const extensions::Extension* MaybeGetAppExtension(
...@@ -78,7 +79,7 @@ class ExtensionAppShimHandler : public AppShimHostBootstrap::Client, ...@@ -78,7 +79,7 @@ class ExtensionAppShimHandler : public AppShimHostBootstrap::Client,
// Return true if the specified app should use an app shim (false, e.g, for // Return true if the specified app should use an app shim (false, e.g, for
// bookmark apps that open in tabs). // bookmark apps that open in tabs).
virtual bool AllowShimToConnect(Profile* profile, virtual bool AllowShimToConnect(Profile* profile,
const extensions::Extension* extension); const std::string& app_id);
// Create an AppShimHost for the specified parameters (intercept-able for // Create an AppShimHost for the specified parameters (intercept-able for
// tests). // tests).
...@@ -96,7 +97,7 @@ class ExtensionAppShimHandler : public AppShimHostBootstrap::Client, ...@@ -96,7 +97,7 @@ class ExtensionAppShimHandler : public AppShimHostBootstrap::Client,
// Launch the app in Chrome. This will (often) create a new window. // Launch the app in Chrome. This will (often) create a new window.
virtual void LaunchApp(Profile* profile, virtual void LaunchApp(Profile* profile,
const extensions::Extension* extension, const std::string& app_id,
const std::vector<base::FilePath>& files); const std::vector<base::FilePath>& files);
// Open the specified URL in a new Chrome window. This is the fallback when // Open the specified URL in a new Chrome window. This is the fallback when
...@@ -108,7 +109,7 @@ class ExtensionAppShimHandler : public AppShimHostBootstrap::Client, ...@@ -108,7 +109,7 @@ class ExtensionAppShimHandler : public AppShimHostBootstrap::Client,
// Launch the shim process for an app. // Launch the shim process for an app.
virtual void LaunchShim(Profile* profile, virtual void LaunchShim(Profile* profile,
const extensions::Extension* extension, const std::string& app_id,
bool recreate_shims, bool recreate_shims,
ShimLaunchedCallback launched_callback, ShimLaunchedCallback launched_callback,
ShimTerminatedCallback terminated_callback); ShimTerminatedCallback terminated_callback);
...@@ -145,12 +146,6 @@ class ExtensionAppShimHandler : public AppShimHostBootstrap::Client, ...@@ -145,12 +146,6 @@ class ExtensionAppShimHandler : public AppShimHostBootstrap::Client,
static const extensions::Extension* MaybeGetAppForBrowser(Browser* browser); static const extensions::Extension* MaybeGetAppForBrowser(Browser* browser);
// Instructs the shim to request user attention. Returns false if there is no
// shim for this window.
void RequestUserAttentionForWindow(
extensions::AppWindow* app_window,
chrome::mojom::AppShimAttentionType attention_type);
// AppShimHostBootstrap::Client: // AppShimHostBootstrap::Client:
void OnShimProcessConnected( void OnShimProcessConnected(
std::unique_ptr<AppShimHostBootstrap> bootstrap) override; std::unique_ptr<AppShimHostBootstrap> bootstrap) override;
...@@ -250,14 +245,12 @@ class ExtensionAppShimHandler : public AppShimHostBootstrap::Client, ...@@ -250,14 +245,12 @@ class ExtensionAppShimHandler : public AppShimHostBootstrap::Client,
std::unique_ptr<AppShimHostBootstrap> bootstrap); std::unique_ptr<AppShimHostBootstrap> bootstrap);
// Continuation of OnShimSelectedProfile, once the profile has loaded. // Continuation of OnShimSelectedProfile, once the profile has loaded.
void OnShimSelectedProfileAndAppLoaded( void OnShimSelectedProfileAndAppLoaded(const std::string& app_id,
Profile* profile, Profile* profile);
const extensions::Extension* extension);
// Load the specified profile and extension, and run |callback| with // Load the specified profile and extension, and run |callback| with
// the result. The callback's arguments may be nullptr on failure. // the result. The callback's arguments may be nullptr on failure.
using LoadProfileAppCallback = using LoadProfileAppCallback = base::OnceCallback<void(Profile*)>;
base::OnceCallback<void(Profile*, const extensions::Extension*)>;
void LoadProfileAndApp(const base::FilePath& profile_path, void LoadProfileAndApp(const base::FilePath& profile_path,
const std::string& app_id, const std::string& app_id,
LoadProfileAppCallback callback); LoadProfileAppCallback callback);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import "base/mac/scoped_nsobject.h" #import "base/mac/scoped_nsobject.h"
#include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h" #include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h"
#include "chrome/browser/profiles/profile.h"
#import "chrome/browser/ui/views/apps/app_window_native_widget_mac.h" #import "chrome/browser/ui/views/apps/app_window_native_widget_mac.h"
#import "chrome/browser/ui/views/apps/native_app_window_frame_view_mac.h" #import "chrome/browser/ui/views/apps/native_app_window_frame_view_mac.h"
#import "ui/gfx/mac/coordinate_conversion.h" #import "ui/gfx/mac/coordinate_conversion.h"
...@@ -165,9 +166,15 @@ void ChromeNativeAppWindowViewsMac::Restore() { ...@@ -165,9 +166,15 @@ void ChromeNativeAppWindowViewsMac::Restore() {
} }
void ChromeNativeAppWindowViewsMac::FlashFrame(bool flash) { void ChromeNativeAppWindowViewsMac::FlashFrame(bool flash) {
apps::ExtensionAppShimHandler::Get()->RequestUserAttentionForWindow( Profile* profile =
app_window(), flash ? chrome::mojom::AppShimAttentionType::kCritical Profile::FromBrowserContext(app_window()->browser_context());
: chrome::mojom::AppShimAttentionType::kCancel); AppShimHost* shim_host = apps::ExtensionAppShimHandler::Get()->FindHost(
profile, app_window()->extension_id());
if (!shim_host)
return;
shim_host->GetAppShim()->SetUserAttention(
flash ? chrome::mojom::AppShimAttentionType::kCritical
: chrome::mojom::AppShimAttentionType::kCancel);
} }
void ChromeNativeAppWindowViewsMac::OnWidgetCreated(views::Widget* widget) { void ChromeNativeAppWindowViewsMac::OnWidgetCreated(views::Widget* widget) {
......
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