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
...@@ -69,7 +69,6 @@ ...@@ -69,7 +69,6 @@
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "ui/base/cocoa/focus_window_set.h" #include "ui/base/cocoa/focus_window_set.h"
using extensions::AppWindow;
using extensions::AppWindowRegistry; using extensions::AppWindowRegistry;
using extensions::Extension; using extensions::Extension;
using extensions::ExtensionRegistry; using extensions::ExtensionRegistry;
...@@ -311,10 +310,27 @@ bool ExtensionAppShimHandler::Delegate::IsProfileLockedForPath( ...@@ -311,10 +310,27 @@ bool ExtensionAppShimHandler::Delegate::IsProfileLockedForPath(
return profiles::IsProfileLocked(full_path); return profiles::IsProfileLocked(full_path);
} }
AppWindowList ExtensionAppShimHandler::Delegate::GetWindows( bool ExtensionAppShimHandler::Delegate::ShowAppWindows(
Profile* profile, Profile* profile,
const std::string& extension_id) { const std::string& app_id) {
return AppWindowRegistry::Get(profile)->GetAppWindowsForApp(extension_id); AppWindowList windows =
AppWindowRegistry::Get(profile)->GetAppWindowsForApp(app_id);
for (auto it = windows.rbegin(); it != windows.rend(); ++it) {
if (*it)
(*it)->GetBaseWindow()->Show();
}
return !windows.empty();
}
void ExtensionAppShimHandler::Delegate::CloseAppWindows(
Profile* profile,
const std::string& app_id) {
AppWindowList windows =
AppWindowRegistry::Get(profile)->GetAppWindowsForApp(app_id);
for (auto it = windows.begin(); it != windows.end(); ++it) {
if (*it)
(*it)->GetBaseWindow()->Close();
}
} }
const Extension* ExtensionAppShimHandler::Delegate::MaybeGetAppExtension( const Extension* ExtensionAppShimHandler::Delegate::MaybeGetAppExtension(
...@@ -325,7 +341,8 @@ const Extension* ExtensionAppShimHandler::Delegate::MaybeGetAppExtension( ...@@ -325,7 +341,8 @@ const Extension* ExtensionAppShimHandler::Delegate::MaybeGetAppExtension(
bool ExtensionAppShimHandler::Delegate::AllowShimToConnect( bool ExtensionAppShimHandler::Delegate::AllowShimToConnect(
Profile* profile, Profile* profile,
const extensions::Extension* extension) { const std::string& app_id) {
const Extension* extension = MaybeGetAppExtension(profile, app_id);
if (!profile || !extension) if (!profile || !extension)
return false; return false;
if (extension->is_hosted_app() && if (extension->is_hosted_app() &&
...@@ -349,15 +366,22 @@ std::unique_ptr<AppShimHost> ExtensionAppShimHandler::Delegate::CreateHost( ...@@ -349,15 +366,22 @@ std::unique_ptr<AppShimHost> ExtensionAppShimHandler::Delegate::CreateHost(
void ExtensionAppShimHandler::Delegate::EnableExtension( void ExtensionAppShimHandler::Delegate::EnableExtension(
Profile* profile, Profile* profile,
const std::string& extension_id, const std::string& app_id,
base::OnceCallback<void()> callback) { base::OnceCallback<void()> callback) {
(new EnableViaPrompt(profile, extension_id, std::move(callback)))->Run(); const Extension* extension = MaybeGetAppExtension(profile, app_id);
if (extension)
std::move(callback).Run();
else
(new EnableViaPrompt(profile, app_id, std::move(callback)))->Run();
} }
void ExtensionAppShimHandler::Delegate::LaunchApp( void ExtensionAppShimHandler::Delegate::LaunchApp(
Profile* profile, Profile* profile,
const Extension* extension, const std::string& app_id,
const std::vector<base::FilePath>& files) { const std::vector<base::FilePath>& files) {
const extensions::Extension* extension =
MaybeGetAppExtension(profile, app_id);
DCHECK(extension);
extensions::RecordAppLaunchType( extensions::RecordAppLaunchType(
extension_misc::APP_LAUNCH_CMD_LINE_APP, extension->GetType()); extension_misc::APP_LAUNCH_CMD_LINE_APP, extension->GetType());
if (extension->is_hosted_app()) { if (extension->is_hosted_app()) {
...@@ -399,10 +423,16 @@ void ExtensionAppShimHandler::Delegate::OpenAppURLInBrowserWindow( ...@@ -399,10 +423,16 @@ void ExtensionAppShimHandler::Delegate::OpenAppURLInBrowserWindow(
void ExtensionAppShimHandler::Delegate::LaunchShim( void ExtensionAppShimHandler::Delegate::LaunchShim(
Profile* profile, Profile* profile,
const Extension* extension, const std::string& app_id,
bool recreate_shims, bool recreate_shims,
apps::ShimLaunchedCallback launched_callback, apps::ShimLaunchedCallback launched_callback,
apps::ShimTerminatedCallback terminated_callback) { apps::ShimTerminatedCallback terminated_callback) {
const Extension* extension = MaybeGetAppExtension(profile, app_id);
if (!extension) {
std::move(launched_callback).Run(base::Process());
return;
}
// Only force recreation of shims when RemoteViews is in use (that is, for // Only force recreation of shims when RemoteViews is in use (that is, for
// PWAs). Otherwise, shims may be created unexpectedly. // PWAs). Otherwise, shims may be created unexpectedly.
// https://crbug.com/941160 // https://crbug.com/941160
...@@ -502,15 +532,6 @@ const Extension* ExtensionAppShimHandler::MaybeGetAppForBrowser( ...@@ -502,15 +532,6 @@ const Extension* ExtensionAppShimHandler::MaybeGetAppForBrowser(
web_app::GetAppIdFromApplicationName(browser->app_name())); web_app::GetAppIdFromApplicationName(browser->app_name()));
} }
void ExtensionAppShimHandler::RequestUserAttentionForWindow(
AppWindow* app_window,
chrome::mojom::AppShimAttentionType attention_type) {
Profile* profile = Profile::FromBrowserContext(app_window->browser_context());
AppShimHost* host = FindHost(profile, app_window->extension_id());
if (host && !host->UsesRemoteViews())
host->GetAppShim()->SetUserAttention(attention_type);
}
void ExtensionAppShimHandler::OnShimLaunchRequested( void ExtensionAppShimHandler::OnShimLaunchRequested(
AppShimHost* host, AppShimHost* host,
bool recreate_shims, bool recreate_shims,
...@@ -531,16 +552,7 @@ void ExtensionAppShimHandler::OnShimLaunchRequested( ...@@ -531,16 +552,7 @@ void ExtensionAppShimHandler::OnShimLaunchRequested(
profile = delegate_->ProfileForPath(host->GetProfilePath()); profile = delegate_->ProfileForPath(host->GetProfilePath());
} }
} }
delegate_->LaunchShim(profile, host->GetAppId(), recreate_shims,
const Extension* extension =
delegate_->MaybeGetAppExtension(profile, host->GetAppId());
if (!profile || !extension) {
// If the profile or extension has been unloaded, indicate that the launch
// failed. This will close the AppShimHost eventually, if appropriate.
std::move(launched_callback).Run(base::Process());
return;
}
delegate_->LaunchShim(profile, extension, recreate_shims,
std::move(launched_callback), std::move(launched_callback),
std::move(terminated_callback)); std::move(terminated_callback));
} }
...@@ -569,7 +581,7 @@ void ExtensionAppShimHandler::OnShimProcessConnectedForRegisterOnly( ...@@ -569,7 +581,7 @@ void ExtensionAppShimHandler::OnShimProcessConnectedForRegisterOnly(
// exit), but many tests assume this behavior, and need to be updated. // exit), but many tests assume this behavior, and need to be updated.
Profile* profile = delegate_->ProfileForPath(bootstrap->GetProfilePath()); Profile* profile = delegate_->ProfileForPath(bootstrap->GetProfilePath());
const Extension* extension = delegate_->MaybeGetAppExtension(profile, app_id); const Extension* extension = delegate_->MaybeGetAppExtension(profile, app_id);
if (profile && extension && delegate_->AllowShimToConnect(profile, extension)) if (profile && extension && delegate_->AllowShimToConnect(profile, app_id))
GetOrCreateProfileState(profile, extension); GetOrCreateProfileState(profile, extension);
// Because this was a register-only launch, it must have been launched by // Because this was a register-only launch, it must have been launched by
...@@ -637,11 +649,9 @@ void ExtensionAppShimHandler::OnShimProcessConnectedForLaunch( ...@@ -637,11 +649,9 @@ void ExtensionAppShimHandler::OnShimProcessConnectedForLaunch(
for (const auto& profile_path : profile_paths_to_launch) { for (const auto& profile_path : profile_paths_to_launch) {
if (profile_path.empty()) if (profile_path.empty())
continue; continue;
LoadProfileAppCallback callback_wrapped = base::BindOnce( LoadProfileAppCallback callback_wrapped =
[](base::OnceClosure callback_to_wrap, Profile*, base::BindOnce([](base::OnceClosure callback_to_wrap,
const extensions::Extension*) { Profile*) { std::move(callback_to_wrap).Run(); },
std::move(callback_to_wrap).Run();
},
std::move(callback)); std::move(callback));
callback = base::BindOnce(&ExtensionAppShimHandler::LoadProfileAndApp, callback = base::BindOnce(&ExtensionAppShimHandler::LoadProfileAndApp,
weak_factory_.GetWeakPtr(), profile_path, weak_factory_.GetWeakPtr(), profile_path,
...@@ -689,7 +699,7 @@ void ExtensionAppShimHandler::OnShimProcessConnectedAndProfilesToLaunchLoaded( ...@@ -689,7 +699,7 @@ void ExtensionAppShimHandler::OnShimProcessConnectedAndProfilesToLaunchLoaded(
// Create a ProfileState for this app, if appropriate (e.g, not for // Create a ProfileState for this app, if appropriate (e.g, not for
// open-in-a-tab bookmark apps). // open-in-a-tab bookmark apps).
ProfileState* profile_state = nullptr; ProfileState* profile_state = nullptr;
if (delegate_->AllowShimToConnect(profile, extension)) if (delegate_->AllowShimToConnect(profile, app_id))
profile_state = GetOrCreateProfileState(profile, extension); profile_state = GetOrCreateProfileState(profile, extension);
// If there exist any open window for this profile, then bring them to the // If there exist any open window for this profile, then bring them to the
...@@ -707,7 +717,7 @@ void ExtensionAppShimHandler::OnShimProcessConnectedAndProfilesToLaunchLoaded( ...@@ -707,7 +717,7 @@ void ExtensionAppShimHandler::OnShimProcessConnectedAndProfilesToLaunchLoaded(
// Launch the app (open a window for it) if there were no open windows for // Launch the app (open a window for it) if there were no open windows for
// it already, or if we were asked to open files. // it already, or if we were asked to open files.
if (!had_open_windows || !launch_files.empty()) { if (!had_open_windows || !launch_files.empty()) {
delegate_->LaunchApp(profile, extension, launch_files); delegate_->LaunchApp(profile, app_id, launch_files);
launch_files.clear(); launch_files.clear();
} }
...@@ -849,7 +859,7 @@ void ExtensionAppShimHandler::OnProfileLoaded( ...@@ -849,7 +859,7 @@ void ExtensionAppShimHandler::OnProfileLoaded(
// TODO(jackhou): Add some UI for this case and remove the LOG. // TODO(jackhou): Add some UI for this case and remove the LOG.
LOG(ERROR) << "Requested directory is not a known profile '" LOG(ERROR) << "Requested directory is not a known profile '"
<< profile_path.value() << "'."; << profile_path.value() << "'.";
std::move(callback).Run(profile, nullptr); std::move(callback).Run(profile);
return; return;
} }
...@@ -859,7 +869,7 @@ void ExtensionAppShimHandler::OnProfileLoaded( ...@@ -859,7 +869,7 @@ void ExtensionAppShimHandler::OnProfileLoaded(
// life within a certain window. // life within a certain window.
const Extension* extension = delegate_->MaybeGetAppExtension(profile, app_id); const Extension* extension = delegate_->MaybeGetAppExtension(profile, app_id);
if (extension) { if (extension) {
std::move(callback).Run(profile, extension); std::move(callback).Run(profile);
} else { } else {
delegate_->EnableExtension( delegate_->EnableExtension(
profile, app_id, profile, app_id,
...@@ -872,12 +882,7 @@ void ExtensionAppShimHandler::OnProfileLoaded( ...@@ -872,12 +882,7 @@ void ExtensionAppShimHandler::OnProfileLoaded(
void ExtensionAppShimHandler::OnAppEnabled(const base::FilePath& profile_path, void ExtensionAppShimHandler::OnAppEnabled(const base::FilePath& profile_path,
const std::string& app_id, const std::string& app_id,
LoadProfileAppCallback callback) { LoadProfileAppCallback callback) {
// If the profile doesn't exist, it may have been deleted during the enable std::move(callback).Run(delegate_->ProfileForPath(profile_path));
// prompt.
Profile* profile = delegate_->ProfileForPath(profile_path);
const Extension* extension =
profile ? delegate_->MaybeGetAppExtension(profile, app_id) : nullptr;
std::move(callback).Run(profile, extension);
} }
bool ExtensionAppShimHandler::IsAcceptablyCodeSigned(pid_t pid) const { bool ExtensionAppShimHandler::IsAcceptablyCodeSigned(pid_t pid) const {
...@@ -921,13 +926,8 @@ void ExtensionAppShimHandler::OnShimProcessDisconnected(AppShimHost* host) { ...@@ -921,13 +926,8 @@ void ExtensionAppShimHandler::OnShimProcessDisconnected(AppShimHost* host) {
apps_.erase(found_app); apps_.erase(found_app);
// Close app windows if we decided to do so above. // Close app windows if we decided to do so above.
if (close_windows) { if (close_windows)
AppWindowList windows = delegate_->GetWindows(profile, app_id); delegate_->CloseAppWindows(profile, app_id);
for (auto it = windows.begin(); it != windows.end(); ++it) {
if (*it)
(*it)->GetBaseWindow()->Close();
}
}
} }
void ExtensionAppShimHandler::OnShimFocus(AppShimHost* host) { void ExtensionAppShimHandler::OnShimFocus(AppShimHost* host) {
...@@ -943,16 +943,11 @@ void ExtensionAppShimHandler::OnShimFocus(AppShimHost* host) { ...@@ -943,16 +943,11 @@ void ExtensionAppShimHandler::OnShimFocus(AppShimHost* host) {
return; return;
} }
AppWindowList windows = delegate_->GetWindows(profile, host->GetAppId()); if (delegate_->ShowAppWindows(profile, host->GetAppId()))
if (!windows.empty()) {
for (auto it = windows.rbegin(); it != windows.rend(); ++it) {
if (*it)
(*it)->GetBaseWindow()->Show();
}
return; return;
}
delegate_->LaunchApp(profile, extension, std::vector<base::FilePath>()); delegate_->LaunchApp(profile, host->GetAppId(),
std::vector<base::FilePath>());
} }
void ExtensionAppShimHandler::OnShimOpenedFiles( void ExtensionAppShimHandler::OnShimOpenedFiles(
...@@ -970,10 +965,7 @@ void ExtensionAppShimHandler::OnShimOpenedFiles( ...@@ -970,10 +965,7 @@ void ExtensionAppShimHandler::OnShimOpenedFiles(
profile = delegate_->ProfileForPath(host->GetProfilePath()); profile = delegate_->ProfileForPath(host->GetProfilePath());
} }
DCHECK(profile); DCHECK(profile);
const Extension* extension = delegate_->LaunchApp(profile, host->GetAppId(), files);
delegate_->MaybeGetAppExtension(profile, host->GetAppId());
DCHECK(extension);
delegate_->LaunchApp(profile, extension, files);
} }
void ExtensionAppShimHandler::OnShimSelectedProfile( void ExtensionAppShimHandler::OnShimSelectedProfile(
...@@ -983,12 +975,13 @@ void ExtensionAppShimHandler::OnShimSelectedProfile( ...@@ -983,12 +975,13 @@ void ExtensionAppShimHandler::OnShimSelectedProfile(
profile_path, host->GetAppId(), profile_path, host->GetAppId(),
base::BindOnce( base::BindOnce(
&ExtensionAppShimHandler::OnShimSelectedProfileAndAppLoaded, &ExtensionAppShimHandler::OnShimSelectedProfileAndAppLoaded,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr(), host->GetAppId()));
} }
void ExtensionAppShimHandler::OnShimSelectedProfileAndAppLoaded( void ExtensionAppShimHandler::OnShimSelectedProfileAndAppLoaded(
Profile* profile, const std::string& app_id,
const extensions::Extension* extension) { Profile* profile) {
const Extension* extension = delegate_->MaybeGetAppExtension(profile, app_id);
if (!extension) if (!extension)
return; return;
...@@ -1007,7 +1000,7 @@ void ExtensionAppShimHandler::OnShimSelectedProfileAndAppLoaded( ...@@ -1007,7 +1000,7 @@ void ExtensionAppShimHandler::OnShimSelectedProfileAndAppLoaded(
} else { } else {
// Otherwise, launch the app for this profile (which will open a new // Otherwise, launch the app for this profile (which will open a new
// window). // window).
delegate_->LaunchApp(profile, extension, std::vector<base::FilePath>()); delegate_->LaunchApp(profile, app_id, std::vector<base::FilePath>());
} }
} }
......
...@@ -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);
......
...@@ -56,7 +56,8 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate { ...@@ -56,7 +56,8 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate {
} }
MOCK_METHOD1(IsProfileLockedForPath, bool(const base::FilePath&)); MOCK_METHOD1(IsProfileLockedForPath, bool(const base::FilePath&));
MOCK_METHOD2(GetWindows, AppWindowList(Profile*, const std::string&)); MOCK_METHOD2(ShowAppWindows, bool(Profile*, const std::string&));
MOCK_METHOD2(CloseAppWindows, void(Profile*, const std::string&));
MOCK_METHOD2(MaybeGetAppExtension, MOCK_METHOD2(MaybeGetAppExtension,
const Extension*(content::BrowserContext*, const std::string&)); const Extension*(content::BrowserContext*, const std::string&));
...@@ -64,16 +65,16 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate { ...@@ -64,16 +65,16 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate {
void(Profile*, const std::string&, base::OnceCallback<void()>)); void(Profile*, const std::string&, base::OnceCallback<void()>));
MOCK_METHOD3(LaunchApp, MOCK_METHOD3(LaunchApp,
void(Profile*, void(Profile*,
const Extension*, const std::string& app_id,
const std::vector<base::FilePath>&)); const std::vector<base::FilePath>&));
MOCK_METHOD2(OpenAppURLInBrowserWindow, MOCK_METHOD2(OpenAppURLInBrowserWindow,
void(const base::FilePath&, const GURL& url)); void(const base::FilePath&, const GURL& url));
// Conditionally mock LaunchShim. Some tests will execute |launch_callback| // Conditionally mock LaunchShim. Some tests will execute |launch_callback|
// with a particular value. // with a particular value.
MOCK_METHOD3(DoLaunchShim, void(Profile*, const Extension*, bool)); MOCK_METHOD3(DoLaunchShim, void(Profile*, const std::string&, bool));
void LaunchShim(Profile* profile, void LaunchShim(Profile* profile,
const Extension* extension, const std::string& app_id,
bool recreate_shim, bool recreate_shim,
ShimLaunchedCallback launched_callback, ShimLaunchedCallback launched_callback,
ShimTerminatedCallback terminated_callback) override { ShimTerminatedCallback terminated_callback) override {
...@@ -81,7 +82,7 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate { ...@@ -81,7 +82,7 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate {
*launch_shim_callback_capture_ = std::move(launched_callback); *launch_shim_callback_capture_ = std::move(launched_callback);
if (terminated_shim_callback_capture_) if (terminated_shim_callback_capture_)
*terminated_shim_callback_capture_ = std::move(terminated_callback); *terminated_shim_callback_capture_ = std::move(terminated_callback);
DoLaunchShim(profile, extension, recreate_shim); DoLaunchShim(profile, app_id, recreate_shim);
} }
void SetCaptureShimLaunchedCallback(ShimLaunchedCallback* callback) { void SetCaptureShimLaunchedCallback(ShimLaunchedCallback* callback) {
launch_shim_callback_capture_ = callback; launch_shim_callback_capture_ = callback;
...@@ -98,7 +99,7 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate { ...@@ -98,7 +99,7 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate {
allow_shim_to_connect_ = should_create_host; allow_shim_to_connect_ = should_create_host;
} }
bool AllowShimToConnect(Profile* profile, bool AllowShimToConnect(Profile* profile,
const extensions::Extension* extension) override { const std::string& app_id) override {
return allow_shim_to_connect_; return allow_shim_to_connect_;
} }
...@@ -405,13 +406,6 @@ class ExtensionAppShimHandlerTest : public testing::Test { ...@@ -405,13 +406,6 @@ class ExtensionAppShimHandlerTest : public testing::Test {
EXPECT_CALL(*delegate_, ProfileForPath(profile_path_c_)) EXPECT_CALL(*delegate_, ProfileForPath(profile_path_c_))
.WillRepeatedly(Return(&profile_c_)); .WillRepeatedly(Return(&profile_c_));
// In most tests, we don't care about the result of GetWindows, it just
// needs to be non-empty.
AppWindowList app_window_list;
app_window_list.push_back(static_cast<extensions::AppWindow*>(NULL));
EXPECT_CALL(*delegate_, GetWindows(_, _))
.WillRepeatedly(Return(app_window_list));
EXPECT_CALL(*delegate_, MaybeGetAppExtension(&profile_a_, kTestAppIdA)) EXPECT_CALL(*delegate_, MaybeGetAppExtension(&profile_a_, kTestAppIdA))
.WillRepeatedly(Return(extension_a_.get())); .WillRepeatedly(Return(extension_a_.get()));
EXPECT_CALL(*delegate_, MaybeGetAppExtension(&profile_b_, kTestAppIdA)) EXPECT_CALL(*delegate_, MaybeGetAppExtension(&profile_b_, kTestAppIdA))
...@@ -608,8 +602,7 @@ TEST_F(ExtensionAppShimHandlerTest, LaunchAndCloseShim) { ...@@ -608,8 +602,7 @@ TEST_F(ExtensionAppShimHandlerTest, LaunchAndCloseShim) {
EXPECT_EQ(host_ab_.get(), handler_->FindHost(&profile_a_, kTestAppIdB)); EXPECT_EQ(host_ab_.get(), handler_->FindHost(&profile_a_, kTestAppIdB));
std::vector<base::FilePath> some_file(1, base::FilePath("some_file")); std::vector<base::FilePath> some_file(1, base::FilePath("some_file"));
EXPECT_CALL(*delegate_, EXPECT_CALL(*delegate_, LaunchApp(&profile_b_, kTestAppIdB, some_file));
LaunchApp(&profile_b_, extension_b_.get(), some_file));
DoShimLaunch(bootstrap_bb_, std::move(host_bb_unique_), DoShimLaunch(bootstrap_bb_, std::move(host_bb_unique_),
chrome::mojom::AppShimLaunchType::kNormal, some_file); chrome::mojom::AppShimLaunchType::kNormal, some_file);
EXPECT_EQ(host_bb_.get(), handler_->FindHost(&profile_b_, kTestAppIdB)); EXPECT_EQ(host_bb_.get(), handler_->FindHost(&profile_b_, kTestAppIdB));
...@@ -641,41 +634,33 @@ TEST_F(ExtensionAppShimHandlerTest, AppLifetime) { ...@@ -641,41 +634,33 @@ TEST_F(ExtensionAppShimHandlerTest, AppLifetime) {
// When the app activates, a host is created. If there is no shim, one is // When the app activates, a host is created. If there is no shim, one is
// launched. // launched.
delegate_->SetHostForCreate(std::move(host_aa_unique_)); delegate_->SetHostForCreate(std::move(host_aa_unique_));
EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, extension_a_.get(), false)); EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, kTestAppIdA, false));
handler_->OnAppActivated(&profile_a_, kTestAppIdA); handler_->OnAppActivated(&profile_a_, kTestAppIdA);
EXPECT_EQ(host_aa_.get(), handler_->FindHost(&profile_a_, kTestAppIdA)); EXPECT_EQ(host_aa_.get(), handler_->FindHost(&profile_a_, kTestAppIdA));
// Normal shim launch adds an entry in the map. // Normal shim launch adds an entry in the map.
// App should not be launched here, but return success to the shim. // App should not be launched here, but return success to the shim.
EXPECT_CALL(*delegate_, EXPECT_CALL(*delegate_, LaunchApp(&profile_a_, kTestAppIdA, _)).Times(0);
LaunchApp(&profile_a_, extension_a_.get(), _))
.Times(0);
RegisterOnlyLaunch(bootstrap_aa_, nullptr); RegisterOnlyLaunch(bootstrap_aa_, nullptr);
EXPECT_EQ(chrome::mojom::AppShimLaunchResult::kSuccess, EXPECT_EQ(chrome::mojom::AppShimLaunchResult::kSuccess,
*bootstrap_aa_result_); *bootstrap_aa_result_);
EXPECT_EQ(host_aa_.get(), handler_->FindHost(&profile_a_, kTestAppIdA)); EXPECT_EQ(host_aa_.get(), handler_->FindHost(&profile_a_, kTestAppIdA));
// Return no app windows for OnShimFocus. This will result in a launch call. // Return no app windows for OnShimFocus. This will result in a launch call.
AppWindowList app_window_list; EXPECT_CALL(*delegate_, ShowAppWindows(&profile_a_, kTestAppIdA))
EXPECT_CALL(*delegate_, GetWindows(&profile_a_, kTestAppIdA)) .WillRepeatedly(Return(false));
.WillRepeatedly(Return(app_window_list)); EXPECT_CALL(*delegate_, LaunchApp(&profile_a_, kTestAppIdA, _)).Times(1);
EXPECT_CALL(*delegate_, LaunchApp(&profile_a_, extension_a_.get(), _))
.Times(1);
ShimNormalFocus(host_aa_.get()); ShimNormalFocus(host_aa_.get());
// Return one window. This should do nothing. // Return one window. This should do nothing.
app_window_list.push_back(static_cast<extensions::AppWindow*>(nullptr)); EXPECT_CALL(*delegate_, ShowAppWindows(&profile_a_, kTestAppIdA))
EXPECT_CALL(*delegate_, GetWindows(&profile_a_, kTestAppIdA)) .WillRepeatedly(Return(true));
.WillRepeatedly(Return(app_window_list)); EXPECT_CALL(*delegate_, LaunchApp(&profile_a_, kTestAppIdA, _)).Times(0);
EXPECT_CALL(*delegate_,
LaunchApp(&profile_a_, extension_a_.get(), _))
.Times(0);
ShimNormalFocus(host_aa_.get()); ShimNormalFocus(host_aa_.get());
// Open files should trigger a launch with those files. // Open files should trigger a launch with those files.
std::vector<base::FilePath> some_file(1, base::FilePath("some_file")); std::vector<base::FilePath> some_file(1, base::FilePath("some_file"));
EXPECT_CALL(*delegate_, EXPECT_CALL(*delegate_, LaunchApp(&profile_a_, kTestAppIdA, some_file));
LaunchApp(&profile_a_, extension_a_.get(), some_file));
host_aa_->FilesOpened(some_file); host_aa_->FilesOpened(some_file);
// Process disconnect will cause the host to be deleted. // Process disconnect will cause the host to be deleted.
...@@ -693,14 +678,14 @@ TEST_F(ExtensionAppShimHandlerTest, FailToLaunch) { ...@@ -693,14 +678,14 @@ TEST_F(ExtensionAppShimHandlerTest, FailToLaunch) {
ShimLaunchedCallback launch_callback; ShimLaunchedCallback launch_callback;
delegate_->SetCaptureShimLaunchedCallback(&launch_callback); delegate_->SetCaptureShimLaunchedCallback(&launch_callback);
delegate_->SetHostForCreate(std::move(host_aa_unique_)); delegate_->SetHostForCreate(std::move(host_aa_unique_));
EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, extension_a_.get(), false)); EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, kTestAppIdA, false));
handler_->OnAppActivated(&profile_a_, kTestAppIdA); handler_->OnAppActivated(&profile_a_, kTestAppIdA);
EXPECT_EQ(host_aa_.get(), handler_->FindHost(&profile_a_, kTestAppIdA)); EXPECT_EQ(host_aa_.get(), handler_->FindHost(&profile_a_, kTestAppIdA));
EXPECT_TRUE(launch_callback); EXPECT_TRUE(launch_callback);
// Run the callback claiming that the launch failed. This should trigger // Run the callback claiming that the launch failed. This should trigger
// another launch, this time forcing shim recreation. // another launch, this time forcing shim recreation.
EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, extension_a_.get(), true)); EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, kTestAppIdA, true));
std::move(launch_callback).Run(base::Process()); std::move(launch_callback).Run(base::Process());
EXPECT_TRUE(launch_callback); EXPECT_TRUE(launch_callback);
...@@ -718,7 +703,7 @@ TEST_F(ExtensionAppShimHandlerTest, FailToConnect) { ...@@ -718,7 +703,7 @@ TEST_F(ExtensionAppShimHandlerTest, FailToConnect) {
delegate_->SetCaptureShimTerminatedCallback(&terminated_callback); delegate_->SetCaptureShimTerminatedCallback(&terminated_callback);
delegate_->SetHostForCreate(std::move(host_aa_unique_)); delegate_->SetHostForCreate(std::move(host_aa_unique_));
EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, extension_a_.get(), false)); EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, kTestAppIdA, false));
handler_->OnAppActivated(&profile_a_, kTestAppIdA); handler_->OnAppActivated(&profile_a_, kTestAppIdA);
EXPECT_EQ(host_aa_.get(), handler_->FindHost(&profile_a_, kTestAppIdA)); EXPECT_EQ(host_aa_.get(), handler_->FindHost(&profile_a_, kTestAppIdA));
EXPECT_TRUE(launched_callback); EXPECT_TRUE(launched_callback);
...@@ -731,7 +716,7 @@ TEST_F(ExtensionAppShimHandlerTest, FailToConnect) { ...@@ -731,7 +716,7 @@ TEST_F(ExtensionAppShimHandlerTest, FailToConnect) {
// Report that the process terminated. This should trigger a re-create and // Report that the process terminated. This should trigger a re-create and
// re-launch. // re-launch.
EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, extension_a_.get(), true)); EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, kTestAppIdA, true));
std::move(terminated_callback).Run(); std::move(terminated_callback).Run();
EXPECT_TRUE(launched_callback); EXPECT_TRUE(launched_callback);
EXPECT_TRUE(terminated_callback); EXPECT_TRUE(terminated_callback);
...@@ -757,7 +742,7 @@ TEST_F(ExtensionAppShimHandlerTest, FailCodeSignature) { ...@@ -757,7 +742,7 @@ TEST_F(ExtensionAppShimHandlerTest, FailCodeSignature) {
// Fail to code-sign. This should result in a host being created, and a launch // Fail to code-sign. This should result in a host being created, and a launch
// having been requested. // having been requested.
EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, extension_a_.get(), false)); EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, kTestAppIdA, false));
NormalLaunch(bootstrap_aa_, std::move(host_aa_unique_)); NormalLaunch(bootstrap_aa_, std::move(host_aa_unique_));
EXPECT_EQ(host_aa_.get(), handler_->FindHost(&profile_a_, kTestAppIdA)); EXPECT_EQ(host_aa_.get(), handler_->FindHost(&profile_a_, kTestAppIdA));
EXPECT_TRUE(launched_callback); EXPECT_TRUE(launched_callback);
...@@ -776,7 +761,7 @@ TEST_F(ExtensionAppShimHandlerTest, FailCodeSignature) { ...@@ -776,7 +761,7 @@ TEST_F(ExtensionAppShimHandlerTest, FailCodeSignature) {
// Simulate the termination after the register failed. // Simulate the termination after the register failed.
handler_->SetAcceptablyCodeSigned(true); handler_->SetAcceptablyCodeSigned(true);
EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, extension_a_.get(), true)); EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, kTestAppIdA, true));
std::move(terminated_callback).Run(); std::move(terminated_callback).Run();
EXPECT_TRUE(launched_callback); EXPECT_TRUE(launched_callback);
EXPECT_TRUE(terminated_callback); EXPECT_TRUE(terminated_callback);
...@@ -796,11 +781,6 @@ TEST_F(ExtensionAppShimHandlerTest, MaybeTerminate) { ...@@ -796,11 +781,6 @@ TEST_F(ExtensionAppShimHandlerTest, MaybeTerminate) {
*bootstrap_ab_result_); *bootstrap_ab_result_);
EXPECT_EQ(host_ab_.get(), handler_->FindHost(&profile_a_, kTestAppIdB)); EXPECT_EQ(host_ab_.get(), handler_->FindHost(&profile_a_, kTestAppIdB));
// Return empty window list.
AppWindowList app_window_list;
EXPECT_CALL(*delegate_, GetWindows(_, _))
.WillRepeatedly(Return(app_window_list));
// Quitting when there's another shim should not terminate. // Quitting when there's another shim should not terminate.
EXPECT_CALL(*delegate_, MaybeTerminate()) EXPECT_CALL(*delegate_, MaybeTerminate())
.Times(0); .Times(0);
...@@ -856,11 +836,6 @@ TEST_F(ExtensionAppShimHandlerTest, LoadProfile) { ...@@ -856,11 +836,6 @@ TEST_F(ExtensionAppShimHandlerTest, LoadProfile) {
TEST_F(ExtensionAppShimHandlerTest, ExtensionUninstalled) { TEST_F(ExtensionAppShimHandlerTest, ExtensionUninstalled) {
LaunchAndActivate(bootstrap_aa_, std::move(host_aa_unique_), &profile_a_); LaunchAndActivate(bootstrap_aa_, std::move(host_aa_unique_), &profile_a_);
// Have GetWindows() return an empty window list for focus (otherwise, it
// will contain a single nullptr, which can't be focused). Expect 1 call only.
AppWindowList empty_window_list;
EXPECT_CALL(*delegate_, GetWindows(_, _)).WillOnce(Return(empty_window_list));
ShimNormalFocus(host_aa_.get()); ShimNormalFocus(host_aa_.get());
EXPECT_NE(nullptr, host_aa_.get()); EXPECT_NE(nullptr, host_aa_.get());
...@@ -885,8 +860,7 @@ TEST_F(ExtensionAppShimHandlerTest, PreExistingHost) { ...@@ -885,8 +860,7 @@ TEST_F(ExtensionAppShimHandlerTest, PreExistingHost) {
// Launch the app for this host. It should find the pre-existing host, and the // Launch the app for this host. It should find the pre-existing host, and the
// pre-existing host's launch result should be set. // pre-existing host's launch result should be set.
EXPECT_CALL(*handler_, OnShimFocus(host_aa_.get())).Times(1); EXPECT_CALL(*handler_, OnShimFocus(host_aa_.get())).Times(1);
EXPECT_CALL(*delegate_, LaunchApp(&profile_a_, extension_a_.get(), _)) EXPECT_CALL(*delegate_, LaunchApp(&profile_a_, kTestAppIdA, _)).Times(0);
.Times(0);
EXPECT_FALSE(host_aa_->did_connect_to_host()); EXPECT_FALSE(host_aa_->did_connect_to_host());
DoShimLaunch(bootstrap_aa_, nullptr, DoShimLaunch(bootstrap_aa_, nullptr,
chrome::mojom::AppShimLaunchType::kRegisterOnly, chrome::mojom::AppShimLaunchType::kRegisterOnly,
...@@ -951,7 +925,7 @@ TEST_F(ExtensionAppShimHandlerTest, MultiProfileShimLaunch) { ...@@ -951,7 +925,7 @@ TEST_F(ExtensionAppShimHandlerTest, MultiProfileShimLaunch) {
delegate_->SetCaptureShimTerminatedCallback(&terminated_callback); delegate_->SetCaptureShimTerminatedCallback(&terminated_callback);
// Launch the app for profile A. This should trigger a shim launch request. // Launch the app for profile A. This should trigger a shim launch request.
EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, extension_a_.get(), EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, kTestAppIdA,
false /* recreate_shim */)); false /* recreate_shim */));
EXPECT_EQ(nullptr, handler_->FindHost(&profile_a_, kTestAppIdA)); EXPECT_EQ(nullptr, handler_->FindHost(&profile_a_, kTestAppIdA));
handler_->OnAppActivated(&profile_a_, kTestAppIdA); handler_->OnAppActivated(&profile_a_, kTestAppIdA);
...@@ -978,7 +952,7 @@ TEST_F(ExtensionAppShimHandlerTest, MultiProfileSelectMenu) { ...@@ -978,7 +952,7 @@ TEST_F(ExtensionAppShimHandlerTest, MultiProfileSelectMenu) {
delegate_->SetCaptureShimTerminatedCallback(&terminated_callback); delegate_->SetCaptureShimTerminatedCallback(&terminated_callback);
// Launch the app for profile A. This should trigger a shim launch request. // Launch the app for profile A. This should trigger a shim launch request.
EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, extension_a_.get(), EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, kTestAppIdA,
false /* recreate_shim */)); false /* recreate_shim */));
EXPECT_EQ(nullptr, handler_->FindHost(&profile_a_, kTestAppIdA)); EXPECT_EQ(nullptr, handler_->FindHost(&profile_a_, kTestAppIdA));
handler_->OnAppActivated(&profile_a_, kTestAppIdA); handler_->OnAppActivated(&profile_a_, kTestAppIdA);
...@@ -994,7 +968,7 @@ TEST_F(ExtensionAppShimHandlerTest, MultiProfileSelectMenu) { ...@@ -994,7 +968,7 @@ TEST_F(ExtensionAppShimHandlerTest, MultiProfileSelectMenu) {
// Select profile B from the menu. This should request that the app be // Select profile B from the menu. This should request that the app be
// launched. // launched.
EXPECT_CALL(*delegate_, LaunchApp(&profile_b_, extension_a_.get(), _)); EXPECT_CALL(*delegate_, LaunchApp(&profile_b_, kTestAppIdA, _));
host_aa_->ProfileSelectedFromMenu(profile_path_b_); host_aa_->ProfileSelectedFromMenu(profile_path_b_);
EXPECT_CALL(*delegate_, DoLaunchShim(_, _, _)).Times(0); EXPECT_CALL(*delegate_, DoLaunchShim(_, _, _)).Times(0);
handler_->OnAppActivated(&profile_b_, kTestAppIdA); handler_->OnAppActivated(&profile_b_, kTestAppIdA);
...@@ -1024,13 +998,12 @@ TEST_F(ExtensionAppShimHandlerTest, ProfileMenuOneProfile) { ...@@ -1024,13 +998,12 @@ TEST_F(ExtensionAppShimHandlerTest, ProfileMenuOneProfile) {
// When the app activates, a host is created. This will trigger building // When the app activates, a host is created. This will trigger building
// the avatar menu. // the avatar menu.
delegate_->SetHostForCreate(std::move(host_aa_unique_)); delegate_->SetHostForCreate(std::move(host_aa_unique_));
EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, extension_a_.get(), false)); EXPECT_CALL(*delegate_, DoLaunchShim(&profile_a_, kTestAppIdA, false));
handler_->OnAppActivated(&profile_a_, kTestAppIdA); handler_->OnAppActivated(&profile_a_, kTestAppIdA);
EXPECT_EQ(host_aa_.get(), handler_->FindHost(&profile_a_, kTestAppIdA)); EXPECT_EQ(host_aa_.get(), handler_->FindHost(&profile_a_, kTestAppIdA));
// Launch the shim. // Launch the shim.
EXPECT_CALL(*delegate_, LaunchApp(&profile_a_, extension_a_.get(), _)) EXPECT_CALL(*delegate_, LaunchApp(&profile_a_, kTestAppIdA, _)).Times(0);
.Times(0);
RegisterOnlyLaunch(bootstrap_aa_, nullptr); RegisterOnlyLaunch(bootstrap_aa_, nullptr);
EXPECT_EQ(chrome::mojom::AppShimLaunchResult::kSuccess, EXPECT_EQ(chrome::mojom::AppShimLaunchResult::kSuccess,
*bootstrap_aa_result_); *bootstrap_aa_result_);
...@@ -1084,10 +1057,8 @@ TEST_F(ExtensionAppShimHandlerTest, FindProfileFromBadProfile) { ...@@ -1084,10 +1057,8 @@ TEST_F(ExtensionAppShimHandlerTest, FindProfileFromBadProfile) {
// Launch the shim requesting profile C. // Launch the shim requesting profile C.
delegate_->SetHostForCreate(std::move(host_aa_unique_)); delegate_->SetHostForCreate(std::move(host_aa_unique_));
EXPECT_CALL(*delegate_, LaunchApp(&profile_a_, extension_a_.get(), _)) EXPECT_CALL(*delegate_, LaunchApp(&profile_a_, kTestAppIdA, _)).Times(1);
.Times(1); EXPECT_CALL(*delegate_, LaunchApp(&profile_b_, kTestAppIdA, _)).Times(0);
EXPECT_CALL(*delegate_, LaunchApp(&profile_b_, extension_a_.get(), _))
.Times(0);
EXPECT_CALL(*delegate_, EnableExtension(&profile_c_, kTestAppIdA, _)) EXPECT_CALL(*delegate_, EnableExtension(&profile_c_, kTestAppIdA, _))
.WillOnce(RunOnceCallback<2>()); .WillOnce(RunOnceCallback<2>());
NormalLaunch(bootstrap_ca_, nullptr); NormalLaunch(bootstrap_ca_, nullptr);
...@@ -1103,10 +1074,8 @@ TEST_F(ExtensionAppShimHandlerTest, FindProfileFromNoProfile) { ...@@ -1103,10 +1074,8 @@ TEST_F(ExtensionAppShimHandlerTest, FindProfileFromNoProfile) {
// Launch the shim without specifying a profile. // Launch the shim without specifying a profile.
delegate_->SetHostForCreate(std::move(host_aa_unique_)); delegate_->SetHostForCreate(std::move(host_aa_unique_));
EXPECT_CALL(*delegate_, LaunchApp(&profile_a_, extension_a_.get(), _)) EXPECT_CALL(*delegate_, LaunchApp(&profile_a_, kTestAppIdA, _)).Times(1);
.Times(1); EXPECT_CALL(*delegate_, LaunchApp(&profile_b_, kTestAppIdA, _)).Times(0);
EXPECT_CALL(*delegate_, LaunchApp(&profile_b_, extension_a_.get(), _))
.Times(0);
NormalLaunch(bootstrap_xa_, nullptr); NormalLaunch(bootstrap_xa_, nullptr);
EXPECT_EQ(chrome::mojom::AppShimLaunchResult::kSuccess, EXPECT_EQ(chrome::mojom::AppShimLaunchResult::kSuccess,
*bootstrap_xa_result_); *bootstrap_xa_result_);
......
...@@ -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,8 +166,14 @@ void ChromeNativeAppWindowViewsMac::Restore() { ...@@ -165,8 +166,14 @@ 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());
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); : chrome::mojom::AppShimAttentionType::kCancel);
} }
......
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